d2d1d5fe5c45bb3cf3d0ff71816062edb25c1280
[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_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode)
14 {
15         const int maxfd = *Threads_GetMaxFD(NULL);
16         tVFS_Handle     *handles = *Threads_GetHandlesPtr();
17         if( !handles ) {
18                 handles = calloc( maxfd, sizeof(tVFS_Handle) );
19                 *Threads_GetHandlesPtr() = handles;
20         }
21
22         // TODO: Global handles
23
24         for( int i = 0; i < maxfd; i ++ )
25         {
26                 if( handles[i].Node == NULL ) {
27                         handles[i].Node = Node;
28                         handles[i].Mode = Mode;
29                         return i;
30                 }
31         }
32         return -1;
33 }
34
35 tVFS_Handle *VFS_GetHandle(int FD)
36 {
37         const int maxfd = *Threads_GetMaxFD(NULL);
38         tVFS_Handle     *handles = *Threads_GetHandlesPtr();
39         if( !handles )
40                 return NULL;
41
42         if( FD < 0 || FD >= maxfd )
43                 return NULL;
44
45         return &handles[FD];
46 }
47
48 int VFS_SetHandle(int FD, tVFS_Node *Node, int Mode)
49 {
50         const int maxfd = *Threads_GetMaxFD(NULL);
51         tVFS_Handle     *handles = *Threads_GetHandlesPtr();
52         if( !handles )
53                 return -1;
54
55         if( FD < 0 || FD >= maxfd )
56                 return -1;
57
58         handles[FD].Node = Node;
59         handles[FD].Mode = Mode;
60         return FD;
61 }

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