xref: /illumos-gate/usr/src/cmd/fs.d/ufs/fsck/pass1b.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
2*355d6bb5Sswilcox  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
147c478bd9Sstevel@tonic-gate  * provided that: (1) source distributions retain this entire copyright
157c478bd9Sstevel@tonic-gate  * notice and comment, and (2) distributions including binaries display
167c478bd9Sstevel@tonic-gate  * the following acknowledgement:  ``This product includes software
177c478bd9Sstevel@tonic-gate  * developed by the University of California, Berkeley and its contributors''
187c478bd9Sstevel@tonic-gate  * in the documentation or other materials provided with the distribution
197c478bd9Sstevel@tonic-gate  * and in all advertising materials mentioning features or use of this
207c478bd9Sstevel@tonic-gate  * software. Neither the name of the University nor the names of its
217c478bd9Sstevel@tonic-gate  * contributors may be used to endorse or promote products derived
227c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
237c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
247c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
257c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
28*355d6bb5Sswilcox #include <stdio.h>
29*355d6bb5Sswilcox #include <stdlib.h>
30*355d6bb5Sswilcox #include <unistd.h>
317c478bd9Sstevel@tonic-gate #include <sys/param.h>
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
347c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
357c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
367c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
377c478bd9Sstevel@tonic-gate #include "fsck.h"
387c478bd9Sstevel@tonic-gate 
39*355d6bb5Sswilcox static int pass1bcheck(struct inodesc *);
407c478bd9Sstevel@tonic-gate 
41*355d6bb5Sswilcox void
pass1b(void)42*355d6bb5Sswilcox pass1b(void)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate 	struct dinode *dp;
457c478bd9Sstevel@tonic-gate 	struct inodesc idesc;
46*355d6bb5Sswilcox 	fsck_ino_t inumber;
477c478bd9Sstevel@tonic-gate 
48*355d6bb5Sswilcox 	/*
49*355d6bb5Sswilcox 	 * We can get STOP failures from ckinode() that
50*355d6bb5Sswilcox 	 * are completely independent of our dup checks.
51*355d6bb5Sswilcox 	 * If that were not the case, then we could track
52*355d6bb5Sswilcox 	 * when we've seen all of the dups and short-
53*355d6bb5Sswilcox 	 * circuit our search.  As it is, we need to
54*355d6bb5Sswilcox 	 * keep going, so there's no point in looking
55*355d6bb5Sswilcox 	 * at what ckinode() returns to us.
56*355d6bb5Sswilcox 	 */
57*355d6bb5Sswilcox 
58*355d6bb5Sswilcox 	for (inumber = UFSROOTINO; inumber < maxino; inumber++) {
59*355d6bb5Sswilcox 		init_inodesc(&idesc);
60*355d6bb5Sswilcox 		idesc.id_type = ADDR;
61*355d6bb5Sswilcox 		idesc.id_func = pass1bcheck;
62*355d6bb5Sswilcox 		idesc.id_number = inumber;
63*355d6bb5Sswilcox 		idesc.id_fix = DONTKNOW;
64*355d6bb5Sswilcox 		dp = ginode(inumber);
65*355d6bb5Sswilcox 		if (statemap[inumber] != USTATE)
66*355d6bb5Sswilcox 			(void) ckinode(dp, &idesc, CKI_TRAVERSE);
677c478bd9Sstevel@tonic-gate 	}
687c478bd9Sstevel@tonic-gate }
697c478bd9Sstevel@tonic-gate 
70*355d6bb5Sswilcox static int
pass1bcheck(struct inodesc * idesc)71*355d6bb5Sswilcox pass1bcheck(struct inodesc *idesc)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate 	int res = KEEPON;
74*355d6bb5Sswilcox 	int nfrags;
75*355d6bb5Sswilcox 	daddr32_t lbn;
767c478bd9Sstevel@tonic-gate 	daddr32_t blkno = idesc->id_blkno;
777c478bd9Sstevel@tonic-gate 
78*355d6bb5Sswilcox 	for (nfrags = 0; nfrags < idesc->id_numfrags; blkno++, nfrags++) {
79*355d6bb5Sswilcox 		if (chkrange(blkno, 1)) {
807c478bd9Sstevel@tonic-gate 			res = SKIP;
81*355d6bb5Sswilcox 		} else {
82*355d6bb5Sswilcox 			/*
83*355d6bb5Sswilcox 			 * Note that we only report additional dup claimants
84*355d6bb5Sswilcox 			 * in this pass, as the first claimant found was
85*355d6bb5Sswilcox 			 * listed during pass 1.
86*355d6bb5Sswilcox 			 */
87*355d6bb5Sswilcox 			lbn = idesc->id_lbn * sblock.fs_frag + nfrags;
88*355d6bb5Sswilcox 			if (find_dup_ref(blkno, idesc->id_number, lbn, DB_INCR))
89*355d6bb5Sswilcox 				blkerror(idesc->id_number, "DUP", blkno, lbn);
907c478bd9Sstevel@tonic-gate 		}
917c478bd9Sstevel@tonic-gate 	}
927c478bd9Sstevel@tonic-gate 	return (res);
937c478bd9Sstevel@tonic-gate }
94