]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: add the hexdump_block command
authorTheodore Ts'o <tytso@mit.edu>
Sat, 20 Jun 2015 04:10:20 +0000 (00:10 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 20 Jun 2015 04:10:20 +0000 (00:10 -0400)
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/debug_cmds.ct
debugfs/debugfs.8.in
debugfs/debugfs.h
debugfs/logdump.c

index 34dad9e6f731eba91f07dbd137884429d3bccec0..3564a632bf46d469b5b3bbd81a77f3ff8f201098 100644 (file)
@@ -145,6 +145,9 @@ request do_set_block_group_descriptor, "Set block group descriptor field",
 request do_logdump, "Dump the contents of the journal",
        logdump;
 
+request do_hexdump_block, "Dump the contents of a block",
+       hexdump_block, hexdump;
+
 request do_htree_dump, "Dump a hash-indexed directory",
        htree_dump, htree;
 
index a463c73a1bfc6832c5475f59ca9ec475219cff96..aa9070d79b6db600c504d6c82ccfbda1cba88dd7 100644 (file)
@@ -392,6 +392,11 @@ is specified, also clear num-1 inodes after the specified inode.
 Print a list of commands understood by
 .BR debugfs .
 .TP
+.BI hexdump_block " block"
+Dump the contents of
+.I block
+in hex and ASCII.
+.TP
 .BI htree_dump " filespec"
 Dump the hash-indexed directory
 .IR filespec ,
index 76bb22c285f65a63e2a285f79453f39c83d2cda8..7c3975459dc268aafb5a660aa81987269c84eed2 100644 (file)
@@ -103,6 +103,7 @@ extern void do_dirsearch(int argc, char **argv);
 
 /* logdump.c */
 extern void do_logdump(int argc, char **argv);
+extern void do_hexdump_block(int argc, char **argv);
 
 /* lsdel.c */
 extern void do_lsdel(int argc, char **argv);
index 70a7c3630cd6d97137bb6c791d62a71b73f402c3..1dc78690cd9fff8084cf7de97865597f832cd16f 100644 (file)
@@ -714,3 +714,38 @@ static void do_hexdump (FILE *out_file, char *buf, int blocksize)
        }
 }
 
+void do_hexdump_block(int argc, char **argv)
+{
+       blk64_t block;
+       char *buf;
+       errcode_t errcode;
+       FILE *out;
+
+       if (common_args_process(argc, argv, 2, 2, argv[0],
+                               "<block>", 0))
+               return;
+
+       if (strtoblk(argv[0], argv[1], "block number", &block))
+               return;
+
+       buf = malloc(current_fs->blocksize);
+       if (!buf) {
+               fprintf(stderr, "Couldn't allocate block buffer.\n");
+               return;
+       }
+       out = open_pager();
+
+       errcode = io_channel_read_blk64(current_fs->io, block, 1, buf);
+       if (errcode) {
+               com_err("hexdump_block", errcode,
+                       "while reading block %llu\n", block);
+               goto errout;
+       }
+
+       do_hexdump(out, buf, current_fs->blocksize);
+
+errout:
+       free(buf);
+       close_pager(out);
+}
+