Whamcloud - gitweb
debugfs: add a new debugfs command 'blocks'
authorTheodore Ts'o <tytso@mit.edu>
Sat, 9 Jul 2011 16:13:40 +0000 (12:13 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 9 Jul 2011 16:13:40 +0000 (12:13 -0400)
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" <tytso@mit.edu>
debugfs/debug_cmds.ct
debugfs/debugfs.8.in
debugfs/debugfs.c
debugfs/debugfs.h

index 9b6c985..4e9e831 100644 (file)
@@ -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;
 
index f5deb7a..fe07f34 100644 (file)
@@ -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
index 12ee638..e7d7436 100644 (file)
@@ -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;
index f7ec8da..0ea2474 100644 (file)
@@ -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);