#include "debugfs.h"
-void do_zap_block(int argc, char *argv[])
+void do_zap_block(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
+ void *infop EXT2FS_ATTR((unused)))
{
unsigned long pattern = 0;
unsigned char *buf;
return;
}
-void do_block_dump(int argc, char *argv[])
+void do_block_dump(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
+ void *infop EXT2FS_ATTR((unused)))
{
unsigned char *buf;
ext2_ino_t inode;
errcode_t errcode;
blk64_t block;
char *file = NULL;
- unsigned int i, j;
+ int xattr_dump = 0;
int c, err;
- int suppress = -1;
if (check_fs_open(argv[0]))
return;
reset_getopt();
- while ((c = getopt (argc, argv, "f:")) != EOF) {
+ while ((c = getopt (argc, argv, "f:x")) != EOF) {
switch (c) {
case 'f':
file = optarg;
break;
-
+ case 'x':
+ xattr_dump = 1;
+ break;
default:
goto print_usage;
}
}
- if (argc != optind+1) {
+ if (argc != optind + 1) {
print_usage:
- com_err(0, 0, "Usage: dump_block [-f file] "
- " block_num");
+ com_err(0, 0, "Usage: block_dump [-x] [-f inode] block_num");
return;
}
goto errout;
}
- for (i=0; i < current_fs->blocksize; i += 16) {
+ if (xattr_dump)
+ block_xattr_dump(stdout, buf, current_fs->blocksize);
+ else
+ 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, 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;
- printf("*\n");
+ fprintf(fp, "*\n");
continue;
}
} else {
- if (memcmp(buf + i, buf + suppress, 16) == 0)
+ if (memcmp(buf + i, buf + suppress, max) == 0)
continue;
suppress = -1;
}
- printf("%04o ", i);
+ fprintf(fp, "%04o ", (unsigned int)i);
for (j = 0; j < 16; j++) {
- printf("%02x", buf[i+j]);
+ if (j < max)
+ fprintf(fp, "%02x", buf[i+j]);
+ else
+ fprintf(fp, " ");
if ((j % 2) == 1)
- putchar(' ');
+ fprintf(fp, " ");
}
- putchar(' ');
- for (j = 0; j < 16; j++)
- printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
- putchar('\n');
+ fprintf(fp, " ");
+ for (j = 0; j < max; j++)
+ fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+ fprintf(fp, "\n");
}
- putchar('\n');
-
-errout:
- free(buf);
- return;
+ fprintf(fp, "\n");
}