From f5a9d5eadc41dac13ba9efc1c170578a80424f31 Mon Sep 17 00:00:00 2001 From: mycroft Date: Wed, 10 Jan 2001 08:22:20 +0000 Subject: [PATCH] Abstract the code to attach a directory to its parent's child list into a separate function, and call it from multiple places in linkup() to handle reconnects and creation of /lost+found. --- sbin/fsck_ffs/dir.c | 32 ++++++++++++++++++++++++-------- sbin/fsck_ffs/pass3.c | 12 +++--------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c index 3dcc18f912b7..ce6b99e5a2bf 100644 --- a/sbin/fsck_ffs/dir.c +++ b/sbin/fsck_ffs/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.29 2001/01/09 05:51:14 mycroft Exp $ */ +/* $NetBSD: dir.c,v 1.30 2001/01/10 08:22:20 mycroft Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)dir.c 8.8 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: dir.c,v 1.29 2001/01/09 05:51:14 mycroft Exp $"); +__RCSID("$NetBSD: dir.c,v 1.30 2001/01/10 08:22:20 mycroft Exp $"); #endif #endif /* not lint */ @@ -79,6 +79,7 @@ static struct direct *fsck_readdir __P((struct inodesc *)); static struct bufarea *getdirblk __P((daddr_t, long)); static int lftempname __P((char *, ino_t)); static int mkentry __P((struct inodesc *)); +void reparent __P((ino_t, ino_t)); /* * Propagate connected state through the tree. @@ -118,6 +119,21 @@ propagate(inumber) } } +void +reparent(inumber, parent) + ino_t inumber, parent; +{ + struct inoinfo *inp, *pinp; + + inp = getinoinfo(inumber); + inp->i_parent = inp->i_dotdot = parent; + pinp = getinoinfo(parent); + inp->i_parentp = pinp; + inp->i_sibling = pinp->i_child; + pinp->i_child = inp; + propagate(lfdir); +} + /* * Scan each entry in a directory block. */ @@ -501,11 +517,11 @@ linkup(orphan, parentdir) printf("\n"); } } + reparent(lfdir, ROOTINO); } } if (lfdir == 0) { - pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY"); - printf("\n\n"); + pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); markclean = 0; return (0); } @@ -518,7 +534,8 @@ linkup(orphan, parentdir) return (0); } oldlfdir = lfdir; - if ((lfdir = allocdir(ROOTINO, (ino_t)0, lfmode)) == 0) { + lfdir = allocdir(ROOTINO, (ino_t)0, lfmode); + if (lfdir == 0) { pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n"); markclean = 0; return (0); @@ -529,6 +546,7 @@ linkup(orphan, parentdir) return (0); } inodirty(); + reparent(lfdir, ROOTINO); idesc.id_type = ADDR; idesc.id_func = pass4check; idesc.id_number = oldlfdir; @@ -557,6 +575,7 @@ linkup(orphan, parentdir) dp->di_nlink = iswap16(iswap16(dp->di_nlink) + 1); inodirty(); lncntp[lfdir]++; + reparent(orphan, lfdir); pwarn("DIR I=%u CONNECTED. ", orphan); if (parentdir != (ino_t)-1) printf("PARENT WAS I=%u\n", parentdir); @@ -690,7 +709,6 @@ allocdir(parent, request, mode) ino_t parent, request; int mode; { - struct inoinfo *inp; ino_t ino; char *cp; struct dinode *dp; @@ -735,8 +753,6 @@ allocdir(parent, request, mode) return (0); } cacheino(dp, ino); - inp = getinoinfo(ino); - inp->i_parent = inp->i_dotdot = parent; statemap[ino] = statemap[parent]; if (statemap[ino] == DSTATE) { lncntp[ino] = iswap16(dp->di_nlink); diff --git a/sbin/fsck_ffs/pass3.c b/sbin/fsck_ffs/pass3.c index 4704959aa63d..ac0675cb85f4 100644 --- a/sbin/fsck_ffs/pass3.c +++ b/sbin/fsck_ffs/pass3.c @@ -1,4 +1,4 @@ -/* $NetBSD: pass3.c,v 1.11 2001/01/09 05:51:14 mycroft Exp $ */ +/* $NetBSD: pass3.c,v 1.12 2001/01/10 08:22:20 mycroft Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)pass3.c 8.2 (Berkeley) 4/27/95"; #else -__RCSID("$NetBSD: pass3.c,v 1.11 2001/01/09 05:51:14 mycroft Exp $"); +__RCSID("$NetBSD: pass3.c,v 1.12 2001/01/10 08:22:20 mycroft Exp $"); #endif #endif /* not lint */ @@ -54,7 +54,7 @@ __RCSID("$NetBSD: pass3.c,v 1.11 2001/01/09 05:51:14 mycroft Exp $"); void pass3() { - struct inoinfo **inpp, *inp, *pinp; + struct inoinfo **inpp, *inp; ino_t orphan; int loopcnt; @@ -74,12 +74,6 @@ pass3() inp = getinoinfo(inp->i_parent); } (void)linkup(orphan, inp->i_dotdot); - inp->i_parent = inp->i_dotdot = lfdir; lncntp[lfdir]--; - pinp = getinoinfo(lfdir); - inp->i_parentp = pinp; - inp->i_sibling = pinp->i_child; - pinp->i_child = inp; - propagate(orphan); } }