Whamcloud - gitweb
e2fsck: track errors/badness found for each inode
authorAndreas Dilger <andreas.dilger@intel.com>
Fri, 13 Apr 2012 07:13:58 +0000 (01:13 -0600)
committerAndreas Dilger <adilger@whamcloud.com>
Thu, 15 Dec 2022 18:49:58 +0000 (11:49 -0700)
The present e2fsck code checks the inode, per field basis.  It
doesn't take into consideration to total sanity of the inode.
This may cause e2fsck turning a garbage inode into an apparently
sane inode ("It is a vessel of fertilizer, and none may abide
its strength").

Add heuristics into fix_problem() so that e2fsck tracks the degree
of badness of an inode, without needing to be added in many places
in code and explicitly set. An icount is used to keep track the
badness of every inode.  Take advantage of pctx->ino almost always
pointing at the bad inode and increment badness when fix_problem()
is called on an inode.  This also handles future problem addition.

That leaves only a handful of places in the code that need special
handling to either set a higher badness (e.g. inode blocks that are
directly referencing filesystem metadata or have wildly incorrect
timestamps), or should not contribute to inode badness at all.

Badness above a certain threshold value results in clearing the
inode.  The default badness threshold value is 12, it can be tuned
for e2fsck using "-E inode_badness_threshold=<value>" if needed.

When multiply-claimed blocks are found, this is often caused by a
corrupted inode or indirect block that causes a bad inode to overlap
with many good inodes.  This problem is made worse when running
on a large filesystem (16TB or more) because random 32-bit numbers
in the inode->i_blocks[] array are always "valid" block numbers
(with smaller filesystems the random block numbers would be detected
as an error).  Garbage triple/double/indirect blocks will also point
to random "valid" blocks that will themselves contain random 32-bit
block numbers and multiply duplicate blocks count exponentially.

Rather than clone all of those blocks, or possibly deleting/zeroing
all such inodes (as done with "-E shared=delete") it would be better
to find the "bad" inode(s) causing the most problems, and clear only
those inodes, rather than clearing all of inodes with shared blocks.
However, care should be taken to avoid spuriously clearing inodes
that only share blocks with a small number of peers, as it is
difficult to know for sure in this case which inode is the bad one.

An added difficulty in implementing this is that the full list of
inodes sharing a given block is only available in pass1d, at which
point it is already starting to clone the shared blocks.  Some checks
could be done in pass1b, by penalizing inodes wiht the most shared
*blocks*, but it is better to count the shared *inodes*.

If a bad inode is found in pass1b it can be cleared before adding it
to the shared cluster/inode dictionaries.  Otherwise, if found in
pass1d the code to remove inodes/cluster dict_delete_free() code is
non-functional.  For now, restart e2fsck pass1 if very bad inodes
are found.  This will not affect already-processed inodes, and should
reduce the number of duplicate blocks significantly.

Add a new f_ibadness_dup test case for a many-conflicting inode.
Update f_ind_inode_collision, which is a many-blocks conflicting
case that is much better handled by this new mechanism.

Signed-off-by: Girish Shilamkar <girish@clusterfs.com>
Change-Id: I9f5f48d979afebb9c953d9fb2777ebf570f30c15
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
33 files changed:
e2fsck/e2fsck.8.in
e2fsck/e2fsck.c
e2fsck/e2fsck.h
e2fsck/pass1.c
e2fsck/pass1b.c
e2fsck/pass2.c
e2fsck/pass3.c
e2fsck/problem.c
e2fsck/problem.h
e2fsck/super.c
e2fsck/unix.c
lib/ext2fs/ext2fs.h
lib/ext2fs/icount.c
tests/f_ibadness/expect.1 [new file with mode: 0644]
tests/f_ibadness/expect.2 [new file with mode: 0644]
tests/f_ibadness/image.gz [new file with mode: 0644]
tests/f_ibadness/name [new file with mode: 0644]
tests/f_ibadness/script [new file with mode: 0644]
tests/f_ibadness_bad_extents/expect.1 [new file with mode: 0644]
tests/f_ibadness_bad_extents/expect.2 [new file with mode: 0644]
tests/f_ibadness_bad_extents/image.gz [new file with mode: 0644]
tests/f_ibadness_bad_extents/name [new file with mode: 0644]
tests/f_ibadness_bad_extents/script [new file with mode: 0644]
tests/f_ibadness_dup/expect.1 [new file with mode: 0644]
tests/f_ibadness_dup/expect.2 [new file with mode: 0644]
tests/f_ibadness_dup/name [new file with mode: 0644]
tests/f_ibadness_dup/script [new file with mode: 0644]
tests/f_ind_inode_collision/expect.1
tests/f_ind_inode_collision/expect.2
tests/f_messy_inode/expect.1
tests/f_messy_inode/expect.2
tests/f_messy_inode/script [new file with mode: 0644]
tests/filter.sed

index 42df117..b5959ad 100644 (file)
@@ -221,6 +221,16 @@ be 1 or 2.  The default extended attribute version format is 2.
 Only replay the journal if required, but do not perform any further checks
 or repairs.
 .TP
+.BI inode_badness_threshold= threshold_value
+A badness counter is associated with every inode, which determines the degree
+of inode corruption. Each error found in the inode will increase the badness
+by 1 or 2, and inodes with a badness at or above
+.I threshold_value
+will be prompted for deletion. The default
+.I threshold_value
+is 12, and must either be 0 (disabled), or between 3 and 200, as some valid
+inode states may set a badness of 1 or 2 that should not clear the inode.
+.TP
 .BI fragcheck
 During pass 1, print a detailed report of any discontiguous blocks for
 files in the file system.
index b79c600..14fd2bb 100644 (file)
@@ -87,6 +87,10 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
                ext2fs_free_icount(ctx->inode_link_info);
                ctx->inode_link_info = 0;
        }
+       if (ctx->inode_badness) {
+               ext2fs_free_icount(ctx->inode_badness);
+               ctx->inode_badness = 0;
+       }
        if (ctx->journal_io) {
                if (ctx->fs && ctx->fs->io != ctx->journal_io)
                        io_channel_close(ctx->journal_io);
@@ -138,10 +142,6 @@ errcode_t e2fsck_reset_context(e2fsck_t ctx)
                ext2fs_free_inode_bitmap(ctx->inode_bb_map);
                ctx->inode_bb_map = 0;
        }
-       if (ctx->inode_bad_map) {
-               ext2fs_free_inode_bitmap(ctx->inode_bad_map);
-               ctx->inode_bad_map = 0;
-       }
        if (ctx->inode_imagic_map) {
                ext2fs_free_inode_bitmap(ctx->inode_imagic_map);
                ctx->inode_imagic_map = 0;
index 72c3eda..40fa4d2 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <stddef.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -237,6 +238,21 @@ enum clone_opt {
        E2F_CLONE_ZERO
 };
 
+#define EXT4_FITS_IN_INODE(ext4_inode, einode, field)  \
+       ((offsetof(typeof(*ext4_inode), field) +        \
+         sizeof(ext4_inode->field)) <=                 \
+          (EXT2_GOOD_OLD_INODE_SIZE +                  \
+           (einode)->i_extra_isize))                   \
+
+#define EXT4_XTIME_FUTURE(ctx, sb, xtime, margin)      \
+       (!((ctx)->flags & E2F_FLAG_TIME_INSANE) &&      \
+        (xtime) > (ctx)->now + (margin))
+#define EXT4_XTIME_ANCIENT(ctx, sb, xtime, margin)     \
+       ((sb)->s_mkfs_time > (margin) && (xtime) < (sb)->s_mkfs_time - (margin))
+
+#define BADNESS_THRESHOLD      12
+#define BADNESS_MAX            0x7fff
+
 /*
  * Define the extended attribute refcount structure
  */
@@ -331,7 +347,6 @@ struct e2fsck_struct {
 
        /* The following inode bitmaps are separately used in thread_ctx Pass1*/
        ext2fs_inode_bitmap inode_used_map; /* Inodes which are in use */
-       ext2fs_inode_bitmap inode_bad_map; /* Inodes which are bad somehow */
        ext2fs_inode_bitmap inode_dir_map; /* Inodes which are directories */
        ext2fs_inode_bitmap inode_bb_map; /* Inodes which are in bad blocks */
        ext2fs_inode_bitmap inode_imagic_map; /* AFS inodes */
@@ -349,6 +364,8 @@ struct e2fsck_struct {
         */
        ext2_icount_t   inode_count;
        ext2_icount_t inode_link_info;
+       ext2_icount_t inode_badness;
+       unsigned int inode_badness_threshold;
 
        ext2_refcount_t refcount;
        ext2_refcount_t refcount_extra;
@@ -708,6 +725,14 @@ extern int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
 extern void e2fsck_clear_inode(e2fsck_t ctx, ext2_ino_t ino,
                               struct ext2_inode *inode, int restart_flag,
                               const char *source);
+#define e2fsck_mark_inode_bad(ctx, pctx, code) \
+       e2fsck_mark_inode_bad_loc(ctx, pctx, code, 1, __func__, __LINE__)
+#define e2fsck_mark_inode_badder(ctx, pctx, code) \
+       e2fsck_mark_inode_bad_loc(ctx, pctx, code, 2, __func__, __LINE__)
+extern void e2fsck_mark_inode_bad_loc(e2fsck_t ctx,
+                               struct problem_context *pctx, __u32 code,
+                               int count, const char *func, const int line);
+extern int e2fsck_fix_bad_inode(e2fsck_t ctx, struct problem_context *pctx);
 extern void e2fsck_intercept_block_allocations(e2fsck_t ctx);
 
 /* pass2.c */
index 329f1ab..5ef3ed9 100644 (file)
@@ -20,7 +20,8 @@
  *     - A bitmap of which inodes are in use.          (inode_used_map)
  *     - A bitmap of which inodes are directories.     (inode_dir_map)
  *     - A bitmap of which inodes are regular files.   (inode_reg_map)
- *     - A bitmap of which inodes have bad fields.     (inode_bad_map)
+ *     - An icount mechanism is used to keep track of
+ *       inodes with bad fields and its badness        (ctx->inode_badness)
  *     - A bitmap of which inodes are in bad blocks.   (inode_bb_map)
  *     - A bitmap of which inodes are imagic inodes.   (inode_imagic_map)
  *     - A bitmap of which inodes are casefolded.      (inode_casefold_map)
@@ -86,7 +87,6 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
 static void mark_table_blocks(e2fsck_t ctx);
 static void alloc_bb_map(e2fsck_t ctx);
 static void alloc_imagic_map(e2fsck_t ctx);
-static void mark_inode_bad(e2fsck_t ctx, ino_t ino);
 static void add_casefolded_dir(e2fsck_t ctx, ino_t ino);
 static void handle_fs_bad_blocks(e2fsck_t ctx);
 static EXT2_QSORT_TYPE process_inode_cmp(const void *a, const void *b);
@@ -578,7 +578,7 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx,
        struct ext2_super_block *sb = ctx->fs->super;
        struct ext2_inode_large *inode;
        __u32 *eamagic;
-       int min, max;
+       int min, max, dirty = 0;
 
        ea_ibody_quota->blocks = 0;
        ea_ibody_quota->inodes = 0;
@@ -609,8 +609,9 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx,
                        inode->i_extra_isize = ctx->want_extra_isize;
                else
                        inode->i_extra_isize = (inode->i_extra_isize + 3) & ~3;
-               e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode,
-                                       EXT2_INODE_SIZE(sb), "pass1");
+               dirty = 1;
+
+               goto out;
        }
 
        /* check if there is no place for an EA header */
@@ -625,10 +626,7 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx,
                memset((char *)inode + EXT2_GOOD_OLD_INODE_SIZE, 0,
                        EXT2_INODE_SIZE(sb) - EXT2_GOOD_OLD_INODE_SIZE);
                inode->i_extra_isize = ctx->want_extra_isize;
-               e2fsck_write_inode_full(ctx, pctx->ino,
-                                       (struct ext2_inode *)inode,
-                                       EXT2_INODE_SIZE(sb),
-                                       "check_inode_extra_space");
+               dirty = 1;
                if (inode->i_extra_isize < ctx->min_extra_isize)
                        ctx->min_extra_isize = inode->i_extra_isize;
        }
