Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / e2fsck / pass3.c
index 5a5fd3e..a379e9b 100644 (file)
@@ -34,6 +34,7 @@
  *             - The dirinfo directory information cache.
  */
 
+#include "config.h"
 #ifdef HAVE_ERRNO_H
 #include <errno.h>
 #endif
@@ -73,8 +74,9 @@ void e2fsck_pass3(e2fsck_t ctx)
        /*
         * Allocate some bitmaps to do loop detection.
         */
-       pctx.errcode = ext2fs_allocate_inode_bitmap(fs, _("inode done bitmap"),
-                                                   &inode_done_map);
+       pctx.errcode = e2fsck_allocate_inode_bitmap(fs, _("inode done bitmap"),
+                                       EXT2FS_BMAP64_AUTODIR,
+                                       "inode_done_map", &inode_done_map);
        if (pctx.errcode) {
                pctx.num = 2;
                fix_problem(ctx, PR_3_ALLOCATE_IBITMAP_ERROR, &pctx);
@@ -87,7 +89,7 @@ void e2fsck_pass3(e2fsck_t ctx)
        if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                goto abort_exit;
 
-       ext2fs_mark_inode_bitmap(inode_done_map, EXT2_ROOT_INO);
+       ext2fs_mark_inode_bitmap2(inode_done_map, EXT2_ROOT_INO);
 
        maxdirs = e2fsck_get_num_dirinfo(ctx);
        count = 1;
@@ -102,7 +104,7 @@ void e2fsck_pass3(e2fsck_t ctx)
                        goto abort_exit;
                if (ctx->progress && (ctx->progress)(ctx, 3, count++, maxdirs))
                        goto abort_exit;
-               if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, dir->ino))
+               if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, dir->ino))
                        if (check_directory(ctx, dir->ino, &pctx))
                                goto abort_exit;
        }
