xref: /openbsd-src/sbin/fsck_ext2fs/pass1b.c (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: pass1b.c,v 1.3 1997/06/14 04:16:55 downsj Exp $	*/
2 /*	$NetBSD: pass1b.c,v 1.1 1997/06/11 11:21:53 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[] = "@(#)pass1b.c	8.1 (Berkeley) 6/5/93";
41 #else
42 #if 0
43 static char rcsid[] = "$NetBSD: pass1b.c,v 1.1 1997/06/11 11:21:53 bouyer Exp $";
44 #else
45 static char rcsid[] = "$OpenBSD: pass1b.c,v 1.3 1997/06/14 04:16:55 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 
55 #include <string.h>
56 #include "fsck.h"
57 #include "extern.h"
58 
59 static int	pass1bcheck __P((struct inodesc *));
60 static  struct dups *duphead;
61 
62 void
63 pass1b()
64 {
65 	register int c, i;
66 	register struct ext2fs_dinode *dp;
67 	struct inodesc idesc;
68 	ino_t inumber;
69 
70 	memset(&idesc, 0, sizeof(struct inodesc));
71 	idesc.id_type = ADDR;
72 	idesc.id_func = pass1bcheck;
73 	duphead = duplist;
74 	inumber = 0;
75 	for (c = 0; c < sblock.e2fs_ncg; c++) {
76 		for (i = 0; i < sblock.e2fs.e2fs_ipg; i++, inumber++) {
77 			if ((inumber < EXT2_FIRSTINO) && (inumber != EXT2_ROOTINO))
78 				continue;
79 			dp = ginode(inumber);
80 			if (dp == NULL)
81 				continue;
82 			idesc.id_number = inumber;
83 			if (statemap[inumber] != USTATE &&
84 			    (ckinode(dp, &idesc) & STOP))
85 				return;
86 		}
87 	}
88 }
89 
90 static int
91 pass1bcheck(idesc)
92 	register struct inodesc *idesc;
93 {
94 	register struct dups *dlp;
95 	int nfrags, res = KEEPON;
96 	daddr_t blkno = idesc->id_blkno;
97 
98 	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
99 		if (chkrange(blkno, 1))
100 			res = SKIP;
101 		for (dlp = duphead; dlp; dlp = dlp->next) {
102 			if (dlp->dup == blkno) {
103 				blkerror(idesc->id_number, "DUP", blkno);
104 				dlp->dup = duphead->dup;
105 				duphead->dup = blkno;
106 				duphead = duphead->next;
107 			}
108 			if (dlp == muldup)
109 				break;
110 		}
111 		if (muldup == 0 || duphead == muldup->next)
112 			return (STOP);
113 	}
114 	return (res);
115 }
116