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.
bitmap-optimize
Theodore Ts'o 2002-05-11 22:13:20 -04:00
parent b5ffeadece
commit b38cd28363
6 changed files with 50 additions and 5 deletions

View 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

View 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;

View 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':

View 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;
}

View 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

View 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;
}