3 * - AllocHandle, GetHandle
12 #define MAX_KERNEL_FILES 128
13 #define MAX_USER_FILES 64
16 tVFS_Handle *VFS_GetHandle(int FD);
17 int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
19 typedef struct sUserHandles
21 struct sUserHandles *Next;
23 tVFS_Handle Handles[MAX_USER_FILES];
27 tUserHandles *gpUserHandles = NULL;
28 tVFS_Handle gaKernelHandles[MAX_KERNEL_FILES];
32 * \fn tVFS_Handle *VFS_GetHandle(int FD)
33 * \brief Gets a pointer to the handle information structure
35 tVFS_Handle *VFS_GetHandle(int FD)
39 //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
41 if(FD < 0) return NULL;
43 if(FD & VFS_KERNEL_FLAG) {
44 FD &= (VFS_KERNEL_FLAG - 1);
45 if(FD >= MAX_KERNEL_FILES) return NULL;
46 h = &gaKernelHandles[ FD ];
50 int pid = Threads_GetPID();
51 for( ent = gpUserHandles; ent; ent = ent->Next ) {
52 if( ent->PID == pid ) break;
53 if( ent->PID > pid ) {
54 Log_Error("VFS", "PID %i does not have a handle list", pid);
58 if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL;
59 h = &ent->Handles[ FD ];
62 if(h->Node == NULL) return NULL;
63 //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
67 int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
71 // Check for a user open
74 tUserHandles *ent, *prev;
75 int pid = Threads_GetPID();
76 for( ent = gpUserHandles; ent; prev = ent, ent = ent->Next ) {
77 if( ent->PID == pid ) break;
78 if( ent->PID > pid ) break;
80 if( ent->PID > pid ) {
81 ent = calloc( 1, sizeof(tUserHandles) );
83 ent->Next = prev->Next;
87 ent->Next = gpUserHandles;
92 for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
94 if(ent->Handles[i].Node) continue;
95 ent->Handles[i].Node = Node;
96 ent->Handles[i].Position = 0;
97 ent->Handles[i].Mode = Mode;
104 for(i=0;i<MAX_KERNEL_FILES;i++)
106 if(gaKernelHandles[i].Node) continue;
107 gaKernelHandles[i].Node = Node;
108 gaKernelHandles[i].Position = 0;
109 gaKernelHandles[i].Mode = Mode;
110 return i|VFS_KERNEL_FLAG;