AcessNative - Better error reporting in NativeFS
[tpg/acess2.git] / AcessNative / acesskernel_src / nativefs.c
index 7c20b69..65e874d 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
@@ -31,7 +33,7 @@ typedef struct
 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
+ 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);\r
 size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer);\r
 void   NativeFS_Close(tVFS_Node *Node);\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,16 +192,16 @@ 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
@@ -204,8 +212,9 @@ 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

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