DiskTool - Mounts successfully, debugging readdir
authorJohn Hodge <[email protected]>
Mon, 9 Jul 2012 08:24:35 +0000 (16:24 +0800)
committerJohn Hodge <[email protected]>
Mon, 9 Jul 2012 08:24:35 +0000 (16:24 +0800)
Tools/DiskTool/src/actions.c
Tools/DiskTool/src/main.c
Tools/DiskTool/src/vfs_handles.c

index f1f8686..417a86b 100644 (file)
@@ -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;
+       }
 }
 
index fbfe7a0..53a9598 100644 (file)
@@ -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;
index 42fa659..4f30151 100644 (file)
@@ -1,15 +1,33 @@
 /*
  * 
  */
+#include <acess.h>
+#include <vfs.h>
 #include <vfs_int.h>
 
+#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];
 }

UCC git Repository :: git.ucc.asn.au