3 * - AllocHandle, GetHandle
12 #define MAX_KERNEL_FILES 128
13 #define MAX_USER_FILES 64
16 extern int Server_GetClientID(void);
19 tVFS_Handle *VFS_GetHandle(int FD);
20 int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
23 typedef struct sUserHandles
25 struct sUserHandles *Next;
27 tVFS_Handle Handles[MAX_USER_FILES];
31 tUserHandles *gpUserHandles = NULL;
32 tVFS_Handle gaKernelHandles[MAX_KERNEL_FILES];
36 * \fn tVFS_Handle *VFS_GetHandle(int FD)
37 * \brief Gets a pointer to the handle information structure
39 tVFS_Handle *VFS_GetHandle(int FD)
43 //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
45 if(FD < 0) return NULL;
47 if(FD & VFS_KERNEL_FLAG) {
48 FD &= (VFS_KERNEL_FLAG - 1);
49 if(FD >= MAX_KERNEL_FILES) return NULL;
50 h = &gaKernelHandles[ FD ];
54 int pid = Server_GetClientID();
55 for( ent = gpUserHandles; ent; ent = ent->Next ) {
56 if( ent->PID == pid ) break;
57 if( ent->PID > pid ) {
58 Log_Error("VFS", "PID %i does not have a handle list", pid);
63 Log_Error("VFS", "PID %i does not have a handle list", pid);
66 if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL;
67 h = &ent->Handles[ FD ];
70 if(h->Node == NULL) return NULL;
71 //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
75 int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
79 // Check for a user open
82 tUserHandles *ent, *prev = NULL;
83 int pid = Server_GetClientID();
84 for( ent = gpUserHandles; ent; prev = ent, ent = ent->Next ) {
85 if( ent->PID == pid ) break;
86 if( ent->PID > pid ) break;
88 if( !ent || ent->PID > pid ) {
89 ent = calloc( 1, sizeof(tUserHandles) );
92 ent->Next = prev->Next;
96 ent->Next = gpUserHandles;
101 for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
103 if(ent->Handles[i].Node) continue;
104 ent->Handles[i].Node = Node;
105 ent->Handles[i].Position = 0;
106 ent->Handles[i].Mode = Mode;
113 for(i=0;i<MAX_KERNEL_FILES;i++)
115 if(gaKernelHandles[i].Node) continue;
116 gaKernelHandles[i].Node = Node;
117 gaKernelHandles[i].Position = 0;
118 gaKernelHandles[i].Mode = Mode;
119 return i|VFS_KERNEL_FLAG;