Merge branch 'master' of git://git.ucc.asn.au/tpg/acess2
[tpg/acess2.git] / Tools / DiskTool / src / actions.c
index d1fb703..5cda588 100644 (file)
@@ -84,8 +84,6 @@ int DiskTool_MountImage(const char *Identifier, const char *Path)
        
        // 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);
        
@@ -95,6 +93,11 @@ int DiskTool_MountImage(const char *Identifier, const char *Path)
        return VFS_Mount(tpath, mountpoint, "", "");
 }
 
+int DiskTool_MkDir(const char *Directory)
+{
+       return -1;
+}
+
 int DiskTool_Copy(const char *Source, const char *Destination)
 {
        int src = DiskTool_int_TranslateOpen(Source, VFS_OPENFLAG_READ);
@@ -138,7 +141,14 @@ int DiskTool_ListDirectory(const char *Directory)
        char    name[256];
        while( VFS_ReadDir(fd, name) )
        {
-               Log("- %s", name);
+               tFInfo  fi;
+               int child = VFS_OpenChild(fd, name, 0);
+               if( child != -1 )
+               {
+                       VFS_FInfo(child, &fi, 0);
+                       VFS_Close(child);
+               }
+               Log("- %02x %6lli %s", fi.flags, fi.size, name);
        }
        
        VFS_Close(fd);
@@ -146,6 +156,29 @@ int DiskTool_ListDirectory(const char *Directory)
        return 0;
 }
 
+int DiskTool_Cat(const char *File)
+{
+       int src = DiskTool_int_TranslateOpen(File, VFS_OPENFLAG_READ);
+       if( src == -1 ) {
+               Log_Error("DiskTool", "Unable to open %s for reading", File);
+               return -1;
+       }
+       
+       char    buf[1024];
+       size_t  len, total = 0;
+       while( (len = VFS_Read(src, sizeof(buf), buf)) == sizeof(buf) ) {
+               _fwrite_stdout(len, buf);
+               total += len;
+       }
+       _fwrite_stdout(len, buf);
+       total += len;
+
+       Log_Notice("DiskTool", "%i bytes from %s", total, File);
+
+       VFS_Close(src);
+       return 0;
+}
+
 int DiskTool_LVM_Read(void *Handle, Uint64 Block, size_t BlockCount, void *Dest)
 {
        return VFS_ReadAt( (int)(tVAddr)Handle, Block*512, BlockCount*512, Dest) / 512;
@@ -163,7 +196,7 @@ void DiskTool_LVM_Cleanup(void *Handle)
 int DiskTool_int_TranslateOpen(const char *File, int Flags)
 {
        size_t tpath_len = DiskTool_int_TranslatePath(NULL, File);
-       if(tpath_len == -1)
+       if(tpath_len == 0)
                return -1;
        char tpath[tpath_len-1];
        DiskTool_int_TranslatePath(tpath, File);

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