X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Fvfs%2Fhandle.c;h=88877aba00bd91cc5344acd49766291fa08ace61;hb=3bcb89ec409dc04c55465bdb79ffc7828f003e3c;hp=6d2b83fbe12fdbaa28623a58f6076f4823015415;hpb=11dbd684e9a3d907d43d71a3145205f1a86992fb;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/vfs/handle.c b/KernelLand/Kernel/vfs/handle.c index 6d2b83fb..88877aba 100644 --- a/KernelLand/Kernel/vfs/handle.c +++ b/KernelLand/Kernel/vfs/handle.c @@ -2,6 +2,7 @@ * Acess2 VFS * - AllocHandle, GetHandle */ +#define SANITY 1 #define DEBUG 0 #include #include @@ -25,6 +26,19 @@ tVFS_Handle *gaUserHandles = (void*)MM_PPD_HANDLES; tVFS_Handle *gaKernelHandles = (void*)MM_KERNEL_VFS; // === CODE === +inline void _ReferenceNode(tVFS_Node *Node) +{ + if( !MM_GetPhysAddr(Node->Type) ) { + Log_Error("VFS", "Node %p's type is invalid (%p bad pointer) - %P corrupted", + Node, Node->Type, MM_GetPhysAddr(&Node->Type)); + return ; + } + if( Node->Type && Node->Type->Reference ) + Node->Type->Reference( Node ); + else + Node->ReferenceCount ++; +} + /** * \fn tVFS_Handle *VFS_GetHandle(int FD) * \brief Gets a pointer to the handle information structure @@ -60,7 +74,7 @@ int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) { int max_handles = *Threads_GetMaxFD(); // Allocate Buffer - if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 ) + if( MM_GetPhysAddr( gaUserHandles ) == 0 ) { Uint addr, size; size = max_handles * sizeof(tVFS_Handle); @@ -87,7 +101,7 @@ int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) else { // Allocate space if not already - if( MM_GetPhysAddr( (tVAddr)gaKernelHandles ) == 0 ) + if( MM_GetPhysAddr( gaKernelHandles ) == 0 ) { Uint addr, size; size = MAX_KERNEL_FILES * sizeof(tVFS_Handle); @@ -121,7 +135,7 @@ void VFS_ReferenceUserHandles(void) int max_handles = *Threads_GetMaxFD(); // Check if this process has any handles - if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 ) + if( MM_GetPhysAddr( gaUserHandles ) == 0 ) return ; for( i = 0; i < max_handles; i ++ ) @@ -130,8 +144,8 @@ void VFS_ReferenceUserHandles(void) h = &gaUserHandles[i]; if( !h->Node ) continue ; - if( h->Node->Type && h->Node->Type->Reference ) - h->Node->Type->Reference( h->Node ); + _ReferenceNode(h->Node); + h->Mount->OpenHandleCount ++; } } @@ -141,7 +155,7 @@ void VFS_CloseAllUserHandles(void) int max_handles = *Threads_GetMaxFD(); // Check if this process has any handles - if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 ) + if( MM_GetPhysAddr( gaUserHandles ) == 0 ) return ; for( i = 0; i < max_handles; i ++ ) @@ -150,8 +164,7 @@ void VFS_CloseAllUserHandles(void) h = &gaUserHandles[i]; if( !h->Node ) continue ; - if( h->Node->Type && h->Node->Type->Close ) - h->Node->Type->Close( h->Node ); + _CloseNode(h->Node); } } @@ -165,7 +178,7 @@ void *VFS_SaveHandles(int NumFDs, int *FDs) int max_handles = *Threads_GetMaxFD(); // Check if this process has any handles - if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) == 0 ) + if( MM_GetPhysAddr( gaUserHandles ) == 0 ) return NULL; // Allocate @@ -196,8 +209,7 @@ void *VFS_SaveHandles(int NumFDs, int *FDs) // Reference node if( !h->Node ) continue ; - if( h->Node->Type && h->Node->Type->Reference ) - h->Node->Type->Reference( h->Node ); + _ReferenceNode(h->Node); h->Mount->OpenHandleCount ++; } @@ -214,7 +226,7 @@ void VFS_RestoreHandles(int NumFDs, void *Handles) return ; // Check if there is already a set of handles - if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) != 0 ) + if( MM_GetPhysAddr( gaUserHandles ) != 0 ) return ; @@ -243,8 +255,7 @@ void VFS_RestoreHandles(int NumFDs, void *Handles) if( !h->Node ) continue ; - if( h->Node->Type && h->Node->Type->Reference ) - h->Node->Type->Reference( h->Node ); + _ReferenceNode(h->Node); h->Mount->OpenHandleCount ++; } } @@ -265,8 +276,10 @@ void VFS_FreeSavedHandles(int NumFDs, void *Handles) if( !h->Node ) continue ; - if( h->Node->Type && h->Node->Type->Close ) - h->Node->Type->Close( h->Node ); + _CloseNode(h->Node); + + ASSERT(h->Mount->OpenHandleCount > 0); + LOG("dec. mntpt '%s' to %i", h->Mount->MountPoint, h->Mount->OpenHandleCount-1); h->Mount->OpenHandleCount --; } free( Handles );