1*6d07b400Sbouyer /* $NetBSD: pass1b.c,v 1.8 2009/10/19 18:41:08 bouyer Exp $ */
2bf07c871Sagc
3bf07c871Sagc /*
4bf07c871Sagc * Copyright (c) 1980, 1986, 1993
5bf07c871Sagc * The Regents of the University of California. All rights reserved.
6bf07c871Sagc *
7bf07c871Sagc * Redistribution and use in source and binary forms, with or without
8bf07c871Sagc * modification, are permitted provided that the following conditions
9bf07c871Sagc * are met:
10bf07c871Sagc * 1. Redistributions of source code must retain the above copyright
11bf07c871Sagc * notice, this list of conditions and the following disclaimer.
12bf07c871Sagc * 2. Redistributions in binary form must reproduce the above copyright
13bf07c871Sagc * notice, this list of conditions and the following disclaimer in the
14bf07c871Sagc * documentation and/or other materials provided with the distribution.
15bf07c871Sagc * 3. Neither the name of the University nor the names of its contributors
16bf07c871Sagc * may be used to endorse or promote products derived from this software
17bf07c871Sagc * without specific prior written permission.
18bf07c871Sagc *
19bf07c871Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20bf07c871Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21bf07c871Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22bf07c871Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23bf07c871Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24bf07c871Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25bf07c871Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26bf07c871Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27bf07c871Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28bf07c871Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29bf07c871Sagc * SUCH DAMAGE.
30bf07c871Sagc */
318f7c2b37Sbouyer
328f7c2b37Sbouyer /*
338f7c2b37Sbouyer * Copyright (c) 1997 Manuel Bouyer.
348f7c2b37Sbouyer *
358f7c2b37Sbouyer * Redistribution and use in source and binary forms, with or without
368f7c2b37Sbouyer * modification, are permitted provided that the following conditions
378f7c2b37Sbouyer * are met:
388f7c2b37Sbouyer * 1. Redistributions of source code must retain the above copyright
398f7c2b37Sbouyer * notice, this list of conditions and the following disclaimer.
408f7c2b37Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
418f7c2b37Sbouyer * notice, this list of conditions and the following disclaimer in the
428f7c2b37Sbouyer * documentation and/or other materials provided with the distribution.
438f7c2b37Sbouyer *
442f853da9Sbouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
452f853da9Sbouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
462f853da9Sbouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
472f853da9Sbouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
482f853da9Sbouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
492f853da9Sbouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
502f853da9Sbouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
512f853da9Sbouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
522f853da9Sbouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
532f853da9Sbouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
548f7c2b37Sbouyer */
558f7c2b37Sbouyer
564b836889Slukem #include <sys/cdefs.h>
578f7c2b37Sbouyer #ifndef lint
588f7c2b37Sbouyer #if 0
598f7c2b37Sbouyer static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
608f7c2b37Sbouyer #else
61*6d07b400Sbouyer __RCSID("$NetBSD: pass1b.c,v 1.8 2009/10/19 18:41:08 bouyer Exp $");
628f7c2b37Sbouyer #endif
638f7c2b37Sbouyer #endif /* not lint */
648f7c2b37Sbouyer
658f7c2b37Sbouyer #include <sys/param.h>
668f7c2b37Sbouyer #include <sys/time.h>
678f7c2b37Sbouyer #include <ufs/ext2fs/ext2fs_dinode.h>
688f7c2b37Sbouyer #include <ufs/ext2fs/ext2fs.h>
698f7c2b37Sbouyer
708f7c2b37Sbouyer #include <string.h>
718f7c2b37Sbouyer #include "fsck.h"
728f7c2b37Sbouyer #include "extern.h"
738f7c2b37Sbouyer
74ccde05f0Sxtraeme static int pass1bcheck(struct inodesc *);
758f7c2b37Sbouyer static struct dups *duphead;
768f7c2b37Sbouyer
778f7c2b37Sbouyer void
pass1b(void)78ccde05f0Sxtraeme pass1b(void)
798f7c2b37Sbouyer {
805bd52bbaSlukem int c;
815bd52bbaSlukem uint32_t i;
824b836889Slukem struct ext2fs_dinode *dp;
838f7c2b37Sbouyer struct inodesc idesc;
848f7c2b37Sbouyer ino_t inumber;
858f7c2b37Sbouyer
868f7c2b37Sbouyer memset(&idesc, 0, sizeof(struct inodesc));
878f7c2b37Sbouyer idesc.id_type = ADDR;
888f7c2b37Sbouyer idesc.id_func = pass1bcheck;
898f7c2b37Sbouyer duphead = duplist;
908f7c2b37Sbouyer inumber = 0;
918f7c2b37Sbouyer for (c = 0; c < sblock.e2fs_ncg; c++) {
928f7c2b37Sbouyer for (i = 0; i < sblock.e2fs.e2fs_ipg; i++, inumber++) {
938f7c2b37Sbouyer if ((inumber < EXT2_FIRSTINO) && (inumber != EXT2_ROOTINO))
948f7c2b37Sbouyer continue;
958f7c2b37Sbouyer dp = ginode(inumber);
968f7c2b37Sbouyer if (dp == NULL)
978f7c2b37Sbouyer continue;
988f7c2b37Sbouyer idesc.id_number = inumber;
998f7c2b37Sbouyer if (statemap[inumber] != USTATE &&
1008f7c2b37Sbouyer (ckinode(dp, &idesc) & STOP))
1018f7c2b37Sbouyer return;
1028f7c2b37Sbouyer }
1038f7c2b37Sbouyer }
1048f7c2b37Sbouyer }
1058f7c2b37Sbouyer
1068f7c2b37Sbouyer static int
pass1bcheck(struct inodesc * idesc)107ccde05f0Sxtraeme pass1bcheck(struct inodesc *idesc)
1088f7c2b37Sbouyer {
1094b836889Slukem struct dups *dlp;
1108f7c2b37Sbouyer int nfrags, res = KEEPON;
1118f7c2b37Sbouyer daddr_t blkno = idesc->id_blkno;
1128f7c2b37Sbouyer
1138f7c2b37Sbouyer for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
1148f7c2b37Sbouyer if (chkrange(blkno, 1))
1158f7c2b37Sbouyer res = SKIP;
1168f7c2b37Sbouyer for (dlp = duphead; dlp; dlp = dlp->next) {
1178f7c2b37Sbouyer if (dlp->dup == blkno) {
1188f7c2b37Sbouyer blkerror(idesc->id_number, "DUP", blkno);
1198f7c2b37Sbouyer dlp->dup = duphead->dup;
1208f7c2b37Sbouyer duphead->dup = blkno;
1218f7c2b37Sbouyer duphead = duphead->next;
1228f7c2b37Sbouyer }
1238f7c2b37Sbouyer if (dlp == muldup)
1248f7c2b37Sbouyer break;
1258f7c2b37Sbouyer }
1268f7c2b37Sbouyer if (muldup == 0 || duphead == muldup->next)
1278f7c2b37Sbouyer return (STOP);
1288f7c2b37Sbouyer }
1298f7c2b37Sbouyer return (res);
1308f7c2b37Sbouyer }
131