xref: /original-bsd/sbin/fsck/pass3.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1980, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)pass3.c	8.1 (Berkeley) 06/05/93";
10 #endif /* not lint */
11 
12 #include <sys/param.h>
13 #include <sys/time.h>
14 #include <ufs/ufs/dinode.h>
15 #include <ufs/ffs/fs.h>
16 #include "fsck.h"
17 
18 pass3()
19 {
20 	register struct inoinfo **inpp, *inp;
21 	ino_t orphan;
22 	int loopcnt;
23 
24 	for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
25 		inp = *inpp;
26 		if (inp->i_number == ROOTINO ||
27 		    !(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
28 			continue;
29 		if (statemap[inp->i_number] == DCLEAR)
30 			continue;
31 		for (loopcnt = 0; ; loopcnt++) {
32 			orphan = inp->i_number;
33 			if (inp->i_parent == 0 ||
34 			    statemap[inp->i_parent] != DSTATE ||
35 			    loopcnt > numdirs)
36 				break;
37 			inp = getinoinfo(inp->i_parent);
38 		}
39 		(void)linkup(orphan, inp->i_dotdot);
40 		inp->i_parent = inp->i_dotdot = lfdir;
41 		lncntp[lfdir]--;
42 		statemap[orphan] = DFOUND;
43 		propagate();
44 	}
45 }
46