Home | History | Annotate | Line # | Download | only in fsck_ffs
pass1.c revision 1.28
      1  1.28        he /*	$NetBSD: pass1.c,v 1.28 2003/04/02 22:27:09 he Exp $	*/
      2  1.13       cgd 
      3   1.1       cgd /*
      4   1.7   mycroft  * Copyright (c) 1980, 1986, 1993
      5   1.7   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  */
     35   1.1       cgd 
     36  1.17     lukem #include <sys/cdefs.h>
     37   1.1       cgd #ifndef lint
     38  1.13       cgd #if 0
     39  1.19     lukem static char sccsid[] = "@(#)pass1.c	8.6 (Berkeley) 4/28/95";
     40  1.13       cgd #else
     41  1.28        he __RCSID("$NetBSD: pass1.c,v 1.28 2003/04/02 22:27:09 he Exp $");
     42  1.13       cgd #endif
     43   1.1       cgd #endif /* not lint */
     44   1.1       cgd 
     45   1.1       cgd #include <sys/param.h>
     46   1.6       cgd #include <sys/time.h>
     47  1.19     lukem 
     48   1.7   mycroft #include <ufs/ufs/dinode.h>
     49   1.7   mycroft #include <ufs/ufs/dir.h>
     50   1.7   mycroft #include <ufs/ffs/fs.h>
     51  1.27      fvdl #include <ufs/ufs/ufs_bswap.h>
     52  1.27      fvdl #include <ufs/ffs/ffs_extern.h>
     53  1.12       cgd 
     54  1.19     lukem #include <err.h>
     55  1.20     lukem #include <stdio.h>
     56  1.20     lukem #include <stdlib.h>
     57   1.1       cgd #include <string.h>
     58  1.12       cgd 
     59   1.1       cgd #include "fsck.h"
     60  1.12       cgd #include "extern.h"
     61  1.16  christos #include "fsutil.h"
     62   1.1       cgd 
     63  1.26      fvdl static daddr_t badblk;
     64  1.26      fvdl static daddr_t dupblk;
     65  1.15  christos static void checkinode __P((ino_t, struct inodesc *));
     66  1.27      fvdl static ino_t lastino;
     67   1.1       cgd 
     68  1.12       cgd void
     69   1.1       cgd pass1()
     70   1.1       cgd {
     71  1.27      fvdl 	ino_t inumber, inosused;
     72  1.27      fvdl 	int c;
     73  1.27      fvdl 	daddr_t i, cgd;
     74   1.1       cgd 	struct inodesc idesc;
     75  1.27      fvdl 	struct cg *cgp = cgrp;
     76  1.27      fvdl 	struct inostat *info;
     77  1.27      fvdl 	uint8_t *cp;
     78   1.1       cgd 
     79   1.1       cgd 	/*
     80   1.1       cgd 	 * Set file system reserved blocks in used block map.
     81   1.1       cgd 	 */
     82  1.21    bouyer 	for (c = 0; c < sblock->fs_ncg; c++) {
     83  1.21    bouyer 		cgd = cgdmin(sblock, c);
     84  1.14   mycroft 		if (c == 0)
     85  1.21    bouyer 			i = cgbase(sblock, c);
     86  1.14   mycroft 		else
     87  1.21    bouyer 			i = cgsblock(sblock, c);
     88   1.1       cgd 		for (; i < cgd; i++)
     89   1.1       cgd 			setbmap(i);
     90   1.1       cgd 	}
     91  1.21    bouyer 	i = sblock->fs_csaddr;
     92  1.21    bouyer 	cgd = i + howmany(sblock->fs_cssize, sblock->fs_fsize);
     93  1.14   mycroft 	for (; i < cgd; i++)
     94  1.14   mycroft 		setbmap(i);
     95   1.1       cgd 	/*
     96   1.1       cgd 	 * Find all allocated blocks.
     97   1.1       cgd 	 */
     98  1.10   mycroft 	memset(&idesc, 0, sizeof(struct inodesc));
     99   1.1       cgd 	idesc.id_type = ADDR;
    100   1.1       cgd 	idesc.id_func = pass1check;
    101   1.1       cgd 	n_files = n_blks = 0;
    102  1.21    bouyer 	for (c = 0; c < sblock->fs_ncg; c++) {
    103  1.27      fvdl 		inumber = c * sblock->fs_ipg;
    104  1.27      fvdl 		setinodebuf(inumber);
    105  1.27      fvdl 		getblk(&cgblk, cgtod(sblock, c), sblock->fs_cgsize);
    106  1.27      fvdl 		memcpy(cgp, cgblk.b_un.b_cg, sblock->fs_cgsize);
    107  1.27      fvdl 		if((doswap && !needswap) || (!doswap && needswap))
    108  1.27      fvdl 			ffs_cg_swap(cgblk.b_un.b_cg, cgp, sblock);
    109  1.27      fvdl 		if (is_ufs2)
    110  1.27      fvdl 			inosused = cgp->cg_initediblk;
    111  1.27      fvdl 		else
    112  1.27      fvdl 			inosused = sblock->fs_ipg;
    113  1.24     lukem 		if (got_siginfo) {
    114  1.27      fvdl 			printf("%s: phase 1: cyl group %d of %d (%d%%)\n",
    115  1.24     lukem 			    cdevname(), c, sblock->fs_ncg,
    116  1.24     lukem 			    c * 100 / sblock->fs_ncg);
    117  1.24     lukem 			got_siginfo = 0;
    118  1.24     lukem 		}
    119  1.27      fvdl 		/*
    120  1.27      fvdl 		 * If we are using soft updates, then we can trust the
    121  1.27      fvdl 		 * cylinder group inode allocation maps to tell us which
    122  1.27      fvdl 		 * inodes are allocated. We will scan the used inode map
    123  1.27      fvdl 		 * to find the inodes that are really in use, and then
    124  1.27      fvdl 		 * read only those inodes in from disk.
    125  1.27      fvdl 		 */
    126  1.27      fvdl 		if (preen && usedsoftdep) {
    127  1.27      fvdl 			if (!cg_chkmagic(cgp, 0))
    128  1.27      fvdl 				pfatal("CG %d: BAD MAGIC NUMBER\n", c);
    129  1.27      fvdl 			cp = &cg_inosused(cgp, 0)[(inosused - 1) / CHAR_BIT];
    130  1.27      fvdl 			for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
    131  1.27      fvdl 				if (*cp == 0)
    132  1.27      fvdl 					continue;
    133  1.27      fvdl 				for (i = 1 << (CHAR_BIT - 1); i > 0; i >>= 1) {
    134  1.27      fvdl 					if (*cp & i)
    135  1.27      fvdl 						break;
    136  1.27      fvdl 					inosused--;
    137  1.27      fvdl 				}
    138  1.27      fvdl 				break;
    139  1.27      fvdl 			}
    140  1.27      fvdl 			if (inosused < 0)
    141  1.27      fvdl 				inosused = 0;
    142  1.27      fvdl 		}
    143  1.27      fvdl 		/*
    144  1.27      fvdl 		 * Allocate inoinfo structures for the allocated inodes.
    145  1.27      fvdl 		 */
    146  1.27      fvdl 		inostathead[c].il_numalloced = inosused;
    147  1.27      fvdl 		if (inosused == 0) {
    148  1.27      fvdl 			inostathead[c].il_stat = 0;
    149  1.27      fvdl 			continue;
    150  1.27      fvdl 		}
    151  1.27      fvdl 		info = calloc((unsigned)inosused, sizeof(struct inostat));
    152  1.27      fvdl 		if (info == NULL) {
    153  1.27      fvdl 			pfatal("cannot alloc %u bytes for inoinfo\n",
    154  1.27      fvdl 			    (unsigned)(sizeof(struct inostat) * inosused));
    155  1.27      fvdl 			abort();
    156  1.27      fvdl 		}
    157  1.27      fvdl 		inostathead[c].il_stat = info;
    158  1.27      fvdl 		/*
    159  1.27      fvdl 		 * Scan the allocated inodes.
    160  1.27      fvdl 		 */
    161  1.27      fvdl 		for (i = 0; i < inosused; i++, inumber++) {
    162  1.27      fvdl 			if (inumber < ROOTINO) {
    163  1.27      fvdl 				(void)getnextinode(inumber);
    164   1.1       cgd 				continue;
    165  1.27      fvdl 			}
    166   1.7   mycroft 			checkinode(inumber, &idesc);
    167   1.7   mycroft 		}
    168  1.27      fvdl 		lastino += 1;
    169  1.27      fvdl 		if (inosused < sblock->fs_ipg || inumber == lastino)
    170  1.27      fvdl 			continue;
    171  1.27      fvdl 		/*
    172  1.27      fvdl 		 * If we were not able to determine in advance which inodes
    173  1.27      fvdl 		 * were in use, then reduce the size of the inoinfo structure
    174  1.27      fvdl 		 * to the size necessary to describe the inodes that we
    175  1.27      fvdl 		 * really found.
    176  1.27      fvdl 		 */
    177  1.27      fvdl 		if (lastino < (c * sblock->fs_ipg))
    178  1.27      fvdl 			inosused = 0;
    179  1.27      fvdl 		else
    180  1.27      fvdl 			inosused = lastino - (c * sblock->fs_ipg);
    181  1.27      fvdl 		inostathead[c].il_numalloced = inosused;
    182  1.27      fvdl 		if (inosused == 0) {
    183  1.27      fvdl 			free(inostathead[c].il_stat);
    184  1.27      fvdl 			inostathead[c].il_stat = 0;
    185  1.27      fvdl 			continue;
    186  1.27      fvdl 		}
    187  1.27      fvdl 		info = calloc((unsigned)inosused, sizeof(struct inostat));
    188  1.27      fvdl 		if (info == NULL) {
    189  1.27      fvdl 			pfatal("cannot alloc %u bytes for inoinfo\n",
    190  1.27      fvdl 			    (unsigned)(sizeof(struct inostat) * inosused));
    191  1.27      fvdl 			abort();
    192  1.27      fvdl 		}
    193  1.27      fvdl 		memmove(info, inostathead[c].il_stat, inosused * sizeof(*info));
    194  1.27      fvdl 		free(inostathead[c].il_stat);
    195  1.27      fvdl 		inostathead[c].il_stat = info;
    196   1.7   mycroft 	}
    197   1.7   mycroft 	freeinodebuf();
    198  1.21    bouyer 	do_blkswap = 0; /* has been done */
    199   1.7   mycroft }
    200   1.7   mycroft 
    201  1.15  christos static void
    202   1.7   mycroft checkinode(inumber, idesc)
    203   1.7   mycroft 	ino_t inumber;
    204  1.17     lukem 	struct inodesc *idesc;
    205   1.7   mycroft {
    206  1.27      fvdl 	union dinode *dp;
    207   1.7   mycroft 	struct zlncnt *zlnp;
    208  1.27      fvdl 	daddr_t ndb;
    209  1.27      fvdl 	int j;
    210   1.7   mycroft 	mode_t mode;
    211  1.27      fvdl 	u_int64_t size, kernmaxfilesize;
    212  1.27      fvdl 	int64_t blocks;
    213  1.27      fvdl 	char symbuf[MAXSYMLINKLEN_UFS1];
    214  1.27      fvdl 	struct inostat *info;
    215   1.7   mycroft 
    216   1.7   mycroft 	dp = getnextinode(inumber);
    217  1.27      fvdl 	info = inoinfo(inumber);
    218  1.27      fvdl 	mode = iswap16(DIP(dp, mode)) & IFMT;
    219  1.27      fvdl 	size = iswap64(DIP(dp, size));
    220   1.7   mycroft 	if (mode == 0) {
    221  1.27      fvdl 		if ((is_ufs2 &&
    222  1.27      fvdl 		    (memcmp(dp->dp2.di_db, ufs2_zino.di_db,
    223  1.27      fvdl 			NDADDR * sizeof(int64_t)) ||
    224  1.27      fvdl 		    memcmp(dp->dp2.di_ib, ufs2_zino.di_ib,
    225  1.27      fvdl 			NIADDR * sizeof(int64_t))))
    226  1.27      fvdl 		    ||
    227  1.27      fvdl 		    (!is_ufs2 &&
    228  1.27      fvdl 		    (memcmp(dp->dp1.di_db, ufs1_zino.di_db,
    229  1.26      fvdl 			NDADDR * sizeof(int32_t)) ||
    230  1.27      fvdl 		    memcmp(dp->dp1.di_ib, ufs1_zino.di_ib,
    231  1.27      fvdl 			NIADDR * sizeof(int32_t)))) ||
    232  1.27      fvdl 		    mode || size) {
    233  1.15  christos 			pfatal("PARTIALLY ALLOCATED INODE I=%u", inumber);
    234   1.1       cgd 			if (reply("CLEAR") == 1) {
    235   1.1       cgd 				dp = ginode(inumber);
    236   1.1       cgd 				clearinode(dp);
    237   1.1       cgd 				inodirty();
    238  1.21    bouyer 			} else
    239  1.21    bouyer 				markclean = 0;
    240   1.1       cgd 		}
    241  1.27      fvdl 		info->ino_state = USTATE;
    242   1.7   mycroft 		return;
    243   1.7   mycroft 	}
    244   1.7   mycroft 	lastino = inumber;
    245  1.27      fvdl 	/* This should match the file size limit in ffs_mountfs(). */
    246  1.27      fvdl 	if (is_ufs2)
    247  1.27      fvdl 		kernmaxfilesize = sblock->fs_maxfilesize;
    248  1.27      fvdl 	else
    249  1.27      fvdl 		kernmaxfilesize = (u_int64_t)0x80000000 * sblock->fs_bsize - 1;
    250  1.27      fvdl 	if (size > kernmaxfilesize  || size + sblock->fs_bsize - 1 < size ||
    251  1.21    bouyer 	    (mode == IFDIR && size > MAXDIRSIZE)) {
    252   1.7   mycroft 		if (debug)
    253  1.23     lukem 			printf("bad size %llu:",(unsigned long long)size);
    254   1.7   mycroft 		goto unknown;
    255   1.7   mycroft 	}
    256   1.7   mycroft 	if (!preen && mode == IFMT && reply("HOLD BAD BLOCK") == 1) {
    257   1.7   mycroft 		dp = ginode(inumber);
    258  1.27      fvdl 		DIP(dp, size) = iswap64(sblock->fs_fsize);
    259  1.21    bouyer 		size = sblock->fs_fsize;
    260  1.27      fvdl 		DIP(dp, mode) = iswap16(IFREG|0600);
    261   1.7   mycroft 		inodirty();
    262   1.7   mycroft 	}
    263  1.21    bouyer 	ndb = howmany(size, sblock->fs_bsize);
    264   1.7   mycroft 	if (ndb < 0) {
    265   1.7   mycroft 		if (debug)
    266  1.27      fvdl 			printf("bad size %llu ndb %lld:",
    267  1.27      fvdl 				(unsigned long long)size, (long long)ndb);
    268   1.7   mycroft 		goto unknown;
    269   1.7   mycroft 	}
    270   1.7   mycroft 	if (mode == IFBLK || mode == IFCHR)
    271   1.7   mycroft 		ndb++;
    272   1.7   mycroft 	if (mode == IFLNK) {
    273   1.7   mycroft 		/*
    274   1.7   mycroft 		 * Note that the old fastlink format always had di_blocks set
    275   1.7   mycroft 		 * to 0.  Other than that we no longer use the `spare' field
    276   1.7   mycroft 		 * (which is now the extended uid) for sanity checking, the
    277   1.7   mycroft 		 * new format is the same as the old.  We simply ignore the
    278   1.7   mycroft 		 * conversion altogether.  - mycroft, 19MAY1994
    279   1.7   mycroft 		 */
    280  1.27      fvdl 		if (!is_ufs2 && doinglevel2 &&
    281  1.27      fvdl 		    size > 0 && size < MAXSYMLINKLEN_UFS1 &&
    282  1.27      fvdl 		    DIP(dp, blocks) != 0) {
    283   1.7   mycroft 			if (bread(fsreadfd, symbuf,
    284  1.27      fvdl 			    fsbtodb(sblock, iswap32(DIP(dp, db[0]))),
    285   1.9        ws 			    (long)secsize) != 0)
    286  1.19     lukem 				errx(EEXIT, "cannot read symlink");
    287   1.7   mycroft 			if (debug) {
    288  1.21    bouyer 				symbuf[size] = 0;
    289  1.23     lukem 				printf("convert symlink %u(%s) of size %lld\n",
    290  1.18       mrg 				    inumber, symbuf,
    291  1.21    bouyer 				    (unsigned long long)size);
    292   1.7   mycroft 			}
    293   1.7   mycroft 			dp = ginode(inumber);
    294  1.27      fvdl 			memmove(dp->dp1.di_db, symbuf, (long)size);
    295  1.27      fvdl 			DIP(dp, blocks) = 0;
    296   1.7   mycroft 			inodirty();
    297   1.7   mycroft 		}
    298   1.7   mycroft 		/*
    299   1.7   mycroft 		 * Fake ndb value so direct/indirect block checks below
    300   1.7   mycroft 		 * will detect any garbage after symlink string.
    301   1.7   mycroft 		 */
    302  1.21    bouyer 		if (size < sblock->fs_maxsymlinklen ||
    303  1.25       dbj 		    (isappleufs && (size < APPLEUFS_MAXSYMLINKLEN)) ||
    304  1.27      fvdl 		    (sblock->fs_maxsymlinklen == 0 && DIP(dp, blocks) == 0)) {
    305  1.27      fvdl 			if (is_ufs2)
    306  1.27      fvdl 				ndb = howmany(size, sizeof(int64_t));
    307  1.27      fvdl 			else
    308  1.27      fvdl 				ndb = howmany(size, sizeof(int32_t));
    309   1.7   mycroft 			if (ndb > NDADDR) {
    310   1.7   mycroft 				j = ndb - NDADDR;
    311   1.7   mycroft 				for (ndb = 1; j > 1; j--)
    312  1.21    bouyer 					ndb *= NINDIR(sblock);
    313   1.7   mycroft 				ndb += NDADDR;
    314   1.7   mycroft 			}
    315   1.7   mycroft 		}
    316   1.7   mycroft 	}
    317   1.7   mycroft 	for (j = ndb; j < NDADDR; j++)
    318  1.27      fvdl 		if (DIP(dp, db[j]) != 0) {
    319  1.27      fvdl 		    if (debug) {
    320  1.27      fvdl 			if (!is_ufs2)
    321  1.27      fvdl 			    printf("bad direct addr ix %d: %d [ndb %lld]\n",
    322  1.27      fvdl 				j, iswap32(dp->dp1.di_db[j]),
    323  1.27      fvdl 				(long long)ndb);
    324  1.27      fvdl 			else
    325  1.27      fvdl 			    printf("bad direct addr ix %d: %lld [ndb %lld]\n",
    326  1.28        he 				j, (long long)iswap64(dp->dp2.di_db[j]),
    327  1.27      fvdl 				(long long)ndb);
    328  1.27      fvdl 		    }
    329  1.27      fvdl 		    goto unknown;
    330   1.7   mycroft 		}
    331  1.27      fvdl 
    332   1.7   mycroft 	for (j = 0, ndb -= NDADDR; ndb > 0; j++)
    333  1.21    bouyer 		ndb /= NINDIR(sblock);
    334  1.27      fvdl 
    335   1.7   mycroft 	for (; j < NIADDR; j++)
    336  1.27      fvdl 		if (DIP(dp, ib[j]) != 0) {
    337  1.27      fvdl 		    if (debug) {
    338  1.27      fvdl 			if (!is_ufs2)
    339  1.27      fvdl 			    printf("bad indirect addr: %d\n",
    340  1.27      fvdl 				iswap32(dp->dp1.di_ib[j]));
    341  1.27      fvdl 			else
    342  1.27      fvdl 			    printf("bad indirect addr: %lld\n",
    343  1.27      fvdl 				(long long)iswap64(dp->dp2.di_ib[j]));
    344  1.27      fvdl 		    }
    345  1.27      fvdl 		    goto unknown;
    346   1.7   mycroft 		}
    347   1.7   mycroft 	if (ftypeok(dp) == 0)
    348   1.7   mycroft 		goto unknown;
    349   1.7   mycroft 	n_files++;
    350  1.27      fvdl 	info->ino_linkcnt = iswap16(DIP(dp, nlink));
    351  1.27      fvdl 	if (info->ino_linkcnt <= 0) {
    352   1.7   mycroft 		zlnp = (struct zlncnt *)malloc(sizeof *zlnp);
    353   1.7   mycroft 		if (zlnp == NULL) {
    354  1.21    bouyer 			markclean = 0;
    355   1.7   mycroft 			pfatal("LINK COUNT TABLE OVERFLOW");
    356  1.22      fvdl 			if (reply("CONTINUE") == 0) {
    357  1.22      fvdl 				ckfini();
    358  1.19     lukem 				exit(EEXIT);
    359  1.22      fvdl 			}
    360   1.7   mycroft 		} else {
    361   1.7   mycroft 			zlnp->zlncnt = inumber;
    362   1.7   mycroft 			zlnp->next = zlnhead;
    363   1.7   mycroft 			zlnhead = zlnp;
    364   1.7   mycroft 		}
    365   1.7   mycroft 	}
    366   1.7   mycroft 	if (mode == IFDIR) {
    367  1.21    bouyer 		if (size == 0)
    368  1.27      fvdl 			info->ino_state = DCLEAR;
    369   1.7   mycroft 		else
    370  1.27      fvdl 			info->ino_state = DSTATE;
    371   1.7   mycroft 		cacheino(dp, inumber);
    372  1.27      fvdl 		countdirs++;
    373   1.7   mycroft 	} else
    374  1.27      fvdl 		info->ino_state = FSTATE;
    375  1.27      fvdl 	info->ino_type = IFTODT(mode);
    376  1.27      fvdl 	if (!is_ufs2 && doinglevel2 &&
    377  1.27      fvdl 	    (iswap16(dp->dp1.di_ouid) != (u_short)-1 ||
    378  1.27      fvdl 		iswap16(dp->dp1.di_ogid) != (u_short)-1)) {
    379   1.7   mycroft 		dp = ginode(inumber);
    380  1.27      fvdl 		dp->dp1.di_uid = iswap32(iswap16(dp->dp1.di_ouid));
    381  1.27      fvdl 		dp->dp1.di_ouid = iswap16(-1);
    382  1.27      fvdl 		dp->dp1.di_gid = iswap32(iswap16(dp->dp1.di_ogid));
    383  1.27      fvdl 		dp->dp1.di_ogid = iswap16(-1);
    384   1.7   mycroft 		inodirty();
    385   1.7   mycroft 	}
    386   1.7   mycroft 	badblk = dupblk = 0;
    387   1.7   mycroft 	idesc->id_number = inumber;
    388   1.7   mycroft 	(void)ckinode(dp, idesc);
    389  1.21    bouyer 	idesc->id_entryno *= btodb(sblock->fs_fsize);
    390  1.27      fvdl 	if (is_ufs2)
    391  1.27      fvdl 		blocks = iswap64(dp->dp2.di_blocks);
    392  1.27      fvdl 	else
    393  1.27      fvdl 		blocks = iswap32(dp->dp1.di_blocks);
    394  1.27      fvdl 	if (blocks != idesc->id_entryno) {
    395  1.27      fvdl 		pwarn("INCORRECT BLOCK COUNT I=%u (%lld should be %lld)",
    396  1.27      fvdl 		    inumber, (long long)blocks, (long long)idesc->id_entryno);
    397   1.7   mycroft 		if (preen)
    398   1.7   mycroft 			printf(" (CORRECTED)\n");
    399  1.21    bouyer 		else if (reply("CORRECT") == 0) {
    400  1.21    bouyer 			markclean = 0;
    401   1.7   mycroft 			return;
    402  1.21    bouyer 		}
    403   1.7   mycroft 		dp = ginode(inumber);
    404  1.27      fvdl 		if (is_ufs2)
    405  1.27      fvdl 			dp->dp2.di_blocks = iswap64(idesc->id_entryno);
    406  1.27      fvdl 		else
    407  1.27      fvdl 			dp->dp1.di_blocks = iswap32((int32_t)idesc->id_entryno);
    408   1.7   mycroft 		inodirty();
    409   1.7   mycroft 	}
    410   1.7   mycroft 	return;
    411   1.7   mycroft unknown:
    412  1.15  christos 	pfatal("UNKNOWN FILE TYPE I=%u", inumber);
    413  1.27      fvdl 	info->ino_state = FCLEAR;
    414   1.7   mycroft 	if (reply("CLEAR") == 1) {
    415  1.27      fvdl 		info->ino_state = USTATE;
    416   1.7   mycroft 		dp = ginode(inumber);
    417   1.7   mycroft 		clearinode(dp);
    418   1.7   mycroft 		inodirty();
    419  1.21    bouyer 	} else
    420  1.21    bouyer 		markclean = 0;
    421   1.1       cgd }
    422   1.1       cgd 
    423  1.12       cgd int
    424   1.1       cgd pass1check(idesc)
    425  1.17     lukem 	struct inodesc *idesc;
    426   1.1       cgd {
    427   1.1       cgd 	int res = KEEPON;
    428   1.1       cgd 	int anyout, nfrags;
    429  1.26      fvdl 	daddr_t blkno = idesc->id_blkno;
    430  1.17     lukem 	struct dups *dlp;
    431   1.1       cgd 	struct dups *new;
    432   1.1       cgd 
    433   1.1       cgd 	if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
    434   1.1       cgd 		blkerror(idesc->id_number, "BAD", blkno);
    435   1.1       cgd 		if (badblk++ >= MAXBAD) {
    436  1.15  christos 			pwarn("EXCESSIVE BAD BLKS I=%u",
    437   1.1       cgd 				idesc->id_number);
    438   1.1       cgd 			if (preen)
    439   1.1       cgd 				printf(" (SKIPPING)\n");
    440  1.22      fvdl 			else if (reply("CONTINUE") == 0) {
    441  1.22      fvdl 				markclean = 0;
    442  1.22      fvdl 				ckfini();
    443  1.19     lukem 				exit(EEXIT);
    444  1.22      fvdl 			}
    445   1.1       cgd 			return (STOP);
    446   1.1       cgd 		}
    447   1.1       cgd 	}
    448   1.1       cgd 	for (nfrags = idesc->id_numfrags; nfrags > 0; blkno++, nfrags--) {
    449   1.1       cgd 		if (anyout && chkrange(blkno, 1)) {
    450   1.1       cgd 			res = SKIP;
    451   1.1       cgd 		} else if (!testbmap(blkno)) {
    452   1.1       cgd 			n_blks++;
    453   1.1       cgd 			setbmap(blkno);
    454   1.1       cgd 		} else {
    455   1.1       cgd 			blkerror(idesc->id_number, "DUP", blkno);
    456   1.1       cgd 			if (dupblk++ >= MAXDUP) {
    457  1.15  christos 				pwarn("EXCESSIVE DUP BLKS I=%u",
    458   1.1       cgd 					idesc->id_number);
    459   1.1       cgd 				if (preen)
    460   1.1       cgd 					printf(" (SKIPPING)\n");
    461  1.22      fvdl 				else if (reply("CONTINUE") == 0) {
    462  1.22      fvdl 					markclean = 0;
    463  1.22      fvdl 					ckfini();
    464  1.19     lukem 					exit(EEXIT);
    465  1.22      fvdl 				}
    466   1.1       cgd 				return (STOP);
    467   1.1       cgd 			}
    468   1.1       cgd 			new = (struct dups *)malloc(sizeof(struct dups));
    469   1.1       cgd 			if (new == NULL) {
    470  1.21    bouyer 				markclean = 0;
    471   1.1       cgd 				pfatal("DUP TABLE OVERFLOW.");
    472  1.22      fvdl 				if (reply("CONTINUE") == 0) {
    473  1.22      fvdl 					markclean = 0;
    474  1.22      fvdl 					ckfini();
    475  1.19     lukem 					exit(EEXIT);
    476  1.22      fvdl 				}
    477   1.1       cgd 				return (STOP);
    478   1.1       cgd 			}
    479   1.1       cgd 			new->dup = blkno;
    480   1.1       cgd 			if (muldup == 0) {
    481   1.1       cgd 				duplist = muldup = new;
    482   1.1       cgd 				new->next = 0;
    483   1.1       cgd 			} else {
    484   1.1       cgd 				new->next = muldup->next;
    485   1.1       cgd 				muldup->next = new;
    486   1.1       cgd 			}
    487   1.1       cgd 			for (dlp = duplist; dlp != muldup; dlp = dlp->next)
    488   1.1       cgd 				if (dlp->dup == blkno)
    489   1.1       cgd 					break;
    490   1.1       cgd 			if (dlp == muldup && dlp->dup != blkno)
    491   1.1       cgd 				muldup = new;
    492   1.1       cgd 		}
    493   1.1       cgd 		/*
    494   1.1       cgd 		 * count the number of blocks found in id_entryno
    495   1.1       cgd 		 */
    496   1.1       cgd 		idesc->id_entryno++;
    497   1.1       cgd 	}
    498   1.1       cgd 	return (res);
    499   1.1       cgd }
    500