xref: /original-bsd/sbin/fsck/fsck.h (revision d5bfdc7c)
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.10 (Berkeley) 02/01/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	128*1024 /* maximum space to allocate to buffers */
23 
24 #ifndef BUFSIZ
25 #define BUFSIZ 1024
26 #endif
27 
28 #define	USTATE	01		/* inode not allocated */
29 #define	FSTATE	02		/* inode is file */
30 #define	DSTATE	03		/* inode is directory */
31 #define	DFOUND	04		/* directory found during descent */
32 #define	DCLEAR	05		/* directory is to be cleared */
33 #define	FCLEAR	06		/* file is to be cleared */
34 
35 /*
36  * buffer cache structure.
37  */
38 struct bufarea {
39 	struct bufarea	*b_next;		/* free list queue */
40 	struct bufarea	*b_prev;		/* free list queue */
41 	daddr_t	b_bno;
42 	int	b_size;
43 	int	b_errs;
44 	int	b_flags;
45 	union {
46 		char	*b_buf;			/* buffer space */
47 		daddr_t	*b_indir;		/* indirect block */
48 		struct	fs *b_fs;		/* super block */
49 		struct	cg *b_cg;		/* cylinder group */
50 		struct	dinode *b_dinode;	/* inode block */
51 	} b_un;
52 	char	b_dirty;
53 };
54 
55 #define	B_INUSE 1
56 
57 #define	MINBUFS		5	/* minimum number of buffers required */
58 struct bufarea bufhead;		/* head of list of other blks in filesys */
59 struct bufarea sblk;		/* file system superblock */
60 struct bufarea cgblk;		/* cylinder group blocks */
61 struct bufarea *getdatablk();
62 
63 #define	dirty(bp)	(bp)->b_dirty = 1
64 #define	initbarea(bp) \
65 	(bp)->b_dirty = 0; \
66 	(bp)->b_bno = (daddr_t)-1; \
67 	(bp)->b_flags = 0;
68 
69 #define	sbdirty()	sblk.b_dirty = 1
70 #define	cgdirty()	cgblk.b_dirty = 1
71 #define	sblock		(*sblk.b_un.b_fs)
72 #define	cgrp		(*cgblk.b_un.b_cg)
73 
74 enum fixstate {DONTKNOW, NOFIX, FIX};
75 
76 struct inodesc {
77 	enum fixstate id_fix;	/* policy on fixing errors */
78 	int (*id_func)();	/* function to be applied to blocks of inode */
79 	ino_t id_number;	/* inode number described */
80 	ino_t id_parent;	/* for DATA nodes, their parent */
81 	daddr_t id_blkno;	/* current block number being examined */
82 	int id_numfrags;	/* number of frags contained in block */
83 	long id_filesize;	/* for DATA nodes, the size of the directory */
84 	int id_loc;		/* for DATA nodes, current location in dir */
85 	int id_entryno;		/* for DATA nodes, current entry number */
86 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
87 	char *id_name;		/* for DATA nodes, name to find or enter */
88 	char id_type;		/* type of descriptor, DATA or ADDR */
89 };
90 /* file types */
91 #define	DATA	1
92 #define	ADDR	2
93 
94 /*
95  * Linked list of duplicate blocks.
96  *
97  * The list is composed of two parts. The first part of the
98  * list (from duplist through the node pointed to by muldup)
99  * contains a single copy of each duplicate block that has been
100  * found. The second part of the list (from muldup to the end)
101  * contains duplicate blocks that have been found more than once.
102  * To check if a block has been found as a duplicate it is only
103  * necessary to search from duplist through muldup. To find the
104  * total number of times that a block has been found as a duplicate
105  * the entire list must be searched for occurences of the block
106  * in question. The following diagram shows a sample list where
107  * w (found twice), x (found once), y (found three times), and z
108  * (found once) are duplicate block numbers:
109  *
110  *    w -> y -> x -> z -> y -> w -> y
111  *    ^		     ^
112  *    |		     |
113  * duplist	  muldup
114  */
115 struct dups {
116 	struct dups *next;
117 	daddr_t dup;
118 };
119 struct dups *duplist;		/* head of dup list */
120 struct dups *muldup;		/* end of unique duplicate dup block numbers */
121 
122 /*
123  * Linked list of inodes with zero link counts.
124  */
125 struct zlncnt {
126 	struct zlncnt *next;
127 	ino_t zlncnt;
128 };
129 struct zlncnt *zlnhead;		/* head of zero link count list */
130 
131 char	*devname;		/* name of device being checked */
132 long	dev_bsize;		/* computed value of DEV_BSIZE */
133 long	secsize;		/* actual disk sector size */
134 char	nflag;			/* assume a no response */
135 char	yflag;			/* assume a yes response */
136 int	bflag;			/* location of alternate super block */
137 int	debug;			/* output debugging info */
138 int	cvtflag;		/* convert to old file system format */
139 char	preen;			/* just fix normal inconsistencies */
140 char	hotroot;		/* checking root device */
141 char	havesb;			/* superblock has been read */
142 int	fsmodified;		/* 1 => write done to file system */
143 int	fsreadfd;		/* file descriptor for reading file system */
144 int	fswritefd;		/* file descriptor for writing file system */
145 
146 daddr_t	maxfsblock;		/* number of blocks in the file system */
147 char	*blockmap;		/* ptr to primary blk allocation map */
148 ino_t	maxino;			/* number of inodes in file system */
149 ino_t	lastino;		/* last inode in use */
150 char	*statemap;		/* ptr to inode state table */
151 short	*lncntp;		/* ptr to link count table */
152 
153 char	pathname[BUFSIZ];	/* current pathname */
154 char	*pathp;			/* ptr to current position in pathname */
155 char	*endpathname;		/* ptr to current end of pathname */
156 
157 ino_t	lfdir;			/* lost & found directory inode number */
158 char	*lfname;		/* lost & found directory name */
159 int	lfmode;			/* lost & found directory creation mode */
160 
161 daddr_t	n_blks;			/* number of blocks in use */
162 daddr_t	n_files;		/* number of files in use */
163 
164 #define	clearinode(dp)	(*(dp) = zino)
165 struct	dinode zino;
166 
167 #define	setbmap(blkno)	setbit(blockmap, blkno)
168 #define	testbmap(blkno)	isset(blockmap, blkno)
169 #define	clrbmap(blkno)	clrbit(blockmap, blkno)
170 
171 #define	STOP	0x01
172 #define	SKIP	0x02
173 #define	KEEPON	0x04
174 #define	ALTERED	0x08
175 #define	FOUND	0x10
176 
177 time_t time();
178 struct dinode *ginode();
179 struct bufarea *getblk();
180 ino_t allocino();
181 int findino();
182