pass1b.c revision 225736
1139749Simp/*
264777Snyan * Copyright (c) 1980, 1986, 1993
364777Snyan *	The Regents of the University of California.  All rights reserved.
464777Snyan *
564777Snyan * Redistribution and use in source and binary forms, with or without
664777Snyan * modification, are permitted provided that the following conditions
764777Snyan * are met:
864777Snyan * 1. Redistributions of source code must retain the above copyright
964777Snyan *    notice, this list of conditions and the following disclaimer.
1064777Snyan * 2. Redistributions in binary form must reproduce the above copyright
1164777Snyan *    notice, this list of conditions and the following disclaimer in the
1264777Snyan *    documentation and/or other materials provided with the distribution.
1364777Snyan * 4. Neither the name of the University nor the names of its contributors
1464777Snyan *    may be used to endorse or promote products derived from this software
1564777Snyan *    without specific prior written permission.
1664777Snyan *
1764777Snyan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1864777Snyan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1964777Snyan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2064777Snyan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2164777Snyan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2264777Snyan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2364777Snyan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2464777Snyan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2564777Snyan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2664777Snyan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2764777Snyan * SUCH DAMAGE.
2864777Snyan */
2964777Snyan
3064777Snyan#if 0
3164777Snyan#ifndef lint
3264777Snyanstatic const char sccsid[] = "@(#)pass1b.c	8.4 (Berkeley) 4/28/95";
3364777Snyan#endif /* not lint */
3464777Snyan#endif
3564777Snyan#include <sys/cdefs.h>
3664777Snyan__FBSDID("$FreeBSD: stable/9/sbin/fsck_ffs/pass1b.c 136346 2004-10-10 06:37:56Z imp $");
3764777Snyan
3864777Snyan#include <sys/param.h>
3964777Snyan
4064777Snyan#include <ufs/ufs/dinode.h>
4164777Snyan#include <ufs/ffs/fs.h>
4264777Snyan
4364777Snyan#include <string.h>
4464777Snyan
4564777Snyan#include "fsck.h"
4664777Snyan
4764777Snyanstatic  struct dups *duphead;
4864777Snyanstatic int pass1bcheck(struct inodesc *);
4964777Snyan
5064777Snyanvoid
5164777Snyanpass1b(void)
5264777Snyan{
5364777Snyan	int c, i;
54141550Simp	union dinode *dp;
55141550Simp	struct inodesc idesc;
56141550Simp	ino_t inumber;
57141550Simp
58141550Simp	memset(&idesc, 0, sizeof(struct inodesc));
59141550Simp	idesc.id_type = ADDR;
60141550Simp	idesc.id_func = pass1bcheck;
61141550Simp	duphead = duplist;
62141550Simp	inumber = 0;
63141550Simp	for (c = 0; c < sblock.fs_ncg; c++) {
64141550Simp		if (got_siginfo) {
65141550Simp			printf("%s: phase 1b: cyl group %d of %d (%d%%)\n",
66141550Simp			    cdevname, c, sblock.fs_ncg,
67141550Simp			    c * 100 / sblock.fs_ncg);
68141550Simp			got_siginfo = 0;
6964777Snyan		}
70141550Simp		if (got_sigalarm) {
71141550Simp			setproctitle("%s p1b %d%%", cdevname,
7264777Snyan			    c * 100 / sblock.fs_ncg);
7364777Snyan			got_sigalarm = 0;
7464777Snyan		}
7564777Snyan		for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
7664777Snyan			if (inumber < ROOTINO)
7764777Snyan				continue;
7864777Snyan			dp = ginode(inumber);
79141550Simp			if (dp == NULL)
8064777Snyan				continue;
8164777Snyan			idesc.id_number = inumber;
8264777Snyan			if (inoinfo(inumber)->ino_state != USTATE &&
8364777Snyan			    (ckinode(dp, &idesc) & STOP))
8464777Snyan				return;
8564777Snyan		}
8664777Snyan	}
87141550Simp}
8864777Snyan
8964777Snyanstatic int
9064777Snyanpass1bcheck(struct inodesc *idesc)
9164777Snyan{
9264777Snyan	struct dups *dlp;
93141550Simp	int nfrags, res = KEEPON;
9464777Snyan	ufs2_daddr_t blkno = idesc->id_blkno;
9564777Snyan
9664777Snyan	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
9764777Snyan		if (chkrange(blkno, 1))
9864777Snyan			res = SKIP;
9964777Snyan		for (dlp = duphead; dlp; dlp = dlp->next) {
10064777Snyan			if (dlp->dup == blkno) {
10164777Snyan				blkerror(idesc->id_number, "DUP", blkno);
10264777Snyan				dlp->dup = duphead->dup;
10364777Snyan				duphead->dup = blkno;
10464777Snyan				duphead = duphead->next;
10564777Snyan			}
10664777Snyan			if (dlp == muldup)
10764777Snyan				break;
108141550Simp		}
10964777Snyan		if (muldup == 0 || duphead == muldup->next)
11064777Snyan			return (STOP);
11164777Snyan	}
11264777Snyan	return (res);
11364777Snyan}
11464777Snyan