xref: /csrg-svn/sbin/fsck/fsck.h (revision 39973)
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*39973Smckusick  *	@(#)fsck.h	5.9 (Berkeley) 02/01/90
722057Sdist  */
816260Smckusick 
934225Smckusick #define	MAXDUP		10	 /* limit on dup blks (per inode) */
1034225Smckusick #define	MAXBAD		10	 /* limit on bad blks (per inode) */
1134225Smckusick #define MAXBUFSPACE	128*1024 /* maximum space to allocate to buffers */
1216260Smckusick 
1316260Smckusick #ifndef BUFSIZ
1416260Smckusick #define BUFSIZ 1024
1516260Smckusick #endif
1616260Smckusick 
1717936Smckusick #define	USTATE	01		/* inode not allocated */
1817936Smckusick #define	FSTATE	02		/* inode is file */
1917936Smckusick #define	DSTATE	03		/* inode is directory */
2017936Smckusick #define	DFOUND	04		/* directory found during descent */
2117936Smckusick #define	DCLEAR	05		/* directory is to be cleared */
2217936Smckusick #define	FCLEAR	06		/* file is to be cleared */
2316260Smckusick 
2434225Smckusick /*
2534225Smckusick  * buffer cache structure.
2634225Smckusick  */
2716260Smckusick struct bufarea {
2834225Smckusick 	struct bufarea	*b_next;		/* free list queue */
2934225Smckusick 	struct bufarea	*b_prev;		/* free list queue */
3016260Smckusick 	daddr_t	b_bno;
3116260Smckusick 	int	b_size;
3221540Smckusick 	int	b_errs;
3334225Smckusick 	int	b_flags;
3416260Smckusick 	union {
3534225Smckusick 		char	*b_buf;			/* buffer space */
3634225Smckusick 		daddr_t	*b_indir;		/* indirect block */
3734225Smckusick 		struct	fs *b_fs;		/* super block */
3834225Smckusick 		struct	cg *b_cg;		/* cylinder group */
39*39973Smckusick 		struct	dinode *b_dinode;	/* inode block */
4016260Smckusick 	} b_un;
4116260Smckusick 	char	b_dirty;
4216260Smckusick };
4316260Smckusick 
4434225Smckusick #define	B_INUSE 1
4516260Smckusick 
4634225Smckusick #define	MINBUFS		5	/* minimum number of buffers required */
47*39973Smckusick struct bufarea bufhead;		/* head of list of other blks in filesys */
48*39973Smckusick struct bufarea sblk;		/* file system superblock */
49*39973Smckusick struct bufarea cgblk;		/* cylinder group blocks */
50*39973Smckusick struct bufarea *getdatablk();
5116260Smckusick 
52*39973Smckusick #define	dirty(bp)	(bp)->b_dirty = 1
53*39973Smckusick #define	initbarea(bp) \
54*39973Smckusick 	(bp)->b_dirty = 0; \
55*39973Smckusick 	(bp)->b_bno = (daddr_t)-1; \
56*39973Smckusick 	(bp)->b_flags = 0;
5734225Smckusick 
5816260Smckusick #define	sbdirty()	sblk.b_dirty = 1
5916260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
6034225Smckusick #define	sblock		(*sblk.b_un.b_fs)
6134225Smckusick #define	cgrp		(*cgblk.b_un.b_cg)
6216260Smckusick 
6317930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX};
6417930Smckusick 
6516260Smckusick struct inodesc {
6617930Smckusick 	enum fixstate id_fix;	/* policy on fixing errors */
6716260Smckusick 	int (*id_func)();	/* function to be applied to blocks of inode */
6816260Smckusick 	ino_t id_number;	/* inode number described */
6916260Smckusick 	ino_t id_parent;	/* for DATA nodes, their parent */
7016260Smckusick 	daddr_t id_blkno;	/* current block number being examined */
7116260Smckusick 	int id_numfrags;	/* number of frags contained in block */
7216260Smckusick 	long id_filesize;	/* for DATA nodes, the size of the directory */
7316260Smckusick 	int id_loc;		/* for DATA nodes, current location in dir */
7416260Smckusick 	int id_entryno;		/* for DATA nodes, current entry number */
75*39973Smckusick 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
7617930Smckusick 	char *id_name;		/* for DATA nodes, name to find or enter */
7717930Smckusick 	char id_type;		/* type of descriptor, DATA or ADDR */
7816260Smckusick };
7916260Smckusick /* file types */
8016260Smckusick #define	DATA	1
8116260Smckusick #define	ADDR	2
8216260Smckusick 
8321743Smckusick /*
8421759Smckusick  * Linked list of duplicate blocks.
8521759Smckusick  *
8621759Smckusick  * The list is composed of two parts. The first part of the
8721759Smckusick  * list (from duplist through the node pointed to by muldup)
8821759Smckusick  * contains a single copy of each duplicate block that has been
8921759Smckusick  * found. The second part of the list (from muldup to the end)
9021759Smckusick  * contains duplicate blocks that have been found more than once.
9121759Smckusick  * To check if a block has been found as a duplicate it is only
9221759Smckusick  * necessary to search from duplist through muldup. To find the
9321759Smckusick  * total number of times that a block has been found as a duplicate
9421759Smckusick  * the entire list must be searched for occurences of the block
9521759Smckusick  * in question. The following diagram shows a sample list where
9621759Smckusick  * w (found twice), x (found once), y (found three times), and z
9721759Smckusick  * (found once) are duplicate block numbers:
9821759Smckusick  *
9921759Smckusick  *    w -> y -> x -> z -> y -> w -> y
10021759Smckusick  *    ^		     ^
10121759Smckusick  *    |		     |
10221759Smckusick  * duplist	  muldup
10321743Smckusick  */
10421743Smckusick struct dups {
10521743Smckusick 	struct dups *next;
10621743Smckusick 	daddr_t dup;
10721743Smckusick };
10821743Smckusick struct dups *duplist;		/* head of dup list */
10921743Smckusick struct dups *muldup;		/* end of unique duplicate dup block numbers */
11016260Smckusick 
11121759Smckusick /*
11221759Smckusick  * Linked list of inodes with zero link counts.
11321759Smckusick  */
11421759Smckusick struct zlncnt {
11521759Smckusick 	struct zlncnt *next;
11621759Smckusick 	ino_t zlncnt;
11721759Smckusick };
11821759Smckusick struct zlncnt *zlnhead;		/* head of zero link count list */
11916260Smckusick 
120*39973Smckusick char	*devname;		/* name of device being checked */
12130518Smckusick long	dev_bsize;		/* computed value of DEV_BSIZE */
12230609Skarels long	secsize;		/* actual disk sector size */
12316260Smckusick char	nflag;			/* assume a no response */
12416260Smckusick char	yflag;			/* assume a yes response */
12516260Smckusick int	bflag;			/* location of alternate super block */
12616260Smckusick int	debug;			/* output debugging info */
12734139Smckusick int	cvtflag;		/* convert to old file system format */
12816260Smckusick char	preen;			/* just fix normal inconsistencies */
12916260Smckusick char	hotroot;		/* checking root device */
13030859Skarels char	havesb;			/* superblock has been read */
131*39973Smckusick int	fsmodified;		/* 1 => write done to file system */
132*39973Smckusick int	fsreadfd;		/* file descriptor for reading file system */
133*39973Smckusick int	fswritefd;		/* file descriptor for writing file system */
13416260Smckusick 
135*39973Smckusick daddr_t	maxfsblock;		/* number of blocks in the file system */
13616260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
137*39973Smckusick ino_t	maxino;			/* number of inodes in file system */
138*39973Smckusick ino_t	lastino;		/* last inode in use */
13916260Smckusick char	*statemap;		/* ptr to inode state table */
14016260Smckusick short	*lncntp;		/* ptr to link count table */
14116260Smckusick 
14216260Smckusick char	pathname[BUFSIZ];	/* current pathname */
143*39973Smckusick char	*pathp;			/* ptr to current position in pathname */
144*39973Smckusick char	*endpathname;		/* ptr to current end of pathname */
14516260Smckusick 
14617930Smckusick ino_t	lfdir;			/* lost & found directory inode number */
14717930Smckusick char	*lfname;		/* lost & found directory name */
14836827Smckusick int	lfmode;			/* lost & found directory creation mode */
14916260Smckusick 
150*39973Smckusick daddr_t	n_blks;			/* number of blocks in use */
151*39973Smckusick daddr_t	n_files;		/* number of files in use */
15216260Smckusick 
153*39973Smckusick #define	clearinode(dp)	(*(dp) = zino)
15416260Smckusick struct	dinode zino;
15516260Smckusick 
156*39973Smckusick #define	setbmap(blkno)	setbit(blockmap, blkno)
157*39973Smckusick #define	testbmap(blkno)	isset(blockmap, blkno)
158*39973Smckusick #define	clrbmap(blkno)	clrbit(blockmap, blkno)
15916260Smckusick 
160*39973Smckusick #define	STOP	0x01
161*39973Smckusick #define	SKIP	0x02
162*39973Smckusick #define	KEEPON	0x04
163*39973Smckusick #define	ALTERED	0x08
164*39973Smckusick #define	FOUND	0x10
16516260Smckusick 
166*39973Smckusick time_t time();
167*39973Smckusick struct dinode *ginode();
168*39973Smckusick struct bufarea *getblk();
169*39973Smckusick ino_t allocino();
170*39973Smckusick int findino();
171