3 * - By John Hodge (thePowersGang)
6 * - High level actions that call the VFS
7 * # Kernel-space compiled
10 #include <disktool_common.h>
11 #include <Storage/LVM/include/lvm.h>
14 extern int NativeFS_Install(char **Arguments);
17 void DiskTool_Initialise(void) __attribute__((constructor(101)));
18 int DiskTool_int_TranslateOpen(const char *File, int Mode);
19 int DiskTook_LVM_Read(void *Handle, Uint64 Block, size_t BlockCount, void *Dest);
20 int DiskTook_LVM_Write(void *Handle, Uint64 Block, size_t BlockCount, const void *Dest);
23 tLVM_VolType gDiskTool_VolumeType = {
25 .Read = DiskTook_LVM_Read,
26 .Write = DiskTook_LVM_Write
30 void DiskTool_Initialise(void)
33 NativeFS_Install(NULL);
35 VFS_Mount("/", "/Native", "nativefs", "");
38 int DiskTool_RegisterLVM(const char *Identifier, const char *Path)
40 int fd = DiskTool_int_TranslateOpen(Path, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE);
43 VFS_Seek(fd, 0, SEEK_END);
44 LVM_AddVolume( &gDiskTool_VolumeType, Identifier, (void*)(tVAddr)fd, 512, VFS_Tell(fd)/512);
48 int DiskTool_MountImage(const char *Identifier, const char *Path)
50 // Validate Identifier and make mountpoint string
51 char mountpoint[sizeof("/Mount/") + strlen(Identifier) + 1];
52 strcpy(mountpoint, "/Mount/");
53 strcat(mountpoint, Identifier);
56 size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path);
59 char tpath[tpath_len-1];
60 DiskTool_int_TranslatePath(tpath, Path);
63 // TODO: Detect filesystem?
64 return VFS_Mount(tpath, mountpoint, "fat", "");
67 int DiskTool_Copy(const char *Source, const char *Destination)
69 int src = DiskTool_int_TranslateOpen(Source, VFS_OPENFLAG_READ);
71 Log_Error("DiskTool", "Unable to open %s for reading", Source);
74 int dst = DiskTool_int_TranslateOpen(Destination, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_CREATE);
76 Log_Error("DiskTool", "Unable to open %s for writing", Destination);
82 size_t len, total = 0;
83 while( (len = VFS_Read(src, sizeof(buf), buf)) == sizeof(buf) ) {
84 VFS_Write(dst, len, buf);
87 VFS_Write(dst, len, buf), total += len;
89 Log_Notice("DiskTool", "Copied %i from %s to %s", total, Source, Destination);
97 int DiskTool_ListDirectory(const char *Directory)
99 int fd = DiskTool_int_TranslateOpen(Directory, VFS_OPENFLAG_READ|VFS_OPENFLAG_DIRECTORY);
101 // fprintf(stderr, "Can't open '%s'\n", Directory);
105 Log("Directory listing of '%s'", Directory);
108 while( VFS_ReadDir(fd, name) )
118 int DiskTook_LVM_Read(void *Handle, Uint64 Block, size_t BlockCount, void *Dest)
120 VFS_ReadAt( (int)(tVAddr)Handle, Block*512, BlockCount*512, Dest);
123 int DiskTook_LVM_Write(void *Handle, Uint64 Block, size_t BlockCount, const void *Dest)
125 VFS_WriteAt( (int)(tVAddr)Handle, Block*512, BlockCount*512, Dest);
129 // --- Internal helpers ---
130 int DiskTool_int_TranslateOpen(const char *File, int Flags)
132 size_t tpath_len = DiskTool_int_TranslatePath(NULL, File);
135 char tpath[tpath_len-1];
136 DiskTool_int_TranslatePath(tpath, File);
138 return VFS_Open(tpath, Flags);