Whamcloud - gitweb
e2fsck: report ext2fs_open2() and ext2fs_check_desc() errors
[tools/e2fsprogs.git] / e2fsck / super.c
index 3f9e333..6c18d0e 100644 (file)
@@ -9,6 +9,7 @@
  * %End-Header%
  */
 
+#include "config.h"
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
@@ -159,7 +160,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
        errcode_t                       retval;
        __u32                           count;
 
-       if (!ext2fs_inode_has_valid_blocks(inode))
+       if (!ext2fs_inode_has_valid_blocks2(fs, inode))
                return 0;
 
        pb.buf = block_buf + 3 * ctx->fs->blocksize;
@@ -170,8 +171,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
        if (inode->i_links_count) {
                pb.truncating = 1;
                pb.truncate_block = (e2_blkcnt_t)
-                       ((((long long)inode->i_size_high << 32) +
-                         inode->i_size + fs->blocksize - 1) /
+                       ((EXT2_I_SIZE(inode) + fs->blocksize - 1) /
                         fs->blocksize);
                pb.truncate_offset = inode->i_size % fs->blocksize;
        } else {
@@ -197,9 +197,10 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
        if (pb.truncated_blocks)
                ext2fs_iblk_sub_blocks(fs, inode, pb.truncated_blocks);
 
-       if (ext2fs_file_acl_block(inode)) {
-               retval = ext2fs_adjust_ea_refcount2(fs, ext2fs_file_acl_block(inode),
-                                                  block_buf, -1, &count);
+       if (ext2fs_file_acl_block(fs, inode)) {
+               retval = ext2fs_adjust_ea_refcount2(fs,
+                                       ext2fs_file_acl_block(fs, inode),
+                                       block_buf, -1, &count);
                if (retval == EXT2_ET_BAD_EA_BLOCK_NUM) {
                        retval = 0;
                        count = 1;
@@ -212,9 +213,8 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
                }
                if (count == 0)
                        ext2fs_block_alloc_stats2(fs,
-                                                ext2fs_file_acl_block(inode),
-                                                -1);
-               ext2fs_file_acl_block_set(inode, 0);
+                                       ext2fs_file_acl_block(fs, inode), -1);
+               ext2fs_file_acl_block_set(fs, inode, 0);
        }
        return 0;
 }
@@ -400,6 +400,8 @@ void check_resize_inode(e2fsck_t ctx)
 
        gdt_off = fs->desc_blocks;
        pblk = fs->super->s_first_data_block + 1 + fs->desc_blocks;
+       if (fs->blocksize == 1024 && fs->super->s_first_data_block == 0)
+               pblk++; /* Deal with 1024 blocksize bigalloc fs */
        for (i = 0; i < fs->super->s_reserved_gdt_blocks / 4;
             i++, gdt_off++, pblk++) {
                gdt_off %= fs->blocksize/4;
@@ -555,7 +557,8 @@ void check_super_block(e2fsck_t ctx)
                }
        }
 
-       should_be = (sb->s_log_block_size == 0) ? 1 : 0;
+       should_be = (sb->s_log_block_size == 0 &&
+                    EXT2FS_CLUSTER_RATIO(fs) == 1) ? 1 : 0;
        if (sb->s_first_data_block != should_be) {
                pctx.blk = sb->s_first_data_block;
                pctx.blk2 = should_be;
@@ -632,6 +635,8 @@ void check_super_block(e2fsck_t ctx)
 
                should_be = 0;
                if (!ext2fs_group_desc_csum_verify(fs, i)) {
+                       pctx.csum1 = ext2fs_bg_checksum(fs, i);
+                       pctx.csum2 = ext2fs_group_desc_csum(fs, i);
                        if (fix_problem(ctx, PR_0_GDT_CSUM, &pctx)) {
                                ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
                                ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
@@ -663,15 +668,6 @@ void check_super_block(e2fsck_t ctx)
                        ext2fs_unmark_valid(fs);
                }
 
-               if (ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
-                   !ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT)) {
-                       if (fix_problem(ctx, PR_0_BB_UNINIT_IB_INIT, &pctx)) {
-                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
-                               should_be = 1;
-                       }
-                       ext2fs_unmark_valid(fs);
-               }
-
                if (csum_flag &&
                    (ext2fs_bg_itable_unused(fs, i) > ext2fs_bg_free_inodes_count(fs, i) ||
                     ext2fs_bg_itable_unused(fs, i) > sb->s_inodes_per_group)) {
@@ -690,7 +686,7 @@ void check_super_block(e2fsck_t ctx)
                        return;
        }
 
-       ctx->free_blocks = free_blocks;
+       ctx->free_blocks = EXT2FS_C2B(fs, free_blocks);
        ctx->free_inodes = free_inodes;
 
        if ((ext2fs_free_blocks_count(sb) > ext2fs_blocks_count(sb)) ||
@@ -716,7 +712,7 @@ void check_super_block(e2fsck_t ctx)
        if (!(ctx->options & E2F_OPT_READONLY) && uuid_is_null(sb->s_uuid)) {
                if (fix_problem(ctx, PR_0_ADD_UUID, &pctx)) {
                        uuid_generate(sb->s_uuid);
-                       ext2fs_mark_super_dirty(fs);
+                       fs->flags |= EXT2_FLAG_DIRTY;
                        fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
                }
        }
@@ -734,7 +730,7 @@ void check_super_block(e2fsck_t ctx)
            (fs_proc_check("ext4") || check_for_modules("ext4"))) {
                if (fix_problem(ctx, PR_0_CLEAR_TESTFS_FLAG, &pctx)) {
                        fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
-                       ext2fs_mark_super_dirty(fs);
+                       fs->flags |= EXT2_FLAG_DIRTY;
                        fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
                }
        }
@@ -823,7 +819,7 @@ void check_super_block(e2fsck_t ctx)
                        problem = PR_0_FUTURE_SB_LAST_MOUNT_FUDGED;
                if (fix_problem(ctx, problem, &pctx)) {
                        fs->super->s_mtime = ctx->now;
-                       ext2fs_mark_super_dirty(fs);
+                       fs->flags |= EXT2_FLAG_DIRTY;
                }
        }
        if (!broken_system_clock &&
@@ -835,7 +831,7 @@ void check_super_block(e2fsck_t ctx)
                        problem = PR_0_FUTURE_SB_LAST_WRITE_FUDGED;
                if (fix_problem(ctx, problem, &pctx)) {
                        fs->super->s_wtime = ctx->now;
-                       ext2fs_mark_super_dirty(fs);
+                       fs->flags |= EXT2_FLAG_DIRTY;
                }
        }
 
@@ -854,6 +850,11 @@ void check_super_block(e2fsck_t ctx)
         */
        e2fsck_fix_dirhash_hint(ctx);
 
+       /*
+        * Hide quota inodes if necessary.
+        */
+       e2fsck_hide_quota(ctx);
+
        return;
 }