X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Tools%2FNetTest%2Fvfs_shim.c;h=d2d1d5fe5c45bb3cf3d0ff71816062edb25c1280;hb=d7dcea0e5a8df0f479e99f168a10b9a9535c7ad6;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=c3b821ccc009ec819f2580a53c0ed423aad43bf9;p=tpg%2Facess2.git diff --git a/Tools/NetTest/vfs_shim.c b/Tools/NetTest/vfs_shim.c index e69de29b..d2d1d5fe 100644 --- a/Tools/NetTest/vfs_shim.c +++ b/Tools/NetTest/vfs_shim.c @@ -0,0 +1,61 @@ +/* + * Acess2 Networking Test Suite (NetTest) + * - By John Hodge (thePowersGang) + * + * vfs_shim.c + * - VFS Layer Emulation + */ +#include +#include +#include + +// === CODE === +int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) +{ + const int maxfd = *Threads_GetMaxFD(NULL); + tVFS_Handle *handles = *Threads_GetHandlesPtr(); + if( !handles ) { + handles = calloc( maxfd, sizeof(tVFS_Handle) ); + *Threads_GetHandlesPtr() = handles; + } + + // TODO: Global handles + + for( int i = 0; i < maxfd; i ++ ) + { + if( handles[i].Node == NULL ) { + handles[i].Node = Node; + handles[i].Mode = Mode; + return i; + } + } + return -1; +} + +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]; +} + +int VFS_SetHandle(int FD, tVFS_Node *Node, int Mode) +{ + 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; +}