X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fnativefs.c;h=e603c26b123370b6b0be94a7d67dfb4cd9d00dd0;hb=7b64f5e7f00e445a5637e9e3289a1332a14d28e5;hp=7c20b69e0d55e10cf8b4f37aa8b4e610e0b07f5e;hpb=3a8670fa06b6be062caead81737848fcb01b0c60;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/nativefs.c b/AcessNative/acesskernel_src/nativefs.c index 7c20b69e..e603c26b 100644 --- a/AcessNative/acesskernel_src/nativefs.c +++ b/AcessNative/acesskernel_src/nativefs.c @@ -7,12 +7,14 @@ */ #define DEBUG 0 #define off_t _acess_off_t +#define sprintf _acess_sprintf #include // Acess #include // Acess #undef off_t +#undef sprintf #include // Posix #include // Posix -#include // Posix +#include // C //NOTES: // tVFS_Node->ImplPtr is a pointer to the filesystem flags (tNativeFS) @@ -22,7 +24,7 @@ // === STRUCTURES === typedef struct { - int InodeHandle; + void *InodeHandle; int bReadOnly; } tNativeFS; @@ -30,10 +32,11 @@ typedef struct int NativeFS_Install(char **Arguments); 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); -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); +tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags); + int NativeFS_ReadDir(tVFS_Node *Node, int Position, char Dest[FILENAME_MAX]); +tVFS_Node *NativeFS_MkNod(tVFS_Node *Node, const char *Name, Uint Flags); +size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer, Uint Flags); +size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer, Uint Flags); void NativeFS_Close(tVFS_Node *Node); // === GLOBALS === @@ -45,6 +48,7 @@ tVFS_NodeType gNativeFS_FileNodeType = { tVFS_NodeType gNativeFS_DirNodeType = { .FindDir = NativeFS_FindDir, .ReadDir = NativeFS_ReadDir, + .MkNod = NativeFS_MkNod, .Close = NativeFS_Close }; tVFS_Driver gNativeFS_Driver = { @@ -75,7 +79,7 @@ tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments) // Check if directory exists // Parse flags from arguments info = malloc(sizeof(tNativeFS)); - info->InodeHandle = Inode_GetHandle(); + info->InodeHandle = Inode_GetHandle(NULL); info->bReadOnly = 0; // Create node ret = malloc(sizeof(tVFS_Node)); @@ -113,7 +117,7 @@ void NativeFS_Close(tVFS_Node *Node) } } -tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) +tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags) { char *path; tNativeFS *info = Node->ImplPtr; @@ -152,11 +156,18 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name) else { LOG("File"); - baseRet.Inode = (Uint64)(tVAddr) fopen(path, "r+"); + FILE *fp = fopen(path, "r+"); + if( !fp ) { + Log_Error("NativeFS", "fopen of '%s' failed: %s", path, strerror(errno)); + free(path); + LEAVE('n'); + return NULL; + } + baseRet.Inode = (Uint64)(tVAddr) fp; baseRet.Type = &gNativeFS_FileNodeType; - fseek( (FILE*)(tVAddr)baseRet.Inode, 0, SEEK_END ); - baseRet.Size = ftell( (FILE*)(tVAddr)baseRet.Inode ); + fseek( fp, 0, SEEK_END ); + baseRet.Size = ftell( fp ); } // Create new node @@ -168,11 +179,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); @@ -184,19 +194,36 @@ 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; +} + +tVFS_Node *NativeFS_MkNod(tVFS_Node *Node, const char *Name, Uint Flags) +{ + char path[Node->ImplInt+1+strlen(Name)+1]; + sprintf(path, "%s/%s", Node->Data, Name); + if( Flags & VFS_FFLAG_DIRECTORY ) + { + mkdir(path, 0755); + } + else + { + FILE *tmp = fopen(path, "w"); + if(!tmp) return NULL; + fclose(tmp); + } + return NativeFS_FindDir(Node, Name, 0); } -size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer) +size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer, Uint Flags) { ENTER("pNode XOffset xLength pBuffer", Node, Offset, Length, Buffer); if( fseek( (FILE *)(tVAddr)Node->Inode, Offset, SEEK_SET ) != 0 ) @@ -204,11 +231,12 @@ size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void * LEAVE('i', 0); return 0; } - LEAVE('-'); - return fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode ); + size_t ret = fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode ); + LEAVE('x', ret); + return ret; } -size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer) +size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer, Uint Flags) { FILE *fp = (FILE *)(tVAddr)Node->Inode; ENTER("pNode XOffset xLength pBuffer", Node, Offset, Length, Buffer);