Whamcloud - gitweb
debugfs: support encoding when printing the file hash
[tools/e2fsprogs.git] / debugfs / dump.c
index 0fa14b6..fdd6619 100644 (file)
@@ -144,7 +144,8 @@ static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
        return;
 }
 
-void do_dump(int argc, char **argv)
+void do_dump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
+            void *infop EXT2FS_ATTR((unused)))
 {
        ext2_ino_t      inode;
        int             fd;
@@ -208,9 +209,7 @@ static void rdump_symlink(ext2_ino_t ino, struct ext2_inode *inode,
                goto errout;
        }
 
-       /* Apparently, this is the right way to detect and handle fast
-        * symlinks; see do_stat() in debugfs.c. */
-       if (inode->i_blocks == 0)
+       if (ext2fs_is_fast_symlink(inode))
                strcpy(buf, (char *) inode->i_block);
        else {
                unsigned bytes = inode->i_size;
@@ -284,7 +283,7 @@ static void rdump_inode(ext2_ino_t ino, struct ext2_inode *inode,
                /* Create the directory with 0700 permissions, because we
                 * expect to have to create entries it.  Then fix its perms
                 * once we've done the traversal. */
-               if (mkdir(fullname, S_IRWXU) == -1) {
+               if (name[0] && mkdir(fullname, S_IRWXU) == -1) {
                        com_err("rdump", errno, "while making directory %s", fullname);
                        goto errout;
                }
@@ -312,7 +311,7 @@ static int rdump_dirent(struct ext2_dir_entry *dirent,
        const char *dumproot = private;
        struct ext2_inode inode;
 
-       thislen = dirent->name_len & 0xFF;
+       thislen = ext2fs_dirent_name_len(dirent);
        strncpy(name, dirent->name, thislen);
        name[thislen] = 0;
 
@@ -324,20 +323,15 @@ static int rdump_dirent(struct ext2_dir_entry *dirent,
        return 0;
 }
 
-void do_rdump(int argc, char **argv)
+void do_rdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
+             void *infop EXT2FS_ATTR((unused)))
 {
-       ext2_ino_t ino;
-       struct ext2_inode inode;
        struct stat st;
-       char *arg, *dest_dir, *basename;
-
-       if (common_args_process(argc, argv, 3, 3, "rdump",
-                               "<directory> <native directory>", 0))
-               return;
+       char *dest_dir;
+       int i;
 
-       arg = argv[1];
-       ino = string_to_inode(arg);
-       if (!ino)
+       if (common_args_process(argc, argv, 3, INT_MAX, "rdump",
+                               "<directory>... <native directory>", 0))
                return;
 
        /* Pull out last argument */
@@ -354,19 +348,28 @@ void do_rdump(int argc, char **argv)
                return;
        }
 
-       if (debugfs_read_inode(ino, &inode, arg))
-               return;
+       for (i = 1; i < argc; i++) {
+               char *arg = argv[i], *basename;
+               struct ext2_inode inode;
+               ext2_ino_t ino = string_to_inode(arg);
+               if (!ino)
+                       continue;
 
-       basename = strrchr(arg, '/');
-       if (basename)
-               basename++;
-       else
-               basename = arg;
+               if (debugfs_read_inode(ino, &inode, arg))
+                       continue;
 
-       rdump_inode(ino, &inode, basename, dest_dir);
+               basename = strrchr(arg, '/');
+               if (basename)
+                       basename++;
+               else
+                       basename = arg;
+
+               rdump_inode(ino, &inode, basename, dest_dir);
+       }
 }
 
-void do_cat(int argc, char **argv)
+void do_cat(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
+           void *infop EXT2FS_ATTR((unused)))
 {
        ext2_ino_t      inode;