OSDN Git Service

Merge branch 'maint' into next
[android-x86/external-e2fsprogs.git] / e2fsck / super.c
index 82c07b2..1728906 100644 (file)
@@ -54,16 +54,16 @@ struct process_block_struct {
 };
 
 static int release_inode_block(ext2_filsys fs,
-                              blk_t    *block_nr,
+                              blk64_t  *block_nr,
                               e2_blkcnt_t blockcnt,
-                              blk_t    ref_blk EXT2FS_ATTR((unused)),
+                              blk64_t  ref_blk EXT2FS_ATTR((unused)),
                               int      ref_offset EXT2FS_ATTR((unused)),
                               void *priv_data)
 {
        struct process_block_struct *pb;
        e2fsck_t                ctx;
        struct problem_context  *pctx;
-       blk_t                   blk = *block_nr;
+       blk64_t                 blk = *block_nr;
        int                     retval = 0;
 
        pb = (struct process_block_struct *) priv_data;
@@ -77,14 +77,14 @@ static int release_inode_block(ext2_filsys fs,
                return 0;
 
        if ((blk < fs->super->s_first_data_block) ||
-           (blk >= fs->super->s_blocks_count)) {
+           (blk >= ext2fs_blocks_count(fs->super))) {
                fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx);
        return_abort:
                pb->abort = 1;
                return BLOCK_ABORT;
        }
 
-       if (!ext2fs_test_block_bitmap(fs->block_map, blk)) {
+       if (!ext2fs_test_block_bitmap2(fs->block_map, blk)) {
                fix_problem(ctx, PR_0_ORPHAN_ALREADY_CLEARED_BLOCK, pctx);
                goto return_abort;
        }
@@ -103,7 +103,7 @@ static int release_inode_block(ext2_filsys fs,
                        int     i, limit;
                        blk_t   *bp;
 
-                       pb->errcode = io_channel_read_blk(fs->io, blk, 1,
+                       pb->errcode = io_channel_read_blk64(fs->io, blk, 1,
                                                        pb->buf);
                        if (pb->errcode)
                                goto return_abort;
@@ -125,13 +125,13 @@ static int release_inode_block(ext2_filsys fs,
                 * it here.
                 */
                if ((blockcnt == pb->truncate_block) && pb->truncate_offset) {
-                       pb->errcode = io_channel_read_blk(fs->io, blk, 1,
+                       pb->errcode = io_channel_read_blk64(fs->io, blk, 1,
                                                        pb->buf);
                        if (pb->errcode)
                                goto return_abort;
                        memset(pb->buf + pb->truncate_offset, 0,
                               fs->blocksize - pb->truncate_offset);
-                       pb->errcode = io_channel_write_blk(fs->io, blk, 1,
+                       pb->errcode = io_channel_write_blk64(fs->io, blk, 1,
                                                         pb->buf);
                        if (pb->errcode)
                                goto return_abort;
@@ -141,7 +141,7 @@ static int release_inode_block(ext2_filsys fs,
                retval |= BLOCK_CHANGED;
        }
 
-       ext2fs_block_alloc_stats(fs, blk, -1);
+       ext2fs_block_alloc_stats2(fs, blk, -1);
        return retval;
 }
 
@@ -180,7 +180,7 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
                pb.truncate_offset = 0;
        }
        pb.truncated_blocks = 0;
-       retval = ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_DEPTH_TRAVERSE,
+       retval = ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_DEPTH_TRAVERSE,
                                      block_buf, release_inode_block, &pb);
        if (retval) {
                com_err("release_inode_blocks", retval,
@@ -197,8 +197,8 @@ 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 (inode->i_file_acl) {
-               retval = ext2fs_adjust_ea_refcount(fs, inode->i_file_acl,
+       if (ext2fs_file_acl_block(inode)) {
+               retval = ext2fs_adjust_ea_refcount2(fs, ext2fs_file_acl_block(inode),
                                                   block_buf, -1, &count);
                if (retval == EXT2_ET_BAD_EA_BLOCK_NUM) {
                        retval = 0;
@@ -206,13 +206,15 @@ static int release_inode_blocks(e2fsck_t ctx, ext2_ino_t ino,
                }
                if (retval) {
                        com_err("release_inode_blocks", retval,
-               _("while calling ext2fs_adjust_ea_refcount for inode %d"),
+               _("while calling ext2fs_adjust_ea_refcount2 for inode %d"),
                                ino);
                        return 1;
                }
                if (count == 0)
-                       ext2fs_block_alloc_stats(fs, inode->i_file_acl, -1);
-               inode->i_file_acl = 0;
+                       ext2fs_block_alloc_stats2(fs,
+                                                ext2fs_file_acl_block(inode),
+                                                -1);
+               ext2fs_file_acl_block_set(inode, 0);
        }
        return 0;
 }
@@ -311,7 +313,7 @@ void check_resize_inode(e2fsck_t ctx)
        struct problem_context  pctx;
        int             i, gdt_off, ind_off;
        dgrp_t          j;
-       blk_t           blk, pblk, expect;
+       blk64_t         blk, pblk, expect;
        __u32           *dind_buf = 0, *ind_buf;
        errcode_t       retval;
 
@@ -374,7 +376,7 @@ void check_resize_inode(e2fsck_t ctx)
        if ((i < EXT2_N_BLOCKS) || !blk || !inode.i_links_count ||
            !(inode.i_mode & LINUX_S_IFREG) ||
            (blk < fs->super->s_first_data_block ||
-            blk >= fs->super->s_blocks_count)) {
+            blk >= ext2fs_blocks_count(fs->super))) {
        resize_inode_invalid:
                if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) {
                        memset(&inode, 0, sizeof(inode));
@@ -454,21 +456,20 @@ static void e2fsck_fix_dirhash_hint(e2fsck_t ctx)
 void check_super_block(e2fsck_t ctx)
 {
        ext2_filsys fs = ctx->fs;
-       blk_t   first_block, last_block;
+       blk64_t first_block, last_block;
        struct ext2_super_block *sb = fs->super;
-       struct ext2_group_desc *gd;
        problem_t       problem;
-       blk_t   blocks_per_group = fs->super->s_blocks_per_group;
-       blk_t   bpg_max;
+       blk64_t blocks_per_group = fs->super->s_blocks_per_group;
+       __u32   bpg_max;
        int     inodes_per_block;
        int     ipg_max;
        int     inode_size;
        int     accept_time_fudge;
        int     broken_system_clock;
        dgrp_t  i;
-       blk_t   should_be;
+       blk64_t should_be;
        struct problem_context  pctx;
-       blk_t   free_blocks = 0;
+       blk64_t free_blocks = 0;
        ino_t   free_inodes = 0;
        int     csum_flag, clear_test_fs_flag;
 
@@ -494,10 +495,10 @@ void check_super_block(e2fsck_t ctx)
         */
        check_super_value(ctx, "inodes_count", sb->s_inodes_count,
                          MIN_CHECK, 1, 0);
-       check_super_value(ctx, "blocks_count", sb->s_blocks_count,
+       check_super_value(ctx, "blocks_count", ext2fs_blocks_count(sb),
                          MIN_CHECK, 1, 0);
        check_super_value(ctx, "first_data_block", sb->s_first_data_block,
-                         MAX_CHECK, 0, sb->s_blocks_count);
+                         MAX_CHECK, 0, ext2fs_blocks_count(sb));
        check_super_value(ctx, "log_block_size", sb->s_log_block_size,
                          MIN_CHECK | MAX_CHECK, 0,
                          EXT2_MAX_BLOCK_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE);
@@ -513,8 +514,8 @@ void check_super_block(e2fsck_t ctx)
                          MIN_CHECK | MAX_CHECK, 8, bpg_max);
        check_super_value(ctx, "inodes_per_group", sb->s_inodes_per_group,
                          MIN_CHECK | MAX_CHECK, inodes_per_block, ipg_max);
-       check_super_value(ctx, "r_blocks_count", sb->s_r_blocks_count,
-                         MAX_CHECK, 0, sb->s_blocks_count / 2);
+       check_super_value(ctx, "r_blocks_count", ext2fs_r_blocks_count(sb),
+                         MAX_CHECK, 0, ext2fs_blocks_count(sb) / 2);
        check_super_value(ctx, "reserved_gdt_blocks",
                          sb->s_reserved_gdt_blocks, MAX_CHECK, 0,
                          fs->blocksize/4);
@@ -535,8 +536,8 @@ void check_super_block(e2fsck_t ctx)
        }
 
        if ((ctx->flags & E2F_FLAG_GOT_DEVSIZE) &&
-           (ctx->num_blocks < sb->s_blocks_count)) {
-               pctx.blk = sb->s_blocks_count;
+           (ctx->num_blocks < ext2fs_blocks_count(sb))) {
+               pctx.blk = ext2fs_blocks_count(sb);
                pctx.blk2 = ctx->num_blocks;
                if (fix_problem(ctx, PR_0_FS_SIZE_WRONG, &pctx)) {
                        ctx->flags |= E2F_FLAG_ABORT;
@@ -575,105 +576,106 @@ void check_super_block(e2fsck_t ctx)
         * Verify the group descriptors....
         */
        first_block = sb->s_first_data_block;
-       last_block = sb->s_blocks_count-1;
+       last_block = ext2fs_blocks_count(sb)-1;
 
        csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                               EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
-       for (i = 0, gd=fs->group_desc; i < fs->group_desc_count; i++, gd++) {
+       for (i = 0; i < fs->group_desc_count; i++) {
                pctx.group = i;
 
                if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
                                               EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
-                       first_block = ext2fs_group_first_block(fs, i);
-                       last_block = ext2fs_group_last_block(fs, i);
+                       first_block = ext2fs_group_first_block2(fs, i);
+                       last_block = ext2fs_group_last_block2(fs, i);
                }
 
-               if ((gd->bg_block_bitmap < first_block) ||
-                   (gd->bg_block_bitmap > last_block)) {
-                       pctx.blk = gd->bg_block_bitmap;
+               if ((ext2fs_block_bitmap_loc(fs, i) < first_block) ||
+                   (ext2fs_block_bitmap_loc(fs, i) > last_block)) {
+                       pctx.blk = ext2fs_block_bitmap_loc(fs, i);
                        if (fix_problem(ctx, PR_0_BB_NOT_GROUP, &pctx))
-                               gd->bg_block_bitmap = 0;
+                               ext2fs_block_bitmap_loc_set(fs, i, 0);
                }
-               if (gd->bg_block_bitmap == 0) {
+               if (ext2fs_block_bitmap_loc(fs, i) == 0) {
                        ctx->invalid_block_bitmap_flag[i]++;
                        ctx->invalid_bitmaps++;
                }
-               if ((gd->bg_inode_bitmap < first_block) ||
-                   (gd->bg_inode_bitmap > last_block)) {
-                       pctx.blk = gd->bg_inode_bitmap;
+               if ((ext2fs_inode_bitmap_loc(fs, i) < first_block) ||
+                   (ext2fs_inode_bitmap_loc(fs, i) > last_block)) {
+                       pctx.blk = ext2fs_inode_bitmap_loc(fs, i);
                        if (fix_problem(ctx, PR_0_IB_NOT_GROUP, &pctx))
-                               gd->bg_inode_bitmap = 0;
+                               ext2fs_inode_bitmap_loc_set(fs, i, 0);
                }
-               if (gd->bg_inode_bitmap == 0) {
+               if (ext2fs_inode_bitmap_loc(fs, i) == 0) {
                        ctx->invalid_inode_bitmap_flag[i]++;
                        ctx->invalid_bitmaps++;
                }
-               if ((gd->bg_inode_table < first_block) ||
-                   ((gd->bg_inode_table +
+               if ((ext2fs_inode_table_loc(fs, i) < first_block) ||
+                   ((ext2fs_inode_table_loc(fs, i) +
                      fs->inode_blocks_per_group - 1) > last_block)) {
-                       pctx.blk = gd->bg_inode_table;
+                       pctx.blk = ext2fs_inode_table_loc(fs, i);
                        if (fix_problem(ctx, PR_0_ITABLE_NOT_GROUP, &pctx))
-                               gd->bg_inode_table = 0;
+                               ext2fs_inode_table_loc_set(fs, i, 0);
                }
-               if (gd->bg_inode_table == 0) {
+               if (ext2fs_inode_table_loc(fs, i) == 0) {
                        ctx->invalid_inode_table_flag[i]++;
                        ctx->invalid_bitmaps++;
                }
-               free_blocks += gd->bg_free_blocks_count;
-               free_inodes += gd->bg_free_inodes_count;
+               free_blocks += ext2fs_bg_free_blocks_count(fs, i);
+               free_inodes += ext2fs_bg_free_inodes_count(fs, i);
 
-               if ((gd->bg_free_blocks_count > sb->s_blocks_per_group) ||
-                   (gd->bg_free_inodes_count > sb->s_inodes_per_group) ||
-                   (gd->bg_used_dirs_count > sb->s_inodes_per_group))
+               if ((ext2fs_bg_free_blocks_count(fs, i) > sb->s_blocks_per_group) ||
+                   (ext2fs_bg_free_inodes_count(fs, i) > sb->s_inodes_per_group) ||
+                   (ext2fs_bg_used_dirs_count(fs, i) > sb->s_inodes_per_group))
                        ext2fs_unmark_valid(fs);
 
                should_be = 0;
                if (!ext2fs_group_desc_csum_verify(fs, i)) {
                        if (fix_problem(ctx, PR_0_GDT_CSUM, &pctx)) {
-                               gd->bg_flags &= ~(EXT2_BG_BLOCK_UNINIT |
-                                                 EXT2_BG_INODE_UNINIT);
-                               gd->bg_itable_unused = 0;
+                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
+                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
                }
 
                if (!csum_flag &&
-                   (gd->bg_flags &(EXT2_BG_BLOCK_UNINIT|EXT2_BG_INODE_UNINIT)||
-                    gd->bg_itable_unused != 0)){
+                   (ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) ||
+                    ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) ||
+                    ext2fs_bg_itable_unused(fs, i) != 0)) {
                        if (fix_problem(ctx, PR_0_GDT_UNINIT, &pctx)) {
-                               gd->bg_flags &= ~(EXT2_BG_BLOCK_UNINIT |
-                                                 EXT2_BG_INODE_UNINIT);
-                               gd->bg_itable_unused = 0;
+                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
+                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
                }
 
                if (i == fs->group_desc_count - 1 &&
-                   gd->bg_flags & EXT2_BG_BLOCK_UNINIT) {
+                   ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT)) {
                        if (fix_problem(ctx, PR_0_BB_UNINIT_LAST, &pctx)) {
-                               gd->bg_flags &= ~EXT2_BG_BLOCK_UNINIT;
+                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
                }
 
-               if (gd->bg_flags & EXT2_BG_BLOCK_UNINIT &&
-                   !(gd->bg_flags & EXT2_BG_INODE_UNINIT)) {
+               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)) {
-                               gd->bg_flags &= ~EXT2_BG_BLOCK_UNINIT;
+                               ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
                }
 
                if (csum_flag &&
-                   (gd->bg_itable_unused > gd->bg_free_inodes_count ||
-                    gd->bg_itable_unused > sb->s_inodes_per_group)) {
-                       pctx.blk = gd->bg_itable_unused;
+                   (ext2fs_bg_itable_unused(fs, i) > ext2fs_bg_free_inodes_count(fs, i) ||
+                    ext2fs_bg_itable_unused(fs, i) > sb->s_inodes_per_group)) {
+                       pctx.blk = ext2fs_bg_itable_unused(fs, i);
                        if (fix_problem(ctx, PR_0_GDT_ITABLE_UNUSED, &pctx)) {
-                               gd->bg_itable_unused = 0;
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
@@ -681,6 +683,9 @@ void check_super_block(e2fsck_t ctx)
 
                if (should_be)
                        ext2fs_group_desc_csum_set(fs, i);
+               /* If the user aborts e2fsck by typing ^C, stop right away */
+               if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+                       return;
        }
 
        /*
@@ -690,18 +695,18 @@ void check_super_block(e2fsck_t ctx)
         * inodes; if the filesystem is not unmounted cleanly, the
         * global counts may not be accurate.
         */
-       if ((free_blocks != sb->s_free_blocks_count) ||
+       if ((free_blocks != ext2fs_free_blocks_count(sb)) ||
            (free_inodes != sb->s_free_inodes_count)) {
                if (ctx->options & E2F_OPT_READONLY)
                        ext2fs_unmark_valid(fs);
                else {
-                       sb->s_free_blocks_count = free_blocks;
+                       ext2fs_free_blocks_count_set(sb, free_blocks);
                        sb->s_free_inodes_count = free_inodes;
                        ext2fs_mark_super_dirty(fs);
                }
        }
 
-       if ((sb->s_free_blocks_count > sb->s_blocks_count) ||
+       if ((ext2fs_free_blocks_count(sb) > ext2fs_blocks_count(sb)) ||
            (sb->s_free_inodes_count > sb->s_inodes_count))
                ext2fs_unmark_valid(fs);
 
@@ -894,7 +899,7 @@ int check_backup_super_block(e2fsck_t ctx)
        ext2_filsys     fs = ctx->fs;
        errcode_t       retval;
        dgrp_t          g;
-       blk_t           sb;
+       blk64_t         sb;
        int             ret = 0;
        char            buf[SUPERBLOCK_SIZE];
        struct ext2_super_block *backup_sb;