Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / e2fsck / pass2.c
index 51b7fad..1300e38 100644 (file)
@@ -66,12 +66,6 @@ static int check_dir_block(ext2_filsys fs,
 static int allocate_dir_block(e2fsck_t ctx,
                              struct ext2_db_entry *dir_blocks_info,
                              char *buf, struct problem_context *pctx);
-static int update_dir_block(ext2_filsys fs,
-                           blk_t       *block_nr,
-                           e2_blkcnt_t blockcnt,
-                           blk_t       ref_block,
-                           int         ref_offset,
-                           void        *priv_data);
 static void clear_htree(e2fsck_t ctx, ext2_ino_t ino);
 static int htree_depth(struct dx_dir_info *dx_dir,
                       struct dx_dirblock_info *dx_db);
@@ -976,7 +970,7 @@ out_htree:
                group = ext2fs_group_of_ino(fs, dirent->inode);
                first_unused_inode = group * fs->super->s_inodes_per_group +
                                        1 + fs->super->s_inodes_per_group -
-                                       fs->group_desc[group].bg_itable_unused;
+                                       ext2fs_bg_itable_unused(fs, group);
                cd->pctx.group = group;
 
                /*
@@ -987,11 +981,11 @@ out_htree:
                 * we could call a function in pass1.c that checks the
                 * newly visible inodes.
                 */
-               if (ext2fs_bg_flag_test(fs, group, EXT2_BG_INODE_UNINIT)) {
+               if (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)) {
                        pctx.num = dirent->inode;
                        if (fix_problem(ctx, PR_2_INOREF_BG_INO_UNINIT,
                                        &cd->pctx)){
-                               ext2fs_bg_flag_clear(fs, group,
+                               ext2fs_bg_flags_clear(fs, group,
                                                      EXT2_BG_INODE_UNINIT);
                                ext2fs_mark_super_dirty(fs);
                                ctx->flags |= E2F_FLAG_RESTART_LATER;
@@ -1003,7 +997,7 @@ out_htree:
                } else if (dirent->inode >= first_unused_inode) {
                        pctx.num = dirent->inode;
                        if (fix_problem(ctx, PR_2_INOREF_IN_UNUSED, &cd->pctx)){
-                               fs->group_desc[group].bg_itable_unused = 0;
+                               ext2fs_bg_itable_unused_set(fs, group, 0);
                                ext2fs_mark_super_dirty(fs);
                                ctx->flags |= E2F_FLAG_RESTART_LATER;
                        } else {
@@ -1013,13 +1007,18 @@ out_htree:
                        }
                }
 
-               if (!(ext2fs_test_inode_bitmap2(ctx->inode_used_map,
-                                              dirent->inode))) {
-                       /*
-                        * If the inode is unused, offer to clear it.
-                        */
+               /* 
+                * Offer to clear unused inodes; if we are going to be
+                * restarting the scan due to bg_itable_unused being
+                * wrong, then don't clear any inodes to avoid zapping
+                * inodes that were skipped during pass1 due to an
+                * incorrect bg_itable_unused; we'll get any real
+                * problems after we restart.
+                */
+               if (!(ctx->flags & E2F_FLAG_RESTART_LATER) &&
+                   !(ext2fs_test_inode_bitmap2(ctx->inode_used_map,
+                                               dirent->inode)))
                        problem = PR_2_UNUSED_INODE;
-               }
 
                if (problem) {
                        if (fix_problem(ctx, problem, &cd->pctx)) {
@@ -1165,10 +1164,10 @@ static int deallocate_inode_block(ext2_filsys fs,
        if (HOLE_BLKADDR(*block_nr))
                return 0;
        if ((*block_nr < fs->super->s_first_data_block) ||
-           (*block_nr >= fs->super->s_blocks_count))
+           (*block_nr >= ext2fs_blocks_count(fs->super)))
                return 0;
        ext2fs_unmark_block_bitmap2(ctx->block_found_map, *block_nr);
-       ext2fs_block_alloc_stats(fs, *block_nr, -1);
+       ext2fs_block_alloc_stats2(fs, *block_nr, -1);
        return 0;
 }
 
@@ -1209,8 +1208,10 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
                }
                if (count == 0) {
                        ext2fs_unmark_block_bitmap2(ctx->block_found_map,
-                                                  ext2fs_file_acl_block(&inode));
-                       ext2fs_block_alloc_stats(fs, ext2fs_file_acl_block(&inode), -1);
+                                               ext2fs_file_acl_block(&inode));
+                       ext2fs_block_alloc_stats2(fs,
+                                               ext2fs_file_acl_block(&inode),
+                                               -1);
                }
                ext2fs_file_acl_block_set(&inode, 0);
        }
@@ -1365,7 +1366,7 @@ extern int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
 
        if (ext2fs_file_acl_block(&inode) &&
            ((ext2fs_file_acl_block(&inode) < fs->super->s_first_data_block) ||
-            (ext2fs_file_acl_block(&inode) >= fs->super->s_blocks_count))) {
+            (ext2fs_file_acl_block(&inode) >= ext2fs_blocks_count(fs->super)))) {
                if (fix_problem(ctx, PR_2_FILE_ACL_BAD, &pctx)) {
                        ext2fs_file_acl_block_set(&inode, 0);
                        inode_modified++;
@@ -1463,8 +1464,8 @@ static int allocate_dir_block(e2fsck_t ctx,
         * Finally, update the block pointers for the inode
         */
        db->blk = blk;
-       pctx->errcode = ext2fs_block_iterate2(fs, db->ino, BLOCK_FLAG_HOLE,
-                                     0, update_dir_block, db);
+       pctx->errcode = ext2fs_bmap2(fs, db->ino, &inode, 0, BMAP_SET,
+                                    db->blockcnt, 0, &blk);
        if (pctx->errcode) {
                pctx->str = "ext2fs_block_iterate";
                fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx);
@@ -1473,23 +1474,3 @@ static int allocate_dir_block(e2fsck_t ctx,
 
        return 0;
 }
-
-/*
- * This is a helper function for allocate_dir_block().
- */
-static int update_dir_block(ext2_filsys fs EXT2FS_ATTR((unused)),
-                           blk_t       *block_nr,
-                           e2_blkcnt_t blockcnt,
-                           blk_t ref_block EXT2FS_ATTR((unused)),
-                           int ref_offset EXT2FS_ATTR((unused)),
-                           void *priv_data)
-{
-       struct ext2_db_entry *db;
-
-       db = (struct ext2_db_entry *) priv_data;
-       if (db->blockcnt == (int) blockcnt) {
-               *block_nr = db->blk;
-               return BLOCK_CHANGED;
-       }
-       return 0;
-}