Home | History | Annotate | Line # | Download | only in dump_lfs
lfs_inode.c revision 1.28
      1  1.28  dholland /*      $NetBSD: lfs_inode.c,v 1.28 2015/10/15 06:25:12 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.28  dholland __RCSID("$NetBSD: lfs_inode.c,v 1.28 2015/10/15 06:25:12 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.28  dholland 	/*
     77  1.28  dholland 	 * XXX this should not be assuming that the in-memory
     78  1.28  dholland 	 * superblock has the on-disk superblock at the front of the
     79  1.28  dholland 	 * structure.
     80  1.28  dholland 	 */
     81  1.15  christos 	union {
     82  1.15  christos 		char tbuf[LFS_SBPAD];
     83  1.15  christos 		struct lfs lfss;
     84  1.15  christos 	} u;
     85  1.15  christos 
     86   1.3  perseant 	off_t sboff = LFS_LABELPAD;
     87   1.1  perseant 
     88   1.4     lukem 	sblock = (struct lfs *)superblock;
     89   1.3  perseant 	while(1) {
     90   1.3  perseant 		rawread(sboff, (char *) sblock, LFS_SBPAD);
     91  1.28  dholland 		switch (sblock->lfs_dlfs_u.u_32.dlfs_magic) {
     92  1.28  dholland 		    case LFS_MAGIC:
     93  1.28  dholland 			sblock->lfs_is64 = false;
     94  1.28  dholland 			sblock->lfs_dobyteswap = false;
     95  1.28  dholland 			break;
     96  1.28  dholland 		    case LFS_MAGIC_SWAPPED:
     97  1.28  dholland 			sblock->lfs_is64 = false;
     98  1.28  dholland 			sblock->lfs_dobyteswap = true;
     99  1.28  dholland 			break;
    100  1.28  dholland 		    case LFS64_MAGIC:
    101  1.28  dholland 			sblock->lfs_is64 = true;
    102  1.28  dholland 			sblock->lfs_dobyteswap = false;
    103  1.28  dholland 			break;
    104  1.28  dholland 		    case LFS64_MAGIC_SWAPPED:
    105  1.28  dholland 			sblock->lfs_is64 = true;
    106  1.28  dholland 			sblock->lfs_dobyteswap = true;
    107  1.28  dholland 			break;
    108  1.28  dholland 		    default:
    109  1.28  dholland 			quit("bad sblock magic number\n");
    110  1.28  dholland 			break;
    111   1.3  perseant 		}
    112  1.21  dholland 		if (lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 0)) != sboff) {
    113  1.21  dholland 			sboff = lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 0));
    114   1.3  perseant 			continue;
    115   1.3  perseant 		}
    116   1.3  perseant 		break;
    117   1.3  perseant 	}
    118   1.3  perseant 
    119   1.3  perseant 	/*
    120   1.3  perseant 	 * Read the secondary and take the older of the two
    121   1.3  perseant 	 */
    122  1.21  dholland 	rawread(lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 1)), u.tbuf,
    123  1.15  christos 	    sizeof(u.tbuf));
    124  1.28  dholland 
    125  1.28  dholland 	if (u.lfss.lfs_dlfs_u.u_32.dlfs_magic !=
    126  1.28  dholland 	    sblock->lfs_dlfs_u.u_32.dlfs_magic) {
    127  1.28  dholland 		msg("Warning: secondary superblock at 0x%" PRIx64 " mismatched or wrong magic\n",
    128  1.21  dholland 			LFS_FSBTODB(sblock, (off_t)lfs_sb_getsboff(sblock, 1)));
    129   1.3  perseant 	} else {
    130  1.28  dholland 		u.lfss.lfs_is64 = sblock->lfs_is64;
    131  1.28  dholland 		u.lfss.lfs_dobyteswap = sblock->lfs_dobyteswap;
    132  1.28  dholland 
    133  1.22  dholland 		if (lfs_sb_getversion(sblock) > 1) {
    134  1.20  dholland 			if (lfs_sb_getserial(&u.lfss) < lfs_sb_getserial(sblock)) {
    135  1.15  christos 				memcpy(sblock, u.tbuf, sizeof(u.tbuf));
    136  1.21  dholland 				sboff = lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 1));
    137   1.3  perseant 			}
    138   1.3  perseant 		} else {
    139  1.20  dholland 			if (lfs_sb_getotstamp(&u.lfss) < lfs_sb_getotstamp(sblock)) {
    140  1.15  christos 				memcpy(sblock, u.tbuf, sizeof(u.tbuf));
    141  1.21  dholland 				sboff = lfs_fsbtob(sblock, (off_t)lfs_sb_getsboff(sblock, 1));
    142   1.3  perseant 			}
    143   1.3  perseant 		}
    144   1.3  perseant 	}
    145   1.3  perseant 	if (sboff != LFS_SBPAD) {
    146   1.3  perseant 		msg("Using superblock at alternate location 0x%lx\n",
    147   1.3  perseant 		    (unsigned long)(btodb(sboff)));
    148   1.1  perseant 	}
    149   1.3  perseant 
    150  1.28  dholland 	/* ugh */
    151  1.28  dholland 	is_ufs2 = sblock->lfs_is64;
    152  1.28  dholland 
    153  1.28  dholland 	/*
    154  1.28  dholland 	 * XXX for now dump won't work on lfs64 because of the 64-bit
    155  1.28  dholland 	 * inodes in directories. dump needs more abstraction.
    156  1.28  dholland 	 */
    157  1.28  dholland 	if (sblock->lfs_is64) {
    158  1.28  dholland 		quit("LFS64 directory entries not supported yet");
    159  1.28  dholland 	}
    160  1.28  dholland 
    161  1.28  dholland 	return sblock->lfs_dobyteswap;
    162   1.1  perseant }
    163   1.1  perseant 
    164   1.1  perseant /*
    165   1.1  perseant  * Fill in the ufsi struct, as well as the maxino and dev_bsize global
    166   1.1  perseant  * variables.
    167   1.1  perseant  */
    168   1.1  perseant struct ufsi *
    169   1.1  perseant fs_parametrize(void)
    170   1.1  perseant {
    171   1.1  perseant 	static struct ufsi ufsi;
    172   1.1  perseant 
    173   1.2  perseant 	spcl.c_flags = iswap32(iswap32(spcl.c_flags) | DR_NEWINODEFMT);
    174   1.2  perseant 
    175  1.20  dholland 	ufsi.ufs_dsize = LFS_FSBTODB(sblock, lfs_sb_getsize(sblock));
    176  1.22  dholland 	if (lfs_sb_getversion(sblock) == 1)
    177  1.21  dholland 		ufsi.ufs_dsize = lfs_sb_getsize(sblock) >> lfs_sb_getblktodb(sblock);
    178  1.20  dholland 	ufsi.ufs_bsize = lfs_sb_getbsize(sblock);
    179  1.21  dholland 	ufsi.ufs_bshift = lfs_sb_getbshift(sblock);
    180  1.20  dholland 	ufsi.ufs_fsize = lfs_sb_getfsize(sblock);
    181  1.20  dholland 	ufsi.ufs_frag = lfs_sb_getfrag(sblock);
    182  1.21  dholland 	ufsi.ufs_fsatoda = lfs_sb_getfsbtodb(sblock);
    183  1.22  dholland 	if (lfs_sb_getversion(sblock) == 1)
    184   1.3  perseant 		ufsi.ufs_fsatoda = 0;
    185  1.21  dholland 	ufsi.ufs_nindir = lfs_sb_getnindir(sblock);
    186  1.21  dholland 	ufsi.ufs_inopb = lfs_sb_getinopb(sblock);
    187  1.21  dholland 	ufsi.ufs_maxsymlinklen = lfs_sb_getmaxsymlinklen(sblock);
    188  1.21  dholland 	ufsi.ufs_bmask = ~(lfs_sb_getbmask(sblock));
    189  1.21  dholland 	ufsi.ufs_qbmask = lfs_sb_getbmask(sblock);
    190  1.21  dholland 	ufsi.ufs_fmask = ~(lfs_sb_getffmask(sblock));
    191  1.21  dholland 	ufsi.ufs_qfmask = lfs_sb_getffmask(sblock);
    192   1.1  perseant 
    193  1.21  dholland 	dev_bsize = lfs_sb_getbsize(sblock) >> lfs_sb_getblktodb(sblock);
    194   1.1  perseant 
    195   1.1  perseant 	return &ufsi;
    196   1.1  perseant }
    197   1.1  perseant 
    198   1.1  perseant ino_t
    199   1.1  perseant fs_maxino(void)
    200   1.1  perseant {
    201  1.26  dholland 	return ((getino(LFS_IFILE_INUM)->dp1.di_size
    202  1.20  dholland 		   - (lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock))
    203  1.20  dholland 		   * lfs_sb_getbsize(sblock))
    204  1.20  dholland 		  / lfs_sb_getbsize(sblock)) * lfs_sb_getifpb(sblock) - 1;
    205   1.1  perseant }
    206   1.1  perseant 
    207   1.7      fvdl void
    208   1.7      fvdl fs_mapinodes(ino_t maxino, u_int64_t *tapesz, int *anydirskipped)
    209   1.7      fvdl {
    210   1.7      fvdl 	ino_t ino;
    211   1.7      fvdl 
    212  1.17  dholland 	for (ino = ULFS_ROOTINO; ino < maxino; ino++)
    213   1.7      fvdl 		mapfileino(ino, tapesz, anydirskipped);
    214   1.7      fvdl }
    215   1.7      fvdl 
    216   1.1  perseant /*
    217   1.1  perseant  * XXX KS - I know there's a better way to do this.
    218   1.1  perseant  */
    219  1.17  dholland #define BASE_SINDIR (ULFS_NDADDR)
    220  1.19  dholland #define BASE_DINDIR (ULFS_NDADDR+LFS_NINDIR(fs))
    221  1.19  dholland #define BASE_TINDIR (ULFS_NDADDR+LFS_NINDIR(fs)+LFS_NINDIR(fs)*LFS_NINDIR(fs))
    222   1.1  perseant 
    223  1.19  dholland #define D_UNITS (LFS_NINDIR(fs))
    224  1.19  dholland #define T_UNITS (LFS_NINDIR(fs)*LFS_NINDIR(fs))
    225   1.1  perseant 
    226   1.1  perseant static daddr_t
    227  1.25  dholland lfs_bmap(struct lfs *fs, union lfs_dinode *idinode, daddr_t lbn)
    228   1.1  perseant {
    229  1.11     lukem 	daddr_t residue, up;
    230   1.1  perseant 	int off=0;
    231   1.1  perseant 	char bp[MAXBSIZE];
    232  1.11     lukem 
    233  1.11     lukem 	up = UNASSIGNED;	/* XXXGCC -Wunitialized [sh3] */
    234   1.1  perseant 
    235  1.25  dholland 	if(lbn > 0 && lbn > lfs_lblkno(fs, lfs_dino_getsize(fs, idinode))) {
    236   1.1  perseant 		return UNASSIGNED;
    237   1.1  perseant 	}
    238   1.1  perseant 	/*
    239   1.1  perseant 	 * Indirect blocks: if it is a first-level indirect, pull its
    240   1.1  perseant 	 * address from the inode; otherwise, call ourselves to find the
    241   1.1  perseant 	 * address of the parent indirect block, and load that to find
    242   1.1  perseant 	 * the desired address.
    243   1.1  perseant 	 */
    244   1.1  perseant 	if(lbn < 0) {
    245   1.1  perseant 		lbn *= -1;
    246  1.17  dholland 		if (lbn == ULFS_NDADDR) {
    247   1.1  perseant 			/* printf("lbn %d: single indir base\n", -lbn); */
    248  1.25  dholland 			return lfs_dino_getib(fs, idinode, 0); /* single indirect */
    249   1.1  perseant 		} else if(lbn == BASE_DINDIR+1) {
    250   1.1  perseant 			/* printf("lbn %d: double indir base\n", -lbn); */
    251  1.25  dholland 			return lfs_dino_getib(fs, idinode, 1); /* double indirect */
    252   1.1  perseant 		} else if(lbn == BASE_TINDIR+2) {
    253   1.1  perseant 			/* printf("lbn %d: triple indir base\n", -lbn); */
    254  1.25  dholland 			return lfs_dino_getib(fs, idinode, 2); /* triple indirect */
    255   1.1  perseant 		}
    256   1.1  perseant 
    257   1.1  perseant 		/*
    258   1.1  perseant 		 * Find the immediate parent. This is essentially finding the
    259   1.1  perseant 		 * residue of modulus, and then rounding accordingly.
    260   1.1  perseant 		 */
    261  1.19  dholland 		residue = (lbn-ULFS_NDADDR) % LFS_NINDIR(fs);
    262   1.1  perseant 		if(residue == 1) {
    263   1.1  perseant 			/* Double indirect.  Parent is the triple. */
    264  1.25  dholland 			up = lfs_dino_getib(fs, idinode, 2);
    265  1.19  dholland 			off = (lbn-2-BASE_TINDIR)/(LFS_NINDIR(fs)*LFS_NINDIR(fs));
    266   1.1  perseant 			if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
    267   1.1  perseant 				return UNASSIGNED;
    268   1.1  perseant 			/* printf("lbn %d: parent is the triple\n", -lbn); */
    269  1.20  dholland 			bread(LFS_FSBTODB(sblock, up), bp, lfs_sb_getbsize(sblock));
    270  1.27  dholland 			return lfs_iblock_get(fs, bp, off);
    271   1.1  perseant 		} else /* residue == 0 */ {
    272   1.1  perseant 			/* Single indirect.  Two cases. */
    273   1.1  perseant 			if(lbn < BASE_TINDIR) {
    274   1.1  perseant 				/* Parent is the double, simple */
    275   1.1  perseant 				up = -(BASE_DINDIR) - 1;
    276   1.1  perseant 				off = (lbn-BASE_DINDIR) / D_UNITS;
    277   1.1  perseant 				/* printf("lbn %d: parent is %d/%d\n", -lbn, up,off); */
    278   1.1  perseant 			} else {
    279   1.1  perseant 				/* Ancestor is the triple, more complex */
    280   1.1  perseant 				up = ((lbn-BASE_TINDIR) / T_UNITS)
    281   1.1  perseant 					* T_UNITS + BASE_TINDIR + 1;
    282   1.1  perseant 				off = (lbn/D_UNITS) - (up/D_UNITS);
    283   1.1  perseant 				up = -up;
    284   1.1  perseant 				/* printf("lbn %d: parent is %d/%d\n", -lbn, up,off); */
    285   1.1  perseant 			}
    286   1.1  perseant 		}
    287   1.1  perseant 	} else {
    288   1.1  perseant 		/* Direct block.  Its parent must be a single indirect. */
    289  1.17  dholland 		if (lbn < ULFS_NDADDR)
    290  1.25  dholland 			return lfs_dino_getdb(fs, idinode, lbn);
    291   1.1  perseant 		else {
    292   1.1  perseant 			/* Parent is an indirect block. */
    293  1.17  dholland 			up = -(((lbn-ULFS_NDADDR) / D_UNITS) * D_UNITS + ULFS_NDADDR);
    294  1.17  dholland 			off = (lbn-ULFS_NDADDR) % D_UNITS;
    295   1.1  perseant 			/* printf("lbn %d: parent is %d/%d\n", lbn,up,off); */
    296   1.1  perseant 		}
    297   1.1  perseant 	}
    298   1.1  perseant 	up = lfs_bmap(fs,idinode,up);
    299   1.1  perseant 	if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
    300   1.1  perseant 		return UNASSIGNED;
    301  1.20  dholland 	bread(LFS_FSBTODB(sblock, up), bp, lfs_sb_getbsize(sblock));
    302  1.27  dholland 	return lfs_iblock_get(fs, bp, off);
    303   1.1  perseant }
    304   1.1  perseant 
    305  1.24  dholland static IFILE *
    306   1.1  perseant lfs_ientry(ino_t ino)
    307   1.1  perseant {
    308  1.24  dholland 	static char ifileblock[MAXBSIZE];
    309   1.7      fvdl 	static daddr_t ifblkno;
    310   1.7      fvdl 	daddr_t lbn;
    311   1.7      fvdl 	daddr_t blkno;
    312   1.7      fvdl 	union dinode *dp;
    313  1.25  dholland 	union lfs_dinode *ldp;
    314  1.24  dholland 	unsigned index;
    315   1.1  perseant 
    316  1.20  dholland 	lbn = ino/lfs_sb_getifpb(sblock) + lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock);
    317  1.26  dholland 	dp = getino(LFS_IFILE_INUM);
    318  1.25  dholland 	/* XXX this is foolish */
    319  1.25  dholland 	if (sblock->lfs_is64) {
    320  1.25  dholland 		ldp = (union lfs_dinode *)&dp->dlp64;
    321  1.25  dholland 	} else {
    322  1.25  dholland 		ldp = (union lfs_dinode *)&dp->dlp32;
    323  1.25  dholland 	}
    324  1.25  dholland 	blkno = lfs_bmap(sblock, ldp, lbn);
    325   1.7      fvdl 	if (blkno != ifblkno)
    326  1.24  dholland 		bread(LFS_FSBTODB(sblock, blkno), ifileblock,
    327  1.20  dholland 		    lfs_sb_getbsize(sblock));
    328  1.24  dholland 	index = ino % lfs_sb_getifpb(sblock);
    329  1.24  dholland 	if (sblock->lfs_is64) {
    330  1.24  dholland 		return (IFILE *) &((IFILE64 *)ifileblock)[index];
    331  1.24  dholland 	} else if (lfs_sb_getversion(sblock) > 1) {
    332  1.24  dholland 		return (IFILE *) &((IFILE32 *)ifileblock)[index];
    333  1.24  dholland 	} else {
    334  1.24  dholland 		return (IFILE *) &((IFILE_V1 *)ifileblock)[index];
    335  1.24  dholland 	}
    336   1.1  perseant }
    337   1.1  perseant 
    338   1.1  perseant /* Search a block for a specific dinode. */
    339  1.25  dholland static union lfs_dinode *
    340  1.25  dholland lfs_ifind(struct lfs *fs, ino_t ino, void *block)
    341   1.1  perseant {
    342  1.25  dholland 	union lfs_dinode *dip;
    343  1.25  dholland 	unsigned i, num;
    344   1.1  perseant 
    345  1.25  dholland 	num = LFS_INOPB(fs);
    346  1.25  dholland 	for (i = num; i-- > 0; ) {
    347  1.25  dholland 		dip = DINO_IN_BLOCK(fs, block, i);
    348  1.25  dholland 		if (lfs_dino_getinumber(fs, dip) == ino)
    349  1.25  dholland 			return dip;
    350  1.25  dholland 	}
    351   1.1  perseant 	return NULL;
    352   1.1  perseant }
    353   1.1  perseant 
    354   1.7      fvdl union dinode *
    355   1.9     perry getino(ino_t inum)
    356   1.1  perseant {
    357   1.1  perseant 	static daddr_t inoblkno;
    358   1.1  perseant 	daddr_t blkno;
    359  1.25  dholland 	static union {
    360  1.25  dholland 		char space[MAXBSIZE];
    361  1.25  dholland 		struct lfs64_dinode u_64[MAXBSIZE/sizeof(struct lfs64_dinode)];
    362  1.25  dholland 		struct lfs32_dinode u_32[MAXBSIZE/sizeof(struct lfs32_dinode)];
    363  1.25  dholland 	} inoblock;
    364  1.18  christos 	static union dinode ifile_dinode; /* XXX fill this in */
    365  1.18  christos 	static union dinode empty_dinode; /* Always stays zeroed */
    366  1.25  dholland 	union lfs_dinode *dp;
    367  1.25  dholland 	ino_t inum2;
    368   1.1  perseant 
    369  1.26  dholland 	if (inum == LFS_IFILE_INUM) {
    370   1.1  perseant 		/* Load the ifile inode if not already */
    371  1.25  dholland 		inum2 = sblock->lfs_is64 ?
    372  1.25  dholland 			ifile_dinode.dlp64.di_inumber :
    373  1.25  dholland 			ifile_dinode.dlp32.di_inumber;
    374  1.25  dholland 		if (inum2 == 0) {
    375  1.20  dholland 			blkno = lfs_sb_getidaddr(sblock);
    376  1.25  dholland 			bread(LFS_FSBTODB(sblock, blkno), inoblock.space,
    377  1.20  dholland 				(int)lfs_sb_getbsize(sblock));
    378  1.25  dholland 			dp = lfs_ifind(sblock, inum, inoblock.space);
    379  1.25  dholland 			/* Structure copy */
    380  1.25  dholland 			if (sblock->lfs_is64) {
    381  1.25  dholland 				ifile_dinode.dlp64 = dp->u_64;
    382  1.25  dholland 			} else {
    383  1.25  dholland 				ifile_dinode.dlp32 = dp->u_32;
    384  1.25  dholland 			}
    385   1.1  perseant 		}
    386  1.18  christos 		return &ifile_dinode;
    387   1.1  perseant 	}
    388   1.1  perseant 
    389   1.1  perseant 	curino = inum;
    390  1.24  dholland 	blkno = lfs_if_getdaddr(sblock, lfs_ientry(inum));
    391   1.1  perseant 	if(blkno == LFS_UNUSED_DADDR)
    392  1.18  christos 		return &empty_dinode;
    393   1.1  perseant 
    394   1.1  perseant 	if(blkno != inoblkno) {
    395  1.25  dholland 		bread(LFS_FSBTODB(sblock, blkno), inoblock.space,
    396  1.20  dholland 			(int)lfs_sb_getbsize(sblock));
    397   1.1  perseant 	}
    398  1.25  dholland 	return (void *)lfs_ifind(sblock, inum, inoblock.space);
    399   1.1  perseant }
    400  1.12  perseant 
    401  1.12  perseant /*
    402  1.12  perseant  * Tell the filesystem not to overwrite any currently dirty segments
    403  1.12  perseant  * until we are finished.  (It may still write into clean segments, of course,
    404  1.12  perseant  * since we're not using those.)  This is only called when dump_lfs is called
    405  1.12  perseant  * with -X, i.e. we are working on a mounted filesystem.
    406  1.12  perseant  */
    407  1.12  perseant static int root_fd = -1;
    408  1.12  perseant char *wrap_mpname;
    409  1.12  perseant 
    410  1.12  perseant int
    411  1.12  perseant lfs_wrap_stop(char *mpname)
    412  1.12  perseant {
    413  1.12  perseant 	int waitfor = 0;
    414  1.12  perseant 
    415  1.12  perseant 	root_fd = open(mpname, O_RDONLY, 0);
    416  1.12  perseant 	if (root_fd < 0)
    417  1.12  perseant 		return -1;
    418  1.12  perseant 	wrap_mpname = mpname;
    419  1.12  perseant 	fcntl(root_fd, LFCNREWIND, -1); /* Ignore return value */
    420  1.12  perseant 	if (fcntl(root_fd, LFCNWRAPSTOP, &waitfor) < 0) {
    421  1.12  perseant 		perror("LFCNWRAPSTOP");
    422  1.12  perseant 		return -1;
    423  1.12  perseant 	}
    424  1.12  perseant 	msg("Disabled log wrap on %s\n", mpname);
    425  1.12  perseant 	return 0;
    426  1.12  perseant }
    427  1.12  perseant 
    428  1.12  perseant /*
    429  1.12  perseant  * Allow the filesystem to continue normal operation.
    430  1.12  perseant  * This would happen anyway when we exit; we do it explicitly here
    431  1.12  perseant  * to show the message, for the user's benefit.
    432  1.12  perseant  */
    433  1.12  perseant void
    434  1.12  perseant lfs_wrap_go(void)
    435  1.12  perseant {
    436  1.12  perseant 	int waitfor = 0;
    437  1.12  perseant 
    438  1.12  perseant 	if (root_fd < 0)
    439  1.12  perseant 		return;
    440  1.12  perseant 
    441  1.13  perseant 	fcntl(root_fd, LFCNWRAPGO, &waitfor);
    442  1.12  perseant 	close(root_fd);
    443  1.12  perseant 	root_fd = -1;
    444  1.12  perseant 	msg("Re-enabled log wrap on %s\n", wrap_mpname);
    445  1.12  perseant }
    446