fsck.h revision 1.16 1 /* $NetBSD: fsck.h,v 1.16 2006/11/09 19:36:36 christos Exp $ */
2
3 /*-
4 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant (at) hhhh.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1980, 1986, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)fsck.h 8.1 (Berkeley) 6/5/93
68 */
69
70 #ifdef KS_DEBUG
71 #include <err.h>
72 #define debug_printf warn
73 #else
74 #define debug_printf
75 #endif
76
77 #define MAXDUP 10 /* limit on dup blks (per inode) */
78 #define MAXBAD 10 /* limit on bad blks (per inode) */
79 #define MAXBUFSPACE 40*1024 /* maximum space to allocate to buffers */
80 #define INOBUFSIZE 56*1024 /* size of buffer to read inodes in pass1 */
81
82 #ifndef BUFSIZ
83 #define BUFSIZ 1024
84 #endif
85
86 #define USTATE 01 /* inode not allocated */
87 #define FSTATE 02 /* inode is file */
88 #define DSTATE 03 /* inode is directory */
89 #define DFOUND 04 /* directory found during descent */
90 #define DCLEAR 05 /* directory is to be cleared */
91 #define FCLEAR 06 /* file is to be cleared */
92
93 #define EEXIT 8 /* Standard error exit */
94
95 /*
96 * buffer cache structure.
97 */
98 struct ubufarea {
99 struct ubufarea *b_next; /* free list queue */
100 struct ubufarea *b_prev; /* free list queue */
101 daddr_t b_bno;
102 int b_size;
103 int b_errs;
104 int b_flags;
105 union {
106 char *b_buf; /* buffer space */
107 /* XXX ondisk32 */
108 int32_t *b_indir; /* indirect block */
109 struct lfs *b_fs; /* super block */
110 struct cg *b_cg;/* cylinder group */
111 struct ufs1_dinode *b_dinode; /* inode block */
112 } b_un;
113 char b_dirty;
114 };
115 #define B_INUSE 1
116
117 #define MINBUFS 5 /* minimum number of buffers required */
118
119 #define dirty(bp) (bp)->b_dirty = 1
120 #define initbarea(bp) \
121 (bp)->b_dirty = 0; \
122 (bp)->b_bno = (daddr_t)-1; \
123 (bp)->b_flags = 0;
124
125 enum fixstate {
126 DONTKNOW, NOFIX, FIX, IGNORE
127 };
128
129 struct inodesc {
130 enum fixstate id_fix; /* policy on fixing errors */
131 int (*id_func) (struct inodesc *); /* function to be applied to
132 * blocks of inode */
133 ino_t id_number; /* inode number described */
134 ino_t id_parent; /* for DATA nodes, their parent */
135 daddr_t id_blkno; /* current block number being examined */
136 daddr_t id_lblkno; /* current logical block number */
137 int id_numfrags; /* number of frags contained in block */
138 quad_t id_filesize; /* for DATA nodes, the size of the directory */
139 int id_loc; /* for DATA nodes, current location in dir */
140 int id_entryno; /* for DATA nodes, current entry number */
141 struct direct *id_dirp; /* for DATA nodes, ptr to current entry */
142 const char *id_name; /* for DATA nodes, name to find or enter */
143 char id_type; /* type of descriptor, DATA or ADDR */
144 };
145 /* file types */
146 #define DATA 1
147 #define ADDR 2
148
149 /*
150 * Linked list of duplicate blocks.
151 *
152 * The list is composed of two parts. The first part of the
153 * list (from duplist through the node pointed to by muldup)
154 * contains a single copy of each duplicate block that has been
155 * found. The second part of the list (from muldup to the end)
156 * contains duplicate blocks that have been found more than once.
157 * To check if a block has been found as a duplicate it is only
158 * necessary to search from duplist through muldup. To find the
159 * total number of times that a block has been found as a duplicate
160 * the entire list must be searched for occurrences of the block
161 * in question. The following diagram shows a sample list where
162 * w (found twice), x (found once), y (found three times), and z
163 * (found once) are duplicate block numbers:
164 *
165 * w -> y -> x -> z -> y -> w -> y
166 * ^ ^
167 * | |
168 * duplist muldup
169 */
170 struct dups {
171 struct dups *next;
172 daddr_t dup;
173 };
174 /*
175 * Linked list of inodes with zero link counts.
176 */
177 struct zlncnt {
178 struct zlncnt *next;
179 ino_t zlncnt;
180 };
181 /*
182 * Inode cache data structures.
183 */
184 struct inoinfo {
185 struct inoinfo *i_nexthash; /* next entry in hash chain */
186 struct inoinfo *i_child, *i_sibling, *i_parentp;
187 ino_t i_number; /* inode number of this entry */
188 ino_t i_parent; /* inode number of parent */
189 ino_t i_dotdot; /* inode number of `..' */
190 size_t i_isize; /* size of inode */
191 u_int i_numblks; /* size of block array in bytes */
192 /* XXX ondisk32 */
193 int32_t i_blks[1]; /* actually longer */
194 } **inphead, **inpsort;
195
196 #ifndef VERBOSE_BLOCKMAP
197 #define setbmap(blkno) setbit(blockmap, blkno)
198 #define testbmap(blkno) isset(blockmap, blkno)
199 #define clrbmap(blkno) clrbit(blockmap, blkno)
200 #else
201 #define setbmap(blkno,ino) if(blkno > maxfsblock)raise(1); else blockmap[blkno] = ino
202 #define testbmap(blkno) blockmap[blkno]
203 #define clrbmap(blkno) blockmap[blkno] = 0
204 #endif
205
206 #define STOP 0x01
207 #define SKIP 0x02
208 #define KEEPON 0x04
209 #define ALTERED 0x08
210 #define FOUND 0x10
211
212 ino_t allocino(ino_t, int);
213 int ino_to_fsba(struct lfs *, ino_t);
214 struct ufs1_dinode *ginode(ino_t);
215 struct inoinfo *getinoinfo(ino_t);
216 daddr_t lfs_ino_daddr(ino_t);
217 void clearinode(ino_t);
218 void reset_maxino(ino_t);
219
220 #include "fsck_vars.h"
221