2 * dumpe2fs.c - List the control structures of a second
5 * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
6 * Laboratoire MASI, Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
9 * This file can be redistributed under the terms of the GNU General
16 * 94/02/27 - Ported to use the ext2fs library
26 #include <linux/ext2_fs.h>
28 #include "ext2fs/ext2fs.h"
31 #include "../version.h"
33 #define in_use(m, x) (test_bit ((x), (m)))
35 const char * program_name = "dumpe2fs";
36 char * device_name = NULL;
38 static volatile void usage (void)
40 fprintf (stderr, "usage: %s device\n", program_name);
44 static void print_free (unsigned long group, char * bitmap,
45 unsigned long nbytes, unsigned long offset)
51 for (i = 0; i < nbytes; i++)
52 if (!in_use (bitmap, i))
56 if (i == nbytes - 1 || in_use (bitmap, i + 1))
57 printf ("%lu", group * nbytes + i + offset);
60 for (j = i; j < nbytes && !in_use (bitmap, j);
63 printf ("%lu-%lu", group * nbytes + i + offset,
64 group * nbytes + (j - 1) + offset);
71 static void list_desc (ext2_filsys fs)
74 char * block_bitmap = fs->block_map;
75 char * inode_bitmap = fs->inode_map;
78 for (i = 0; i < fs->group_desc_count; i++)
80 printf ("Group %lu:\n", i);
81 printf (" Block bitmap at %lu, Inode bitmap at %lu, "
82 "Inode table at %lu\n",
83 fs->group_desc[i].bg_block_bitmap,
84 fs->group_desc[i].bg_inode_bitmap,
85 fs->group_desc[i].bg_inode_table);
86 printf (" %d free blocks, %d free inodes, %d directories\n",
87 fs->group_desc[i].bg_free_blocks_count,
88 fs->group_desc[i].bg_free_inodes_count,
89 fs->group_desc[i].bg_used_dirs_count);
90 printf (" Free blocks: ");
91 print_free (i, block_bitmap, fs->super->s_blocks_per_group,
92 fs->super->s_first_data_block);
93 block_bitmap += fs->super->s_blocks_per_group / 8;
95 printf (" Free inodes: ");
96 print_free (i, inode_bitmap, fs->super->s_inodes_per_group, 1);
97 inode_bitmap += fs->super->s_inodes_per_group / 8;
102 static void list_bad_blocks(ext2_filsys fs)
104 badblocks_list bb_list = 0;
105 badblocks_iterate bb_iter;
109 retval = ext2fs_read_bb_inode(fs, &bb_list);
111 com_err("ext2fs_read_bb_inode", retval, "");
114 retval = badblocks_list_iterate_begin(bb_list, &bb_iter);
116 com_err("badblocks_list_iterate_begin", retval,
117 "while printing bad block list");
120 if (badblocks_list_iterate(bb_iter, &blk))
121 printf("Bad blocks: %ld", blk);
122 while (badblocks_list_iterate(bb_iter, &blk))
123 printf(", %ld", blk);
124 badblocks_list_iterate_end(bb_iter);
128 void main (int argc, char ** argv)
133 fprintf (stderr, "dumpe2fs %s, %s for EXT2 FS %s, %s\n",
134 E2FSPROGS_VERSION, E2FSPROGS_DATE,
135 EXT2FS_VERSION, EXT2FS_DATE);
137 program_name = *argv;
140 device_name = argv[1];
141 retval = ext2fs_open (device_name, 0, 0, 0, unix_io_manager, &fs);
144 com_err (program_name, retval, "while trying to open %s",
146 printf ("Couldn't find valid filesystem superblock.\n");
149 retval = ext2fs_read_bitmaps (fs);
152 com_err (program_name, retval, "while trying to read the bitmaps",
157 list_super (fs->super);
158 list_bad_blocks (fs);