X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fnativefs.c;h=0e791b8fe49167cf6154d4ceb8cb5839758f2bef;hb=d047958aaade97d65ed5d5ca6c3835c2699e1010;hp=4fc0f31553ec020ab56b9391440edc25e4ecd00e;hpb=74c10f8633b8d738b60ad3b6439b18bbe211ab86;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c index 4fc0f315..0e791b8f 100644 --- a/AcessNative/acesskernel_src/nativefs.c +++ b/AcessNative/acesskernel_src/nativefs.c @@ -31,23 +31,26 @@ typedef struct tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments); void NativeFS_Unmount(tVFS_Node *Node); tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name); -char *NativeFS_ReadDir(tVFS_Node *Node, int Position); + int NativeFS_ReadDir(tVFS_Node *Node, int Position, char Dest[FILENAME_MAX]); size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer); size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer); +void NativeFS_Close(tVFS_Node *Node); // === GLOBALS === tVFS_NodeType gNativeFS_FileNodeType = { .Read = NativeFS_Read, .Write = NativeFS_Write, + .Close = NativeFS_Close }; tVFS_NodeType gNativeFS_DirNodeType = { .FindDir = NativeFS_FindDir, .ReadDir = NativeFS_ReadDir, + .Close = NativeFS_Close }; tVFS_Driver gNativeFS_Driver = { - "nativefs", 0, - NativeFS_Mount, NativeFS_Unmount, - NULL, + .Name = "nativefs", + .InitDevice = NativeFS_Mount, + .Unmount = NativeFS_Unmount }; // === CODE === @@ -101,12 +104,18 @@ void NativeFS_Unmount(tVFS_Node *Node) void NativeFS_Close(tVFS_Node *Node) { tNativeFS *info = Node->ImplPtr; - Inode_UncacheNode( info->InodeHandle, Node->Inode ); + DIR *dp = (Node->Flags & VFS_FFLAG_DIRECTORY) ? (DIR*)(tVAddr)Node->Inode : 0; + FILE *fp = (Node->Flags & VFS_FFLAG_DIRECTORY) ? 0 : (FILE*)(tVAddr)Node->Inode; + + if( Inode_UncacheNode( info->InodeHandle, Node->Inode ) == 1 ) { + if(dp) closedir(dp); + if(fp) fclose(fp); + } } tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) { - char *path = malloc(Node->ImplInt + 1 + strlen(Name) + 1); + char *path; tNativeFS *info = Node->ImplPtr; tVFS_Node baseRet; struct stat statbuf; @@ -114,6 +123,7 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) ENTER("pNode sName", Node, Name); // Create path + path = malloc(Node->ImplInt + 1 + strlen(Name) + 1); strcpy(path, Node->Data); path[Node->ImplInt] = '/'; strcpy(path + Node->ImplInt + 1, Name); @@ -158,11 +168,10 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) return Inode_CacheNode(info->InodeHandle, &baseRet); } -char *NativeFS_ReadDir(tVFS_Node *Node, int Position) +int NativeFS_ReadDir(tVFS_Node *Node, int Position, char Dest[FILENAME_MAX]) { struct dirent *ent; DIR *dp = (void*)(tVAddr)Node->Inode; - char *ret; ENTER("pNode iPosition", Node, Position); @@ -174,16 +183,16 @@ char *NativeFS_ReadDir(tVFS_Node *Node, int Position) } while(Position-- && ent); if( !ent ) { - LEAVE('n'); - return NULL; + LEAVE('i', -ENOENT); + return -ENOENT; } - ret = strdup(ent->d_name); + strncpy(Dest, ent->d_name, FILENAME_MAX); // TODO: Unlock node - LEAVE('s', ret); - return ret; + LEAVE('i', 0); + return 0; } size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer)