From af0df2aa4a073f7e1a2d58b40010ecd891e80a60 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 9 Jul 2011 12:13:40 -0400 Subject: [PATCH] debugfs: add a new debugfs command 'blocks' The blocks command prints out the blocks used by a particular inode, in a format which is useful for test suite automation. Signed-off-by: "Theodore Ts'o" --- debugfs/debug_cmds.ct | 3 +++ debugfs/debugfs.8.in | 5 +++++ debugfs/debugfs.c | 28 ++++++++++++++++++++++++++++ debugfs/debugfs.h | 1 + 4 files changed, 37 insertions(+) diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct index 9b6c985..4e9e831 100644 --- a/debugfs/debug_cmds.ct +++ b/debugfs/debug_cmds.ct @@ -46,6 +46,9 @@ request do_stat, "Show inode information ", request do_dump_extents, "Dump extents information ", dump_extents, extents, ex; +request do_blocks, "Dump blocks used by an inode ", + blocks; + request do_link, "Create directory link", link, ln; diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in index f5deb7a..fe07f34 100644 --- a/debugfs/debugfs.8.in +++ b/debugfs/debugfs.8.in @@ -157,6 +157,11 @@ This is a list of the commands which .B debugfs supports. .TP +.I blocks filespace +Print the blocks used by the inode +.I filespec +to stdout. +.TP .I bmap filespec logical_block Print the physical block number corresponding to the logical block number .I logical_block diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 12ee638..e7d7436 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -912,6 +912,34 @@ void do_dump_extents(int argc, char **argv) return; } +static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)), + blk64_t *blocknr, + e2_blkcnt_t blockcnt, + blk64_t ref_block EXT2FS_ATTR((unused)), + int ref_offset EXT2FS_ATTR((unused)), + void *private EXT2FS_ATTR((unused))) +{ + printf("%llu ", *blocknr); + return 0; +} + +void do_blocks(int argc, char *argv[]) +{ + ext2_ino_t inode; + + if (check_fs_open(argv[0])) + return; + + if (common_inode_args_process(argc, argv, &inode, 0)) { + return; + } + + ext2fs_block_iterate3(current_fs, inode, BLOCK_FLAG_READ_ONLY, NULL, + print_blocks_proc, NULL); + fputc('\n', stdout); + return; +} + void do_chroot(int argc, char *argv[]) { ext2_ino_t inode; diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h index f7ec8da..0ea2474 100644 --- a/debugfs/debugfs.h +++ b/debugfs/debugfs.h @@ -104,6 +104,7 @@ extern void do_find_free_block(int argc, char **argv); extern void do_find_free_inode(int argc, char **argv); extern void do_stat(int argc, char **argv); extern void do_dump_extents(int argc, char **argv); +extern void do_blocks(int argc, char *argv[]); extern void do_chroot(int argc, char **argv); extern void do_clri(int argc, char **argv); -- 1.8.3.1