]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Add a new command "bmap" to debugfs which calculates the logical->physical block
authorTheodore Ts'o <tytso@mit.edu>
Sun, 12 May 2002 02:13:20 +0000 (22:13 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 12 May 2002 02:13:20 +0000 (22:13 -0400)
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
debugfs/debug_cmds.ct
debugfs/debugfs.c
debugfs/util.c
lib/ext2fs/ChangeLog
lib/ext2fs/bmap.c

index 2317403d3110cd8dcd1e6814cf0b250087dab5e2..360b5452a8572656228e2fb8bc79c37b0967d149 100644 (file)
@@ -1,3 +1,15 @@
+2002-05-11    <tytso@snap.thunk.org>
+
+       * 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    <tytso@snap.thunk.org>
 
        * util.c (parse_ulong): Fix typo which cases parse_ulong to
index 96d972e58462904a5538bf84b89ef05f35a1b57b..e1e27160059cfb44aca4589fd6cb0996aa55370c 100644 (file)
@@ -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;
 
index ed4f23bb356f9a4ee421217729afa6ebf6beecd5..096bafef7bdb7b3200488aacf0de44b271436b45 100644 (file)
@@ -199,7 +199,7 @@ void do_init_filesys(int argc, char **argv)
                return;
 
        memset(&param, 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],
+                               "<file> 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':
index 1a169c120def410492081c410879b11c5430e56a..a5ee131b5d886fe8e8b1d5b83f84aa78b2e4d347 100644 (file)
@@ -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;
        }
index 61032e504537cc59f8329b0f68a91aefe6a21f77..eda86e7e1a91a3f057fb8e2e568ee4b333373d90 100644 (file)
@@ -1,3 +1,9 @@
+2002-05-11    <tytso@snap.thunk.org>
+
+       * 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    <tytso@snap.thunk.org>
 
        * ismounted.c (check_mntent_file, is_swap_device): Verify that the
index b8b5280eb98b82c5162b100effd31028c808bdc3..0fb56d66d022a1255a8c916b650b4e6782e016fd 100644 (file)
@@ -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;
        }