Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / e2fsck / pass1b.c
index 9aeab50..155fcba 100644 (file)
@@ -54,7 +54,7 @@ typedef long intptr_t;
 #define BLOCK_COUNT_EXTATTR    (-5)
 
 struct block_el {
-       blk_t   block;
+       blk64_t block;
        struct block_el *next;
 };
 
@@ -82,14 +82,14 @@ struct dup_inode {
        struct block_el         *block_list;
 };
 
-static int process_pass1b_block(ext2_filsys fs, blk_t  *blocknr,
-                               e2_blkcnt_t blockcnt, blk_t ref_blk,
+static int process_pass1b_block(ext2_filsys fs, blk64_t        *blocknr,
+                               e2_blkcnt_t blockcnt, blk64_t ref_blk,
                                int ref_offset, void *priv_data);
 static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
                        struct dup_inode *dp, char *block_buf);
 static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
                      struct dup_inode *dp, char* block_buf);
-static int check_if_fs_block(e2fsck_t ctx, blk_t test_blk);
+static int check_if_fs_block(e2fsck_t ctx, blk64_t test_blk);
 
 static void pass1b(e2fsck_t ctx, char *block_buf);
 static void pass1c(e2fsck_t ctx, char *block_buf);
@@ -115,7 +115,7 @@ static int dict_int_cmp(const void *a, const void *b)
 /*
  * Add a duplicate block record
  */
