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