Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Kernel - File System.c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Kernel ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgKN_File_System_Mount ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgKN_FS_MOUNT_ID tgKN_File_System_Mount( C_TgKN_FILE_SYSTEM_ID tiFS, C_ETgFILE_IO_ACCESS enMode, CPCU_TgCHAR pszPath )
{
    union
    {
        P_STg2_UTM_Node                     psNode;
        P_STg2_KN_FS_Mount                  ps;
    }                                   sMount;

    TgPARAM_CHECK_INDEX( tiFS.m.iI, g_asKN_FS );

    if (TgTRUE != tgEQ_KN_FILE_SYSTEM_ID( tiFS, g_asKN_FS[tiFS.m.iI].m_tiFS ))
    {
        return (KTgKN_FS_MOUNT_ID__INVALID);
    };

    sMount.psNode = tgCM_UTM_AM_ST_Pop( &g_sKN_FS_Mount__Free_Stack.m_sStack );
    if (nullptr == sMount.psNode)
    {
        return (KTgKN_FS_MOUNT_ID__INVALID);
    };

    tgInit_KN_FS_MOUNT_ID( &sMount.ps->m_tiFS_Mount, (TgSINT32)(sMount.ps - g_asKN_FS_Mount) );
    sMount.ps->m_tiFS = tiFS;
    sMount.ps->m_enMode = enMode;

    if (nullptr != g_asKN_FS[tiFS.m.iI].m_pfnMount)
    {
        g_asKN_FS[tiFS.m.iI].m_pfnMount( sMount.ps->m_tiFS_Mount, pszPath );
    };

    return (sMount.ps->m_tiFS_Mount);
}


/* ---- tgKN_FILE_ALLOCATOR__Default_Malloc_Pool ------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
P_TgVOID tgKN_FILE_ALLOCATOR__Default_Malloc_Pool( C_TgSIZE uiSize )
{
    return (TgMALLOC_POOL( uiSize ));
}




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Private Functions                                                                                                                                                     */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgKN_Register_File_System --------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgKN_FILE_SYSTEM_ID tgKN_Register_File_System( PC_STg2_KN_File_System_DESC psFS_DESC )
{
    TgSINT32                            iFS_Index;

    iFS_Index = tgAM32_XADD( &g_niKN_FS, 1 );
    if (iFS_Index >= KTgKN_MAX_FILE_SYSTEM)
    {
        return (KTgKN_FILE_SYSTEM_ID__INVALID);
    };

    tgCM_UTM_SN_Init( &g_asKN_FS[iFS_Index].m_sAdd_Lock.m_sLock );
    tgCM_UTM_SNC_Init( &g_asKN_FS[iFS_Index].m_sProcess_Lock.m_sLock );
    tgCM_UTS_QU_Init( &g_asKN_FS[iFS_Index].m_sAdd_Queue );
    tgCM_UTS_QU_Init( &g_asKN_FS[iFS_Index].m_sProcess_Queue );
    tgCM_UTM_AM_ST_Init( &g_asKN_FS[iFS_Index].m_sComplete_Job.m_sStack );
    tgInit_KN_FILE_SYSTEM_ID( &g_asKN_FS[iFS_Index].m_tiFS, iFS_Index );
    g_asKN_FS[iFS_Index].m_niExecute = 0;
    g_asKN_FS[iFS_Index].m_niMax_Execute = psFS_DESC->m_niMax_Execute;
    g_asKN_FS[iFS_Index].m_pfnFree_Space = psFS_DESC->m_pfnFree_Space;
    g_asKN_FS[iFS_Index].m_pfnMount = psFS_DESC->m_pfnMount;
    g_asKN_FS[iFS_Index].m_pfnExecute_Job = psFS_DESC->m_pfnExecute_Job;

    return (g_asKN_FS[iFS_Index].m_tiFS);
}