From: John Hodge Date: Mon, 9 Jul 2012 05:40:47 +0000 (+0800) Subject: DiskTool - Adding action interface, module loading (for filesystems) X-Git-Tag: rel0.15~611^2~41^2~27 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=aa3975dc61be78c0e6860cafad7278017fd456d5;p=tpg%2Facess2.git DiskTool - Adding action interface, module loading (for filesystems) - TODO: Stub modules.h to perform neat initialisation --- diff --git a/Tools/DiskTool/src/Makefile b/Tools/DiskTool/src/Makefile index f7d72569..05811f79 100644 --- a/Tools/DiskTool/src/Makefile +++ b/Tools/DiskTool/src/Makefile @@ -1,7 +1,7 @@ TARGET := $(shell gcc -v 2>&1 | grep Targ | awk '{print $$2}') --include ../../Makefile.Version.cfg +include ../../../Makefile.Version.cfg -include Makefile.BuildNum ifeq ($(BUILD_NUM),) BUILD_NUM = 1 @@ -9,6 +9,7 @@ endif KERNEL_SRC = ../../../KernelLand/Kernel/ +MODULE_SRC = ../../../KernelLand/Modules/ BIN = ../DiskTool # Kernel Sources (compiled with -ffreestanding) @@ -16,13 +17,15 @@ 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 +# Modules +MODULES := 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 +L_OBJ = vfs_handles.o threads.o nativefs.o time.o actions.o # Native Sources (compiled as usual) N_OBJ = main.o script.o logging.o # Compilation Options -CFLAGS := -Wall +CFLAGS := -Wall -std=gnu99 CPPFLAGS := -I include/ K_CPPFLAGS := -I $(KERNEL_SRC)include LDFLAGS += -Wl,--defsym,__buildnum=$(BUILD_NUM) @@ -30,14 +33,22 @@ LDFLAGS += -Wl,--defsym,__buildnum=$(BUILD_NUM) BUILDINFO_OBJ := obj/$(TARGET)/buildinfo.o BUILDINFO_SRC := $(BUILDINFO_OBJ:%.o=%.c) +# ==================== # == Start of Magic == +# ==================== +# -- Load modules --- +$(foreach module,$(MODULES), $(eval include $(MODULE_SRC)$(module)/Makefile) $(eval M_OBJ += $(addprefix $(module)/,$(OBJ))) ) + +# -- Apply Prefixes to object paths OBJ_PREFIX = obj/$(TARGET)/ K_OBJ_PREFIX = $(OBJ_PREFIX)_Kernel/ +M_OBJ_PREFIX = $(OBJ_PREFIX)_Module/ K_OBJ := $(addprefix $(K_OBJ_PREFIX),$(K_OBJ)) +M_OBJ := $(addprefix $(M_OBJ_PREFIX),$(M_OBJ)) L_OBJ := $(addprefix $(OBJ_PREFIX),$(L_OBJ)) N_OBJ := $(addprefix $(OBJ_PREFIX),$(N_OBJ)) -OBJ := $(N_OBJ) $(L_OBJ) $(K_OBJ) $(BUILDINFO_OBJ) +OBJ := $(N_OBJ) $(L_OBJ) $(K_OBJ) $(M_OBJ) $(BUILDINFO_OBJ) DEPFILES = $(filter %.o,$(OBJ)) DEPFILES := $(DEPFILES:%=%.dep) @@ -55,14 +66,19 @@ $(BIN): $(OBJ) @$(CC) -o $(BIN) $(OBJ) $(LDFLAGS) @echo BUILD_NUM = $$(( $(BUILD_NUM) + 1 )) > Makefile.BuildNum +$(M_OBJ): $(M_OBJ_PREFIX)%.o: $(MODULE_SRC)%.c + @mkdir -p $(dir $@) + @echo [CC Module] -o $@ + @$(CC) -c $< -o $@ -ffreestanding $(CFLAGS) $(CPPFLAGS) $(K_CPPFLAGS) -MMD -MP -MF $@.dep + $(K_OBJ): $(K_OBJ_PREFIX)%.o: $(KERNEL_SRC)%.c @mkdir -p $(dir $@) - @echo [CC Acess] -o $@ + @echo [CC Kernel] -o $@ @$(CC) -c $< -o $@ -ffreestanding $(CFLAGS) $(CPPFLAGS) $(K_CPPFLAGS) -MMD -MP -MF $@.dep $(L_OBJ): $(OBJ_PREFIX)%.o: %.c @mkdir -p $(dir $@) - @echo [CC Acess] -o $@ + @echo [CC Local] -o $@ @$(CC) -c $< -o $@ -ffreestanding $(CFLAGS) $(CPPFLAGS) $(K_CPPFLAGS) -MMD -MP -MF $@.dep $(N_OBJ): $(OBJ_PREFIX)%.o: %.c diff --git a/Tools/DiskTool/src/actions.c b/Tools/DiskTool/src/actions.c new file mode 100644 index 00000000..d5c75ef3 --- /dev/null +++ b/Tools/DiskTool/src/actions.c @@ -0,0 +1,69 @@ +/* + * Acess2 DiskTool + * - By John Hodge (thePowersGang) + * + * actions.c + * - High level actions that call the VFS + * # Kernel-space compiled + */ +#include +#include +#include + +// === PROTOTYPES === +size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path); + int DiskTool_int_TranslateOpen(const char *File, int Mode); + +// === CODE === +int DiskTool_MountImage(const char *Identifier, const char *Path) +{ + // Validate Identifier and make mountpoint string + char mountpoint[sizeof("/Mount/") + strlen(Identifier) + 1]; + strcpy(mountpoint, "/Mount/"); + strcat(mountpoint, Identifier); + + // Translate path + size_t tpath_len = DiskTool_int_TranslatePath(NULL, Path); + if(tpath_len == -1) + return -1; + char tpath[tpath_len-1]; + DiskTool_int_TranslatePath(tpath, Path); + + // Call mount + // TODO: Detect filesystem? + return VFS_Mount(tpath, mountpoint, "fat", ""); +} + +int DiskTool_Copy(const char *Source, const char *Destination) +{ + return -1; +} + +// --- Internal helpers --- +size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path) +{ + const char *colon = strchr(Path, ':'); + if( colon ) + { + const char *pos; + for(pos = Path; pos < colon; pos ++) + { + if( !isalpha(*pos) ) + goto native_path; + } + + return -1; + } + +native_path: + if( Buffer ) + strcpy(Buffer, Path); + return strlen(Path); +} + +int DiskTool_int_TranslateOpen(const char *File, int Mode) +{ + // Determine if the source is a mounted image or a file on the source FS + return -1; +} + diff --git a/Tools/DiskTool/src/include/disktool_common.h b/Tools/DiskTool/src/include/disktool_common.h new file mode 100644 index 00000000..e36c3adf --- /dev/null +++ b/Tools/DiskTool/src/include/disktool_common.h @@ -0,0 +1,15 @@ +/* + * Acess2 DiskTool + * - By John Hodge (thePowersGang) + * + * include/disktool_common.h + * - DiskTool internal API between native and kernel code + */ +#ifndef _INCLUDE__DISKTOOL_COMMON_H_ +#define _INCLUDE__DISKTOOL_COMMON_H_ + +extern int DiskTool_MountImage(const char *Identifier, const char *Path); +extern int DiskTool_Copy(const char *Source, const char *Destination); + +#endif + diff --git a/Tools/DiskTool/src/include/modules.h b/Tools/DiskTool/src/include/modules.h new file mode 100644 index 00000000..e69de29b diff --git a/Tools/DiskTool/src/logging.c b/Tools/DiskTool/src/logging.c index 1517b65e..8f627f2d 100644 --- a/Tools/DiskTool/src/logging.c +++ b/Tools/DiskTool/src/logging.c @@ -7,11 +7,11 @@ #include #define PUTERR(col,type) {\ - fprintf(stderr, "\e["col"m[%8.8s]"type" ", Ident); \ + fprintf(stderr, "\e["col"m[%-8.8s]"type" ", Ident); \ va_list args; va_start(args, Message);\ vfprintf(stderr, Message, args);\ va_end(args);\ - fprintf(stderr, "\n"); \ + fprintf(stderr, "\e[0m\n"); \ } // === CODE === @@ -20,17 +20,17 @@ void Log_KernelPanic(const char *Ident, const char *Message, ...) { exit(-1); } void Log_Panic(const char *Ident, const char *Message, ...) - PUTERR("37", "p") + PUTERR("34", "p") void Log_Error(const char *Ident, const char *Message, ...) - PUTERR("32", "e") + PUTERR("31", "e") void Log_Warning(const char *Ident, const char *Message, ...) - PUTERR("34", "w") + PUTERR("33", "w") void Log_Notice(const char *Ident, const char *Message, ...) - PUTERR("33", "n") + PUTERR("32", "n") void Log_Log(const char *Ident, const char *Message, ...) - PUTERR("31", "l") + PUTERR("37", "l") void Log_Debug(const char *Ident, const char *Message, ...) - PUTERR("31", "d") + PUTERR("37", "d") void Warning(const char *Message, ...) { const char *Ident = "WARNING"; diff --git a/Tools/DiskTool/src/main.c b/Tools/DiskTool/src/main.c index bb9e9f24..7dd85833 100644 --- a/Tools/DiskTool/src/main.c +++ b/Tools/DiskTool/src/main.c @@ -5,11 +5,31 @@ #include #include #include +#include // === CODE === int main(int argc, char *argv[]) { - + // Setup + + // Parse arguments + for( int i = 1; i < argc; i ++ ) + { + if( strcmp("--image", argv[i]) == 0 || strcmp("-i", argv[i]) == 0 ) { + // Mount an image + if( argc - i < 3 ) { + fprintf(stderr, "--image/-i takes 2 arguments (ident and path)\n"); + exit(-1); + } + + if( DiskTool_MountImage(argv[i+1], argv[i+2]) ) { + fprintf(stderr, "Unable to mount '%s' as '%s'\n", argv[i+2], argv[i+1]); + exit(-1); + } + + i += 2; + } + } return 0; }