Makefile.user.cfg
QemuLog.txt
Screenshots/
+
+Tools/*/src/obj/
+Tools/*/src/Makefile.BuildNum
+Tools/DiskTool/DiskTool
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 := 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
# 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)
-N_OBJ = main.o script.o logging.o
+N_OBJ = main.o script.o logging.o helpers.o
# Compilation Options
-CFLAGS := -Wall -std=gnu99 -g
+CFLAGS := -Wall -std=gnu99 -g -Werror
CPPFLAGS := -I include/
K_CPPFLAGS := -I $(KERNEL_SRC)include
LDFLAGS += -Wl,--defsym,__buildnum=$(BUILD_NUM) -g
*/
#include <acess.h>
#include <disktool_common.h>
-#include <ctype.h>
// === IMPORTS ===
extern int NativeFS_Install(char **Arguments);
// === PROTOTYPES ===
void DiskTool_Initialise(void) __attribute__((constructor(101)));
-size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path);
int DiskTool_int_TranslateOpen(const char *File, int Mode);
// === CODE ===
int DiskTool_Copy(const char *Source, const char *Destination)
{
- return -1;
+ int src = DiskTool_int_TranslateOpen(Source, VFS_OPENFLAG_READ);
+ if( src == -1 ) {
+ Log_Error("DiskTool", "Unable to open %s for reading", Source);
+ return -1;
+ }
+ int dst = DiskTool_int_TranslateOpen(Destination, VFS_OPENFLAG_WRITE|VFS_OPENFLAG_CREATE);
+ if( dst == -1 ) {
+ Log_Error("DiskTool", "Unable to open %s for writing", Destination);
+ VFS_Close(src);
+ return -1;
+ }
+
+ char buf[1024];
+ size_t len, total = 0;
+ while( (len = VFS_Read(src, sizeof(buf), buf)) == sizeof(buf) )
+ VFS_Write(dst, len, buf), total += len;
+ VFS_Write(dst, len, buf), total += len;
+
+ Log_Notice("DiskTool", "Copied %i from %s to %s", total, Source, Destination);
+
+ VFS_Close(dst);
+ VFS_Close(src);
+
+ return 0;
}
int DiskTool_ListDirectory(const char *Directory)
{
- int fd = DiskTool_int_TranslateOpen(Directory, 2);
+ int fd = DiskTool_int_TranslateOpen(Directory, VFS_OPENFLAG_READ|VFS_OPENFLAG_DIRECTORY);
if(fd == -1) {
// fprintf(stderr, "Can't open '%s'\n", Directory);
return -1;
}
- printf("Directory listing of '%s'\n", Directory);
+ Log("Directory listing of '%s'", Directory);
char name[256];
while( VFS_ReadDir(fd, name) )
{
- printf("%s\n", name);
+ Log("- %s", name);
}
VFS_Close(fd);
}
// --- Internal helpers ---
-size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path)
-{
- int len;
- const char *colon = strchr(Path, ':');
- if( colon )
- {
- const char *pos;
- for(pos = Path; pos < colon; pos ++)
- {
- if( !isalpha(*pos) )
- goto native_path;
- }
-
- len = strlen("/Mount/");
- len += strlen(Path);
- if( Buffer ) {
- strcpy(Buffer, "/Mount/");
- strncat(Buffer+strlen("/Mount/"), Path, colon - Path);
- strcat(Buffer, colon + 1);
- }
- return len;
- }
-
-native_path:
- len = strlen("/Native");
- len += strlen( getenv("PWD") ) + 1;
- len += strlen(Path);
- if( Buffer ) {
- strcpy(Buffer, "/Native");
- strcat(Buffer, getenv("PWD"));
- strcat(Buffer, "/");
- strcat(Buffer, Path);
- }
- return len;
-}
-
-int DiskTool_int_TranslateOpen(const char *File, int Mode)
+int DiskTool_int_TranslateOpen(const char *File, int Flags)
{
size_t tpath_len = DiskTool_int_TranslatePath(NULL, File);
if(tpath_len == -1)
char tpath[tpath_len-1];
DiskTool_int_TranslatePath(tpath, File);
-// printf("Opening '%s'\n", tpath);
-
- switch(Mode)
- {
- case 0: // Read
- return VFS_Open(tpath, VFS_OPENFLAG_READ);
- case 1: // Write
- return VFS_Open(tpath, VFS_OPENFLAG_READ|VFS_OPENFLAG_WRITE);
- case 2: // Directory
- return VFS_Open(tpath, VFS_OPENFLAG_READ|VFS_OPENFLAG_EXEC);
- default:
- return -1;
- }
+ return VFS_Open(tpath, Flags);
}
--- /dev/null
+/*
+ * Acess2 DiskTool
+ * - By John Hodge (thePowersGang)
+ *
+ * helpers.c
+ */
+#include <stdlib.h>
+#include <acess_logging.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+
+// === GLOBALS ===
+char gsWorkingDirectory[1024];
+
+
+// === CODE ===
+size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path)
+{
+ int len;
+ const char *colon = strchr(Path, ':');
+
+ if( colon )
+ {
+ const char *pos;
+ for(pos = Path; pos < colon; pos ++)
+ {
+ if( !isalpha(*pos) )
+ goto native_path;
+ }
+
+ len = strlen("/Mount/");
+ len += strlen(Path);
+ if( Buffer ) {
+ strcpy(Buffer, "/Mount/");
+ strncat(Buffer+strlen("/Mount/"), Path, colon - Path);
+ strcat(Buffer, colon + 1);
+ }
+ return len;
+ }
+
+native_path:
+
+ if( !gsWorkingDirectory[0] ) {
+ getcwd(gsWorkingDirectory, 1024);
+ }
+
+ len = strlen("/Native");
+ len += strlen( gsWorkingDirectory ) + 1;
+ len += strlen(Path);
+ if( Buffer ) {
+ strcpy(Buffer, "/Native");
+ strcat(Buffer, gsWorkingDirectory);
+ strcat(Buffer, "/");
+ strcat(Buffer, Path);
+ }
+ return len;
+}
#define STR(x) #x
#define EXPAND_STR(x) STR(x)
+#define ASSERT(x) do{}while(0)
+
extern char __buildnum[];
#define BUILD_NUM ((int)(Uint)&__buildnum)
extern const char gsGitHash[];
#include <stdint.h>
typedef uintptr_t Uint;
-typedef unsigned int size_t;
+//typedef unsigned int size_t;
+#include <stddef.h>
typedef uint64_t off_t;
typedef char BOOL;
typedef char tShortSpinlock;
typedef int64_t tTime;
+extern tTime now(void);
+extern int64_t timestamp(int sec, int min, int hr, int day, int month, int year);
#define PACKED __attribute__((packed))
#define DEPRECATED
extern void free(void *buffer);
#include <errno.h>
-
#include <acess_logging.h>
// Threads
#define errno (*(Threads_GetErrno()))
#include <string.h>
+extern int strucmp(const char *s1, const char *s2);
extern int strpos(const char *Str, char Ch);
extern void itoa(char *buf, uint64_t num, int base, int minLength, char pad);
+extern int snprintf(char *buf, size_t len, const char *fmt, ...);
+extern int sprintf(char *buf, const char *fmt, ...);
+extern int ReadUTF8(const Uint8 *str, Uint32 *Val);
+extern int WriteUTF8(Uint8 *str, Uint32 Val);
+#define CheckString(str) (1)
+#define CheckMem(mem,sz) (1)
// TODO: Move out?
-extern int64_t DivUp(int64_t value, int64_t divisor);
+extern int DivUp(int value, int divisor);
+extern uint64_t DivMod64U(uint64_t Num, uint64_t Den, uint64_t *Rem);
#if DEBUG
# define ENTER(str, v...) Log("%s:%i: ENTER "str, __func__, __LINE__)
extern void Warning(const char *Message, ...);
extern void Log(const char *Message, ...);
+extern void Debug_HexDump(const char *Prefix, const void *Data, size_t Length);
#endif
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);
+
+extern size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path);
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <stdint.h>
#include <acess_logging.h>
#define PUTERR(col,type) {\
PUTERR("37", "d")
void Warning(const char *Message, ...) {
- const char *Ident = "WARNING";
+ const char *Ident = "";
PUTERR("33", "W")
}
void Log(const char *Message, ...) {
- const char *Ident = "LOGLOG";
+ const char *Ident = "";
PUTERR("37", "L")
}
-void Debug_HexDump(const char *Prefix, size_t Length, const void *Data)
+void Debug_HexDump(const char *Prefix, const void *Data, size_t Length)
{
-
+ const uint8_t *data = Data;
+ size_t ofs;
+ fprintf(stderr, "[HexDump ]d %s: %i bytes\n", Prefix, (int)Length);
+ for( ofs = 0; ofs + 16 <= Length; ofs += 16 )
+ {
+ fprintf(stderr, "[HexDump ]d %s:", Prefix);
+ fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
+ data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
+ data += 8;
+ fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
+ data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
+ data += 8;
+ fprintf(stderr, "\n");
+ }
+
+ fprintf(stderr, "[HexDump ]d %s:", Prefix);
+ for( ; ofs < Length; ofs ++ )
+ {
+ if( ofs % 16 == 8 ) fprintf(stderr, " ");
+ fprintf(stderr, " %02x", data[ofs%16]);
+ }
+ fprintf(stderr, "\n");
}
}
DiskTool_ListDirectory(argv[i+1]);
+ i += 1;
+ continue ;
+ }
+
+ if( strcmp("cp", argv[i]) == 0 ) {
+
+ if( argc - i < 3 ) {
+ fprintf(stderr, "cp takes 2 arguments (source and destination)\n");
+ exit(-1);
+ }
+
+ DiskTool_Copy(argv[i+1], argv[i+2]);
+
+ i += 2;
+ continue ;
}
}
return 0;
return strcasecmp(s1, s2);
}
-int64_t DivUp(int64_t value, int64_t divisor)
+uint64_t DivMod64U(uint64_t value, uint64_t divisor, uint64_t *remainder)
{
- return (value + divisor - 1) / divisor;
-}
-
-int64_t timestamp(int sec, int min, int hr, int day, int month, int year)
-{
- return 0;
+ if(remainder)
+ *remainder = value % divisor;
+ return value / divisor;
}