-static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk_t blk,
+static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk64_t blk,
                     struct ext2_inode *inode)
 {
        dnode_t *n;
@@ -307,12 +307,15 @@ static void pass1b(e2fsck_t ctx, char *block_buf)
 
                if (ext2fs_inode_has_valid_blocks(&inode) ||
                    (ino == EXT2_BAD_INO))
-                       pctx.errcode = ext2fs_block_iterate2(fs, ino,
+                       pctx.errcode = ext2fs_block_iterate3(fs, ino,
                                             BLOCK_FLAG_READ_ONLY, block_buf,
                                             process_pass1b_block, &pb);
-               if (inode.i_file_acl)
-                       process_pass1b_block(fs, &inode.i_file_acl,
+               if (ext2fs_file_acl_block(&inode)) {
+                       blk64_t blk = ext2fs_file_acl_block(&inode);
+                       process_pass1b_block(fs, &blk,
                                             BLOCK_COUNT_EXTATTR, 0, 0, &pb);
+                       ext2fs_file_acl_block_set(&inode, blk);
+                       }
                if (pb.dup_blocks) {
                        end_problem_latch(ctx, PR_LATCH_DBLOCK);
                        if (ino >= EXT2_FIRST_INODE(fs->super) ||
@@ -327,9 +330,9 @@ static void pass1b(e2fsck_t ctx, char *block_buf)
 }
 
 static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)),
-                               blk_t   *block_nr,
+                               blk64_t *block_nr,
                                e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
-                               blk_t ref_blk EXT2FS_ATTR((unused)),
+                               blk64_t ref_blk EXT2FS_ATTR((unused)),
                                int ref_offset EXT2FS_ATTR((unused)),
                                void *priv_data)
 {
@@ -545,7 +548,7 @@ static void pass1d(e2fsck_t ctx, char *block_buf)
  * Drop the refcount on the dup_block structure, and clear the entry
  * in the block_dup_map if appropriate.
  */
-static void decrement_badcount(e2fsck_t ctx, blk_t block, struct dup_block *p)
+static void decrement_badcount(e2fsck_t ctx, blk64_t block, struct dup_block *p)
 {
        p->num_bad--;
        if (p->num_bad <= 0 ||
@@ -554,9 +557,9 @@ static void decrement_badcount(e2fsck_t ctx, blk_t block, struct dup_block *p)
 }
 
 static int delete_file_block(ext2_filsys fs,
-                            blk_t      *block_nr,
+                            blk64_t    *block_nr,
                             e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
-                            blk_t ref_block EXT2FS_ATTR((unused)),
+                            blk64_t ref_block EXT2FS_ATTR((unused)),
                             int ref_offset EXT2FS_ATTR((unused)),
                             void *priv_data)
 {
@@ -578,11 +581,11 @@ static int delete_file_block(ext2_filsys fs,
                        decrement_badcount(ctx, *block_nr, p);
                } else
                        com_err("delete_file_block", 0,
-                           _("internal error: can't find dup_blk for %u\n"),
+                           _("internal error: can't find dup_blk for %llu\n"),
                                *block_nr);
        } else {
                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;
@@ -605,7 +608,7 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
 
        e2fsck_read_inode(ctx, ino, &inode, "delete_file");
        if (ext2fs_inode_has_valid_blocks(&inode))
-               pctx.errcode = ext2fs_block_iterate2(fs, ino, BLOCK_FLAG_READ_ONLY,
+               pctx.errcode = ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_READ_ONLY,
                                                     block_buf, delete_file_block, &pb);
        if (pctx.errcode)
                fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
@@ -616,17 +619,18 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
        /* Inode may have changed by block_iterate, so reread it */
        e2fsck_read_inode(ctx, ino, &inode, "delete_file");
        e2fsck_clear_inode(ctx, ino, &inode, 0, "delete_file");
-       if (inode.i_file_acl &&
+       if (ext2fs_file_acl_block(&inode) &&
            (fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR)) {
                count = 1;
-               pctx.errcode = ext2fs_adjust_ea_refcount(fs, inode.i_file_acl,
+               pctx.errcode = ext2fs_adjust_ea_refcount2(fs,
+                                                  ext2fs_file_acl_block(&inode),
                                                   block_buf, -1, &count);
                if (pctx.errcode == EXT2_ET_BAD_EA_BLOCK_NUM) {
                        pctx.errcode = 0;
                        count = 1;
                }
                if (pctx.errcode) {
-                       pctx.blk = inode.i_file_acl;
+                       pctx.blk = ext2fs_file_acl_block(&inode);
                        fix_problem(ctx, PR_1B_ADJ_EA_REFCOUNT, &pctx);
                }
                /*
@@ -637,9 +641,12 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
                 */
                if ((count == 0) ||
                    ext2fs_test_block_bitmap2(ctx->block_dup_map,
-                                            inode.i_file_acl))
-                       delete_file_block(fs, &inode.i_file_acl,
+                                             ext2fs_file_acl_block(&inode))) {
+                       blk64_t blk = ext2fs_file_acl_block(&inode);
+                       delete_file_block(fs, &blk,
                                          BLOCK_COUNT_EXTATTR, 0, 0, &pb);
+                       ext2fs_file_acl_block_set(&inode, blk);
+               }
        }
 }
 
@@ -651,9 +658,9 @@ struct clone_struct {
 };
 
 static int clone_file_block(ext2_filsys fs,
-                           blk_t       *block_nr,
+                           blk64_t     *block_nr,
                            e2_blkcnt_t blockcnt,
-                           blk_t ref_block EXT2FS_ATTR((unused)),
+                           blk64_t ref_block EXT2FS_ATTR((unused)),
                            int ref_offset EXT2FS_ATTR((unused)),
                            void *priv_data)
 {
@@ -680,7 +687,7 @@ static int clone_file_block(ext2_filsys fs,
                                return BLOCK_ABORT;
                        }
                        if (cs->dir && (blockcnt >= 0)) {
-                               retval = ext2fs_set_dir_block(fs->dblist,
+                               retval = ext2fs_set_dir_block2(fs->dblist,
                                      cs->dir, new_block, blockcnt);
                                if (retval) {
                                        cs->errcode = retval;
@@ -711,7 +718,7 @@ static int clone_file_block(ext2_filsys fs,
                        return BLOCK_CHANGED;
                } else
                        com_err("clone_file_block", 0,
-                           _("internal error: can't find dup_blk for %u\n"),
+                           _("internal error: can't find dup_blk for %llu\n"),
                                *block_nr);
        }
        return 0;
@@ -724,7 +731,7 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
        errcode_t       retval;
        struct clone_struct cs;
        struct problem_context  pctx;
-       blk_t           blk;
+       blk64_t         blk, new_blk;
        dnode_t         *n;
        struct inode_el *ino_el;
        struct dup_block        *db;
@@ -744,7 +751,7 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
        pctx.ino = ino;
        pctx.str = "clone_file";
        if (ext2fs_inode_has_valid_blocks(&dp->inode))
-               pctx.errcode = ext2fs_block_iterate2(fs, ino, 0, block_buf,
+               pctx.errcode = ext2fs_block_iterate3(fs, ino, 0, block_buf,
                                                     clone_file_block, &cs);
        ext2fs_mark_bb_dirty(fs);
        if (pctx.errcode) {
@@ -760,10 +767,12 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
        }
        /* The inode may have changed on disk, so we have to re-read it */
        e2fsck_read_inode(ctx, ino, &dp->inode, "clone file EA");
-       blk = dp->inode.i_file_acl;
-       if (blk && (clone_file_block(fs, &dp->inode.i_file_acl,
+       blk = ext2fs_file_acl_block(&dp->inode);
+       new_blk = blk;
+       if (blk && (clone_file_block(fs, &new_blk,
                                     BLOCK_COUNT_EXTATTR, 0, 0, &cs) ==
                    BLOCK_CHANGED)) {
+               ext2fs_file_acl_block_set(&dp->inode, new_blk);
                e2fsck_write_inode(ctx, ino, &dp->inode, "clone file EA");
                /*
                 * If we cloned the EA block, find all other inodes
@@ -774,7 +783,7 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
                if (!n) {
                        com_err("clone_file", 0,
                                _("internal error: couldn't lookup EA "
-                                 "block record for %u"), blk);
+                                 "block record for %llu"), blk);
                        retval = 0; /* OK to stumble on... */
                        goto errout;
                }
@@ -792,8 +801,9 @@ static int clone_file(e2fsck_t ctx, ext2_ino_t ino,
                                goto errout;
                        }
                        di = (struct dup_inode *) dnode_get(n);
-                       if (di->inode.i_file_acl == blk) {
-                               di->inode.i_file_acl = dp->inode.i_file_acl;
+                       if (ext2fs_file_acl_block(&di->inode) == blk) {
+                               ext2fs_file_acl_block_set(&di->inode,
+                                         ext2fs_file_acl_block(&dp->inode));
                                e2fsck_write_inode(ctx, ino_el->inode,
                                           &di->inode, "clone file EA");
                                decrement_badcount(ctx, blk, db);
@@ -810,10 +820,10 @@ errout:
  * This routine returns 1 if a block overlaps with one of the superblocks,
  * group descriptors, inode bitmaps, or block bitmaps.
  */
-static int check_if_fs_block(e2fsck_t ctx, blk_t test_block)
+static int check_if_fs_block(e2fsck_t ctx, blk64_t test_block)
 {
        ext2_filsys fs = ctx->fs;
-       blk_t   first_block;
+       blk64_t first_block;
        dgrp_t  i;
 
        first_block = fs->super->s_first_data_block;
@@ -827,15 +837,15 @@ static int check_if_fs_block(e2fsck_t ctx, blk_t test_block)
                }
 
                /* Check the inode table */
-               if ((fs->group_desc[i].bg_inode_table) &&
-                   (test_block >= fs->group_desc[i].bg_inode_table) &&
-                   (test_block < (fs->group_desc[i].bg_inode_table +
+               if ((ext2fs_inode_table_loc(fs, i)) &&
+                   (test_block >= ext2fs_inode_table_loc(fs, i)) &&
+                   (test_block < (ext2fs_inode_table_loc(fs, i) +
                                   fs->inode_blocks_per_group)))
                        return 1;
 
                /* Check the bitmap blocks */
-               if ((test_block == fs->group_desc[i].bg_block_bitmap) ||
-                   (test_block == fs->group_desc[i].bg_inode_bitmap))
+               if ((test_block == ext2fs_block_bitmap_loc(fs, i)) ||
+                   (test_block == ext2fs_inode_bitmap_loc(fs, i)))
                        return 1;
 
                first_block += fs->super->s_blocks_per_group;