X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fnativefs.c;h=864a24bc07622f734780d61fa2f70a754ead0916;hb=cfe6a9f2a126cc26ac74d5454e8378bd1193fcf8;hp=9de8ae2d280e9f845bd93116d66d89f9cde4c647;hpb=a4d8188f730bcc25cd4a6f4799ac7d65eb707cf2;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c index 9de8ae2d..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, @@ -70,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; } @@ -124,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 @@ -146,9 +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 - // TODO: Implement NativeFS_ReadDir - 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)