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
KERNEL_SRC = ../../../KernelLand/Kernel/
+MODULE_SRC = ../../../KernelLand/Modules/
BIN = ../DiskTool
# Kernel Sources (compiled with -ffreestanding)
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)
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)
@$(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
[email protected]
+
$(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
[email protected]
$(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
[email protected]
$(N_OBJ): $(OBJ_PREFIX)%.o: %.c
--- /dev/null
+/*
+ * Acess2 DiskTool
+ * - By John Hodge (thePowersGang)
+ *
+ * actions.c
+ * - High level actions that call the VFS
+ * # Kernel-space compiled
+ */
+#include <acess.h>
+#include <disktool_common.h>
+#include <ctype.h>
+
+// === 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;
+}
+
--- /dev/null
+/*
+ * 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
+
#include <acess_logging.h>
#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 ===
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";
#include <errno.h>
#include <stdint.h>
#include <string.h>
+#include <disktool_common.h>
// === 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;
}