* Acess2 VFS
* - AllocHandle, GetHandle
*/
+#define SANITY 1
#define DEBUG 0
#include <acess.h>
#include <mm_virt.h>
#if 0
tVFS_Handle *VFS_GetHandle(int FD);
#endif
+inline void _ReferenceNode(tVFS_Node *Node);
int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
// === GLOBALS ===
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
{
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);
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);
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 ++ )
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 ++;
}
}
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 ++ )
h = &gaUserHandles[i];
if( !h->Node )
continue ;
- if( h->Node->Type && h->Node->Type->Close )
- h->Node->Type->Close( h->Node );
+ _CloseNode(h->Node);
}
}
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
// 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 ++;
}
return ret;
return ;
// Check if there is already a set of handles
- if( MM_GetPhysAddr( (tVAddr)gaUserHandles ) != 0 )
+ if( MM_GetPhysAddr( gaUserHandles ) != 0 )
return ;
if( !h->Node )
continue ;
- if( h->Node->Type && h->Node->Type->Reference )
- h->Node->Type->Reference( h->Node );
+ _ReferenceNode(h->Node);
+ h->Mount->OpenHandleCount ++;
}
}
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 );
}