ctx->fs_fragmented = 0;
ctx->fs_fragmented_dir = 0;
ctx->large_files = 0;
+ ctx->large_dirs = 0;
for (i=0; i < MAX_EXTENT_DEPTH_COUNT; i++)
ctx->extent_depth_count[i] = 0;
__u32 fs_fragmented;
__u32 fs_fragmented_dir;
__u32 large_files;
+ __u32 large_dirs;
__u32 fs_ext_attr_inodes;
__u32 fs_ext_attr_blocks;
__u32 extent_depth_count[MAX_EXTENT_DEPTH_COUNT];
switch (ch) {
case 's':
- if (LINUX_S_ISDIR(inode->i_mode))
- fprintf(f, "%u", inode->i_size);
- else
- fprintf(f, "%llu", EXT2_I_SIZE(inode));
+ fprintf(f, "%llu", EXT2_I_SIZE(inode));
break;
case 'S':
fprintf(f, "%u", large_inode->i_extra_isize);
goto endit;
}
+ if (ctx->large_dirs && !ext2fs_has_feature_largedir(ctx->fs->super)) {
+ ext2_filsys fs = ctx->fs;
+
+ if (fix_problem(ctx, PR_2_FEATURE_LARGE_DIRS, &pctx)) {
+ ext2fs_set_feature_largedir(fs->super);
+ fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
+ ext2fs_mark_super_dirty(fs);
+ }
+ if (fs->super->s_rev_level == EXT2_GOOD_OLD_REV &&
+ fix_problem(ctx, PR_1_FS_REV_LEVEL, &pctx)) {
+ ext2fs_update_dynamic_rev(fs);
+ ext2fs_mark_super_dirty(fs);
+ }
+ }
+
if (ctx->block_dup_map) {
if (ctx->options & E2F_OPT_PREEN) {
clear_problem_context(&pctx);
return 1;
pctx->num = root->indirect_levels;
- if ((root->indirect_levels >= ext2_dir_htree_level(fs)) &&
+ /* if htree level is clearly too high, consider it to be broken */
+ if (root->indirect_levels > EXT4_HTREE_LEVEL &&
fix_problem(ctx, PR_1_HTREE_DEPTH, pctx))
return 1;
+ /* if level is only maybe too high, LARGE_DIR feature could be unset */
+ if (root->indirect_levels > ext2_dir_htree_level(fs) &&
+ !ext2fs_has_feature_largedir(fs->super)) {
+ int blockbits = EXT2_BLOCK_SIZE_BITS(fs->super) + 10;
+ int idx_pb = 1 << (blockbits - 3);
+
+ /* compare inode size/blocks vs. max-sized 2-level htree */
+ if (EXT2_I_SIZE(pctx->inode) <
+ (idx_pb - 1) * (idx_pb - 2) << blockbits &&
+ pctx->inode->i_blocks <
+ (idx_pb - 1) * (idx_pb - 2) << (blockbits - 9) &&
+ fix_problem(ctx, PR_1_HTREE_DEPTH, pctx))
+ return 1;
+ }
+
+ if (root->indirect_levels > EXT4_HTREE_LEVEL_COMPAT ||
+ ext2fs_needs_large_file_feature(EXT2_I_SIZE(inode)))
+ ctx->large_dirs++;
+
return 0;
}
(extent.e_pblk + extent.e_len) >
ext2fs_blocks_count(ctx->fs->super))
problem = PR_1_EXTENT_ENDS_BEYOND;
- else if (is_leaf && is_dir &&
+ else if (is_leaf && is_dir && !pctx->inode->i_size_high &&
+ !ext2fs_has_feature_largedir(ctx->fs->super) &&
((extent.e_lblk + extent.e_len) >
(1U << (21 - ctx->fs->super->s_log_block_size))))
problem = PR_1_TOOBIG_DIR;
ino, inode->i_size, pb.last_block, ext2fs_inode_i_blocks(fs, inode),
pb.num_blocks);
#endif
+ size = EXT2_I_SIZE(inode);
if (pb.is_dir) {
- unsigned nblock = inode->i_size >> EXT2_BLOCK_SIZE_BITS(fs->super);
+ unsigned nblock = size >> EXT2_BLOCK_SIZE_BITS(fs->super);
if (inode->i_flags & EXT4_INLINE_DATA_FL) {
int flags;
size_t sz = 0;
EXT2_FLAG_IGNORE_CSUM_ERRORS) |
(ctx->fs->flags &
~EXT2_FLAG_IGNORE_CSUM_ERRORS);
- if (err || sz != inode->i_size) {
+ if (err || sz != size) {
bad_size = 7;
pctx->num = sz;
}
- } else if (inode->i_size & (fs->blocksize - 1))
+ } else if (size & (fs->blocksize - 1))
bad_size = 5;
else if (nblock > (pb.last_block + 1))
bad_size = 1;
bad_size = 2;
}
} else {
- size = EXT2_I_SIZE(inode);
if ((pb.last_init_lblock >= 0) &&
/* Do not allow initialized allocated blocks past i_size*/
(size < (__u64)pb.last_init_lblock * fs->blocksize) &&
pctx->num = (pb.last_block + 1) * fs->blocksize;
pctx->group = bad_size;
if (fix_problem(ctx, PR_1_BAD_I_SIZE, pctx)) {
- if (LINUX_S_ISDIR(inode->i_mode))
- pctx->num &= 0xFFFFFFFFULL;
ext2fs_inode_size_set(fs, inode, pctx->num);
if (EXT2_I_SIZE(inode) == 0 &&
(inode->i_flags & EXT4_INLINE_DATA_FL)) {
}
if (p->is_dir && !ext2fs_has_feature_largedir(fs->super) &&
+ !pctx->inode->i_size_high &&
blockcnt > (1 << (21 - fs->super->s_log_block_size)))
problem = PR_1_TOOBIG_DIR;
if (p->is_dir && p->num_blocks + 1 >= p->max_blocks)
root = (struct ext2_dx_root_info *) (buf + 24);
dx_db->type = DX_DIRBLOCK_ROOT;
dx_db->flags |= DX_FLAG_FIRST | DX_FLAG_LAST;
+
+ /* large_dir was set in pass1 if large dirs were found,
+ * so ext2_dir_htree_level() should now be correct */
if ((root->reserved_zero ||
root->info_length < 8 ||
root->indirect_levels >=
if (inode.i_flags & EXT4_INLINE_DATA_FL)
goto clear_inode;
- if (LINUX_S_ISREG(inode.i_mode) &&
- ext2fs_needs_large_file_feature(EXT2_I_SIZE(&inode)))
- ctx->large_files--;
+ if (ext2fs_needs_large_file_feature(EXT2_I_SIZE(&inode))) {
+ if (LINUX_S_ISREG(inode.i_mode))
+ ctx->large_files--;
+ else if (LINUX_S_ISDIR(inode.i_mode))
+ ctx->large_dirs--;
+ }
del_block.ctx = ctx;
del_block.num = 0;
not_fixed++;
}
if (inode.i_size_high && !ext2fs_has_feature_largedir(fs->super) &&
+ inode.i_blocks < 1ULL << (29 - EXT2_BLOCK_SIZE_BITS(fs->super)) &&
LINUX_S_ISDIR(inode.i_mode)) {
if (fix_problem(ctx, PR_2_DIR_SIZE_HIGH_ZERO, &pctx)) {
inode.i_size_high = 0;
/* Filesystem contains large files, but has no such flag in sb */
{ PR_2_FEATURE_LARGE_FILES,
N_("@f contains large files, but lacks LARGE_FILE flag in @S.\n"),
- PROMPT_FIX, 0, 0, 0, 0 },
+ PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 },
/* Node in HTREE directory not referenced */
{ PR_2_HTREE_NOTREF,
{ PR_2_HTREE_CLEAR,
N_("@n @h %d (%q). "), PROMPT_CLEAR_HTREE, 0, 0, 0, 0 },
+ /* Filesystem has large directories, but has no such flag in sb */
+ { PR_2_FEATURE_LARGE_DIRS,
+ N_("@f has large directories, but lacks LARGE_DIR flag in @S.\n"),
+ PROMPT_FIX, PR_PREEN_OK, 0, 0, 0 },
+
/* Bad block in htree interior node */
{ PR_2_HTREE_BADBLK,
N_("@p @h %d (%q): bad @b number %b.\n"),
N_("Error adjusting refcount for @a @b %b (@i %i): %m\n"),
PROMPT_NONE, PR_FATAL, 0, 0, 0 },
- /* Invalid HTREE root node */
+ /* Problem in HTREE directory inode: root node is invalid */
{ PR_2_HTREE_BAD_ROOT,
/* xgettext:no-c-format */
N_("@p @h %d: root node is @n\n"),
/* Clear invalid HTREE directory */
#define PR_2_HTREE_CLEAR 0x020038
-/* Clear the htree flag forcibly */
-/* #define PR_2_HTREE_FCLR 0x020039 */
+/* Filesystem has large directories, but has no such flag in superblock */
+#define PR_2_FEATURE_LARGE_DIRS 0x020039
/* Bad block in htree interior node */
#define PR_2_HTREE_BADBLK 0x02003A
if (size < 0)
return EINVAL;
- /* Only regular files get to be larger than 4GB */
- if (!LINUX_S_ISREG(inode->i_mode) && (size >> 32))
- return EXT2_ET_FILE_TOO_BIG;
-
- /* If we're writing a large file, set the large_file flag */
- if (LINUX_S_ISREG(inode->i_mode) &&
- ext2fs_needs_large_file_feature(size) &&
- (!ext2fs_has_feature_large_file(fs->super) ||
- fs->super->s_rev_level == EXT2_GOOD_OLD_REV)) {
- ext2fs_set_feature_large_file(fs->super);
- ext2fs_update_dynamic_rev(fs);
- ext2fs_mark_super_dirty(fs);
+ /* If writing a large inode, set the large_file or large_dir flag */
+ if (ext2fs_needs_large_file_feature(size)) {
+ int dirty_sb = 0;
+
+ if (LINUX_S_ISREG(inode->i_mode)) {
+ if (!ext2fs_has_feature_large_file(fs->super)) {
+ ext2fs_set_feature_large_file(fs->super);
+ dirty_sb = 1;
+ }
+ } else if (LINUX_S_ISDIR(inode->i_mode)) {
+ if (!ext2fs_has_feature_largedir(fs->super)) {
+ ext2fs_set_feature_largedir(fs->super);
+ dirty_sb = 1;
+ }
+ } else {
+ /* Only regular files get to be larger than 4GB */
+ return EXT2_ET_FILE_TOO_BIG;
+ }
+ if (dirty_sb) {
+ if (fs->super->s_rev_level == EXT2_GOOD_OLD_REV)
+ ext2fs_update_dynamic_rev(fs);
+ ext2fs_mark_super_dirty(fs);
+ }
}
inode->i_size = size & 0xffffffff;
if (retval)
return retval;
- inode.i_size += fs->blocksize;
+ retval = ext2fs_inode_size_set(fs, &inode,
+ EXT2_I_SIZE(&inode) + fs->blocksize);
+ if (retval)
+ return retval;
ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
retval = ext2fs_write_inode(fs, dir, &inode);
return retval;
#ifdef PUNCH_DEBUG
- printf("%u: write inode size now %u blocks %u\n",
- ino, inode->i_size, inode->i_blocks);
+ printf("%u: write inode size now %lu blocks %u\n",
+ ino, EXT2_I_SIZE(inode), inode->i_blocks);
#endif
return ext2fs_write_inode(fs, ino, inode);
}
}
out_inode:
#ifdef RES_GDT_DEBUG
- printf("inode.i_blocks = %u, i_size = %u\n", inode.i_blocks,
- inode.i_size);
+ printf("inode.i_blocks = %u, i_size = %lu\n", inode.i_blocks,
+ EXT2_I_SIZE(&inode));
#endif
if (inode_dirty) {
inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(0);
Pass 1: Checking inodes, blocks, and sizes
+Inode 15, i_size is 51539608576, should be 1024. Fix? yes
+
Pass 2: Checking directory structure
i_faddr for inode 15 (/test/quux) is 23, should be zero.
Clear? yes
-i_size_high for inode 15 (/test/quux) is 12, should be zero.
-Clear? yes
-
i_file_acl for inode 13 (/test/???) is 12, should be zero.
Clear? yes