Home | History | Annotate | Line # | Download | only in dump
ffs_inode.c revision 1.3.8.3
      1 /*      $NetBSD: ffs_inode.c,v 1.3.8.3 2002/01/17 13:55:20 he 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 #if 0
     44 static char sccsid[] = "@(#)main.c      8.6 (Berkeley) 5/1/95";
     45 #else
     46 __RCSID("$NetBSD: ffs_inode.c,v 1.3.8.3 2002/01/17 13:55:20 he Exp $");
     47 #endif
     48 #endif /* not lint */
     49 
     50 #include <sys/param.h>
     51 #include <sys/time.h>
     52 #include <sys/stat.h>
     53 #include <ufs/ufs/dir.h>
     54 #include <ufs/ufs/dinode.h>
     55 #include <ufs/ffs/fs.h>
     56 #include <ufs/ffs/ffs_extern.h>
     57 
     58 #include <protocols/dumprestore.h>
     59 
     60 #include <ctype.h>
     61 #include <errno.h>
     62 #include <fts.h>
     63 #include <stdio.h>
     64 #ifdef __STDC__
     65 #include <string.h>
     66 #include <unistd.h>
     67 #endif
     68 
     69 #include "dump.h"
     70 
     71 #ifndef SBOFF
     72 #define SBOFF (SBLOCK * DEV_BSIZE)
     73 #endif
     74 
     75 struct fs *sblock;
     76 
     77 /*
     78  * Read the superblock from disk, and check its magic number.
     79  * Determine whether byte-swapping needs to be done on this filesystem.
     80  */
     81 int
     82 fs_read_sblock(char *sblock_buf)
     83 {
     84 	int needswap = 0;
     85 
     86 	sblock = (struct fs *)sblock_buf;
     87 	rawread(SBOFF, (char *) sblock, SBSIZE);
     88 	if (sblock->fs_magic != FS_MAGIC) {
     89 		if (sblock->fs_magic == bswap32(FS_MAGIC)) {
     90 			ffs_sb_swap(sblock, sblock);
     91 			needswap = 1;
     92 		} else
     93 			quit("bad sblock magic number\n");
     94 	}
     95 	return needswap;
     96 }
     97 
     98 /*
     99  * Fill in the ufsi struct, as well as the maxino and dev_bsize global
    100  * variables.
    101  */
    102 struct ufsi *
    103 fs_parametrize(void)
    104 {
    105 	static struct ufsi ufsi;
    106 
    107 #ifdef FS_44INODEFMT
    108 	if (sblock->fs_inodefmt >= FS_44INODEFMT) {
    109 		spcl.c_flags = iswap32(iswap32(spcl.c_flags) | DR_NEWINODEFMT);
    110 	} else {
    111 		/*
    112 		 * Determine parameters for older filesystems. From
    113 		 *	/sys/ufs/ffs/ffs_vfsops.c::ffs_oldfscompat()
    114 		 *
    115 		 * XXX: not sure if other variables (fs_npsect, fs_interleave,
    116 		 * fs_nrpos, fs_maxfilesize) need to be fudged too.
    117 		 */
    118 		sblock->fs_qbmask = ~sblock->fs_bmask;
    119 		sblock->fs_qfmask = ~sblock->fs_fmask;
    120 	}
    121 #endif
    122 
    123 	/* Fill out ufsi struct */
    124 	ufsi.ufs_dsize = fsbtodb(sblock,sblock->fs_size);
    125 	ufsi.ufs_bsize = sblock->fs_bsize;
    126 	ufsi.ufs_bshift = sblock->fs_bshift;
    127 	ufsi.ufs_fsize = sblock->fs_fsize;
    128 	ufsi.ufs_frag = sblock->fs_frag;
    129 	ufsi.ufs_fsatoda = sblock->fs_fsbtodb;
    130 	ufsi.ufs_nindir = sblock->fs_nindir;
    131 	ufsi.ufs_inopb = sblock->fs_inopb;
    132 	ufsi.ufs_maxsymlinklen = sblock->fs_maxsymlinklen;
    133 	ufsi.ufs_bmask = sblock->fs_bmask;
    134 	ufsi.ufs_fmask = sblock->fs_fmask;
    135 	ufsi.ufs_qbmask = sblock->fs_qbmask;
    136 	ufsi.ufs_qfmask = sblock->fs_qfmask;
    137 
    138 	dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
    139 
    140 	return &ufsi;
    141 }
    142 
    143 ino_t
    144 fs_maxino(void)
    145 {
    146 	return sblock->fs_ipg * sblock->fs_ncg;
    147 }
    148 
    149 struct dinode *
    150 getino(inum)
    151 	ino_t inum;
    152 {
    153 	static daddr_t minino, maxino;
    154 	static struct dinode inoblock[MAXINOPB];
    155 	int i;
    156 
    157 	curino = inum;
    158 	if (inum >= minino && inum < maxino)
    159 		return (&inoblock[inum - minino]);
    160 	bread(fsatoda(ufsib, ino_to_fsba(sblock, inum)), (char *)inoblock,
    161 	    (int)ufsib->ufs_bsize);
    162 	if (needswap)
    163 		for (i = 0; i < MAXINOPB; i++)
    164 			ffs_dinode_swap(&inoblock[i], &inoblock[i]);
    165 	minino = inum - (inum % INOPB(sblock));
    166 	maxino = minino + INOPB(sblock);
    167 	return (&inoblock[inum - minino]);
    168 }
    169