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