pass1b.c revision 92839
11558Srgrimes/* 21558Srgrimes * Copyright (c) 1980, 1986, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * Redistribution and use in source and binary forms, with or without 61558Srgrimes * modification, are permitted provided that the following conditions 71558Srgrimes * are met: 81558Srgrimes * 1. Redistributions of source code must retain the above copyright 91558Srgrimes * notice, this list of conditions and the following disclaimer. 101558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111558Srgrimes * notice, this list of conditions and the following disclaimer in the 121558Srgrimes * documentation and/or other materials provided with the distribution. 131558Srgrimes * 3. All advertising materials mentioning features or use of this software 141558Srgrimes * must display the following acknowledgement: 151558Srgrimes * This product includes software developed by the University of 161558Srgrimes * California, Berkeley and its contributors. 171558Srgrimes * 4. Neither the name of the University nor the names of its contributors 181558Srgrimes * may be used to endorse or promote products derived from this software 191558Srgrimes * without specific prior written permission. 201558Srgrimes * 211558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311558Srgrimes * SUCH DAMAGE. 321558Srgrimes */ 331558Srgrimes 341558Srgrimes#ifndef lint 3541477Sjulian#if 0 3623675Speterstatic const char sccsid[] = "@(#)pass1b.c 8.4 (Berkeley) 4/28/95"; 3741477Sjulian#endif 3841477Sjulianstatic const char rcsid[] = 3950476Speter "$FreeBSD: head/sbin/fsck_ffs/pass1b.c 92839 2002-03-20 22:57:10Z imp $"; 401558Srgrimes#endif /* not lint */ 411558Srgrimes 421558Srgrimes#include <sys/param.h> 4323675Speter 441558Srgrimes#include <ufs/ufs/dinode.h> 451558Srgrimes#include <ufs/ffs/fs.h> 4623675Speter 471558Srgrimes#include <string.h> 4823675Speter 491558Srgrimes#include "fsck.h" 501558Srgrimes 511558Srgrimesstatic struct dups *duphead; 5292839Simpstatic int pass1bcheck(struct inodesc *); 531558Srgrimes 547585Sbdevoid 5592839Simppass1b(void) 561558Srgrimes{ 5792806Sobrien int c, i; 5892806Sobrien struct dinode *dp; 591558Srgrimes struct inodesc idesc; 601558Srgrimes ino_t inumber; 611558Srgrimes 6223675Speter memset(&idesc, 0, sizeof(struct inodesc)); 631558Srgrimes idesc.id_type = ADDR; 641558Srgrimes idesc.id_func = pass1bcheck; 651558Srgrimes duphead = duplist; 661558Srgrimes inumber = 0; 671558Srgrimes for (c = 0; c < sblock.fs_ncg; c++) { 6870050Siedowse if (got_siginfo) { 6970050Siedowse printf("%s: phase 1b: cyl group %d of %d (%d%%)\n", 7070050Siedowse cdevname, c, sblock.fs_ncg, 7170050Siedowse c * 100 / sblock.fs_ncg); 7270050Siedowse got_siginfo = 0; 7370050Siedowse } 741558Srgrimes for (i = 0; i < sblock.fs_ipg; i++, inumber++) { 751558Srgrimes if (inumber < ROOTINO) 761558Srgrimes continue; 771558Srgrimes dp = ginode(inumber); 781558Srgrimes if (dp == NULL) 791558Srgrimes continue; 801558Srgrimes idesc.id_number = inumber; 8141474Sjulian if (inoinfo(inumber)->ino_state != USTATE && 821558Srgrimes (ckinode(dp, &idesc) & STOP)) 831558Srgrimes return; 841558Srgrimes } 851558Srgrimes } 861558Srgrimes} 871558Srgrimes 8823675Speterstatic int 8992839Simppass1bcheck(struct inodesc *idesc) 901558Srgrimes{ 9192806Sobrien struct dups *dlp; 921558Srgrimes int nfrags, res = KEEPON; 9323675Speter ufs_daddr_t blkno = idesc->id_blkno; 941558Srgrimes 951558Srgrimes for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) { 961558Srgrimes if (chkrange(blkno, 1)) 971558Srgrimes res = SKIP; 981558Srgrimes for (dlp = duphead; dlp; dlp = dlp->next) { 991558Srgrimes if (dlp->dup == blkno) { 1001558Srgrimes blkerror(idesc->id_number, "DUP", blkno); 1011558Srgrimes dlp->dup = duphead->dup; 1021558Srgrimes duphead->dup = blkno; 1031558Srgrimes duphead = duphead->next; 1041558Srgrimes } 1051558Srgrimes if (dlp == muldup) 1061558Srgrimes break; 1071558Srgrimes } 1081558Srgrimes if (muldup == 0 || duphead == muldup->next) 1091558Srgrimes return (STOP); 1101558Srgrimes } 1111558Srgrimes return (res); 1121558Srgrimes} 113