2 * Acess2 Native Kernel
\r
3 * - Acess kernel emulation on another OS using SDL and UDP
\r
6 * - Host filesystem access
\r
9 #include <acess.h> // Acess
\r
10 #include <vfs.h> // Acess
\r
11 #include <dirent.h> // Posix
\r
12 #include <sys/stat.h> // Posix
\r
13 #include <stdio.h> // Posix
\r
16 // tVFS_Node->ImplPtr is a pointer to the filesystem flags (tNativeFS)
\r
17 // tVFS_Node->Data is the path string (heap string)
\r
18 // tVFS_Node->ImplInt is the path length
\r
20 // === STRUCTURES ===
\r
27 // === PROTOTYPES ===
\r
28 int NativeFS_Install(char **Arguments);
\r
29 tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments);
\r
30 void NativeFS_Unmount(tVFS_Node *Node);
\r
31 tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name);
\r
32 char *NativeFS_ReadDir(tVFS_Node *Node, int Position);
\r
33 Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
\r
36 tVFS_Driver gNativeFS_Driver = {
\r
38 NativeFS_Mount, NativeFS_Unmount,
\r
43 int NativeFS_Install(char **Arguments)
\r
45 VFS_AddDriver(&gNativeFS_Driver);
\r
49 tVFS_Node *NativeFS_Mount(const char *Device, const char **Arguments)
\r
55 dp = opendir(Device);
\r
56 if(!dp) return NULL;
\r
58 // Check if directory exists
\r
59 // Parse flags from arguments
\r
60 info = malloc(sizeof(tNativeFS));
\r
61 info->InodeHandle = Inode_GetHandle();
\r
62 info->bReadOnly = 0;
\r
64 ret = malloc(sizeof(tVFS_Node));
\r
65 memset(ret, 0, sizeof(tVFS_Node));
\r
66 ret->Data = strdup(Device);
\r
67 ret->ImplInt = strlen(ret->Data);
\r
68 ret->ImplPtr = info;
\r
69 ret->Inode = (Uint64)dp;
\r
71 ret->FindDir = NativeFS_FindDir;
\r
72 ret->ReadDir = NativeFS_ReadDir;
\r
77 void NativeFS_Unmount(tVFS_Node *Node)
\r
79 tNativeFS *info = Node->ImplPtr;
\r
80 Inode_ClearCache( info->InodeHandle );
\r
81 closedir( (void *)Node->Inode );
\r
87 void NativeFS_Close(tVFS_Node *Node)
\r
89 tNativeFS *info = Node->ImplPtr;
\r
90 Inode_UncacheNode( info->InodeHandle, Node->Inode );
\r
93 tVFS_Node *NativeFS_FindDir(tVFS_Node *Node, const char *Name)
\r
95 char *path = malloc(Node->ImplInt + 1 + strlen(Name) + 1);
\r
96 tNativeFS *info = Node->ImplPtr;
\r
98 struct stat statbuf;
\r
100 ENTER("pNode sName", Node, Name);
\r
103 strcpy(path, Node->Data);
\r
104 path[Node->ImplInt] = '/';
\r
105 strcpy(path + Node->ImplInt + 1, Name);
\r
107 LOG("path = '%s'", path);
\r
109 // Check if file exists
\r
110 if( stat(path, &statbuf) ) {
\r
112 LOG("Doesn't exist");
\r
117 memset(&baseRet, 0, sizeof(tVFS_Node));
\r
120 if( S_ISDIR(statbuf.st_mode) )
\r
123 baseRet.Inode = (Uint64) opendir(path);
\r
124 baseRet.FindDir = NativeFS_FindDir;
\r
125 baseRet.ReadDir = NativeFS_ReadDir;
\r
126 baseRet.Flags |= VFS_FFLAG_DIRECTORY;
\r
131 baseRet.Inode = (Uint64) fopen(path, "r+");
\r
132 baseRet.Read = NativeFS_Read;
\r
136 baseRet.ImplPtr = info;
\r
137 baseRet.ImplInt = strlen(path);
\r
138 baseRet.Data = path;
\r
141 return Inode_CacheNode(info->InodeHandle, &baseRet);
\r
144 char *NativeFS_ReadDir(tVFS_Node *Node, int Position)
\r
146 // Keep track of the current directory position
\r
150 Uint64 NativeFS_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
\r
152 ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
\r
153 if( fseek( (void *)Node->Inode, Offset, SEEK_SET ) != 0 )
\r
159 return fread( Buffer, 1, Length, (void *)Node->Inode );
\r