~daniel-mehrmann/e2fsprogs/master

« back to all changes in this revision

Viewing changes to misc/dumpe2fs.c

  • Committer: Daniel Mehrmann
  • Date: 2014-12-16 09:16:59 UTC
  • mfrom: (1.2.25)
  • Revision ID: daniel.mehrmann@gmx.de-20141216091659-ymhbl4ualba43vuc
Tags: 1.43-SN-2014-12-16-0ubuntu1
* Merge in snapshot from the maint branch 

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
#include "../version.h"
44
44
#include "nls-enable.h"
 
45
#include "plausible.h"
45
46
 
46
47
#define in_use(m, x)    (ext2fs_test_bit ((x), (m)))
47
48
 
52
53
 
53
54
static void usage(void)
54
55
{
55
 
        fprintf (stderr, _("Usage: %s [-bfhixV] [-o superblock=<num>] "
 
56
        fprintf(stderr, _("Usage: %s [-bfghixV] [-o superblock=<num>] "
56
57
                 "[-o blocksize=<num>] device\n"), program_name);
57
 
        exit (1);
 
58
        exit(1);
58
59
}
59
60
 
60
61
static void print_number(unsigned long long num)
121
122
{
122
123
        int first = 1, bg_flags = 0;
123
124
 
124
 
        if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
 
125
        if (ext2fs_has_group_desc_csum(fs))
125
126
                bg_flags = ext2fs_bg_flags(fs, i);
126
127
 
127
128
        print_bg_opt(bg_flags, EXT2_BG_INODE_UNINIT, "INODE_UNINIT",
150
151
        }
151
152
}
152
153
 
153
 
static void list_desc (ext2_filsys fs)
 
154
static void list_desc(ext2_filsys fs, int grp_only)
154
155
{
155
156
        unsigned long i;
156
157
        blk64_t first_block, last_block;
187
188
                old_desc_blocks = fs->super->s_first_meta_bg;
188
189
        else
189
190
                old_desc_blocks = fs->desc_blocks;
 
191
        if (grp_only)
 
192
                printf("group:block:super:gdt:bbitmap:ibitmap:itable\n");
190
193
        for (i = 0; i < fs->group_desc_count; i++) {
191
194
                first_block = ext2fs_group_first_block2(fs, i);
192
195
                last_block = ext2fs_group_last_block2(fs, i);
194
197
                ext2fs_super_and_bgd_loc2(fs, i, &super_blk,
195
198
                                          &old_desc_blk, &new_desc_blk, 0);
196
199
 
197
 
                printf (_("Group %lu: (Blocks "), i);
 
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);
198
222
                print_range(first_block, last_block);
199
223
                fputs(")", stdout);
200
 
                print_bg_opts(fs, i);
201
 
                if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
 
224
                if (ext2fs_has_group_desc_csum(fs)) {
202
225
                        unsigned csum = ext2fs_bg_checksum(fs, i);
203
226
                        unsigned exp_csum = ext2fs_group_desc_csum(fs, i);
204
227
 
205
 
                        printf(_("  Checksum 0x%04x"), csum);
 
228
                        printf(_(" csum 0x%04x"), csum);
206
229
                        if (csum != exp_csum)
207
230
                                printf(_(" (EXPECTED 0x%04x)"), exp_csum);
208
 
                        printf(_(", unused inodes %u\n"),
209
 
                               ext2fs_bg_itable_unused(fs, i));
210
231
                }
 
232
                print_bg_opts(fs, i);
211
233
                has_super = ((i==0) || super_blk);
212
234
                if (has_super) {
213
235
                        printf (_("  %s superblock at "),
236
258
                print_number(ext2fs_block_bitmap_loc(fs, i));
237
259
                print_bg_rel_offset(fs, ext2fs_block_bitmap_loc(fs, i), 0,
238
260
                                    first_block, last_block);
239
 
                fputs(_(", Inode bitmap at "), stdout);
 
261
                if (fs->super->s_feature_ro_compat &
 
262
                    EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
 
263
                        printf(_(", csum 0x%08x"),
 
264
                               ext2fs_block_bitmap_checksum(fs, i));
 
265
                if (getenv("DUMPE2FS_IGNORE_80COL"))
 
266
                        fputs(_(","), stdout);
 
267
                else
 
268
                        fputs(_("\n "), stdout);
 
269
                fputs(_(" Inode bitmap at "), stdout);
240
270
                print_number(ext2fs_inode_bitmap_loc(fs, i));
241
271
                print_bg_rel_offset(fs, ext2fs_inode_bitmap_loc(fs, i), 0,
242
272
                                    first_block, last_block);
 
273
                if (fs->super->s_feature_ro_compat &
 
274
                    EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
 
275
                        printf(_(", csum 0x%08x"),
 
276
                               ext2fs_inode_bitmap_checksum(fs, i));
243
277
                fputs(_("\n  Inode table at "), stdout);
244
278
                print_range(ext2fs_inode_table_loc(fs, i),
245
279
                            ext2fs_inode_table_loc(fs, i) +
326
360
        ext2fs_badblocks_list_free(bb_list);
327
361
}
328
362
 
 
363
static const char *journal_checksum_type_str(__u8 type)
 
364
{
 
365
        switch (type) {
 
366
        case JBD2_CRC32C_CHKSUM:
 
367
                return "crc32c";
 
368
        default:
 
369
                return "unknown";
 
370
        }
 
371
}
 
372
 
329
373
static void print_inline_journal_information(ext2_filsys fs)
330
374
{
331
375
        journal_superblock_t    *jsb;
394
438
               (unsigned int)ntohl(jsb->s_maxlen),
395
439
               (unsigned int)ntohl(jsb->s_sequence),
396
440
               (unsigned int)ntohl(jsb->s_start));
 
441
        if (jsb->s_feature_compat &
 
442
            ext2fs_cpu_to_be32(JFS_FEATURE_COMPAT_CHECKSUM))
 
443
                printf("%s", _("Journal checksum type:    crc32\n"));
 
444
        if ((jsb->s_feature_incompat &
 
445
             ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
 
446
            (jsb->s_feature_incompat &
 
447
             ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V2)))
 
448
                printf(_("Journal checksum type:    %s\n"
 
449
                         "Journal checksum:         0x%08x\n"),
 
450
                       journal_checksum_type_str(jsb->s_checksum_type),
 
451
                       ext2fs_be32_to_cpu(jsb->s_checksum));
397
452
        if (jsb->s_errno != 0)
398
453
                printf(_("Journal errno:            %d\n"),
399
454
                       (int) ntohl(jsb->s_errno));
404
459
        errcode_t       retval;
405
460
        char            buf[1024];
406
461
        char            str[80];
407
 
        unsigned int    i;
 
462
        unsigned int    i, j, printed = 0;
408
463
        journal_superblock_t    *jsb;
 
464
        __u32                   *mask_ptr, mask, m;
409
465
 
410
466
        /* Get the journal superblock */
411
467
        if ((retval = io_channel_read_blk64(fs->io,
424
480
                exit(1);
425
481
        }
426
482
 
 
483
        if (jsb->s_feature_compat &
 
484
            ext2fs_cpu_to_be32(JFS_FEATURE_COMPAT_CHECKSUM))
 
485
                printf("%s", _("Journal checksum type:    crc32\n"));
 
486
        if ((jsb->s_feature_incompat &
 
487
             ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V3)) ||
 
488
            (jsb->s_feature_incompat &
 
489
             ext2fs_cpu_to_be32(JFS_FEATURE_INCOMPAT_CSUM_V2)))
 
490
                printf(_("Journal checksum type:    %s\n"
 
491
                         "Journal checksum:         0x%08x\n"),
 
492
                       journal_checksum_type_str(jsb->s_checksum_type),
 
493
                       ext2fs_be32_to_cpu(jsb->s_checksum));
 
494
 
 
495
        printf("%s", _("Journal features:        "));
 
496
        for (i = 0, mask_ptr = &jsb->s_feature_compat; i < 3; i++, mask_ptr++) {
 
497
                mask = be32_to_cpu(*mask_ptr);
 
498
                for (j = 0, m = 1; j < 32; j++, m <<= 1) {
 
499
                        if (mask & m) {
 
500
                                printf(" %s", e2p_jrnl_feature2string(i, m));
 
501
                                printed++;
 
502
                        }
 
503
                }
 
504
        }
 
505
 
427
506
        printf(_("\nJournal block size:       %u\n"
428
507
                 "Journal length:           %u\n"
429
508
                 "Journal first block:      %u\n"
531
610
        int             flags;
532
611
        int             header_only = 0;
533
612
        int             c;
 
613
        int             grp_only = 0;
534
614
 
535
615
#ifdef ENABLE_NLS
536
616
        setlocale(LC_MESSAGES, "");
545
625
        if (argc && *argv)
546
626
                program_name = *argv;
547
627
 
548
 
        while ((c = getopt (argc, argv, "bfhixVo:")) != EOF) {
 
628
        while ((c = getopt(argc, argv, "bfghixVo:")) != EOF) {
549
629
                switch (c) {
550
630
                case 'b':
551
631
                        print_badblocks++;
553
633
                case 'f':
554
634
                        force++;
555
635
                        break;
 
636
                case 'g':
 
637
                        grp_only++;
 
638
                        break;
556
639
                case 'h':
557
640
                        header_only++;
558
641
                        break;
575
658
                        usage();
576
659
                }
577
660
        }
578
 
        if (argc - 1 > optind) {
 
661
        if (optind != argc - 1) {
579
662
                usage();
580
663
                exit(1);
581
664
        }
585
668
                flags |= EXT2_FLAG_FORCE;
586
669
        if (image_dump)
587
670
                flags |= EXT2_FLAG_IMAGE_FILE;
588
 
 
 
671
try_open_again:
589
672
        if (use_superblock && !use_blocksize) {
590
673
                for (use_blocksize = EXT2_MIN_BLOCK_SIZE;
591
674
                     use_blocksize <= EXT2_MAX_BLOCK_SIZE;
600
683
        } else
601
684
                retval = ext2fs_open (device_name, flags, use_superblock,
602
685
                                      use_blocksize, unix_io_manager, &fs);
 
686
        if (retval && !(flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) {
 
687
                flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
 
688
                goto try_open_again;
 
689
        }
 
690
        if (!retval && (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS))
 
691
                printf("%s", _("\n*** Checksum errors detected in filesystem!  Run e2fsck now!\n\n"));
 
692
        flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
603
693
        if (retval) {
604
694
                com_err (program_name, retval, _("while trying to open %s"),
605
695
                         device_name);
606
696
                printf("%s", _("Couldn't find valid filesystem superblock.\n"));
 
697
                if (retval == EXT2_ET_BAD_MAGIC)
 
698
                        check_plausibility(device_name, CHECK_FS_EXIST, NULL);
607
699
                exit (1);
608
700
        }
609
701
        fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE;
612
704
        if (print_badblocks) {
613
705
                list_bad_blocks(fs, 1);
614
706
        } else {
 
707
                if (grp_only)
 
708
                        goto just_descriptors;
615
709
                list_super (fs->super);
616
710
                if (fs->super->s_feature_incompat &
617
711
                      EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
628
722
                        ext2fs_close_free(&fs);
629
723
                        exit (0);
630
724
                }
 
725
                fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
 
726
try_bitmaps_again:
631
727
                retval = ext2fs_read_bitmaps (fs);
632
 
                list_desc (fs);
 
728
                if (retval && !(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS)) {
 
729
                        fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
 
730
                        goto try_bitmaps_again;
 
731
                }
 
732
                if (!retval && (fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS))
 
733
                        printf("%s", _("\n*** Checksum errors detected in bitmaps!  Run e2fsck now!\n\n"));
 
734
just_descriptors:
 
735
                list_desc(fs, grp_only);
633
736
                if (retval) {
634
737
                        printf(_("\n%s: %s: error reading bitmaps: %s\n"),
635
738
                               program_name, device_name,