@@ -636,6 +634,12 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx,
        if (*eamagic == EXT2_EXT_ATTR_MAGIC)
                check_ea_in_inode(ctx, pctx, ea_ibody_quota);
 
+       /* Since crtime cannot be set directly from userspace, consider
+        * very old/future values worse than a bad atime/mtime. */
+       if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_crtime, ctx->time_fudge))
+               e2fsck_mark_inode_badder(ctx, pctx, PR_1_CRTIME_BAD);
+       else if (EXT4_XTIME_ANCIENT(ctx, sb, inode->i_crtime, ctx->time_fudge))
+               e2fsck_mark_inode_badder(ctx, pctx, PR_1_CRTIME_BAD);
        /*
         * If the inode's extended atime (ctime, crtime, mtime) is stored in
         * the old, invalid format, repair it.
@@ -648,7 +652,7 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx,
             CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, crtime) ||
             CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, mtime))) {
 
-               if (!fix_problem(ctx, PR_1_EA_TIME_OUT_OF_RANGE, pctx))
+               if (!fix_problem_bad(ctx, PR_1_EA_TIME_OUT_OF_RANGE, pctx, 2))
                        return;
 
                if (CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, atime))
@@ -659,10 +663,13 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx,
                        inode->i_crtime_extra &= ~EXT4_EPOCH_MASK;
                if (CHECK_INODE_EXTRA_NEGATIVE_EPOCH(inode, mtime))
                        inode->i_mtime_extra &= ~EXT4_EPOCH_MASK;
-               e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode,
-                                       EXT2_INODE_SIZE(sb), "pass1");
+               dirty = 1;
        }
 
+out:
+       if (dirty)
+               e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode,
+                                       EXT2_INODE_SIZE(sb), "pass1");
 }
 
 static _INLINE_ int is_blocks_used(e2fsck_t ctx, blk64_t block,
@@ -1130,6 +1137,28 @@ err:
        return retval;
 }
 
+int e2fsck_fix_bad_inode(e2fsck_t ctx, struct problem_context *pctx)
+{
+       __u16 badness;
+       int rc = 0;
+
+       if (!ctx->inode_badness)
+               return 0;
+
+       if (ext2fs_icount_fetch(ctx->inode_badness, pctx->ino, &badness))
+               return 0;
+
+       if (badness > ctx->inode_badness_threshold) {
+               __u64 pctx_num_sav = pctx->num;
+
+               pctx->num = badness;
+               rc = fix_problem_notbad(ctx, PR_1B_INODE_TOOBAD, pctx);
+               pctx->num = pctx_num_sav;
+       }
+
+       return rc;
+}
+
 static void finish_processing_inode(e2fsck_t ctx, ext2_ino_t ino,
                                    struct problem_context *pctx,
                                    int failed_csum)
@@ -1149,7 +1178,7 @@ static void finish_processing_inode(e2fsck_t ctx, ext2_ino_t ino,
 #define FINISH_INODE_LOOP(ctx, ino, pctx, failed_csum) \
        do { \
                finish_processing_inode((ctx), (ino), (pctx), (failed_csum)); \
-               if ((ctx)->flags & E2F_FLAG_ABORT) { \
+               if (e2fsck_should_abort(ctx)) { \
                        e2fsck_pass1_check_unlock(ctx); \
                        return; \
                } \
@@ -1637,6 +1666,23 @@ static void e2fsck_pass1_post(e2fsck_t ctx)
 }
 
 
+/*
+ * Lustre FS creates special inodes - precreated objects.
+ * They are zero-sized and have special attributes:
+ * mode |= S_ISUID | S_ISGID;
+ * valid |= LA_ATIME | LA_MTIME | LA_CTIME;
+ * atime = 0;
+ * mtime = 0;
+ * ctime = 0;
+ */
+static int precreated_object(struct ext2_inode *inode)
+{
+       if (((inode->i_mode & (S_ISUID | S_ISGID)) == (S_ISUID | S_ISGID)) &&
+            inode->i_ctime == 0)
+               return 1;
+       return 0;
+}
+
 void e2fsck_pass1_run(e2fsck_t ctx)
 {
        int     i;
@@ -1814,9 +1860,8 @@ void e2fsck_pass1_run(e2fsck_t ctx)
        if (ctx->global_ctx) {
                if (ctx->options & E2F_OPT_DEBUG &&
                    ctx->options & E2F_OPT_MULTITHREAD)
-                       fprintf(stderr, "thread %d jumping to group %u\n",
-                                       ctx->thread_info.et_thread_index,
-                                       ctx->thread_info.et_group_start);
+                       log_out(ctx, "jumping to group %u\n",
+                               ctx->thread_info.et_group_start);
                pctx.errcode = ext2fs_inode_scan_goto_blockgroup(scan,
                                        ctx->thread_info.et_group_start);
                if (pctx.errcode) {
@@ -2169,6 +2214,12 @@ void e2fsck_pass1_run(e2fsck_t ctx)
 #endif
                                e2fsck_write_inode(ctx, ino, inode, "pass1");
                                failed_csum = 0;
+                       } else {
+                               /* Consider an inode in extent fs w/o extents
+                                * at least a bit suspect. It only matters if
+                                * the inode has several other problems. */
+                               e2fsck_mark_inode_bad(ctx, &pctx,
+                                                     PR_1_UNSET_EXTENT_FL);
                        }
                }
 
@@ -2371,18 +2422,21 @@ void e2fsck_pass1_run(e2fsck_t ctx)
                        frag = fsize = 0;
                }
 
+               /* Fixed in pass2, e2fsck_process_bad_inode(). */
                if (inode->i_faddr || frag || fsize ||
                    (!ext2fs_has_feature_largedir(fs->super) &&
-                   (LINUX_S_ISDIR(inode->i_mode) && inode->i_size_high)))
-                       mark_inode_bad(ctx, ino);
+                    LINUX_S_ISDIR(inode->i_mode) && inode->i_size_high))
+                       e2fsck_mark_inode_bad(ctx, &pctx,
+                                             PR_2_DIR_SIZE_HIGH_ZERO);
                if ((fs->super->s_creator_os != EXT2_OS_HURD) &&
                    !ext2fs_has_feature_64bit(fs->super) &&
                    inode->osd2.linux2.l_i_file_acl_high != 0)
-                       mark_inode_bad(ctx, ino);
+                       e2fsck_mark_inode_bad(ctx, &pctx,
+                                             PR_2_I_FILE_ACL_HI_ZERO);
                if ((fs->super->s_creator_os != EXT2_OS_HURD) &&
                    !ext2fs_has_feature_huge_file(fs->super) &&
                    (inode->osd2.linux2.l_i_blocks_hi != 0))
