xref: /csrg-svn/sbin/fsck/fsck.h (revision 16260)
1*16260Smckusick /* @(#)fsck.h	3.1 (Berkeley) 03/31/84 */
2*16260Smckusick 
3*16260Smckusick /* RECONSTRUCT ONLY BAD CG IN PASS 6 */
4*16260Smckusick 
5*16260Smckusick #define	MAXDUP		10	/* limit on dup blks (per inode) */
6*16260Smckusick #define	MAXBAD		10	/* limit on bad blks (per inode) */
7*16260Smckusick #define	DUPTBLSIZE	100	/* num of dup blocks to remember */
8*16260Smckusick #define	MAXLNCNT	500	/* num zero link cnts to remember */
9*16260Smckusick 
10*16260Smckusick typedef	int	(*SIG_TYP)();
11*16260Smckusick 
12*16260Smckusick #ifndef BUFSIZ
13*16260Smckusick #define BUFSIZ 1024
14*16260Smckusick #endif
15*16260Smckusick 
16*16260Smckusick #define	MAXNINDIR	(MAXBSIZE / sizeof (daddr_t))
17*16260Smckusick #define	MAXINOPB	(MAXBSIZE / sizeof (struct dinode))
18*16260Smckusick #define	SPERB		(MAXBSIZE / sizeof(short))
19*16260Smckusick 
20*16260Smckusick #define	USTATE	0		/* inode not allocated */
21*16260Smckusick #define	FSTATE	01		/* inode is file */
22*16260Smckusick #define	DSTATE	02		/* inode is directory */
23*16260Smckusick #define	CLEAR	03		/* inode is to be cleared */
24*16260Smckusick 
25*16260Smckusick typedef struct dinode	DINODE;
26*16260Smckusick typedef struct direct	DIRECT;
27*16260Smckusick 
28*16260Smckusick #define	ALLOC	((dp->di_mode & IFMT) != 0)
29*16260Smckusick #define	DIRCT	((dp->di_mode & IFMT) == IFDIR)
30*16260Smckusick #define	SPECIAL	((dp->di_mode & IFMT) == IFBLK || (dp->di_mode & IFMT) == IFCHR)
31*16260Smckusick 
32*16260Smckusick struct bufarea {
33*16260Smckusick 	struct bufarea	*b_next;		/* must be first */
34*16260Smckusick 	daddr_t	b_bno;
35*16260Smckusick 	int	b_size;
36*16260Smckusick 	union {
37*16260Smckusick 		char	b_buf[MAXBSIZE];	/* buffer space */
38*16260Smckusick 		short	b_lnks[SPERB];		/* link counts */
39*16260Smckusick 		daddr_t	b_indir[MAXNINDIR];	/* indirect block */
40*16260Smckusick 		struct	fs b_fs;		/* super block */
41*16260Smckusick 		struct	cg b_cg;		/* cylinder group */
42*16260Smckusick 		struct dinode b_dinode[MAXINOPB]; /* inode block */
43*16260Smckusick 	} b_un;
44*16260Smckusick 	char	b_dirty;
45*16260Smckusick };
46*16260Smckusick 
47*16260Smckusick typedef struct bufarea BUFAREA;
48*16260Smckusick 
49*16260Smckusick BUFAREA	inoblk;			/* inode blocks */
50*16260Smckusick BUFAREA	fileblk;		/* other blks in filesys */
51*16260Smckusick BUFAREA	sblk;			/* file system superblock */
52*16260Smckusick BUFAREA	cgblk;			/* cylinder group blocks */
53*16260Smckusick 
54*16260Smckusick #define	initbarea(x)	(x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
55*16260Smckusick #define	dirty(x)	(x)->b_dirty = 1
56*16260Smckusick #define	inodirty()	inoblk.b_dirty = 1
57*16260Smckusick #define	sbdirty()	sblk.b_dirty = 1
58*16260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
59*16260Smckusick 
60*16260Smckusick #define	dirblk		fileblk.b_un
61*16260Smckusick #define	sblock		sblk.b_un.b_fs
62*16260Smckusick #define	cgrp		cgblk.b_un.b_cg
63*16260Smckusick 
64*16260Smckusick struct filecntl {
65*16260Smckusick 	int	rfdes;
66*16260Smckusick 	int	wfdes;
67*16260Smckusick 	int	mod;
68*16260Smckusick } dfile;			/* file descriptors for filesys */
69*16260Smckusick 
70*16260Smckusick struct inodesc {
71*16260Smckusick 	char id_type;		/* type of descriptor, DATA or ADDR */
72*16260Smckusick 	int (*id_func)();	/* function to be applied to blocks of inode */
73*16260Smckusick 	ino_t id_number;	/* inode number described */
74*16260Smckusick 	ino_t id_parent;	/* for DATA nodes, their parent */
75*16260Smckusick 	daddr_t id_blkno;	/* current block number being examined */
76*16260Smckusick 	int id_numfrags;	/* number of frags contained in block */
77*16260Smckusick 	long id_filesize;	/* for DATA nodes, the size of the directory */
78*16260Smckusick 	int id_loc;		/* for DATA nodes, current location in dir */
79*16260Smckusick 	int id_entryno;		/* for DATA nodes, current entry number */
80*16260Smckusick 	DIRECT *id_dirp;	/* for data nodes, ptr to current entry */
81*16260Smckusick 	enum {DONTKNOW, NOFIX, FIX} id_fix; /* policy on fixing errors */
82*16260Smckusick };
83*16260Smckusick /* file types */
84*16260Smckusick #define	DATA	1
85*16260Smckusick #define	ADDR	2
86*16260Smckusick 
87*16260Smckusick 
88*16260Smckusick daddr_t	duplist[DUPTBLSIZE];	/* dup block table */
89*16260Smckusick daddr_t	*enddup;		/* next entry in dup table */
90*16260Smckusick daddr_t	*muldup;		/* multiple dups part of table */
91*16260Smckusick 
92*16260Smckusick ino_t	badlncnt[MAXLNCNT];	/* table of inos with zero link cnts */
93*16260Smckusick ino_t	*badlnp;		/* next entry in table */
94*16260Smckusick 
95*16260Smckusick char	rawflg;
96*16260Smckusick char	*devname;
97*16260Smckusick char	nflag;			/* assume a no response */
98*16260Smckusick char	yflag;			/* assume a yes response */
99*16260Smckusick int	bflag;			/* location of alternate super block */
100*16260Smckusick int	debug;			/* output debugging info */
101*16260Smckusick char	preen;			/* just fix normal inconsistencies */
102*16260Smckusick char	rplyflag;		/* any questions asked? */
103*16260Smckusick char	hotroot;		/* checking root device */
104*16260Smckusick char	fixcg;			/* corrupted free list bit maps */
105*16260Smckusick 
106*16260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
107*16260Smckusick char	*freemap;		/* ptr to secondary blk allocation map */
108*16260Smckusick char	*statemap;		/* ptr to inode state table */
109*16260Smckusick short	*lncntp;		/* ptr to link count table */
110*16260Smckusick 
111*16260Smckusick char	*srchname;		/* name being searched for in dir */
112*16260Smckusick char	pathname[BUFSIZ];	/* current pathname */
113*16260Smckusick char	*pathp;			/* pointer to pathname position */
114*16260Smckusick char	*endpathname;
115*16260Smckusick 
116*16260Smckusick char	*lfname;
117*16260Smckusick 
118*16260Smckusick ino_t	imax;			/* number of inodes */
119*16260Smckusick ino_t	lastino;		/* hiwater mark of inodes */
120*16260Smckusick ino_t	lfdir;			/* lost & found directory */
121*16260Smckusick 
122*16260Smckusick off_t	maxblk;			/* largest logical blk in file */
123*16260Smckusick off_t	bmapsz;			/* num chars in blockmap */
124*16260Smckusick 
125*16260Smckusick daddr_t	n_ffree;		/* number of small free blocks */
126*16260Smckusick daddr_t	n_bfree;		/* number of large free blocks */
127*16260Smckusick daddr_t	n_blks;			/* number of blocks used */
128*16260Smckusick daddr_t	n_files;		/* number of files seen */
129*16260Smckusick daddr_t	n_index;
130*16260Smckusick daddr_t	n_bad;
131*16260Smckusick daddr_t	fmax;			/* number of blocks in the volume */
132*16260Smckusick 
133*16260Smckusick daddr_t	badblk;
134*16260Smckusick daddr_t	dupblk;
135*16260Smckusick 
136*16260Smckusick int	inosumbad;
137*16260Smckusick int	offsumbad;
138*16260Smckusick int	frsumbad;
139*16260Smckusick int	sbsumbad;
140*16260Smckusick 
141*16260Smckusick #define	zapino(x)	(*(x) = zino)
142*16260Smckusick struct	dinode zino;
143*16260Smckusick 
144*16260Smckusick #define	setbmap(x)	setbit(blockmap, x)
145*16260Smckusick #define	getbmap(x)	isset(blockmap, x)
146*16260Smckusick #define	clrbmap(x)	clrbit(blockmap, x)
147*16260Smckusick 
148*16260Smckusick #define	setfmap(x)	setbit(freemap, x)
149*16260Smckusick #define	getfmap(x)	isset(freemap, x)
150*16260Smckusick #define	clrfmap(x)	clrbit(freemap, x)
151*16260Smckusick 
152*16260Smckusick #define	ALTERED	010
153*16260Smckusick #define	KEEPON	04
154*16260Smckusick #define	SKIP	02
155*16260Smckusick #define	STOP	01
156*16260Smckusick 
157*16260Smckusick time_t	time();
158*16260Smckusick DINODE	*ginode();
159*16260Smckusick BUFAREA	*getblk();
160*16260Smckusick int	findino();
161