#include <events.h>
// === CODE ===
-int VFS_SelectNode(tVFS_Node *Node, int Type, tTime *Timeout, const char *Name)
+int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
{
-
- return 0;
-}
+ const int maxfd = *Threads_GetMaxFD(NULL);
+ tVFS_Handle *handles = *Threads_GetHandlesPtr();
+ if( !handles ) {
+ handles = calloc( maxfd, sizeof(tVFS_Handle) );
+ *Threads_GetHandlesPtr() = handles;
+ }
-int VFS_MarkAvaliable(tVFS_Node *Node, BOOL bAvail)
-{
- Node->DataAvaliable = bAvail;
- if( Node->DataAvaliable && Node->ReadThreads )
- Threads_PostEvent( (void*)Node->ReadThreads, THREAD_EVENT_VFS );
- return 0;
-}
+ // TODO: Global handles
-int VFS_MarkError(tVFS_Node *Node, BOOL bError)
-{
- Node->ErrorOccurred = bError;
- if( Node->ErrorOccurred && Node->ErrorThreads )
- Threads_PostEvent( (void*)Node->ErrorThreads, THREAD_EVENT_VFS );
- return 0;
-}
-
-int VFS_Open(const char *Path, Uint Flags)
-{
+ for( int i = 0; i < maxfd; i ++ )
+ {
+ if( handles[i].Node == NULL ) {
+ handles[i].Node = Node;
+ handles[i].Mode = Mode;
+ return i;
+ }
+ }
return -1;
}
-void VFS_Close(int FD)
+tVFS_Handle *VFS_GetHandle(int FD)
{
+ const int maxfd = *Threads_GetMaxFD(NULL);
+ tVFS_Handle *handles = *Threads_GetHandlesPtr();
+ if( !handles )
+ return NULL;
+
+ if( FD < 0 || FD >= maxfd )
+ return NULL;
+
+ return &handles[FD];
}
-tVFS_Handle *VFS_GetHandle(int FD)
+int VFS_SetHandle(int FD, tVFS_Node *Node, int Mode)
{
- return NULL;
-}
+ const int maxfd = *Threads_GetMaxFD(NULL);
+ tVFS_Handle *handles = *Threads_GetHandlesPtr();
+ if( !handles )
+ return -1;
+
+ if( FD < 0 || FD >= maxfd )
+ return -1;
+ handles[FD].Node = Node;
+ handles[FD].Mode = Mode;
+ return FD;
+}