X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fnativefs.c;h=864a24bc07622f734780d61fa2f70a754ead0916;hb=6d32a3c22e659994d7ae6164ba3722ab12d11421;hp=6d6e2fedd6a60ceaea9d3d06b90b0090341f2e20;hpb=3764c294f21229bdf700f436fa4884f5e76e0d3a;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c index 6d6e2fed..864a24bc 100644 --- a/AcessNative/acesskernel_src/nativefs.c +++ b/AcessNative/acesskernel_src/nativefs.c @@ -6,8 +6,10 @@ * - Host filesystem access */ #define DEBUG 1 +#define off_t _acess_off_t #include // Acess #include // Acess +#undef off_t #include // Posix #include // Posix #include // Posix @@ -33,6 +35,13 @@ char *NativeFS_ReadDir(tVFS_Node *Node, int Position); Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer); // === GLOBALS === +tVFS_NodeType gNativeFS_FileNodeType = { + .Read = NativeFS_Read +}; +tVFS_NodeType gNativeFS_DirNodeType = { + .FindDir = NativeFS_FindDir, + .ReadDir = NativeFS_ReadDir, +}; tVFS_Driver gNativeFS_Driver = { "nativefs", 0, NativeFS_Mount, NativeFS_Unmount, @@ -53,7 +62,10 @@ tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments) DIR *dp; dp = opendir(Device); - if(!dp) return NULL; + if(!dp) { + Log_Warning("NativeFS", "ERRO: Unable to open device root '%s'", Device); + return NULL; + } // Check if directory exists // Parse flags from arguments @@ -67,9 +79,8 @@ tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments) ret->ImplInt = strlen(ret->Data); ret->ImplPtr = info; ret->Inode = (Uint64)dp; - - ret->FindDir = NativeFS_FindDir; - ret->ReadDir = NativeFS_ReadDir; + + ret->Type = &gNativeFS_DirNodeType; return ret; } @@ -121,15 +132,18 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) { LOG("Directory"); baseRet.Inode = (Uint64) opendir(path); - baseRet.FindDir = NativeFS_FindDir; - baseRet.ReadDir = NativeFS_ReadDir; + baseRet.Type = &gNativeFS_DirNodeType; baseRet.Flags |= VFS_FFLAG_DIRECTORY; + baseRet.Size = -1; } else { LOG("File"); baseRet.Inode = (Uint64) fopen(path, "r+"); - baseRet.Read = NativeFS_Read; + baseRet.Type = &gNativeFS_FileNodeType; + + fseek( (FILE*)(tVAddr)baseRet.Inode, 0, SEEK_END ); + baseRet.Size = ftell( (FILE*)(tVAddr)baseRet.Inode ); } // Create new node @@ -143,8 +157,30 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) char *NativeFS_ReadDir(tVFS_Node *Node, int Position) { - // Keep track of the current directory position - return NULL; + struct dirent *ent; + DIR *dp = (void*)(tVAddr)Node->Inode; + char *ret; + + ENTER("pNode iPosition", Node, Position); + + // TODO: Keep track of current position in the directory + // TODO: Lock node during this + rewinddir(dp); + do { + ent = readdir(dp); + } while(Position-- && ent); + + if( !ent ) { + LEAVE('n'); + return NULL; + } + + ret = strdup(ent->d_name); + + // TODO: Unlock node + + LEAVE('s', ret); + return ret; } Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)