1*b9fc9a72Sderaadt /* $OpenBSD: pass1b.c,v 1.9 2015/01/16 06:39:57 deraadt Exp $ */
20190393fSart /* $NetBSD: pass1b.c,v 1.2 1997/09/14 14:27:26 lukem Exp $ */
38c424e8eSdownsj
48c424e8eSdownsj /*
55ff4e0c8Sdownsj * Copyright (c) 1997 Manuel Bouyer.
68c424e8eSdownsj * Copyright (c) 1980, 1986, 1993
78c424e8eSdownsj * The Regents of the University of California. All rights reserved.
88c424e8eSdownsj *
98c424e8eSdownsj * Redistribution and use in source and binary forms, with or without
108c424e8eSdownsj * modification, are permitted provided that the following conditions
118c424e8eSdownsj * are met:
128c424e8eSdownsj * 1. Redistributions of source code must retain the above copyright
138c424e8eSdownsj * notice, this list of conditions and the following disclaimer.
148c424e8eSdownsj * 2. Redistributions in binary form must reproduce the above copyright
158c424e8eSdownsj * notice, this list of conditions and the following disclaimer in the
168c424e8eSdownsj * documentation and/or other materials provided with the distribution.
171ef0d710Smillert * 3. Neither the name of the University nor the names of its contributors
188c424e8eSdownsj * may be used to endorse or promote products derived from this software
198c424e8eSdownsj * without specific prior written permission.
208c424e8eSdownsj *
218c424e8eSdownsj * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
228c424e8eSdownsj * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238c424e8eSdownsj * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248c424e8eSdownsj * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
258c424e8eSdownsj * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
268c424e8eSdownsj * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
278c424e8eSdownsj * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
288c424e8eSdownsj * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
298c424e8eSdownsj * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
308c424e8eSdownsj * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318c424e8eSdownsj * SUCH DAMAGE.
328c424e8eSdownsj */
338c424e8eSdownsj
348c424e8eSdownsj #include <sys/time.h>
358c424e8eSdownsj #include <ufs/ext2fs/ext2fs_dinode.h>
368c424e8eSdownsj #include <ufs/ext2fs/ext2fs.h>
378c424e8eSdownsj
388c424e8eSdownsj #include <string.h>
398c424e8eSdownsj #include "fsck.h"
408c424e8eSdownsj #include "extern.h"
418c424e8eSdownsj
42c72b5b24Smillert static int pass1bcheck(struct inodesc *);
438c424e8eSdownsj static struct dups *duphead;
448c424e8eSdownsj
458c424e8eSdownsj void
pass1b(void)468809fabbSderaadt pass1b(void)
478c424e8eSdownsj {
480190393fSart int c, i;
490190393fSart struct ext2fs_dinode *dp;
508c424e8eSdownsj struct inodesc idesc;
518c424e8eSdownsj ino_t inumber;
528c424e8eSdownsj
538c424e8eSdownsj memset(&idesc, 0, sizeof(struct inodesc));
548c424e8eSdownsj idesc.id_type = ADDR;
558c424e8eSdownsj idesc.id_func = pass1bcheck;
568c424e8eSdownsj duphead = duplist;
578c424e8eSdownsj inumber = 0;
588c424e8eSdownsj for (c = 0; c < sblock.e2fs_ncg; c++) {
598c424e8eSdownsj for (i = 0; i < sblock.e2fs.e2fs_ipg; i++, inumber++) {
608c424e8eSdownsj if ((inumber < EXT2_FIRSTINO) && (inumber != EXT2_ROOTINO))
618c424e8eSdownsj continue;
628c424e8eSdownsj dp = ginode(inumber);
638c424e8eSdownsj if (dp == NULL)
648c424e8eSdownsj continue;
658c424e8eSdownsj idesc.id_number = inumber;
668c424e8eSdownsj if (statemap[inumber] != USTATE &&
678c424e8eSdownsj (ckinode(dp, &idesc) & STOP))
688c424e8eSdownsj return;
698c424e8eSdownsj }
708c424e8eSdownsj }
718c424e8eSdownsj }
728c424e8eSdownsj
738c424e8eSdownsj static int
pass1bcheck(struct inodesc * idesc)748809fabbSderaadt pass1bcheck(struct inodesc *idesc)
758c424e8eSdownsj {
760190393fSart struct dups *dlp;
778c424e8eSdownsj int nfrags, res = KEEPON;
78b6d2e2d5Sderaadt daddr32_t blkno = idesc->id_blkno;
798c424e8eSdownsj
808c424e8eSdownsj for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
818c424e8eSdownsj if (chkrange(blkno, 1))
828c424e8eSdownsj res = SKIP;
838c424e8eSdownsj for (dlp = duphead; dlp; dlp = dlp->next) {
848c424e8eSdownsj if (dlp->dup == blkno) {
858c424e8eSdownsj blkerror(idesc->id_number, "DUP", blkno);
868c424e8eSdownsj dlp->dup = duphead->dup;
878c424e8eSdownsj duphead->dup = blkno;
888c424e8eSdownsj duphead = duphead->next;
898c424e8eSdownsj }
908c424e8eSdownsj if (dlp == muldup)
918c424e8eSdownsj break;
928c424e8eSdownsj }
938c424e8eSdownsj if (muldup == 0 || duphead == muldup->next)
948c424e8eSdownsj return (STOP);
958c424e8eSdownsj }
968c424e8eSdownsj return (res);
978c424e8eSdownsj }
98