xref: /csrg-svn/sbin/fsck/fsck.h (revision 68908)
122057Sdist /*
261492Sbostic  * Copyright (c) 1980, 1986, 1993
361492Sbostic  *	The Regents of the University of California.  All rights reserved.
422057Sdist  *
542701Sbostic  * %sccs.include.redist.c%
639976Smckusick  *
7*68908Smckusick  *	@(#)fsck.h	8.3 (Berkeley) 04/27/95
822057Sdist  */
916260Smckusick 
10*68908Smckusick #include <unistd.h>
11*68908Smckusick #include <stdlib.h>
12*68908Smckusick #include <stdio.h>
13*68908Smckusick 
1440023Smckusick #define	MAXDUP		10	/* limit on dup blks (per inode) */
1540023Smckusick #define	MAXBAD		10	/* limit on bad blks (per inode) */
1640023Smckusick #define	MAXBUFSPACE	40*1024	/* maximum space to allocate to buffers */
1740023Smckusick #define	INOBUFSIZE	56*1024	/* size of buffer to read inodes in pass1 */
1816260Smckusick 
1916260Smckusick #ifndef BUFSIZ
2016260Smckusick #define BUFSIZ 1024
2116260Smckusick #endif
2216260Smckusick 
2317936Smckusick #define	USTATE	01		/* inode not allocated */
2417936Smckusick #define	FSTATE	02		/* inode is file */
2517936Smckusick #define	DSTATE	03		/* inode is directory */
2617936Smckusick #define	DFOUND	04		/* directory found during descent */
2717936Smckusick #define	DCLEAR	05		/* directory is to be cleared */
2817936Smckusick #define	FCLEAR	06		/* file is to be cleared */
2916260Smckusick 
3034225Smckusick /*
3134225Smckusick  * buffer cache structure.
3234225Smckusick  */
3316260Smckusick struct bufarea {
3468548Smckusick 	struct bufarea *b_next;		/* free list queue */
3568548Smckusick 	struct bufarea *b_prev;		/* free list queue */
3668548Smckusick 	ufs_daddr_t b_bno;
3768548Smckusick 	int b_size;
3868548Smckusick 	int b_errs;
3968548Smckusick 	int b_flags;
4016260Smckusick 	union {
4168548Smckusick 		char *b_buf;			/* buffer space */
4268548Smckusick 		ufs_daddr_t *b_indir;		/* indirect block */
4368548Smckusick 		struct fs *b_fs;		/* super block */
4468548Smckusick 		struct cg *b_cg;		/* cylinder group */
4568548Smckusick 		struct dinode *b_dinode;	/* inode block */
4616260Smckusick 	} b_un;
4768548Smckusick 	char b_dirty;
4816260Smckusick };
4916260Smckusick 
5034225Smckusick #define	B_INUSE 1
5116260Smckusick 
5234225Smckusick #define	MINBUFS		5	/* minimum number of buffers required */
5339973Smckusick struct bufarea bufhead;		/* head of list of other blks in filesys */
5439973Smckusick struct bufarea sblk;		/* file system superblock */
5539973Smckusick struct bufarea cgblk;		/* cylinder group blocks */
5640650Smckusick struct bufarea *pdirbp;		/* current directory contents */
5740650Smckusick struct bufarea *pbp;		/* current inode block */
5839973Smckusick struct bufarea *getdatablk();
5916260Smckusick 
6039973Smckusick #define	dirty(bp)	(bp)->b_dirty = 1
6139973Smckusick #define	initbarea(bp) \
6239973Smckusick 	(bp)->b_dirty = 0; \
6368548Smckusick 	(bp)->b_bno = (ufs_daddr_t)-1; \
6439973Smckusick 	(bp)->b_flags = 0;
6534225Smckusick 
6616260Smckusick #define	sbdirty()	sblk.b_dirty = 1
6716260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
6834225Smckusick #define	sblock		(*sblk.b_un.b_fs)
6934225Smckusick #define	cgrp		(*cgblk.b_un.b_cg)
7016260Smckusick 
7144997Smckusick enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
7217930Smckusick 
7316260Smckusick struct inodesc {
7417930Smckusick 	enum fixstate id_fix;	/* policy on fixing errors */
7516260Smckusick 	int (*id_func)();	/* function to be applied to blocks of inode */
7616260Smckusick 	ino_t id_number;	/* inode number described */
7716260Smckusick 	ino_t id_parent;	/* for DATA nodes, their parent */
7868548Smckusick 	ufs_daddr_t id_blkno;	/* current block number being examined */
7916260Smckusick 	int id_numfrags;	/* number of frags contained in block */
8052982Smckusick 	quad_t id_filesize;	/* for DATA nodes, the size of the directory */
8116260Smckusick 	int id_loc;		/* for DATA nodes, current location in dir */
8216260Smckusick 	int id_entryno;		/* for DATA nodes, current entry number */
8339973Smckusick 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
8417930Smckusick 	char *id_name;		/* for DATA nodes, name to find or enter */
8517930Smckusick 	char id_type;		/* type of descriptor, DATA or ADDR */
8616260Smckusick };
8716260Smckusick /* file types */
8816260Smckusick #define	DATA	1
8916260Smckusick #define	ADDR	2
9016260Smckusick 
9121743Smckusick /*
9221759Smckusick  * Linked list of duplicate blocks.
9321759Smckusick  *
9421759Smckusick  * The list is composed of two parts. The first part of the
9521759Smckusick  * list (from duplist through the node pointed to by muldup)
9621759Smckusick  * contains a single copy of each duplicate block that has been
9721759Smckusick  * found. The second part of the list (from muldup to the end)
9821759Smckusick  * contains duplicate blocks that have been found more than once.
9921759Smckusick  * To check if a block has been found as a duplicate it is only
10021759Smckusick  * necessary to search from duplist through muldup. To find the
10121759Smckusick  * total number of times that a block has been found as a duplicate
10221759Smckusick  * the entire list must be searched for occurences of the block
10321759Smckusick  * in question. The following diagram shows a sample list where
10421759Smckusick  * w (found twice), x (found once), y (found three times), and z
10521759Smckusick  * (found once) are duplicate block numbers:
10621759Smckusick  *
10721759Smckusick  *    w -> y -> x -> z -> y -> w -> y
10821759Smckusick  *    ^		     ^
10921759Smckusick  *    |		     |
11021759Smckusick  * duplist	  muldup
11121743Smckusick  */
11221743Smckusick struct dups {
11321743Smckusick 	struct dups *next;
11468548Smckusick 	ufs_daddr_t dup;
11521743Smckusick };
11621743Smckusick struct dups *duplist;		/* head of dup list */
11721743Smckusick struct dups *muldup;		/* end of unique duplicate dup block numbers */
11816260Smckusick 
11921759Smckusick /*
12021759Smckusick  * Linked list of inodes with zero link counts.
12121759Smckusick  */
12221759Smckusick struct zlncnt {
12321759Smckusick 	struct zlncnt *next;
12421759Smckusick 	ino_t zlncnt;
12521759Smckusick };
12621759Smckusick struct zlncnt *zlnhead;		/* head of zero link count list */
12716260Smckusick 
12840023Smckusick /*
12940023Smckusick  * Inode cache data structures.
13040023Smckusick  */
13140023Smckusick struct inoinfo {
13240023Smckusick 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
13340023Smckusick 	ino_t	i_number;		/* inode number of this entry */
13440023Smckusick 	ino_t	i_parent;		/* inode number of parent */
13540023Smckusick 	ino_t	i_dotdot;		/* inode number of `..' */
13640023Smckusick 	size_t	i_isize;		/* size of inode */
13740023Smckusick 	u_int	i_numblks;		/* size of block array in bytes */
13868548Smckusick 	ufs_daddr_t i_blks[1];		/* actually longer */
13940023Smckusick } **inphead, **inpsort;
14040023Smckusick long numdirs, listmax, inplast;
14140023Smckusick 
14261110Sbostic char	*cdevname;		/* name of device being checked */
14330518Smckusick long	dev_bsize;		/* computed value of DEV_BSIZE */
14430609Skarels long	secsize;		/* actual disk sector size */
14516260Smckusick char	nflag;			/* assume a no response */
14616260Smckusick char	yflag;			/* assume a yes response */
14716260Smckusick int	bflag;			/* location of alternate super block */
14816260Smckusick int	debug;			/* output debugging info */
14954503Smckusick int	cvtlevel;		/* convert to newer file system format */
15054503Smckusick int	doinglevel1;		/* converting to new cylinder group format */
15154503Smckusick int	doinglevel2;		/* converting to new inode format */
15254503Smckusick int	newinofmt;		/* filesystem has new inode format */
15316260Smckusick char	preen;			/* just fix normal inconsistencies */
15416260Smckusick char	hotroot;		/* checking root device */
15530859Skarels char	havesb;			/* superblock has been read */
15639973Smckusick int	fsmodified;		/* 1 => write done to file system */
15739973Smckusick int	fsreadfd;		/* file descriptor for reading file system */
15839973Smckusick int	fswritefd;		/* file descriptor for writing file system */
15916260Smckusick 
16068548Smckusick ufs_daddr_t maxfsblock;		/* number of blocks in the file system */
16116260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
16239973Smckusick ino_t	maxino;			/* number of inodes in file system */
16339973Smckusick ino_t	lastino;		/* last inode in use */
16416260Smckusick char	*statemap;		/* ptr to inode state table */
165*68908Smckusick u_char	*typemap;		/* ptr to inode type table */
16616260Smckusick short	*lncntp;		/* ptr to link count table */
16716260Smckusick 
16817930Smckusick ino_t	lfdir;			/* lost & found directory inode number */
16917930Smckusick char	*lfname;		/* lost & found directory name */
17036827Smckusick int	lfmode;			/* lost & found directory creation mode */
17116260Smckusick 
17268548Smckusick ufs_daddr_t n_blks;		/* number of blocks in use */
17368548Smckusick ufs_daddr_t n_files;		/* number of files in use */
17416260Smckusick 
17539973Smckusick #define	clearinode(dp)	(*(dp) = zino)
17616260Smckusick struct	dinode zino;
17716260Smckusick 
17839973Smckusick #define	setbmap(blkno)	setbit(blockmap, blkno)
17939973Smckusick #define	testbmap(blkno)	isset(blockmap, blkno)
18039973Smckusick #define	clrbmap(blkno)	clrbit(blockmap, blkno)
18116260Smckusick 
18239973Smckusick #define	STOP	0x01
18339973Smckusick #define	SKIP	0x02
18439973Smckusick #define	KEEPON	0x04
18539973Smckusick #define	ALTERED	0x08
18639973Smckusick #define	FOUND	0x10
18716260Smckusick 
188*68908Smckusick #define	EEXIT	8		/* Standard error exit. */
189*68908Smckusick 
190*68908Smckusick struct fstab;
191*68908Smckusick 
192*68908Smckusick void		adjust __P((struct inodesc *, int lcnt));
193*68908Smckusick ufs_daddr_t	allocblk __P((long frags));
194*68908Smckusick ino_t		allocdir __P((ino_t parent, ino_t request, int mode));
195*68908Smckusick ino_t		allocino __P((ino_t request, int type));
196*68908Smckusick void		blkerror __P((ino_t ino, char *type, ufs_daddr_t blk));
197*68908Smckusick char	       *blockcheck __P((char *name));
198*68908Smckusick int		bread __P((int fd, char *buf, ufs_daddr_t blk, long size));
199*68908Smckusick void		bufinit __P((void));
200*68908Smckusick void		bwrite __P((int fd, char *buf, ufs_daddr_t blk, long size));
201*68908Smckusick void		cacheino __P((struct dinode *dp, ino_t inumber));
202*68908Smckusick void		catch __P((int));
203*68908Smckusick void		catchquit __P((int));
204*68908Smckusick int		changeino __P((ino_t dir, char *name, ino_t newnum));
205*68908Smckusick int		checkfstab __P((int preen, int maxrun,
206*68908Smckusick 			int (*docheck)(struct fstab *),
207*68908Smckusick 			int (*chkit)(char *, char *, long, int)));
208*68908Smckusick int		chkrange __P((ufs_daddr_t blk, int cnt));
209*68908Smckusick void		ckfini __P((void));
210*68908Smckusick int		ckinode __P((struct dinode *dp, struct inodesc *));
211*68908Smckusick void		clri __P((struct inodesc *, char *type, int flag));
212*68908Smckusick void		direrror __P((ino_t ino, char *errmesg));
213*68908Smckusick int		dirscan __P((struct inodesc *));
214*68908Smckusick int		dofix __P((struct inodesc *, char *msg));
215*68908Smckusick void		ffs_clrblock __P((struct fs *, u_char *, ufs_daddr_t));
216*68908Smckusick void		ffs_fragacct __P((struct fs *, int, int32_t [], int));
217*68908Smckusick int		ffs_isblock __P((struct fs *, u_char *, ufs_daddr_t));
218*68908Smckusick void		ffs_setblock __P((struct fs *, u_char *, ufs_daddr_t));
219*68908Smckusick void		fileerror __P((ino_t cwd, ino_t ino, char *errmesg));
220*68908Smckusick int		findino __P((struct inodesc *));
221*68908Smckusick int		findname __P((struct inodesc *));
222*68908Smckusick void		flush __P((int fd, struct bufarea *bp));
223*68908Smckusick void		freeblk __P((ufs_daddr_t blkno, long frags));
224*68908Smckusick void		freeino __P((ino_t ino));
225*68908Smckusick void		freeinodebuf __P((void));
226*68908Smckusick int		ftypeok __P((struct dinode *dp));
227*68908Smckusick void		getblk __P((struct bufarea *bp, ufs_daddr_t blk, long size));
228*68908Smckusick struct bufarea *getdatablk __P((ufs_daddr_t blkno, long size));
229*68908Smckusick struct inoinfo *getinoinfo __P((ino_t inumber));
230*68908Smckusick struct dinode  *getnextinode __P((ino_t inumber));
231*68908Smckusick void		getpathname __P((char *namebuf, ino_t curdir, ino_t ino));
232*68908Smckusick struct dinode  *ginode __P((ino_t inumber));
233*68908Smckusick void		inocleanup __P((void));
234*68908Smckusick void		inodirty __P((void));
235*68908Smckusick int		linkup __P((ino_t orphan, ino_t parentdir));
236*68908Smckusick int		makeentry __P((ino_t parent, ino_t ino, char *name));
237*68908Smckusick void		panic __P((const char *fmt, ...));
238*68908Smckusick void		pass1 __P((void));
239*68908Smckusick void		pass1b __P((void));
240*68908Smckusick int		pass1check __P((struct inodesc *));
241*68908Smckusick void		pass2 __P((void));
242*68908Smckusick void		pass3 __P((void));
243*68908Smckusick void		pass4 __P((void));
244*68908Smckusick int		pass4check __P((struct inodesc *));
245*68908Smckusick void		pass5 __P((void));
246*68908Smckusick void		pfatal __P((const char *fmt, ...));
247*68908Smckusick void		pinode __P((ino_t ino));
248*68908Smckusick void		propagate __P((void));
249*68908Smckusick void		pwarn __P((const char *fmt, ...));
250*68908Smckusick int		reply __P((char *question));
251*68908Smckusick void		resetinodebuf __P((void));
252*68908Smckusick int		setup __P((char *dev));
253*68908Smckusick void		voidquit __P((int));
254