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.
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);
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;
#include <stdio.h>
#include <string.h>
+#include <stddef.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
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
*/
/* 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 */
*/
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;
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 */
* - 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)
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, ext2_ino_t ino);
static void add_casefolded_dir(e2fsck_t ctx, ext2_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);
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;
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 */
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;
}
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.
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))
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,
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)
#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; \
} \
}
+/*
+ * 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;
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) {
#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);
}
}
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)
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])
goto endit;
}
}
+ next_unlock:
e2fsck_pass1_check_unlock(ctx);
}
process_inodes(ctx, block_buf, inodes_to_process,
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,
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;
}
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)
}
/*
- * 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, ext2_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, ext2_ino_t ino)
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;
}
}
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);
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
#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,
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;
}
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--;
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");
}
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;
}
*/
struct dup_inode {
ext2_ino_t dir;
- int num_dupblocks;
+ unsigned int num_dupblocks;
struct ext2_inode_large inode;
struct cluster_el *cluster_list;
};
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);
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)) {
}
}
+out:
/*
* Time to free all of the accumulated data structures that we
* don't need anymore.
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,
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) ||
}
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);
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;
}
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);
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);
* 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() */
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;
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) {
{
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)) {
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);
}
}
- /*
- * 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 -
}
}
+ /*
+ * 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
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))
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;
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);
}
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;
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;
}
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;
/*
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;
/*
"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"),
" %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"),
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 */
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;
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);
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)
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)) {
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,
/* 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
*/
#define PR_1_CLEAR_EXTRA_ISIZE 0x010095
+/* invalid inode creation time */
+#define PR_1_CRTIME_BAD 0x010096
+
/* Failed to goto block group */
#define PR_1_SCAN_GOTO 0x0100A0
/* 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 */
/* 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
*/
/*
* 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);
* 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)
}
}
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)
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++;
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);
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)
/* 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,
&icount->multiple);
if (retval)
goto errout;
- } else
+ } else {
icount->multiple = 0;
+ }
*ret = icount;
return 0;
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;
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+Inode with badness over threshold
--- /dev/null
+FSCK_OPT="-fyd"
+SECOND_FSCK_OPT=-yf
+
+. $cmd_dir/run_e2fsck
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+All in inode extents corrupt
--- /dev/null
+FSCK_OPT="-fyd"
+SECOND_FSCK_OPT=-yf
+
+. $cmd_dir/run_e2fsck
--- /dev/null
+Pass 1: Checking inodes, blocks, and sizes
+check_inode_extra_space: increase inode 20 badness 0 to 2 for 10096
+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
--- /dev/null
+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
--- /dev/null
+bad inode with dup blocks over many other inodes
+
--- /dev/null
+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
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
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
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
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
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
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
--- /dev/null
+FSCK_OPT="-fy"
+OUT1=$test_name.1.log
+AFTER_CMD="sed -i -e 's/:[0-9]\{4\}:/::/' $OUT1"
+
+. $cmd_dir/run_e2fsck
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/