xref: /minix3/sbin/fsck_ext2fs/pass1.c (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc /*	$NetBSD: pass1.c,v 1.24 2013/06/19 17:51:25 dholland Exp $	*/
294715d8eSBen Gras 
394715d8eSBen Gras /*
494715d8eSBen Gras  * Copyright (c) 1980, 1986, 1993
594715d8eSBen Gras  *	The Regents of the University of California.  All rights reserved.
694715d8eSBen Gras  *
794715d8eSBen Gras  * Redistribution and use in source and binary forms, with or without
894715d8eSBen Gras  * modification, are permitted provided that the following conditions
994715d8eSBen Gras  * are met:
1094715d8eSBen Gras  * 1. Redistributions of source code must retain the above copyright
1194715d8eSBen Gras  *    notice, this list of conditions and the following disclaimer.
1294715d8eSBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
1394715d8eSBen Gras  *    notice, this list of conditions and the following disclaimer in the
1494715d8eSBen Gras  *    documentation and/or other materials provided with the distribution.
1594715d8eSBen Gras  * 3. Neither the name of the University nor the names of its contributors
1694715d8eSBen Gras  *    may be used to endorse or promote products derived from this software
1794715d8eSBen Gras  *    without specific prior written permission.
1894715d8eSBen Gras  *
1994715d8eSBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2094715d8eSBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2194715d8eSBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2294715d8eSBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2394715d8eSBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2494715d8eSBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2594715d8eSBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2694715d8eSBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2794715d8eSBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2894715d8eSBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2994715d8eSBen Gras  * SUCH DAMAGE.
3094715d8eSBen Gras  */
3194715d8eSBen Gras 
3294715d8eSBen Gras /*
3394715d8eSBen Gras  * Copyright (c) 1997 Manuel Bouyer.
3494715d8eSBen Gras  *
3594715d8eSBen Gras  * Redistribution and use in source and binary forms, with or without
3694715d8eSBen Gras  * modification, are permitted provided that the following conditions
3794715d8eSBen Gras  * are met:
3894715d8eSBen Gras  * 1. Redistributions of source code must retain the above copyright
3994715d8eSBen Gras  *    notice, this list of conditions and the following disclaimer.
4094715d8eSBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
4194715d8eSBen Gras  *    notice, this list of conditions and the following disclaimer in the
4294715d8eSBen Gras  *    documentation and/or other materials provided with the distribution.
4394715d8eSBen Gras  *
4494715d8eSBen Gras  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
4594715d8eSBen Gras  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
4694715d8eSBen Gras  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
4794715d8eSBen Gras  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
4894715d8eSBen Gras  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4994715d8eSBen Gras  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5094715d8eSBen Gras  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5194715d8eSBen Gras  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5294715d8eSBen Gras  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
5394715d8eSBen Gras  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5494715d8eSBen Gras  */
5594715d8eSBen Gras 
5694715d8eSBen Gras #include <sys/cdefs.h>
5794715d8eSBen Gras #ifndef lint
5894715d8eSBen Gras #if 0
5994715d8eSBen Gras static char sccsid[] = "@(#)pass1.c	8.1 (Berkeley) 6/5/93";
6094715d8eSBen Gras #else
61*84d9c625SLionel Sambuc __RCSID("$NetBSD: pass1.c,v 1.24 2013/06/19 17:51:25 dholland Exp $");
6294715d8eSBen Gras #endif
6394715d8eSBen Gras #endif /* not lint */
6494715d8eSBen Gras 
6594715d8eSBen Gras #include <sys/param.h>
6694715d8eSBen Gras #include <sys/time.h>
6794715d8eSBen Gras #include <ufs/ext2fs/ext2fs_dinode.h>
6894715d8eSBen Gras #include <ufs/ext2fs/ext2fs_dir.h>
6994715d8eSBen Gras #include <ufs/ext2fs/ext2fs.h>
7094715d8eSBen Gras 
7194715d8eSBen Gras #include <ufs/ufs/dinode.h> /* for IFMT & friends */
7294715d8eSBen Gras 
7394715d8eSBen Gras #include <stdio.h>
7494715d8eSBen Gras #include <stdlib.h>
7594715d8eSBen Gras #include <string.h>
7694715d8eSBen Gras #include <time.h>
7794715d8eSBen Gras 
7894715d8eSBen Gras #include "fsck.h"
7994715d8eSBen Gras #include "extern.h"
8094715d8eSBen Gras #include "fsutil.h"
8194715d8eSBen Gras #include "exitvalues.h"
8294715d8eSBen Gras 
8394715d8eSBen Gras static daddr_t badblk;
8494715d8eSBen Gras static daddr_t dupblk;
8594715d8eSBen Gras static void checkinode(ino_t, struct inodesc *);
8694715d8eSBen Gras 
8794715d8eSBen Gras void
pass1(void)8894715d8eSBen Gras pass1(void)
8994715d8eSBen Gras {
9094715d8eSBen Gras 	ino_t inumber;
9194715d8eSBen Gras 	int c, i;
9294715d8eSBen Gras 	size_t j;
9394715d8eSBen Gras 	daddr_t dbase;
9494715d8eSBen Gras 	struct inodesc idesc;
9594715d8eSBen Gras 
9694715d8eSBen Gras 	/*
9794715d8eSBen Gras 	 * Set file system reserved blocks in used block map.
9894715d8eSBen Gras 	 */
9994715d8eSBen Gras 	for (c = 0; c < sblock.e2fs_ncg; c++) {
10094715d8eSBen Gras 		dbase = c * sblock.e2fs.e2fs_bpg +
10194715d8eSBen Gras 		    sblock.e2fs.e2fs_first_dblock;
10294715d8eSBen Gras 		/* Mark the blocks used for the inode table */
10394715d8eSBen Gras 		if (fs2h32(sblock.e2fs_gd[c].ext2bgd_i_tables) >= dbase) {
10494715d8eSBen Gras 			for (i = 0; i < sblock.e2fs_itpg; i++)
10594715d8eSBen Gras 				setbmap(
10694715d8eSBen Gras 				    fs2h32(sblock.e2fs_gd[c].ext2bgd_i_tables)
10794715d8eSBen Gras 				    + i);
10894715d8eSBen Gras 		}
10994715d8eSBen Gras 		/* Mark the blocks used for the block bitmap */
11094715d8eSBen Gras 		if (fs2h32(sblock.e2fs_gd[c].ext2bgd_b_bitmap) >= dbase)
11194715d8eSBen Gras 			setbmap(fs2h32(sblock.e2fs_gd[c].ext2bgd_b_bitmap));
11294715d8eSBen Gras 		/* Mark the blocks used for the inode bitmap */
11394715d8eSBen Gras 		if (fs2h32(sblock.e2fs_gd[c].ext2bgd_i_bitmap) >= dbase)
11494715d8eSBen Gras 			setbmap(fs2h32(sblock.e2fs_gd[c].ext2bgd_i_bitmap));
11594715d8eSBen Gras 
11694715d8eSBen Gras 		if (sblock.e2fs.e2fs_rev == E2FS_REV0 ||
11794715d8eSBen Gras 		    (sblock.e2fs.e2fs_features_rocompat &
11894715d8eSBen Gras 			EXT2F_ROCOMPAT_SPARSESUPER) == 0 ||
11994715d8eSBen Gras 		    cg_has_sb(c)) {
12094715d8eSBen Gras 			/* Mark copuy of SB and descriptors */
12194715d8eSBen Gras 			setbmap(dbase);
12294715d8eSBen Gras 			for (i = 1; i <= sblock.e2fs_ngdb; i++)
12394715d8eSBen Gras 				setbmap(dbase+i);
12494715d8eSBen Gras 		}
12594715d8eSBen Gras 
12694715d8eSBen Gras 
12794715d8eSBen Gras 		if (c == 0) {
12894715d8eSBen Gras 			for(i = 0; i < dbase; i++)
12994715d8eSBen Gras 				setbmap(i);
13094715d8eSBen Gras 		}
13194715d8eSBen Gras 	}
13294715d8eSBen Gras 
13394715d8eSBen Gras 	/*
13494715d8eSBen Gras 	 * Find all allocated blocks.
13594715d8eSBen Gras 	 */
13694715d8eSBen Gras 	memset(&idesc, 0, sizeof(struct inodesc));
13794715d8eSBen Gras 	idesc.id_type = ADDR;
13894715d8eSBen Gras 	idesc.id_func = pass1check;
13994715d8eSBen Gras 	inumber = 1;
14094715d8eSBen Gras 	n_files = n_blks = 0;
14194715d8eSBen Gras 	resetinodebuf();
14294715d8eSBen Gras 	for (c = 0; c < sblock.e2fs_ncg; c++) {
14394715d8eSBen Gras 		for (j = 0;
14494715d8eSBen Gras 			j < sblock.e2fs.e2fs_ipg && inumber <= sblock.e2fs.e2fs_icount;
14594715d8eSBen Gras 			j++, inumber++) {
14694715d8eSBen Gras 			if (inumber < EXT2_ROOTINO) /* XXX */
14794715d8eSBen Gras 				continue;
14894715d8eSBen Gras 			checkinode(inumber, &idesc);
14994715d8eSBen Gras 		}
15094715d8eSBen Gras 	}
15194715d8eSBen Gras 	freeinodebuf();
15294715d8eSBen Gras }
15394715d8eSBen Gras 
15494715d8eSBen Gras static void
checkinode(ino_t inumber,struct inodesc * idesc)15594715d8eSBen Gras checkinode(ino_t inumber, struct inodesc *idesc)
15694715d8eSBen Gras {
15794715d8eSBen Gras 	struct ext2fs_dinode *dp;
15894715d8eSBen Gras 	struct zlncnt *zlnp;
15994715d8eSBen Gras 	int ndb, j;
16094715d8eSBen Gras 	mode_t mode;
16194715d8eSBen Gras 
16294715d8eSBen Gras 	dp = getnextinode(inumber);
16394715d8eSBen Gras 	if (inumber < EXT2_FIRSTINO &&
16494715d8eSBen Gras 	    inumber != EXT2_ROOTINO &&
16594715d8eSBen Gras 	    !(inumber == EXT2_RESIZEINO &&
16694715d8eSBen Gras 	      (sblock.e2fs.e2fs_features_compat & EXT2F_COMPAT_RESIZE) != 0))
16794715d8eSBen Gras 		return;
16894715d8eSBen Gras 
16994715d8eSBen Gras 	mode = fs2h16(dp->e2di_mode) & IFMT;
17094715d8eSBen Gras 	if (mode == 0 || (dp->e2di_dtime != 0 && dp->e2di_nlink == 0)) {
17194715d8eSBen Gras 		if (mode == 0 && (
17294715d8eSBen Gras 		    memcmp(dp->e2di_blocks, zino.e2di_blocks,
173*84d9c625SLionel Sambuc 		    (EXT2FS_NDADDR + EXT2FS_NIADDR) * sizeof(u_int32_t)) ||
17494715d8eSBen Gras 		    dp->e2di_mode || inosize(dp))) {
17594715d8eSBen Gras 			pfatal("PARTIALLY ALLOCATED INODE I=%llu",
17694715d8eSBen Gras 			    (unsigned long long)inumber);
17794715d8eSBen Gras 			if (reply("CLEAR") == 1) {
17894715d8eSBen Gras 				dp = ginode(inumber);
17994715d8eSBen Gras 				clearinode(dp);
18094715d8eSBen Gras 				inodirty();
18194715d8eSBen Gras 			}
18294715d8eSBen Gras 		}
18394715d8eSBen Gras #ifdef notyet /* it seems that dtime == 0 is valid for a unallocated inode */
18494715d8eSBen Gras 		if (dp->e2di_dtime == 0) {
18594715d8eSBen Gras 			pwarn("DELETED INODE I=%llu HAS A NULL DTIME",
18694715d8eSBen Gras 			    (unsigned long long)inumber);
18794715d8eSBen Gras 			if (preen) {
18894715d8eSBen Gras 				printf(" (CORRECTED)\n");
18994715d8eSBen Gras 			}
19094715d8eSBen Gras 			if (preen || reply("CORRECT")) {
19194715d8eSBen Gras 				time_t t;
19294715d8eSBen Gras 				time(&t);
19394715d8eSBen Gras 				dp->e2di_dtime = h2fs32(t);
19494715d8eSBen Gras 				dp = ginode(inumber);
19594715d8eSBen Gras 				inodirty();
19694715d8eSBen Gras 			}
19794715d8eSBen Gras 		}
19894715d8eSBen Gras #endif
19994715d8eSBen Gras 		statemap[inumber] = USTATE;
20094715d8eSBen Gras 		return;
20194715d8eSBen Gras 	}
20294715d8eSBen Gras 	lastino = inumber;
20394715d8eSBen Gras 	if (dp->e2di_dtime != 0) {
20494715d8eSBen Gras 		pwarn("INODE I=%llu HAS DTIME=%s",
20594715d8eSBen Gras 		    (unsigned long long)inumber,
20694715d8eSBen Gras 		    print_mtime(fs2h32(dp->e2di_dtime)));
20794715d8eSBen Gras 		if (preen) {
20894715d8eSBen Gras 			printf(" (CORRECTED)\n");
20994715d8eSBen Gras 		}
21094715d8eSBen Gras 		if (preen || reply("CORRECT")) {
21194715d8eSBen Gras 			dp = ginode(inumber);
21294715d8eSBen Gras 			dp->e2di_dtime = 0;
21394715d8eSBen Gras 			inodirty();
21494715d8eSBen Gras 		}
21594715d8eSBen Gras 	}
21694715d8eSBen Gras 	if (inosize(dp) + sblock.e2fs_bsize - 1 < inosize(dp)) {
21794715d8eSBen Gras 		if (debug)
21894715d8eSBen Gras 			printf("bad size %llu:", (unsigned long long)inosize(dp));
21994715d8eSBen Gras 		goto unknown;
22094715d8eSBen Gras 	}
22194715d8eSBen Gras 	if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
22294715d8eSBen Gras 		dp = ginode(inumber);
22394715d8eSBen Gras 		dp->e2di_mode = h2fs16(IFREG|0600);
22494715d8eSBen Gras 		inossize(dp, sblock.e2fs_bsize);
22594715d8eSBen Gras 		inodirty();
22694715d8eSBen Gras 	}
22794715d8eSBen Gras 	ndb = howmany(inosize(dp), sblock.e2fs_bsize);
22894715d8eSBen Gras 	if (ndb < 0) {
22994715d8eSBen Gras 		if (debug)
23094715d8eSBen Gras 			printf("bad size %llu ndb %d:",
23194715d8eSBen Gras 			    (unsigned long long)inosize(dp), ndb);
23294715d8eSBen Gras 		goto unknown;
23394715d8eSBen Gras 	}
23494715d8eSBen Gras 	if (mode == IFBLK || mode == IFCHR)
23594715d8eSBen Gras 		ndb++;
23694715d8eSBen Gras 	if (mode == IFLNK) {
23794715d8eSBen Gras 		/*
23894715d8eSBen Gras 		 * Fake ndb value so direct/indirect block checks below
23994715d8eSBen Gras 		 * will detect any garbage after symlink string.
24094715d8eSBen Gras 		 */
24194715d8eSBen Gras 		if (inosize(dp) < EXT2_MAXSYMLINKLEN ||
24294715d8eSBen Gras 		    (EXT2_MAXSYMLINKLEN == 0 && dp->e2di_blocks == 0)) {
24394715d8eSBen Gras 			ndb = howmany(inosize(dp), sizeof(u_int32_t));
244*84d9c625SLionel Sambuc 			if (ndb > EXT2FS_NDADDR) {
245*84d9c625SLionel Sambuc 				j = ndb - EXT2FS_NDADDR;
24694715d8eSBen Gras 				for (ndb = 1; j > 1; j--)
247*84d9c625SLionel Sambuc 					ndb *= EXT2_NINDIR(&sblock);
248*84d9c625SLionel Sambuc 				ndb += EXT2FS_NDADDR;
24994715d8eSBen Gras 			}
25094715d8eSBen Gras 		}
25194715d8eSBen Gras 	}
25294715d8eSBen Gras 	/* Linux puts things in blocks for FIFO, so skip this check */
25394715d8eSBen Gras 	if (mode != IFIFO) {
254*84d9c625SLionel Sambuc 		for (j = ndb; j < EXT2FS_NDADDR; j++)
25594715d8eSBen Gras 			if (dp->e2di_blocks[j] != 0) {
25694715d8eSBen Gras 				if (debug)
25794715d8eSBen Gras 					printf("bad direct addr: %d\n",
25894715d8eSBen Gras 					    fs2h32(dp->e2di_blocks[j]));
25994715d8eSBen Gras 				goto unknown;
26094715d8eSBen Gras 			}
261*84d9c625SLionel Sambuc 		for (j = 0, ndb -= EXT2FS_NDADDR; ndb > 0; j++)
262*84d9c625SLionel Sambuc 			ndb /= EXT2_NINDIR(&sblock);
263*84d9c625SLionel Sambuc 		for (; j < EXT2FS_NIADDR; j++) {
264*84d9c625SLionel Sambuc 			if (dp->e2di_blocks[j+EXT2FS_NDADDR] != 0) {
26594715d8eSBen Gras 				if (debug)
26694715d8eSBen Gras 					printf("bad indirect addr: %d\n",
267*84d9c625SLionel Sambuc 					    fs2h32(dp->e2di_blocks[j+EXT2FS_NDADDR]));
26894715d8eSBen Gras 				goto unknown;
26994715d8eSBen Gras 			}
27094715d8eSBen Gras 		}
27194715d8eSBen Gras 	}
27294715d8eSBen Gras 	if (ftypeok(dp) == 0)
27394715d8eSBen Gras 		goto unknown;
27494715d8eSBen Gras 	if (inumber >= EXT2_FIRSTINO || inumber == EXT2_ROOTINO) {
27594715d8eSBen Gras 		/* Don't count reserved inodes except root */
27694715d8eSBen Gras 		n_files++;
27794715d8eSBen Gras 	}
27894715d8eSBen Gras 	lncntp[inumber] = fs2h16(dp->e2di_nlink);
27994715d8eSBen Gras 	if (dp->e2di_nlink == 0) {
28094715d8eSBen Gras 		zlnp = malloc(sizeof *zlnp);
28194715d8eSBen Gras 		if (zlnp == NULL) {
28294715d8eSBen Gras 			pfatal("LINK COUNT TABLE OVERFLOW");
28394715d8eSBen Gras 			if (reply("CONTINUE") == 0)
28494715d8eSBen Gras 				exit(FSCK_EXIT_CHECK_FAILED);
28594715d8eSBen Gras 		} else {
28694715d8eSBen Gras 			zlnp->zlncnt = inumber;
28794715d8eSBen Gras 			zlnp->next = zlnhead;
28894715d8eSBen Gras 			zlnhead = zlnp;
28994715d8eSBen Gras 		}
29094715d8eSBen Gras 	}
29194715d8eSBen Gras 	if (mode == IFDIR) {
29294715d8eSBen Gras 		if (inosize(dp) == 0)
29394715d8eSBen Gras 			statemap[inumber] = DCLEAR;
29494715d8eSBen Gras 		else
29594715d8eSBen Gras 			statemap[inumber] = DSTATE;
29694715d8eSBen Gras 		cacheino(dp, inumber);
29794715d8eSBen Gras 	} else {
29894715d8eSBen Gras 		statemap[inumber] = FSTATE;
29994715d8eSBen Gras 	}
30094715d8eSBen Gras 	typemap[inumber] = E2IFTODT(mode);
30194715d8eSBen Gras 	badblk = dupblk = 0;
30294715d8eSBen Gras 	idesc->id_number = inumber;
30394715d8eSBen Gras 	(void)ckinode(dp, idesc);
30494715d8eSBen Gras 	idesc->id_entryno *= btodb(sblock.e2fs_bsize);
305*84d9c625SLionel Sambuc 	if (inonblock(dp) != (uint32_t)idesc->id_entryno) {
306*84d9c625SLionel Sambuc 		pwarn("INCORRECT BLOCK COUNT I=%llu (%llu should be %d)",
307*84d9c625SLionel Sambuc 		    (unsigned long long)inumber,
308*84d9c625SLionel Sambuc 		    (unsigned long long)inonblock(dp),
30994715d8eSBen Gras 		    idesc->id_entryno);
31094715d8eSBen Gras 		if (preen)
31194715d8eSBen Gras 			printf(" (CORRECTED)\n");
31294715d8eSBen Gras 		else if (reply("CORRECT") == 0)
31394715d8eSBen Gras 			return;
31494715d8eSBen Gras 		dp = ginode(inumber);
315*84d9c625SLionel Sambuc 		inosnblock(dp, idesc->id_entryno);
31694715d8eSBen Gras 		inodirty();
31794715d8eSBen Gras 	}
31894715d8eSBen Gras 	return;
31994715d8eSBen Gras unknown:
32094715d8eSBen Gras 	pfatal("UNKNOWN FILE TYPE I=%llu", (unsigned long long)inumber);
32194715d8eSBen Gras 	statemap[inumber] = FCLEAR;
32294715d8eSBen Gras 	if (reply("CLEAR") == 1) {
32394715d8eSBen Gras 		statemap[inumber] = USTATE;
32494715d8eSBen Gras 		dp = ginode(inumber);
32594715d8eSBen Gras 		clearinode(dp);
32694715d8eSBen Gras 		inodirty();
32794715d8eSBen Gras 	}
32894715d8eSBen Gras }
32994715d8eSBen Gras 
33094715d8eSBen Gras int
pass1check(struct inodesc * idesc)33194715d8eSBen Gras pass1check(struct inodesc *idesc)
33294715d8eSBen Gras {
33394715d8eSBen Gras 	int res = KEEPON;
33494715d8eSBen Gras 	int anyout, nfrags;
33594715d8eSBen Gras 	daddr_t blkno = idesc->id_blkno;
33694715d8eSBen Gras 	struct dups *dlp;
33794715d8eSBen Gras 	struct dups *new;
33894715d8eSBen Gras 
33994715d8eSBen Gras 	if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
34094715d8eSBen Gras 		blkerror(idesc->id_number, "BAD", blkno);
34194715d8eSBen Gras 		if (badblk++ >= MAXBAD) {
34294715d8eSBen Gras 			pwarn("EXCESSIVE BAD BLKS I=%llu",
34394715d8eSBen Gras 			    (unsigned long long)idesc->id_number);
34494715d8eSBen Gras 			if (preen)
34594715d8eSBen Gras 				printf(" (SKIPPING)\n");
34694715d8eSBen Gras 			else if (reply("CONTINUE") == 0)
34794715d8eSBen Gras 				exit(FSCK_EXIT_CHECK_FAILED);
34894715d8eSBen Gras 			return (STOP);
34994715d8eSBen Gras 		}
35094715d8eSBen Gras 	}
35194715d8eSBen Gras 	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
35294715d8eSBen Gras 		if (anyout && chkrange(blkno, 1)) {
35394715d8eSBen Gras 			res = SKIP;
35494715d8eSBen Gras 		} else if (!testbmap(blkno)) {
35594715d8eSBen Gras 			n_blks++;
35694715d8eSBen Gras 			setbmap(blkno);
35794715d8eSBen Gras 		} else {
35894715d8eSBen Gras 			blkerror(idesc->id_number, "DUP", blkno);
35994715d8eSBen Gras 			if (dupblk++ >= MAXDUP) {
36094715d8eSBen Gras 				pwarn("EXCESSIVE DUP BLKS I=%llu",
36194715d8eSBen Gras 				    (unsigned long long)idesc->id_number);
36294715d8eSBen Gras 				if (preen)
36394715d8eSBen Gras 					printf(" (SKIPPING)\n");
36494715d8eSBen Gras 				else if (reply("CONTINUE") == 0)
36594715d8eSBen Gras 					exit(FSCK_EXIT_CHECK_FAILED);
36694715d8eSBen Gras 				return (STOP);
36794715d8eSBen Gras 			}
36894715d8eSBen Gras 			new = malloc(sizeof(struct dups));
36994715d8eSBen Gras 			if (new == NULL) {
37094715d8eSBen Gras 				pfatal("DUP TABLE OVERFLOW.");
37194715d8eSBen Gras 				if (reply("CONTINUE") == 0)
37294715d8eSBen Gras 					exit(FSCK_EXIT_CHECK_FAILED);
37394715d8eSBen Gras 				return (STOP);
37494715d8eSBen Gras 			}
37594715d8eSBen Gras 			new->dup = blkno;
37694715d8eSBen Gras 			if (muldup == 0) {
37794715d8eSBen Gras 				duplist = muldup = new;
37894715d8eSBen Gras 				new->next = 0;
37994715d8eSBen Gras 			} else {
38094715d8eSBen Gras 				new->next = muldup->next;
38194715d8eSBen Gras 				muldup->next = new;
38294715d8eSBen Gras 			}
38394715d8eSBen Gras 			for (dlp = duplist; dlp != muldup; dlp = dlp->next)
38494715d8eSBen Gras 				if (dlp->dup == blkno)
38594715d8eSBen Gras 					break;
38694715d8eSBen Gras 			if (dlp == muldup && dlp->dup != blkno)
38794715d8eSBen Gras 				muldup = new;
38894715d8eSBen Gras 		}
38994715d8eSBen Gras 		/*
39094715d8eSBen Gras 		 * count the number of blocks found in id_entryno
39194715d8eSBen Gras 		 */
39294715d8eSBen Gras 		idesc->id_entryno++;
39394715d8eSBen Gras 	}
39494715d8eSBen Gras 	return (res);
39594715d8eSBen Gras }
396