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 * 4. Neither the name of the University nor the names of its contributors
141558Srgrimes *    may be used to endorse or promote products derived from this software
151558Srgrimes *    without specific prior written permission.
161558Srgrimes *
171558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201558Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271558Srgrimes * SUCH DAMAGE.
281558Srgrimes */
291558Srgrimes
30114589Sobrien#if 0
311558Srgrimes#ifndef lint
3223675Speterstatic const char sccsid[] = "@(#)pass1b.c	8.4 (Berkeley) 4/28/95";
33114589Sobrien#endif /* not lint */
3441477Sjulian#endif
35114589Sobrien#include <sys/cdefs.h>
36114589Sobrien__FBSDID("$FreeBSD$");
371558Srgrimes
381558Srgrimes#include <sys/param.h>
3923675Speter
401558Srgrimes#include <ufs/ufs/dinode.h>
411558Srgrimes#include <ufs/ffs/fs.h>
4223675Speter
431558Srgrimes#include <string.h>
4423675Speter
451558Srgrimes#include "fsck.h"
461558Srgrimes
471558Srgrimesstatic  struct dups *duphead;
4892839Simpstatic int pass1bcheck(struct inodesc *);
491558Srgrimes
507585Sbdevoid
5192839Simppass1b(void)
521558Srgrimes{
5392806Sobrien	int c, i;
5498542Smckusick	union dinode *dp;
551558Srgrimes	struct inodesc idesc;
561558Srgrimes	ino_t inumber;
571558Srgrimes
5823675Speter	memset(&idesc, 0, sizeof(struct inodesc));
591558Srgrimes	idesc.id_type = ADDR;
601558Srgrimes	idesc.id_func = pass1bcheck;
611558Srgrimes	duphead = duplist;
621558Srgrimes	inumber = 0;
631558Srgrimes	for (c = 0; c < sblock.fs_ncg; c++) {
6470050Siedowse		if (got_siginfo) {
6570050Siedowse			printf("%s: phase 1b: cyl group %d of %d (%d%%)\n",
6670050Siedowse			    cdevname, c, sblock.fs_ncg,
6770050Siedowse			    c * 100 / sblock.fs_ncg);
6870050Siedowse			got_siginfo = 0;
6970050Siedowse		}
70126345Sscottl		if (got_sigalarm) {
71126345Sscottl			setproctitle("%s p1b %d%%", cdevname,
72126345Sscottl			    c * 100 / sblock.fs_ncg);
73136346Simp			got_sigalarm = 0;
74126345Sscottl		}
751558Srgrimes		for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
761558Srgrimes			if (inumber < ROOTINO)
771558Srgrimes				continue;
781558Srgrimes			dp = ginode(inumber);
791558Srgrimes			if (dp == NULL)
801558Srgrimes				continue;
811558Srgrimes			idesc.id_number = inumber;
8241474Sjulian			if (inoinfo(inumber)->ino_state != USTATE &&
831558Srgrimes			    (ckinode(dp, &idesc) & STOP))
841558Srgrimes				return;
851558Srgrimes		}
861558Srgrimes	}
871558Srgrimes}
881558Srgrimes
8923675Speterstatic int
9092839Simppass1bcheck(struct inodesc *idesc)
911558Srgrimes{
9292806Sobrien	struct dups *dlp;
931558Srgrimes	int nfrags, res = KEEPON;
9498542Smckusick	ufs2_daddr_t blkno = idesc->id_blkno;
951558Srgrimes
961558Srgrimes	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
971558Srgrimes		if (chkrange(blkno, 1))
981558Srgrimes			res = SKIP;
991558Srgrimes		for (dlp = duphead; dlp; dlp = dlp->next) {
1001558Srgrimes			if (dlp->dup == blkno) {
1011558Srgrimes				blkerror(idesc->id_number, "DUP", blkno);
1021558Srgrimes				dlp->dup = duphead->dup;
1031558Srgrimes				duphead->dup = blkno;
1041558Srgrimes				duphead = duphead->next;
1051558Srgrimes			}
1061558Srgrimes			if (dlp == muldup)
1071558Srgrimes				break;
1081558Srgrimes		}
1091558Srgrimes		if (muldup == 0 || duphead == muldup->next)
1101558Srgrimes			return (STOP);
1111558Srgrimes	}
1121558Srgrimes	return (res);
1131558Srgrimes}
114