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