Create a command that will dump an entire inode's space in hex.
[ Modified by tytso to add a description to the man page, and to add
the more formal command name, inode_dump, in addition to short
command name of "idump". ]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
zap_block, zap;
request do_block_dump, "Dump contents of a block",
- block_dump, bd;
+ block_dump, bdump, bd;
request do_list_quota, "List quota",
list_quota, lq;
request do_get_quota, "Get quota",
get_quota, gq;
+request do_idump, "Dump the inode structure in hex",
+ inode_dump, idump, id;
+
+
end;
Print a listing of the inodes which use the one or more blocks specified
on the command line.
.TP
+.BI inode_dump " filespec"
+Print the contents of the inode data structure in hex and ASCII format.
+.TP
.BI imap " filespec"
Print the location of the inode data structure (in the inode table)
of the inode
}
+void do_idump(int argc, char *argv[])
+{
+ ext2_ino_t ino;
+ char *buf;
+ errcode_t err;
+ int isize;
+
+ if (common_args_process(argc, argv, 2, 2, argv[0],
+ "<file>", 0))
+ return;
+ ino = string_to_inode(argv[1]);
+ if (!ino)
+ return;
+
+ isize = EXT2_INODE_SIZE(current_fs->super);
+ err = ext2fs_get_mem(isize, &buf);
+ if (err) {
+ com_err(argv[0], err, "while allocating memory");
+ return;
+ }
+
+ err = ext2fs_read_inode_full(current_fs, ino,
+ (struct ext2_inode *)buf, isize);
+ if (err) {
+ com_err(argv[0], err, "while reading inode %d", ino);
+ goto err;
+ }
+
+ do_byte_hexdump(stdout, buf, isize);
+err:
+ ext2fs_free_mem(&buf);
+}
+
#ifndef READ_ONLY
void do_set_current_time(int argc, char *argv[])
{
/* zap.c */
extern void do_zap_block(int argc, char **argv);
extern void do_block_dump(int argc, char **argv);
+extern void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize);
char *file = NULL;
unsigned int i, j;
int c, err;
- int suppress = -1;
if (check_fs_open(argv[0]))
return;
goto errout;
}
- for (i=0; i < current_fs->blocksize; i += 16) {
+ do_byte_hexdump(stdout, buf, current_fs->blocksize);
+errout:
+ free(buf);
+}
+
+void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize)
+{
+ size_t i, j;
+ int suppress = -1;
+
+ for (i = 0; i < bufsize; i += 16) {
if (suppress < 0) {
if (i && memcmp(buf + i, buf + i - 16, 16) == 0) {
suppress = i;
- printf("*\n");
+ fprintf(fp, "*\n");
continue;
}
} else {
continue;
suppress = -1;
}
- printf("%04o ", i);
+ fprintf(fp, "%04o ", (unsigned int)i);
for (j = 0; j < 16; j++) {
- printf("%02x", buf[i+j]);
+ fprintf(fp, "%02x", buf[i+j]);
if ((j % 2) == 1)
- putchar(' ');
+ fprintf(fp, " ");
}
- putchar(' ');
+ fprintf(fp, " ");
for (j = 0; j < 16; j++)
- printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
- putchar('\n');
+ fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+ fprintf(fp, "\n");
}
- putchar('\n');
-
-errout:
- free(buf);
- return;
+ fprintf(fp, "\n");
}