xref: /csrg-svn/sbin/fsck/fsck.h (revision 30518)
122057Sdist /*
222057Sdist  * Copyright (c) 1980 Regents of the University of California.
322057Sdist  * All rights reserved.  The Berkeley software License Agreement
422057Sdist  * specifies the terms and conditions for redistribution.
522057Sdist  *
6*30518Smckusick  *	@(#)fsck.h	5.3 (Berkeley) 02/18/87
722057Sdist  */
816260Smckusick 
916260Smckusick #define	MAXDUP		10	/* limit on dup blks (per inode) */
1016260Smckusick #define	MAXBAD		10	/* limit on bad blks (per inode) */
1116260Smckusick 
1216260Smckusick typedef	int	(*SIG_TYP)();
1316260Smckusick 
1416260Smckusick #ifndef BUFSIZ
1516260Smckusick #define BUFSIZ 1024
1616260Smckusick #endif
1716260Smckusick 
1817936Smckusick #define	USTATE	01		/* inode not allocated */
1917936Smckusick #define	FSTATE	02		/* inode is file */
2017936Smckusick #define	DSTATE	03		/* inode is directory */
2117936Smckusick #define	DFOUND	04		/* directory found during descent */
2217936Smckusick #define	DCLEAR	05		/* directory is to be cleared */
2317936Smckusick #define	FCLEAR	06		/* file is to be cleared */
2416260Smckusick 
2516260Smckusick typedef struct dinode	DINODE;
2616260Smckusick typedef struct direct	DIRECT;
2716260Smckusick 
2817930Smckusick #define	ALLOC(dip)	(((dip)->di_mode & IFMT) != 0)
2917930Smckusick #define	DIRCT(dip)	(((dip)->di_mode & IFMT) == IFDIR)
3017930Smckusick #define	SPECIAL(dip) \
3117930Smckusick 	(((dip)->di_mode & IFMT) == IFBLK || ((dip)->di_mode & IFMT) == IFCHR)
3216260Smckusick 
3317930Smckusick #define	MAXNINDIR	(MAXBSIZE / sizeof (daddr_t))
3417930Smckusick #define	MAXINOPB	(MAXBSIZE / sizeof (struct dinode))
3517930Smckusick #define	SPERB		(MAXBSIZE / sizeof(short))
3617930Smckusick 
3716260Smckusick struct bufarea {
3816260Smckusick 	struct bufarea	*b_next;		/* must be first */
3916260Smckusick 	daddr_t	b_bno;
4016260Smckusick 	int	b_size;
4121540Smckusick 	int	b_errs;
4216260Smckusick 	union {
4316260Smckusick 		char	b_buf[MAXBSIZE];	/* buffer space */
4416260Smckusick 		short	b_lnks[SPERB];		/* link counts */
4516260Smckusick 		daddr_t	b_indir[MAXNINDIR];	/* indirect block */
4616260Smckusick 		struct	fs b_fs;		/* super block */
4716260Smckusick 		struct	cg b_cg;		/* cylinder group */
4816260Smckusick 		struct dinode b_dinode[MAXINOPB]; /* inode block */
4916260Smckusick 	} b_un;
5016260Smckusick 	char	b_dirty;
5116260Smckusick };
5216260Smckusick 
5316260Smckusick typedef struct bufarea BUFAREA;
5416260Smckusick 
5516260Smckusick BUFAREA	inoblk;			/* inode blocks */
5616260Smckusick BUFAREA	fileblk;		/* other blks in filesys */
5716260Smckusick BUFAREA	sblk;			/* file system superblock */
5816260Smckusick BUFAREA	cgblk;			/* cylinder group blocks */
5916260Smckusick 
6016260Smckusick #define	initbarea(x)	(x)->b_dirty = 0;(x)->b_bno = (daddr_t)-1
6116260Smckusick #define	dirty(x)	(x)->b_dirty = 1
6216260Smckusick #define	inodirty()	inoblk.b_dirty = 1
6316260Smckusick #define	sbdirty()	sblk.b_dirty = 1
6416260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
6516260Smckusick 
6616260Smckusick #define	dirblk		fileblk.b_un
6716260Smckusick #define	sblock		sblk.b_un.b_fs
6816260Smckusick #define	cgrp		cgblk.b_un.b_cg
6916260Smckusick 
7016260Smckusick struct filecntl {
7116260Smckusick 	int	rfdes;
7216260Smckusick 	int	wfdes;
7316260Smckusick 	int	mod;
7416260Smckusick } dfile;			/* file descriptors for filesys */
7516260Smckusick 
7617930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX};
7717930Smckusick 
7816260Smckusick struct inodesc {
7917930Smckusick 	enum fixstate id_fix;	/* policy on fixing errors */
8016260Smckusick 	int (*id_func)();	/* function to be applied to blocks of inode */
8116260Smckusick 	ino_t id_number;	/* inode number described */
8216260Smckusick 	ino_t id_parent;	/* for DATA nodes, their parent */
8316260Smckusick 	daddr_t id_blkno;	/* current block number being examined */
8416260Smckusick 	int id_numfrags;	/* number of frags contained in block */
8516260Smckusick 	long id_filesize;	/* for DATA nodes, the size of the directory */
8616260Smckusick 	int id_loc;		/* for DATA nodes, current location in dir */
8716260Smckusick 	int id_entryno;		/* for DATA nodes, current entry number */
8817930Smckusick 	DIRECT *id_dirp;	/* for DATA nodes, ptr to current entry */
8917930Smckusick 	char *id_name;		/* for DATA nodes, name to find or enter */
9017930Smckusick 	char id_type;		/* type of descriptor, DATA or ADDR */
9116260Smckusick };
9216260Smckusick /* file types */
9316260Smckusick #define	DATA	1
9416260Smckusick #define	ADDR	2
9516260Smckusick 
9621743Smckusick /*
9721759Smckusick  * Linked list of duplicate blocks.
9821759Smckusick  *
9921759Smckusick  * The list is composed of two parts. The first part of the
10021759Smckusick  * list (from duplist through the node pointed to by muldup)
10121759Smckusick  * contains a single copy of each duplicate block that has been
10221759Smckusick  * found. The second part of the list (from muldup to the end)
10321759Smckusick  * contains duplicate blocks that have been found more than once.
10421759Smckusick  * To check if a block has been found as a duplicate it is only
10521759Smckusick  * necessary to search from duplist through muldup. To find the
10621759Smckusick  * total number of times that a block has been found as a duplicate
10721759Smckusick  * the entire list must be searched for occurences of the block
10821759Smckusick  * in question. The following diagram shows a sample list where
10921759Smckusick  * w (found twice), x (found once), y (found three times), and z
11021759Smckusick  * (found once) are duplicate block numbers:
11121759Smckusick  *
11221759Smckusick  *    w -> y -> x -> z -> y -> w -> y
11321759Smckusick  *    ^		     ^
11421759Smckusick  *    |		     |
11521759Smckusick  * duplist	  muldup
11621743Smckusick  */
11721743Smckusick struct dups {
11821743Smckusick 	struct dups *next;
11921743Smckusick 	daddr_t dup;
12021743Smckusick };
12121743Smckusick struct dups *duplist;		/* head of dup list */
12221743Smckusick struct dups *muldup;		/* end of unique duplicate dup block numbers */
12316260Smckusick 
12421759Smckusick /*
12521759Smckusick  * Linked list of inodes with zero link counts.
12621759Smckusick  */
12721759Smckusick struct zlncnt {
12821759Smckusick 	struct zlncnt *next;
12921759Smckusick 	ino_t zlncnt;
13021759Smckusick };
13121759Smckusick struct zlncnt *zlnhead;		/* head of zero link count list */
13216260Smckusick 
13316260Smckusick char	rawflg;
13416260Smckusick char	*devname;
135*30518Smckusick long	dev_bsize;		/* computed value of DEV_BSIZE */
13616260Smckusick char	nflag;			/* assume a no response */
13716260Smckusick char	yflag;			/* assume a yes response */
13816260Smckusick int	bflag;			/* location of alternate super block */
13916260Smckusick int	debug;			/* output debugging info */
14016260Smckusick char	preen;			/* just fix normal inconsistencies */
14116260Smckusick char	hotroot;		/* checking root device */
14216260Smckusick 
14316260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
14416260Smckusick char	*statemap;		/* ptr to inode state table */
14516260Smckusick short	*lncntp;		/* ptr to link count table */
14616260Smckusick 
14716260Smckusick char	pathname[BUFSIZ];	/* current pathname */
14816260Smckusick char	*pathp;			/* pointer to pathname position */
14916260Smckusick char	*endpathname;
15016260Smckusick 
15117930Smckusick daddr_t	fmax;			/* number of blocks in the volume */
15216260Smckusick ino_t	imax;			/* number of inodes */
15316260Smckusick ino_t	lastino;		/* hiwater mark of inodes */
15417930Smckusick ino_t	lfdir;			/* lost & found directory inode number */
15517930Smckusick char	*lfname;		/* lost & found directory name */
15616260Smckusick 
15716260Smckusick off_t	maxblk;			/* largest logical blk in file */
15816260Smckusick off_t	bmapsz;			/* num chars in blockmap */
15916260Smckusick 
16016260Smckusick daddr_t	n_blks;			/* number of blocks used */
16116260Smckusick daddr_t	n_files;		/* number of files seen */
16216260Smckusick 
16316260Smckusick #define	zapino(x)	(*(x) = zino)
16416260Smckusick struct	dinode zino;
16516260Smckusick 
16616260Smckusick #define	setbmap(x)	setbit(blockmap, x)
16716260Smckusick #define	getbmap(x)	isset(blockmap, x)
16816260Smckusick #define	clrbmap(x)	clrbit(blockmap, x)
16916260Smckusick 
17030354Smckusick #define	FOUND	020
17116260Smckusick #define	ALTERED	010
17216260Smckusick #define	KEEPON	04
17316260Smckusick #define	SKIP	02
17416260Smckusick #define	STOP	01
17516260Smckusick 
17616260Smckusick time_t	time();
17716260Smckusick DINODE	*ginode();
17816260Smckusick BUFAREA	*getblk();
17916260Smckusick int	findino();
180