1*f298a94bSchs /* $NetBSD: pass1b.c,v 1.24 2023/01/07 19:41:29 chs Exp $ */
20114e805Scgd
361f28255Scgd /*
4ccfa3742Smycroft * Copyright (c) 1980, 1986, 1993
5ccfa3742Smycroft * The Regents of the University of California. All rights reserved.
661f28255Scgd *
761f28255Scgd * Redistribution and use in source and binary forms, with or without
861f28255Scgd * modification, are permitted provided that the following conditions
961f28255Scgd * are met:
1061f28255Scgd * 1. Redistributions of source code must retain the above copyright
1161f28255Scgd * notice, this list of conditions and the following disclaimer.
1261f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright
1361f28255Scgd * notice, this list of conditions and the following disclaimer in the
1461f28255Scgd * documentation and/or other materials provided with the distribution.
15bf07c871Sagc * 3. Neither the name of the University nor the names of its contributors
1661f28255Scgd * may be used to endorse or promote products derived from this software
1761f28255Scgd * without specific prior written permission.
1861f28255Scgd *
1961f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2061f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2161f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2261f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2361f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2461f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2561f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2661f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2761f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2861f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2961f28255Scgd * SUCH DAMAGE.
3061f28255Scgd */
3161f28255Scgd
32b1db0383Slukem #include <sys/cdefs.h>
3361f28255Scgd #ifndef lint
340114e805Scgd #if 0
35e1111111Slukem static char sccsid[] = "@(#)pass1b.c 8.4 (Berkeley) 4/28/95";
360114e805Scgd #else
37*f298a94bSchs __RCSID("$NetBSD: pass1b.c,v 1.24 2023/01/07 19:41:29 chs Exp $");
380114e805Scgd #endif
3961f28255Scgd #endif /* not lint */
4061f28255Scgd
4161f28255Scgd #include <sys/param.h>
429a2c8849Scgd #include <sys/time.h>
43e1111111Slukem
44ccfa3742Smycroft #include <ufs/ufs/dinode.h>
45ccfa3742Smycroft #include <ufs/ffs/fs.h>
465eeab43eScgd
4761f28255Scgd #include <string.h>
48e1111111Slukem
4961f28255Scgd #include "fsck.h"
505eeab43eScgd #include "extern.h"
51bb82a84dSlukem #include "fsutil.h"
5261f28255Scgd
5361f28255Scgd static struct dups *duphead;
5452781d18Sxtraeme static int pass1bcheck(struct inodesc *);
5561f28255Scgd
565eeab43eScgd void
pass1b(void)5752781d18Sxtraeme pass1b(void)
5861f28255Scgd {
59*f298a94bSchs uint32_t c, i;
6042614ed3Sfvdl union dinode *dp;
6161f28255Scgd struct inodesc idesc;
6261f28255Scgd ino_t inumber;
6361f28255Scgd
64ea7b5d4eSmycroft memset(&idesc, 0, sizeof(struct inodesc));
6561f28255Scgd idesc.id_type = ADDR;
6661f28255Scgd idesc.id_func = pass1bcheck;
6761f28255Scgd duphead = duplist;
6861f28255Scgd inumber = 0;
699aaa32d9Sbouyer for (c = 0; c < sblock->fs_ncg; c++) {
70bb82a84dSlukem if (got_siginfo) {
71bb82a84dSlukem fprintf(stderr,
72bb82a84dSlukem "%s: phase 1b: cyl group %d of %d (%d%%)\n",
73bb82a84dSlukem cdevname(), c, sblock->fs_ncg,
74bb82a84dSlukem c * 100 / sblock->fs_ncg);
75bb82a84dSlukem got_siginfo = 0;
76bb82a84dSlukem }
77d90f13b3Schristos #ifdef PROGRESS
78a73c2bd5Schristos progress_bar(cdevname(), "phase 1b", c, sblock->fs_ncg);
79d90f13b3Schristos #endif /* PROGRESS */
809aaa32d9Sbouyer for (i = 0; i < sblock->fs_ipg; i++, inumber++) {
81dcd34a91Sdholland if (inumber < UFS_ROOTINO)
8261f28255Scgd continue;
8361f28255Scgd dp = ginode(inumber);
8461f28255Scgd if (dp == NULL)
8561f28255Scgd continue;
8661f28255Scgd idesc.id_number = inumber;
87063f96f3Sbouyer idesc.id_uid = iswap32(DIP(dp, uid));
88063f96f3Sbouyer idesc.id_gid = iswap32(DIP(dp, gid));
8942614ed3Sfvdl if (inoinfo(inumber)->ino_state != USTATE &&
9061f28255Scgd (ckinode(dp, &idesc) & STOP))
9161f28255Scgd return;
9261f28255Scgd }
9361f28255Scgd }
94d90f13b3Schristos #ifdef PROGRESS
95a73c2bd5Schristos progress_done();
96d90f13b3Schristos #endif /* PROGRESS */
9761f28255Scgd }
9861f28255Scgd
995528d374Schristos static int
pass1bcheck(struct inodesc * idesc)10052781d18Sxtraeme pass1bcheck(struct inodesc *idesc)
10161f28255Scgd {
102b1db0383Slukem struct dups *dlp;
10361f28255Scgd int nfrags, res = KEEPON;
104a3ff3a30Sfvdl daddr_t blkno = idesc->id_blkno;
10561f28255Scgd
10661f28255Scgd for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
10761f28255Scgd if (chkrange(blkno, 1))
10861f28255Scgd res = SKIP;
10961f28255Scgd for (dlp = duphead; dlp; dlp = dlp->next) {
11061f28255Scgd if (dlp->dup == blkno) {
11161f28255Scgd blkerror(idesc->id_number, "DUP", blkno);
11261f28255Scgd dlp->dup = duphead->dup;
11361f28255Scgd duphead->dup = blkno;
11461f28255Scgd duphead = duphead->next;
11561f28255Scgd }
11661f28255Scgd if (dlp == muldup)
11761f28255Scgd break;
11861f28255Scgd }
11961f28255Scgd if (muldup == 0 || duphead == muldup->next)
12061f28255Scgd return (STOP);
12161f28255Scgd }
12261f28255Scgd return (res);
12361f28255Scgd }
124