From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, darrick.wong@oracle.com
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 03/24] debugfs: create idump command to dump an inode in hex
Date: Fri, 18 Jul 2014 15:52:36 -0700 [thread overview]
Message-ID: <20140718225236.31374.97509.stgit@birch.djwong.org> (raw)
In-Reply-To: <20140718225200.31374.85411.stgit@birch.djwong.org>
Create a command that will dump an entire inode's space in hex.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
debugfs/debug_cmds.ct | 4 ++++
debugfs/debugfs.c | 33 +++++++++++++++++++++++++++++++++
debugfs/debugfs.h | 1 +
debugfs/zap.c | 33 +++++++++++++++++++--------------
4 files changed, 57 insertions(+), 14 deletions(-)
diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct
index 814fd52..9a66494 100644
--- a/debugfs/debug_cmds.ct
+++ b/debugfs/debug_cmds.ct
@@ -208,5 +208,9 @@ request do_list_quota, "List quota",
request do_get_quota, "Get quota",
get_quota, gq;
+request do_idump, "Dump inode",
+ idump;
+
+
end;
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 5eecabe..8078a02 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -1888,6 +1888,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[])
{
diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h
index df51aa0..6eb5732 100644
--- a/debugfs/debugfs.h
+++ b/debugfs/debugfs.h
@@ -191,3 +191,4 @@ void do_list_xattr(int argc, char **argv);
/* 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);
diff --git a/debugfs/zap.c b/debugfs/zap.c
index 8109209..917bddf 100644
--- a/debugfs/zap.c
+++ b/debugfs/zap.c
@@ -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');
next prev parent reply other threads:[~2014-07-18 22:52 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-18 22:52 [PATCH 00/24] e2fsprogs patchbomb 7/14, part 1 Darrick J. Wong
2014-07-18 22:52 ` [PATCH 01/24] e4defrag: backwards-allocated files should be defragmented too Darrick J. Wong
2014-07-21 23:44 ` Akira Fujita
2014-07-22 16:32 ` Theodore Ts'o
2014-07-18 22:52 ` [PATCH 02/24] debugfs: Only print the first 60 bytes from i_block on a fast symlink Darrick J. Wong
2014-07-19 16:49 ` Andreas Dilger
2014-07-22 16:43 ` Theodore Ts'o
2014-07-22 20:39 ` Darrick J. Wong
2014-07-22 20:34 ` Darrick J. Wong
2014-07-18 22:52 ` Darrick J. Wong [this message]
2014-07-22 17:47 ` [PATCH 03/24] debugfs: create idump command to dump an inode in hex Theodore Ts'o
2014-07-18 22:52 ` [PATCH 04/24] debugfs: allow bmap to allocate blocks Darrick J. Wong
2014-07-22 17:52 ` Theodore Ts'o
2014-07-18 22:52 ` [PATCH 05/24] e2fsck: report correct inode number in pass1b Darrick J. Wong
2014-07-22 17:47 ` Theodore Ts'o
2014-07-18 22:52 ` [PATCH 06/24] e2fsck: don't offer to recreate the journal if fsck is aborting due to bad block bitmaps Darrick J. Wong
2014-07-22 17:58 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 07/24] e2fsck: skip clearing bad extents if bitmaps are unreadable Darrick J. Wong
2014-07-22 17:58 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 08/24] e2fsck: fix inode coherency issue when iterating an inode's blocks Darrick J. Wong
2014-07-22 18:58 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 09/24] e2fsck: clear i_block if there are too many bad block mappings Darrick J. Wong
2014-07-22 18:59 ` Theodore Ts'o
2014-07-22 22:14 ` Darrick J. Wong
2014-07-22 22:48 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 10/24] e2fsck: don't clobber critical metadata during check_blocks Darrick J. Wong
2014-07-25 1:03 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 11/24] e2fsck: free ctx->fs, not fs, at the end of fsck Darrick J. Wong
2014-07-25 1:14 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 12/24] e2fsck: force all block allocations to use block_found_map Darrick J. Wong
2014-07-25 2:18 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 13/24] e2fsck: fix off-by-one bounds check on group number Darrick J. Wong
2014-07-25 2:20 ` Theodore Ts'o
2014-07-18 22:53 ` [PATCH 14/24] libext2fs: fix bounds check of the bitmap test range in get_free_blocks2 Darrick J. Wong
2014-07-25 11:13 ` Theodore Ts'o
2014-07-18 22:54 ` [PATCH 15/24] misc: fix problems with strncat Darrick J. Wong
2014-07-25 11:22 ` Theodore Ts'o
2014-07-18 22:54 ` [PATCH 16/24] e2fsck: don't crash during rehash Darrick J. Wong
2014-07-25 11:22 ` Theodore Ts'o
2014-07-18 22:54 ` [PATCH 17/24] e2fsck: reserve blocks for root/lost+found directory repair Darrick J. Wong
2014-07-25 12:12 ` Theodore Ts'o
2014-07-25 20:19 ` Darrick J. Wong
2014-07-18 22:54 ` [PATCH 18/24] e2fsck: collapse holes in extent-based directories Darrick J. Wong
2014-07-25 12:33 ` Theodore Ts'o
2014-07-18 22:54 ` [PATCH 19/24] e2fsck: always submit logical block 0 of a directory for pass 2 Darrick J. Wong
2014-07-25 12:40 ` Theodore Ts'o
2014-07-18 22:54 ` [PATCH 20/24] e2fsck: pass2 should not process directory blocks that are impossibly large Darrick J. Wong
2014-07-25 12:42 ` Theodore Ts'o
2014-07-18 22:55 ` [PATCH 21/24] e2fsck: clear uninit flag on directory extents Darrick J. Wong
2014-07-25 13:00 ` Theodore Ts'o
2014-07-18 22:55 ` [PATCH 22/24] e2fsck: check return value of ext2fs_extent_fix_parents() Darrick J. Wong
2014-07-25 12:51 ` Theodore Ts'o
2014-07-18 22:55 ` [PATCH 23/24] mke2fs: set error behavior at initialization time Darrick J. Wong
2014-07-25 13:00 ` Theodore Ts'o
2014-07-18 22:55 ` [PATCH 24/24] e2fuzz: Create a tool to fuzz ext* filesystems Darrick J. Wong
2014-07-25 13:16 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140718225236.31374.97509.stgit@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).