Tools/nativelib - Many features implimented
[tpg/acess2.git] / Tools / NetTest / vfs_shim.c
1 /*
2  * Acess2 Networking Test Suite (NetTest)
3  * - By John Hodge (thePowersGang)
4  *
5  * vfs_shim.c
6  * - VFS Layer Emulation
7  */
8 #include <vfs.h>
9 #include <vfs_int.h>
10 #include <events.h>
11
12 // === CODE ===
13 int VFS_SelectNode(tVFS_Node *Node, int Type, tTime *Timeout, const char *Name)
14 {
15         
16         return 0;
17 }
18
19 int VFS_MarkAvaliable(tVFS_Node *Node, BOOL bAvail)
20 {
21         Node->DataAvaliable = bAvail;
22         if( Node->DataAvaliable && Node->ReadThreads )
23                 Threads_PostEvent( (void*)Node->ReadThreads, THREAD_EVENT_VFS );
24         return 0;
25 }
26
27 int VFS_MarkError(tVFS_Node *Node, BOOL bError)
28 {
29         Node->ErrorOccurred = bError;
30         if( Node->ErrorOccurred && Node->ErrorThreads )
31                 Threads_PostEvent( (void*)Node->ErrorThreads, THREAD_EVENT_VFS );
32         return 0;
33 }
34
35 #if 0
36 int VFS_Open(const char *Path, Uint Flags)
37 {
38         return -1;
39 }
40
41 void VFS_Close(int FD)
42 {
43 }
44 #endif
45
46 int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
47 {
48         const int maxfd = *Threads_GetMaxFD();
49         tVFS_Handle     *handles = *Threads_GetHandlesPtr();
50         if( !handles ) {
51                 handles = calloc( maxfd, sizeof(tVFS_Handle) );
52                 *Threads_GetHandlesPtr() = handles;
53         }
54
55         // TODO: Global handles
56
57         for( int i = 0; i < maxfd; i ++ )
58         {
59                 if( handles[i].Node == NULL ) {
60                         handles[i].Node = Node;
61                         handles[i].Mode = Mode;
62                         return i;
63                 }
64         }
65         return -1;
66 }
67
68 tVFS_Handle *VFS_GetHandle(int FD)
69 {
70         const int maxfd = *Threads_GetMaxFD();
71         tVFS_Handle     *handles = *Threads_GetHandlesPtr();
72         if( !handles )
73                 return NULL;
74
75         if( FD < 0 || FD >= maxfd )
76                 return NULL;
77
78         return &handles[FD];
79 }

UCC git Repository :: git.ucc.asn.au