From: John Hodge Date: Fri, 6 Jul 2012 08:31:10 +0000 (+0800) Subject: DiskTool - Side project to use the VFS for image manipulation X-Git-Tag: rel0.15~611^2~41^2~31 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3f76cec1a9c81a0ac06f0c64aa34ea7f3de9558a;p=tpg%2Facess2.git DiskTool - Side project to use the VFS for image manipulation --- diff --git a/Tools/DiskTool/src/Makefile b/Tools/DiskTool/src/Makefile new file mode 100644 index 00000000..150cdbae --- /dev/null +++ b/Tools/DiskTool/src/Makefile @@ -0,0 +1,57 @@ + +TARGET := $(shell gcc -v 2>&1 | grep Targ | awk '{print $$2}') + +KERNEL_SRC = ../../../KernelLand/Kernel/ + +BIN = ../DiskTool +# Kernel Sources (compiled with -ffreestanding) +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 +# Local kernel soruces (same as above, but located in same directory as Makefile) +L_OBJ = vfs_handles.o threads.o nativefs.o +# Native Sources (compiled as usual) +N_OBJ = main.o script.o logging.o + +# Compilation Options +CFLAGS := -Wall +CPPFLAGS := -I include/ +K_CPPFLAGS := -I $(KERNEL_SRC)include + +# == Start of Magic == +OBJ_PREFIX = obj/$(TARGET)/ +K_OBJ_PREFIX = $(OBJ_PREFIX)_Kernel/ +K_OBJ := $(addprefix $(K_OBJ_PREFIX),$(K_OBJ)) +L_OBJ := $(addprefix $(OBJ_PREFIX),$(L_OBJ)) +N_OBJ := $(addprefix $(OBJ_PREFIX),$(N_OBJ)) + +OBJ := $(N_OBJ) $(L_OBJ) $(K_OBJ) + +DEPFILES = $(filter %.o,$(OBJ)) +DEPFILES := $(DEPFILES:%=%.dep) + + +.PHONY: all clean + +all: $(BIN) + +clean: + $(RM) -f $(OBJ) $(DEPFILES) $(BIN) + +$(BIN): $(OBJ) + $(CC) -o $(BIN) $(OBJ) $(LDFLAGS) + +$(K_OBJ): $(K_OBJ_PREFIX)%.o: $(KERNEL_SRC)%.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ -ffreestanding $(CFLAGS) $(CPPFLAGS) $(K_CPPFLAGS) -MMD -MP -MF $@.dep + +$(L_OBJ): $(OBJ_PREFIX)%.o: %.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ -ffreestanding $(CFLAGS) $(CPPFLAGS) $(K_CPPFLAGS) -MMD -MP -MF $@.dep + +$(N_OBJ): $(OBJ_PREFIX)%.o: %.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep + +-include $(DEPFILES) diff --git a/Tools/DiskTool/src/include/acess.h b/Tools/DiskTool/src/include/acess.h new file mode 100644 index 00000000..ec319f21 --- /dev/null +++ b/Tools/DiskTool/src/include/acess.h @@ -0,0 +1,103 @@ +/* + * Acess2 DiskTool utility + * - By John Hodge (thePowersGang) + * + * include/acess.h + * - Mock kernel core header + */ +#ifndef _DISKTOOL__ACESS_H_ +#define _DISKTOOL__ACESS_H_ + +#define CONCAT(x,y) x ## y +#define EXPAND_CONCAT(x,y) CONCAT(x,y) +#define STR(x) #x +#define EXPAND_STR(x) STR(x) + +extern char __buildnum[]; +#define BUILD_NUM ((int)(Uint)&__buildnum) +extern const char gsGitHash[]; + +#define BITS 32 +#define NULL ((void*)0) +#include + +typedef uintptr_t Uint; +typedef unsigned int size_t; +typedef uint64_t off_t; +typedef char BOOL; + + +typedef uint8_t Uint8; +typedef uint16_t Uint16; +typedef uint32_t Uint32; +typedef uint64_t Uint64; + +typedef int8_t Sint8; +typedef int16_t Sint16; +typedef int32_t Sint32; +typedef int64_t Sint64; + +typedef uintptr_t tVAddr; +typedef uint32_t tPAddr; + +typedef uint32_t tUID; +typedef uint32_t tGID; +typedef uint32_t tTID; + +// NOTE: Since this is single-threaded (for now) mutexes can be implimented as simple locks +typedef char tMutex; +typedef char tShortSpinlock; + +typedef int64_t tTime; + +#define PACKED __attribute__((packed)) +#define DEPRECATED +#define EXPORT(s) +#define EXPORTV(s) + +#include + +// These are actually library functions, but they can't be included, so they're defined manually +extern void *malloc(size_t bytes); +extern void *calloc(size_t nmemb, size_t size); +extern void *realloc(void *oldptr, size_t bytes); +extern void free(void *buffer); + +#include + +#include + +// Threads +extern int *Threads_GetErrno(void); +//extern tPGID Threads_GetPGID(void); +//extern tPID Threads_GetPID(void); +extern tTID Threads_GetTID(void); +extern tUID Threads_GetUID(void); +extern tGID Threads_GetGID(void); + +// Kinda hacky way of not colliding with native errno +#define errno (*(Threads_GetErrno())) + +#include + + +#define ENTER(...) do{}while(0) +#define LOG(...) do{}while(0) +#define LEAVE(...) do{}while(0) +#define LEAVE_RET(t,v) return v; + +static inline int Mutex_Acquire(tMutex *m) { + if(*m) Log_KernelPanic("---", "Double mutex lock"); + *m = 1; + return 0; +} +static inline void Mutex_Release(tMutex *m) { *m = 0; } + +static inline void SHORTLOCK(tShortSpinlock *Lock) { + if(*Lock) Log_KernelPanic("---", "Double short lock"); + *Lock = 1; +} +static inline void SHORTREL(tShortSpinlock *m) { *m = 0; } + +#endif + diff --git a/Tools/DiskTool/src/include/acess_logging.h b/Tools/DiskTool/src/include/acess_logging.h new file mode 100644 index 00000000..b5d7af09 --- /dev/null +++ b/Tools/DiskTool/src/include/acess_logging.h @@ -0,0 +1,16 @@ + +#ifndef _DISKTOOL__ACESS_LOGGING_H_ +#define _DISKTOOL__ACESS_LOGGING_H_ + +extern void Log_KernelPanic(const char *Ident, const char *Message, ...) __attribute__((noreturn)); +extern void Log_Panic(const char *Ident, const char *Message, ...); +extern void Log_Error(const char *Ident, const char *Message, ...); +extern void Log_Warning(const char *Ident, const char *Message, ...); +extern void Log_Notice(const char *Ident, const char *Message, ...); +extern void Log_Log(const char *Ident, const char *Message, ...); +extern void Log_Debug(const char *Ident, const char *Message, ...); + +extern void Warning(const char *Message, ...); +extern void Log(const char *Message, ...); +#endif + diff --git a/Tools/DiskTool/src/include/arch.h b/Tools/DiskTool/src/include/arch.h new file mode 100644 index 00000000..e69de29b diff --git a/Tools/DiskTool/src/logging.c b/Tools/DiskTool/src/logging.c new file mode 100644 index 00000000..1517b65e --- /dev/null +++ b/Tools/DiskTool/src/logging.c @@ -0,0 +1,42 @@ +/* + * + */ +#include +#include +#include +#include + +#define PUTERR(col,type) {\ + 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"); \ +} + +// === CODE === +void Log_KernelPanic(const char *Ident, const char *Message, ...) { + PUTERR("35", "k") + exit(-1); +} +void Log_Panic(const char *Ident, const char *Message, ...) + PUTERR("37", "p") +void Log_Error(const char *Ident, const char *Message, ...) + PUTERR("32", "e") +void Log_Warning(const char *Ident, const char *Message, ...) + PUTERR("34", "w") +void Log_Notice(const char *Ident, const char *Message, ...) + PUTERR("33", "n") +void Log_Log(const char *Ident, const char *Message, ...) + PUTERR("31", "l") +void Log_Debug(const char *Ident, const char *Message, ...) + PUTERR("31", "d") + +void Warning(const char *Message, ...) { + const char *Ident = "WARNING"; + PUTERR("34", "W") +} +void Log(const char *Message, ...) { + const char *Ident = "LOGLOG"; + PUTERR("31", "L") +} diff --git a/Tools/DiskTool/src/main.c b/Tools/DiskTool/src/main.c new file mode 100644 index 00000000..3698df64 --- /dev/null +++ b/Tools/DiskTool/src/main.c @@ -0,0 +1,44 @@ +/* + */ +#include +#include +#include +#include +#include + +// === CODE === +int main(int argc, char *argv[]) +{ + return 0; +} + +int *Threads_GetErrno(void) +{ + return &errno; +} + +// TODO: Move into a helper lib? +extern void itoa(char *buf, uint64_t num, int base, int minLength, char pad) +{ + char fmt[] = "%0ll*x"; + switch(base) + { + case 8: fmt[5] = 'o'; break; + case 10: fmt[5] = 'd'; break; + case 16: fmt[5] = 'x'; break; + } + if(pad != '0') { + fmt[1] = '%'; + sprintf(buf, fmt+1, minLength, num); + } + else { + sprintf(buf, fmt, minLength, num); + } +} + +int strpos(const char *Str, char Ch) +{ + const char *r = strchr(Str, Ch); + if(!r) return -1; + return r - Str; +} diff --git a/Tools/DiskTool/src/nativefs.c b/Tools/DiskTool/src/nativefs.c new file mode 100644 index 00000000..e69de29b diff --git a/Tools/DiskTool/src/script.c b/Tools/DiskTool/src/script.c new file mode 100644 index 00000000..e69de29b diff --git a/Tools/DiskTool/src/threads.c b/Tools/DiskTool/src/threads.c new file mode 100644 index 00000000..b5c2edf4 --- /dev/null +++ b/Tools/DiskTool/src/threads.c @@ -0,0 +1,24 @@ +/* + * + */ +#include + +// === CODE === +Uint32 Threads_WaitEvents(Uint32 Events) +{ + Log_KernelPanic("Threads", "Can't use _WaitEvents in DiskTool"); + return 0; +} + +void Threads_ClearEvent(Uint32 Mask) +{ + +} + +tUID Threads_GetUID(void) { return 0; } +tGID Threads_GetGID(void) { return 0; } + +int *Threads_GetMaxFD(void) { static int max_fd=32; return &max_fd; } +char **Threads_GetCWD(void) { static char *cwd; return &cwd; } +char **Threads_GetChroot(void) { static char *chroot; return &chroot; } + diff --git a/Tools/DiskTool/src/vfs_handles.c b/Tools/DiskTool/src/vfs_handles.c new file mode 100644 index 00000000..53c932f1 --- /dev/null +++ b/Tools/DiskTool/src/vfs_handles.c @@ -0,0 +1,10 @@ +/* + * + */ +#include + +// === CODE === +tVFS_Handle *VFS_GetHandle(int ID) +{ + return NULL; +}