1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
8
9 /*
10 * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms are permitted
14 * provided that: (1) source distributions retain this entire copyright
15 * notice and comment, and (2) distributions including binaries display
16 * the following acknowledgement: ``This product includes software
17 * developed by the University of California, Berkeley and its contributors''
18 * in the documentation or other materials provided with the distribution
19 * and in all advertising materials mentioning features or use of this
20 * software. Neither the name of the University nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <sys/param.h>
32 #include <sys/types.h>
33 #include <sys/mntent.h>
34 #include <sys/fs/ufs_fs.h>
35 #include <sys/vnode.h>
36 #include <sys/fs/ufs_inode.h>
37 #include "fsck.h"
38
39 static int pass1bcheck(struct inodesc *);
40
41 void
pass1b(void)42 pass1b(void)
43 {
44 struct dinode *dp;
45 struct inodesc idesc;
46 fsck_ino_t inumber;
47
48 /*
49 * We can get STOP failures from ckinode() that
50 * are completely independent of our dup checks.
51 * If that were not the case, then we could track
52 * when we've seen all of the dups and short-
53 * circuit our search. As it is, we need to
54 * keep going, so there's no point in looking
55 * at what ckinode() returns to us.
56 */
57
58 for (inumber = UFSROOTINO; inumber < maxino; inumber++) {
59 init_inodesc(&idesc);
60 idesc.id_type = ADDR;
61 idesc.id_func = pass1bcheck;
62 idesc.id_number = inumber;
63 idesc.id_fix = DONTKNOW;
64 dp = ginode(inumber);
65 if (statemap[inumber] != USTATE)
66 (void) ckinode(dp, &idesc, CKI_TRAVERSE);
67 }
68 }
69
70 static int
pass1bcheck(struct inodesc * idesc)71 pass1bcheck(struct inodesc *idesc)
72 {
73 int res = KEEPON;
74 int nfrags;
75 daddr32_t lbn;
76 daddr32_t blkno = idesc->id_blkno;
77
78 for (nfrags = 0; nfrags < idesc->id_numfrags; blkno++, nfrags++) {
79 if (chkrange(blkno, 1)) {
80 res = SKIP;
81 } else {
82 /*
83 * Note that we only report additional dup claimants
84 * in this pass, as the first claimant found was
85 * listed during pass 1.
86 */
87 lbn = idesc->id_lbn * sblock.fs_frag + nfrags;
88 if (find_dup_ref(blkno, idesc->id_number, lbn, DB_INCR))
89 blkerror(idesc->id_number, "DUP", blkno, lbn);
90 }
91 }
92 return (res);
93 }
94