3 * - AllocHandle, GetHandle
13 #define MAX_KERNEL_FILES 128
16 tVFS_Handle *VFS_GetHandle(int FD);
17 int VFS_AllocHandle(int FD, tVFS_Node *Node, int Mode);
20 tVFS_Handle *gaUserHandles = (void*)MM_PPD_VFS;
21 tVFS_Handle *gaKernelHandles = (void*)MM_KERNEL_VFS;
25 * \fn tVFS_Handle *VFS_GetHandle(int FD)
26 * \brief Gets a pointer to the handle information structure
28 tVFS_Handle *VFS_GetHandle(int FD)
32 //Log_Debug("VFS", "VFS_GetHandle: (FD=0x%x)", FD);
34 if(FD < 0) return NULL;
36 if(FD & VFS_KERNEL_FLAG) {
37 FD &= (VFS_KERNEL_FLAG - 1);
38 if(FD >= MAX_KERNEL_FILES) return NULL;
39 h = &gaKernelHandles[ FD ];
41 if(FD >= CFGINT(CFG_VFS_MAXFILES)) return NULL;
42 h = &gaUserHandles[ FD ];
45 if(h->Node == NULL) return NULL;
46 //Log_Debug("VFS", "VFS_GetHandle: RETURN %p", h);
50 int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
54 // Check for a user open
58 if( MM_GetPhysAddr( (Uint)gaUserHandles ) == 0 )
61 size = CFGINT(CFG_VFS_MAXFILES) * sizeof(tVFS_Handle);
62 for(addr = 0; addr < size; addr += 0x1000)
63 MM_Allocate( (Uint)gaUserHandles + addr );
64 memset( gaUserHandles, 0, size );
67 for(i=0;i<CFGINT(CFG_VFS_MAXFILES);i++)
69 if(gaUserHandles[i].Node) continue;
70 gaUserHandles[i].Node = node;
71 gaUserHandles[i].Position = 0;
72 gaUserHandles[i].Mode = Mode;
78 // Allocate space if not already
79 if( MM_GetPhysAddr( (Uint)gaKernelHandles ) == 0 )
82 size = MAX_KERNEL_FILES * sizeof(tVFS_Handle);
83 for(addr = 0; addr < size; addr += 0x1000)
84 MM_Allocate( (Uint)gaKernelHandles + addr );
85 memset( gaKernelHandles, 0, size );
88 for(i=0;i<MAX_KERNEL_FILES;i++)
90 if(gaKernelHandles[i].Node) continue;
91 gaKernelHandles[i].Node = node;
92 gaKernelHandles[i].Position = 0;
93 gaKernelHandles[i].Mode = Mode;
94 return i|VFS_KERNEL_FLAG;