From becf36f6ace508fd091052b9e9bcdea192bfbc48 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 5 May 2003 11:35:04 -0400 Subject: [PATCH] debugfs.c (do_imap), debugfs.h, debug_cmds.ct, debugfs.8.in: Added new command, imap, which prints the location of a specified inode in the inode table. --- debugfs/ChangeLog | 6 ++++++ debugfs/debug_cmds.ct | 3 +++ debugfs/debugfs.8.in | 11 +++++++++++ debugfs/debugfs.c | 34 ++++++++++++++++++++++++++++++++++ debugfs/debugfs.h | 1 + 5 files changed, 55 insertions(+) diff --git a/debugfs/ChangeLog b/debugfs/ChangeLog index de4a25e..e178944 100644 --- a/debugfs/ChangeLog +++ b/debugfs/ChangeLog @@ -1,3 +1,9 @@ +2003-05-05 Theodore Ts'o + + * debugfs.c (do_imap), debugfs.h, debug_cmds.ct, debugfs.8.in: + Added new command, imap, which prints the location of a + specified inode in the inode table. + 2003-04-21 Theodore Ts'o * Release of E2fsprogs 1.33 diff --git a/debugfs/debug_cmds.ct b/debugfs/debug_cmds.ct index e1e2716..21cab09 100644 --- a/debugfs/debug_cmds.ct +++ b/debugfs/debug_cmds.ct @@ -139,5 +139,8 @@ request do_dirsearch, "Search a directory for a particular filename", request do_bmap, "Calculate the logical->physical block mapping for an inode", bmap; +request do_imap, "Calculate the location of an inode", + imap; + end; diff --git a/debugfs/debugfs.8.in b/debugfs/debugfs.8.in index 43d6e97..f51f8fe 100644 --- a/debugfs/debugfs.8.in +++ b/debugfs/debugfs.8.in @@ -144,6 +144,12 @@ This is a list of the commands which .B debugfs supports. .TP +.I bmap filespec logical_block +Print the physical block number corresponding to the logical block number +.I logical_block +in the inode +.IR filespec . +.TP .I cat filespec Dump the contents of the inode .I filespec @@ -226,6 +232,11 @@ Print a list of commands understood by Print a listing of the inodes which use the one or more blocks specified on the command line. .TP +.I imap filespec +Print the location of the inode data structure (in the inode table) +of the inode +.IR filespec . +.TP .I initialize device blocksize Create an ext2 file system on .I device diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index e6bcdba..651bd7b 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1463,6 +1463,8 @@ void do_bmap(int argc, char *argv[]) return; ino = string_to_inode(argv[1]); + if (!ino) + return; blk = parse_ulong(argv[2], argv[0], "logical_block", &err); errcode = ext2fs_bmap(current_fs, ino, 0, 0, 0, blk, &pblk); @@ -1474,6 +1476,38 @@ void do_bmap(int argc, char *argv[]) printf("%d\n", pblk); } +void do_imap(int argc, char *argv[]) +{ + ext2_ino_t ino; + unsigned long group, block, block_nr, offset; + + if (common_args_process(argc, argv, 2, 2, argv[0], + "", 0)) + return; + ino = string_to_inode(argv[1]); + if (!ino) + return 0; + + group = (ino - 1) / EXT2_INODES_PER_GROUP(current_fs->super); + offset = ((ino - 1) % EXT2_INODES_PER_GROUP(current_fs->super)) * + EXT2_INODE_SIZE(current_fs->super); + block = offset >> EXT2_BLOCK_SIZE_BITS(current_fs->super); + if (!current_fs->group_desc[(unsigned)group].bg_inode_table) { + com_err(argv[0], 0, "Inode table for group %d is missing\n", + group); + return; + } + block_nr = current_fs->group_desc[(unsigned)group].bg_inode_table + + block; + offset &= (EXT2_BLOCK_SIZE(current_fs->super) - 1); + + printf("Inode %d is part of block group %d\n" + "\tlocated at block %d, offset 0x%04x\n", ino, group, + block_nr, offset); + +} + + static int source_file(const char *cmd_file, int sci_idx) { diff --git a/debugfs/debugfs.h b/debugfs/debugfs.h index d8a5b8f..e30d95e 100644 --- a/debugfs/debugfs.h +++ b/debugfs/debugfs.h @@ -111,4 +111,5 @@ extern void do_show_debugfs_params(int argc, char **argv); extern void do_expand_dir(int argc, char **argv); extern void do_features(int argc, char **argv); extern void do_bmap(int argc, char **argv); +extern void do_imap(int argc, char **argv); -- 1.8.3.1