3 * - By John Hodge (thePowersGang)
6 * - High level actions that call the VFS
7 * # Kernel-space compiled
10 #include <disktool_common.h>
14 extern int NativeFS_Install(char **Arguments);
17 void DiskTool_Initialise(void) __attribute__((constructor(101)));
18 size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path);
19 int DiskTool_int_TranslateOpen(const char *File, int Mode);
22 void DiskTool_Initialise(void)
25 NativeFS_Install(NULL);
27 VFS_Mount("/", "/Native", "nativefs", "");
30 int DiskTool_MountImage(const char *Identifier, const char *Path)
32 // Validate Identifier and make mountpoint string
33 char mountpoint[sizeof("/Mount/") + strlen(Identifier) + 1];
34 strcpy(mountpoint, "/Mount/");
35 strcat(mountpoint, Identifier);
38 size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path);
41 char tpath[tpath_len-1];
42 DiskTool_int_TranslatePath(tpath, Path);
45 // TODO: Detect filesystem?
46 return VFS_Mount(tpath, mountpoint, "fat", "");
49 int DiskTool_Copy(const char *Source, const char *Destination)
54 int DiskTool_ListDirectory(const char *Directory)
56 int fd = DiskTool_int_TranslateOpen(Directory, 2);
58 // fprintf(stderr, "Can't open '%s'\n", Directory);
62 printf("Directory listing of '%s'\n", Directory);
65 while( VFS_ReadDir(fd, name) )
75 // --- Internal helpers ---
76 size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path)
79 const char *colon = strchr(Path, ':');
83 for(pos = Path; pos < colon; pos ++)
89 len = strlen("/Mount/");
92 strcpy(Buffer, "/Mount/");
93 strncat(Buffer+strlen("/Mount/"), Path, colon - Path);
94 strcat(Buffer, colon + 1);
100 len = strlen("/Native");
101 len += strlen( getenv("PWD") ) + 1;
104 strcpy(Buffer, "/Native");
105 strcat(Buffer, getenv("PWD"));
107 strcat(Buffer, Path);
112 int DiskTool_int_TranslateOpen(const char *File, int Mode)
114 size_t tpath_len = DiskTool_int_TranslatePath(NULL, File);
117 char tpath[tpath_len-1];
118 DiskTool_int_TranslatePath(tpath, File);
120 // printf("Opening '%s'\n", tpath);
125 return VFS_Open(tpath, VFS_OPENFLAG_READ);
127 return VFS_Open(tpath, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE);
129 return VFS_Open(tpath, VFS_OPENFLAG_READ|VFS_OPENFLAG_EXEC);