/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1980, 1986, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <sys/param.h>3233#include <ufs/ufs/dinode.h>34#include <ufs/ffs/fs.h>3536#include <string.h>3738#include "fsck.h"3940static struct dups *duphead;41static int pass1bcheck(struct inodesc *);4243void44pass1b(void)45{46int c, i;47union dinode *dp;48struct inodesc idesc;49ino_t inumber, inosused;5051memset(&idesc, 0, sizeof(struct inodesc));52idesc.id_func = pass1bcheck;53duphead = duplist;54for (c = 0; c < sblock.fs_ncg; c++) {55if (got_siginfo) {56printf("%s: phase 1b: cyl group %d of %d (%d%%)\n",57cdevname, c, sblock.fs_ncg,58c * 100 / sblock.fs_ncg);59got_siginfo = 0;60}61if (got_sigalarm) {62setproctitle("%s p1b %d%%", cdevname,63c * 100 / sblock.fs_ncg);64got_sigalarm = 0;65}66inosused = inostathead[c].il_numalloced;67if (inosused == 0)68continue;69setinodebuf(c, inosused);70inumber = c * sblock.fs_ipg;71for (i = 0; i < inosused; i++, inumber++) {72if (inumber < UFS_ROOTINO) {73(void)getnextinode(inumber, 0);74continue;75}76dp = getnextinode(inumber, 0);77idesc.id_number = inumber;78idesc.id_type = inoinfo(inumber)->ino_idtype;79if (inoinfo(inumber)->ino_state != USTATE &&80(ckinode(dp, &idesc) & STOP)) {81rerun = 1;82freeinodebuf();83return;84}85}86}87freeinodebuf();88}8990static int91pass1bcheck(struct inodesc *idesc)92{93struct dups *dlp;94int nfrags, res = KEEPON;95ufs2_daddr_t blkno = idesc->id_blkno;9697for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {98if (chkrange(blkno, 1))99res = SKIP;100for (dlp = duphead; dlp; dlp = dlp->next) {101if (dlp->dup == blkno) {102blkerror(idesc->id_number, "DUP", blkno);103dlp->dup = duphead->dup;104duphead->dup = blkno;105duphead = duphead->next;106}107if (dlp == muldup)108break;109}110if (muldup == NULL || duphead == muldup->next) {111rerun = 1;112return (STOP);113}114}115return (res);116}117118119