ChangeLog, pass3.c, pass4.c, problem.c, problem.h, super.c:
problem.c: Add PR_3_NO_DIRINFO error code.
super.c (check_super_value): Rename min and max to min_val and max_val
to avoid possible cpp macro conflicts.
pass4.c (e2fsck_pass4): Rename max to maxgroup, to avoid possible cpp
macro conflicts.
pass3.c (e2fsck_pass3): Rename max to maxdirs, to avoid possible cpp
macro conflicts.
(check_directory): Fix logic to avoid possible core dump in the
case of ext2fs_get_dir_info returning NULL. (By the time we get here,
it should never happen, but...). Also simply/streamline the control
flow of the function.
diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index 59db2cc..7ef240e 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,3 +1,20 @@
+1998-09-02 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * problem.c: Add PR_3_NO_DIRINFO error code.
+
+ * super.c (check_super_value): Rename min and max to min_val and
+ max_val to avoid possible cpp macro conflicts.
+
+ * pass4.c (e2fsck_pass4): Rename max to maxgroup, to avoid
+ possible cpp macro conflicts.
+
+ * pass3.c (e2fsck_pass3): Rename max to maxdirs, to avoid possible
+ cpp macro conflicts.
+ (check_directory): Fix logic to avoid possible core dump
+ in the case of ext2fs_get_dir_info returning NULL. (By
+ the time we get here, it should never happen, but...).
+ Also simply/streamline the control flow of the function.
+
1998-08-17 Theodore Ts'o <tytso@rsts-11.mit.edu>
* unix.c (check_if_skip): Move the "not cleanly mounted" check
diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c
index c87ebd9..0700698 100644
--- a/e2fsck/pass3.c
+++ b/e2fsck/pass3.c
@@ -64,7 +64,7 @@
#endif
struct problem_context pctx;
struct dir_info *dir;
- unsigned long max, count;
+ unsigned long maxdirs, count;
#ifdef RESOURCE_TRACK
init_resource_track(&rtrack);
@@ -109,16 +109,16 @@
ext2fs_mark_inode_bitmap(inode_done_map, EXT2_ROOT_INO);
- max = e2fsck_get_num_dirinfo(ctx);
+ maxdirs = e2fsck_get_num_dirinfo(ctx);
count = 1;
if (ctx->progress)
- if ((ctx->progress)(ctx, 3, 0, max))
+ if ((ctx->progress)(ctx, 3, 0, maxdirs))
goto abort_exit;
for (i=0; (dir = e2fsck_dir_info_iter(ctx, &i)) != 0;) {
if (ctx->progress)
- if ((ctx->progress)(ctx, 3, count++, max))
+ if ((ctx->progress)(ctx, 3, count++, maxdirs))
goto abort_exit;
if (ext2fs_test_inode_bitmap(ctx->inode_dir_map, dir->ino))
check_directory(ctx, dir, &pctx);
@@ -256,17 +256,19 @@
ext2_filsys fs = ctx->fs;
struct dir_info *p = dir;
+ if (!p)
+ return;
+
ext2fs_clear_inode_bitmap(inode_loop_detect);
- while (p) {
- /*
- * If we find a parent which we've already checked,
- * then stop; we know it's either already connected to
- * the directory tree, or it isn't but the user has
- * already told us he doesn't want us to reconnect the
- * disconnected subtree.
- */
- if (ext2fs_test_inode_bitmap(inode_done_map, p->ino))
- goto check_dot_dot;
+
+ /*
+ * Keep going until we find a parent which we've already
+ * checked. We know it's either already connected to the
+ * directory tree, or it isn't but the user has already told
+ * us he doesn't want us to reconnect the disconnected
+ * subtree.
+ */
+ while (!ext2fs_test_inode_bitmap(inode_done_map, p->ino)) {
/*
* Mark this inode as being "done"; by the time we
* return from this function, the inode we either be
@@ -275,6 +277,7 @@
* lost+found.
*/
ext2fs_mark_inode_bitmap(inode_done_map, p->ino);
+
/*
* If this directory doesn't have a parent, or we've
* seen the parent once already, then offer to
@@ -282,23 +285,25 @@
*/
if (!p->parent ||
(ext2fs_test_inode_bitmap(inode_loop_detect,
- p->parent)))
+ p->parent))) {
+ pctx->ino = p->ino;
+ if (fix_problem(ctx, PR_3_UNCONNECTED_DIR, pctx)) {
+ if (e2fsck_reconnect_file(ctx, p->ino))
+ ext2fs_unmark_valid(fs);
+ else {
+ p->parent = lost_and_found;
+ fix_dotdot(ctx, p, lost_and_found);
+ }
+ }
break;
+ }
ext2fs_mark_inode_bitmap(inode_loop_detect,
p->parent);
+ pctx->ino = p->parent;
p = e2fsck_get_dir_info(ctx, p->parent);
- }
- /*
- * If we've reached here, we've hit a detached directory
- * inode; offer to reconnect it to lost+found.
- */
- pctx->ino = p->ino;
- if (fix_problem(ctx, PR_3_UNCONNECTED_DIR, pctx)) {
- if (e2fsck_reconnect_file(ctx, p->ino))
- ext2fs_unmark_valid(fs);
- else {
- p->parent = lost_and_found;
- fix_dotdot(ctx, p, lost_and_found);
+ if (!p) {
+ fix_problem(ctx, PR_3_NO_DIRINFO, pctx);
+ return;
}
}
@@ -306,7 +311,6 @@
* Make sure that .. and the parent directory are the same;
* offer to fix it if not.
*/
-check_dot_dot:
if (dir->parent != dir->dotdot) {
pctx->ino = dir->ino;
pctx->ino2 = dir->dotdot;
diff --git a/e2fsck/pass4.c b/e2fsck/pass4.c
index f65785a..adde764 100644
--- a/e2fsck/pass4.c
+++ b/e2fsck/pass4.c
@@ -85,7 +85,7 @@
#endif
struct problem_context pctx;
__u16 link_count, link_counted;
- int group, max;
+ int group, maxgroup;
#ifdef RESOURCE_TRACK
init_resource_track(&rtrack);
@@ -101,16 +101,16 @@
fix_problem(ctx, PR_4_PASS_HEADER, &pctx);
group = 0;
- max = fs->group_desc_count;
+ maxgroup = fs->group_desc_count;
if (ctx->progress)
- if ((ctx->progress)(ctx, 4, 0, max))
+ if ((ctx->progress)(ctx, 4, 0, maxgroup))
return;
for (i=1; i <= fs->super->s_inodes_count; i++) {
if ((i % fs->super->s_inodes_per_group) == 0) {
group++;
if (ctx->progress)
- if ((ctx->progress)(ctx, 4, group, max))
+ if ((ctx->progress)(ctx, 4, group, maxgroup))
return;
}
if (i == EXT2_BAD_INO ||
diff --git a/e2fsck/problem.c b/e2fsck/problem.c
index f996b9b..d6f6774 100644
--- a/e2fsck/problem.c
+++ b/e2fsck/problem.c
@@ -787,6 +787,11 @@
"Cannot proceed without a @r.\n",
PROMPT_NONE, PR_FATAL },
+ /* Internal error: couldn't find dir_info */
+ { PR_3_NO_DIRINFO,
+ "Internal error: couldn't find dir_info for %i.\n",
+ PROMPT_NONE, PR_FATAL },
+
/* Pass 4 errors */
/* Pass 4: Checking reference counts */
diff --git a/e2fsck/problem.h b/e2fsck/problem.h
index fdc9d2d..0f16ba6 100644
--- a/e2fsck/problem.h
+++ b/e2fsck/problem.h
@@ -472,6 +472,9 @@
/* Cannot proceed without a root inode. */
#define PR_3_NO_ROOT_INODE_ABORT 0x030015
+/* Internal error: couldn't find dir_info */
+#define PR_3_NO_DIRINFO 0x020016
+
/*
* Pass 4 errors
*/
diff --git a/e2fsck/super.c b/e2fsck/super.c
index f5dc7f2..ce33c3a 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -24,12 +24,12 @@
static void check_super_value(e2fsck_t ctx, const char *descr,
unsigned long value, int flags,
- unsigned long min, unsigned long max)
+ unsigned long min_val, unsigned long max_val)
{
struct problem_context pctx;
- if (((flags & MIN_CHECK) && (value < min)) ||
- ((flags & MAX_CHECK) && (value > max))) {
+ if (((flags & MIN_CHECK) && (value < min_val)) ||
+ ((flags & MAX_CHECK) && (value > max_val))) {
clear_problem_context(&pctx);
pctx.num = value;
pctx.str = descr;
@@ -57,7 +57,7 @@
blk_t first_block, last_block;
struct ext2fs_sb *s = (struct ext2fs_sb *) fs->super;
blk_t blocks_per_group = fs->super->s_blocks_per_group;
- int i;
+ dgrp_t i;
blk_t should_be;
struct problem_context pctx;