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