Home | History | Annotate | Line # | Download | only in dump
ffs_inode.c revision 1.10
      1 /*	$NetBSD: ffs_inode.c,v 1.10 2001/12/23 12:54:53 lukem Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1980, 1991, 1993, 1994
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 #ifndef lint
     38 __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
     39 	The Regents of the University of California.  All rights reserved.\n");
     40 #endif /* not lint */
     41 
     42 #ifndef lint
     43 __RCSID("$NetBSD: ffs_inode.c,v 1.10 2001/12/23 12:54:53 lukem Exp $");
     44 #endif /* not lint */
     45 
     46 #include <sys/param.h>
     47 #include <sys/time.h>
     48 #include <sys/stat.h>
     49 #include <ufs/ufs/dir.h>
     50 #include <ufs/ufs/dinode.h>
     51 #include <ufs/ffs/fs.h>
     52 #include <ufs/ffs/ffs_extern.h>
     53 
     54 #include <protocols/dumprestore.h>
     55 
     56 #include <ctype.h>
     57 #include <errno.h>
     58 #include <fts.h>
     59 #include <stdio.h>
     60 #include <string.h>
     61 #include <unistd.h>
     62 
     63 #include "dump.h"
     64 
     65 #ifndef SBOFF
     66 #define SBOFF (SBLOCK * DEV_BSIZE)
     67 #endif
     68 
     69 struct fs *sblock;
     70 
     71 /*
     72  * Read the superblock from disk, and check its magic number.
     73  * Determine whether byte-swapping needs to be done on this file system.
     74  */
     75 int
     76 fs_read_sblock(char *superblock)
     77 {
     78 	int ns = 0;
     79 
     80 	sblock = (struct fs *)superblock;
     81 	rawread(SBOFF, (char *) superblock, SBSIZE);
     82 	if (sblock->fs_magic != FS_MAGIC) {
     83 		if (sblock->fs_magic == bswap32(FS_MAGIC)) {
     84 			ffs_sb_swap(sblock, sblock);
     85 			ns = 1;
     86 		} else
     87 			quit("bad sblock magic number\n");
     88 	}
     89 	return ns;
     90 }
     91 
     92 /*
     93  * Fill in the ufsi struct, as well as the maxino and dev_bsize global
     94  * variables.
     95  */
     96 struct ufsi *
     97 fs_parametrize(void)
     98 {
     99 	static struct ufsi ufsi;
    100 
    101 #ifdef FS_44INODEFMT
    102 	if (sblock->fs_inodefmt >= FS_44INODEFMT) {
    103 		spcl.c_flags = iswap32(iswap32(spcl.c_flags) | DR_NEWINODEFMT);
    104 	} else {
    105 		/*
    106 		 * Determine parameters for older file systems. From
    107 		 *	/sys/ufs/ffs/ffs_vfsops.c::ffs_oldfscompat()
    108 		 *
    109 		 * XXX: not sure if other variables (fs_npsect, fs_interleave,
    110 		 * fs_nrpos, fs_maxfilesize) need to be fudged too.
    111 		 */
    112 		sblock->fs_qbmask = ~sblock->fs_bmask;
    113 		sblock->fs_qfmask = ~sblock->fs_fmask;
    114 	}
    115 #endif
    116 
    117 	/* Fill out ufsi struct */
    118 	ufsi.ufs_dsize = fsbtodb(sblock,sblock->fs_size);
    119 	ufsi.ufs_bsize = sblock->fs_bsize;
    120 	ufsi.ufs_bshift = sblock->fs_bshift;
    121 	ufsi.ufs_fsize = sblock->fs_fsize;
    122 	ufsi.ufs_frag = sblock->fs_frag;
    123 	ufsi.ufs_fsatoda = sblock->fs_fsbtodb;
    124 	ufsi.ufs_nindir = sblock->fs_nindir;
    125 	ufsi.ufs_inopb = sblock->fs_inopb;
    126 	ufsi.ufs_maxsymlinklen = sblock->fs_maxsymlinklen;
    127 	ufsi.ufs_bmask = sblock->fs_bmask;
    128 	ufsi.ufs_fmask = sblock->fs_fmask;
    129 	ufsi.ufs_qbmask = sblock->fs_qbmask;
    130 	ufsi.ufs_qfmask = sblock->fs_qfmask;
    131 
    132 	dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
    133 
    134 	return &ufsi;
    135 }
    136 
    137 ino_t
    138 fs_maxino(void)
    139 {
    140 
    141 	return sblock->fs_ipg * sblock->fs_ncg;
    142 }
    143 
    144 struct dinode *
    145 getino(ino_t inum)
    146 {
    147 	static daddr_t minino, maxino;
    148 	static struct dinode inoblock[MAXINOPB];
    149 	int i;
    150 
    151 	curino = inum;
    152 	if (inum >= minino && inum < maxino)
    153 		return (&inoblock[inum - minino]);
    154 	bread(fsatoda(ufsib, ino_to_fsba(sblock, inum)), (char *)inoblock,
    155 	    (int)ufsib->ufs_bsize);
    156 	if (needswap)
    157 		for (i = 0; i < MAXINOPB; i++)
    158 			ffs_dinode_swap(&inoblock[i], &inoblock[i]);
    159 	minino = inum - (inum % INOPB(sblock));
    160 	maxino = minino + INOPB(sblock);
    161 	return (&inoblock[inum - minino]);
    162 }
    163