xref: /original-bsd/sbin/fsck/fsck.h (revision 8e7bb52d)
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.12 (Berkeley) 02/07/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 *getdatablk();
63 
64 #define	dirty(bp)	(bp)->b_dirty = 1
65 #define	initbarea(bp) \
66 	(bp)->b_dirty = 0; \
67 	(bp)->b_bno = (daddr_t)-1; \
68 	(bp)->b_flags = 0;
69 
70 #define	sbdirty()	sblk.b_dirty = 1
71 #define	cgdirty()	cgblk.b_dirty = 1
72 #define	sblock		(*sblk.b_un.b_fs)
73 #define	cgrp		(*cgblk.b_un.b_cg)
74 
75 enum fixstate {DONTKNOW, NOFIX, FIX};
76 
77 struct inodesc {
78 	enum fixstate id_fix;	/* policy on fixing errors */
79 	int (*id_func)();	/* function to be applied to blocks of inode */
80 	ino_t id_number;	/* inode number described */
81 	ino_t id_parent;	/* for DATA nodes, their parent */
82 	daddr_t id_blkno;	/* current block number being examined */
83 	int id_numfrags;	/* number of frags contained in block */
84 	long id_filesize;	/* for DATA nodes, the size of the directory */
85 	int id_loc;		/* for DATA nodes, current location in dir */
86 	int id_entryno;		/* for DATA nodes, current entry number */
87 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
88 	char *id_name;		/* for DATA nodes, name to find or enter */
89 	char id_type;		/* type of descriptor, DATA or ADDR */
90 };
91 /* file types */
92 #define	DATA	1
93 #define	ADDR	2
94 
95 /*
96  * Linked list of duplicate blocks.
97  *
98  * The list is composed of two parts. The first part of the
99  * list (from duplist through the node pointed to by muldup)
100  * contains a single copy of each duplicate block that has been
101  * found. The second part of the list (from muldup to the end)
102  * contains duplicate blocks that have been found more than once.
103  * To check if a block has been found as a duplicate it is only
104  * necessary to search from duplist through muldup. To find the
105  * total number of times that a block has been found as a duplicate
106  * the entire list must be searched for occurences of the block
107  * in question. The following diagram shows a sample list where
108  * w (found twice), x (found once), y (found three times), and z
109  * (found once) are duplicate block numbers:
110  *
111  *    w -> y -> x -> z -> y -> w -> y
112  *    ^		     ^
113  *    |		     |
114  * duplist	  muldup
115  */
116 struct dups {
117 	struct dups *next;
118 	daddr_t dup;
119 };
120 struct dups *duplist;		/* head of dup list */
121 struct dups *muldup;		/* end of unique duplicate dup block numbers */
122 
123 /*
124  * Linked list of inodes with zero link counts.
125  */
126 struct zlncnt {
127 	struct zlncnt *next;
128 	ino_t zlncnt;
129 };
130 struct zlncnt *zlnhead;		/* head of zero link count list */
131 
132 /*
133  * Inode cache data structures.
134  */
135 struct inoinfo {
136 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
137 	ino_t	i_number;		/* inode number of this entry */
138 	ino_t	i_parent;		/* inode number of parent */
139 	ino_t	i_dotdot;		/* inode number of `..' */
140 	size_t	i_isize;		/* size of inode */
141 	u_int	i_numblks;		/* size of block array in bytes */
142 	daddr_t	i_blks[1];		/* actually longer */
143 } **inphead, **inpsort;
144 long numdirs, listmax, inplast;
145 
146 char	*devname;		/* name of device being checked */
147 long	dev_bsize;		/* computed value of DEV_BSIZE */
148 long	secsize;		/* actual disk sector size */
149 char	nflag;			/* assume a no response */
150 char	yflag;			/* assume a yes response */
151 int	bflag;			/* location of alternate super block */
152 int	debug;			/* output debugging info */
153 int	cvtflag;		/* convert to old file system format */
154 char	preen;			/* just fix normal inconsistencies */
155 char	hotroot;		/* checking root device */
156 char	havesb;			/* superblock has been read */
157 int	fsmodified;		/* 1 => write done to file system */
158 int	fsreadfd;		/* file descriptor for reading file system */
159 int	fswritefd;		/* file descriptor for writing file system */
160 
161 daddr_t	maxfsblock;		/* number of blocks in the file system */
162 char	*blockmap;		/* ptr to primary blk allocation map */
163 ino_t	maxino;			/* number of inodes in file system */
164 ino_t	lastino;		/* last inode in use */
165 char	*statemap;		/* ptr to inode state table */
166 short	*lncntp;		/* ptr to link count table */
167 
168 char	pathname[BUFSIZ];	/* current pathname */
169 char	*pathp;			/* ptr to current position in pathname */
170 char	*endpathname;		/* ptr to current end of pathname */
171 
172 ino_t	lfdir;			/* lost & found directory inode number */
173 char	*lfname;		/* lost & found directory name */
174 int	lfmode;			/* lost & found directory creation mode */
175 
176 daddr_t	n_blks;			/* number of blocks in use */
177 daddr_t	n_files;		/* number of files in use */
178 
179 #define	clearinode(dp)	(*(dp) = zino)
180 struct	dinode zino;
181 
182 #define	setbmap(blkno)	setbit(blockmap, blkno)
183 #define	testbmap(blkno)	isset(blockmap, blkno)
184 #define	clrbmap(blkno)	clrbit(blockmap, blkno)
185 
186 #define	STOP	0x01
187 #define	SKIP	0x02
188 #define	KEEPON	0x04
189 #define	ALTERED	0x08
190 #define	FOUND	0x10
191 
192 time_t time();
193 struct dinode *ginode();
194 struct inoinfo *getinoinfo();
195 struct bufarea *getblk();
196 ino_t allocino();
197 int findino();
198