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