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