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 &&
83260178Sscottl			    (ckinode(dp, &idesc) & STOP)) {
84260178Sscottl				rerun = 1;
851558Srgrimes				return;
86260178Sscottl			}
871558Srgrimes		}
881558Srgrimes	}
891558Srgrimes}
901558Srgrimes
9123675Speterstatic int
9292839Simppass1bcheck(struct inodesc *idesc)
931558Srgrimes{
9492806Sobrien	struct dups *dlp;
951558Srgrimes	int nfrags, res = KEEPON;
9698542Smckusick	ufs2_daddr_t blkno = idesc->id_blkno;
971558Srgrimes
981558Srgrimes	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
991558Srgrimes		if (chkrange(blkno, 1))
1001558Srgrimes			res = SKIP;
1011558Srgrimes		for (dlp = duphead; dlp; dlp = dlp->next) {
1021558Srgrimes			if (dlp->dup == blkno) {
1031558Srgrimes				blkerror(idesc->id_number, "DUP", blkno);
1041558Srgrimes				dlp->dup = duphead->dup;
1051558Srgrimes				duphead->dup = blkno;
1061558Srgrimes				duphead = duphead->next;
1071558Srgrimes			}
1081558Srgrimes			if (dlp == muldup)
1091558Srgrimes				break;
1101558Srgrimes		}
111260178Sscottl		if (muldup == 0 || duphead == muldup->next) {
112260178Sscottl			rerun = 1;
1131558Srgrimes			return (STOP);
114260178Sscottl		}
1151558Srgrimes	}
1161558Srgrimes	return (res);
1171558Srgrimes}
118