]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: create inode_dump command to dump an inode in hex
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 22 Jul 2014 16:44:42 +0000 (12:44 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 22 Jul 2014 17:48:54 +0000 (13:48 -0400)
Create a command that will dump an entire inode's space in hex.

[ Modified by tytso to add a description to the man page, and to add
  the more formal command name, inode_dump, in addition to short
  command name of "idump". ]

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/debug_cmds.ct
debugfs/debugfs.8.in
debugfs/debugfs.c
debugfs/debugfs.h
debugfs/zap.c

index 6a18df67c83f92d3700d4496eed09e4bc671ea7a..ed3728fda21c28f6812d845bb718b2ab9e13e3ba 100644 (file)
@@ -188,7 +188,7 @@ request do_zap_block, "Zap block: fill with 0, pattern, flip bits etc.",
        zap_block, zap;
 
 request do_block_dump, "Dump contents of a block",
-       block_dump, bd;
+       block_dump, bdump, bd;
 
 request do_list_quota, "List quota",
        list_quota, lq;
@@ -196,5 +196,9 @@ request do_list_quota, "List quota",
 request do_get_quota, "Get quota",
        get_quota, gq;
 
+request do_idump, "Dump the inode structure in hex",
+       inode_dump, idump, id;
+
+
 end;
 
index 73254d31068b0e33cc98cbcf9c7e575226237009..9a125f6c68722c96c7506c754792c09b97cb0fa1 100644 (file)
@@ -346,6 +346,9 @@ showing its tree structure.
 Print a listing of the inodes which use the one or more blocks specified
 on the command line.
 .TP
+.BI inode_dump " filespec"
+Print the contents of the inode data structure in hex and ASCII format.
+.TP
 .BI imap " filespec"
 Print the location of the inode data structure (in the inode table)
 of the inode
index 1703aba8f3618484cda0fd0a20ffcfb461d0c773..b41626c1dd68d6b5f6ec0055b25d04248018f552 100644 (file)
@@ -2145,6 +2145,39 @@ void do_imap(int argc, char *argv[])
 
 }
 
+void do_idump(int argc, char *argv[])
+{
+       ext2_ino_t      ino;
+       char            *buf;
+       errcode_t       err;
+       int             isize;
+
+       if (common_args_process(argc, argv, 2, 2, argv[0],
+                               "<file>", 0))
+               return;
+       ino = string_to_inode(argv[1]);
+       if (!ino)
+               return;
+
+       isize = EXT2_INODE_SIZE(current_fs->super);
+       err = ext2fs_get_mem(isize, &buf);
+       if (err) {
+               com_err(argv[0], err, "while allocating memory");
+               return;
+       }
+
+       err = ext2fs_read_inode_full(current_fs, ino,
+                                    (struct ext2_inode *)buf, isize);
+       if (err) {
+               com_err(argv[0], err, "while reading inode %d", ino);
+               goto err;
+       }
+
+       do_byte_hexdump(stdout, buf, isize);
+err:
+       ext2fs_free_mem(&buf);
+}
+
 #ifndef READ_ONLY
 void do_set_current_time(int argc, char *argv[])
 {
index 9b67f69c043fed9005f1291f56085d1b2492d742..0e75cee4ed51d4898cef6ff2b9063c5a905e2002 100644 (file)
@@ -183,3 +183,4 @@ extern time_t string_to_time(const char *arg);
 /* zap.c */
 extern void do_zap_block(int argc, char **argv);
 extern void do_block_dump(int argc, char **argv);
+extern void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize);
index 81092097768a5d9e5899817f5c91770ce7af6af4..917bddf9d259de24d6d938e72423d456e06d9035 100644 (file)
@@ -176,7 +176,6 @@ void do_block_dump(int argc, char *argv[])
        char            *file = NULL;
        unsigned int    i, j;
        int             c, err;
-       int             suppress = -1;
 
        if (check_fs_open(argv[0]))
                return;
@@ -229,11 +228,21 @@ void do_block_dump(int argc, char *argv[])
                goto errout;
        }
 
-       for (i=0; i < current_fs->blocksize; i += 16) {
+       do_byte_hexdump(stdout, buf, current_fs->blocksize);
+errout:
+       free(buf);
+}
+
+void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize)
+{
+       size_t          i, j;
+       int             suppress = -1;
+
+       for (i = 0; i < bufsize; i += 16) {
                if (suppress < 0) {
                        if (i && memcmp(buf + i, buf + i - 16, 16) == 0) {
                                suppress = i;
-                               printf("*\n");
+                               fprintf(fp, "*\n");
                                continue;
                        }
                } else {
@@ -241,20 +250,16 @@ void do_block_dump(int argc, char *argv[])
                                continue;
                        suppress = -1;
                }
-               printf("%04o  ", i);
+               fprintf(fp, "%04o  ", (unsigned int)i);
                for (j = 0; j < 16; j++) {
-                       printf("%02x", buf[i+j]);
+                       fprintf(fp, "%02x", buf[i+j]);
                        if ((j % 2) == 1)
-                               putchar(' ');
+                               fprintf(fp, " ");
                }
-               putchar(' ');
+               fprintf(fp, " ");
                for (j = 0; j < 16; j++)
-                       printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
-               putchar('\n');
+                       fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+               fprintf(fp, "\n");
        }
-       putchar('\n');
-
-errout:
-       free(buf);
-       return;
+       fprintf(fp, "\n");
 }