Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / misc / dumpe2fs.c
1 /*
2  * dumpe2fs.c           - List the control structures of a second
3  *                        extended filesystem
4  *
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)
8  *
9  * Copyright 1995, 1996, 1997 by Theodore Ts'o.
10  *
11  * %Begin-Header%
12  * This file may be redistributed under the terms of the GNU Public
13  * License.
14  * %End-Header%
15  */
16
17 /*
18  * History:
19  * 94/01/09     - Creation
20  * 94/02/27     - Ported to use the ext2fs library
21  */
22
23 #include "config.h"
24 #ifdef HAVE_GETOPT_H
25 #include <getopt.h>
26 #else
27 extern char *optarg;
28 extern int optind;
29 #endif
30 #include <fcntl.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <unistd.h>
35
36 #include "ext2fs/ext2_fs.h"
37
38 #include "ext2fs/ext2fs.h"
39 #include "e2p/e2p.h"
40 #include "jfs_user.h"
41 #include <uuid/uuid.h>
42
43 #include "../version.h"
44 #include "nls-enable.h"
45 #include "plausible.h"
46
47 #define in_use(m, x)    (ext2fs_test_bit ((x), (m)))
48
49 static const char * program_name = "dumpe2fs";
50 static char * device_name = NULL;
51 static int hex_format = 0;
52 static int blocks64 = 0;
53
54 static void usage(void)
55 {
56         fprintf(stderr, _("Usage: %s [-bfghixV] [-o superblock=<num>] "
57                  "[-o blocksize=<num>] device\n"), program_name);
58         exit(1);
59 }
60
61 static void print_number(unsigned long long num)
62 {
63         if (hex_format) {
64                 if (blocks64)
65                         printf("0x%08llx", num);
66                 else
67                         printf("0x%04llx", num);
68         } else
69                 printf("%llu", num);
70 }
71
72 static void print_range(unsigned long long a, unsigned long long b)
73 {
74         if (hex_format) {
75                 if (blocks64)
76                         printf("0x%08llx-0x%08llx", a, b);
77                 else
78                         printf("0x%04llx-0x%04llx", a, b);
79         } else
80                 printf("%llu-%llu", a, b);
81 }
82
83 static void print_free(unsigned long group, char * bitmap,
84                        unsigned long num, unsigned long offset, int ratio)
85 {
86         int p = 0;
87         unsigned long i;
88         unsigned long j;
89
90         offset /= ratio;
91         offset += group * num;
92         for (i = 0; i < num; i++)
93                 if (!in_use (bitmap, i))
94                 {
95                         if (p)
96                                 printf (", ");
97                         print_number((i + offset) * ratio);
98                         for (j = i; j < num && !in_use (bitmap, j); j++)
99                                 ;
100                         if (--j != i) {
101                                 fputc('-', stdout);
102                                 print_number((j + offset) * ratio);
103                                 i = j;
104                         }
105                         p = 1;
106                 }
107 }
108
109 static void print_bg_opt(int bg_flags, int mask,
110                           const char *str, int *first)
111 {
112         if (bg_flags & mask) {
113                 if (*first) {
114                         fputs(" [", stdout);
115                         *first = 0;
116                 } else
117                         fputs(", ", stdout);
118                 fputs(str, stdout);
119         }
120 }
121 static void print_bg_opts(ext2_filsys fs, dgrp_t i)
122 {
123         int first = 1, bg_flags = 0;
124
125         if (ext2fs_has_group_desc_csum(fs))
126                 bg_flags = ext2fs_bg_flags(fs, i);
127
128         print_bg_opt(bg_flags, EXT2_BG_INODE_UNINIT, "INODE_UNINIT",
129                      &first);
130         print_bg_opt(bg_flags, EXT2_BG_BLOCK_UNINIT, "BLOCK_UNINIT",
131                      &first);
132         print_bg_opt(bg_flags, EXT2_BG_INODE_ZEROED, "ITABLE_ZEROED",
133                      &first);
134         if (!first)
135                 fputc(']', stdout);
136         fputc('\n', stdout);
137 }
138
139 static void print_bg_rel_offset(ext2_filsys fs, blk64_t block, int itable,
140                                 blk64_t first_block, blk64_t last_block)
141 {
142         if ((block >= first_block) && (block <= last_block)) {
143                 if (itable && block == first_block)
144                         return;
145                 printf(" (+%u)", (unsigned)(block - first_block));
146         } else if (fs->super->s_feature_incompat &
147                    EXT4_FEATURE_INCOMPAT_FLEX_BG) {
148                 dgrp_t flex_grp = ext2fs_group_of_blk2(fs, block);
149                 printf(" (bg #%u + %u)", flex_grp,
150                        (unsigned)(block-ext2fs_group_first_block2(fs,flex_grp)));
151         }
152 }
153
154 static void list_desc(ext2_filsys fs, int grp_only)
155 {
156         unsigned long i;
157         blk64_t first_block, last_block;
158         blk64_t super_blk, old_desc_blk, new_desc_blk;
159         char *block_bitmap=NULL, *inode_bitmap=NULL;
160         const char *units = _("blocks");
161         int inode_blocks_per_group, old_desc_blocks, reserved_gdt;
162         int             block_nbytes, inode_nbytes;
163         int has_super;
164         blk64_t         blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block);
165         ext2_ino_t      ino_itr = 1;
166         errcode_t       retval;
167
168         if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
169                                        EXT4_FEATURE_RO_COMPAT_BIGALLOC))
170                 units = _("clusters");
171
172         block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8;
173         inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;
174
175         if (fs->block_map)
176                 block_bitmap = malloc(block_nbytes);
177         if (fs->inode_map)
178                 inode_bitmap = malloc(inode_nbytes);
179
180         inode_blocks_per_group = ((fs->super->s_inodes_per_group *
181                                    EXT2_INODE_SIZE(fs->super)) +
182                                   EXT2_BLOCK_SIZE(fs->super) - 1) /
183                                  EXT2_BLOCK_SIZE(fs->super);
184         reserved_gdt = fs->super->s_reserved_gdt_blocks;
185         fputc('\n', stdout);
186         first_block = fs->super->s_first_data_block;
187         if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
188                 old_desc_blocks = fs->super->s_first_meta_bg;
189         else
190                 old_desc_blocks = fs->desc_blocks;
191         if (grp_only)
192                 printf("group:block:super:gdt:bbitmap:ibitmap:itable\n");
193         for (i = 0; i < fs->group_desc_count; i++) {
194                 first_block = ext2fs_group_first_block2(fs, i);
195                 last_block = ext2fs_group_last_block2(fs, i);
196
197                 ext2fs_super_and_bgd_loc2(fs, i, &super_blk,
198                                           &old_desc_blk, &new_desc_blk, 0);
199
200                 if (grp_only) {
201                         printf("%lu:%llu:", i, first_block);
202                         if (i == 0 || super_blk)
203                                 printf("%llu:", super_blk);
204                         else
205                                 printf("-1:");
206                         if (old_desc_blk) {
207                                 print_range(old_desc_blk,
208                                             old_desc_blk + old_desc_blocks - 1);
209                                 printf(":");
210                         } else if (new_desc_blk)
211                                 printf("%llu:", new_desc_blk);
212                         else
213                                 printf("-1:");
214                         printf("%llu:%llu:%llu\n",
215                                ext2fs_block_bitmap_loc(fs, i),
216                                ext2fs_inode_bitmap_loc(fs, i),
217                                ext2fs_inode_table_loc(fs, i));
218                         continue;
219                 }
220
221                 printf (_("Group %lu: (Blocks "), i);
222                 print_range(first_block, last_block);
223                 fputs(")", stdout);
224                 print_bg_opts(fs, i);
225                 if (ext2fs_has_group_desc_csum(fs)) {
226                         unsigned csum = ext2fs_bg_checksum(fs, i);
227                         unsigned exp_csum = ext2fs_group_desc_csum(fs, i);
228
229                         printf(_("  Checksum 0x%04x"), csum);
230                         if (csum != exp_csum)
231                                 printf(_(" (EXPECTED 0x%04x)"), exp_csum);
232                         printf(_(", unused inodes %u\n"),
233                                ext2fs_bg_itable_unused(fs, i));
234                 }
235                 has_super = ((i==0) || super_blk);
236                 if (has_super) {
237                         printf (_("  %s superblock at "),
238                                 i == 0 ? _("Primary") : _("Backup"));
239                         print_number(super_blk);
240                 }
241                 if (old_desc_blk) {
242                         printf("%s", _(", Group descriptors at "));
243                         print_range(old_desc_blk,
244                                     old_desc_blk + old_desc_blocks - 1);
245                         if (reserved_gdt) {
246                                 printf("%s", _("\n  Reserved GDT blocks at "));
247                                 print_range(old_desc_blk + old_desc_blocks,
248                                             old_desc_blk + old_desc_blocks +
249                                             reserved_gdt - 1);
250                         }
251                 } else if (new_desc_blk) {
252                         fputc(has_super ? ',' : ' ', stdout);
253                         printf("%s", _(" Group descriptor at "));
254                         print_number(new_desc_blk);
255                         has_super++;
256                 }
257                 if (has_super)
258                         fputc('\n', stdout);
259                 fputs(_("  Block bitmap at "), stdout);
260                 print_number(ext2fs_block_bitmap_loc(fs, i));
261                 print_bg_rel_offset(fs, ext2fs_block_bitmap_loc(fs, i), 0,
262                                     first_block, last_block);
263                 if (fs->super->s_feature_ro_compat &
264                     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
265                         printf(_(", csum 0x%08x"),
266                                ext2fs_block_bitmap_checksum(fs, i));
267                 fputs(_(", Inode bitmap at "), stdout);
268                 print_number(ext2fs_inode_bitmap_loc(fs, i));
269                 print_bg_rel_offset(fs, ext2fs_inode_bitmap_loc(fs, i), 0,
270                                     first_block, last_block);
271                 if (fs->super->s_feature_ro_compat &
272                     EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
273                         printf(_(", csum 0x%08x"),
274                                ext2fs_inode_bitmap_checksum(fs, i));
275                 fputs(_("\n  Inode table at "), stdout);
276                 print_range(ext2fs_inode_table_loc(fs, i),
277                             ext2fs_inode_table_loc(fs, i) +
278                             inode_blocks_per_group - 1);
279                 print_bg_rel_offset(fs, ext2fs_inode_table_loc(fs, i), 1,
280                                     first_block, last_block);
281                 printf (_("\n  %u free %s, %u free inodes, "
282                           "%u directories%s"),
283                         ext2fs_bg_free_blocks_count(fs, i), units,
284                         ext2fs_bg_free_inodes_count(fs, i),
285                         ext2fs_bg_used_dirs_count(fs, i),
286                         ext2fs_bg_itable_unused(fs, i) ? "" : "\n");
287                 if (ext2fs_bg_itable_unused(fs, i))
288                         printf (_(", %u unused inodes\n"),
289                                 ext2fs_bg_itable_unused(fs, i));
290                 if (block_bitmap) {
291                         fputs(_("  Free blocks: "), stdout);
292                         retval = ext2fs_get_block_bitmap_range2(fs->block_map,
293                                  blk_itr, block_nbytes << 3, block_bitmap);
294                         if (retval)
295                                 com_err("list_desc", retval,
296                                         "while reading block bitmap");
297                         else
298                                 print_free(i, block_bitmap,
299                                            fs->super->s_clusters_per_group,
300                                            fs->super->s_first_data_block,
301                                            EXT2FS_CLUSTER_RATIO(fs));
302                         fputc('\n', stdout);
303                         blk_itr += fs->super->s_clusters_per_group;
304                 }
305                 if (inode_bitmap) {
306                         fputs(_("  Free inodes: "), stdout);
307                         retval = ext2fs_get_inode_bitmap_range2(fs->inode_map,
308                                  ino_itr, inode_nbytes << 3, inode_bitmap);
309                         if (retval)
310                                 com_err("list_desc", retval,
311                                         "while reading inode bitmap");
312                         else
313                                 print_free(i, inode_bitmap,
314                                            fs->super->s_inodes_per_group,
315                                            1, 1);
316                         fputc('\n', stdout);
317                         ino_itr += fs->super->s_inodes_per_group;
318                 }
319         }
320         if (block_bitmap)
321                 free(block_bitmap);
322         if (inode_bitmap)
323                 free(inode_bitmap);
324 }
325
326 static void list_bad_blocks(ext2_filsys fs, int dump)
327 {
328         badblocks_list          bb_list = 0;
329         badblocks_iterate       bb_iter;
330         blk_t                   blk;
331         errcode_t               retval;
332         const char              *header, *fmt;
333
334         retval = ext2fs_read_bb_inode(fs, &bb_list);
335         if (retval) {
336                 com_err("ext2fs_read_bb_inode", retval, 0);
337                 return;
338         }
339         retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
340         if (retval) {
341                 com_err("ext2fs_badblocks_list_iterate_begin", retval,
342                         "%s", _("while printing bad block list"));
343                 return;
344         }
345         if (dump) {
346                 header = fmt = "%u\n";
347         } else {
348                 header =  _("Bad blocks: %u");
349                 fmt = ", %u";
350         }
351         while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) {
352                 printf(header ? header : fmt, blk);
353                 header = 0;
354         }
355         ext2fs_badblocks_list_iterate_end(bb_iter);
356         if (!dump)
357                 fputc('\n', stdout);
358         ext2fs_badblocks_list_free(bb_list);
359 }
360
361 static const char *journal_checksum_type_str(__u8 type)
362 {
363         switch (type) {
364         case JBD2_CRC32C_CHKSUM:
365                 return "crc32c";
366         default:
367                 return "unknown";
368         }
369 }
370
371 static void print_inline_journal_information(ext2_filsys fs)
372 {
373         journal_superblock_t    *jsb;
374         struct ext2_inode       inode;
375         ext2_file_t             journal_file;
376         errcode_t               retval;
377         ino_t                   ino = fs->super->s_journal_inum;
378         char                    buf[1024];
379         __u32                   *mask_ptr, mask, m;
380         int                     i, j, size, printed = 0;
381
382         if (fs->flags & EXT2_FLAG_IMAGE_FILE)
383                 return;
384         retval = ext2fs_read_inode(fs, ino,  &inode);
385         if (retval) {
386                 com_err(program_name, retval, "%s",
387                         _("while reading journal inode"));
388                 exit(1);
389         }
390         retval = ext2fs_file_open2(fs, ino, &inode, 0, &journal_file);
391         if (retval) {
392                 com_err(program_name, retval, "%s",
393                         _("while opening journal inode"));
394                 exit(1);
395         }
396         retval = ext2fs_file_read(journal_file, buf, sizeof(buf), 0);
397         if (retval) {
398                 com_err(program_name, retval, "%s",
399                         _("while reading journal super block"));
400                 exit(1);
401         }
402         ext2fs_file_close(journal_file);
403         jsb = (journal_superblock_t *) buf;
404         if (be32_to_cpu(jsb->s_header.h_magic) != JFS_MAGIC_NUMBER) {
405                 fprintf(stderr, "%s",
406                         _("Journal superblock magic number invalid!\n"));
407                 exit(1);
408         }
409         printf("%s", _("Journal features:        "));
410         for (i=0, mask_ptr=&jsb->s_feature_compat; i <3; i++,mask_ptr++) {
411                 mask = be32_to_cpu(*mask_ptr);
412                 for (j=0,m=1; j < 32; j++, m<<=1) {
413                         if (mask & m) {
414                                 printf(" %s", e2p_jrnl_feature2string(i, m));
415                                 printed++;
416                         }
417                 }
418         }
419         if (printed == 0)
420                 printf(" (none)");
421         printf("\n");
422         fputs(_("Journal size:             "), stdout);
423         if ((fs->super->s_feature_ro_compat &
424              EXT4_FEATURE_RO_COMPAT_HUGE_FILE) &&
425             (inode.i_flags & EXT4_HUGE_FILE_FL))
426                 size = inode.i_blocks / (fs->blocksize / 1024);
427         else
428                 size = inode.i_blocks >> 1;
429         if (size < 8192)
430                 printf("%uk\n", size);
431         else
432                 printf("%uM\n", size >> 10);
433         printf(_("Journal length:           %u\n"
434                  "Journal sequence:         0x%08x\n"
435                  "Journal start:            %u\n"),
436                (unsigned int)ntohl(jsb->s_maxlen),
437                (unsigned int)ntohl(jsb->s_sequence),
438                (unsigned int)ntohl(jsb->s_start));
439         if (jsb->s_feature_compat &
440             ext2fs_cpu_to_be32(JFS_FEATURE_COMPAT_CHECKSUM))
441                 printf("%s", _("Journal checksum type:    crc32\n"));
442         if ((jsb->s_feature_incompat &
443              ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
444             (jsb->s_feature_incompat &
445              ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V2)))
446                 printf(_("Journal checksum type:    %s\n"
447                          "Journal checksum:         0x%08x\n"),
448                        journal_checksum_type_str(jsb->s_checksum_type),
449                        ext2fs_be32_to_cpu(jsb->s_checksum));
450         if (jsb->s_errno != 0)
451                 printf(_("Journal errno:            %d\n"),
452                        (int) ntohl(jsb->s_errno));
453 }
454
455 static void print_journal_information(ext2_filsys fs)
456 {
457         errcode_t       retval;
458         char            buf[1024];
459         char            str[80];
460         unsigned int    i, j, printed = 0;
461         journal_superblock_t    *jsb;
462         __u32                   *mask_ptr, mask, m;
463
464         /* Get the journal superblock */
465         if ((retval = io_channel_read_blk64(fs->io,
466                                             fs->super->s_first_data_block + 1,
467                                             -1024, buf))) {
468                 com_err(program_name, retval, "%s",
469                         _("while reading journal superblock"));
470                 exit(1);
471         }
472         jsb = (journal_superblock_t *) buf;
473         if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) ||
474             (jsb->s_header.h_blocktype !=
475              (unsigned) ntohl(JFS_SUPERBLOCK_V2))) {
476                 com_err(program_name, 0, "%s",
477                         _("Couldn't find journal superblock magic numbers"));
478                 exit(1);
479         }
480
481         if (jsb->s_feature_compat &
482             ext2fs_cpu_to_be32(JFS_FEATURE_COMPAT_CHECKSUM))
483                 printf("%s", _("Journal checksum type:    crc32\n"));
484         if ((jsb->s_feature_incompat &
485              ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
486             (jsb->s_feature_incompat &
487              ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V2)))
488                 printf(_("Journal checksum type:    %s\n"
489                          "Journal checksum:         0x%08x\n"),
490                        journal_checksum_type_str(jsb->s_checksum_type),
491                        ext2fs_be32_to_cpu(jsb->s_checksum));
492
493         printf("%s", _("Journal features:        "));
494         for (i = 0, mask_ptr = &jsb->s_feature_compat; i < 3; i++, mask_ptr++) {
495                 mask = be32_to_cpu(*mask_ptr);
496                 for (j = 0, m = 1; j < 32; j++, m <<= 1) {
497                         if (mask & m) {
498                                 printf(" %s", e2p_jrnl_feature2string(i, m));
499                                 printed++;
500                         }
501                 }
502         }
503
504         printf(_("\nJournal block size:       %u\n"
505                  "Journal length:           %u\n"
506                  "Journal first block:      %u\n"
507                  "Journal sequence:         0x%08x\n"
508                  "Journal start:            %u\n"
509                  "Journal number of users:  %u\n"),
510                (unsigned int)ntohl(jsb->s_blocksize),  (unsigned int)ntohl(jsb->s_maxlen),
511                (unsigned int)ntohl(jsb->s_first), (unsigned int)ntohl(jsb->s_sequence),
512                (unsigned int)ntohl(jsb->s_start), (unsigned int)ntohl(jsb->s_nr_users));
513
514         for (i=0; i < ntohl(jsb->s_nr_users); i++) {
515                 uuid_unparse(&jsb->s_users[i*16], str);
516                 printf(i ? "                          %s\n"
517                        : _("Journal users:            %s\n"),
518                        str);
519         }
520 }
521
522 static void parse_extended_opts(const char *opts, blk64_t *superblock,
523                                 int *blocksize)
524 {
525         char    *buf, *token, *next, *p, *arg, *badopt = 0;
526         int     len;
527         int     do_usage = 0;
528
529         len = strlen(opts);
530         buf = malloc(len+1);
531         if (!buf) {
532                 fprintf(stderr, "%s",
533                         _("Couldn't allocate memory to parse options!\n"));
534                 exit(1);
535         }
536         strcpy(buf, opts);
537         for (token = buf; token && *token; token = next) {
538                 p = strchr(token, ',');
539                 next = 0;
540                 if (p) {
541                         *p = 0;
542                         next = p+1;
543                 }
544                 arg = strchr(token, '=');
545                 if (arg) {
546                         *arg = 0;
547                         arg++;
548                 }
549                 if (strcmp(token, "superblock") == 0 ||
550                     strcmp(token, "sb") == 0) {
551                         if (!arg) {
552                                 do_usage++;
553                                 badopt = token;
554                                 continue;
555                         }
556                         *superblock = strtoul(arg, &p, 0);
557                         if (*p) {
558                                 fprintf(stderr,
559                                         _("Invalid superblock parameter: %s\n"),
560                                         arg);
561                                 do_usage++;
562                                 continue;
563                         }
564                 } else if (strcmp(token, "blocksize") == 0 ||
565                            strcmp(token, "bs") == 0) {
566                         if (!arg) {
567                                 do_usage++;
568                                 badopt = token;
569                                 continue;
570                         }
571                         *blocksize = strtoul(arg, &p, 0);
572                         if (*p) {
573                                 fprintf(stderr,
574                                         _("Invalid blocksize parameter: %s\n"),
575                                         arg);
576                                 do_usage++;
577                                 continue;
578                         }
579                 } else {
580                         do_usage++;
581                         badopt = token;
582                 }
583         }
584         if (do_usage) {
585                 fprintf(stderr, _("\nBad extended option(s) specified: %s\n\n"
586                         "Extended options are separated by commas, "
587                         "and may take an argument which\n"
588                         "\tis set off by an equals ('=') sign.\n\n"
589                         "Valid extended options are:\n"
590                         "\tsuperblock=<superblock number>\n"
591                         "\tblocksize=<blocksize>\n"),
592                         badopt ? badopt : "");
593                 free(buf);
594                 exit(1);
595         }
596         free(buf);
597 }
598
599 int main (int argc, char ** argv)
600 {
601         errcode_t       retval;
602         ext2_filsys     fs;
603         int             print_badblocks = 0;
604         blk64_t         use_superblock = 0;
605         int             use_blocksize = 0;
606         int             image_dump = 0;
607         int             force = 0;
608         int             flags;
609         int             header_only = 0;
610         int             c;
611         int             grp_only = 0;
612
613 #ifdef ENABLE_NLS
614         setlocale(LC_MESSAGES, "");
615         setlocale(LC_CTYPE, "");
616         bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
617         textdomain(NLS_CAT_NAME);
618         set_com_err_gettext(gettext);
619 #endif
620         add_error_table(&et_ext2_error_table);
621         fprintf (stderr, "dumpe2fs %s (%s)\n", E2FSPROGS_VERSION,
622                  E2FSPROGS_DATE);
623         if (argc && *argv)
624                 program_name = *argv;
625
626         while ((c = getopt(argc, argv, "bfghixVo:")) != EOF) {
627                 switch (c) {
628                 case 'b':
629                         print_badblocks++;
630                         break;
631                 case 'f':
632                         force++;
633                         break;
634                 case 'g':
635                         grp_only++;
636                         break;
637                 case 'h':
638                         header_only++;
639                         break;
640                 case 'i':
641                         image_dump++;
642                         break;
643                 case 'o':
644                         parse_extended_opts(optarg, &use_superblock,
645                                             &use_blocksize);
646                         break;
647                 case 'V':
648                         /* Print version number and exit */
649                         fprintf(stderr, _("\tUsing %s\n"),
650                                 error_message(EXT2_ET_BASE));
651                         exit(0);
652                 case 'x':
653                         hex_format++;
654                         break;
655                 default:
656                         usage();
657                 }
658         }
659         if (optind != argc - 1) {
660                 usage();
661                 exit(1);
662         }
663         device_name = argv[optind++];
664         flags = EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
665         if (force)
666                 flags |= EXT2_FLAG_FORCE;
667         if (image_dump)
668                 flags |= EXT2_FLAG_IMAGE_FILE;
669 try_open_again:
670         if (use_superblock && !use_blocksize) {
671                 for (use_blocksize = EXT2_MIN_BLOCK_SIZE;
672                      use_blocksize <= EXT2_MAX_BLOCK_SIZE;
673                      use_blocksize *= 2) {
674                         retval = ext2fs_open (device_name, flags,
675                                               use_superblock,
676                                               use_blocksize, unix_io_manager,
677                                               &fs);
678                         if (!retval)
679                                 break;
680                 }
681         } else
682                 retval = ext2fs_open (device_name, flags, use_superblock,
683                                       use_blocksize, unix_io_manager, &fs);
684         if (retval && !(flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) {
685                 flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
686                 goto try_open_again;
687         }
688         if (!retval && (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS))
689                 printf("%s", _("\n*** Checksum errors detected in filesystem!  Run e2fsck now!\n\n"));
690         flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
691         if (retval) {
692                 com_err (program_name, retval, _("while trying to open %s"),
693                          device_name);
694                 printf("%s", _("Couldn't find valid filesystem superblock.\n"));
695                 if (retval == EXT2_ET_BAD_MAGIC)
696                         check_plausibility(device_name, CHECK_FS_EXIST, NULL);
697                 exit (1);
698         }
699         fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE;
700         if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
701                 blocks64 = 1;
702         if (print_badblocks) {
703                 list_bad_blocks(fs, 1);
704         } else {
705                 if (grp_only)
706                         goto just_descriptors;
707                 list_super (fs->super);
708                 if (fs->super->s_feature_incompat &
709                       EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
710                         print_journal_information(fs);
711                         ext2fs_close_free(&fs);
712                         exit(0);
713                 }
714                 if ((fs->super->s_feature_compat &
715                      EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
716                     (fs->super->s_journal_inum != 0))
717                         print_inline_journal_information(fs);
718                 list_bad_blocks(fs, 0);
719                 if (header_only) {
720                         ext2fs_close_free(&fs);
721                         exit (0);
722                 }
723                 fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
724 try_bitmaps_again:
725                 retval = ext2fs_read_bitmaps (fs);
726                 if (retval && !(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) {
727                         fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
728                         goto try_bitmaps_again;
729                 }
730                 if (!retval && (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS))
731                         printf("%s", _("\n*** Checksum errors detected in bitmaps!  Run e2fsck now!\n\n"));
732 just_descriptors:
733                 list_desc(fs, grp_only);
734                 if (retval) {
735                         printf(_("\n%s: %s: error reading bitmaps: %s\n"),
736                                program_name, device_name,
737                                error_message(retval));
738                 }
739         }
740         ext2fs_close_free(&fs);
741         remove_error_table(&et_ext2_error_table);
742         exit (0);
743 }