From d4b0ce03168d313e89110ab9fbaa6caf616d1786 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 18 Jun 1999 01:09:29 +0000 Subject: [PATCH] ChangeLog, problem.c, problem.h, super.c: problem.c, problem.h (PR_0_INODE_COUNT_WRONG): Add new problem code. super.c (check_super_block): Add check to make sure the total number of inodes is sane, since this can be calculated from the number of groups times the number of inodes per group. Offer to correct it if it is incorrect. --- e2fsck/ChangeLog | 10 ++++++++++ e2fsck/problem.c | 5 +++++ e2fsck/problem.h | 3 +++ e2fsck/super.c | 10 ++++++++++ 4 files changed, 28 insertions(+) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index c4c103d..3752671 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,13 @@ +1999-05-22 + + * problem.c, problem.h (PR_0_INODE_COUNT_WRONG): Add new problem + code. + + * super.c (check_super_block): Add check to make sure the total + number of inodes is sane, since this can be calculated + from the number of groups times the number of inodes per + group. Offer to correct it if it is incorrect. + 1999-03-19 * pass5.c (check_block_end): Fix fencepost condition where when diff --git a/e2fsck/problem.c b/e2fsck/problem.c index 6811826..e7a0dc6 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -164,6 +164,11 @@ static const struct e2fsck_problem problem_table[] = { { PR_0_GETSIZE_ERROR, "Error determining size of the physical device: %m\n", PROMPT_NONE, PR_FATAL }, + + /* Inode count in superblock is incorrect */ + { PR_0_INODE_COUNT_WRONG, + "@i count in @S is %i, should be %j\n", + PROMPT_FIX, 0 }, /* Pass 1 errors */ diff --git a/e2fsck/problem.h b/e2fsck/problem.h index 240bd7a..1e21440 100644 --- a/e2fsck/problem.h +++ b/e2fsck/problem.h @@ -88,6 +88,9 @@ struct problem_context { /* Error determing physical device size of filesystem */ #define PR_0_GETSIZE_ERROR 0x00000C +/* Inode count in the superblock incorrect */ +#define PR_0_INODE_COUNT_WRONG 0x00000D + /* * Pass 1 errors */ diff --git a/e2fsck/super.c b/e2fsck/super.c index ce33c3a..66a8eb5 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -138,6 +138,16 @@ void check_super_block(e2fsck_t ctx) return; } + should_be = s->s_inodes_per_group * fs->group_desc_count; + if (s->s_inodes_count != should_be) { + pctx.ino = s->s_inodes_count; + pctx.ino2 = should_be; + if (fix_problem(ctx, PR_0_INODE_COUNT_WRONG, &pctx)) { + s->s_inodes_count = should_be; + ext2fs_mark_super_dirty(fs); + } + } + /* * Verify the group descriptors.... */ -- 1.8.3.1