xref: /original-bsd/sbin/fsck/fsck.h (revision 670f2583)
1 /* @(#)fsck.h	3.6 (Berkeley) 06/02/85 */
2 
3 #define	MAXDUP		10	/* limit on dup blks (per inode) */
4 #define	MAXBAD		10	/* limit on bad blks (per inode) */
5 
6 typedef	int	(*SIG_TYP)();
7 
8 #ifndef BUFSIZ
9 #define BUFSIZ 1024
10 #endif
11 
12 #define	USTATE	01		/* inode not allocated */
13 #define	FSTATE	02		/* inode is file */
14 #define	DSTATE	03		/* inode is directory */
15 #define	DFOUND	04		/* directory found during descent */
16 #define	DCLEAR	05		/* directory is to be cleared */
17 #define	FCLEAR	06		/* file is to be cleared */
18 
19 typedef struct dinode	DINODE;
20 typedef struct direct	DIRECT;
21 
22 #define	ALLOC(dip)	(((dip)->di_mode & IFMT) != 0)
23 #define	DIRCT(dip)	(((dip)->di_mode & IFMT) == IFDIR)
24 #define	SPECIAL(dip) \
25 	(((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR)
26 
27 #define	MAXNINDIR	(MAXBSIZE / sizeof (daddr_t))
28 #define	MAXINOPB	(MAXBSIZE / sizeof (struct dinode))
29 #define	SPERB		(MAXBSIZE / sizeof(short))
30 
31 struct bufarea {
32 	struct bufarea	*b_next;		/* must be first */
33 	daddr_t	b_bno;
34 	int	b_size;
35 	int	b_errs;
36 	union {
37 		char	b_buf[MAXBSIZE];	/* buffer space */
38 		short	b_lnks[SPERB];		/* link counts */
39 		daddr_t	b_indir[MAXNINDIR];	/* indirect block */
40 		struct	fs b_fs;		/* super block */
41 		struct	cg b_cg;		/* cylinder group */
42 		struct dinode b_dinode[MAXINOPB]; /* inode block */
43 	} b_un;
44 	char	b_dirty;
45 };
46 
47 typedef struct bufarea BUFAREA;
48 
49 BUFAREA	inoblk;			/* inode blocks */
50 BUFAREA	fileblk;		/* other blks in filesys */
51 BUFAREA	sblk;			/* file system superblock */
52 BUFAREA	cgblk;			/* cylinder group blocks */
53 
54 #define	initbarea(x)	(x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
55 #define	dirty(x)	(x)->b_dirty = 1
56 #define	inodirty()	inoblk.b_dirty = 1
57 #define	sbdirty()	sblk.b_dirty = 1
58 #define	cgdirty()	cgblk.b_dirty = 1
59 
60 #define	dirblk		fileblk.b_un
61 #define	sblock		sblk.b_un.b_fs
62 #define	cgrp		cgblk.b_un.b_cg
63 
64 struct filecntl {
65 	int	rfdes;
66 	int	wfdes;
67 	int	mod;
68 } dfile;			/* file descriptors for filesys */
69 
70 enum fixstate {DONTKNOW, NOFIX, FIX};
71 
72 struct inodesc {
73 	enum fixstate id_fix;	/* policy on fixing errors */
74 	int (*id_func)();	/* function to be applied to blocks of inode */
75 	ino_t id_number;	/* inode number described */
76 	ino_t id_parent;	/* for DATA nodes, their parent */
77 	daddr_t id_blkno;	/* current block number being examined */
78 	int id_numfrags;	/* number of frags contained in block */
79 	long id_filesize;	/* for DATA nodes, the size of the directory */
80 	int id_loc;		/* for DATA nodes, current location in dir */
81 	int id_entryno;		/* for DATA nodes, current entry number */
82 	DIRECT *id_dirp;	/* for DATA nodes, ptr to current entry */
83 	char *id_name;		/* for DATA nodes, name to find or enter */
84 	char id_type;		/* type of descriptor, DATA or ADDR */
85 };
86 /* file types */
87 #define	DATA	1
88 #define	ADDR	2
89 
90 /*
91  * Linked list of duplicate blocks.
92  *
93  * The list is composed of two parts. The first part of the
94  * list (from duplist through the node pointed to by muldup)
95  * contains a single copy of each duplicate block that has been
96  * found. The second part of the list (from muldup to the end)
97  * contains duplicate blocks that have been found more than once.
98  * To check if a block has been found as a duplicate it is only
99  * necessary to search from duplist through muldup. To find the
100  * total number of times that a block has been found as a duplicate
101  * the entire list must be searched for occurences of the block
102  * in question. The following diagram shows a sample list where
103  * w (found twice), x (found once), y (found three times), and z
104  * (found once) are duplicate block numbers:
105  *
106  *    w -> y -> x -> z -> y -> w -> y
107  *    ^		     ^
108  *    |		     |
109  * duplist	  muldup
110  */
111 struct dups {
112 	struct dups *next;
113 	daddr_t dup;
114 };
115 struct dups *duplist;		/* head of dup list */
116 struct dups *muldup;		/* end of unique duplicate dup block numbers */
117 
118 /*
119  * Linked list of inodes with zero link counts.
120  */
121 struct zlncnt {
122 	struct zlncnt *next;
123 	ino_t zlncnt;
124 };
125 struct zlncnt *zlnhead;		/* head of zero link count list */
126 
127 char	rawflg;
128 char	*devname;
129 char	nflag;			/* assume a no response */
130 char	yflag;			/* assume a yes response */
131 int	bflag;			/* location of alternate super block */
132 int	debug;			/* output debugging info */
133 char	preen;			/* just fix normal inconsistencies */
134 char	hotroot;		/* checking root device */
135 
136 char	*blockmap;		/* ptr to primary blk allocation map */
137 char	*statemap;		/* ptr to inode state table */
138 short	*lncntp;		/* ptr to link count table */
139 
140 char	pathname[BUFSIZ];	/* current pathname */
141 char	*pathp;			/* pointer to pathname position */
142 char	*endpathname;
143 
144 daddr_t	fmax;			/* number of blocks in the volume */
145 ino_t	imax;			/* number of inodes */
146 ino_t	lastino;		/* hiwater mark of inodes */
147 ino_t	lfdir;			/* lost & found directory inode number */
148 char	*lfname;		/* lost & found directory name */
149 
150 off_t	maxblk;			/* largest logical blk in file */
151 off_t	bmapsz;			/* num chars in blockmap */
152 
153 daddr_t	n_blks;			/* number of blocks used */
154 daddr_t	n_files;		/* number of files seen */
155 
156 #define	zapino(x)	(*(x) = zino)
157 struct	dinode zino;
158 
159 #define	setbmap(x)	setbit(blockmap, x)
160 #define	getbmap(x)	isset(blockmap, x)
161 #define	clrbmap(x)	clrbit(blockmap, x)
162 
163 #define	ALTERED	010
164 #define	KEEPON	04
165 #define	SKIP	02
166 #define	STOP	01
167 
168 time_t	time();
169 DINODE	*ginode();
170 BUFAREA	*getblk();
171 int	findino();
172