-                       mark_inode_bad(ctx, ino);
+                       e2fsck_mark_inode_bad(ctx, &pctx, PR_2_BLOCKS_HI_ZERO);
                if (inode->i_flags & EXT2_IMAGIC_FL) {
                        if (imagic_fs) {
                                if (!ctx->inode_imagic_map)
@@ -2473,8 +2527,37 @@ void e2fsck_pass1_run(e2fsck_t ctx)
                        check_immutable(ctx, &pctx);
                        check_size(ctx, &pctx);
                        ctx->fs_sockets_count++;
-               } else
-                       mark_inode_bad(ctx, ino);
+               } else {
+                       e2fsck_mark_inode_bad(ctx, &pctx, PR_2_BAD_MODE);
+               }
+
+               /* Future atime/mtime may be valid in rare cases, but are more
+                * likely to indicate corruption.  Don't try to fix timestamps,
+                * but take into consideration whether inode is corrupted.  If
+                * no other problems with the inode, probably it is OK. */
+               if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_atime, ctx->time_fudge))
+                       e2fsck_mark_inode_bad(ctx, &pctx, PR_1_INODE_BAD_TIME);
+               if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_mtime, ctx->time_fudge))
+                       e2fsck_mark_inode_bad(ctx, &pctx, PR_1_INODE_BAD_TIME);
+
+               /* Since ctime cannot be set directly from userspace, consider
+                * very old/future values worse than a bad atime/mtime. Same for
+                * crtime, but it is checked in check_inode_extra_space(). */
+               if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_ctime, ctx->time_fudge))
+                       e2fsck_mark_inode_badder(ctx, &pctx,
+                                                PR_1_INODE_BAD_TIME);
+               else if (!precreated_object(inode) &&
+                        EXT4_XTIME_ANCIENT(ctx, sb, inode->i_ctime,
+                                           ctx->time_fudge))
+                       e2fsck_mark_inode_badder(ctx, &pctx,
+                                                PR_1_INODE_BAD_TIME);
+
+               /* no restart if clearing bad inode before block processing */
+               if (e2fsck_fix_bad_inode(ctx, &pctx)) {
+                       e2fsck_clear_inode(ctx, ino, inode, 0, "pass1");
+                       goto next_unlock;
+               }
+
                if (!(inode->i_flags & EXT4_EXTENTS_FL) &&
                    !(inode->i_flags & EXT4_INLINE_DATA_FL)) {
                        if (inode->i_block[EXT2_IND_BLOCK])
@@ -2535,6 +2618,7 @@ void e2fsck_pass1_run(e2fsck_t ctx)
                                goto endit;
                        }
                }