@@ -141,20 +143,20 @@ abort_exit:
 static void check_root(e2fsck_t ctx)
 {
        ext2_filsys fs = ctx->fs;
-       blk_t                   blk;
+       blk64_t                 blk;
        struct ext2_inode       inode;
        char *                  block;
        struct problem_context  pctx;
 
        clear_problem_context(&pctx);
 
-       if (ext2fs_test_inode_bitmap(ctx->inode_used_map, EXT2_ROOT_INO)) {
+       if (ext2fs_test_inode_bitmap2(ctx->inode_used_map, EXT2_ROOT_INO)) {
                /*
                 * If the root inode is not a directory, die here.  The
                 * user must have answered 'no' in pass1 when we
                 * offered to clear it.
                 */
-               if (!(ext2fs_test_inode_bitmap(ctx->inode_dir_map,
+               if (!(ext2fs_test_inode_bitmap2(ctx->inode_dir_map,
                                               EXT2_ROOT_INO))) {
                        fix_problem(ctx, PR_3_ROOT_NOT_DIR_ABORT, &pctx);
                        ctx->flags |= E2F_FLAG_ABORT;
@@ -173,15 +175,15 @@ static void check_root(e2fsck_t ctx)
        /*
         * First, find a free block
         */
-       pctx.errcode = ext2fs_new_block(fs, 0, ctx->block_found_map, &blk);
+       pctx.errcode = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
        if (pctx.errcode) {
                pctx.str = "ext2fs_new_block";
                fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
                ctx->flags |= E2F_FLAG_ABORT;
                return;
        }
-       ext2fs_mark_block_bitmap(ctx->block_found_map, blk);
-       ext2fs_mark_block_bitmap(fs->block_map, blk);
+       ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
+       ext2fs_mark_block_bitmap2(fs->block_map, blk);
        ext2fs_mark_bb_dirty(fs);
 
        /*
@@ -196,7 +198,8 @@ static void check_root(e2fsck_t ctx)
                return;
        }
 
-       pctx.errcode = ext2fs_write_dir_block(fs, blk, block);
+       pctx.errcode = ext2fs_write_dir_block4(fs, blk, block, 0,
+                                              EXT2_ROOT_INO);
        if (pctx.errcode) {
                pctx.str = "ext2fs_write_dir_block";
                fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
@@ -234,9 +237,9 @@ static void check_root(e2fsck_t ctx)
        ext2fs_icount_store(ctx->inode_count, EXT2_ROOT_INO, 2);
        ext2fs_icount_store(ctx->inode_link_info, EXT2_ROOT_INO, 2);
 
-       ext2fs_mark_inode_bitmap(ctx->inode_used_map, EXT2_ROOT_INO);
-       ext2fs_mark_inode_bitmap(ctx->inode_dir_map, EXT2_ROOT_INO);
-       ext2fs_mark_inode_bitmap(fs->inode_map, EXT2_ROOT_INO);
+       ext2fs_mark_inode_bitmap2(ctx->inode_used_map, EXT2_ROOT_INO);
+       ext2fs_mark_inode_bitmap2(ctx->inode_dir_map, EXT2_ROOT_INO);
+       ext2fs_mark_inode_bitmap2(fs->inode_map, EXT2_ROOT_INO);
        ext2fs_mark_ib_dirty(fs);
 }
 
@@ -274,7 +277,7 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir,
                 * If it was marked done already, then we've reached a
                 * parent we've already checked.
                 */
-               if (ext2fs_mark_inode_bitmap(inode_done_map, ino))
+               if (ext2fs_mark_inode_bitmap2(inode_done_map, ino))
                        break;
 
                if (e2fsck_dir_info_get_parent(ctx, ino, &parent)) {
@@ -289,7 +292,7 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir,
                 */
                if (!parent ||
                    (loop_pass &&
-                    (ext2fs_test_inode_bitmap(inode_loop_detect,
+                    (ext2fs_test_inode_bitmap2(inode_loop_detect,
                                               parent)))) {
                        pctx->ino = ino;
                        if (fix_problem(ctx, PR_3_UNCONNECTED_DIR, pctx)) {
@@ -305,7 +308,7 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir,
                }
                ino = parent;
                if (loop_pass) {
-                       ext2fs_mark_inode_bitmap(inode_loop_detect, ino);
+                       ext2fs_mark_inode_bitmap2(inode_loop_detect, ino);
                } else if (parent_count++ > 2048) {
                        /*
                         * If we've run into a path depth that's
@@ -317,7 +320,7 @@ static int check_directory(e2fsck_t ctx, ext2_ino_t dir,
                        if (inode_loop_detect)
                                ext2fs_clear_inode_bitmap(inode_loop_detect);
                        else {
-                               pctx->errcode = ext2fs_allocate_inode_bitmap(fs, _("inode loop detection bitmap"), &inode_loop_detect);
+                               pctx->errcode = e2fsck_allocate_inode_bitmap(fs, _("inode loop detection bitmap"), EXT2FS_BMAP64_AUTODIR, "inode_loop_detect", &inode_loop_detect);
                                if (pctx->errcode) {
                                        pctx->num = 1;
                                        fix_problem(ctx,
@@ -355,7 +358,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
 {
        ext2_filsys fs = ctx->fs;
        ext2_ino_t                      ino;
-       blk_t                   blk;
+       blk64_t                 blk;
        errcode_t               retval;
        struct ext2_inode       inode;
        char *                  block;
@@ -372,7 +375,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        if (retval && !fix)
                return 0;
        if (!retval) {
-               if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, ino)) {
+               if (ext2fs_check_directory(fs, ino) == 0) {
                        ctx->lost_and_found = ino;
                        return ino;
                }
@@ -409,14 +412,14 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        /*
         * First, find a free block
         */
-       retval = ext2fs_new_block(fs, 0, ctx->block_found_map, &blk);
+       retval = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
        if (retval) {
                pctx.errcode = retval;
                fix_problem(ctx, PR_3_ERR_LPF_NEW_BLOCK, &pctx);
                return 0;
        }
-       ext2fs_mark_block_bitmap(ctx->block_found_map, blk);
-       ext2fs_block_alloc_stats(fs, blk, +1);
+       ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
+       ext2fs_block_alloc_stats2(fs, blk, +1);
 
        /*
         * Next find a free inode.
@@ -428,8 +431,8 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
                fix_problem(ctx, PR_3_ERR_LPF_NEW_INODE, &pctx);
                return 0;
        }
-       ext2fs_mark_inode_bitmap(ctx->inode_used_map, ino);
-       ext2fs_mark_inode_bitmap(ctx->inode_dir_map, ino);
+       ext2fs_mark_inode_bitmap2(ctx->inode_used_map, ino);
+       ext2fs_mark_inode_bitmap2(ctx->inode_dir_map, ino);
        ext2fs_inode_alloc_stats2(fs, ino, +1, 1);
 
        /*
@@ -442,7 +445,7 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
                return 0;
        }
 
-       retval = ext2fs_write_dir_block(fs, blk, block);
+       retval = ext2fs_write_dir_block4(fs, blk, block, 0, ino);
        ext2fs_free_mem(&block);
        if (retval) {
                pctx.errcode = retval;
@@ -488,6 +491,8 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        ext2fs_icount_store(ctx->inode_count, ino, 2);
        ext2fs_icount_store(ctx->inode_link_info, ino, 2);
        ctx->lost_and_found = ino;
+       quota_data_add(ctx->qctx, &inode, ino, fs->blocksize);
+       quota_data_inodes(ctx->qctx, &inode, ino, +1);
 #if 0
        printf("/lost+found created; inode #%lu\n", ino);
 #endif
@@ -654,8 +659,12 @@ static void fix_dotdot(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
 
        clear_problem_context(&pctx);
        pctx.ino = ino;
+       if (e2fsck_dir_will_be_rehashed(ctx, ino))
+               ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
        retval = ext2fs_dir_iterate(fs, ino, DIRENT_FLAG_INCLUDE_EMPTY,
                                    0, fix_dotdot_proc, &fp);
+       if (e2fsck_dir_will_be_rehashed(ctx, ino))
+               ctx->fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
        if (retval || !fp.done) {
                pctx.errcode = retval;
                fix_problem(ctx, retval ? PR_3_FIX_PARENT_ERR :
@@ -675,24 +684,25 @@ static void fix_dotdot(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
  */
 
 struct expand_dir_struct {
-       int                     num;
-       int                     guaranteed_size;
-       int                     newblocks;
-       int                     last_block;
+       blk64_t                 num;
+       e2_blkcnt_t             guaranteed_size;
+       blk64_t                 newblocks;
+       blk64_t                 last_block;
        errcode_t               err;
        e2fsck_t                ctx;
+       ext2_ino_t              dir;
 };
 
 static int expand_dir_proc(ext2_filsys fs,
-                          blk_t        *blocknr,
+                          blk64_t      *blocknr,
                           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)
 {
        struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
-       blk_t   new_blk;
-       static blk_t    last_blk = 0;
+       blk64_t new_blk;
+       static blk64_t  last_blk = 0;
        char            *block;
        errcode_t       retval;
        e2fsck_t        ctx;
@@ -708,7 +718,7 @@ static int expand_dir_proc(ext2_filsys fs,
                last_blk = *blocknr;
                return 0;
        }
-       retval = ext2fs_new_block(fs, last_blk, ctx->block_found_map,
+       retval = ext2fs_new_block2(fs, last_blk, ctx->block_found_map,
                                  &new_blk);
        if (retval) {
                es->err = retval;
@@ -721,7 +731,8 @@ static int expand_dir_proc(ext2_filsys fs,
                        return BLOCK_ABORT;
                }
                es->num--;
-               retval = ext2fs_write_dir_block(fs, new_blk, block);
+               retval = ext2fs_write_dir_block4(fs, new_blk, block, 0,
+                                                es->dir);
        } else {
                retval = ext2fs_get_mem(fs->blocksize, &block);
                if (retval) {
@@ -729,7 +740,7 @@ static int expand_dir_proc(ext2_filsys fs,
                        return BLOCK_ABORT;
                }
                memset(block, 0, fs->blocksize);
-               retval = io_channel_write_blk(fs->io, new_blk, 1, block);
+               retval = io_channel_write_blk64(fs->io, new_blk, 1, block);
        }
        if (retval) {
                es->err = retval;
@@ -737,8 +748,8 @@ static int expand_dir_proc(ext2_filsys fs,
        }
        ext2fs_free_mem(&block);
        *blocknr = new_blk;
-       ext2fs_mark_block_bitmap(ctx->block_found_map, new_blk);
-       ext2fs_block_alloc_stats(fs, new_blk, +1);
+       ext2fs_mark_block_bitmap2(ctx->block_found_map, new_blk);
+       ext2fs_block_alloc_stats2(fs, new_blk, +1);
        es->newblocks++;
 
        if (es->num == 0)
@@ -774,8 +785,9 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
        es.err = 0;
        es.newblocks = 0;
        es.ctx = ctx;
+       es.dir = dir;
 
-       retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND,
+       retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND,
                                       0, expand_dir_proc, &es);
 
        if (es.err)
@@ -790,6 +802,7 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
 
        inode.i_size = (es.last_block + 1) * fs->blocksize;
        ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
+       quota_data_add(ctx->qctx, &inode, dir, es.newblocks * fs->blocksize);
 
        e2fsck_write_inode(ctx, dir, &inode, "expand_directory");