+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 ) {
+ if( bCreate )
+ Log_Warning("VFS", "Process %i already has a handle list", PID);
+ return ent;
+ }
+ if( ent->PID > PID ) break;
+ }
+
+ if(!bCreate)
+ return NULL;
+
+ ent = calloc( 1, sizeof(tUserHandles) );
+ ent->PID = PID;
+ if( prev ) {
+ ent->Next = prev->Next;
+ prev->Next = ent;
+ }
+ else {
+ ent->Next = gpUserHandles;
+ gpUserHandles = ent;
+ }
+ Log_Notice("VFS", "Created handle list for process %i", PID);
+ return ent;
+}
+
+/**
+ * \brief Clone the handle list of the current process into another
+ */
+void VFS_CloneHandleList(int PID)
+{
+ tUserHandles *ent;
+ tUserHandles *cur;
+ int i;
+
+ 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));
+
+ for( i = 0; i < CFGINT(CFG_VFS_MAXFILES); i ++ )
+ {
+ if(!cur->Handles[i].Node) continue;
+
+ if(ent->Handles[i].Node->Reference)
+ ent->Handles[i].Node->Reference(ent->Handles[i].Node);
+ }
+}
+