]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - e2fsck/pass3.c
e2fsck: remove get_filename_hash() prototype
[thirdparty/e2fsprogs.git] / e2fsck / pass3.c
index 2d94ece8f1857df868f8f86a6e391c62b993a4d7..6a975b362a4172be06058bed7ab81dab30ccfa08 100644 (file)
@@ -15,7 +15,7 @@
  * not, e2fsck will offer to create a new one.  It is then marked as
  * "done".
  *
- * Then, pass3 interates over all directory inodes; for each directory
+ * Then, pass3 iterates over all directory inodes; for each directory
  * it attempts to trace up the filesystem tree, using dirinfo.parent
  * until it reaches a directory which has been marked "done".  If it
  * can not do so, then the directory must be disconnected, and e2fsck
@@ -100,7 +100,8 @@ void e2fsck_pass3(e2fsck_t ctx)
 
        iter = e2fsck_dir_info_iter_begin(ctx);
        while ((dir = e2fsck_dir_info_iter(ctx, iter)) != 0) {
-               if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+               if (ctx->flags & E2F_FLAG_SIGNAL_MASK ||
+                   ctx->flags & E2F_FLAG_RESTART)
                        goto abort_exit;
                if (ctx->progress && (ctx->progress)(ctx, 3, count++, maxdirs))
                        goto abort_exit;
@@ -380,23 +381,33 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
        ext2_ino_t                      ino;
        blk64_t                 blk;
        errcode_t               retval;
-       struct ext2_inode       inode;
+       struct ext2_inode_large inode;
        char *                  block;
        static const char       name[] = "lost+found";
        struct  problem_context pctx;
+       int                     will_rehash, flags;
 
        if (ctx->lost_and_found)
                return ctx->lost_and_found;
 
        clear_problem_context(&pctx);
 
+       will_rehash = e2fsck_dir_will_be_rehashed(ctx, EXT2_ROOT_INO);
+       if (will_rehash) {
+               flags = ctx->fs->flags;
+               ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
+       }
        retval = ext2fs_lookup(fs, EXT2_ROOT_INO, name,
                               sizeof(name)-1, 0, &ino);
+       if (will_rehash)
+               ctx->fs->flags = (flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) |
+                       (ctx->fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS);
        if (retval && !fix)
                return 0;
        if (!retval) {
                /* Lost+found shouldn't have inline data */
-               retval = ext2fs_read_inode(fs, ino, &inode);
+               retval = ext2fs_read_inode_full(fs, ino, EXT2_INODE(&inode),
+                                               sizeof(inode));
                if (fix && retval)
                        return 0;
 
@@ -406,6 +417,12 @@ ext2_ino_t e2fsck_get_lost_and_found(e2fsck_t ctx, int fix)
                        goto unlink;
                }
 
+               if (fix && (inode.i_flags & EXT4_ENCRYPT_FL)) {
+                       if (!fix_problem(ctx, PR_3_LPF_ENCRYPTED, &pctx))
+                               return 0;
+                       goto unlink;
+               }
+
                if (ext2fs_check_directory(fs, ino) == 0) {
                        ctx->lost_and_found = ino;
                        return ino;
@@ -428,6 +445,15 @@ unlink:
                }
                (void) e2fsck_dir_info_set_parent(ctx, ino, 0);
                e2fsck_adjust_inode_count(ctx, ino, -1);
+               /*
+                * If the old lost+found was a directory, we've just
+                * disconnected it from the directory tree, which
+                * means we need to restart the directory tree scan.
+                * The simplest way to do this is restart the whole
+                * e2fsck operation.
+                */
+               if (LINUX_S_ISDIR(inode.i_mode))
+                       ctx->flags |= E2F_FLAG_RESTART;
        } else if (retval != EXT2_ET_FILE_NOT_FOUND) {
                pctx.errcode = retval;
                fix_problem(ctx, PR_3_ERR_FIND_LPF, &pctx);
@@ -493,13 +519,13 @@ skip_new_block:
        inode.i_size = fs->blocksize;
        inode.i_atime = inode.i_ctime = inode.i_mtime = ctx->now;
        inode.i_links_count = 2;
-       ext2fs_iblk_set(fs, &inode, 1);
+       ext2fs_iblk_set(fs, EXT2_INODE(&inode), 1);
        inode.i_block[0] = blk;
 
        /*
         * Next, write out the inode.
         */
-       pctx.errcode = ext2fs_write_new_inode(fs, ino, &inode);
+       pctx.errcode = ext2fs_write_new_inode(fs, ino, EXT2_INODE(&inode));
        if (pctx.errcode) {
                pctx.str = "ext2fs_write_inode";
                fix_problem(ctx, PR_3_CREATE_LPF_ERROR, &pctx);
@@ -552,7 +578,7 @@ link_error:
        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_add(ctx->qctx, &inode, ino, EXT2_CLUSTER_SIZE(fs->super));
        quota_data_inodes(ctx->qctx, &inode, ino, +1);
 #if 0
        printf("/lost+found created; inode #%lu\n", ino);
@@ -691,8 +717,7 @@ static int fix_dotdot_proc(struct ext2_dir_entry *dirent,
                fix_problem(fp->ctx, PR_3_ADJUST_INODE, &pctx);
        }
        dirent->inode = fp->parent;
-       if (fp->ctx->fs->super->s_feature_incompat &
-           EXT2_FEATURE_INCOMPAT_FILETYPE)
+       if (ext2fs_has_feature_filetype(fp->ctx->fs->super))
                ext2fs_dirent_set_file_type(dirent, EXT2_FT_DIR);
        else
                ext2fs_dirent_set_file_type(dirent, EXT2_FT_UNKNOWN);
@@ -831,7 +856,7 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
        ext2_filsys fs = ctx->fs;
        errcode_t       retval;
        struct expand_dir_struct es;
-       struct ext2_inode       inode;
+       struct ext2_inode_large inode;
        blk64_t         sz;
 
        if (!(fs->flags & EXT2_FLAG_RW))
@@ -864,18 +889,21 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir,
        /*
         * Update the size and block count fields in the inode.
         */
-       retval = ext2fs_read_inode(fs, dir, &inode);
+       retval = ext2fs_read_inode_full(fs, dir,
+                                       EXT2_INODE(&inode), sizeof(inode));
        if (retval)
                return retval;
 
        sz = (es.last_block + 1) * fs->blocksize;
-       retval = ext2fs_inode_size_set(fs, &inode, sz);
+       retval = ext2fs_inode_size_set(fs, EXT2_INODE(&inode), sz);
        if (retval)
                return retval;
-       ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
-       quota_data_add(ctx->qctx, &inode, dir, es.newblocks * fs->blocksize);
+       ext2fs_iblk_add_blocks(fs, EXT2_INODE(&inode), es.newblocks);
+       quota_data_add(ctx->qctx, &inode, dir,
+                      es.newblocks * EXT2_CLUSTER_SIZE(fs->super));
 
-       e2fsck_write_inode(ctx, dir, &inode, "expand_directory");
+       e2fsck_write_inode_full(ctx, dir, EXT2_INODE(&inode),
+                               sizeof(inode), "expand_directory");
 
        return 0;
 }