From b38cd283637dafff6b39d4b76bf76fa2789eb21f Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 11 May 2002 22:13:20 -0400 Subject: [PATCH] Add a new command "bmap" to debugfs which calculates the logical->physical block mapping for a particular inode. Fixed a bug in the libext2 library which broke ext2fs_bmap if no inode structre was passed inside for here. Fixed bad calling parameters to parse_ulong which broken the -b and -s options to debugfs, as well as do_init, and the testb, setb, clearb functions. --- debugfs/ChangeLog | 12 ++++++++++++ debugfs/debug_cmds.ct | 3 +++ debugfs/debugfs.c | 30 +++++++++++++++++++++++++++--- debugfs/util.c | 2 +- lib/ext2fs/ChangeLog | 6 ++++++ lib/ext2fs/bmap.c | 2 +- 6 files changed, 50 insertions(+), 5 deletions(-) diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index 2317403..360b545 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,3 +1,15 @@ +2002-05-11 + + * debug_cmds.ct, debugfs.c (do_bmap): Add new command "bmap" which + calculates the logical->physical block mapping for an + inode. + + * debugfs.c (do_init_filsys, main), util.c + (common_block_args_process): Fix bad calling parameter + order when calling parse_ulong. This broke the -b and -s + options to debugfs, as well as do_init, and the testb, + setb, clearb functions. + 2002-04-01 * util.c (parse_ulong): Fix typo which cases parse_ulong to diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct index 96d972e..e1e2716 100644 --- a/debugfs/debug_cmds.ct +++ b/debugfs/debug_cmds.ct @@ -136,5 +136,8 @@ request do_dx_hash, "Calculate the directory hash of a filename", request do_dirsearch, "Search a directory for a particular filename", dirsearch; +request do_bmap, "Calculate the logical->physical block mapping for an inode", + bmap; + end; diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index ed4f23b..096bafe 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -199,7 +199,7 @@ void do_init_filesys(int argc, char **argv) return; memset(¶m, 0, sizeof(struct ext2_super_block)); - param.s_blocks_count = parse_ulong(argv[0], argv[2], + param.s_blocks_count = parse_ulong(argv[2], argv[0], "blocks count", &err); if (err) return; @@ -1362,6 +1362,30 @@ void do_features(int argc, char *argv[]) print_features(current_fs->super, stdout); } +void do_bmap(int argc, char *argv[]) +{ + ext2_ino_t ino; + blk_t blk, pblk; + int err; + errcode_t errcode; + + if (common_args_process(argc, argv, 3, 3, argv[0], + " logical_blk", 0)) + return; + + ino = string_to_inode(argv[1]); + blk = parse_ulong(argv[2], argv[0], "logical_block", &err); + + errcode = ext2fs_bmap(current_fs, ino, 0, 0, 0, blk, &pblk); + if (errcode) { + com_err("argv[0]", errcode, + "while mapping logical block %d\n", blk); + return; + } + printf("%d\n", pblk); +} + + static int source_file(const char *cmd_file, int sci_idx) { FILE *f; @@ -1433,11 +1457,11 @@ int main(int argc, char **argv) open_flags |= EXT2_FLAG_RW; break; case 'b': - blocksize = parse_ulong(argv[0], optarg, + blocksize = parse_ulong(optarg, argv[0], "block size", 0); break; case 's': - superblock = parse_ulong(argv[0], optarg, + superblock = parse_ulong(optarg, argv[0], "superblock number", 0); break; case 'c': diff --git a/debugfs/util.c b/debugfs/util.c index 1a169c1..a5ee131 100644 --- a/debugfs/util.c +++ b/debugfs/util.c @@ -233,7 +233,7 @@ int common_block_args_process(int argc, char *argv[], if (strtoblk(argv[0], argv[1], block)) return 1; if (argc > 2) { - *count = parse_ulong(argv[0], argv[2], "count", &err); + *count = parse_ulong(argv[2], argv[0], "count", &err); if (err) return 1; } diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 61032e5..eda86e7 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,9 @@ +2002-05-11 + + * bmap.c (ext2fs_bmap): Fix bug which caused ext2fs_bmap to fail + silently if inode pointer is NULL (and ext2fs_bmap is + expected to read the inode itself). + 2002-04-27 * ismounted.c (check_mntent_file, is_swap_device): Verify that the diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index b8b5280..0fb56d6 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -139,7 +139,7 @@ errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, /* Read inode structure if necessary */ if (!inode) { retval = ext2fs_read_inode(fs, ino, &inode_buf); - if (!retval) + if (retval) return retval; inode = &inode_buf; } -- 1.8.3.1