Print a listing of the inodes which use the one or more blocks specified
on the command line.
.TP
-.BI inode_dump " filespec"
+.BI inode_dump " [-b]|[-e] filespec"
Print the contents of the inode data structure in hex and ASCII format.
+The
+.I \-b
+option causes the command to only dump the contents of the
+.B i_blocks
+array. The
+.I \-e
+option causes the command to only dump the contents of the extra inode
+space, which is used to store in-line extended attributes.
.TP
.BI imap " filespec"
Print the location of the inode data structure (in the inode table)
void do_idump(int argc, char *argv[])
{
+ struct ext2_inode_large *inode;
ext2_ino_t ino;
unsigned char *buf;
errcode_t err;
- int isize;
+ unsigned int isize, size, offset = 0;
+ int c, mode = 0;
- if (common_args_process(argc, argv, 2, 2, argv[0],
- "<file>", 0))
+ reset_getopt();
+ while ((c = getopt (argc, argv, "be")) != EOF) {
+ if (mode || c == '?') {
+ print_usage:
+ com_err(argv[0], 0,
+ "Usage: inode_dump [-b]|[-e] <file>");
+ return;
+ }
+ mode = c;
+ }
+ if (optind != argc-1)
return;
- ino = string_to_inode(argv[1]);
+
+ if (check_fs_open(argv[0]))
+ return;
+
+ ino = string_to_inode(argv[optind]);
if (!ino)
return;
goto err;
}
- do_byte_hexdump(stdout, buf, isize);
+ inode = (struct ext2_inode_large *) buf;
+ size = isize;
+ switch (mode) {
+ case 'b':
+ offset = ((char *) (&inode->i_block)) - ((char *) buf);
+ size = sizeof(inode->i_block);
+ break;
+ case 'e':
+ if (size <= EXT2_GOOD_OLD_INODE_SIZE) {
+ no_extra_space:
+ com_err(argv[0], 0, "No extra space in inode");
+ goto err;
+ }
+ offset = EXT2_GOOD_OLD_INODE_SIZE + inode->i_extra_isize;
+ if (offset > size)
+ goto err;
+ size -= offset;
+ break;
+ }
+ do_byte_hexdump(stdout, buf + offset, size);
err:
ext2fs_free_mem(&buf);
}
void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize)
{
- size_t i, j;
+ size_t i, j, max;
int suppress = -1;
for (i = 0; i < bufsize; i += 16) {
+ max = (bufsize - i > 16) ? 16 : bufsize - i;
if (suppress < 0) {
- if (i && memcmp(buf + i, buf + i - 16, 16) == 0) {
+ if (i && memcmp(buf + i, buf + i - max, max) == 0) {
suppress = i;
fprintf(fp, "*\n");
continue;
}
} else {
- if (memcmp(buf + i, buf + suppress, 16) == 0)
+ if (memcmp(buf + i, buf + suppress, max) == 0)
continue;
suppress = -1;
}
fprintf(fp, "%04o ", (unsigned int)i);
for (j = 0; j < 16; j++) {
- fprintf(fp, "%02x", buf[i+j]);
+ if (j < max)
+ fprintf(fp, "%02x", buf[i+j]);
+ else
+ fprintf(fp, " ");
if ((j % 2) == 1)
fprintf(fp, " ");
}
fprintf(fp, " ");
- for (j = 0; j < 16; j++)
+ for (j = 0; j < max; j++)
fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
fprintf(fp, "\n");
}