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