Whamcloud - gitweb
e2fsck: improve error messages when the journal sb is corrupt
[tools/e2fsprogs.git] / e2fsck / pass5.c
index e23680a..4a7e53c 100644 (file)
@@ -75,6 +75,8 @@ void e2fsck_pass5(e2fsck_t ctx)
        ctx->inode_dir_map = 0;
        ext2fs_free_block_bitmap(ctx->block_found_map);
        ctx->block_found_map = 0;
+       ext2fs_free_block_bitmap(ctx->block_metadata_map);
+       ctx->block_metadata_map = 0;
 
        print_resource_track(ctx, _("Pass 5"), &rtrack, ctx->fs->io);
 }
@@ -82,14 +84,13 @@ void e2fsck_pass5(e2fsck_t ctx)
 static void check_inode_bitmap_checksum(e2fsck_t ctx)
 {
        struct problem_context  pctx;
-       char            *buf;
+       char            *buf = NULL;
        dgrp_t          i;
        int             nbytes;
        ext2_ino_t      ino_itr;
        errcode_t       retval;
 
-       if (!EXT2_HAS_RO_COMPAT_FEATURE(ctx->fs->super,
-                                       EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+       if (!ext2fs_has_feature_metadata_csum(ctx->fs->super))
                return;
 
        /* If bitmap is dirty from being fixed, checksum will be corrected */
@@ -97,8 +98,7 @@ static void check_inode_bitmap_checksum(e2fsck_t ctx)
                return;
 
        nbytes = (size_t)(EXT2_INODES_PER_GROUP(ctx->fs->super) / 8);
-       retval = ext2fs_get_memalign(ctx->fs->blocksize, ctx->fs->blocksize,
-                                    &buf);
+       retval = ext2fs_get_mem(ctx->fs->blocksize, &buf);
        if (retval) {
                com_err(ctx->program_name, 0, "%s",
                    _("check_inode_bitmap_checksum: Memory allocation error"));
@@ -138,14 +138,13 @@ static void check_inode_bitmap_checksum(e2fsck_t ctx)
 static void check_block_bitmap_checksum(e2fsck_t ctx)
 {
        struct problem_context  pctx;
-       char            *buf;
+       char            *buf = NULL;
        dgrp_t          i;
        int             nbytes;
        blk64_t         blk_itr;
        errcode_t       retval;
 
-       if (!EXT2_HAS_RO_COMPAT_FEATURE(ctx->fs->super,
-                                       EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+       if (!ext2fs_has_feature_metadata_csum(ctx->fs->super))
                return;
 
        /* If bitmap is dirty from being fixed, checksum will be corrected */
@@ -153,8 +152,7 @@ static void check_block_bitmap_checksum(e2fsck_t ctx)
                return;
 
        nbytes = (size_t)(EXT2_CLUSTERS_PER_GROUP(ctx->fs->super) / 8);
-       retval = ext2fs_get_memalign(ctx->fs->blocksize, ctx->fs->blocksize,
-                                    &buf);
+       retval = ext2fs_get_mem(ctx->fs->blocksize, &buf);
        if (retval) {
                com_err(ctx->program_name, 0, "%s",
                    _("check_block_bitmap_checksum: Memory allocation error"));
@@ -325,12 +323,7 @@ static void check_block_bitmaps(e2fsck_t ctx)
        problem_t       problem, save_problem;
        int             fixit, had_problem;
        errcode_t       retval;
-       int             csum_flag;
-       int     old_desc_blocks = 0;
-       int     count = 0;
-       int     cmp_block = 0;
        int     redo_flag = 0;
-       blk64_t super_blk, old_desc_blk, new_desc_blk;
        char *actual_buf, *bitmap_buf;
 
        actual_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize,
@@ -372,7 +365,6 @@ static void check_block_bitmaps(e2fsck_t ctx)
                goto errout;
        }
 
-       csum_flag = ext2fs_has_group_desc_csum(fs);
 redo_counts:
        had_problem = 0;
        save_problem = 0;
@@ -896,7 +888,7 @@ static void check_block_end(e2fsck_t ctx)
        clear_problem_context(&pctx);
 
        end = ext2fs_get_block_bitmap_start2(fs->block_map) +
-               ((blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) * fs->group_desc_count) - 1;
+               EXT2_GROUPS_TO_CLUSTERS(fs->super, fs->group_desc_count) - 1;
        pctx.errcode = ext2fs_fudge_block_bitmap_end2(fs->block_map, end,
                                                     &save_blocks_count);
        if (pctx.errcode) {