fsck.h revision 1.10 1 /* $NetBSD: fsck.h,v 1.10 2004/03/22 19:46:53 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 1980, 1986, 1993
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)fsck.h 8.1 (Berkeley) 6/5/93
32 */
33
34 /*
35 * Copyright (c) 1997 Manuel Bouyer.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by Manuel Bouyer.
48 * 4. The name of the author may not be used to endorse or promote products
49 * derived from this software without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 * @(#)fsck.h 8.1 (Berkeley) 6/5/93
63 */
64
65 #define MAXDUP 10 /* limit on dup blks (per inode) */
66 #define MAXBAD 10 /* limit on bad blks (per inode) */
67 #define MAXBUFSPACE 80*1024 /* maximum space to allocate to buffers */
68 #define INOBUFSIZE 128*1024 /* size of buffer to read inodes in pass1 */
69
70 #ifndef BUFSIZ
71 #define BUFSIZ 1024
72 #endif
73
74 #define USTATE 01 /* inode not allocated */
75 #define FSTATE 02 /* inode is file */
76 #define DSTATE 03 /* inode is directory */
77 #define DFOUND 04 /* directory found during descent */
78 #define DCLEAR 05 /* directory is to be cleared */
79 #define FCLEAR 06 /* file is to be cleared */
80
81 /*
82 * buffer cache structure.
83 */
84 struct bufarea {
85 struct bufarea *b_next; /* free list queue */
86 struct bufarea *b_prev; /* free list queue */
87 daddr_t b_bno;
88 int b_size;
89 int b_errs;
90 int b_flags;
91 union {
92 char *b_buf; /* buffer space */
93 /* XXX ondisk32 */
94 int32_t *b_indir; /* indirect block */
95 struct ext2fs *b_fs; /* super block */
96 struct ext2_gd *b_cgd; /* cylinder group descriptor */
97 struct ext2fs_dinode *b_dinode; /* inode block */
98 } b_un;
99 char b_dirty;
100 };
101
102 #define B_INUSE 1
103
104 #define MINBUFS 5 /* minimum number of buffers required */
105 struct bufarea bufhead; /* head of list of other blks in filesys */
106 struct bufarea sblk; /* file system superblock */
107 struct bufarea asblk; /* first alternate superblock */
108 struct bufarea *pdirbp; /* current directory contents */
109 struct bufarea *pbp; /* current inode block */
110 struct bufarea *getdatablk __P((daddr_t, long));
111 struct m_ext2fs sblock;
112
113 #define dirty(bp) (bp)->b_dirty = 1
114 #define initbarea(bp) \
115 (bp)->b_dirty = 0; \
116 (bp)->b_bno = (daddr_t)-1; \
117 (bp)->b_flags = 0;
118
119 #define sbdirty() copyback_sb(&sblk); sblk.b_dirty = 1
120
121 enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
122
123 struct inodesc {
124 enum fixstate id_fix; /* policy on fixing errors */
125 int (*id_func) /* function to be applied to blocks of inode */
126 __P((struct inodesc *));
127 ino_t id_number; /* inode number described */
128 ino_t id_parent; /* for DATA nodes, their parent */
129 daddr_t id_blkno; /* current block number being examined */
130 int id_numfrags; /* number of frags contained in block */
131 quad_t id_filesize; /* for DATA nodes, the size of the directory */
132 int id_loc; /* for DATA nodes, current location in dir */
133 int id_entryno; /* for DATA nodes, current entry number */
134 struct ext2fs_direct *id_dirp; /* for DATA nodes, ptr to current entry */
135 char *id_name; /* for DATA nodes, name to find or enter */
136 char id_type; /* type of descriptor, DATA or ADDR */
137 };
138 /* file types */
139 #define DATA 1
140 #define ADDR 2
141
142 /*
143 * Linked list of duplicate blocks.
144 *
145 * The list is composed of two parts. The first part of the
146 * list (from duplist through the node pointed to by muldup)
147 * contains a single copy of each duplicate block that has been
148 * found. The second part of the list (from muldup to the end)
149 * contains duplicate blocks that have been found more than once.
150 * To check if a block has been found as a duplicate it is only
151 * necessary to search from duplist through muldup. To find the
152 * total number of times that a block has been found as a duplicate
153 * the entire list must be searched for occurrences of the block
154 * in question. The following diagram shows a sample list where
155 * w (found twice), x (found once), y (found three times), and z
156 * (found once) are duplicate block numbers:
157 *
158 * w -> y -> x -> z -> y -> w -> y
159 * ^ ^
160 * | |
161 * duplist muldup
162 */
163 struct dups {
164 struct dups *next;
165 daddr_t dup;
166 };
167 struct dups *duplist; /* head of dup list */
168 struct dups *muldup; /* end of unique duplicate dup block numbers */
169
170 /*
171 * Linked list of inodes with zero link counts.
172 */
173 struct zlncnt {
174 struct zlncnt *next;
175 ino_t zlncnt;
176 };
177 struct zlncnt *zlnhead; /* head of zero link count list */
178
179 /*
180 * Inode cache data structures.
181 */
182 struct inoinfo {
183 struct inoinfo *i_nexthash; /* next entry in hash chain */
184 struct inoinfo *i_child, *i_sibling, *i_parentp;
185 ino_t i_number; /* inode number of this entry */
186 ino_t i_parent; /* inode number of parent */
187 ino_t i_dotdot; /* inode number of `..' */
188 size_t i_isize; /* size of inode */
189 u_int i_numblks; /* size of block array in bytes */
190 /* XXX ondisk32 */
191 int32_t i_blks[1]; /* actually longer */
192 } **inphead, **inpsort;
193 long numdirs, listmax, inplast;
194
195 long dev_bsize; /* computed value of DEV_BSIZE */
196 long secsize; /* actual disk sector size */
197 char nflag; /* assume a no response */
198 char yflag; /* assume a yes response */
199 int bflag; /* location of alternate super block */
200 int debug; /* output debugging info */
201 int preen; /* just fix normal inconsistencies */
202 char havesb; /* superblock has been read */
203 char skipclean; /* skip clean file systems if preening */
204 int fsmodified; /* 1 => write done to file system */
205 int fsreadfd; /* file descriptor for reading file system */
206 int fswritefd; /* file descriptor for writing file system */
207 int rerun; /* rerun fsck. Only used in non-preen mode */
208
209 daddr_t maxfsblock; /* number of blocks in the file system */
210 char *blockmap; /* ptr to primary blk allocation map */
211 ino_t maxino; /* number of inodes in file system */
212 ino_t lastino; /* last inode in use */
213 char *statemap; /* ptr to inode state table */
214 u_char *typemap; /* ptr to inode type table */
215 int16_t *lncntp; /* ptr to link count table */
216
217 ino_t lfdir; /* lost & found directory inode number */
218 extern char *lfname; /* lost & found directory name */
219 extern int lfmode; /* lost & found directory creation mode */
220
221 daddr_t n_blks; /* number of blocks in use */
222 daddr_t n_files; /* number of files in use */
223
224 #define clearinode(dp) (*(dp) = zino)
225 struct ext2fs_dinode zino;
226
227 #define setbmap(blkno) setbit(blockmap, blkno)
228 #define testbmap(blkno) isset(blockmap, blkno)
229 #define clrbmap(blkno) clrbit(blockmap, blkno)
230
231 #define STOP 0x01
232 #define SKIP 0x02
233 #define KEEPON 0x04
234 #define ALTERED 0x08
235 #define FOUND 0x10
236
237 struct ext2fs_dinode *ginode __P((ino_t));
238 struct inoinfo *getinoinfo __P((ino_t));
239 void getblk __P((struct bufarea *, daddr_t, long));
240 ino_t allocino __P((ino_t, int));
241 void copyback_sb __P((struct bufarea*));
242 daddr_t cgoverhead __P((int)); /* overhead per cg */
243