pass1b.c revision 41477
120253Sjoerg/*
220302Sjoerg * Copyright (c) 1980, 1986, 1993
320302Sjoerg *	The Regents of the University of California.  All rights reserved.
420253Sjoerg *
520253Sjoerg * Redistribution and use in source and binary forms, with or without
620253Sjoerg * modification, are permitted provided that the following conditions
720253Sjoerg * are met:
820253Sjoerg * 1. Redistributions of source code must retain the above copyright
920302Sjoerg *    notice, this list of conditions and the following disclaimer.
1020253Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1120253Sjoerg *    notice, this list of conditions and the following disclaimer in the
1220253Sjoerg *    documentation and/or other materials provided with the distribution.
1320253Sjoerg * 3. All advertising materials mentioning features or use of this software
1420302Sjoerg *    must display the following acknowledgement:
1520253Sjoerg *	This product includes software developed by the University of
1620253Sjoerg *	California, Berkeley and its contributors.
1720302Sjoerg * 4. Neither the name of the University nor the names of its contributors
1820253Sjoerg *    may be used to endorse or promote products derived from this software
1920253Sjoerg *    without specific prior written permission.
2020253Sjoerg *
2120253Sjoerg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2220253Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2320253Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2420253Sjoerg * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2520253Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2620253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2730259Scharnier * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2830259Scharnier * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2950479Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3030259Scharnier * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3130259Scharnier * SUCH DAMAGE.
3230259Scharnier */
3338112Snate
3461957Sache#ifndef lint
3521330Sdavidn#if 0
3621330Sdavidnstatic const char sccsid[] = "@(#)pass1b.c	8.4 (Berkeley) 4/28/95";
3744229Sdavidn#endif
3820253Sjoergstatic const char rcsid[] =
3956000Sdavidn	"$Id: pass1b.c,v 1.4 1998/06/15 07:07:17 charnier Exp $";
4056000Sdavidn#endif /* not lint */
4156000Sdavidn
4252512Sdavidn#include <sys/param.h>
4352512Sdavidn
4452512Sdavidn#include <ufs/ufs/dinode.h>
4520253Sjoerg#include <ufs/ffs/fs.h>
4620267Sjoerg
4720267Sjoerg#include <string.h>
4852512Sdavidn
4920267Sjoerg#include "fsck.h"
5020267Sjoerg
5120267Sjoergstatic  struct dups *duphead;
5220267Sjoergstatic int pass1bcheck __P((struct inodesc *));
5352512Sdavidn
5420267Sjoergvoid
5552512Sdavidnpass1b()
5620253Sjoerg{
5744229Sdavidn	register int c, i;
5844229Sdavidn	register struct dinode *dp;
5944229Sdavidn	struct inodesc idesc;
6044229Sdavidn	ino_t inumber;
6144229Sdavidn
6244229Sdavidn	memset(&idesc, 0, sizeof(struct inodesc));
6344229Sdavidn	idesc.id_type = ADDR;
6444229Sdavidn	idesc.id_func = pass1bcheck;
6544229Sdavidn	duphead = duplist;
6644229Sdavidn	inumber = 0;
6744229Sdavidn	for (c = 0; c < sblock.fs_ncg; c++) {
6844229Sdavidn		for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
6944229Sdavidn			if (inumber < ROOTINO)
7044229Sdavidn				continue;
7144229Sdavidn			dp = ginode(inumber);
7244229Sdavidn			if (dp == NULL)
7344229Sdavidn				continue;
7444229Sdavidn			idesc.id_number = inumber;
7544229Sdavidn			if (inoinfo(inumber)->ino_state != USTATE &&
7644229Sdavidn			    (ckinode(dp, &idesc) & STOP))
7744229Sdavidn				return;
7844229Sdavidn		}
7944229Sdavidn	}
8044229Sdavidn}
8144229Sdavidn
8244229Sdavidnstatic int
8344229Sdavidnpass1bcheck(idesc)
8444229Sdavidn	register struct inodesc *idesc;
8544229Sdavidn{
8644229Sdavidn	register struct dups *dlp;
8744229Sdavidn	int nfrags, res = KEEPON;
8844229Sdavidn	ufs_daddr_t blkno = idesc->id_blkno;
8944229Sdavidn
9044229Sdavidn	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
9120253Sjoerg		if (chkrange(blkno, 1))
9220253Sjoerg			res = SKIP;
9320253Sjoerg		for (dlp = duphead; dlp; dlp = dlp->next) {
9420253Sjoerg			if (dlp->dup == blkno) {
9520253Sjoerg				blkerror(idesc->id_number, "DUP", blkno);
9620253Sjoerg				dlp->dup = duphead->dup;
9720253Sjoerg				duphead->dup = blkno;
9820253Sjoerg				duphead = duphead->next;
9920253Sjoerg			}
10020253Sjoerg			if (dlp == muldup)
10120253Sjoerg				break;
10220253Sjoerg		}
10344229Sdavidn		if (muldup == 0 || duphead == muldup->next)
10420253Sjoerg			return (STOP);
10520253Sjoerg	}
10620253Sjoerg	return (res);
10720253Sjoerg}
10820267Sjoerg