Home | History | Annotate | Line # | Download | only in dump_lfs
lfs_inode.c revision 1.25
      1  1.25  dholland /*      $NetBSD: lfs_inode.c,v 1.25 2015/08/12 18:28:00 dholland Exp $ */
      2   1.1  perseant 
      3   1.1  perseant /*-
      4   1.1  perseant  * Copyright (c) 1980, 1991, 1993, 1994
      5   1.1  perseant  *      The Regents of the University of California.  All rights reserved.
      6   1.1  perseant  *
      7   1.1  perseant  * Redistribution and use in source and binary forms, with or without
      8   1.1  perseant  * modification, are permitted provided that the following conditions
      9   1.1  perseant  * are met:
     10   1.1  perseant  * 1. Redistributions of source code must retain the above copyright
     11   1.1  perseant  *    notice, this list of conditions and the following disclaimer.
     12   1.1  perseant  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  perseant  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  perseant  *    documentation and/or other materials provided with the distribution.
     15   1.8       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1  perseant  *    may be used to endorse or promote products derived from this software
     17   1.1  perseant  *    without specific prior written permission.
     18   1.1  perseant  *
     19   1.1  perseant  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1  perseant  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1  perseant  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1  perseant  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1  perseant  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1  perseant  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1  perseant  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1  perseant  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1  perseant  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1  perseant  * SUCH DAMAGE.
     30   1.1  perseant  */
     31   1.1  perseant 
     32   1.1  perseant #include <sys/cdefs.h>
     33   1.1  perseant #ifndef lint
     34  1.14     lukem __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\
     35  1.14     lukem  The Regents of the University of California.  All rights reserved.");
     36   1.1  perseant #endif /* not lint */
     37   1.1  perseant 
     38   1.1  perseant #ifndef lint
     39   1.1  perseant #if 0
     40   1.1  perseant static char sccsid[] = "@(#)main.c      8.6 (Berkeley) 5/1/95";
     41   1.1  perseant #else
     42  1.25  dholland __RCSID("$NetBSD: lfs_inode.c,v 1.25 2015/08/12 18:28:00 dholland Exp $");
     43   1.1  perseant #endif
     44   1.1  perseant #endif /* not lint */
     45   1.1  perseant 
     46   1.1  perseant #include <sys/param.h>
     47   1.1  perseant #include <sys/time.h>
     48   1.1  perseant #include <sys/stat.h>
     49   1.1  perseant #include <sys/mount.h>
     50   1.1  perseant 
     51   1.1  perseant #include <ctype.h>
     52   1.1  perseant #include <errno.h>
     53  1.12  perseant #include <fcntl.h>
     54   1.1  perseant #include <fts.h>
     55   1.1  perseant #include <stdio.h>
     56   1.1  perseant #include <string.h>
     57   1.1  perseant #include <unistd.h>
     58   1.1  perseant 
     59   1.1  perseant #include "dump.h"
     60  1.18  christos #undef di_inumber
     61   1.1  perseant 
     62   1.1  perseant #define	HASDUMPEDFILE	0x1
     63   1.1  perseant #define	HASSUBDIRS	0x2
     64   1.1  perseant 
     65   1.1  perseant struct lfs *sblock;
     66   1.1  perseant 
     67   1.7      fvdl int is_ufs2 = 0;
     68   1.7      fvdl 
     69   1.1  perseant /*
     70   1.1  perseant  * Read the superblock from disk, and check its magic number.
     71   1.1  perseant  * Determine whether byte-swapping needs to be done on this filesystem.
     72   1.1  perseant  */
     73   1.1  perseant int
     74   1.4     lukem fs_read_sblock(char *superblock)
     75   1.1  perseant {
     76  1.15  christos 	union {
     77  1.15  christos 		char tbuf[LFS_SBPAD];
     78  1.15  christos 		struct lfs lfss;
     79  1.15  christos 	} u;
     80  1.15  christos 
     81   1.4     lukem 	int ns = 0;
     82   1.3  perseant 	off_t sboff = LFS_LABELPAD;
     83   1.1  perseant 
     84   1.4     lukem 	sblock = (struct lfs *)superblock;
     85   1.3  perseant 	while(1) {
     86   1.3  perseant 		rawread(sboff, (char *) sblock, LFS_SBPAD);
     87  1.23  dholland 		if (sblock->lfs_dlfs_u.u_32.dlfs_magic != LFS_MAGIC) {
     88   1.2  perseant #ifdef notyet
     89   1.3  perseant 			if (sblock->lfs_magic == bswap32(LFS_MAGIC)) {
     90   1.3  perseant 				lfs_sb_swap(sblock, sblock, 0);
     91   1.4     lukem 				ns = 1;
     92   1.3  perseant 			} else
     93   1.1  perseant #endif
     94   1.3  perseant 				quit("bad sblock magic number\n");
     95   1.3  perseant 		}
     96  1.21  dholland 		if (lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 0)) != sboff) {
     97  1.21  dholland 			sboff = lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 0));
     98   1.3  perseant 			continue;
     99   1.3  perseant 		}
    100   1.3  perseant 		break;
    101   1.3  perseant 	}
    102   1.3  perseant 
    103   1.3  perseant 	/*
    104   1.3  perseant 	 * Read the secondary and take the older of the two
    105   1.3  perseant 	 */
    106  1.21  dholland 	rawread(lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 1)), u.tbuf,
    107  1.15  christos 	    sizeof(u.tbuf));
    108   1.3  perseant #ifdef notyet
    109   1.4     lukem 	if (ns)
    110  1.15  christos 		lfs_sb_swap(u.tbuf, u.tbuf, 0);
    111   1.3  perseant #endif
    112  1.23  dholland 	if (u.lfss.lfs_dlfs_u.u_32.dlfs_magic != LFS_MAGIC) {
    113  1.12  perseant 		msg("Warning: secondary superblock at 0x%" PRIx64 " bad magic\n",
    114  1.21  dholland 			LFS_FSBTODB(sblock, (off_t)lfs_sb_getsboff(sblock, 1)));
    115   1.3  perseant 	} else {
    116  1.22  dholland 		if (lfs_sb_getversion(sblock) > 1) {
    117  1.20  dholland 			if (lfs_sb_getserial(&u.lfss) < lfs_sb_getserial(sblock)) {
    118  1.15  christos 				memcpy(sblock, u.tbuf, sizeof(u.tbuf));
    119  1.21  dholland 				sboff = lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 1));
    120   1.3  perseant 			}
    121   1.3  perseant 		} else {
    122  1.20  dholland 			if (lfs_sb_getotstamp(&u.lfss) < lfs_sb_getotstamp(sblock)) {
    123  1.15  christos 				memcpy(sblock, u.tbuf, sizeof(u.tbuf));
    124  1.21  dholland 				sboff = lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 1));
    125   1.3  perseant 			}
    126   1.3  perseant 		}
    127   1.3  perseant 	}
    128   1.3  perseant 	if (sboff != LFS_SBPAD) {
    129   1.3  perseant 		msg("Using superblock at alternate location 0x%lx\n",
    130   1.3  perseant 		    (unsigned long)(btodb(sboff)));
    131   1.1  perseant 	}
    132   1.3  perseant 
    133   1.4     lukem 	return ns;
    134   1.1  perseant }
    135   1.1  perseant 
    136   1.1  perseant /*
    137   1.1  perseant  * Fill in the ufsi struct, as well as the maxino and dev_bsize global
    138   1.1  perseant  * variables.
    139   1.1  perseant  */
    140   1.1  perseant struct ufsi *
    141   1.1  perseant fs_parametrize(void)
    142   1.1  perseant {
    143   1.1  perseant 	static struct ufsi ufsi;
    144   1.1  perseant 
    145   1.2  perseant 	spcl.c_flags = iswap32(iswap32(spcl.c_flags) | DR_NEWINODEFMT);
    146   1.2  perseant 
    147  1.20  dholland 	ufsi.ufs_dsize = LFS_FSBTODB(sblock, lfs_sb_getsize(sblock));
    148  1.22  dholland 	if (lfs_sb_getversion(sblock) == 1)
    149  1.21  dholland 		ufsi.ufs_dsize = lfs_sb_getsize(sblock) >> lfs_sb_getblktodb(sblock);
    150  1.20  dholland 	ufsi.ufs_bsize = lfs_sb_getbsize(sblock);
    151  1.21  dholland 	ufsi.ufs_bshift = lfs_sb_getbshift(sblock);
    152  1.20  dholland 	ufsi.ufs_fsize = lfs_sb_getfsize(sblock);
    153  1.20  dholland 	ufsi.ufs_frag = lfs_sb_getfrag(sblock);
    154  1.21  dholland 	ufsi.ufs_fsatoda = lfs_sb_getfsbtodb(sblock);
    155  1.22  dholland 	if (lfs_sb_getversion(sblock) == 1)
    156   1.3  perseant 		ufsi.ufs_fsatoda = 0;
    157  1.21  dholland 	ufsi.ufs_nindir = lfs_sb_getnindir(sblock);
    158  1.21  dholland 	ufsi.ufs_inopb = lfs_sb_getinopb(sblock);
    159  1.21  dholland 	ufsi.ufs_maxsymlinklen = lfs_sb_getmaxsymlinklen(sblock);
    160  1.21  dholland 	ufsi.ufs_bmask = ~(lfs_sb_getbmask(sblock));
    161  1.21  dholland 	ufsi.ufs_qbmask = lfs_sb_getbmask(sblock);
    162  1.21  dholland 	ufsi.ufs_fmask = ~(lfs_sb_getffmask(sblock));
    163  1.21  dholland 	ufsi.ufs_qfmask = lfs_sb_getffmask(sblock);
    164   1.1  perseant 
    165  1.21  dholland 	dev_bsize = lfs_sb_getbsize(sblock) >> lfs_sb_getblktodb(sblock);
    166   1.1  perseant 
    167   1.1  perseant 	return &ufsi;
    168   1.1  perseant }
    169   1.1  perseant 
    170   1.1  perseant ino_t
    171   1.1  perseant fs_maxino(void)
    172   1.1  perseant {
    173  1.20  dholland 	return ((getino(lfs_sb_getifile(sblock))->dp1.di_size
    174  1.20  dholland 		   - (lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock))
    175  1.20  dholland 		   * lfs_sb_getbsize(sblock))
    176  1.20  dholland 		  / lfs_sb_getbsize(sblock)) * lfs_sb_getifpb(sblock) - 1;
    177   1.1  perseant }
    178   1.1  perseant 
    179   1.7      fvdl void
    180   1.7      fvdl fs_mapinodes(ino_t maxino, u_int64_t *tapesz, int *anydirskipped)
    181   1.7      fvdl {
    182   1.7      fvdl 	ino_t ino;
    183   1.7      fvdl 
    184  1.17  dholland 	for (ino = ULFS_ROOTINO; ino < maxino; ino++)
    185   1.7      fvdl 		mapfileino(ino, tapesz, anydirskipped);
    186   1.7      fvdl }
    187   1.7      fvdl 
    188   1.1  perseant /*
    189   1.1  perseant  * XXX KS - I know there's a better way to do this.
    190   1.1  perseant  */
    191  1.17  dholland #define BASE_SINDIR (ULFS_NDADDR)
    192  1.19  dholland #define BASE_DINDIR (ULFS_NDADDR+LFS_NINDIR(fs))
    193  1.19  dholland #define BASE_TINDIR (ULFS_NDADDR+LFS_NINDIR(fs)+LFS_NINDIR(fs)*LFS_NINDIR(fs))
    194   1.1  perseant 
    195  1.19  dholland #define D_UNITS (LFS_NINDIR(fs))
    196  1.19  dholland #define T_UNITS (LFS_NINDIR(fs)*LFS_NINDIR(fs))
    197   1.1  perseant 
    198   1.1  perseant static daddr_t
    199  1.25  dholland lfs_bmap(struct lfs *fs, union lfs_dinode *idinode, daddr_t lbn)
    200   1.1  perseant {
    201  1.11     lukem 	daddr_t residue, up;
    202   1.1  perseant 	int off=0;
    203   1.1  perseant 	char bp[MAXBSIZE];
    204  1.11     lukem 
    205  1.11     lukem 	up = UNASSIGNED;	/* XXXGCC -Wunitialized [sh3] */
    206   1.1  perseant 
    207  1.25  dholland 	if(lbn > 0 && lbn > lfs_lblkno(fs, lfs_dino_getsize(fs, idinode))) {
    208   1.1  perseant 		return UNASSIGNED;
    209   1.1  perseant 	}
    210   1.1  perseant 	/*
    211   1.1  perseant 	 * Indirect blocks: if it is a first-level indirect, pull its
    212   1.1  perseant 	 * address from the inode; otherwise, call ourselves to find the
    213   1.1  perseant 	 * address of the parent indirect block, and load that to find
    214   1.1  perseant 	 * the desired address.
    215   1.1  perseant 	 */
    216   1.1  perseant 	if(lbn < 0) {
    217   1.1  perseant 		lbn *= -1;
    218  1.17  dholland 		if (lbn == ULFS_NDADDR) {
    219   1.1  perseant 			/* printf("lbn %d: single indir base\n", -lbn); */
    220  1.25  dholland 			return lfs_dino_getib(fs, idinode, 0); /* single indirect */
    221   1.1  perseant 		} else if(lbn == BASE_DINDIR+1) {
    222   1.1  perseant 			/* printf("lbn %d: double indir base\n", -lbn); */
    223  1.25  dholland 			return lfs_dino_getib(fs, idinode, 1); /* double indirect */
    224   1.1  perseant 		} else if(lbn == BASE_TINDIR+2) {
    225   1.1  perseant 			/* printf("lbn %d: triple indir base\n", -lbn); */
    226  1.25  dholland 			return lfs_dino_getib(fs, idinode, 2); /* triple indirect */
    227   1.1  perseant 		}
    228   1.1  perseant 
    229   1.1  perseant 		/*
    230   1.1  perseant 		 * Find the immediate parent. This is essentially finding the
    231   1.1  perseant 		 * residue of modulus, and then rounding accordingly.
    232   1.1  perseant 		 */
    233  1.19  dholland 		residue = (lbn-ULFS_NDADDR) % LFS_NINDIR(fs);
    234   1.1  perseant 		if(residue == 1) {
    235   1.1  perseant 			/* Double indirect.  Parent is the triple. */
    236  1.25  dholland 			up = lfs_dino_getib(fs, idinode, 2);
    237  1.19  dholland 			off = (lbn-2-BASE_TINDIR)/(LFS_NINDIR(fs)*LFS_NINDIR(fs));
    238   1.1  perseant 			if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
    239   1.1  perseant 				return UNASSIGNED;
    240   1.1  perseant 			/* printf("lbn %d: parent is the triple\n", -lbn); */
    241  1.20  dholland 			bread(LFS_FSBTODB(sblock, up), bp, lfs_sb_getbsize(sblock));
    242   1.6      fvdl 			/* XXX ondisk32 */
    243   1.6      fvdl 			return (daddr_t)((int32_t *)bp)[off];
    244   1.1  perseant 		} else /* residue == 0 */ {
    245   1.1  perseant 			/* Single indirect.  Two cases. */
    246   1.1  perseant 			if(lbn < BASE_TINDIR) {
    247   1.1  perseant 				/* Parent is the double, simple */
    248   1.1  perseant 				up = -(BASE_DINDIR) - 1;
    249   1.1  perseant 				off = (lbn-BASE_DINDIR) / D_UNITS;
    250   1.1  perseant 				/* printf("lbn %d: parent is %d/%d\n", -lbn, up,off); */
    251   1.1  perseant 			} else {
    252   1.1  perseant 				/* Ancestor is the triple, more complex */
    253   1.1  perseant 				up = ((lbn-BASE_TINDIR) / T_UNITS)
    254   1.1  perseant 					* T_UNITS + BASE_TINDIR + 1;
    255   1.1  perseant 				off = (lbn/D_UNITS) - (up/D_UNITS);
    256   1.1  perseant 				up = -up;
    257   1.1  perseant 				/* printf("lbn %d: parent is %d/%d\n", -lbn, up,off); */
    258   1.1  perseant 			}
    259   1.1  perseant 		}
    260   1.1  perseant 	} else {
    261   1.1  perseant 		/* Direct block.  Its parent must be a single indirect. */
    262  1.17  dholland 		if (lbn < ULFS_NDADDR)
    263  1.25  dholland 			return lfs_dino_getdb(fs, idinode, lbn);
    264   1.1  perseant 		else {
    265   1.1  perseant 			/* Parent is an indirect block. */
    266  1.17  dholland 			up = -(((lbn-ULFS_NDADDR) / D_UNITS) * D_UNITS + ULFS_NDADDR);
    267  1.17  dholland 			off = (lbn-ULFS_NDADDR) % D_UNITS;
    268   1.1  perseant 			/* printf("lbn %d: parent is %d/%d\n", lbn,up,off); */
    269   1.1  perseant 		}
    270   1.1  perseant 	}
    271   1.1  perseant 	up = lfs_bmap(fs,idinode,up);
    272   1.1  perseant 	if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
    273   1.1  perseant 		return UNASSIGNED;
    274  1.20  dholland 	bread(LFS_FSBTODB(sblock, up), bp, lfs_sb_getbsize(sblock));
    275   1.6      fvdl 	/* XXX ondisk32 */
    276   1.6      fvdl 	return (daddr_t)((int32_t *)bp)[off];
    277   1.1  perseant }
    278   1.1  perseant 
    279  1.24  dholland static IFILE *
    280   1.1  perseant lfs_ientry(ino_t ino)
    281   1.1  perseant {
    282  1.24  dholland 	static char ifileblock[MAXBSIZE];
    283   1.7      fvdl 	static daddr_t ifblkno;
    284   1.7      fvdl 	daddr_t lbn;
    285   1.7      fvdl 	daddr_t blkno;
    286   1.7      fvdl 	union dinode *dp;
    287  1.25  dholland 	union lfs_dinode *ldp;
    288  1.24  dholland 	unsigned index;
    289   1.1  perseant 
    290  1.20  dholland 	lbn = ino/lfs_sb_getifpb(sblock) + lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock);
    291  1.20  dholland 	dp = getino(lfs_sb_getifile(sblock));
    292  1.25  dholland 	/* XXX this is foolish */
    293  1.25  dholland 	if (sblock->lfs_is64) {
    294  1.25  dholland 		ldp = (union lfs_dinode *)&dp->dlp64;
    295  1.25  dholland 	} else {
    296  1.25  dholland 		ldp = (union lfs_dinode *)&dp->dlp32;
    297  1.25  dholland 	}
    298  1.25  dholland 	blkno = lfs_bmap(sblock, ldp, lbn);
    299   1.7      fvdl 	if (blkno != ifblkno)
    300  1.24  dholland 		bread(LFS_FSBTODB(sblock, blkno), ifileblock,
    301  1.20  dholland 		    lfs_sb_getbsize(sblock));
    302  1.24  dholland 	index = ino % lfs_sb_getifpb(sblock);
    303  1.24  dholland 	if (sblock->lfs_is64) {
    304  1.24  dholland 		return (IFILE *) &((IFILE64 *)ifileblock)[index];
    305  1.24  dholland 	} else if (lfs_sb_getversion(sblock) > 1) {
    306  1.24  dholland 		return (IFILE *) &((IFILE32 *)ifileblock)[index];
    307  1.24  dholland 	} else {
    308  1.24  dholland 		return (IFILE *) &((IFILE_V1 *)ifileblock)[index];
    309  1.24  dholland 	}
    310   1.1  perseant }
    311   1.1  perseant 
    312   1.1  perseant /* Search a block for a specific dinode. */
    313  1.25  dholland static union lfs_dinode *
    314  1.25  dholland lfs_ifind(struct lfs *fs, ino_t ino, void *block)
    315   1.1  perseant {
    316  1.25  dholland 	union lfs_dinode *dip;
    317  1.25  dholland 	unsigned i, num;
    318   1.1  perseant 
    319  1.25  dholland 	num = LFS_INOPB(fs);
    320  1.25  dholland 	for (i = num; i-- > 0; ) {
    321  1.25  dholland 		dip = DINO_IN_BLOCK(fs, block, i);
    322  1.25  dholland 		if (lfs_dino_getinumber(fs, dip) == ino)
    323  1.25  dholland 			return dip;
    324  1.25  dholland 	}
    325   1.1  perseant 	return NULL;
    326   1.1  perseant }
    327   1.1  perseant 
    328   1.7      fvdl union dinode *
    329   1.9     perry getino(ino_t inum)
    330   1.1  perseant {
    331   1.1  perseant 	static daddr_t inoblkno;
    332   1.1  perseant 	daddr_t blkno;
    333  1.25  dholland 	static union {
    334  1.25  dholland 		char space[MAXBSIZE];
    335  1.25  dholland 		struct lfs64_dinode u_64[MAXBSIZE/sizeof(struct lfs64_dinode)];
    336  1.25  dholland 		struct lfs32_dinode u_32[MAXBSIZE/sizeof(struct lfs32_dinode)];
    337  1.25  dholland 	} inoblock;
    338  1.18  christos 	static union dinode ifile_dinode; /* XXX fill this in */
    339  1.18  christos 	static union dinode empty_dinode; /* Always stays zeroed */
    340  1.25  dholland 	union lfs_dinode *dp;
    341  1.25  dholland 	ino_t inum2;
    342   1.1  perseant 
    343  1.20  dholland 	if(inum == lfs_sb_getifile(sblock)) {
    344   1.1  perseant 		/* Load the ifile inode if not already */
    345  1.25  dholland 		inum2 = sblock->lfs_is64 ?
    346  1.25  dholland 			ifile_dinode.dlp64.di_inumber :
    347  1.25  dholland 			ifile_dinode.dlp32.di_inumber;
    348  1.25  dholland 		if (inum2 == 0) {
    349  1.20  dholland 			blkno = lfs_sb_getidaddr(sblock);
    350  1.25  dholland 			bread(LFS_FSBTODB(sblock, blkno), inoblock.space,
    351  1.20  dholland 				(int)lfs_sb_getbsize(sblock));
    352  1.25  dholland 			dp = lfs_ifind(sblock, inum, inoblock.space);
    353  1.25  dholland 			/* Structure copy */
    354  1.25  dholland 			if (sblock->lfs_is64) {
    355  1.25  dholland 				ifile_dinode.dlp64 = dp->u_64;
    356  1.25  dholland 			} else {
    357  1.25  dholland 				ifile_dinode.dlp32 = dp->u_32;
    358  1.25  dholland 			}
    359   1.1  perseant 		}
    360  1.18  christos 		return &ifile_dinode;
    361   1.1  perseant 	}
    362   1.1  perseant 
    363   1.1  perseant 	curino = inum;
    364  1.24  dholland 	blkno = lfs_if_getdaddr(sblock, lfs_ientry(inum));
    365   1.1  perseant 	if(blkno == LFS_UNUSED_DADDR)
    366  1.18  christos 		return &empty_dinode;
    367   1.1  perseant 
    368   1.1  perseant 	if(blkno != inoblkno) {
    369  1.25  dholland 		bread(LFS_FSBTODB(sblock, blkno), inoblock.space,
    370  1.20  dholland 			(int)lfs_sb_getbsize(sblock));
    371   1.1  perseant 	}
    372  1.25  dholland 	return (void *)lfs_ifind(sblock, inum, inoblock.space);
    373   1.1  perseant }
    374  1.12  perseant 
    375  1.12  perseant /*
    376  1.12  perseant  * Tell the filesystem not to overwrite any currently dirty segments
    377  1.12  perseant  * until we are finished.  (It may still write into clean segments, of course,
    378  1.12  perseant  * since we're not using those.)  This is only called when dump_lfs is called
    379  1.12  perseant  * with -X, i.e. we are working on a mounted filesystem.
    380  1.12  perseant  */
    381  1.12  perseant static int root_fd = -1;
    382  1.12  perseant char *wrap_mpname;
    383  1.12  perseant 
    384  1.12  perseant int
    385  1.12  perseant lfs_wrap_stop(char *mpname)
    386  1.12  perseant {
    387  1.12  perseant 	int waitfor = 0;
    388  1.12  perseant 
    389  1.12  perseant 	root_fd = open(mpname, O_RDONLY, 0);
    390  1.12  perseant 	if (root_fd < 0)
    391  1.12  perseant 		return -1;
    392  1.12  perseant 	wrap_mpname = mpname;
    393  1.12  perseant 	fcntl(root_fd, LFCNREWIND, -1); /* Ignore return value */
    394  1.12  perseant 	if (fcntl(root_fd, LFCNWRAPSTOP, &waitfor) < 0) {
    395  1.12  perseant 		perror("LFCNWRAPSTOP");
    396  1.12  perseant 		return -1;
    397  1.12  perseant 	}
    398  1.12  perseant 	msg("Disabled log wrap on %s\n", mpname);
    399  1.12  perseant 	return 0;
    400  1.12  perseant }
    401  1.12  perseant 
    402  1.12  perseant /*
    403  1.12  perseant  * Allow the filesystem to continue normal operation.
    404  1.12  perseant  * This would happen anyway when we exit; we do it explicitly here
    405  1.12  perseant  * to show the message, for the user's benefit.
    406  1.12  perseant  */
    407  1.12  perseant void
    408  1.12  perseant lfs_wrap_go(void)
    409  1.12  perseant {
    410  1.12  perseant 	int waitfor = 0;
    411  1.12  perseant 
    412  1.12  perseant 	if (root_fd < 0)
    413  1.12  perseant 		return;
    414  1.12  perseant 
    415  1.13  perseant 	fcntl(root_fd, LFCNWRAPGO, &waitfor);
    416  1.12  perseant 	close(root_fd);
    417  1.12  perseant 	root_fd = -1;
    418  1.12  perseant 	msg("Re-enabled log wrap on %s\n", wrap_mpname);
    419  1.12  perseant }
    420