*/\r
#define DEBUG 1\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
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
-Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);\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
\r
// === GLOBALS ===\r
tVFS_NodeType gNativeFS_FileNodeType = {\r
- .Read = NativeFS_Read\r
+ .Read = NativeFS_Read,\r
+ .Write = NativeFS_Write,\r
+ .Close = NativeFS_Close\r
};\r
tVFS_NodeType gNativeFS_DirNodeType = {\r
.FindDir = NativeFS_FindDir,\r
.ReadDir = NativeFS_ReadDir,\r
+ .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
\r
dp = opendir(Device);\r
if(!dp) {\r
- Log_Warning("NativeFS", "ERRO: Unable to open device root '%s'", Device);\r
+ Log_Warning("NativeFS", "ERROR: Unable to open device root '%s'", Device);\r
return NULL;\r
}\r
\r
ret->Data = strdup(Device);\r
ret->ImplInt = strlen(ret->Data);\r
ret->ImplPtr = info;\r
- ret->Inode = (Uint64)dp;\r
+ ret->Inode = (Uint64)(tVAddr)dp;\r
+ ret->Flags = VFS_FFLAG_DIRECTORY;\r
\r
ret->Type = &gNativeFS_DirNodeType; \r
- \r
+\r
return ret;\r
}\r
\r
{\r
tNativeFS *info = Node->ImplPtr;\r
Inode_ClearCache( info->InodeHandle );\r
- closedir( (void *)Node->Inode );\r
+ closedir( (void *)(tVAddr)Node->Inode );\r
free(Node->Data);\r
free(Node);\r
free(info);\r
void NativeFS_Close(tVFS_Node *Node)\r
{\r
tNativeFS *info = Node->ImplPtr;\r
- Inode_UncacheNode( info->InodeHandle, Node->Inode );\r
+ DIR *dp = (Node->Flags & VFS_FFLAG_DIRECTORY) ? (DIR*)(tVAddr)Node->Inode : 0;\r
+ FILE *fp = (Node->Flags & VFS_FFLAG_DIRECTORY) ? 0 : (FILE*)(tVAddr)Node->Inode;\r
+ \r
+ if( Inode_UncacheNode( info->InodeHandle, Node->Inode ) == 1 ) {\r
+ if(dp) closedir(dp);\r
+ if(fp) fclose(fp);\r
+ }\r
}\r
\r
tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name)\r
{\r
- char *path = malloc(Node->ImplInt + 1 + strlen(Name) + 1);\r
+ char *path;\r
tNativeFS *info = Node->ImplPtr;\r
tVFS_Node baseRet;\r
struct stat statbuf;\r
ENTER("pNode sName", Node, Name);\r
\r
// Create path\r
+ path = malloc(Node->ImplInt + 1 + strlen(Name) + 1);\r
strcpy(path, Node->Data);\r
path[Node->ImplInt] = '/';\r
strcpy(path + Node->ImplInt + 1, Name);\r
if( S_ISDIR(statbuf.st_mode) )\r
{\r
LOG("Directory");\r
- baseRet.Inode = (Uint64) opendir(path);\r
+ baseRet.Inode = (Uint64)(tVAddr) opendir(path);\r
baseRet.Type = &gNativeFS_DirNodeType;\r
baseRet.Flags |= VFS_FFLAG_DIRECTORY;\r
baseRet.Size = -1;\r
else\r
{\r
LOG("File");\r
- baseRet.Inode = (Uint64) fopen(path, "r+");\r
+ baseRet.Inode = (Uint64)(tVAddr) fopen(path, "r+");\r
baseRet.Type = &gNativeFS_FileNodeType;\r
\r
fseek( (FILE*)(tVAddr)baseRet.Inode, 0, SEEK_END );\r
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
} 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
-Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)\r
+size_t NativeFS_Read(tVFS_Node *Node, _acess_off_t Offset, size_t Length, void *Buffer)\r
{\r
- ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);\r
- if( fseek( (void *)Node->Inode, Offset, SEEK_SET ) != 0 )\r
+ ENTER("pNode XOffset xLength pBuffer", Node, Offset, Length, Buffer);\r
+ if( fseek( (FILE *)(tVAddr)Node->Inode, Offset, SEEK_SET ) != 0 )\r
{\r
LEAVE('i', 0);\r
return 0;\r
}\r
LEAVE('-');\r
- return fread( Buffer, 1, Length, (void *)Node->Inode );\r
+ return fread( Buffer, 1, Length, (FILE *)(tVAddr)Node->Inode );\r
+}\r
+\r
+size_t NativeFS_Write(tVFS_Node *Node, _acess_off_t Offset, size_t Length, const void *Buffer)\r
+{\r
+ FILE *fp = (FILE *)(tVAddr)Node->Inode;\r
+ ENTER("pNode XOffset xLength pBuffer", Node, Offset, Length, Buffer);\r
+ if( fseek( fp, Offset, SEEK_SET ) != 0 )\r
+ {\r
+ LEAVE('i', 0);\r
+ return 0;\r
+ }\r
+ size_t ret = fwrite( Buffer, 1, Length, fp );\r
+ fflush( fp );\r
+ LEAVE('i', ret);\r
+ return ret;\r
+\r
}\r