From: John Hodge Date: Mon, 9 Jul 2012 08:24:35 +0000 (+0800) Subject: DiskTool - Mounts successfully, debugging readdir X-Git-Tag: rel0.15~611^2~41^2~21 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=65e8f70ac79804f4c7519c4c0237642984e4c0b0;p=tpg%2Facess2.git DiskTool - Mounts successfully, debugging readdir --- diff --git a/Tools/DiskTool/src/actions.c b/Tools/DiskTool/src/actions.c index f1f86864..417a86b9 100644 --- a/Tools/DiskTool/src/actions.c +++ b/Tools/DiskTool/src/actions.c @@ -51,9 +51,31 @@ int DiskTool_Copy(const char *Source, const char *Destination) return -1; } +int DiskTool_ListDirectory(const char *Directory) +{ + int fd = DiskTool_int_TranslateOpen(Directory, 2); + if(fd == -1) { +// fprintf(stderr, "Can't open '%s'\n", Directory); + return -1; + } + + printf("Directory listing of '%s'\n", Directory); + + char name[256]; + while( VFS_ReadDir(fd, name) ) + { + printf("%s\n", name); + } + + VFS_Close(fd); + + return 0; +} + // --- Internal helpers --- size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path) { + int len; const char *colon = strchr(Path, ':'); if( colon ) { @@ -64,11 +86,18 @@ size_t DiskTool_int_TranslatePath(char *Buffer, const char *Path) goto native_path; } - return -1; + 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: { - int len = strlen("/Native"); +native_path: + len = strlen("/Native"); len += strlen( getenv("PWD") ) + 1; len += strlen(Path); if( Buffer ) { @@ -78,12 +107,28 @@ native_path: { strcat(Buffer, Path); } return len; - } } 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; + size_t tpath_len = DiskTool_int_TranslatePath(NULL, File); + if(tpath_len == -1) + return -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; + } } diff --git a/Tools/DiskTool/src/main.c b/Tools/DiskTool/src/main.c index fbfe7a0b..53a9598c 100644 --- a/Tools/DiskTool/src/main.c +++ b/Tools/DiskTool/src/main.c @@ -26,6 +26,16 @@ int main(int argc, char *argv[]) } i += 2; + continue ; + } + + if( strcmp("ls", argv[i]) == 0 ) { + if( argc - i < 2 ) { + fprintf(stderr, "ls 1 argument (path)\n"); + exit(-1); + } + + DiskTool_ListDirectory(argv[i+1]); } } return 0; diff --git a/Tools/DiskTool/src/vfs_handles.c b/Tools/DiskTool/src/vfs_handles.c index 42fa659b..4f30151a 100644 --- a/Tools/DiskTool/src/vfs_handles.c +++ b/Tools/DiskTool/src/vfs_handles.c @@ -1,15 +1,33 @@ /* * */ +#include +#include #include +#define MAX_KERNEL_FILES 32 + +// === GLOBALS === +tVFS_Handle gaKernelHandles[MAX_KERNEL_FILES]; + // === CODE === -int VFS_AllocHandle(int bKernel) +int VFS_AllocHandle(int bIsUser, tVFS_Node *Node, int Mode) { - return 0; + for( int i = 0; i < MAX_KERNEL_FILES; i ++ ) + { + if(gaKernelHandles[i].Node) continue; + gaKernelHandles[i].Node = Node; + gaKernelHandles[i].Position = 0; + gaKernelHandles[i].Mode = Mode; + return i; + } + + return -1; } tVFS_Handle *VFS_GetHandle(int ID) { - return NULL; + if( ID < 0 || ID >= MAX_KERNEL_FILES ) + return NULL; + return &gaKernelHandles[ID]; }