+       next_unlock:
                e2fsck_pass1_check_unlock(ctx);
        }
        process_inodes(ctx, block_buf, inodes_to_process,
@@ -2892,6 +2976,7 @@ static errcode_t e2fsck_pass1_thread_prepare(e2fsck_t global_ctx, e2fsck_t *thre
        thread_context->block_dup_map = NULL;
        thread_context->casefolded_dirs = NULL;
        thread_context->expand_eisize_map = NULL;
+       thread_context->inode_badness = NULL;
 
        retval = e2fsck_allocate_block_bitmap(global_ctx->fs,
                                _("in-use block map"), EXT2FS_BMAP64_RBTREE,
@@ -3011,6 +3096,11 @@ static errcode_t e2fsck_pass1_merge_icounts(e2fsck_t global_ctx, e2fsck_t thread
                return ret;
        ret = e2fsck_pass1_merge_icount(&global_ctx->inode_link_info,
                                        &thread_ctx->inode_link_info);
+       if (ret)
+               return ret;
+
+       ret = e2fsck_pass1_merge_icount(&global_ctx->inode_badness,
+                                       &thread_ctx->inode_badness);
 
        return ret;
 }
@@ -3286,11 +3376,6 @@ static errcode_t e2fsck_pass1_merge_context(e2fsck_t global_ctx,
                return retval;
 
        retval = e2fsck_pass1_merge_bitmap(global_fs,
-                               &thread_ctx->inode_bad_map,
-                               &global_ctx->inode_bad_map);
-       if (retval)
-               return retval;
-       retval = e2fsck_pass1_merge_bitmap(global_fs,
                                        &thread_ctx->inode_dir_map,
                                        &global_ctx->inode_dir_map);
        if (retval)
@@ -3755,27 +3840,43 @@ static EXT2_QSORT_TYPE process_inode_cmp(const void *a, const void *b)
 }
 
 /*
- * Mark an inode as being bad in some what
+ * Mark an inode as being bad and increment its badness counter.
  */
-static void mark_inode_bad(e2fsck_t ctx, ino_t ino)
+void e2fsck_mark_inode_bad_loc(e2fsck_t ctx, struct problem_context *pctx,
+                              __u32 code, int badness, const char *func,
+                              const int line)
 {
-       struct          problem_context pctx;
+       __u16 badness_before, badness_after;
 
-       if (!ctx->inode_bad_map) {
-               clear_problem_context(&pctx);
+       if (!ctx->inode_badness_threshold)      /* badness is disabled */
+               return;
 
-               pctx.errcode = e2fsck_allocate_inode_bitmap(ctx->fs,
-                               _("bad inode map"), EXT2FS_BMAP64_RBTREE,
-                               "inode_bad_map", &ctx->inode_bad_map);
-               if (pctx.errcode) {
-                       pctx.num = 3;
-                       fix_problem(ctx, PR_1_ALLOCATE_IBITMAP_ERROR, &pctx);
-                       /* Should never get here */
+       if (!ctx->inode_badness) {
+               errcode_t retval;
+
+               retval = ext2fs_create_icount2(ctx->fs, 0, 0, NULL,
+                                              &ctx->inode_badness);
+               if (retval) {
+                       pctx->errcode = retval;
+                       fix_problem(ctx, PR_1_ALLOCATE_ICOUNT, pctx);
                        ctx->flags |= E2F_FLAG_ABORT;
                        return;
                }
        }
-       ext2fs_mark_inode_bitmap2(ctx->inode_bad_map, ino);
+       ext2fs_icount_fetch(ctx->inode_badness, pctx->ino, &badness_before);
+       if (badness + badness_before > BADNESS_MAX)
+               badness_after = BADNESS_MAX;
+       else if (badness < 0 && badness_before < -badness)
+               badness_after = 0;
+       else
+               badness_after = badness_before + badness;
+       ext2fs_icount_store(ctx->inode_badness, pctx->ino, badness_after);
+
+       if (ctx->options & E2F_OPT_DEBUG)
+               log_out(ctx,
+                       "%s:%d: increase inode %lu badness %u to %u for %x\n",
+                       func, line, (unsigned long)pctx->ino, badness_before,
+                       badness_after, code);
 }
 
 static void add_casefolded_dir(e2fsck_t ctx, ino_t ino)
@@ -3982,7 +4083,8 @@ static int check_ext_attr(e2fsck_t ctx, struct problem_context *pctx,
        if (!ext2fs_has_feature_xattr(fs->super) ||
            (blk < fs->super->s_first_data_block) ||
            (blk >= ext2fs_blocks_count(fs->super))) {
-               mark_inode_bad(ctx, ino);
+               /* Fixed in pass2, e2fsck_process_bad_inode(). */
+               e2fsck_mark_inode_bad(ctx, pctx, PR_2_FILE_ACL_ZERO);
                return 0;
        }
 
@@ -4263,8 +4365,10 @@ static int handle_htree(e2fsck_t ctx, struct problem_context *pctx,
        }
 
        retval = io_channel_read_blk64(fs->io, blk, 1, block_buf);
-       if (retval && fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
-               return 1;
+       if (retval) {
+               if (fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
+                       return 1;
+       }
 
        /* XXX should check that beginning matches a directory */
        root = (struct ext2_dx_root_info *) (block_buf + 24);
@@ -4346,8 +4450,8 @@ void e2fsck_clear_inode(e2fsck_t ctx, ext2_ino_t ino,
        ext2fs_unmark_inode_bitmap2(ctx->inode_used_map, ino);
        if (ctx->inode_reg_map)
                ext2fs_unmark_inode_bitmap2(ctx->inode_reg_map, ino);
-       if (ctx->inode_bad_map)
-               ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino);
+       if (ctx->inode_badness)
+               ext2fs_icount_store(ctx->inode_badness, ino, 0);
 
        /*
         * If the inode was partially accounted for before processing
@@ -4520,7 +4624,9 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx,
 #endif
                if (try_repairs && problem) {
 report_problem:
-                       if (fix_problem(ctx, problem, pctx)) {
+                       /* Record badness only if extent is within inode */
+                       if (fix_problem_bad(ctx, problem, pctx,
+                                           info.curr_level == 0)) {
                                if (ctx->invalid_bitmaps) {
                                        /*
                                         * If fsck knows the bitmaps are bad,
@@ -4589,9 +4695,9 @@ report_problem:
                                                      extent.e_pblk)) {
                                next_try_repairs = 0;
                                pctx->blk = blk;
-                               fix_problem(ctx,
-                                           PR_1_CRITICAL_METADATA_COLLISION,
-                                           pctx);
+                               fix_problem_bad(ctx,
+                                              PR_1_CRITICAL_METADATA_COLLISION,
+                                              pctx, 2);
                                if ((ctx->options & E2F_OPT_NO) == 0)
                                        ctx->flags |= E2F_FLAG_RESTART_LATER;
                        }
@@ -5068,6 +5174,10 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
 
        if (!pb.num_blocks && pb.is_dir &&
            !(inode->i_flags & EXT4_INLINE_DATA_FL)) {
+               /*
+                * The mode might be in-correct. Increasing the badness by
+                * small amount won't hurt much.
+                */
                if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) {
                        e2fsck_clear_inode(ctx, ino, inode, 0, "check_blocks");
                        ctx->fs_directory_count--;
@@ -5200,7 +5310,11 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx,
                e2fsck_rehash_dir_later(ctx, ino);
 
 out:
-       if (dirty_inode)
+       /* need restart if clearing bad inode after block processing */
+       if (e2fsck_fix_bad_inode(ctx, pctx))
+               e2fsck_clear_inode(ctx, ino, inode, E2F_FLAG_RESTART,
+                                  "check_blocks_bad");
+       else if (dirty_inode)
                e2fsck_write_inode(ctx, ino, inode, "check_blocks");
 }
 
@@ -5352,7 +5466,7 @@ static int process_block(ext2_filsys fs,
            blk < ctx->fs->super->s_blocks_count &&
            ext2fs_test_block_bitmap2(ctx->block_metadata_map, blk)) {
                pctx->blk = blk;
-               fix_problem(ctx, PR_1_CRITICAL_METADATA_COLLISION, pctx);
+               fix_problem_bad(ctx, PR_1_CRITICAL_METADATA_COLLISION, pctx, 2);
                if ((ctx->options & E2F_OPT_NO) == 0)
                        ctx->flags |= E2F_FLAG_RESTART_LATER;
        }
index b0a585f..92c7185 100644 (file)
@@ -78,7 +78,7 @@ struct dup_cluster {
  */
 struct dup_inode {
        ext2_ino_t              dir;
-       int                     num_dupblocks;
+       unsigned int            num_dupblocks;
        struct ext2_inode_large inode;
        struct cluster_el       *cluster_list;
 };
@@ -237,6 +237,8 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)
        init_resource_track(&rtrack, ctx->fs->io);
        pass1b(ctx, block_buf);
        print_resource_track(ctx, "Pass 1b", &rtrack, ctx->fs->io);
+       if (ctx->flags & E2F_FLAG_RESTART)
+               goto out;
 
        init_resource_track(&rtrack, ctx->fs->io);
        pass1c(ctx, block_buf);
@@ -245,6 +247,8 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)
        init_resource_track(&rtrack, ctx->fs->io);
        pass1d(ctx, block_buf);
        print_resource_track(ctx, "Pass 1d", &rtrack, ctx->fs->io);
+       if (ctx->flags & E2F_FLAG_RESTART)
+               goto out;
 
        if (ext2fs_has_feature_shared_blocks(ctx->fs->super) &&
            (ctx->options & E2F_OPT_UNSHARE_BLOCKS)) {
@@ -264,6 +268,7 @@ void e2fsck_pass1_dupblocks(e2fsck_t ctx, char *block_buf)
                }
        }
 
+out:
        /*
         * Time to free all of the accumulated data structures that we
         * don't need anymore.
@@ -341,6 +346,14 @@ static void pass1b(e2fsck_t ctx, char *block_buf)
                pb.last_blk = 0;
                pb.pctx->blk = pb.pctx->blk2 = 0;
 
+               if (e2fsck_fix_bad_inode(ctx, &pctx)) {
+                       struct dup_inode dp = { .inode = inode };
+
+                       /* no restart if cleared before block processing */
+                       delete_file(ctx, ino, &dp, block_buf);
+                       continue;
+               }
+
                if (ext2fs_inode_has_valid_blocks2(fs, EXT2_INODE(&inode)) ||
                    (ino == EXT2_BAD_INO))
                        pctx.errcode = ext2fs_block_iterate3(fs, ino,
@@ -358,7 +371,7 @@ static void pass1b(e2fsck_t ctx, char *block_buf)
                        if (ino != EXT2_BAD_INO) {
                                op = pctx.blk == pctx.blk2 ?
                                        PR_1B_DUP_BLOCK : PR_1B_DUP_RANGE;
-                               fix_problem(ctx, op, pb.pctx);
+                               fix_problem_notbad(ctx, op, pb.pctx);
                        }
                        end_problem_latch(ctx, PR_LATCH_DBLOCK);
                        if (ino >= EXT2_FIRST_INODE(fs->super) ||
@@ -367,6 +380,12 @@ static void pass1b(e2fsck_t ctx, char *block_buf)
                }
                if (pctx.errcode)
                        fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
+
+               if (e2fsck_fix_bad_inode(ctx, &pctx)) {
+                       e2fsck_clear_inode(ctx, ino, EXT2_INODE(&inode),
+                                          E2F_FLAG_RESTART, "pass1b");
+                       continue;
+               }
        }
        ext2fs_close_inode_scan(scan);
        e2fsck_use_inode_shortcuts(ctx, 0);
@@ -401,7 +420,8 @@ static int process_pass1b_block(ext2_filsys fs EXT2FS_ATTR((unused)),
                                op = p->pctx->blk == p->pctx->blk2 ?
                                                PR_1B_DUP_BLOCK :
                                                PR_1B_DUP_RANGE;
-                               fix_problem(ctx, op, p->pctx);
+                               /* add badness once per indirect block */
+                               fix_problem_bad(ctx, op, p->pctx, blockcnt < 0);
                        }
                        p->pctx->blk = *block_nr;
                }
@@ -595,18 +615,24 @@ static void pass1d(e2fsck_t ctx, char *block_buf)
                        pctx.ino = shared[i];
                        pctx.dir = t->dir;
                        fix_problem(ctx, PR_1D_DUP_FILE_LIST, &pctx);
+                       if (e2fsck_fix_bad_inode(ctx, &pctx)) {
+                               e2fsck_clear_inode(ctx, pctx.ino, pctx.inode,
+                                                  E2F_FLAG_RESTART, "pass1d");
+                               return;
+                       }
                }
                /*
                 * Even if the file shares blocks with itself, we still need to
                 * clone the blocks.
                 */
+               pctx.ino = ino;
                if (file_ok && (meta_data ? shared_len+1 : shared_len) != 0) {
-                       fix_problem(ctx, PR_1D_DUP_BLOCKS_DEALT, &pctx);
+                       fix_problem_notbad(ctx, PR_1D_DUP_BLOCKS_DEALT, &pctx);
                        continue;
                }
                if (ctx->shared != E2F_SHARED_DELETE &&
                    ((ctx->options & E2F_OPT_UNSHARE_BLOCKS) ||
-                    fix_problem(ctx, PR_1D_CLONE_QUESTION, &pctx))) {
+                    fix_problem_notbad(ctx, PR_1D_CLONE_QUESTION, &pctx))) {
                        pctx.errcode = clone_file(ctx, ino, p, block_buf);
                        if (pctx.errcode) {
                                fix_problem(ctx, PR_1D_CLONE_ERROR, &pctx);
@@ -721,8 +747,6 @@ static void delete_file(e2fsck_t ctx, ext2_ino_t ino,
                                                     delete_file_block, &pb);
        if (pctx.errcode)
                fix_problem(ctx, PR_1B_BLOCK_ITERATE, &pctx);
-       if (ctx->inode_bad_map)
-               ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino);
        if (ctx->inode_reg_map)
                ext2fs_unmark_inode_bitmap2(ctx->inode_reg_map, ino);
        ext2fs_unmark_inode_bitmap2(ctx->inode_dir_map, ino);
index b86fe03..0714d7a 100644 (file)
  * Pass 2 relies on the following information from previous passes:
  *     - The directory information collected in pass 1.
  *     - The inode_used_map bitmap
- *     - The inode_bad_map bitmap
+ *     - The inode_badness bitmap
  *     - The inode_dir_map bitmap
  *     - The encrypted_file_info
  *     - The inode_casefold_map bitmap
  *
  * Pass 2 frees the following data structures
- *     - The inode_bad_map bitmap
  *     - The inode_reg_map bitmap
  *     - The encrypted_file_info
  *     - The inode_casefold_map bitmap
+ *     - The inode_badness bitmap
  */
 
 #define _GNU_SOURCE 1 /* get strnlen() */
@@ -282,10 +282,6 @@ void e2fsck_pass2(e2fsck_t ctx)
        ext2fs_free_mem(&buf);
        ext2fs_free_dblist(fs->dblist);
 
-       if (ctx->inode_bad_map) {
-               ext2fs_free_inode_bitmap(ctx->inode_bad_map);
-               ctx->inode_bad_map = 0;
-       }
        if (ctx->inode_reg_map) {
                ext2fs_free_inode_bitmap(ctx->inode_reg_map);
                ctx->inode_reg_map = 0;
@@ -299,6 +295,10 @@ void e2fsck_pass2(e2fsck_t ctx)
                ext2fs_u32_list_free(ctx->casefolded_dirs);
                ctx->casefolded_dirs = 0;
        }
+       if (ctx->inode_badness) {
+               ext2fs_free_icount(ctx->inode_badness);
+               ctx->inode_badness = 0;
+       }
 
        clear_problem_context(&pctx);
        if (ctx->large_files) {
@@ -596,6 +596,7 @@ static _INLINE_ int check_filetype(e2fsck_t ctx,
 {
        int     filetype = ext2fs_dirent_file_type(dirent);
        int     should_be = EXT2_FT_UNKNOWN;
+       __u16   badness = 0;
        struct ext2_inode       inode;
 
        if (!ext2fs_has_feature_filetype(ctx->fs->super)) {
@@ -606,16 +607,16 @@ static _INLINE_ int check_filetype(e2fsck_t ctx,
                return 1;
        }
 
+       if (ctx->inode_badness)
+               ext2fs_icount_fetch(ctx->inode_badness, dirent->inode,
+                                   &badness);
+
        if (ext2fs_test_inode_bitmap2(ctx->inode_dir_map, dirent->inode)) {
                should_be = EXT2_FT_DIR;
        } else if (ext2fs_test_inode_bitmap2(ctx->inode_reg_map,
                                            dirent->inode)) {
                should_be = EXT2_FT_REG_FILE;
-       } else if (ctx->inode_bad_map &&
-                  ext2fs_test_inode_bitmap2(ctx->inode_bad_map,
-                                           dirent->inode))
-               should_be = 0;
-       else {
+       } else {
                e2fsck_read_inode(ctx, dirent->inode, &inode,
                                  "check_filetype");
                should_be = ext2_file_type(inode.i_mode);
@@ -1501,26 +1502,6 @@ skip_checksum:
                        }
                }
 
-               /*
-                * If the inode was marked as having bad fields in
-                * pass1, process it and offer to fix/clear it.
-                * (We wait until now so that we can display the
-                * pathname to the user.)
-                */
-               if (ctx->inode_bad_map &&
-                   ext2fs_test_inode_bitmap2(ctx->inode_bad_map,
-                                            dirent->inode)) {
-                       if (e2fsck_process_bad_inode(ctx, ino,
-                                                    dirent->inode,
-                                                    buf + fs->blocksize)) {
-                               dirent->inode = 0;
-                               dir_modified++;
-                               goto next;
-                       }
-                       if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
-                               return DIRENT_ABORT;
-               }
-
                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 -
@@ -1563,6 +1544,25 @@ skip_checksum:
                        }
                }
 
+               /*
+                * If the inode was marked as having bad fields in
+                * pass1, process it and offer to fix/clear it.
+                * (We wait until now so that we can display the
+                * pathname to the user.)
+                */
+               if (!(ctx->flags & E2F_FLAG_RESTART_LATER) &&
+                   ctx->inode_badness &&
+                   ext2fs_icount_is_set(ctx->inode_badness, dirent->inode)) {
+                       if (e2fsck_process_bad_inode(ctx, ino, dirent->inode,
+                                                    buf + fs->blocksize)) {
+                               dirent->inode = 0;
+                               dir_modified++;
+                               goto next;
+                       }
+                       if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+                               return DIRENT_ABORT;
+               }
+
                /* 
                 * Offer to clear unused inodes; if we are going to be
                 * restarting the scan due to bg_itable_unused being
@@ -1577,15 +1577,19 @@ skip_checksum:
                        problem = PR_2_UNUSED_INODE;
 
                if (problem) {
-                       if (fix_problem(ctx, problem, &cd->pctx)) {
+                       int next = 0;
+
+                       if (fix_problem_notbad(ctx, problem, &cd->pctx)) {
                                dirent->inode = 0;
                                dir_modified++;
-                               goto next;
+                               next = 1;
                        } else {
                                ext2fs_unmark_valid(fs);
                                if (problem == PR_2_BAD_INO)
-                                       goto next;
+                                       next = 1;
                        }
+                       if (next)
+                               goto next;
                }
 
                if (check_filetype(ctx, dirent, ino, &cd->pctx))
@@ -1850,8 +1854,17 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
        struct problem_context  pctx;
        __u32                   count;
        struct del_block        del_block;
+       int extent_fs = 0;
 
        e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
+       /* ext2fs_block_iterate2() depends on the extents flags */
+       if (inode.i_flags & EXT4_EXTENTS_FL)
+               extent_fs = 1;
+       e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode");
+       if (extent_fs) {
+               inode.i_flags |= EXT4_EXTENTS_FL;
+               e2fsck_write_inode(ctx, ino, &inode, "deallocate_inode");
+       }
        clear_problem_context(&pctx);
        pctx.ino = ino;
 
@@ -1880,6 +1893,8 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
                        ext2fs_block_alloc_stats2(fs,
                                  ext2fs_file_acl_block(fs, &inode), -1);
                }
+               if (ctx->inode_badness)
+                       ext2fs_icount_store(ctx->inode_badness, ino, 0);
                ext2fs_file_acl_block_set(fs, &inode, 0);
        }
 
@@ -1939,8 +1954,14 @@ int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
        unsigned char           *frag, *fsize;
        struct problem_context  pctx;
        problem_t               problem = 0;
+       __u16                   badness = 0;
+       unsigned int            flags = ctx->fs->flags;
 
+       flags = ctx->fs->flags;
+       ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
        e2fsck_read_inode(ctx, ino, &inode, "process_bad_inode");
+       ctx->fs->flags = (flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) |
+                         (ctx->fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS);
 
        clear_problem_context(&pctx);
        pctx.ino = ino;
@@ -2064,10 +2085,17 @@ int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
                        not_fixed++;
        }
 
+       if (e2fsck_fix_bad_inode(ctx, &pctx)) {
+               deallocate_inode(ctx, ino, 0);
+               if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+                       return 0;
+               inode_modified = 0;
+       } else {
+               not_fixed++;
+       }
+
        if (inode_modified)
                e2fsck_write_inode(ctx, ino, &inode, "process_bad_inode");
-       if (!not_fixed && ctx->inode_bad_map)
-               ext2fs_unmark_inode_bitmap2(ctx->inode_bad_map, ino);
        return 0;
 }
 
@@ -2087,7 +2115,7 @@ static int allocate_dir_block(e2fsck_t ctx,
        char                    *block;
        struct ext2_inode       inode;
 
-       if (fix_problem(ctx, PR_2_DIRECTORY_HOLE, pctx) == 0)
+       if (fix_problem_notbad(ctx, PR_2_DIRECTORY_HOLE, pctx) == 0)
                return 1;
 
        /*
index 16d243f..8f9c614 100644 (file)
@@ -469,7 +469,7 @@ unlink:
                pctx.errcode = retval;
                fix_problem(ctx, PR_3_ERR_FIND_LPF, &pctx);
        }
-       if (!fix_problem(ctx, PR_3_NO_LF_DIR, 0))
+       if (!fix_problem(ctx, PR_3_NO_LF_DIR, &pctx))
                return 0;
 
        /*
index 11d277a..83a3703 100644 (file)
@@ -1318,6 +1318,11 @@ static struct e2fsck_problem problem_table[] = {
             "without deletion of an EA.\n"),
          PROMPT_FIX, 0 },
 
+       /* invalid inode creation time */
+       { PR_1_CRTIME_BAD,
+         N_("@i %i creation time (%t) invalid.\n"),
+         PROMPT_CLEAR, PR_PREEN_OK | PR_NO_OK },
+
        /* Failed to goto block group */
        { PR_1_SCAN_GOTO,
          N_("failed to goto block group"),
@@ -1375,6 +1380,11 @@ static struct e2fsck_problem problem_table[] = {
          " %b--%c",
          PROMPT_NONE, PR_LATCH_DBLOCK | PR_PREEN_NOHDR, 0, 0, 0 },
 
+       /* Inode is badly corrupt (badness value = ) */
+       { PR_1B_INODE_TOOBAD,
+         N_("@i %i is badly corrupt (badness value = %N).  "),
+         PROMPT_CLEAR, PR_PREEN_OK },
+
        /* Pass 1C: Scan directories for inodes with multiply-claimed blocks. */
        { PR_1C_PASS_HEADER,
          N_("Pass 1C: Scanning directories for @is with @m @bs\n"),
@@ -1882,6 +1892,10 @@ static struct e2fsck_problem problem_table[] = {
           N_("Duplicate filename @E found.  "),
           PROMPT_CLEAR, 0, 0, 0, 0 },
 
+       /* Inode is badly corrupt (badness value = ) */
+       { PR_2_INODE_TOOBAD,
+         N_("@i %i is badly corrupt (badness value = %N).  "),
+         PROMPT_CLEAR, PR_PREEN_OK },
 
        /* Pass 3 errors */
 
@@ -2470,7 +2484,8 @@ static void print_problem(FILE *f, problem_t code, int answer, int fixed,
        fputs("/>\n", f);
 }
 
-int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
+int fix_problem_loc(e2fsck_t ctx, problem_t code, struct problem_context *pctx,
+                   int badness, const char *func, const int line)
 {
        ext2_filsys fs = ctx->fs;
        struct e2fsck_problem *ptr;
@@ -2481,6 +2496,10 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
        int             suppress = 0;
        int             fixed = 0;
 
+       /* ino is always set in pass1, where we will hit most badness */
+       if (pctx && pctx->ino != 0 && badness && code < PR_3_PASS_HEADER)
+               e2fsck_mark_inode_bad_loc(ctx, pctx, code, badness, func, line);
+
        ptr = find_problem(code);
        if (!ptr) {
                printf(_("Unhandled error code (0x%x)!\n"), code);
@@ -2528,7 +2547,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
        if (ptr->flags & PR_LATCH_MASK &&
            (ldesc = find_latch(ptr->flags & PR_LATCH_MASK)) != NULL) {
                if (ldesc->question && !(ldesc->flags & PRL_LATCHED)) {
-                       ans = fix_problem(ctx, ldesc->question, pctx);
+                       ans = fix_problem_loc(ctx, ldesc->question, pctx,
+                                             0, func, line);
                        if (ans == 1)
                                ldesc->flags |= PRL_YES;
                        if (ans == 0)
@@ -2629,7 +2649,8 @@ int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx)
                fatal_error(ctx, 0);
 
        if (ptr->flags & PR_AFTER_CODE)
-               answer = fix_problem(ctx, ptr->second_code, pctx);
+               answer = fix_problem_loc(ctx, ptr->second_code, pctx,
+                                        0, func, line);
 
        if (answer && (ptr->prompt != PROMPT_NONE) &&
            !(ptr->flags & PR_NOT_A_FIX)) {
@@ -2680,6 +2701,13 @@ void preenhalt(e2fsck_t ctx)
        return;
 }
 
+void e2fsck_mark_inode_bad_loc(e2fsck_t ctx,
+                              struct problem_context *pctx, __u32 code,
+                              int count, const char *func, const int line)
+{
+       return;
+}
+
 errcode_t
 profile_get_string(profile_t profile, const char *name, const char *subname,
                   const char *subsubname, const char *def_val,
index 11068bf..336f3fa 100644 (file)
@@ -694,6 +694,9 @@ struct problem_context {
 /* Inode has illegal EA value inode */
 #define PR_1_ATTR_VALUE_EA_INODE               0x010083
 
+/* Inode has bad timestamp */
+#define PR_1_INODE_BAD_TIME                    0x010084
+
 /* Parent inode has invalid EA entry. EA inode does not have
  * EXT4_EA_INODE_FL flag. Delete EA entry? */
 #define PR_1_ATTR_NO_EA_INODE_FL               0x010085
@@ -744,6 +747,9 @@ struct problem_context {
  */
 #define PR_1_CLEAR_EXTRA_ISIZE                 0x010093
 
+/* invalid inode creation time */
+#define PR_1_CRTIME_BAD                                0x010094
+
 /* Failed to goto block group */
 #define PR_1_SCAN_GOTO                         0x0100A0
 
@@ -778,14 +784,17 @@ struct problem_context {
 /* Duplicate/bad block range in inode */
 #define PR_1B_DUP_RANGE                0x011008
 
+/* Inode is badly corrupt (badness value = ) */
+#define PR_1B_INODE_TOOBAD     0x011009
+
 /* Pass 1C: Scan directories for inodes with dup blocks. */
 #define PR_1C_PASS_HEADER      0x012000
 
 
-/* Pass 1D: Reconciling duplicate blocks */
+/* Pass 1D: Reconciling multiply-claimed blocks */
 #define PR_1D_PASS_HEADER      0x013000
 
-/* File has duplicate blocks */
+/* File has multiply-claimed blocks */
 #define PR_1D_DUP_FILE         0x013001
 
 /* List of files sharing duplicate blocks */
@@ -1081,6 +1090,9 @@ struct problem_context {
 /* Non-unique filename found, but can't rename */
 #define PR_2_NON_UNIQUE_FILE_NO_RENAME 0x020054
 
+/* Inode is badly corrupt (badness value = ) */
+#define PR_2_INODE_TOOBAD              0x020055
+
 /*
  * Pass 3 errors
  */
@@ -1340,7 +1352,14 @@ struct problem_context {
 /*
  * Function declarations
  */
-int fix_problem(e2fsck_t ctx, problem_t code, struct problem_context *pctx);
+#define fix_problem(ctx, code, pctx)                   \
+       fix_problem_bad(ctx, code, pctx, 1)
+#define fix_problem_notbad(ctx, code, pctx)            \
+       fix_problem_bad(ctx, code, pctx, 0)
+#define fix_problem_bad(ctx, code, pctx, badness)      \
+       fix_problem_loc(ctx, code, pctx, badness, __func__, __LINE__)
+int fix_problem_loc(e2fsck_t ctx, problem_t code, struct problem_context *pctx,
+                   int badness, const char *func, const int line);
 int end_problem_latch(e2fsck_t ctx, int mask);
 int set_latch_flags(int mask, int setflags, int clearflags);
 int get_latch_flags(int mask, int *value);
index 123813b..c406b37 100644 (file)
@@ -1040,8 +1040,8 @@ void check_super_block(e2fsck_t ctx)
         * write time is in the future.
         */
        if (((ctx->options & E2F_OPT_FORCE) || fs->super->s_checkinterval) &&
-           !broken_system_clock && !(ctx->flags & E2F_FLAG_TIME_INSANE) &&
-           (fs->super->s_mtime > (__u32) ctx->now)) {
+           !broken_system_clock &&
+           EXT4_XTIME_FUTURE(ctx, fs->super, fs->super->s_mtime, 0)) {
                pctx.num = fs->super->s_mtime;
                problem = PR_0_FUTURE_SB_LAST_MOUNT;
                if (fs->super->s_mtime <= (__u32) ctx->now + ctx->time_fudge)
@@ -1052,8 +1052,8 @@ void check_super_block(e2fsck_t ctx)
                }
        }
        if (((ctx->options & E2F_OPT_FORCE) || fs->super->s_checkinterval) &&
-           !broken_system_clock && !(ctx->flags & E2F_FLAG_TIME_INSANE) &&
-           (fs->super->s_wtime > (__u32) ctx->now)) {
+           !broken_system_clock &&
+           EXT4_XTIME_FUTURE(ctx, fs->super, fs->super->s_wtime, 0)) {
                pctx.num = fs->super->s_wtime;
                problem = PR_0_FUTURE_SB_LAST_WRITE;
                if (fs->super->s_wtime <= (__u32) ctx->now + ctx->time_fudge)
index cb360ea..5f9dbcb 100644 (file)
@@ -792,6 +792,22 @@ static void parse_extended_opts(e2fsck_t ctx, const char *opts)
                                extended_usage++;
                                continue;
                        }
+               /* -E inode_badness_threshold=<value> */
+               } else if (strcmp(token, "inode_badness_threshold") == 0) {
+                       unsigned int val;
+
+                       if (!arg) {
+                               extended_usage++;
+                               continue;
+                       }
+                       val = strtoul(arg, &p, 0);
+                       if (*p != '\0' || (val < 3 && val != 0) || val > 200) {
+                               fprintf(stderr, _("Invalid badness '%s'\n"),
+                                       arg);
+                               extended_usage++;
+                               continue;
+                       }
+                       ctx->inode_badness_threshold = val;
                } else if (strcmp(token, "journal_only") == 0) {
                        if (arg) {
                                extended_usage++;
@@ -867,6 +883,7 @@ static void parse_extended_opts(e2fsck_t ctx, const char *opts)
                fputs(("\tshared=<preserve|lost+found|delete>\n"), stderr);
                fputs(("\tclone=<dup|zero>\n"), stderr);
                fputs(("\texpand_extra_isize\n"), stderr);
+               fputs(("\tinode_badness_threhold=(value)\n"), stderr);
                fputs("\toptimize_extents\n", stderr);
                fputs("\tno_optimize_extents\n", stderr);
                fputs("\tinode_count_fullmap\n", stderr);
@@ -950,6 +967,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
 
        phys_mem_kb = get_memory_size() / 1024;
        ctx->readahead_kb = ~0ULL;
+       ctx->inode_badness_threshold = BADNESS_THRESHOLD;
 
 #ifdef HAVE_PTHREAD
        while ((c = getopt(argc, argv, "pam:nyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:")) != EOF)
index b0c3847..714bed5 100644 (file)
@@ -1546,6 +1546,7 @@ extern errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs, int super_only);
 
 /* icount.c */
 extern void ext2fs_free_icount(ext2_icount_t icount);
+extern int ext2fs_icount_is_set(ext2_icount_t icount, ext2_ino_t ino);
 extern errcode_t ext2fs_create_icount_tdb(ext2_filsys fs, char *tdb_dir,
                                          int flags, ext2_icount_t *ret);
 extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags,
index 48665c7..093f51b 100644 (file)
@@ -137,8 +137,9 @@ static errcode_t alloc_icount(ext2_filsys fs, int flags, ext2_icount_t *ret)
                                                      &icount->multiple);
                if (retval)
                        goto errout;
-       } else
+       } else {
                icount->multiple = 0;
+       }
 
        *ret = icount;
        return 0;
@@ -508,6 +509,23 @@ static errcode_t get_inode_count(ext2_icount_t icount, ext2_ino_t ino,
        return 0;
 }
 
+int ext2fs_icount_is_set(ext2_icount_t icount, ext2_ino_t ino)
+{
+       __u16 result;
+
+       if (ext2fs_test_inode_bitmap2(icount->single, ino))
+               return 1;
+       else if (icount->multiple) {
+               if (ext2fs_test_inode_bitmap2(icount->multiple, ino))
+                       return 1;
+               return 0;
+       }
+       ext2fs_icount_fetch(icount, ino, &result);
+       if (result)
+               return 1;
+       return 0;
+}
+
 errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *out)
 {
        errcode_t       ret = 0;
diff --git a/tests/f_ibadness/expect.1 b/tests/f_ibadness/expect.1
new file mode 100644 (file)
index 0000000..b0233fd
--- /dev/null
@@ -0,0 +1,60 @@
+Pass 1: Checking inodes, blocks, and sizes
+e2fsck_pass1_run: increase inode 13 badness 0 to 1 for 10005
+Inode 13 is in use, but has dtime set.  Fix? yes
+
+e2fsck_pass1_run: increase inode 13 badness 1 to 2 for 2000f
+e2fsck_pass1_run: increase inode 13 badness 2 to 3 for 20044
+add_encrypted_file: increase inode 13 badness 3 to 4 for 1008a
+Inode 13 has encrypt flag but no encryption extended attribute.
+Clear flag? yes
+
+e2fsck_pass1_run: increase inode 13 badness 4 to 6 for 10084
+check_ext_attr: increase inode 13 badness 6 to 7 for 2000e
+process_block: increase inode 13 badness 7 to 8 for 1000e
+Inode 13 has illegal block(s).  Clear? yes
+
+Illegal block #0 (4294967295) in inode 13.  CLEARED.
+process_block: increase inode 13 badness 8 to 9 for 1000e
+Illegal block #1 (4294967295) in inode 13.  CLEARED.
+process_block: increase inode 13 badness 9 to 10 for 1000e
+Illegal block #7 (12345678) in inode 13.  CLEARED.
+process_block: increase inode 13 badness 10 to 11 for 1000e
+Illegal triple indirect block (1234567) in inode 13.  CLEARED.
+check_blocks: increase inode 13 badness 11 to 12 for 1000d
+Inode 13, i_blocks is 3453453, should be 138.  Fix? yes
+
+Pass 2: Checking directory structure
+e2fsck_process_bad_inode: increase inode 13 badness 12 to 13 for 2000e
+i_file_acl for inode 13 (/testfile) is 345, should be zero.
+Clear? yes
+
+e2fsck_process_bad_inode: increase inode 13 badness 13 to 14 for 2000d
+i_faddr for inode 13 (/testfile) is 34534, should be zero.
+Clear? yes
+
+Inode 13 is badly corrupt (badness value = 14).  Clear? yes
+
+Entry 'testfile' in / (2) has deleted/unused inode 13.  Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(1368--1369) -1375
+Fix? yes
+
+Free blocks count wrong for group #0 (6822, counted=6825).
+Fix? yes
+
+Free blocks count wrong (14690, counted=14693).
+Fix? yes
+
+Free inodes count wrong for group #0 (2039, counted=2037).
+Fix? yes
+
+Free inodes count wrong (4087, counted=4085).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/4096 files (9.1% non-contiguous), 1691/16384 blocks
+Exit status is 1
diff --git a/tests/f_ibadness/expect.2 b/tests/f_ibadness/expect.2
new file mode 100644 (file)
index 0000000..44d9c79
--- /dev/null
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/4096 files (0.0% non-contiguous), 1691/16384 blocks
+Exit status is 0
diff --git a/tests/f_ibadness/image.gz b/tests/f_ibadness/image.gz
new file mode 100644 (file)
index 0000000..4c9c22f
Binary files /dev/null and b/tests/f_ibadness/image.gz differ
diff --git a/tests/f_ibadness/name b/tests/f_ibadness/name
new file mode 100644 (file)
index 0000000..bdaceb3
--- /dev/null
@@ -0,0 +1 @@
+Inode with badness over threshold
diff --git a/tests/f_ibadness/script b/tests/f_ibadness/script
new file mode 100644 (file)
index 0000000..324a3e4
--- /dev/null
@@ -0,0 +1,4 @@
+FSCK_OPT="-fyd"
+SECOND_FSCK_OPT=-yf
+
+. $cmd_dir/run_e2fsck
diff --git a/tests/f_ibadness_bad_extents/expect.1 b/tests/f_ibadness_bad_extents/expect.1
new file mode 100644 (file)
index 0000000..86d8884
--- /dev/null
@@ -0,0 +1,74 @@
+Pass 1: Checking inodes, blocks, and sizes
+e2fsck_pass1_run: increase inode 2 badness 0 to 1 for 1005c
+e2fsck_pass1_run: increase inode 8 badness 0 to 1 for 1005c
+e2fsck_pass1_run: increase inode 11 badness 0 to 1 for 1005c
+e2fsck_pass1_run: increase inode 12 badness 0 to 1 for 1005c
+Inode 12 missing EXTENT_FL, but is in extents format
+Fix? yes
+
+e2fsck_pass1_run: increase inode 12 badness 1 to 2 for 10005
+Inode 12 is in use, but has dtime set.  Fix? yes
+
+e2fsck_pass1_run: increase inode 12 badness 2 to 3 for 20044
+e2fsck_pass1_run: increase inode 12 badness 3 to 4 for 10084
+e2fsck_pass1_run: increase inode 12 badness 4 to 5 for 10084
+e2fsck_pass1_run: increase inode 12 badness 5 to 7 for 10084
+check_ext_attr: increase inode 12 badness 7 to 8 for 2000e
+scan_extent_node: increase inode 12 badness 8 to 9 for 10058
+Inode 12 has an invalid extent
+       (logical block 0, invalid physical block 1231231222, len 492)
+Clear? yes
+
+scan_extent_node: increase inode 12 badness 9 to 10 for 10058
+Inode 12 has an invalid extent
+       (logical block 556, invalid physical block 4294967295, len 45)
+Clear? yes
+
+scan_extent_node: increase inode 12 badness 10 to 11 for 10058
+Inode 12 has an invalid extent
+       (logical block 666, invalid physical block 4294967295, len 5)
+Clear? yes
+
+scan_extent_node: increase inode 12 badness 11 to 12 for 10058
+Inode 12 has an invalid extent
+       (logical block 700, invalid physical block 4294967295, len 45)
+Clear? yes
+
+check_blocks: increase inode 12 badness 12 to 13 for 1000d
+Inode 12, i_blocks is 984, should be 0.  Fix? yes
+
+Inode 12 is badly corrupt (badness value = 13).  Clear? yes
+
+Restarting e2fsck from the beginning...
+Pass 1: Checking inodes, blocks, and sizes
+e2fsck_pass1_run: increase inode 2 badness 0 to 1 for 1005c
+e2fsck_pass1_run: increase inode 8 badness 0 to 1 for 1005c
+e2fsck_pass1_run: increase inode 11 badness 0 to 1 for 1005c
+Pass 2: Checking directory structure
+Entry 'testfile' in / (2) has deleted/unused inode 12.  Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(6145--6636)
+Fix? yes
+
+Free blocks count wrong for group #0 (6525, counted=7017).
+Fix? yes
+
+Free blocks count wrong (14584, counted=15076).
+Fix? yes
+
+Inode bitmap differences:  -12
+Fix? yes
+
+Free inodes count wrong for group #0 (1012, counted=1013).
+Fix? yes
+
+Free inodes count wrong (2036, counted=2037).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/2048 files (0.0% non-contiguous), 1308/16384 blocks
+Exit status is 1
diff --git a/tests/f_ibadness_bad_extents/expect.2 b/tests/f_ibadness_bad_extents/expect.2
new file mode 100644 (file)
index 0000000..7560785
--- /dev/null
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/2048 files (0.0% non-contiguous), 1308/16384 blocks
+Exit status is 0
diff --git a/tests/f_ibadness_bad_extents/image.gz b/tests/f_ibadness_bad_extents/image.gz
new file mode 100644 (file)
index 0000000..65d1b46
Binary files /dev/null and b/tests/f_ibadness_bad_extents/image.gz differ
diff --git a/tests/f_ibadness_bad_extents/name b/tests/f_ibadness_bad_extents/name
new file mode 100644 (file)
index 0000000..58bd208
--- /dev/null
@@ -0,0 +1 @@
+All in inode extents corrupt
diff --git a/tests/f_ibadness_bad_extents/script b/tests/f_ibadness_bad_extents/script
new file mode 100644 (file)
index 0000000..324a3e4
--- /dev/null
@@ -0,0 +1,4 @@
+FSCK_OPT="-fyd"
+SECOND_FSCK_OPT=-yf
+
+. $cmd_dir/run_e2fsck
diff --git a/tests/f_ibadness_dup/expect.1 b/tests/f_ibadness_dup/expect.1
new file mode 100644 (file)
index 0000000..11369a1
--- /dev/null
@@ -0,0 +1,125 @@
+Pass 1: Checking inodes, blocks, and sizes
+check_inode_extra_space: increase inode 20 badness 0 to 2 for 10094
+e2fsck_pass1_run: increase inode 20 badness 2 to 4 for 10084
+check_blocks: increase inode 20 badness 4 to 5 for 1000c
+Inode 20, i_size is 58, should be 12288.  Fix? yes
+
+check_blocks: increase inode 20 badness 5 to 6 for 1000d
+Inode 20, i_blocks is 2, should be 24.  Fix? yes
+
+check_blocks: increase inode 25 badness 0 to 1 for 1000c
+Inode 25, i_size is 58, should be 2048.  Fix? yes
+
+check_blocks: increase inode 25 badness 1 to 2 for 1000d
+Inode 25, i_blocks is 2, should be 4.  Fix? yes
+
+check_blocks: increase inode 26 badness 0 to 1 for 1000c
+Inode 26, i_size is 58, should be 2048.  Fix? yes
+
+check_blocks: increase inode 26 badness 1 to 2 for 1000d
+Inode 26, i_blocks is 2, should be 4.  Fix? yes
+
+
+Running additional passes to resolve blocks claimed by more than one inode...
+Pass 1B: Rescanning for multiply-claimed blocks
+Multiply-claimed block(s) in inode 12: 27
+Multiply-claimed block(s) in inode 13: 28
+Multiply-claimed block(s) in inode 14: 29
+Multiply-claimed block(s) in inode 15: 30
+Multiply-claimed block(s) in inode 16: 31
+Multiply-claimed block(s) in inode 17: 32
+Multiply-claimed block(s) in inode 18: 33
+Multiply-claimed block(s) in inode 19: 34
+Multiply-claimed block(s) in inode 20: 27--34 36--38
+Multiply-claimed block(s) in inode 21: 36
+Multiply-claimed block(s) in inode 22: 37
+Multiply-claimed block(s) in inode 23: 38
+Multiply-claimed block(s) in inode 25: 30
+Multiply-claimed block(s) in inode 26: 31
+Pass 1C: Scanning directories for inodes with multiply-claimed blocks
+Pass 1D: Reconciling multiply-claimed blocks
+(There are 14 inodes containing multiply-claimed blocks.)
+
+pass1d: increase inode 12 badness 0 to 1 for 13001
+File /dupe1 (inode #12, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 1 file(s):
+pass1d: increase inode 20 badness 6 to 7 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Clone multiply-claimed blocks? yes
+
+pass1d: increase inode 13 badness 0 to 1 for 13001
+File /dupe2 (inode #13, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 1 file(s):
+pass1d: increase inode 20 badness 7 to 8 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Clone multiply-claimed blocks? yes
+
+pass1d: increase inode 14 badness 0 to 1 for 13001
+File /dupe3 (inode #14, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 1 file(s):
+pass1d: increase inode 20 badness 8 to 9 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Clone multiply-claimed blocks? yes
+
+pass1d: increase inode 15 badness 0 to 1 for 13001
+File /dupe4 (inode #15, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 2 file(s):
+pass1d: increase inode 25 badness 2 to 3 for 13002
+       /dupeE (inode #25, mod time Tue Apr 10 21:00:00 2007)
+pass1d: increase inode 20 badness 9 to 10 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Clone multiply-claimed blocks? yes
+
+pass1d: increase inode 16 badness 0 to 1 for 13001
+File /dupe5 (inode #16, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 2 file(s):
+pass1d: increase inode 26 badness 2 to 3 for 13002
+       /dupeF (inode #26, mod time Tue Apr 10 21:00:00 2007)
+pass1d: increase inode 20 badness 10 to 11 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Clone multiply-claimed blocks? yes
+
+pass1d: increase inode 17 badness 0 to 1 for 13001
+File /dupe6 (inode #17, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 1 file(s):
+pass1d: increase inode 20 badness 11 to 12 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Clone multiply-claimed blocks? yes
+
+pass1d: increase inode 18 badness 0 to 1 for 13001
+File /dupe7 (inode #18, mod time Tue Apr 10 21:00:00 2007) 
+  has 1 multiply-claimed block(s), shared with 1 file(s):
+pass1d: increase inode 20 badness 12 to 13 for 13002
+       /dupe9 (inode #20, mod time Thu Jan  1 03:25:45 1970)
+Inode 20 is badly corrupt (badness value = 13).  Clear? yes
+
+Restarting e2fsck from the beginning...
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Entry 'dupe9' in / (2) has deleted/unused inode 20.  Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(27--29) -32 -35
+Fix? yes
+
+Free blocks count wrong for group #0 (58, counted=57).
+Fix? yes
+
+Free blocks count wrong (58, counted=57).
+Fix? yes
+
+Inode bitmap differences:  -20
+Fix? yes
+
+Free inodes count wrong for group #0 (6, counted=7).
+Fix? yes
+
+Free inodes count wrong (6, counted=7).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 25/32 files (8.0% non-contiguous), 43/100 blocks
+Exit status is 1
diff --git a/tests/f_ibadness_dup/expect.2 b/tests/f_ibadness_dup/expect.2
new file mode 100644 (file)
index 0000000..ba31c13
--- /dev/null
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 25/32 files (8.0% non-contiguous), 43/100 blocks
+Exit status is 0
diff --git a/tests/f_ibadness_dup/name b/tests/f_ibadness_dup/name
new file mode 100644 (file)
index 0000000..9615701
--- /dev/null
@@ -0,0 +1,2 @@
+bad inode with dup blocks over many other inodes
+
diff --git a/tests/f_ibadness_dup/script b/tests/f_ibadness_dup/script
new file mode 100644 (file)
index 0000000..65b94a4
--- /dev/null
@@ -0,0 +1,76 @@
+FSCK_OPT="-fyd" # to debug inode badness
+if ! test -x $DEBUGFS_EXE; then
+       echo "$test_name: $test_description: skipped (no debugfs)"
+       return 0
+fi
+
+SKIP_GUNZIP="true"
+TEST_DATA="$test_name.tmp"
+
+echo "/ Murphy Magic.  The SeCrEt of the UnIvErSe is 43, NOT 42" > $TEST_DATA
+
+touch $TMPFILE
+$MKE2FS -N 32 -F -o Linux -b 1024 $TMPFILE 100 > /dev/null 2>&1 
+$DEBUGFS -w $TMPFILE << EOF > /tmp/log 2>&1
+set_current_time 20070410210000
+set_super_value lastcheck 0
+set_super_value hash_seed null
+set_super_value mkfs_time 20070110210000
+write $TEST_DATA dupe1
+write $TEST_DATA dupe2
+write $TEST_DATA dupe3
+write $TEST_DATA dupe4
+write $TEST_DATA dupe5
+write $TEST_DATA dupe6
+write $TEST_DATA dupe7
+write $TEST_DATA dupe8
+write $TEST_DATA dupe9
+write $TEST_DATA dupeA
+write $TEST_DATA dupeB
+write $TEST_DATA dupeC
+write $TEST_DATA dupeD
+write $TEST_DATA dupeE
+write $TEST_DATA dupeF
+stat dupe1
+stat dupe9
+stat dupeF
+set_inode_field dupe9 mtime 12345
+set_inode_field dupe9 ctime 12345
+set_inode_field dupe9 crtime 12345
+set_inode_field dupe9 block[0] 27
+set_inode_field dupe9 block[1] 28
+set_inode_field dupe9 block[2] 29
+set_inode_field dupe9 block[3] 30
+set_inode_field dupe9 block[4] 31
+set_inode_field dupe9 block[5] 32
+set_inode_field dupe9 block[6] 33
+set_inode_field dupe9 block[7] 34
+set_inode_field dupe9 block[8] 35
+set_inode_field dupe9 block[9] 36
+set_inode_field dupe9 block[10] 37
+set_inode_field dupe9 block[11] 38
+set_inode_field dupeE block[1] 30
+set_inode_field dupeF block[1] 31
+q
+EOF
+
+E2FSCK_TIME=200704102100
+export E2FSCK_TIME
+
+#cp $TMPFILE /tmp/image.sav
+#$DEBUGFS -c -f /dev/stdin > /tmp/log 2>&1 <<- EOF
+#      stat dupe1
+#      stat dupe2
+#      stat dupe3
+#      stat dupe4
+#      stat dupe5
+#      stat dupe6
+#      stat dupe7
+#      stat dupe8
+#      stat dupe9
+#EOF
+. $cmd_dir/run_e2fsck
+
+rm -f $TEST_DATA
+
+unset E2FSCK_TIME TEST_DATA
index 63c128b..c8555cb 100644 (file)
@@ -47,78 +47,7 @@ Illegal block number passed to ext2fs_test_block_bitmap #65536 for multiply clai
 Illegal block number passed to ext2fs_test_block_bitmap #16777215 for multiply claimed block map
  28
 Error while iterating over blocks in inode 12 (pass1b): Illegal indirect block found
-Pass 1C: Scanning directories for inodes with multiply-claimed blocks
-Pass 1D: Reconciling multiply-claimed blocks
-(There are 3 inodes containing multiply-claimed blocks.)
-
-File / (inode #2, mod time Sat Jan 17 21:16:16 2015) 
-  has 1 multiply-claimed block(s), shared with 1 file(s):
-       /a (inode #12, mod time Sat Jan 17 21:16:37 2015)
-Clone multiply-claimed blocks? yes
-
-File /lost+found (inode #11, mod time Sat Jan 17 21:16:16 2015) 
-  has 4 multiply-claimed block(s), shared with 1 file(s):
-       /a (inode #12, mod time Sat Jan 17 21:16:37 2015)
-Clone multiply-claimed blocks? yes
-
-File /a (inode #12, mod time Sat Jan 17 21:16:37 2015) 
-  has 17 multiply-claimed block(s), shared with 4 file(s):
-       <filesystem metadata>
-       /lost+found (inode #11, mod time Sat Jan 17 21:16:16 2015)
-       <The group descriptor inode> (inode #7, mod time Sat Jan 17 21:16:16 2015)
-       / (inode #2, mod time Sat Jan 17 21:16:16 2015)
-Clone multiply-claimed blocks? yes
-
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #16877 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #4096 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #196608 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #33152 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #4243456 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #65536 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #16832 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #16384 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #131072 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529376 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #33206 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #25227264 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529397 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529397 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529397 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #65536 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #1421529397 for multiply claimed block map
-Illegal block number passed to ext2fs_test_block_bitmap #16777215 for multiply claimed block map
-Pass 2: Checking directory structure
-Restarting e2fsck from the beginning...
-Pass 1: Checking inodes, blocks, and sizes
-Inode 12 has illegal block(s).  Clear? yes
-
-Illegal block #1038 (1421529376) in inode 12.  CLEARED.
-Illegal block #1039 (1421529376) in inode 12.  CLEARED.
-Illegal block #1040 (1421529376) in inode 12.  CLEARED.
-Illegal block #1100 (16877) in inode 12.  CLEARED.
-Illegal block #1101 (4096) in inode 12.  CLEARED.
-Illegal block #1102 (1421529376) in inode 12.  CLEARED.
-Illegal block #1103 (1421529376) in inode 12.  CLEARED.
-Illegal block #1104 (1421529376) in inode 12.  CLEARED.
-Illegal block #1106 (196608) in inode 12.  CLEARED.
-Illegal block #1136 (1421529376) in inode 12.  CLEARED.
-Illegal block #1420 (33152) in inode 12.  CLEARED.
-Too many illegal blocks in inode 12.
-Clear inode? yes
+Inode 12 is badly corrupt (badness value = 13).  Clear? yes
 
 Restarting e2fsck from the beginning...
 Pass 1: Checking inodes, blocks, and sizes
@@ -128,9 +57,6 @@ Entry 'a' in / (2) has deleted/unused inode 12.  Clear? yes
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-Block bitmap differences:  -(3--7) -(15--17) -(19--24)
-Fix? yes
-
 Inode bitmap differences:  -12
 Fix? yes
 
@@ -142,5 +68,5 @@ Fix? yes
 
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/128 files (9.1% non-contiguous), 18/512 blocks
+test_filesys: 11/128 files (0.0% non-contiguous), 18/512 blocks
 Exit status is 1
index d0a6dac..411e656 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/128 files (9.1% non-contiguous), 18/512 blocks
+test_filesys: 11/128 files (0.0% non-contiguous), 18/512 blocks
 Exit status is 0
index 708f1da..67cca25 100644 (file)
@@ -20,19 +20,23 @@ Pass 2: Checking directory structure
 i_file_acl for inode 14 (/MAKEDEV) is 4294901760, should be zero.
 Clear? yes
 
+Inode 14 is badly corrupt (badness value = 13).  Clear? yes
+
+Entry 'MAKEDEV' in / (2) has deleted/unused inode 14.  Clear? yes
+
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 Block bitmap differences:  -(43--49)
 Fix? yes
 
-Free blocks count wrong for group #0 (68, counted=75).
+Free blocks count wrong for group #0 (70, counted=77).
 Fix? yes
 
-Free blocks count wrong (68, counted=75).
+Free blocks count wrong (70, counted=77).
 Fix? yes
 
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 29/32 files (3.4% non-contiguous), 25/100 blocks
+test_filesys: 28/32 files (3.6% non-contiguous), 23/100 blocks
 Exit status is 1
index 1fffb02..fb4e83a 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 29/32 files (0.0% non-contiguous), 25/100 blocks
+test_filesys: 28/32 files (0.0% non-contiguous), 23/100 blocks
 Exit status is 0
diff --git a/tests/f_messy_inode/script b/tests/f_messy_inode/script
new file mode 100644 (file)
index 0000000..3277356
--- /dev/null
@@ -0,0 +1,5 @@
+FSCK_OPT="-fy"
+OUT1=$test_name.1.log
+AFTER_CMD="sed -i -e 's/:[0-9]\{4\}:/::/' $OUT1"
+
+. $cmd_dir/run_e2fsck
index 5fd68f3..0115213 100644 (file)
@@ -39,3 +39,4 @@ s/mmp_update_date: .*/mmp_update_date: test date/
 s/mmp_update_time: .*/mmp_update_time: test_time/
 s/MMP last updated by '.*' on .*/MMP last updated by 'test_node' on test date/
 s/MMP update by '.*' at .*/MMP last updated by 'test_node' on test date/
+s/:[0-9]*: \(increase inode [0-9]* badness\)/: \1/