xref: /original-bsd/sbin/fsck/fsck.h (revision 9b8639ea)
1 /*
2  * Copyright (c) 1980, 1986 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that the above copyright notice and this paragraph are
7  * duplicated in all such forms and that any documentation,
8  * advertising materials, and other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * by the University of California, Berkeley.  The name of the
11  * University may not be used to endorse or promote products derived
12  * from this software without specific prior written permission.
13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  *	@(#)fsck.h	5.14 (Berkeley) 03/27/90
18  */
19 
20 #define	MAXDUP		10	/* limit on dup blks (per inode) */
21 #define	MAXBAD		10	/* limit on bad blks (per inode) */
22 #define	MAXBUFSPACE	40*1024	/* maximum space to allocate to buffers */
23 #define	INOBUFSIZE	56*1024	/* size of buffer to read inodes in pass1 */
24 
25 #ifndef BUFSIZ
26 #define BUFSIZ 1024
27 #endif
28 
29 #define	USTATE	01		/* inode not allocated */
30 #define	FSTATE	02		/* inode is file */
31 #define	DSTATE	03		/* inode is directory */
32 #define	DFOUND	04		/* directory found during descent */
33 #define	DCLEAR	05		/* directory is to be cleared */
34 #define	FCLEAR	06		/* file is to be cleared */
35 
36 /*
37  * buffer cache structure.
38  */
39 struct bufarea {
40 	struct bufarea	*b_next;		/* free list queue */
41 	struct bufarea	*b_prev;		/* free list queue */
42 	daddr_t	b_bno;
43 	int	b_size;
44 	int	b_errs;
45 	int	b_flags;
46 	union {
47 		char	*b_buf;			/* buffer space */
48 		daddr_t	*b_indir;		/* indirect block */
49 		struct	fs *b_fs;		/* super block */
50 		struct	cg *b_cg;		/* cylinder group */
51 		struct	dinode *b_dinode;	/* inode block */
52 	} b_un;
53 	char	b_dirty;
54 };
55 
56 #define	B_INUSE 1
57 
58 #define	MINBUFS		5	/* minimum number of buffers required */
59 struct bufarea bufhead;		/* head of list of other blks in filesys */
60 struct bufarea sblk;		/* file system superblock */
61 struct bufarea cgblk;		/* cylinder group blocks */
62 struct bufarea *pdirbp;		/* current directory contents */
63 struct bufarea *pbp;		/* current inode block */
64 struct bufarea *getdatablk();
65 
66 #define	dirty(bp)	(bp)->b_dirty = 1
67 #define	initbarea(bp) \
68 	(bp)->b_dirty = 0; \
69 	(bp)->b_bno = (daddr_t)-1; \
70 	(bp)->b_flags = 0;
71 
72 #define	sbdirty()	sblk.b_dirty = 1
73 #define	cgdirty()	cgblk.b_dirty = 1
74 #define	sblock		(*sblk.b_un.b_fs)
75 #define	cgrp		(*cgblk.b_un.b_cg)
76 
77 enum fixstate {DONTKNOW, NOFIX, FIX};
78 
79 struct inodesc {
80 	enum fixstate id_fix;	/* policy on fixing errors */
81 	int (*id_func)();	/* function to be applied to blocks of inode */
82 	ino_t id_number;	/* inode number described */
83 	ino_t id_parent;	/* for DATA nodes, their parent */
84 	daddr_t id_blkno;	/* current block number being examined */
85 	int id_numfrags;	/* number of frags contained in block */
86 	long id_filesize;	/* for DATA nodes, the size of the directory */
87 	int id_loc;		/* for DATA nodes, current location in dir */
88 	int id_entryno;		/* for DATA nodes, current entry number */
89 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
90 	char *id_name;		/* for DATA nodes, name to find or enter */
91 	char id_type;		/* type of descriptor, DATA or ADDR */
92 };
93 /* file types */
94 #define	DATA	1
95 #define	ADDR	2
96 
97 /*
98  * Linked list of duplicate blocks.
99  *
100  * The list is composed of two parts. The first part of the
101  * list (from duplist through the node pointed to by muldup)
102  * contains a single copy of each duplicate block that has been
103  * found. The second part of the list (from muldup to the end)
104  * contains duplicate blocks that have been found more than once.
105  * To check if a block has been found as a duplicate it is only
106  * necessary to search from duplist through muldup. To find the
107  * total number of times that a block has been found as a duplicate
108  * the entire list must be searched for occurences of the block
109  * in question. The following diagram shows a sample list where
110  * w (found twice), x (found once), y (found three times), and z
111  * (found once) are duplicate block numbers:
112  *
113  *    w -> y -> x -> z -> y -> w -> y
114  *    ^		     ^
115  *    |		     |
116  * duplist	  muldup
117  */
118 struct dups {
119 	struct dups *next;
120 	daddr_t dup;
121 };
122 struct dups *duplist;		/* head of dup list */
123 struct dups *muldup;		/* end of unique duplicate dup block numbers */
124 
125 /*
126  * Linked list of inodes with zero link counts.
127  */
128 struct zlncnt {
129 	struct zlncnt *next;
130 	ino_t zlncnt;
131 };
132 struct zlncnt *zlnhead;		/* head of zero link count list */
133 
134 /*
135  * Inode cache data structures.
136  */
137 struct inoinfo {
138 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
139 	ino_t	i_number;		/* inode number of this entry */
140 	ino_t	i_parent;		/* inode number of parent */
141 	ino_t	i_dotdot;		/* inode number of `..' */
142 	size_t	i_isize;		/* size of inode */
143 	u_int	i_numblks;		/* size of block array in bytes */
144 	daddr_t	i_blks[1];		/* actually longer */
145 } **inphead, **inpsort;
146 long numdirs, listmax, inplast;
147 
148 char	*devname;		/* name of device being checked */
149 long	dev_bsize;		/* computed value of DEV_BSIZE */
150 long	secsize;		/* actual disk sector size */
151 char	nflag;			/* assume a no response */
152 char	yflag;			/* assume a yes response */
153 int	bflag;			/* location of alternate super block */
154 int	debug;			/* output debugging info */
155 int	cvtflag;		/* convert to old file system format */
156 char	preen;			/* just fix normal inconsistencies */
157 char	hotroot;		/* checking root device */
158 char	havesb;			/* superblock has been read */
159 int	fsmodified;		/* 1 => write done to file system */
160 int	fsreadfd;		/* file descriptor for reading file system */
161 int	fswritefd;		/* file descriptor for writing file system */
162 
163 daddr_t	maxfsblock;		/* number of blocks in the file system */
164 char	*blockmap;		/* ptr to primary blk allocation map */
165 ino_t	maxino;			/* number of inodes in file system */
166 ino_t	lastino;		/* last inode in use */
167 char	*statemap;		/* ptr to inode state table */
168 short	*lncntp;		/* ptr to link count table */
169 
170 ino_t	lfdir;			/* lost & found directory inode number */
171 char	*lfname;		/* lost & found directory name */
172 int	lfmode;			/* lost & found directory creation mode */
173 
174 daddr_t	n_blks;			/* number of blocks in use */
175 daddr_t	n_files;		/* number of files in use */
176 
177 #define	clearinode(dp)	(*(dp) = zino)
178 struct	dinode zino;
179 
180 #define	setbmap(blkno)	setbit(blockmap, blkno)
181 #define	testbmap(blkno)	isset(blockmap, blkno)
182 #define	clrbmap(blkno)	clrbit(blockmap, blkno)
183 
184 #define	STOP	0x01
185 #define	SKIP	0x02
186 #define	KEEPON	0x04
187 #define	ALTERED	0x08
188 #define	FOUND	0x10
189 
190 time_t time();
191 struct dinode *ginode();
192 struct inoinfo *getinoinfo();
193 struct bufarea *getblk();
194 ino_t allocino();
195 int findino();
196