xref: /openbsd-src/sbin/fsck_ext2fs/pass3.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: pass3.c,v 1.3 1997/06/14 04:16:56 downsj Exp $	*/
2 /*	$NetBSD: pass3.c,v 1.1 1997/06/11 11:21:55 bouyer Exp $	*/
3 
4 /*
5  * Copyright (c) 1997 Manuel Bouyer.
6  * Copyright (c) 1980, 1986, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37 
38 #ifndef lint
39 #if 0
40 static char sccsid[] = "@(#)pass3.c	8.1 (Berkeley) 6/5/93";
41 #else
42 #if 0
43 static char rcsid[] = "$NetBSD: pass3.c,v 1.1 1997/06/11 11:21:55 bouyer Exp $";
44 #else
45 static char rcsid[] = "$OpenBSD: pass3.c,v 1.3 1997/06/14 04:16:56 downsj Exp $";
46 #endif
47 #endif
48 #endif /* not lint */
49 
50 #include <sys/param.h>
51 #include <sys/time.h>
52 #include <ufs/ext2fs/ext2fs_dinode.h>
53 #include <ufs/ext2fs/ext2fs.h>
54 #include "fsck.h"
55 #include "extern.h"
56 
57 void
58 pass3()
59 {
60 	register struct inoinfo **inpp, *inp;
61 	ino_t orphan;
62 	int loopcnt;
63 
64 	for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--) {
65 		inp = *inpp;
66 		if (inp->i_number == EXT2_ROOTINO ||
67 		    !(inp->i_parent == 0 || statemap[inp->i_number] == DSTATE))
68 			continue;
69 		if (statemap[inp->i_number] == DCLEAR)
70 			continue;
71 		for (loopcnt = 0; ; loopcnt++) {
72 			orphan = inp->i_number;
73 			if (inp->i_parent == 0 ||
74 			    statemap[inp->i_parent] != DSTATE ||
75 			    loopcnt > numdirs)
76 				break;
77 			inp = getinoinfo(inp->i_parent);
78 		}
79 		(void)linkup(orphan, inp->i_dotdot);
80 		inp->i_parent = inp->i_dotdot = lfdir;
81 		lncntp[lfdir]--;
82 		statemap[orphan] = DFOUND;
83 		propagate();
84 	}
85 }
86