X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fvfs_handle.c;h=724e76fc483db6249d6afdaa5e1533b654f4dd3e;hb=b6198d9a828e247771a8913099070d51df76db4b;hp=91caeffe9a3a3fe9cc118e7f4970d992eac78c44;hpb=3764c294f21229bdf700f436fa4884f5e76e0d3a;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/vfs_handle.c b/AcessNative/acesskernel_src/vfs_handle.c index 91caeffe..724e76fc 100644 --- a/AcessNative/acesskernel_src/vfs_handle.c +++ b/AcessNative/acesskernel_src/vfs_handle.c @@ -2,11 +2,12 @@ * Acess2 VFS * - AllocHandle, GetHandle */ -#define DEBUG 1 +#define DEBUG 0 #include #include #include #include +#include // === CONSTANTS === #define MAX_KERNEL_FILES 128 @@ -37,7 +38,8 @@ tUserHandles *VFS_int_GetUserHandles(int PID, int bCreate) tUserHandles *ent, *prev = NULL; for( ent = gpUserHandles; ent; prev = ent, ent = ent->Next ) { if( ent->PID == PID ) { - Log_Warning("VFS", "Process %i already has a handle list", PID); + //if( bCreate ) + // Log_Warning("VFS", "Process %i already has a handle list", PID); return ent; } if( ent->PID > PID ) break; @@ -67,21 +69,56 @@ void VFS_CloneHandleList(int PID) { tUserHandles *ent; tUserHandles *cur; - int i; + int i, maxhandles; + + cur = VFS_int_GetUserHandles(Threads_GetPID(), 0); + if(!cur) return ; // Don't need to do anything if the current list is empty + + ent = VFS_int_GetUserHandles(PID, 1); + + maxhandles = *Threads_GetMaxFD(); + memcpy(ent->Handles, cur->Handles, maxhandles*sizeof(tVFS_Handle)); + + for( i = 0; i < maxhandles; i ++ ) + { + if(!cur->Handles[i].Node) continue; + + if(ent->Handles[i].Node->Type->Reference) + ent->Handles[i].Node->Type->Reference(ent->Handles[i].Node); + } +} + +void VFS_CloneHandlesFromList(int PID, int nFD, int FDs[]) +{ + tUserHandles *ent; + tUserHandles *cur; + int i, maxhandles; cur = VFS_int_GetUserHandles(Threads_GetPID(), 0); if(!cur) return ; // Don't need to do anything if the current list is empty ent = VFS_int_GetUserHandles(PID, 1); - memcpy(ent->Handles, cur->Handles, CFGINT(CFG_VFS_MAXFILES)*sizeof(tVFS_Handle)); + maxhandles = *Threads_GetMaxFD(); + if( nFD > maxhandles ) + nFD = maxhandles; + for( i = 0; i < nFD; i ++ ) + { + if( FDs[i] >= maxhandles ) { + ent->Handles[i].Node = NULL; + continue ; + } + memcpy(&ent->Handles[i], &cur->Handles[ FDs[i] ], sizeof(tVFS_Handle)); + } + for( ; i < maxhandles; i ++ ) + cur->Handles[i].Node = NULL; - for( i = 0; i < CFGINT(CFG_VFS_MAXFILES); i ++ ) + for( i = 0; i < maxhandles; i ++ ) { if(!cur->Handles[i].Node) continue; - if(ent->Handles[i].Node->Reference) - ent->Handles[i].Node->Reference(ent->Handles[i].Node); + if(ent->Handles[i].Node->Type->Reference) + ent->Handles[i].Node->Type->Reference(ent->Handles[i].Node); } } @@ -112,6 +149,7 @@ tVFS_Handle *VFS_GetHandle(int FD) { tUserHandles *ent; int pid = Threads_GetPID(); + int maxhandles = *Threads_GetMaxFD(); ent = VFS_int_GetUserHandles(pid, 0); if(!ent) { @@ -119,8 +157,8 @@ tVFS_Handle *VFS_GetHandle(int FD) return NULL; } - if(FD >= CFGINT(CFG_VFS_MAXFILES)) { - LOG("FD (%i) > Limit (%i), RETURN NULL", FD, CFGINT(CFG_VFS_MAXFILES)); + if(FD >= maxhandles) { + LOG("FD (%i) > Limit (%i), RETURN NULL", FD, maxhandles); return NULL; } h = &ent->Handles[ FD ]; @@ -143,10 +181,11 @@ int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) if(bIsUser) { tUserHandles *ent; + int maxhandles = *Threads_GetMaxFD(); // Find the PID's handle list ent = VFS_int_GetUserHandles(Threads_GetPID(), 1); // Get a handle - for(i=0;iHandles[i].Node) continue; ent->Handles[i].Node = Node;