From: John Hodge Date: Fri, 13 Jul 2012 10:52:03 +0000 (+0800) Subject: DiskTool - Added LVM support X-Git-Tag: rel0.15~611^2~41^2~5 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=7378996995784940b371210bf7167628551a3486;p=tpg%2Facess2.git DiskTool - Added LVM support --- diff --git a/Tools/DiskTool/src/Makefile b/Tools/DiskTool/src/Makefile index def66213..b2325672 100644 --- a/Tools/DiskTool/src/Makefile +++ b/Tools/DiskTool/src/Makefile @@ -17,9 +17,9 @@ K_OBJ := lib.o K_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o K_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o # vfs/select.o K_OBJ += vfs/fs/root.o vfs/fs/devfs.o -K_OBJ += drv/proc.o +K_OBJ += drvutil_disk.o drv/proc.o # Modules -MODULES := Filesystems/FAT Filesystems/Ext2 +MODULES := Storage/LVM Filesystems/FAT Filesystems/Ext2 # Local kernel soruces (same as above, but located in same directory as Makefile) L_OBJ = vfs_handles.o threads.o nativefs.o time.o actions.o # Native Sources (compiled as usual) @@ -28,7 +28,7 @@ N_OBJ = main.o script.o logging.o helpers.o # Compilation Options CFLAGS := -Wall -std=gnu99 -g -Werror CPPFLAGS := -I include/ -K_CPPFLAGS := -I $(KERNEL_SRC)include +K_CPPFLAGS := -I $(KERNEL_SRC)include -I $(MODULE_SRC) LDFLAGS += -Wl,--defsym,__buildnum=$(BUILD_NUM) -g BUILDINFO_OBJ := obj/$(TARGET)/buildinfo.o diff --git a/Tools/DiskTool/src/actions.c b/Tools/DiskTool/src/actions.c index 6cbd7b85..43748d8f 100644 --- a/Tools/DiskTool/src/actions.c +++ b/Tools/DiskTool/src/actions.c @@ -8,6 +8,7 @@ */ #include #include +#include // === IMPORTS === extern int NativeFS_Install(char **Arguments); @@ -15,6 +16,15 @@ extern int NativeFS_Install(char **Arguments); // === PROTOTYPES === void DiskTool_Initialise(void) __attribute__((constructor(101))); int DiskTool_int_TranslateOpen(const char *File, int Mode); + int DiskTook_LVM_Read(void *Handle, Uint64 Block, size_t BlockCount, void *Dest); + int DiskTook_LVM_Write(void *Handle, Uint64 Block, size_t BlockCount, const void *Dest); + +// === GLOBALS === +tLVM_VolType gDiskTool_VolumeType = { + .Name = "DiskTool", + .Read = DiskTook_LVM_Read, + .Write = DiskTook_LVM_Write +}; // === CODE === void DiskTool_Initialise(void) @@ -25,6 +35,16 @@ void DiskTool_Initialise(void) VFS_Mount("/", "/Native", "nativefs", ""); } +int DiskTool_RegisterLVM(const char *Identifier, const char *Path) +{ + int fd = DiskTool_int_TranslateOpen(Path, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE); + if(fd == -1) + return -1; + VFS_Seek(fd, 0, SEEK_END); + LVM_AddVolume( &gDiskTool_VolumeType, Identifier, (void*)(tVAddr)fd, 512, VFS_Tell(fd)/512); + return 0; +} + int DiskTool_MountImage(const char *Identifier, const char *Path) { // Validate Identifier and make mountpoint string @@ -95,6 +115,17 @@ int DiskTool_ListDirectory(const char *Directory) return 0; } +int DiskTook_LVM_Read(void *Handle, Uint64 Block, size_t BlockCount, void *Dest) +{ + VFS_ReadAt( (int)(tVAddr)Handle, Block*512, BlockCount*512, Dest); + return 0; +} +int DiskTook_LVM_Write(void *Handle, Uint64 Block, size_t BlockCount, const void *Dest) +{ + VFS_WriteAt( (int)(tVAddr)Handle, Block*512, BlockCount*512, Dest); + return 0; +} + // --- Internal helpers --- int DiskTool_int_TranslateOpen(const char *File, int Flags) { diff --git a/Tools/DiskTool/src/helpers.c b/Tools/DiskTool/src/helpers.c index ddfe0f06..f3266775 100644 --- a/Tools/DiskTool/src/helpers.c +++ b/Tools/DiskTool/src/helpers.c @@ -19,6 +19,13 @@ size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path) { int len; const char *colon = strchr(Path, ':'); + + if( Path[0] == '#' ) + { + if(Buffer) + strcpy(Buffer, Path+1); + return strlen(Path) - 1; + } if( colon ) { diff --git a/Tools/DiskTool/src/include/disktool_common.h b/Tools/DiskTool/src/include/disktool_common.h index f6092558..d98d4201 100644 --- a/Tools/DiskTool/src/include/disktool_common.h +++ b/Tools/DiskTool/src/include/disktool_common.h @@ -8,6 +8,7 @@ #ifndef _INCLUDE__DISKTOOL_COMMON_H_ #define _INCLUDE__DISKTOOL_COMMON_H_ +extern int DiskTool_RegisterLVM(const char *Identifier, const char *Path); extern int DiskTool_MountImage(const char *Identifier, const char *Path); extern int DiskTool_Copy(const char *Source, const char *Destination); extern int DiskTool_ListDirectory(const char *Directory); diff --git a/Tools/DiskTool/src/main.c b/Tools/DiskTool/src/main.c index ff6f0ae1..58ce6d2e 100644 --- a/Tools/DiskTool/src/main.c +++ b/Tools/DiskTool/src/main.c @@ -29,6 +29,22 @@ int main(int argc, char *argv[]) continue ; } + if( strcmp("mountlvm", argv[i]) == 0 ) { + + if( argc - i < 3 ) { + fprintf(stderr, "mountlvm takes 2 arguments (ident and path)\n"); + exit(-1); + } + + if( DiskTool_RegisterLVM(argv[i+1], argv[i+2]) ) { + fprintf(stderr, "Unable to register '%s' as LVM '%s'\n", argv[i+2], argv[i+1]); + exit(-1); + } + + i += 2; + continue ; + } + if( strcmp("ls", argv[i]) == 0 ) { if( argc - i < 2 ) { fprintf(stderr, "ls 1 argument (path)\n"); @@ -53,6 +69,10 @@ int main(int argc, char *argv[]) continue ; } } + + // Unmount all + // Clear LVM + return 0; }