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