3 * - By John Hodge (thePowersGang)
6 * - High level actions that call the VFS
7 * # Kernel-space compiled
10 #include <disktool_common.h>
13 extern int NativeFS_Install(char **Arguments);
16 void DiskTool_Initialise(void) __attribute__((constructor(101)));
17 int DiskTool_int_TranslateOpen(const char *File, int Mode);
20 void DiskTool_Initialise(void)
23 NativeFS_Install(NULL);
25 VFS_Mount("/", "/Native", "nativefs", "");
28 int DiskTool_MountImage(const char *Identifier, const char *Path)
30 // Validate Identifier and make mountpoint string
31 char mountpoint[sizeof("/Mount/") + strlen(Identifier) + 1];
32 strcpy(mountpoint, "/Mount/");
33 strcat(mountpoint, Identifier);
36 size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path);
39 char tpath[tpath_len-1];
40 DiskTool_int_TranslatePath(tpath, Path);
43 // TODO: Detect filesystem?
44 return VFS_Mount(tpath, mountpoint, "fat", "");
47 int DiskTool_Copy(const char *Source, const char *Destination)
49 int src = DiskTool_int_TranslateOpen(Source, VFS_OPENFLAG_READ);
51 Log_Error("DiskTool", "Unable to open %s for reading", Source);
54 int dst = DiskTool_int_TranslateOpen(Destination, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_CREATE);
56 Log_Error("DiskTool", "Unable to open %s for writing", Destination);
62 size_t len, total = 0;
63 while( (len = VFS_Read(src, sizeof(buf), buf)) == sizeof(buf) )
64 VFS_Write(dst, len, buf), total += len;
65 VFS_Write(dst, len, buf), total += len;
67 Log_Notice("DiskTool", "Copied %i from %s to %s", total, Source, Destination);
75 int DiskTool_ListDirectory(const char *Directory)
77 int fd = DiskTool_int_TranslateOpen(Directory, VFS_OPENFLAG_READ|VFS_OPENFLAG_DIRECTORY);
79 // fprintf(stderr, "Can't open '%s'\n", Directory);
83 Log("Directory listing of '%s'", Directory);
86 while( VFS_ReadDir(fd, name) )
96 // --- Internal helpers ---
97 int DiskTool_int_TranslateOpen(const char *File, int Flags)
99 size_t tpath_len = DiskTool_int_TranslatePath(NULL, File);
102 char tpath[tpath_len-1];
103 DiskTool_int_TranslatePath(tpath, File);
105 return VFS_Open(tpath, Flags);