xref: /csrg-svn/sbin/fsck/fsck.h (revision 21759)
1*21759Smckusick /* @(#)fsck.h	3.6 (Berkeley) 06/02/85 */
216260Smckusick 
316260Smckusick #define	MAXDUP		10	/* limit on dup blks (per inode) */
416260Smckusick #define	MAXBAD		10	/* limit on bad blks (per inode) */
516260Smckusick 
616260Smckusick typedef	int	(*SIG_TYP)();
716260Smckusick 
816260Smckusick #ifndef BUFSIZ
916260Smckusick #define BUFSIZ 1024
1016260Smckusick #endif
1116260Smckusick 
1217936Smckusick #define	USTATE	01		/* inode not allocated */
1317936Smckusick #define	FSTATE	02		/* inode is file */
1417936Smckusick #define	DSTATE	03		/* inode is directory */
1517936Smckusick #define	DFOUND	04		/* directory found during descent */
1617936Smckusick #define	DCLEAR	05		/* directory is to be cleared */
1717936Smckusick #define	FCLEAR	06		/* file is to be cleared */
1816260Smckusick 
1916260Smckusick typedef struct dinode	DINODE;
2016260Smckusick typedef struct direct	DIRECT;
2116260Smckusick 
2217930Smckusick #define	ALLOC(dip)	(((dip)->di_mode & IFMT) != 0)
2317930Smckusick #define	DIRCT(dip)	(((dip)->di_mode & IFMT) == IFDIR)
2417930Smckusick #define	SPECIAL(dip) \
2517930Smckusick 	(((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR)
2616260Smckusick 
2717930Smckusick #define	MAXNINDIR	(MAXBSIZE / sizeof (daddr_t))
2817930Smckusick #define	MAXINOPB	(MAXBSIZE / sizeof (struct dinode))
2917930Smckusick #define	SPERB		(MAXBSIZE / sizeof(short))
3017930Smckusick 
3116260Smckusick struct bufarea {
3216260Smckusick 	struct bufarea	*b_next;		/* must be first */
3316260Smckusick 	daddr_t	b_bno;
3416260Smckusick 	int	b_size;
3521540Smckusick 	int	b_errs;
3616260Smckusick 	union {
3716260Smckusick 		char	b_buf[MAXBSIZE];	/* buffer space */
3816260Smckusick 		short	b_lnks[SPERB];		/* link counts */
3916260Smckusick 		daddr_t	b_indir[MAXNINDIR];	/* indirect block */
4016260Smckusick 		struct	fs b_fs;		/* super block */
4116260Smckusick 		struct	cg b_cg;		/* cylinder group */
4216260Smckusick 		struct dinode b_dinode[MAXINOPB]; /* inode block */
4316260Smckusick 	} b_un;
4416260Smckusick 	char	b_dirty;
4516260Smckusick };
4616260Smckusick 
4716260Smckusick typedef struct bufarea BUFAREA;
4816260Smckusick 
4916260Smckusick BUFAREA	inoblk;			/* inode blocks */
5016260Smckusick BUFAREA	fileblk;		/* other blks in filesys */
5116260Smckusick BUFAREA	sblk;			/* file system superblock */
5216260Smckusick BUFAREA	cgblk;			/* cylinder group blocks */
5316260Smckusick 
5416260Smckusick #define	initbarea(x)	(x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
5516260Smckusick #define	dirty(x)	(x)->b_dirty = 1
5616260Smckusick #define	inodirty()	inoblk.b_dirty = 1
5716260Smckusick #define	sbdirty()	sblk.b_dirty = 1
5816260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
5916260Smckusick 
6016260Smckusick #define	dirblk		fileblk.b_un
6116260Smckusick #define	sblock		sblk.b_un.b_fs
6216260Smckusick #define	cgrp		cgblk.b_un.b_cg
6316260Smckusick 
6416260Smckusick struct filecntl {
6516260Smckusick 	int	rfdes;
6616260Smckusick 	int	wfdes;
6716260Smckusick 	int	mod;
6816260Smckusick } dfile;			/* file descriptors for filesys */
6916260Smckusick 
7017930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX};
7117930Smckusick 
7216260Smckusick struct inodesc {
7317930Smckusick 	enum fixstate id_fix;	/* policy on fixing errors */
7416260Smckusick 	int (*id_func)();	/* function to be applied to blocks of inode */
7516260Smckusick 	ino_t id_number;	/* inode number described */
7616260Smckusick 	ino_t id_parent;	/* for DATA nodes, their parent */
7716260Smckusick 	daddr_t id_blkno;	/* current block number being examined */
7816260Smckusick 	int id_numfrags;	/* number of frags contained in block */
7916260Smckusick 	long id_filesize;	/* for DATA nodes, the size of the directory */
8016260Smckusick 	int id_loc;		/* for DATA nodes, current location in dir */
8116260Smckusick 	int id_entryno;		/* for DATA nodes, current entry number */
8217930Smckusick 	DIRECT *id_dirp;	/* for DATA nodes, ptr to current entry */
8317930Smckusick 	char *id_name;		/* for DATA nodes, name to find or enter */
8417930Smckusick 	char id_type;		/* type of descriptor, DATA or ADDR */
8516260Smckusick };
8616260Smckusick /* file types */
8716260Smckusick #define	DATA	1
8816260Smckusick #define	ADDR	2
8916260Smckusick 
9021743Smckusick /*
91*21759Smckusick  * Linked list of duplicate blocks.
92*21759Smckusick  *
93*21759Smckusick  * The list is composed of two parts. The first part of the
94*21759Smckusick  * list (from duplist through the node pointed to by muldup)
95*21759Smckusick  * contains a single copy of each duplicate block that has been
96*21759Smckusick  * found. The second part of the list (from muldup to the end)
97*21759Smckusick  * contains duplicate blocks that have been found more than once.
98*21759Smckusick  * To check if a block has been found as a duplicate it is only
99*21759Smckusick  * necessary to search from duplist through muldup. To find the
100*21759Smckusick  * total number of times that a block has been found as a duplicate
101*21759Smckusick  * the entire list must be searched for occurences of the block
102*21759Smckusick  * in question. The following diagram shows a sample list where
103*21759Smckusick  * w (found twice), x (found once), y (found three times), and z
104*21759Smckusick  * (found once) are duplicate block numbers:
105*21759Smckusick  *
106*21759Smckusick  *    w -> y -> x -> z -> y -> w -> y
107*21759Smckusick  *    ^		     ^
108*21759Smckusick  *    |		     |
109*21759Smckusick  * duplist	  muldup
11021743Smckusick  */
11121743Smckusick struct dups {
11221743Smckusick 	struct dups *next;
11321743Smckusick 	daddr_t dup;
11421743Smckusick };
11521743Smckusick struct dups *duplist;		/* head of dup list */
11621743Smckusick struct dups *muldup;		/* end of unique duplicate dup block numbers */
11716260Smckusick 
118*21759Smckusick /*
119*21759Smckusick  * Linked list of inodes with zero link counts.
120*21759Smckusick  */
121*21759Smckusick struct zlncnt {
122*21759Smckusick 	struct zlncnt *next;
123*21759Smckusick 	ino_t zlncnt;
124*21759Smckusick };
125*21759Smckusick struct zlncnt *zlnhead;		/* head of zero link count list */
12616260Smckusick 
12716260Smckusick char	rawflg;
12816260Smckusick char	*devname;
12916260Smckusick char	nflag;			/* assume a no response */
13016260Smckusick char	yflag;			/* assume a yes response */
13116260Smckusick int	bflag;			/* location of alternate super block */
13216260Smckusick int	debug;			/* output debugging info */
13316260Smckusick char	preen;			/* just fix normal inconsistencies */
13416260Smckusick char	hotroot;		/* checking root device */
13516260Smckusick 
13616260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
13716260Smckusick char	*statemap;		/* ptr to inode state table */
13816260Smckusick short	*lncntp;		/* ptr to link count table */
13916260Smckusick 
14016260Smckusick char	pathname[BUFSIZ];	/* current pathname */
14116260Smckusick char	*pathp;			/* pointer to pathname position */
14216260Smckusick char	*endpathname;
14316260Smckusick 
14417930Smckusick daddr_t	fmax;			/* number of blocks in the volume */
14516260Smckusick ino_t	imax;			/* number of inodes */
14616260Smckusick ino_t	lastino;		/* hiwater mark of inodes */
14717930Smckusick ino_t	lfdir;			/* lost & found directory inode number */
14817930Smckusick char	*lfname;		/* lost & found directory name */
14916260Smckusick 
15016260Smckusick off_t	maxblk;			/* largest logical blk in file */
15116260Smckusick off_t	bmapsz;			/* num chars in blockmap */
15216260Smckusick 
15316260Smckusick daddr_t	n_blks;			/* number of blocks used */
15416260Smckusick daddr_t	n_files;		/* number of files seen */
15516260Smckusick 
15616260Smckusick #define	zapino(x)	(*(x) = zino)
15716260Smckusick struct	dinode zino;
15816260Smckusick 
15916260Smckusick #define	setbmap(x)	setbit(blockmap, x)
16016260Smckusick #define	getbmap(x)	isset(blockmap, x)
16116260Smckusick #define	clrbmap(x)	clrbit(blockmap, x)
16216260Smckusick 
16316260Smckusick #define	ALTERED	010
16416260Smckusick #define	KEEPON	04
16516260Smckusick #define	SKIP	02
16616260Smckusick #define	STOP	01
16716260Smckusick 
16816260Smckusick time_t	time();
16916260Smckusick DINODE	*ginode();
17016260Smckusick BUFAREA	*getblk();
17116260Smckusick int	findino();
172