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