summaryrefslogtreecommitdiff
path: root/misc/dumpe2fs.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2001-12-02 19:29:35 +0100
committerTheodore Ts'o <tytso@mit.edu>2001-12-02 19:29:35 +0100
commita5f0bb9d1b295ad907b2d8a58ce9121f4105e1a8 (patch)
tree22ec5502a27707ba53eadec472af6edc0a46a69c /misc/dumpe2fs.c
parent571fc5a89c17985626df29823617b63094d10b31 (diff)
downloade2fsprogs-a5f0bb9d1b295ad907b2d8a58ce9121f4105e1a8.tar.gz
Pull up dumpe2fs cleanup patch from the experimental branch.
Diffstat (limited to 'misc/dumpe2fs.c')
-rw-r--r--misc/dumpe2fs.c123
1 files changed, 64 insertions, 59 deletions
diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c
index 0f23ff16..87e563f8 100644
--- a/misc/dumpe2fs.c
+++ b/misc/dumpe2fs.c
@@ -45,7 +45,7 @@ extern int optind;
const char * program_name = "dumpe2fs";
char * device_name = NULL;
-int opt_hex = 0;
+char *num_format = "%lu";
static void usage(void)
{
@@ -61,23 +61,19 @@ static void print_free (unsigned long group, char * bitmap,
unsigned long i;
unsigned long j;
+ offset += group * nbytes;
for (i = 0; i < nbytes; i++)
if (!in_use (bitmap, i))
{
if (p)
printf (", ");
- if (i == nbytes - 1 || in_use (bitmap, i + 1))
- printf (opt_hex ? "0x%04x" : "%lu",
- group * nbytes + i + offset);
- else
- {
- for (j = i; j < nbytes && !in_use (bitmap, j);
- j++)
- ;
- printf (opt_hex ? "0x%04lx-0x%04lx" :
- "%lu-%lu", group * nbytes + i + offset,
- group * nbytes + (j - 1) + offset);
- i = j - 1;
+ printf (num_format, i + offset);
+ for (j = i; j < nbytes && !in_use (bitmap, j); j++)
+ ;
+ if (--j != i) {
+ fputc('-', stdout);
+ printf(num_format, j + offset);
+ i = j;
}
p = 1;
}
@@ -86,6 +82,7 @@ static void print_free (unsigned long group, char * bitmap,
static void list_desc (ext2_filsys fs)
{
unsigned long i;
+ long diff;
blk_t group_blk, next_blk;
char * block_bitmap = fs->block_map->bitmap;
char * inode_bitmap = fs->inode_map->bitmap;
@@ -103,50 +100,57 @@ static void list_desc (ext2_filsys fs)
EXT2_DESC_PER_BLOCK(fs->super) - 1) /
EXT2_DESC_PER_BLOCK(fs->super);
- printf ("\n");
+ fputc('\n', stdout);
group_blk = fs->super->s_first_data_block;
for (i = 0; i < fs->group_desc_count; i++) {
next_blk = group_blk + fs->super->s_blocks_per_group;
if (next_blk > fs->super->s_blocks_count)
next_blk = fs->super->s_blocks_count;
- printf (opt_hex ? _("Group %lu: (Blocks 0x%04x -- 0x%04x)\n"):
- _("Group %lu: (Blocks %u -- %u)\n"), i,
- group_blk, next_blk -1 );
- if (ext2fs_bg_has_super (fs, i))
- printf (opt_hex ? _(" %s Superblock at 0x%04x,"
- " Group Descriptors at 0x%04x-0x%04x\n"):
- _(" %s Superblock at %u,"
- " Group Descriptors at %u-%u\n"),
- i == 0 ? _("Primary") : _("Backup"),
- group_blk, group_blk + 1,
- group_blk + group_desc_blocks);
- printf (opt_hex ? _(" Block bitmap at 0x%04x (+%d), "
- "Inode bitmap at 0x%04x (+%d)\n "
- "Inode table at 0x%04x-0x%04x (+%d)\n"):
- _(" Block bitmap at %u (+%d), "
- "Inode bitmap at %u (+%d)\n "
- "Inode table at %u-%u (+%d)\n"),
- fs->group_desc[i].bg_block_bitmap,
- fs->group_desc[i].bg_block_bitmap - group_blk,
- fs->group_desc[i].bg_inode_bitmap,
- fs->group_desc[i].bg_inode_bitmap - group_blk,
- fs->group_desc[i].bg_inode_table,
- fs->group_desc[i].bg_inode_table +
- inode_blocks_per_group - 1,
- fs->group_desc[i].bg_inode_table - group_blk);
- printf (_(" %d free blocks, %d free inodes, %d directories\n"),
+ printf (_("Group %lu: (Blocks "), i);
+ printf(num_format, group_blk);
+ fputc('-', stdout);
+ printf(num_format, next_blk - 1);
+ fputs(")\n", stdout);
+ if (ext2fs_bg_has_super (fs, i)) {
+ printf (_(" %s Superblock at "),
+ i == 0 ? _("Primary") : _("Backup"));
+ printf(num_format, group_blk);
+ printf(_(", Group Descriptors at "));
+ printf(num_format, group_blk+1);
+ fputc('-', stdout);
+ printf(num_format, group_blk + group_desc_blocks);
+ fputc('\n', stdout);
+ }
+ fputs(_(" Block bitmap at "), stdout);
+ printf(num_format, fs->group_desc[i].bg_block_bitmap);
+ diff = fs->group_desc[i].bg_block_bitmap - group_blk;
+ if (diff >= 0)
+ printf(" (+%d)", diff);
+ fputs(_(", Inode bitmap at "), stdout);
+ printf(num_format, fs->group_desc[i].bg_inode_bitmap);
+ diff = fs->group_desc[i].bg_inode_bitmap - group_blk;
+ if (diff >= 0)
+ printf(" (+%d)", diff);
+ fputs(_("\n Inode table at "), stdout);
+ printf(num_format, fs->group_desc[i].bg_inode_table);
+ fputc('-', stdout);
+ printf(num_format, fs->group_desc[i].bg_inode_table +
+ inode_blocks_per_group - 1);
+ diff = fs->group_desc[i].bg_inode_table - group_blk;
+ if (diff > 0)
+ printf(" (+%d)", diff);
+ printf (_("\n %d free blocks, %d free inodes, "
+ "%d directories\n Free blocks: "),
fs->group_desc[i].bg_free_blocks_count,
fs->group_desc[i].bg_free_inodes_count,
fs->group_desc[i].bg_used_dirs_count);
- printf (_(" Free blocks: "));
print_free (i, block_bitmap, fs->super->s_blocks_per_group,
fs->super->s_first_data_block);
- block_bitmap += fs->super->s_blocks_per_group / 8;
- printf ("\n");
- printf (_(" Free inodes: "));
+ fputs(_("\n Free inodes: "), stdout);
print_free (i, inode_bitmap, fs->super->s_inodes_per_group, 1);
+ fputc('\n', stdout);
+ block_bitmap += fs->super->s_blocks_per_group / 8;
inode_bitmap += fs->super->s_inodes_per_group / 8;
- printf ("\n");
group_blk = next_blk;
}
}
@@ -174,7 +178,7 @@ static void list_bad_blocks(ext2_filsys fs)
while (ext2fs_badblocks_list_iterate(bb_iter, &blk))
printf(", %d", blk);
ext2fs_badblocks_list_iterate_end(bb_iter);
- printf("\n");
+ fputc('\n', stdout);
}
static void dump_bad_blocks(ext2_filsys fs)
@@ -223,20 +227,21 @@ static void print_journal_information(ext2_filsys fs)
exit(1);
}
- fputs("\n", stdout);
- printf("Journal block size: %d\n", ntohl(jsb->s_blocksize));
- printf("Journal length: %d\n", ntohl(jsb->s_maxlen));
- printf("Journal first block: %d\n", ntohl(jsb->s_first));
- printf("Journal sequence: 0x%08x\n", ntohl(jsb->s_sequence));
- printf("Journal start: %d\n", ntohl(jsb->s_start));
- printf("Journal number of users: %d\n", ntohl(jsb->s_nr_users));
+ printf(_("\nJournal block size: %d\n"
+ "Journal length: %d\n"
+ "Journal first block: %d\n"
+ "Journal sequence: 0x%08x\n"
+ "Journal start: %d\n"
+ "Journal number of users: %d\n"),
+ ntohl(jsb->s_blocksize), ntohl(jsb->s_maxlen),
+ ntohl(jsb->s_first), ntohl(jsb->s_sequence),
+ ntohl(jsb->s_start), ntohl(jsb->s_nr_users));
+
for (i=0; i < ntohl(jsb->s_nr_users); i++) {
- if (i)
- printf(" ");
- else
- printf("Journal users: ");
uuid_unparse(&jsb->s_users[i*16], str);
- printf("%s\n", str);
+ printf(i ? " %s\n"
+ : "Journal users: %s\n",
+ str);
}
}
@@ -293,7 +298,7 @@ int main (int argc, char ** argv)
error_message(EXT2_ET_BASE));
exit(0);
case 'x':
- opt_hex=1;
+ num_format = "0x%04x";
break;
default:
usage();