xref: /titanic_41/usr/src/cmd/fs.d/ufs/fsck/pass1b.c (revision 8475e04352e630e4bd0f59a283286ee2475a14ce)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/mntent.h>
36 #include <sys/fs/ufs_fs.h>
37 #include <sys/vnode.h>
38 #include <sys/fs/ufs_inode.h>
39 #include "fsck.h"
40 
41 static int pass1bcheck(struct inodesc *);
42 
43 void
44 pass1b(void)
45 {
46 	struct dinode *dp;
47 	struct inodesc idesc;
48 	fsck_ino_t inumber;
49 
50 	/*
51 	 * We can get STOP failures from ckinode() that
52 	 * are completely independent of our dup checks.
53 	 * If that were not the case, then we could track
54 	 * when we've seen all of the dups and short-
55 	 * circuit our search.  As it is, we need to
56 	 * keep going, so there's no point in looking
57 	 * at what ckinode() returns to us.
58 	 */
59 
60 	for (inumber = UFSROOTINO; inumber < maxino; inumber++) {
61 		init_inodesc(&idesc);
62 		idesc.id_type = ADDR;
63 		idesc.id_func = pass1bcheck;
64 		idesc.id_number = inumber;
65 		idesc.id_fix = DONTKNOW;
66 		dp = ginode(inumber);
67 		if (statemap[inumber] != USTATE)
68 			(void) ckinode(dp, &idesc, CKI_TRAVERSE);
69 	}
70 }
71 
72 static int
73 pass1bcheck(struct inodesc *idesc)
74 {
75 	int res = KEEPON;
76 	int nfrags;
77 	daddr32_t lbn;
78 	daddr32_t blkno = idesc->id_blkno;
79 
80 	for (nfrags = 0; nfrags < idesc->id_numfrags; blkno++, nfrags++) {
81 		if (chkrange(blkno, 1)) {
82 			res = SKIP;
83 		} else {
84 			/*
85 			 * Note that we only report additional dup claimants
86 			 * in this pass, as the first claimant found was
87 			 * listed during pass 1.
88 			 */
89 			lbn = idesc->id_lbn * sblock.fs_frag + nfrags;
90 			if (find_dup_ref(blkno, idesc->id_number, lbn, DB_INCR))
91 				blkerror(idesc->id_number, "DUP", blkno, lbn);
92 		}
93 	}
94 	return (res);
95 }
96