>From b9fb5efebee024a53656fe063bf5a0ccf349401c Mon Sep 17 00:00:00 2001 From: Jaco Kroon Date: Tue, 24 Jul 2018 13:18:07 +0200 Subject: [PATCH] Allow opening a filesystem with maxed out inode count. In some scenarios if we resized a filesystem over the limit it could happen that inode count wrapped over, typically to 0. This change would enable us to set the number of inodes on the filesystem to 2^32-1 in order to enable continuing to use the filesystem. This change is required to allow fsck to "clear" the filesystem in order to operate on it. --- e2fsck/super.c | 5 +---- lib/ext2fs/openfs.c | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/e2fsck/super.c b/e2fsck/super.c index eb7ab0d1..3f1a219f 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -665,10 +665,7 @@ void check_super_block(e2fsck_t ctx) should_be = (__u64)sb->s_inodes_per_group * fs->group_desc_count; if (should_be > ~0U) { - pctx.num = should_be; - fix_problem(ctx, PR_0_INODE_COUNT_BIG, &pctx); - ctx->flags |= E2F_FLAG_ABORT; - return; + should_be = ~0U; } if (sb->s_inodes_count != should_be) { pctx.ino = sb->s_inodes_count; diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 85d73e2a..a7a343f9 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -129,6 +129,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, int group_zero_adjust = 0; unsigned int inode_size; __u64 groups_cnt; + __u64 inode_cnt; #ifdef WORDS_BIGENDIAN unsigned int groups_per_block; struct ext2_group_desc *gdp; @@ -386,9 +387,9 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; } fs->group_desc_count = groups_cnt; + inode_cnt = (__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super); if (!(flags & EXT2_FLAG_IGNORE_SB_ERRORS) && - (__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != - fs->super->s_inodes_count) { + (inode_cnt < (1ULL<<32) ? inode_cnt : ~0U) != fs->super->s_inodes_count) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } -- 2.16.4