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 287c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 297c478bd9Sstevel@tonic-gate 30*355d6bb5Sswilcox #include <stdio.h> 31*355d6bb5Sswilcox #include <stdlib.h> 32*355d6bb5Sswilcox #include <unistd.h> 337c478bd9Sstevel@tonic-gate #include <sys/param.h> 347c478bd9Sstevel@tonic-gate #include <sys/types.h> 357c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 367c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h> 377c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 387c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h> 397c478bd9Sstevel@tonic-gate #include "fsck.h" 407c478bd9Sstevel@tonic-gate 41*355d6bb5Sswilcox static int pass1bcheck(struct inodesc *); 427c478bd9Sstevel@tonic-gate 43*355d6bb5Sswilcox void 44*355d6bb5Sswilcox pass1b(void) 457c478bd9Sstevel@tonic-gate { 467c478bd9Sstevel@tonic-gate struct dinode *dp; 477c478bd9Sstevel@tonic-gate struct inodesc idesc; 48*355d6bb5Sswilcox fsck_ino_t inumber; 497c478bd9Sstevel@tonic-gate 50*355d6bb5Sswilcox /* 51*355d6bb5Sswilcox * We can get STOP failures from ckinode() that 52*355d6bb5Sswilcox * are completely independent of our dup checks. 53*355d6bb5Sswilcox * If that were not the case, then we could track 54*355d6bb5Sswilcox * when we've seen all of the dups and short- 55*355d6bb5Sswilcox * circuit our search. As it is, we need to 56*355d6bb5Sswilcox * keep going, so there's no point in looking 57*355d6bb5Sswilcox * at what ckinode() returns to us. 58*355d6bb5Sswilcox */ 59*355d6bb5Sswilcox 60*355d6bb5Sswilcox for (inumber = UFSROOTINO; inumber < maxino; inumber++) { 61*355d6bb5Sswilcox init_inodesc(&idesc); 627c478bd9Sstevel@tonic-gate idesc.id_type = ADDR; 637c478bd9Sstevel@tonic-gate idesc.id_func = pass1bcheck; 647c478bd9Sstevel@tonic-gate idesc.id_number = inumber; 657c478bd9Sstevel@tonic-gate idesc.id_fix = DONTKNOW; 66*355d6bb5Sswilcox dp = ginode(inumber); 67*355d6bb5Sswilcox if (statemap[inumber] != USTATE) 68*355d6bb5Sswilcox (void) ckinode(dp, &idesc, CKI_TRAVERSE); 697c478bd9Sstevel@tonic-gate } 707c478bd9Sstevel@tonic-gate } 717c478bd9Sstevel@tonic-gate 72*355d6bb5Sswilcox static int 73*355d6bb5Sswilcox pass1bcheck(struct inodesc *idesc) 747c478bd9Sstevel@tonic-gate { 757c478bd9Sstevel@tonic-gate int res = KEEPON; 767c478bd9Sstevel@tonic-gate int nfrags; 77*355d6bb5Sswilcox daddr32_t lbn; 787c478bd9Sstevel@tonic-gate daddr32_t blkno = idesc->id_blkno; 797c478bd9Sstevel@tonic-gate 80*355d6bb5Sswilcox for (nfrags = 0; nfrags < idesc->id_numfrags; blkno++, nfrags++) { 81*355d6bb5Sswilcox if (chkrange(blkno, 1)) { 827c478bd9Sstevel@tonic-gate res = SKIP; 83*355d6bb5Sswilcox } else { 84*355d6bb5Sswilcox /* 85*355d6bb5Sswilcox * Note that we only report additional dup claimants 86*355d6bb5Sswilcox * in this pass, as the first claimant found was 87*355d6bb5Sswilcox * listed during pass 1. 88*355d6bb5Sswilcox */ 89*355d6bb5Sswilcox lbn = idesc->id_lbn * sblock.fs_frag + nfrags; 90*355d6bb5Sswilcox if (find_dup_ref(blkno, idesc->id_number, lbn, DB_INCR)) 91*355d6bb5Sswilcox blkerror(idesc->id_number, "DUP", blkno, lbn); 927c478bd9Sstevel@tonic-gate } 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate return (res); 957c478bd9Sstevel@tonic-gate } 96