xref: /minix3/sbin/fsck_ext2fs/pass1b.c (revision 94715d8e544a29153969034072cc27e737b55671)
1*94715d8eSBen Gras /*	$NetBSD: pass1b.c,v 1.8 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[] = "@(#)pass1b.c	8.1 (Berkeley) 6/5/93";
60*94715d8eSBen Gras #else
61*94715d8eSBen Gras __RCSID("$NetBSD: pass1b.c,v 1.8 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 
70*94715d8eSBen Gras #include <string.h>
71*94715d8eSBen Gras #include "fsck.h"
72*94715d8eSBen Gras #include "extern.h"
73*94715d8eSBen Gras 
74*94715d8eSBen Gras static int	pass1bcheck(struct inodesc *);
75*94715d8eSBen Gras static struct	dups *duphead;
76*94715d8eSBen Gras 
77*94715d8eSBen Gras void
pass1b(void)78*94715d8eSBen Gras pass1b(void)
79*94715d8eSBen Gras {
80*94715d8eSBen Gras 	int c;
81*94715d8eSBen Gras 	uint32_t i;
82*94715d8eSBen Gras 	struct ext2fs_dinode *dp;
83*94715d8eSBen Gras 	struct inodesc idesc;
84*94715d8eSBen Gras 	ino_t inumber;
85*94715d8eSBen Gras 
86*94715d8eSBen Gras 	memset(&idesc, 0, sizeof(struct inodesc));
87*94715d8eSBen Gras 	idesc.id_type = ADDR;
88*94715d8eSBen Gras 	idesc.id_func = pass1bcheck;
89*94715d8eSBen Gras 	duphead = duplist;
90*94715d8eSBen Gras 	inumber = 0;
91*94715d8eSBen Gras 	for (c = 0; c < sblock.e2fs_ncg; c++) {
92*94715d8eSBen Gras 		for (i = 0; i < sblock.e2fs.e2fs_ipg; i++, inumber++) {
93*94715d8eSBen Gras 			if ((inumber < EXT2_FIRSTINO) && (inumber != EXT2_ROOTINO))
94*94715d8eSBen Gras 				continue;
95*94715d8eSBen Gras 			dp = ginode(inumber);
96*94715d8eSBen Gras 			if (dp == NULL)
97*94715d8eSBen Gras 				continue;
98*94715d8eSBen Gras 			idesc.id_number = inumber;
99*94715d8eSBen Gras 			if (statemap[inumber] != USTATE &&
100*94715d8eSBen Gras 			    (ckinode(dp, &idesc) & STOP))
101*94715d8eSBen Gras 				return;
102*94715d8eSBen Gras 		}
103*94715d8eSBen Gras 	}
104*94715d8eSBen Gras }
105*94715d8eSBen Gras 
106*94715d8eSBen Gras static int
pass1bcheck(struct inodesc * idesc)107*94715d8eSBen Gras pass1bcheck(struct inodesc *idesc)
108*94715d8eSBen Gras {
109*94715d8eSBen Gras 	struct dups *dlp;
110*94715d8eSBen Gras 	int nfrags, res = KEEPON;
111*94715d8eSBen Gras 	daddr_t blkno = idesc->id_blkno;
112*94715d8eSBen Gras 
113*94715d8eSBen Gras 	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
114*94715d8eSBen Gras 		if (chkrange(blkno, 1))
115*94715d8eSBen Gras 			res = SKIP;
116*94715d8eSBen Gras 		for (dlp = duphead; dlp; dlp = dlp->next) {
117*94715d8eSBen Gras 			if (dlp->dup == blkno) {
118*94715d8eSBen Gras 				blkerror(idesc->id_number, "DUP", blkno);
119*94715d8eSBen Gras 				dlp->dup = duphead->dup;
120*94715d8eSBen Gras 				duphead->dup = blkno;
121*94715d8eSBen Gras 				duphead = duphead->next;
122*94715d8eSBen Gras 			}
123*94715d8eSBen Gras 			if (dlp == muldup)
124*94715d8eSBen Gras 				break;
125*94715d8eSBen Gras 		}
126*94715d8eSBen Gras 		if (muldup == 0 || duphead == muldup->next)
127*94715d8eSBen Gras 			return (STOP);
128*94715d8eSBen Gras 	}
129*94715d8eSBen Gras 	return (res);
130*94715d8eSBen Gras }
131