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 7.
+.TP
.BI fragcheck
During pass 1, print a detailed report of any discontiguous blocks for
files in the filesystem.
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_NORMAL 1
+#define BADNESS_HIGH 2
+#define BADNESS_THRESHOLD 8
+#define BADNESS_BAD_MODE 100
+#define BADNESS_LARGE_FILE 2199023255552ULL
+
/*
* Define the extended attribute refcount structure
*/
unsigned long max);
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;
+ 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, ino, count) \
+ e2fsck_mark_inode_bad_loc(ctx, ino, count, __func__, __LINE__)
+extern void e2fsck_mark_inode_bad_loc(e2fsck_t ctx, ino_t ino, int count,
+ const char *func, const int line);
+extern int is_inode_bad(e2fsck_t ctx, ino_t ino);
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 need to be expanded (expand_eisize_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, ino_t ino);
static void add_encrypted_dir(e2fsck_t ctx, ino_t ino);
static void handle_fs_bad_blocks(e2fsck_t ctx);
static void process_inodes(e2fsck_t ctx, char *block_buf);
if (!(pctx->inode->i_flags & BAD_SPECIAL_FLAGS))
return;
+ e2fsck_mark_inode_bad(ctx, pctx->ino, BADNESS_NORMAL);
if (!fix_problem(ctx, PR_1_SET_IMMUTABLE, pctx))
return;
if (EXT2_I_SIZE(inode) == 0)
return;
+ e2fsck_mark_inode_bad(ctx, pctx->ino, BADNESS_NORMAL);
if (!fix_problem(ctx, PR_1_SET_NONZSIZE, pctx))
return;
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;
if (inode->i_extra_isize &&
(inode->i_extra_isize < min || inode->i_extra_isize > max ||
inode->i_extra_isize & 3)) {
+ e2fsck_mark_inode_bad(ctx, pctx->ino, BADNESS_NORMAL);
if (!fix_problem(ctx, PR_1_EXTRA_ISIZE, pctx))
return;
if (inode->i_extra_isize < min || inode->i_extra_isize > max)
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;
}
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;
+ e2fsck_mark_inode_bad(ctx, pctx->ino, BADNESS_HIGH);
}
+out:
+ if (dirty)
+ e2fsck_write_inode_full(ctx, pctx->ino, pctx->inode,
+ EXT2_INODE_SIZE(sb), "pass1");
}
/*
return;
isdir:
+ e2fsck_mark_inode_bad(ctx, pctx->ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_TREAT_AS_DIRECTORY, pctx)) {
inode->i_mode = (inode->i_mode & 07777) | LINUX_S_IFDIR;
e2fsck_write_inode_full(ctx, pctx->ino, inode,
return 0;
}
+/*
+ * 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(e2fsck_t ctx)
{
int i;
ehp = inode->i_block;
#endif
if ((ext2fs_extent_header_verify(ehp,
- sizeof(inode->i_block)) == 0) &&
- (fix_problem(ctx, PR_1_UNSET_EXTENT_FL, &pctx))) {
- inode->i_flags |= EXT4_EXTENTS_FL;
+ sizeof(inode->i_block)) == 0)) {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
+ if (fix_problem(ctx, PR_1_UNSET_EXTENT_FL,
+ &pctx)) {
+ inode->i_flags |= EXT4_EXTENTS_FL;
#ifdef WORDS_BIGENDIAN
- memcpy(inode->i_block, tmp_block,
- sizeof(inode->i_block));
+ memcpy(inode->i_block, tmp_block,
+ sizeof(inode->i_block));
#endif
- e2fsck_write_inode(ctx, ino, inode, "pass1");
- failed_csum = 0;
+ e2fsck_write_inode(ctx, ino, inode,
+ "pass1");
+ failed_csum = 0;
+ }
}
}
* as a special case.
*/
if (inode->i_dtime && inode->i_links_count) {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_ROOT_DTIME, &pctx)) {
inode->i_dtime = 0;
e2fsck_write_inode(ctx, ino, inode,
*
*/
if (inode->i_dtime) {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_SET_DTIME, &pctx)) {
inode->i_dtime = 0;
e2fsck_write_inode(ctx, ino, inode, "pass1");
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);
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
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, ino, BADNESS_NORMAL);
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, ino, BADNESS_NORMAL);
if (inode->i_flags & EXT2_IMAGIC_FL) {
if (imagic_fs) {
if (!ctx->inode_imagic_map)
ext2fs_mark_inode_bitmap2(ctx->inode_imagic_map,
ino);
} else {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_SET_IMAGIC, &pctx)) {
inode->i_flags &= ~EXT2_IMAGIC_FL;
e2fsck_write_inode(ctx, ino,
check_immutable(ctx, &pctx);
check_size(ctx, &pctx);
ctx->fs_sockets_count++;
- } else
- mark_inode_bad(ctx, ino);
+ } else {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
+ }
+
+ if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_atime, ctx->time_fudge))
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
+ else if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_mtime,
+ ctx->time_fudge))
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
+
+ if (EXT4_XTIME_FUTURE(ctx, sb, inode->i_ctime, ctx->time_fudge))
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_HIGH);
+ else if (!precreated_object(inode) &&
+ EXT4_XTIME_ANCIENT(ctx, sb, inode->i_ctime,
+ ctx->time_fudge))
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_HIGH);
+
+ /* i_crtime is checked in check_inode_extra_space() */
+
if (!(inode->i_flags & EXT4_EXTENTS_FL) &&
!(inode->i_flags & EXT4_INLINE_DATA_FL)) {
if (inode->i_block[EXT2_IND_BLOCK])
}
/*
- * 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, ino_t ino, int count,
+ const char *func, const int line)
{
struct problem_context pctx;
+ __u16 result;
- if (!ctx->inode_bad_map) {
+ if (!ctx->inode_badness) {
clear_problem_context(&pctx);
- pctx.errcode = e2fsck_allocate_inode_bitmap(ctx->fs,
- _("bad inode map"), EXT2FS_BMAP64_RBTREE,
- "inode_bad_map", &ctx->inode_bad_map);
+ pctx.errcode = ext2fs_create_icount2(ctx->fs, 0, 0, NULL,
+ &ctx->inode_badness);
if (pctx.errcode) {
- pctx.num = 3;
- fix_problem(ctx, PR_1_ALLOCATE_IBITMAP_ERROR, &pctx);
- /* Should never get here */
+ 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, ino, &result);
+ ext2fs_icount_store(ctx->inode_badness, ino, count + result);
+
+ if (ctx->options & E2F_OPT_DEBUG)
+ fprintf(stderr, "%s:%d: increase inode %lu badness %u to %u\n",
+ func, line, (unsigned long)ino, result, count + result);
}
static void add_encrypted_dir(e2fsck_t ctx, 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, ino, BADNESS_NORMAL);
return 0;
}
if ((!LINUX_S_ISDIR(inode->i_mode) &&
fix_problem(ctx, PR_1_HTREE_NODIR, pctx)) ||
- (!ext2fs_has_feature_dir_index(fs->super) &&
- fix_problem(ctx, PR_1_HTREE_SET, pctx)))
- return 1;
+ (!ext2fs_has_feature_dir_index(fs->super))) {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
+ if (fix_problem(ctx, PR_1_HTREE_SET, pctx))
+ return 1;
+ }
pctx->errcode = ext2fs_bmap2(fs, ino, inode, 0, 0, 0, 0, &blk);
(blk == 0) ||
(blk < fs->super->s_first_data_block) ||
(blk >= ext2fs_blocks_count(fs->super))) {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
return 1;
else
}
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) {
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
+ 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
}
if (try_repairs && problem) {
+ /* To ensure that extent is in inode */
+ if (info.curr_level == 0)
+ e2fsck_mark_inode_bad(ctx, pctx->ino,
+ BADNESS_HIGH);
report_problem:
if (fix_problem(ctx, problem, pctx)) {
if (ctx->invalid_bitmaps) {
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.
+ */
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) {
e2fsck_clear_inode(ctx, ino, inode, 0, "check_blocks");
ctx->fs_directory_count--;
if (bad_size != 7)
pctx->num = (pb.last_block + 1) * fs->blocksize;
pctx->group = bad_size;
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_BAD_I_SIZE, pctx)) {
if (LINUX_S_ISDIR(inode->i_mode))
pctx->num &= 0xFFFFFFFFULL;
(inode->i_flags & EXT4_HUGE_FILE_FL) &&
(inode->osd2.linux2.l_i_blocks_hi != 0)))) {
pctx->num = pb.num_blocks;
+ e2fsck_mark_inode_bad(ctx, ino, BADNESS_NORMAL);
if (fix_problem(ctx, PR_1_BAD_I_BLOCKS, pctx)) {
inode->i_blocks = pb.num_blocks;
inode->osd2.linux2.l_i_blocks_hi = pb.num_blocks >> 32;
problem = PR_1_TOOBIG_SYMLINK;
if (blk < fs->super->s_first_data_block ||
- blk >= ext2fs_blocks_count(fs->super))
+ blk >= ext2fs_blocks_count(fs->super)) {
problem = PR_1_ILLEGAL_BLOCK_NUM;
+ e2fsck_mark_inode_bad(ctx, pctx->ino, BADNESS_NORMAL);
+ }
/*
* If this IND/DIND/TIND block is squatting atop some critical metadata
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_badness)
+ e2fsck_mark_inode_bad(ctx, ino, 0);
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
*
* Pass 2 frees the following data structures
- * - The inode_bad_map bitmap
* - The inode_reg_map bitmap
*/
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;
{
int filetype = ext2fs_dirent_file_type(dirent);
int should_be = EXT2_FT_UNKNOWN;
+ __u16 result;
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,
+ &result);
+
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))
+ } else if (ctx->inode_badness && result >= BADNESS_BAD_MODE) {
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
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;
+ if (ctx->inode_badness)
+ ext2fs_icount_fetch(ctx->inode_badness, ino, &badness);
e2fsck_read_inode(ctx, ino, &inode, "process_bad_inode");
clear_problem_context(&pctx);
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
}
if (!LINUX_S_ISDIR(inode.i_mode) && !LINUX_S_ISREG(inode.i_mode) &&
} else
not_fixed++;
problem = 0;
+ /*
+ * A high value is associated with bad mode in order to detect
+ * that mode was corrupt in check_filetype()
+ */
+ badness += BADNESS_BAD_MODE;
}
if (inode.i_faddr) {
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
}
switch (fs->super->s_creator_os) {
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
pctx.num = 0;
}
if (fsize && *fsize) {
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
pctx.num = 0;
}
+ /* In pass1 these conditions were used to mark inode bad so that
+ * it calls e2fsck_process_bad_inode and make an extensive check
+ * plus prompt for action to be taken. To compensate for badness
+ * incremented in pass1 by this condition, decrease it.
+ */
+ if ((inode.i_faddr || frag || fsize ||
+ (LINUX_S_ISDIR(inode.i_mode) && inode.i_size_high)) ||
+ (inode.i_file_acl &&
+ (!(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) ||
+ (inode.i_file_acl < fs->super->s_first_data_block) ||
+ (inode.i_file_acl >= fs->super->s_blocks_count)))) {
+ /* badness can be 0 if called from pass4. */
+ if (badness)
+ badness -= BADNESS_NORMAL;
+ }
+
if ((fs->super->s_creator_os == EXT2_OS_LINUX) &&
!ext2fs_has_feature_huge_file(fs->super) &&
(inode.osd2.linux2.l_i_blocks_hi != 0)) {
inode.osd2.linux2.l_i_blocks_hi = 0;
inode_modified++;
}
+ /* Badness was increased in pass1 for this condition */
+ /* badness += BADNESS_NORMAL; */
}
if ((fs->super->s_creator_os == EXT2_OS_LINUX) &&
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
}
if (ext2fs_file_acl_block(fs, &inode) &&
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
}
if (inode.i_size_high && !ext2fs_has_feature_largedir(fs->super) &&
LINUX_S_ISDIR(inode.i_mode)) {
inode_modified++;
} else
not_fixed++;
+ badness += BADNESS_NORMAL;
+ }
+
+ /*
+ * The high value due to BADNESS_BAD_MODE should not delete the inode.
+ */
+ if (ctx->inode_badness && (badness - (badness >= BADNESS_BAD_MODE ?
+ BADNESS_BAD_MODE : 0)) >=
+ ctx->inode_badness_threshold) {
+ pctx.num = badness;
+ if (fix_problem(ctx, PR_2_INODE_TOOBAD, &pctx)) {
+ deallocate_inode(ctx, ino, 0);
+ if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
+ return 0;
+ return 1;
+ }
+ 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);
+ if (ctx->inode_badness)
+ ext2fs_icount_store(ctx->inode_badness, ino, 0);
return 0;
}
}
ext2fs_free_icount(ctx->inode_link_info); ctx->inode_link_info = 0;
ext2fs_free_icount(ctx->inode_count); ctx->inode_count = 0;
+ ext2fs_free_icount(ctx->inode_badness); ctx->inode_badness = 0;
ext2fs_free_inode_bitmap(ctx->inode_bb_map);
ctx->inode_bb_map = 0;
ea_refcount_free(ctx->ea_inode_refs);
"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 },
+
/* Pass 1b errors */
N_("Encrypted @E is too short.\n"),
PROMPT_CLEAR, 0, 0, 0, 0 },
+ /* Inode too bad */
+ { PR_2_INODE_TOOBAD,
+ N_("@i %i is badly corrupt (badness value = %N). "),
+ PROMPT_CLEAR, PR_PREEN_OK },
+
/* Pass 3 errors */
/* Pass 3: Checking directory connectivity */
*/
#define PR_1_CLEAR_EXTRA_ISIZE 0x01008E
+/* invalid inode creation time */
+#define PR_1_CRTIME_BAD 0x01008F
+
/*
* Pass 1b errors
*/
/* Encrypted directory entry is too short */
#define PR_2_BAD_ENCRYPTED_NAME 0x020050
+/* Inode completely corrupt */
+#define PR_2_INODE_TOOBAD 0x020051
+
/*
* Pass 3 errors
*/
* write time is in the future.
*/
if (!broken_system_clock && fs->super->s_checkinterval &&
- !(ctx->flags & E2F_FLAG_TIME_INSANE) &&
- fs->super->s_mtime > (__u32) ctx->now) {
+ 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 (!broken_system_clock && fs->super->s_checkinterval &&
- !(ctx->flags & E2F_FLAG_TIME_INSANE) &&
- fs->super->s_wtime > (__u32) ctx->now) {
+ 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) {
+ if (!arg) {
+ extended_usage++;
+ continue;
+ }
+ ctx->inode_badness_threshold = strtoul(arg, &p, 0);
+ if (*p != '\0' || ctx->inode_badness_threshold > 200) {
+ fprintf(stderr, _("Invalid badness value.\n"));
+ extended_usage++;
+ continue;
+ }
} 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;
+
while ((c = getopt(argc, argv, "panyrcC:B:dE:fvtFVM:b:I:j:P:l:L:N:SsDkz:")) != EOF)
switch (c) {
case 'C':
/* 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;
Filesystem did not have a UUID; generating one.
Pass 1: Checking inodes, blocks, and sizes
+check_ext_attr:: increase inode 14 badness 0 to 1
+process_block:: increase inode 14 badness 1 to 2
Inode 14 has illegal block(s). Clear? yes
Illegal block #2 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 2 to 3
Illegal block #3 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 3 to 4
Illegal block #4 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 4 to 5
Illegal block #5 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 5 to 6
Illegal block #6 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 6 to 7
Illegal block #7 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 7 to 8
Illegal block #8 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 8 to 9
Illegal block #9 (4294901760) in inode 14. CLEARED.
+process_block:: increase inode 14 badness 9 to 10
Illegal block #10 (4294901760) in inode 14. CLEARED.
+check_blocks:: increase inode 14 badness 10 to 11
Inode 14, i_size is 18446462598732849291, should be 2048. Fix? yes
+check_blocks:: increase inode 14 badness 11 to 12
Inode 14, i_blocks is 18, should be 4. Fix? yes
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
+
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 -d"
+OUT1=$test_name.1.log
+AFTER_CMD="sed -i -e 's/:[0-9]\{4\}:/::/' $OUT1"
+
+. $cmd_dir/run_e2fsck