From e931c1212d7bb5ceaf946ef535851f0770284c1c Mon Sep 17 00:00:00 2001 From: tholo Date: Thu, 20 Feb 1997 06:03:04 +0000 Subject: [PATCH] From FreeBSD [Terry Lambert]: The following small diff fixes the annoying fsck bug that causes it to need to be run twice to end up with correct reference counts for inodes for directories that had subdirectories relocated into the lost+found directory. I found the need to rerun *extremely* annoying. This fix causes the count to be correctly adjusted later in pass 4 by correctly stating the parent reference count. Note that the parent reference count is incremented when the directory entry is made (for ".."), but is not really there in the case of a directory that does not make an entry in its parent dir. This can be tested by waiting for the inode sync after cd'ing from a shell into a test fs. Then you "mkdir xxx yyy zzz", wait a second, and hit the machine reset button. --- sbin/fsck_ffs/dir.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index 6bd11ba8e24..9b79c368fe5 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dir.c,v 1.3 1996/10/20 08:36:30 tholo Exp $ */ +/* $OpenBSD: dir.c,v 1.4 1997/02/20 06:03:04 tholo Exp $ */ /* $NetBSD: dir.c,v 1.20 1996/09/27 22:45:11 christos Exp $ */ /* @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)dir.c 8.5 (Berkeley) 12/8/94"; #else -static char rcsid[] = "$OpenBSD: dir.c,v 1.3 1996/10/20 08:36:30 tholo Exp $"; +static char rcsid[] = "$OpenBSD: dir.c,v 1.4 1997/02/20 06:03:04 tholo Exp $"; #endif #endif /* not lint */ @@ -504,8 +504,17 @@ linkup(orphan, parentdir) inodirty(); lncntp[lfdir]++; pwarn("DIR I=%u CONNECTED. ", orphan); - if (parentdir != (ino_t)-1) + if (parentdir != (ino_t)-1) { printf("PARENT WAS I=%u\n", parentdir); + /* + * The parent directory, because of the ordering + * guarantees, has had the link count incremented + * for the child, but no entry was made. This + * fixes the parent link count so that fsck does + * not need to be rerun. + */ + lncntp[parentdir]++; + } if (preen == 0) printf("\n"); } -- 2.20.1