18a16b7a1SPedro F. Giffuni /*-
28a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
38a16b7a1SPedro F. Giffuni *
48fae3551SRodney W. Grimes * Copyright (c) 1980, 1986, 1993
58fae3551SRodney W. Grimes * The Regents of the University of California. All rights reserved.
68fae3551SRodney W. Grimes *
78fae3551SRodney W. Grimes * Redistribution and use in source and binary forms, with or without
88fae3551SRodney W. Grimes * modification, are permitted provided that the following conditions
98fae3551SRodney W. Grimes * are met:
108fae3551SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright
118fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer.
128fae3551SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright
138fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the
148fae3551SRodney W. Grimes * documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
168fae3551SRodney W. Grimes * may be used to endorse or promote products derived from this software
178fae3551SRodney W. Grimes * without specific prior written permission.
188fae3551SRodney W. Grimes *
198fae3551SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208fae3551SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218fae3551SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228fae3551SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238fae3551SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248fae3551SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258fae3551SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268fae3551SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278fae3551SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288fae3551SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298fae3551SRodney W. Grimes * SUCH DAMAGE.
308fae3551SRodney W. Grimes */
318fae3551SRodney W. Grimes
328fae3551SRodney W. Grimes #include <sys/param.h>
33780a5c1eSPeter Wemm
348fae3551SRodney W. Grimes #include <ufs/ufs/dinode.h>
358fae3551SRodney W. Grimes #include <ufs/ffs/fs.h>
36780a5c1eSPeter Wemm
378fae3551SRodney W. Grimes #include <string.h>
38780a5c1eSPeter Wemm
398fae3551SRodney W. Grimes #include "fsck.h"
408fae3551SRodney W. Grimes
418fae3551SRodney W. Grimes static struct dups *duphead;
42b70cd7eeSWarner Losh static int pass1bcheck(struct inodesc *);
438fae3551SRodney W. Grimes
4431f4ab50SBruce Evans void
pass1b(void)45b70cd7eeSWarner Losh pass1b(void)
468fae3551SRodney W. Grimes {
473d438ad6SDavid E. O'Brien int c, i;
481c85e6a3SKirk McKusick union dinode *dp;
498fae3551SRodney W. Grimes struct inodesc idesc;
505cc52631SKirk McKusick ino_t inumber, inosused;
518fae3551SRodney W. Grimes
52780a5c1eSPeter Wemm memset(&idesc, 0, sizeof(struct inodesc));
538fae3551SRodney W. Grimes idesc.id_func = pass1bcheck;
548fae3551SRodney W. Grimes duphead = duplist;
558fae3551SRodney W. Grimes for (c = 0; c < sblock.fs_ncg; c++) {
566db798caSIan Dowse if (got_siginfo) {
576db798caSIan Dowse printf("%s: phase 1b: cyl group %d of %d (%d%%)\n",
586db798caSIan Dowse cdevname, c, sblock.fs_ncg,
596db798caSIan Dowse c * 100 / sblock.fs_ncg);
606db798caSIan Dowse got_siginfo = 0;
616db798caSIan Dowse }
621660ae87SScott Long if (got_sigalarm) {
631660ae87SScott Long setproctitle("%s p1b %d%%", cdevname,
641660ae87SScott Long c * 100 / sblock.fs_ncg);
65e94598bbSWarner Losh got_sigalarm = 0;
661660ae87SScott Long }
675cc52631SKirk McKusick inosused = inostathead[c].il_numalloced;
685cc52631SKirk McKusick if (inosused == 0)
695cc52631SKirk McKusick continue;
705cc52631SKirk McKusick setinodebuf(c, inosused);
71fe815b88SKirk McKusick inumber = c * sblock.fs_ipg;
725cc52631SKirk McKusick for (i = 0; i < inosused; i++, inumber++) {
73bc444e2eSKirk McKusick if (inumber < UFS_ROOTINO) {
74bc444e2eSKirk McKusick (void)getnextinode(inumber, 0);
758fae3551SRodney W. Grimes continue;
76bc444e2eSKirk McKusick }
775cc52631SKirk McKusick dp = getnextinode(inumber, 0);
788fae3551SRodney W. Grimes idesc.id_number = inumber;
795cc52631SKirk McKusick idesc.id_type = inoinfo(inumber)->ino_idtype;
80d33e92f9SJulian Elischer if (inoinfo(inumber)->ino_state != USTATE &&
817703a6ffSScott Long (ckinode(dp, &idesc) & STOP)) {
827703a6ffSScott Long rerun = 1;
83*cf17c2ffSKirk McKusick freeinodebuf();
848fae3551SRodney W. Grimes return;
858fae3551SRodney W. Grimes }
868fae3551SRodney W. Grimes }
878fae3551SRodney W. Grimes }
88*cf17c2ffSKirk McKusick freeinodebuf();
897703a6ffSScott Long }
908fae3551SRodney W. Grimes
91780a5c1eSPeter Wemm static int
pass1bcheck(struct inodesc * idesc)92b70cd7eeSWarner Losh pass1bcheck(struct inodesc *idesc)
938fae3551SRodney W. Grimes {
943d438ad6SDavid E. O'Brien struct dups *dlp;
958fae3551SRodney W. Grimes int nfrags, res = KEEPON;
961c85e6a3SKirk McKusick ufs2_daddr_t blkno = idesc->id_blkno;
978fae3551SRodney W. Grimes
988fae3551SRodney W. Grimes for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
998fae3551SRodney W. Grimes if (chkrange(blkno, 1))
1008fae3551SRodney W. Grimes res = SKIP;
1018fae3551SRodney W. Grimes for (dlp = duphead; dlp; dlp = dlp->next) {
1028fae3551SRodney W. Grimes if (dlp->dup == blkno) {
1038fae3551SRodney W. Grimes blkerror(idesc->id_number, "DUP", blkno);
1048fae3551SRodney W. Grimes dlp->dup = duphead->dup;
1058fae3551SRodney W. Grimes duphead->dup = blkno;
1068fae3551SRodney W. Grimes duphead = duphead->next;
1078fae3551SRodney W. Grimes }
1088fae3551SRodney W. Grimes if (dlp == muldup)
1098fae3551SRodney W. Grimes break;
1108fae3551SRodney W. Grimes }
1117d5e6562SPedro F. Giffuni if (muldup == NULL || duphead == muldup->next) {
1127703a6ffSScott Long rerun = 1;
1138fae3551SRodney W. Grimes return (STOP);
1148fae3551SRodney W. Grimes }
1157703a6ffSScott Long }
1168fae3551SRodney W. Grimes return (res);
1178fae3551SRodney W. Grimes }
118