AcessNative - Updates for recent changes
[tpg/acess2.git] / AcessNative / acesskernel_src / nativefs.c
index e51f286..1a07627 100644 (file)
@@ -7,9 +7,11 @@
  */\r
 #define DEBUG  0\r
 #define off_t  _acess_off_t\r
+#define sprintf _acess_sprintf\r
 #include <acess.h>     // Acess\r
 #include <vfs.h>       // Acess\r
 #undef off_t\r
+#undef sprintf\r
 #include <dirent.h>    // Posix\r
 #include <sys/stat.h>  // Posix\r
 #include <stdio.h>     // Posix\r
@@ -22,7 +24,7 @@
 // === STRUCTURES ===\r
 typedef struct\r
 {\r
-        int    InodeHandle;\r
+       void    *InodeHandle;\r
         int    bReadOnly;\r
 }      tNativeFS;\r
 \r
@@ -30,10 +32,10 @@ typedef struct
  int   NativeFS_Install(char **Arguments);\r
 tVFS_Node      *NativeFS_Mount(const char *Device, const char **Arguments);\r
 void   NativeFS_Unmount(tVFS_Node *Node);\r
-tVFS_Node      *NativeFS_FindDir(tVFS_Node *Node, const char *Name);\r
-char   *NativeFS_ReadDir(tVFS_Node *Node, int Position);\r
-size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer);\r
-size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer);\r
+tVFS_Node      *NativeFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags);\r
+ int   NativeFS_ReadDir(tVFS_Node *Node, int Position, char Dest[FILENAME_MAX]);\r
+size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer, Uint Flags);\r
+size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer, Uint Flags);\r
 void   NativeFS_Close(tVFS_Node *Node);\r
 \r
 // === GLOBALS ===\r
@@ -48,9 +50,9 @@ tVFS_NodeType gNativeFS_DirNodeType = {
        .Close = NativeFS_Close\r
 };\r
 tVFS_Driver    gNativeFS_Driver = {\r
-       "nativefs", 0,\r
-       NativeFS_Mount, NativeFS_Unmount,\r
-       NULL,\r
+       .Name = "nativefs",\r
+       .InitDevice = NativeFS_Mount,\r
+       .Unmount = NativeFS_Unmount\r
 };\r
 \r
 // === CODE ===\r
@@ -75,7 +77,7 @@ tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments)
        // Check if directory exists\r
        // Parse flags from arguments\r
        info = malloc(sizeof(tNativeFS));\r
-       info->InodeHandle = Inode_GetHandle();\r
+       info->InodeHandle = Inode_GetHandle(NULL);\r
        info->bReadOnly = 0;\r
        // Create node\r
        ret = malloc(sizeof(tVFS_Node));\r
@@ -113,7 +115,7 @@ void NativeFS_Close(tVFS_Node *Node)
        }\r
 }\r
 \r
-tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name)\r
+tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name, Uint Flags)\r
 {\r
        char    *path;\r
        tNativeFS       *info = Node->ImplPtr;\r
@@ -152,11 +154,18 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name)
        else\r
        {\r
                LOG("File");\r
-               baseRet.Inode = (Uint64)(tVAddr) fopen(path, "r+");\r
+               FILE    *fp = fopen(path, "r+");\r
+               if( !fp ) {\r
+                       Log_Error("NativeFS", "fopen of '%s' failed: %s", path, strerror(errno));\r
+                       free(path);\r
+                       LEAVE('n');\r
+                       return NULL;\r
+               }\r
+               baseRet.Inode = (Uint64)(tVAddr) fp;\r
                baseRet.Type = &gNativeFS_FileNodeType;\r
                \r
-               fseek( (FILE*)(tVAddr)baseRet.Inode, 0, SEEK_END );\r
-               baseRet.Size = ftell( (FILE*)(tVAddr)baseRet.Inode );\r
+               fseek( fp, 0, SEEK_END );\r
+               baseRet.Size = ftell( fp );\r
        }\r
        \r
        // Create new node\r
@@ -168,11 +177,10 @@ tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name)
        return Inode_CacheNode(info->InodeHandle, &baseRet);\r
 }\r
 \r
-char *NativeFS_ReadDir(tVFS_Node *Node, int Position)\r
+int NativeFS_ReadDir(tVFS_Node *Node, int Position, char Dest[FILENAME_MAX])\r
 {\r
        struct dirent   *ent;\r
        DIR     *dp = (void*)(tVAddr)Node->Inode;\r
-       char    *ret;\r
 \r
        ENTER("pNode iPosition", Node, Position);\r
 \r
@@ -184,19 +192,19 @@ char *NativeFS_ReadDir(tVFS_Node *Node, int Position)
        } while(Position-- && ent);\r
 \r
        if( !ent ) {\r
-               LEAVE('n');\r
-               return NULL;\r
+               LEAVE('i', -ENOENT);\r
+               return -ENOENT;\r
        }\r
        \r
-       ret = strdup(ent->d_name);\r
+       strncpy(Dest, ent->d_name, FILENAME_MAX);\r
 \r
        // TODO: Unlock node    \r
 \r
-       LEAVE('s', ret);\r
-       return ret;\r
+       LEAVE('i', 0);\r
+       return 0;\r
 }\r
 \r
-size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer)\r
+size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer, Uint Flags)\r
 {\r
        ENTER("pNode XOffset xLength pBuffer", Node, Offset, Length, Buffer);\r
        if( fseek( (FILE *)(tVAddr)Node->Inode, Offset, SEEK_SET ) != 0 )\r
@@ -204,11 +212,12 @@ size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *
                LEAVE('i', 0);\r
                return 0;\r
        }\r
-       LEAVE('-');\r
-       return fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode );\r
+       size_t ret = fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode );\r
+       LEAVE('x', ret);\r
+       return ret;\r
 }\r
 \r
-size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer)\r
+size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer, Uint Flags)\r
 {\r
        FILE    *fp = (FILE *)(tVAddr)Node->Inode;\r
        ENTER("pNode XOffset xLength pBuffer", Node, Offset, Length, Buffer);\r

UCC git Repository :: git.ucc.asn.au