xref: /original-bsd/sbin/fsck/pass1b.c (revision b7261a4b)
1 /*
2  * Copyright (c) 1980, 1986 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)pass1b.c	5.7 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 #include <sys/param.h>
13 #include <ufs/dinode.h>
14 #include <ufs/fs.h>
15 #include "fsck.h"
16 
17 int	pass1bcheck();
18 static  struct dups *duphead;
19 
20 pass1b()
21 {
22 	register int c, i;
23 	register struct dinode *dp;
24 	struct inodesc idesc;
25 	ino_t inumber;
26 
27 	bzero((char *)&idesc, sizeof(struct inodesc));
28 	idesc.id_type = ADDR;
29 	idesc.id_func = pass1bcheck;
30 	duphead = duplist;
31 	inumber = 0;
32 	for (c = 0; c < sblock.fs_ncg; c++) {
33 		for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
34 			if (inumber < ROOTINO)
35 				continue;
36 			dp = ginode(inumber);
37 			if (dp == NULL)
38 				continue;
39 			idesc.id_number = inumber;
40 			if (statemap[inumber] != USTATE &&
41 			    (ckinode(dp, &idesc) & STOP))
42 				return;
43 		}
44 	}
45 }
46 
47 pass1bcheck(idesc)
48 	register struct inodesc *idesc;
49 {
50 	register struct dups *dlp;
51 	int nfrags, res = KEEPON;
52 	daddr_t blkno = idesc->id_blkno;
53 
54 	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
55 		if (chkrange(blkno, 1))
56 			res = SKIP;
57 		for (dlp = duphead; dlp; dlp = dlp->next) {
58 			if (dlp->dup == blkno) {
59 				blkerror(idesc->id_number, "DUP", blkno);
60 				dlp->dup = duphead->dup;
61 				duphead->dup = blkno;
62 				duphead = duphead->next;
63 			}
64 			if (dlp == muldup)
65 				break;
66 		}
67 		if (muldup == 0 || duphead == muldup->next)
68 			return (STOP);
69 	}
70 	return (res);
71 }
72