1*abbb3558Sotto /* $OpenBSD: pass1b.c,v 1.22 2020/06/20 07:49:04 otto Exp $ */
287304b87Stholo /* $NetBSD: pass1b.c,v 1.10 1996/09/23 16:18:37 christos Exp $ */
3df930be7Sderaadt
4df930be7Sderaadt /*
5df930be7Sderaadt * Copyright (c) 1980, 1986, 1993
6df930be7Sderaadt * The Regents of the University of California. All rights reserved.
7df930be7Sderaadt *
8df930be7Sderaadt * Redistribution and use in source and binary forms, with or without
9df930be7Sderaadt * modification, are permitted provided that the following conditions
10df930be7Sderaadt * are met:
11df930be7Sderaadt * 1. Redistributions of source code must retain the above copyright
12df930be7Sderaadt * notice, this list of conditions and the following disclaimer.
13df930be7Sderaadt * 2. Redistributions in binary form must reproduce the above copyright
14df930be7Sderaadt * notice, this list of conditions and the following disclaimer in the
15df930be7Sderaadt * documentation and/or other materials provided with the distribution.
161ef0d710Smillert * 3. Neither the name of the University nor the names of its contributors
17df930be7Sderaadt * may be used to endorse or promote products derived from this software
18df930be7Sderaadt * without specific prior written permission.
19df930be7Sderaadt *
20df930be7Sderaadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21df930be7Sderaadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22df930be7Sderaadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23df930be7Sderaadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24df930be7Sderaadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25df930be7Sderaadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26df930be7Sderaadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27df930be7Sderaadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28df930be7Sderaadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29df930be7Sderaadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30df930be7Sderaadt * SUCH DAMAGE.
31df930be7Sderaadt */
32df930be7Sderaadt
33df930be7Sderaadt #include <sys/time.h>
34df930be7Sderaadt #include <ufs/ufs/dinode.h>
35df930be7Sderaadt #include <ufs/ffs/fs.h>
36df930be7Sderaadt
37af9e537cSd #include <stdio.h>
38df930be7Sderaadt #include <string.h>
39df930be7Sderaadt #include "fsck.h"
40df930be7Sderaadt #include "extern.h"
41df930be7Sderaadt
42c72b5b24Smillert static int pass1bcheck(struct inodesc *);
43df930be7Sderaadt static struct dups *duphead;
44df930be7Sderaadt
45af9e537cSd static ino_t info_inumber;
46af9e537cSd
47af9e537cSd static int
pass1b_info(char * buf,size_t buflen)48379d1969Sderaadt pass1b_info(char *buf, size_t buflen)
49af9e537cSd {
503b92bd08Sderaadt return (snprintf(buf, buflen, "phase 1b, inode %llu/%llu",
513b92bd08Sderaadt (unsigned long long)info_inumber,
523b92bd08Sderaadt (unsigned long long)sblock.fs_ipg * sblock.fs_ncg) > 0);
53af9e537cSd }
54af9e537cSd
55df930be7Sderaadt void
pass1b(void)5660d6b16fSgluk pass1b(void)
57df930be7Sderaadt {
58*abbb3558Sotto u_int c, i;
592fffe0e0Smillert union dinode *dp;
60df930be7Sderaadt struct inodesc idesc;
61df930be7Sderaadt ino_t inumber;
62df930be7Sderaadt
63df930be7Sderaadt memset(&idesc, 0, sizeof(struct inodesc));
64df930be7Sderaadt idesc.id_type = ADDR;
65df930be7Sderaadt idesc.id_func = pass1bcheck;
66df930be7Sderaadt duphead = duplist;
67df930be7Sderaadt inumber = 0;
68af9e537cSd info_fn = pass1b_info;
69df930be7Sderaadt for (c = 0; c < sblock.fs_ncg; c++) {
70df930be7Sderaadt for (i = 0; i < sblock.fs_ipg; i++, inumber++) {
71af9e537cSd info_inumber = inumber;
72df930be7Sderaadt if (inumber < ROOTINO)
73df930be7Sderaadt continue;
74df930be7Sderaadt dp = ginode(inumber);
75df930be7Sderaadt if (dp == NULL)
76df930be7Sderaadt continue;
77df930be7Sderaadt idesc.id_number = inumber;
784aab0ea5Sotto if (GET_ISTATE(inumber) != USTATE &&
79df930be7Sderaadt (ckinode(dp, &idesc) & STOP))
80df930be7Sderaadt return;
81df930be7Sderaadt }
82df930be7Sderaadt }
83af9e537cSd info_fn = NULL;
84df930be7Sderaadt }
85df930be7Sderaadt
8687304b87Stholo static int
pass1bcheck(struct inodesc * idesc)8760d6b16fSgluk pass1bcheck(struct inodesc *idesc)
88df930be7Sderaadt {
89e073c79dSmpech struct dups *dlp;
90df930be7Sderaadt int nfrags, res = KEEPON;
911abdbfdeSderaadt daddr_t blkno = idesc->id_blkno;
92df930be7Sderaadt
93df930be7Sderaadt for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
94df930be7Sderaadt if (chkrange(blkno, 1))
95df930be7Sderaadt res = SKIP;
96df930be7Sderaadt for (dlp = duphead; dlp; dlp = dlp->next) {
97df930be7Sderaadt if (dlp->dup == blkno) {
98df930be7Sderaadt blkerror(idesc->id_number, "DUP", blkno);
99df930be7Sderaadt dlp->dup = duphead->dup;
100df930be7Sderaadt duphead->dup = blkno;
101df930be7Sderaadt duphead = duphead->next;
102df930be7Sderaadt }
103df930be7Sderaadt if (dlp == muldup)
104df930be7Sderaadt break;
105df930be7Sderaadt }
106df930be7Sderaadt if (muldup == 0 || duphead == muldup->next)
107df930be7Sderaadt return (STOP);
108df930be7Sderaadt }
109df930be7Sderaadt return (res);
110df930be7Sderaadt }
111