Home | History | Annotate | Line # | Download | only in fsck_lfs
inode.c revision 1.11
      1  1.11  perseant /* $NetBSD: inode.c,v 1.11 2001/07/13 20:30:18 perseant Exp $	 */
      2   1.1  perseant 
      3   1.1  perseant /*
      4   1.1  perseant  * Copyright (c) 1997, 1998
      5   1.1  perseant  *      Konrad Schroder.  All rights reserved.
      6   1.1  perseant  * Copyright (c) 1980, 1986, 1993
      7   1.1  perseant  *	The Regents of the University of California.  All rights reserved.
      8   1.1  perseant  *
      9   1.1  perseant  * Redistribution and use in source and binary forms, with or without
     10   1.1  perseant  * modification, are permitted provided that the following conditions
     11   1.1  perseant  * are met:
     12   1.1  perseant  * 1. Redistributions of source code must retain the above copyright
     13   1.1  perseant  *    notice, this list of conditions and the following disclaimer.
     14   1.1  perseant  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1  perseant  *    notice, this list of conditions and the following disclaimer in the
     16   1.1  perseant  *    documentation and/or other materials provided with the distribution.
     17   1.1  perseant  * 3. All advertising materials mentioning features or use of this software
     18   1.1  perseant  *    must display the following acknowledgement:
     19   1.1  perseant  *	This product includes software developed by the University of
     20   1.1  perseant  *	California, Berkeley and its contributors.
     21   1.1  perseant  * 4. Neither the name of the University nor the names of its contributors
     22   1.1  perseant  *    may be used to endorse or promote products derived from this software
     23   1.1  perseant  *    without specific prior written permission.
     24   1.1  perseant  *
     25   1.1  perseant  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26   1.1  perseant  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27   1.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28   1.1  perseant  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29   1.1  perseant  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30   1.1  perseant  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31   1.1  perseant  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32   1.1  perseant  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33   1.1  perseant  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34   1.1  perseant  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35   1.1  perseant  * SUCH DAMAGE.
     36   1.1  perseant  */
     37   1.1  perseant 
     38   1.1  perseant #include <sys/param.h>
     39   1.1  perseant #include <sys/time.h>
     40   1.1  perseant #include <ufs/ufs/dinode.h>
     41   1.1  perseant #include <ufs/ufs/dir.h>
     42   1.6  perseant #include <sys/mount.h>		/* XXX */
     43   1.1  perseant #include <ufs/lfs/lfs.h>
     44   1.1  perseant #ifndef SMALL
     45   1.1  perseant #include <pwd.h>
     46   1.1  perseant #endif
     47   1.1  perseant #include <stdio.h>
     48   1.1  perseant #include <stdlib.h>
     49   1.1  perseant #include <string.h>
     50   1.1  perseant 
     51   1.1  perseant #include "fsck.h"
     52   1.1  perseant #include "fsutil.h"
     53   1.1  perseant #include "extern.h"
     54   1.1  perseant 
     55   1.6  perseant extern SEGUSE  *seg_table;
     56   1.5  perseant extern daddr_t *din_table;
     57   1.1  perseant 
     58   1.6  perseant static int      iblock(struct inodesc *, long, u_int64_t);
     59   1.6  perseant int             blksreqd(struct lfs *, int);
     60   1.6  perseant int             lfs_maxino(void);
     61   1.6  perseant /* static void dump_inoblk (struct lfs *, struct dinode *); */
     62   1.1  perseant 
     63   1.1  perseant /* stolen from lfs_inode.c */
     64   1.1  perseant /* Search a block for a specific dinode. */
     65   1.6  perseant struct dinode  *
     66   1.6  perseant lfs_difind(struct lfs * fs, ino_t ino, struct dinode * dip)
     67   1.1  perseant {
     68  1.11  perseant 	struct dinode *ldip, *fin;
     69   1.1  perseant 
     70  1.11  perseant #ifdef LFS_IFILE_FRAG_ADDRESSING
     71  1.11  perseant 	if (fs->lfs_version == 1)
     72  1.11  perseant 		fin = dip + INOPB(fs);
     73  1.11  perseant 	else
     74  1.11  perseant 		fin = dip + INOPF(fs);
     75  1.11  perseant #else
     76  1.11  perseant 	fin = dip + INOPB(fs);
     77  1.11  perseant #endif
     78  1.11  perseant 
     79  1.11  perseant 	for (ldip = dip; ldip < fin; ++ldip) {
     80  1.11  perseant 		if (ldip->di_inumber == ino)
     81  1.11  perseant 			return ldip;
     82  1.11  perseant 	}
     83   1.6  perseant 	/* printf("lfs_difind: dinode %u not found\n", ino); */
     84   1.6  perseant 	return NULL;
     85   1.1  perseant }
     86   1.1  perseant 
     87   1.1  perseant /*
     88   1.1  perseant  * Calculate the number of blocks required to be able to address data block
     89   1.1  perseant  * blkno (counting, of course, indirect blocks).  blkno must >=0.
     90   1.1  perseant  */
     91   1.6  perseant int
     92   1.6  perseant blksreqd(struct lfs * fs, int blkno)
     93   1.1  perseant {
     94   1.6  perseant 	long            n = blkno;
     95   1.1  perseant 
     96   1.6  perseant 	if (blkno < NDADDR)
     97   1.6  perseant 		return blkno;
     98   1.6  perseant 	n -= NDADDR;
     99   1.6  perseant 	if (n < NINDIR(fs))
    100   1.6  perseant 		return blkno + 1;
    101   1.6  perseant 	n -= NINDIR(fs);
    102   1.6  perseant 	if (n < NINDIR(fs) * NINDIR(fs))
    103   1.6  perseant 		return blkno + 2 + n / NINDIR(fs) + 1;
    104   1.6  perseant 	n -= NINDIR(fs) * NINDIR(fs);
    105   1.6  perseant 	return blkno + 2 + NINDIR(fs) + n / (NINDIR(fs) * NINDIR(fs)) + 1;
    106   1.1  perseant }
    107   1.1  perseant 
    108   1.1  perseant #define BASE_SINDIR (NDADDR)
    109   1.1  perseant #define BASE_DINDIR (NDADDR+NINDIR(fs))
    110   1.1  perseant #define BASE_TINDIR (NDADDR+NINDIR(fs)+NINDIR(fs)*NINDIR(fs))
    111   1.1  perseant 
    112   1.1  perseant #define D_UNITS (NINDIR(fs))
    113   1.1  perseant #define T_UNITS (NINDIR(fs)*NINDIR(fs))
    114   1.1  perseant 
    115   1.6  perseant ufs_daddr_t     lfs_bmap(struct lfs *, struct dinode *, ufs_daddr_t);
    116   1.1  perseant 
    117   1.6  perseant ufs_daddr_t
    118   1.6  perseant lfs_bmap(struct lfs * fs, struct dinode * idinode, ufs_daddr_t lbn)
    119   1.1  perseant {
    120   1.6  perseant 	ufs_daddr_t     residue, up, off = 0;
    121   1.1  perseant 	struct bufarea *bp;
    122   1.6  perseant 
    123   1.6  perseant 	if (lbn > 0 && lbn > (idinode->di_size - 1) / dev_bsize) {
    124   1.1  perseant 		return UNASSIGNED;
    125   1.1  perseant 	}
    126   1.1  perseant 	/*
    127   1.1  perseant 	 * Indirect blocks: if it is a first-level indirect, pull its
    128   1.1  perseant 	 * address from the inode; otherwise, call ourselves to find the
    129   1.1  perseant 	 * address of the parent indirect block, and load that to find
    130   1.1  perseant 	 * the desired address.
    131   1.1  perseant 	 */
    132   1.6  perseant 	if (lbn < 0) {
    133   1.1  perseant 		lbn *= -1;
    134   1.6  perseant 		if (lbn == NDADDR) {
    135   1.1  perseant 			/* printf("lbn %d: single indir base\n", -lbn); */
    136   1.6  perseant 			return idinode->di_ib[0];	/* single indirect */
    137   1.6  perseant 		} else if (lbn == BASE_DINDIR + 1) {
    138   1.1  perseant 			/* printf("lbn %d: double indir base\n", -lbn); */
    139   1.6  perseant 			return idinode->di_ib[1];	/* double indirect */
    140   1.6  perseant 		} else if (lbn == BASE_TINDIR + 2) {
    141   1.1  perseant 			/* printf("lbn %d: triple indir base\n", -lbn); */
    142   1.6  perseant 			return idinode->di_ib[2];	/* triple indirect */
    143   1.1  perseant 		}
    144   1.1  perseant 		/*
    145   1.1  perseant 		 * Find the immediate parent. This is essentially finding the
    146   1.1  perseant 		 * residue of modulus, and then rounding accordingly.
    147   1.1  perseant 		 */
    148   1.6  perseant 		residue = (lbn - NDADDR) % NINDIR(fs);
    149   1.6  perseant 		if (residue == 1) {
    150   1.1  perseant 			/* Double indirect.  Parent is the triple. */
    151   1.1  perseant 			up = idinode->di_ib[2];
    152   1.6  perseant 			off = (lbn - 2 - BASE_TINDIR) / (NINDIR(fs) * NINDIR(fs));
    153   1.6  perseant 			if (up == UNASSIGNED || up == LFS_UNUSED_DADDR)
    154   1.1  perseant 				return UNASSIGNED;
    155   1.1  perseant 			/* printf("lbn %d: parent is the triple\n", -lbn); */
    156   1.6  perseant 			bp = getddblk(up, sblock.lfs_bsize);
    157   1.1  perseant 			bp->b_flags &= ~B_INUSE;
    158   1.1  perseant 			return ((daddr_t *)(bp->b_un.b_buf))[off];
    159   1.6  perseant 		} else {	/* residue == 0 */
    160   1.1  perseant 			/* Single indirect.  Two cases. */
    161   1.6  perseant 			if (lbn < BASE_TINDIR) {
    162   1.1  perseant 				/* Parent is the double, simple */
    163   1.1  perseant 				up = -(BASE_DINDIR) - 1;
    164   1.6  perseant 				off = (lbn - BASE_DINDIR) / D_UNITS;
    165   1.6  perseant 				/*
    166   1.6  perseant 				 * printf("lbn %d: parent is %d/%d\n", -lbn,
    167   1.6  perseant 				 * up,off);
    168   1.6  perseant 				 */
    169   1.1  perseant 			} else {
    170   1.1  perseant 				/* Ancestor is the triple, more complex */
    171   1.6  perseant 				up = ((lbn - BASE_TINDIR) / T_UNITS)
    172   1.1  perseant 					* T_UNITS + BASE_TINDIR + 1;
    173   1.6  perseant 				off = (lbn / D_UNITS) - (up / D_UNITS);
    174   1.1  perseant 				up = -up;
    175   1.6  perseant 				/*
    176   1.6  perseant 				 * printf("lbn %d: parent is %d/%d\n", -lbn,
    177   1.6  perseant 				 * up,off);
    178   1.6  perseant 				 */
    179   1.1  perseant 			}
    180   1.1  perseant 		}
    181   1.1  perseant 	} else {
    182   1.1  perseant 		/* Direct block.  Its parent must be a single indirect. */
    183   1.6  perseant 		if (lbn < NDADDR)
    184   1.1  perseant 			return idinode->di_db[lbn];
    185   1.1  perseant 		else {
    186   1.1  perseant 			/* Parent is an indirect block. */
    187   1.6  perseant 			up = -(((lbn - NDADDR) / D_UNITS) * D_UNITS + NDADDR);
    188   1.6  perseant 			off = (lbn - NDADDR) % D_UNITS;
    189   1.1  perseant 			/* printf("lbn %d: parent is %d/%d\n", lbn,up,off); */
    190   1.1  perseant 		}
    191   1.1  perseant 	}
    192   1.6  perseant 	up = lfs_bmap(fs, idinode, up);
    193   1.6  perseant 	if (up == UNASSIGNED || up == LFS_UNUSED_DADDR)
    194   1.1  perseant 		return UNASSIGNED;
    195   1.6  perseant 	bp = getddblk(up, sblock.lfs_bsize);
    196   1.1  perseant 	bp->b_flags &= ~B_INUSE;
    197   1.1  perseant 	return ((daddr_t *)(bp->b_un.b_buf))[off];
    198   1.1  perseant }
    199   1.1  perseant 
    200   1.1  perseant /*
    201   1.1  perseant  * This is kind of gross.  We use this to find the nth block
    202   1.1  perseant  * from a file whose inode has disk address idaddr.  In practice
    203   1.1  perseant  * we will only use this to find blocks of the ifile.
    204   1.1  perseant  */
    205   1.7  perseant static struct bufarea empty;
    206   1.7  perseant 
    207   1.1  perseant struct bufarea *
    208   1.6  perseant getfileblk(struct lfs * fs, struct dinode * idinode, ino_t lbn)
    209   1.1  perseant {
    210   1.6  perseant 	struct bufarea *bp;
    211   1.6  perseant 	ufs_daddr_t     blkno;
    212   1.6  perseant 	static char     empty_buf[65536];
    213   1.6  perseant 
    214   1.6  perseant 	empty.b_un.b_buf = &(empty_buf[0]);
    215   1.6  perseant 
    216   1.6  perseant 	blkno = lfs_bmap(fs, idinode, lbn);
    217   1.6  perseant 	if (blkno == UNASSIGNED || blkno == LFS_UNUSED_DADDR) {
    218   1.6  perseant 		printf("Warning: ifile lbn %d unassigned!\n", lbn);
    219   1.6  perseant 		return &empty;
    220   1.6  perseant 	}
    221   1.6  perseant 	bp = getddblk(blkno, sblock.lfs_bsize);
    222   1.6  perseant 	return bp;
    223   1.1  perseant }
    224   1.1  perseant 
    225   1.5  perseant #if 0
    226   1.6  perseant static struct dinode *
    227   1.6  perseant gidinode(void)
    228   1.1  perseant {
    229   1.6  perseant 	static struct dinode *idinode;
    230   1.1  perseant 
    231   1.6  perseant 	if (!idinode) {		/* only need to do this once */
    232   1.6  perseant 		idinode = lfs_difind(&sblock, sblock.lfs_ifile, &ifblock);
    233   1.6  perseant 	}
    234   1.6  perseant 	return idinode;
    235   1.1  perseant }
    236   1.5  perseant #endif
    237   1.1  perseant 
    238   1.6  perseant struct ifile   *
    239   1.6  perseant lfs_ientry(ino_t ino, struct bufarea ** bpp)
    240   1.1  perseant {
    241  1.11  perseant 	IFILE *ifp;
    242   1.1  perseant 
    243   1.6  perseant 	*bpp = getfileblk(&sblock, lfs_ginode(LFS_IFILE_INUM),
    244   1.6  perseant 			  ino / sblock.lfs_ifpb + sblock.lfs_cleansz +
    245   1.6  perseant 			  sblock.lfs_segtabsz);
    246   1.7  perseant 	if (*bpp == &empty) {
    247   1.7  perseant 		printf("Warning: ino %d ientry in unassigned block\n", ino);
    248   1.7  perseant 	}
    249   1.6  perseant 	if (*bpp) {
    250  1.11  perseant 		if (sblock.lfs_version > 1) {
    251  1.11  perseant 			ifp = (((IFILE *)((*bpp)->b_un.b_buf)) +
    252  1.11  perseant 			       (ino % sblock.lfs_ifpb));
    253  1.11  perseant 		} else {
    254  1.11  perseant 			ifp = (IFILE *)(((IFILE_V1 *)
    255  1.11  perseant 					 ((*bpp)->b_un.b_buf)) +
    256  1.11  perseant 					(ino % sblock.lfs_ifpb));
    257  1.11  perseant 		}
    258   1.6  perseant 		return ifp;
    259   1.6  perseant 	} else
    260   1.6  perseant 		return NULL;
    261   1.6  perseant }
    262   1.6  perseant 
    263   1.6  perseant SEGUSE         *
    264   1.6  perseant lfs_gseguse(int segnum, struct bufarea ** bpp)
    265   1.6  perseant {
    266   1.6  perseant 	int             blkno;
    267  1.11  perseant 	struct bufarea *bp;
    268   1.6  perseant 
    269  1.11  perseant 	blkno = segnum / sblock.lfs_sepb + sblock.lfs_cleansz;
    270  1.11  perseant 	(*bpp) = bp = getfileblk(&sblock, lfs_ginode(LFS_IFILE_INUM), blkno);
    271  1.11  perseant 	if (sblock.lfs_version == 1)
    272  1.11  perseant 		return (SEGUSE *)((SEGUSE_V1 *)(bp->b_un.b_buf) +
    273  1.11  perseant 				  segnum % sblock.lfs_sepb);
    274  1.11  perseant 	else
    275  1.11  perseant 		return (SEGUSE *)(bp->b_un.b_buf) + segnum % sblock.lfs_sepb;
    276   1.5  perseant }
    277   1.5  perseant 
    278   1.5  perseant daddr_t
    279   1.5  perseant lfs_ino_daddr(ino_t inumber)
    280   1.5  perseant {
    281   1.6  perseant 	daddr_t         daddr;
    282   1.6  perseant 	IFILE          *ifp;
    283   1.5  perseant 	struct bufarea *bp;
    284   1.5  perseant 
    285   1.6  perseant 	if (din_table[inumber]) {
    286   1.5  perseant 		daddr = din_table[inumber];
    287   1.5  perseant 	} else {
    288   1.6  perseant 		if (inumber == LFS_IFILE_INUM)
    289   1.7  perseant 			daddr = idaddr;
    290   1.5  perseant 		else {
    291   1.5  perseant 			ifp = lfs_ientry(inumber, &bp);
    292   1.6  perseant 			if (ifp == NULL) {
    293   1.5  perseant 				return NULL;
    294   1.5  perseant 			}
    295   1.6  perseant 			if (ifp->if_daddr == LFS_UNUSED_DADDR) {
    296   1.5  perseant 				bp->b_flags &= ~B_INUSE;
    297   1.5  perseant 				return NULL;
    298   1.5  perseant 			}
    299   1.5  perseant 			bp->b_flags &= ~B_INUSE;
    300   1.5  perseant 			daddr = ifp->if_daddr;
    301   1.5  perseant 		}
    302   1.6  perseant 
    303   1.5  perseant 		din_table[inumber] = daddr;
    304  1.11  perseant 		seg_table[dtosn(&sblock, daddr)].su_nbytes += DINODE_SIZE;
    305   1.5  perseant 	}
    306   1.5  perseant 	return daddr;
    307   1.1  perseant }
    308   1.1  perseant 
    309   1.6  perseant struct dinode  *
    310   1.5  perseant lfs_ginode(ino_t inumber)
    311   1.5  perseant {
    312   1.6  perseant 	struct ifile   *ifp;
    313   1.6  perseant 	struct dinode  *din;
    314   1.6  perseant 	struct bufarea *bp;
    315   1.6  perseant 	daddr_t         daddr;
    316   1.5  perseant 
    317   1.7  perseant 	if (inumber >= maxino)
    318   1.6  perseant 		errexit("bad inode number %d to lfs_ginode\n", inumber);
    319   1.1  perseant 
    320   1.5  perseant #if 0
    321   1.6  perseant 	if (inumber == LFS_IFILE_INUM) {
    322   1.7  perseant 		daddr = idaddr;
    323   1.6  perseant 		if (din_table[LFS_IFILE_INUM] == 0) {
    324   1.6  perseant 			din_table[LFS_IFILE_INUM] = daddr;
    325  1.11  perseant 			seg_table[dtosn(&sblock, daddr)].su_nbytes += DINODE_SIZE;
    326   1.6  perseant 		}
    327   1.6  perseant 		return gidinode();
    328   1.6  perseant 	}
    329   1.5  perseant #endif
    330   1.5  perseant 
    331   1.6  perseant 	daddr = lfs_ino_daddr(inumber);
    332   1.6  perseant 	if (daddr == 0)
    333   1.6  perseant 		return NULL;
    334   1.6  perseant 
    335   1.6  perseant 	if (pbp)
    336   1.6  perseant 		pbp->b_flags &= ~B_INUSE;
    337   1.6  perseant 
    338  1.11  perseant 	if (sblock.lfs_version == 1)
    339  1.11  perseant 		pbp = getddblk(daddr, sblock.lfs_bsize);
    340  1.11  perseant 	else
    341  1.11  perseant 		pbp = getddblk(daddr, sblock.lfs_fsize);
    342   1.6  perseant 	din = lfs_difind(&sblock, inumber, pbp->b_un.b_dinode);
    343   1.6  perseant 
    344   1.6  perseant 	if (din == NULL) {
    345   1.6  perseant 		pfatal("INODE %d NOT FOUND\n", inumber);
    346   1.6  perseant 		if (reply("free")) {
    347   1.6  perseant 			ifp = lfs_ientry(inumber, &bp);
    348   1.6  perseant 			ifp->if_daddr = LFS_UNUSED_DADDR;
    349   1.6  perseant 			ifp->if_nextfree = sblock.lfs_free;
    350   1.6  perseant 			sblock.lfs_free = inumber;
    351   1.6  perseant 			sbdirty();
    352   1.6  perseant 			dirty(bp);
    353   1.6  perseant 			bp->b_flags &= ~B_INUSE;
    354   1.6  perseant 		}
    355   1.6  perseant 	}
    356   1.6  perseant 	return din;
    357   1.1  perseant }
    358   1.1  perseant 
    359   1.1  perseant /* imported from lfs_vfsops.c */
    360   1.1  perseant int
    361   1.6  perseant ino_to_fsba(struct lfs * fs, ino_t ino)
    362   1.1  perseant {
    363   1.6  perseant 	daddr_t         daddr = LFS_UNUSED_DADDR;
    364   1.6  perseant 	struct ifile   *ifp;
    365   1.6  perseant 	struct bufarea *bp;
    366   1.6  perseant 
    367   1.6  perseant 	/* Translate the inode number to a disk address. */
    368   1.6  perseant 	if (ino == LFS_IFILE_INUM)
    369   1.6  perseant 		daddr = fs->lfs_idaddr;
    370   1.6  perseant 	else {
    371   1.6  perseant 		ifp = lfs_ientry(ino, &bp);
    372   1.6  perseant 		if (ifp) {
    373   1.6  perseant 			daddr = ifp->if_daddr;
    374   1.6  perseant 		} else {
    375   1.6  perseant 			pwarn("Can't locate inode #%ud\n", ino);
    376   1.6  perseant 		}
    377   1.6  perseant 		bp->b_flags &= ~B_INUSE;
    378   1.6  perseant 	}
    379   1.6  perseant 	return daddr;
    380   1.1  perseant }
    381   1.1  perseant 
    382   1.1  perseant /*
    383   1.1  perseant  * Check validity of held (direct) blocks in an inode.
    384   1.1  perseant  */
    385   1.1  perseant int
    386   1.6  perseant ckinode(struct dinode *dp, struct inodesc *idesc)
    387   1.6  perseant {
    388   1.6  perseant 	register ufs_daddr_t *ap;
    389   1.6  perseant 	long            ret, n, ndb, offset;
    390   1.6  perseant 	struct dinode   dino;
    391   1.6  perseant 	u_int64_t       remsize, sizepb;
    392   1.6  perseant 	mode_t          mode;
    393   1.6  perseant 	char            pathbuf[MAXPATHLEN + 1];
    394   1.6  perseant 
    395   1.6  perseant 	if (idesc->id_fix != IGNORE)
    396   1.6  perseant 		idesc->id_fix = DONTKNOW;
    397   1.6  perseant 	idesc->id_entryno = 0;
    398   1.6  perseant 	idesc->id_filesize = dp->di_size;
    399   1.6  perseant 	mode = dp->di_mode & IFMT;
    400   1.6  perseant 	if (mode == IFBLK || mode == IFCHR ||
    401   1.6  perseant 	    (mode == IFLNK && (dp->di_size < sblock.lfs_maxsymlinklen ||
    402   1.6  perseant 	                       (sblock.lfs_maxsymlinklen == 0 &&
    403   1.6  perseant 				dp->di_blocks == 0))))
    404   1.6  perseant 		return (KEEPON);
    405   1.6  perseant 	dino = *dp;
    406   1.6  perseant 	ndb = howmany(dino.di_size, sblock.lfs_bsize);
    407   1.6  perseant 
    408   1.6  perseant 	for (ap = &dino.di_db[0]; ap < &dino.di_db[NDADDR]; ap++) {
    409   1.6  perseant 		if (--ndb == 0 && (offset = blkoff(&sblock, dino.di_size)) != 0) {
    410   1.6  perseant 			idesc->id_numfrags =
    411   1.6  perseant 				numfrags(&sblock, fragroundup(&sblock, offset));
    412   1.6  perseant 		} else
    413   1.6  perseant 			idesc->id_numfrags = sblock.lfs_frag;
    414   1.6  perseant 		if (*ap == 0) {
    415   1.6  perseant 			if (idesc->id_type == DATA && ndb >= 0) {
    416   1.6  perseant 				/* An empty block in a directory XXX */
    417   1.6  perseant 				getpathname(pathbuf, idesc->id_number,
    418   1.6  perseant 					    idesc->id_number);
    419   1.6  perseant 				pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
    420   1.6  perseant 				       pathbuf);
    421   1.6  perseant 				if (reply("ADJUST LENGTH") == 1) {
    422   1.6  perseant 					dp = ginode(idesc->id_number);
    423   1.6  perseant 					dp->di_size = (ap - &dino.di_db[0]) *
    424   1.6  perseant 						sblock.lfs_bsize;
    425   1.6  perseant 					printf(
    426   1.6  perseant 					"YOU MUST RERUN FSCK AFTERWARDS\n");
    427   1.6  perseant 					rerun = 1;
    428   1.6  perseant 					inodirty();
    429   1.6  perseant 				}
    430   1.6  perseant 			}
    431   1.6  perseant 			continue;
    432   1.6  perseant 		}
    433   1.6  perseant 		idesc->id_blkno = *ap;
    434   1.6  perseant 		idesc->id_lblkno = ap - &dino.di_db[0];
    435   1.6  perseant 		if (idesc->id_type == ADDR) {
    436   1.6  perseant 			ret = (*idesc->id_func)(idesc);
    437   1.6  perseant 		} else
    438   1.6  perseant 			ret = dirscan(idesc);
    439   1.6  perseant 		idesc->id_lblkno = 0;
    440   1.6  perseant 		if (ret & STOP)
    441   1.6  perseant 			return (ret);
    442   1.6  perseant 	}
    443   1.6  perseant 	idesc->id_numfrags = sblock.lfs_frag;
    444   1.6  perseant 	remsize = dino.di_size - sblock.lfs_bsize * NDADDR;
    445   1.6  perseant 	sizepb = sblock.lfs_bsize;
    446   1.6  perseant 	for (ap = &dino.di_ib[0], n = 1; n <= NIADDR; ap++, n++) {
    447   1.6  perseant 		if (*ap) {
    448   1.6  perseant 			idesc->id_blkno = *ap;
    449   1.6  perseant 			ret = iblock(idesc, n, remsize);
    450   1.6  perseant 			if (ret & STOP)
    451   1.6  perseant 				return (ret);
    452   1.6  perseant 		} else {
    453   1.6  perseant 			if (idesc->id_type == DATA && remsize > 0) {
    454   1.6  perseant 				/* An empty block in a directory XXX */
    455   1.6  perseant 				getpathname(pathbuf, idesc->id_number,
    456   1.6  perseant 					    idesc->id_number);
    457   1.6  perseant 				pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
    458   1.6  perseant 				       pathbuf);
    459   1.6  perseant 				if (reply("ADJUST LENGTH") == 1) {
    460   1.6  perseant 					dp = ginode(idesc->id_number);
    461   1.6  perseant 					dp->di_size -= remsize;
    462   1.6  perseant 					remsize = 0;
    463   1.6  perseant 					printf(
    464   1.6  perseant 					"YOU MUST RERUN FSCK AFTERWARDS\n");
    465   1.6  perseant 					rerun = 1;
    466   1.6  perseant 					inodirty();
    467   1.6  perseant 					break;
    468   1.6  perseant 				}
    469   1.6  perseant 			}
    470   1.6  perseant 		}
    471   1.6  perseant 		sizepb *= NINDIR(&sblock);
    472   1.6  perseant 		remsize -= sizepb;
    473   1.6  perseant 	}
    474   1.6  perseant 	return (KEEPON);
    475   1.1  perseant }
    476   1.1  perseant 
    477   1.1  perseant static int
    478   1.6  perseant iblock(struct inodesc * idesc, long ilevel, u_int64_t isize)
    479   1.6  perseant {
    480   1.7  perseant 	daddr_t	       *ap, *aplim;
    481   1.7  perseant 	struct bufarea *bp;
    482   1.6  perseant 	int             i, n, (*func)(struct inodesc *), nif;
    483   1.6  perseant 	u_int64_t       sizepb;
    484   1.6  perseant 	char            pathbuf[MAXPATHLEN + 1], buf[BUFSIZ];
    485   1.6  perseant 	struct dinode  *dp;
    486   1.6  perseant 
    487   1.6  perseant 	if (idesc->id_type == ADDR) {
    488   1.6  perseant 		func = idesc->id_func;
    489   1.6  perseant 		n = (*func)(idesc);
    490   1.6  perseant 		if ((n & KEEPON) == 0)
    491   1.6  perseant 			return (n);
    492   1.6  perseant 	} else
    493   1.6  perseant 		func = dirscan;
    494  1.11  perseant 	if (chkrange(idesc->id_blkno, fragstofsb(&sblock, idesc->id_numfrags)))
    495   1.6  perseant 		return (SKIP);
    496   1.6  perseant 	bp = getddblk(idesc->id_blkno, sblock.lfs_bsize);
    497   1.6  perseant 	ilevel--;
    498   1.6  perseant 	for (sizepb = sblock.lfs_bsize, i = 0; i < ilevel; i++)
    499   1.6  perseant 		sizepb *= NINDIR(&sblock);
    500   1.6  perseant 	if (isize > sizepb * NINDIR(&sblock))
    501   1.6  perseant 		nif = NINDIR(&sblock);
    502   1.6  perseant 	else
    503   1.6  perseant 		nif = howmany(isize, sizepb);
    504   1.6  perseant 	if (idesc->id_func == pass1check && nif < NINDIR(&sblock)) {
    505   1.6  perseant 		aplim = &bp->b_un.b_indir[NINDIR(&sblock)];
    506   1.6  perseant 		for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
    507   1.6  perseant 			if (*ap == 0)
    508   1.6  perseant 				continue;
    509   1.6  perseant 			(void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%u",
    510   1.7  perseant 					      idesc->id_number);
    511   1.6  perseant 			if (dofix(idesc, buf)) {
    512   1.6  perseant 				*ap = 0;
    513   1.6  perseant 				dirty(bp);
    514   1.6  perseant 			}
    515   1.6  perseant 		}
    516   1.6  perseant 		flush(fswritefd, bp);
    517   1.6  perseant 	}
    518   1.6  perseant 	aplim = &bp->b_un.b_indir[nif];
    519   1.6  perseant 	for (ap = bp->b_un.b_indir; ap < aplim; ap++) {
    520   1.6  perseant 		if (*ap) {
    521   1.6  perseant 			idesc->id_blkno = *ap;
    522   1.6  perseant 			if (ilevel == 0)
    523   1.6  perseant 				n = (*func)(idesc);
    524   1.6  perseant 			else
    525   1.6  perseant 				n = iblock(idesc, ilevel, isize);
    526   1.6  perseant 			if (n & STOP) {
    527   1.6  perseant 				bp->b_flags &= ~B_INUSE;
    528   1.6  perseant 				return (n);
    529   1.6  perseant 			}
    530   1.6  perseant 		} else {
    531   1.6  perseant 			if (idesc->id_type == DATA && isize > 0) {
    532   1.6  perseant 				/* An empty block in a directory XXX */
    533   1.6  perseant 				getpathname(pathbuf, idesc->id_number,
    534   1.6  perseant 					    idesc->id_number);
    535   1.6  perseant 				pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
    536   1.6  perseant 				       pathbuf);
    537   1.6  perseant 				if (reply("ADJUST LENGTH") == 1) {
    538   1.6  perseant 					dp = ginode(idesc->id_number);
    539   1.6  perseant 					dp->di_size -= isize;
    540   1.6  perseant 					isize = 0;
    541   1.6  perseant 					printf(
    542   1.6  perseant 					"YOU MUST RERUN FSCK AFTERWARDS\n");
    543   1.6  perseant 					rerun = 1;
    544   1.6  perseant 					inodirty();
    545   1.6  perseant 					bp->b_flags &= ~B_INUSE;
    546   1.6  perseant 					return (STOP);
    547   1.6  perseant 				}
    548   1.6  perseant 			}
    549   1.6  perseant 		}
    550   1.6  perseant 		isize -= sizepb;
    551   1.6  perseant 	}
    552   1.6  perseant 	bp->b_flags &= ~B_INUSE;
    553   1.6  perseant 	return (KEEPON);
    554   1.1  perseant }
    555   1.1  perseant 
    556   1.1  perseant /*
    557   1.1  perseant  * Check that a block in a legal block number.
    558   1.1  perseant  * Return 0 if in range, 1 if out of range.
    559   1.1  perseant  */
    560   1.1  perseant int
    561   1.6  perseant chkrange(daddr_t blk, int cnt)
    562   1.6  perseant {
    563  1.11  perseant 	if (blk < sntod(&sblock, 0)) {
    564  1.11  perseant 		return (1);
    565  1.11  perseant 	}
    566  1.11  perseant 	if (blk > maxfsblock) {
    567  1.11  perseant 		return (1);
    568  1.11  perseant 	}
    569  1.11  perseant 	if (blk + cnt < sntod(&sblock, 0)) {
    570   1.7  perseant 		return (1);
    571   1.7  perseant 	}
    572  1.11  perseant 	if (blk + cnt > maxfsblock) {
    573   1.6  perseant 		return (1);
    574   1.6  perseant 	}
    575   1.6  perseant 	return (0);
    576   1.1  perseant }
    577   1.1  perseant 
    578   1.1  perseant /*
    579   1.1  perseant  * General purpose interface for reading inodes.
    580   1.1  perseant  */
    581   1.6  perseant struct dinode  *
    582   1.1  perseant ginode(ino_t inumber)
    583   1.1  perseant {
    584   1.6  perseant 	return lfs_ginode(inumber);
    585   1.1  perseant }
    586   1.1  perseant 
    587   1.1  perseant /*
    588   1.1  perseant  * Routines to maintain information about directory inodes.
    589   1.1  perseant  * This is built during the first pass and used during the
    590   1.1  perseant  * second and third passes.
    591   1.1  perseant  *
    592   1.1  perseant  * Enter inodes into the cache.
    593   1.1  perseant  */
    594   1.1  perseant void
    595   1.6  perseant cacheino(struct dinode *dp, ino_t inumber)
    596   1.6  perseant {
    597   1.6  perseant 	register struct inoinfo *inp;
    598   1.6  perseant 	struct inoinfo **inpp;
    599   1.6  perseant 	unsigned int    blks;
    600   1.6  perseant 
    601   1.6  perseant 	blks = howmany(dp->di_size, sblock.lfs_bsize);
    602   1.6  perseant 	if (blks > NDADDR)
    603   1.6  perseant 		blks = NDADDR + NIADDR;
    604   1.6  perseant 	inp = (struct inoinfo *)
    605   1.6  perseant 		malloc(sizeof(*inp) + (blks - 1) * sizeof(daddr_t));
    606   1.6  perseant 	if (inp == NULL)
    607   1.6  perseant 		return;
    608   1.6  perseant 	inpp = &inphead[inumber % numdirs];
    609   1.6  perseant 	inp->i_nexthash = *inpp;
    610   1.6  perseant 	*inpp = inp;
    611   1.6  perseant 	inp->i_child = inp->i_sibling = inp->i_parentp = 0;
    612   1.6  perseant 	if (inumber == ROOTINO)
    613   1.6  perseant 		inp->i_parent = ROOTINO;
    614   1.6  perseant 	else
    615   1.6  perseant 		inp->i_parent = (ino_t)0;
    616   1.6  perseant 	inp->i_dotdot = (ino_t)0;
    617   1.6  perseant 	inp->i_number = inumber;
    618   1.6  perseant 	inp->i_isize = dp->di_size;
    619   1.6  perseant 	inp->i_numblks = blks * sizeof(daddr_t);
    620   1.6  perseant 	memcpy(&inp->i_blks[0], &dp->di_db[0], (size_t)inp->i_numblks);
    621   1.6  perseant 	if (inplast == listmax) {
    622   1.6  perseant 		listmax += 100;
    623   1.6  perseant 		inpsort = (struct inoinfo **)realloc((char *) inpsort,
    624   1.6  perseant 			     (unsigned)listmax * sizeof(struct inoinfo *));
    625   1.6  perseant 		if (inpsort == NULL)
    626   1.6  perseant 			errexit("cannot increase directory list");
    627   1.6  perseant 	}
    628   1.6  perseant 	inpsort[inplast++] = inp;
    629   1.1  perseant }
    630   1.1  perseant 
    631   1.1  perseant /*
    632   1.1  perseant  * Look up an inode cache structure.
    633   1.1  perseant  */
    634   1.1  perseant struct inoinfo *
    635   1.6  perseant getinoinfo(ino_t inumber)
    636   1.1  perseant {
    637   1.6  perseant 	register struct inoinfo *inp;
    638   1.1  perseant 
    639   1.6  perseant 	for (inp = inphead[inumber % numdirs]; inp; inp = inp->i_nexthash) {
    640   1.6  perseant 		if (inp->i_number != inumber)
    641   1.6  perseant 			continue;
    642   1.6  perseant 		return (inp);
    643   1.6  perseant 	}
    644   1.6  perseant 	errexit("cannot find inode %d\n", inumber);
    645   1.6  perseant 	return ((struct inoinfo *)0);
    646   1.1  perseant }
    647   1.1  perseant 
    648   1.1  perseant /*
    649   1.1  perseant  * Clean up all the inode cache structure.
    650   1.1  perseant  */
    651   1.1  perseant void
    652   1.1  perseant inocleanup()
    653   1.1  perseant {
    654   1.6  perseant 	register struct inoinfo **inpp;
    655   1.1  perseant 
    656   1.6  perseant 	if (inphead == NULL)
    657   1.6  perseant 		return;
    658   1.6  perseant 	for (inpp = &inpsort[inplast - 1]; inpp >= inpsort; inpp--)
    659   1.6  perseant 		free((char *)(*inpp));
    660   1.6  perseant 	free((char *)inphead);
    661   1.6  perseant 	free((char *)inpsort);
    662   1.6  perseant 	inphead = inpsort = NULL;
    663   1.1  perseant }
    664   1.1  perseant 
    665   1.1  perseant void
    666   1.1  perseant inodirty()
    667   1.1  perseant {
    668   1.6  perseant 	dirty(pbp);
    669   1.1  perseant }
    670   1.1  perseant 
    671   1.1  perseant void
    672   1.6  perseant clri(struct inodesc *idesc, char *type, int flag)
    673   1.6  perseant {
    674   1.6  perseant 	register struct dinode *dp;
    675   1.6  perseant 	struct bufarea *bp;
    676   1.6  perseant 	IFILE          *ifp;
    677   1.6  perseant 
    678   1.6  perseant 	dp = ginode(idesc->id_number);
    679   1.6  perseant 	if (flag == 1) {
    680   1.6  perseant 		pwarn("%s %s", type,
    681   1.6  perseant 		      (dp->di_mode & IFMT) == IFDIR ? "DIR" : "FILE");
    682   1.6  perseant 		pinode(idesc->id_number);
    683   1.6  perseant 	}
    684   1.6  perseant 	if (preen || reply("CLEAR") == 1) {
    685   1.6  perseant 		if (preen)
    686   1.6  perseant 			printf(" (CLEARED)\n");
    687   1.6  perseant 		n_files--;
    688   1.6  perseant 		(void)ckinode(dp, idesc);
    689   1.6  perseant 		clearinode(dp);
    690   1.6  perseant 		statemap[idesc->id_number] = USTATE;
    691   1.6  perseant 		inodirty();
    692   1.6  perseant 
    693   1.6  perseant 		/* Send cleared inode to the free list */
    694   1.6  perseant 
    695   1.6  perseant 		ifp = lfs_ientry(idesc->id_number, &bp);
    696   1.6  perseant 		ifp->if_daddr = LFS_UNUSED_DADDR;
    697   1.6  perseant 		ifp->if_nextfree = sblock.lfs_free;
    698   1.6  perseant 		sblock.lfs_free = idesc->id_number;
    699   1.6  perseant 		sbdirty();
    700   1.6  perseant 		dirty(bp);
    701   1.6  perseant 		bp->b_flags &= ~B_INUSE;
    702   1.6  perseant 	}
    703   1.1  perseant }
    704   1.1  perseant 
    705   1.1  perseant int
    706   1.6  perseant findname(struct inodesc *idesc)
    707   1.1  perseant {
    708   1.6  perseant 	register struct direct *dirp = idesc->id_dirp;
    709   1.1  perseant 
    710   1.6  perseant 	if (dirp->d_ino != idesc->id_parent)
    711   1.6  perseant 		return (KEEPON);
    712   1.6  perseant 	memcpy(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
    713   1.6  perseant 	return (STOP | FOUND);
    714   1.1  perseant }
    715   1.1  perseant 
    716   1.1  perseant int
    717   1.6  perseant findino(struct inodesc *idesc)
    718   1.1  perseant {
    719   1.6  perseant 	register struct direct *dirp = idesc->id_dirp;
    720   1.1  perseant 
    721   1.6  perseant 	if (dirp->d_ino == 0)
    722   1.6  perseant 		return (KEEPON);
    723   1.6  perseant 	if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
    724   1.7  perseant 	    dirp->d_ino >= ROOTINO && dirp->d_ino < maxino) {
    725   1.6  perseant 		idesc->id_parent = dirp->d_ino;
    726   1.6  perseant 		return (STOP | FOUND);
    727   1.6  perseant 	}
    728   1.6  perseant 	return (KEEPON);
    729   1.1  perseant }
    730   1.1  perseant 
    731   1.1  perseant void
    732   1.6  perseant pinode(ino_t ino)
    733   1.1  perseant {
    734   1.6  perseant 	register struct dinode *dp;
    735   1.6  perseant 	register char  *p;
    736   1.6  perseant 	struct passwd  *pw;
    737   1.6  perseant 	time_t          t;
    738   1.6  perseant 
    739   1.6  perseant 	printf(" I=%u ", ino);
    740   1.7  perseant 	if (ino < ROOTINO || ino >= maxino)
    741   1.6  perseant 		return;
    742   1.6  perseant 	dp = ginode(ino);
    743   1.6  perseant 	if (dp) {
    744   1.6  perseant 		printf(" OWNER=");
    745   1.1  perseant #ifndef SMALL
    746   1.6  perseant 		if ((pw = getpwuid((int)dp->di_uid)) != 0)
    747   1.6  perseant 			printf("%s ", pw->pw_name);
    748   1.6  perseant 		else
    749   1.1  perseant #endif
    750   1.6  perseant 			printf("%u ", (unsigned)dp->di_uid);
    751   1.6  perseant 		printf("MODE=%o\n", dp->di_mode);
    752   1.6  perseant 		if (preen)
    753   1.6  perseant 			printf("%s: ", cdevname());
    754   1.8     lukem 		printf("SIZE=%llu ", (unsigned long long)dp->di_size);
    755   1.6  perseant 		t = dp->di_mtime;
    756   1.6  perseant 		p = ctime(&t);
    757   1.6  perseant 		printf("MTIME=%12.12s %4.4s ", &p[4], &p[20]);
    758   1.6  perseant 	}
    759   1.1  perseant }
    760   1.1  perseant 
    761   1.1  perseant void
    762   1.6  perseant blkerror(ino_t ino, char *type, daddr_t blk)
    763   1.6  perseant {
    764   1.6  perseant 
    765   1.6  perseant 	pfatal("%d %s I=%u", blk, type, ino);
    766   1.6  perseant 	printf("\n");
    767   1.6  perseant 	if (exitonfail)
    768   1.6  perseant 		exit(1);
    769   1.6  perseant 	switch (statemap[ino]) {
    770   1.6  perseant 
    771   1.6  perseant 	case FSTATE:
    772   1.6  perseant 		statemap[ino] = FCLEAR;
    773   1.6  perseant 		return;
    774   1.6  perseant 
    775   1.6  perseant 	case DSTATE:
    776   1.6  perseant 		statemap[ino] = DCLEAR;
    777   1.6  perseant 		return;
    778   1.6  perseant 
    779   1.6  perseant 	case FCLEAR:
    780   1.6  perseant 	case DCLEAR:
    781   1.6  perseant 		return;
    782   1.6  perseant 
    783   1.6  perseant 	default:
    784   1.6  perseant 		errexit("BAD STATE %d TO BLKERR", statemap[ino]);
    785   1.6  perseant 		/* NOTREACHED */
    786   1.6  perseant 	}
    787   1.1  perseant }
    788   1.1  perseant 
    789   1.1  perseant /*
    790   1.1  perseant  * allocate an unused inode
    791   1.1  perseant  */
    792   1.1  perseant ino_t
    793   1.6  perseant allocino(ino_t request, int type)
    794   1.6  perseant {
    795   1.6  perseant 	register ino_t  ino;
    796   1.6  perseant 	register struct dinode *dp;
    797   1.6  perseant 	time_t          t;
    798   1.6  perseant 
    799   1.6  perseant 	if (request == 0)
    800   1.6  perseant 		request = ROOTINO;
    801   1.6  perseant 	else if (statemap[request] != USTATE)
    802   1.6  perseant 		return (0);
    803   1.6  perseant 	for (ino = request; ino < maxino; ino++)
    804   1.6  perseant 		if (statemap[ino] == USTATE)
    805   1.6  perseant 			break;
    806   1.6  perseant 	if (ino == maxino)
    807   1.6  perseant 		return (0);
    808   1.6  perseant 	switch (type & IFMT) {
    809   1.6  perseant 	case IFDIR:
    810   1.6  perseant 		statemap[ino] = DSTATE;
    811   1.6  perseant 		break;
    812   1.6  perseant 	case IFREG:
    813   1.6  perseant 	case IFLNK:
    814   1.6  perseant 		statemap[ino] = FSTATE;
    815   1.6  perseant 		break;
    816   1.6  perseant 	default:
    817   1.6  perseant 		return (0);
    818   1.6  perseant 	}
    819   1.6  perseant 	dp = ginode(ino);
    820   1.6  perseant 	dp->di_db[0] = allocblk((long)1);
    821   1.6  perseant 	if (dp->di_db[0] == 0) {
    822   1.6  perseant 		statemap[ino] = USTATE;
    823   1.6  perseant 		return (0);
    824   1.6  perseant 	}
    825   1.6  perseant 	dp->di_mode = type;
    826   1.6  perseant 	(void)time(&t);
    827   1.6  perseant 	dp->di_atime = t;
    828   1.6  perseant 	dp->di_mtime = dp->di_ctime = dp->di_atime;
    829   1.6  perseant 	dp->di_size = sblock.lfs_fsize;
    830  1.11  perseant 	dp->di_blocks = btofsb(&sblock, sblock.lfs_fsize);
    831   1.6  perseant 	n_files++;
    832   1.6  perseant 	inodirty();
    833   1.6  perseant 	if (newinofmt)
    834   1.6  perseant 		typemap[ino] = IFTODT(type);
    835   1.6  perseant 	return (ino);
    836   1.1  perseant }
    837   1.1  perseant 
    838   1.1  perseant /*
    839   1.1  perseant  * deallocate an inode
    840   1.1  perseant  */
    841   1.1  perseant void
    842   1.6  perseant freeino(ino_t ino)
    843   1.1  perseant {
    844   1.6  perseant 	struct inodesc  idesc;
    845   1.6  perseant 	struct dinode  *dp;
    846   1.1  perseant 
    847   1.6  perseant 	memset(&idesc, 0, sizeof(struct inodesc));
    848   1.6  perseant 	idesc.id_type = ADDR;
    849   1.6  perseant 	idesc.id_func = pass4check;
    850   1.6  perseant 	idesc.id_number = ino;
    851   1.6  perseant 	dp = ginode(ino);
    852   1.6  perseant 	(void)ckinode(dp, &idesc);
    853   1.6  perseant 	clearinode(dp);
    854   1.6  perseant 	inodirty();
    855   1.6  perseant 	statemap[ino] = USTATE;
    856   1.5  perseant 
    857   1.6  perseant 	n_files--;
    858   1.1  perseant }
    859