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