xref: /csrg-svn/sbin/fsck/fsck.h (revision 69319)
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*69319Smckusick  *	@(#)fsck.h	8.4 (Berkeley) 05/09/95
822057Sdist  */
916260Smckusick 
1068908Smckusick #include <unistd.h>
1168908Smckusick #include <stdlib.h>
1268908Smckusick #include <stdio.h>
1368908Smckusick 
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 */
5816260Smckusick 
5939973Smckusick #define	dirty(bp)	(bp)->b_dirty = 1
6039973Smckusick #define	initbarea(bp) \
6139973Smckusick 	(bp)->b_dirty = 0; \
6268548Smckusick 	(bp)->b_bno = (ufs_daddr_t)-1; \
6339973Smckusick 	(bp)->b_flags = 0;
6434225Smckusick 
6516260Smckusick #define	sbdirty()	sblk.b_dirty = 1
6616260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
6734225Smckusick #define	sblock		(*sblk.b_un.b_fs)
6834225Smckusick #define	cgrp		(*cgblk.b_un.b_cg)
6916260Smckusick 
7044997Smckusick enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
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 */
7768548Smckusick 	ufs_daddr_t id_blkno;	/* current block number being examined */
7816260Smckusick 	int id_numfrags;	/* number of frags contained in block */
7952982Smckusick 	quad_t 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 */
8239973Smckusick 	struct 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 /*
9121759Smckusick  * Linked list of duplicate blocks.
9221759Smckusick  *
9321759Smckusick  * The list is composed of two parts. The first part of the
9421759Smckusick  * list (from duplist through the node pointed to by muldup)
9521759Smckusick  * contains a single copy of each duplicate block that has been
9621759Smckusick  * found. The second part of the list (from muldup to the end)
9721759Smckusick  * contains duplicate blocks that have been found more than once.
9821759Smckusick  * To check if a block has been found as a duplicate it is only
9921759Smckusick  * necessary to search from duplist through muldup. To find the
10021759Smckusick  * total number of times that a block has been found as a duplicate
10121759Smckusick  * the entire list must be searched for occurences of the block
10221759Smckusick  * in question. The following diagram shows a sample list where
10321759Smckusick  * w (found twice), x (found once), y (found three times), and z
10421759Smckusick  * (found once) are duplicate block numbers:
10521759Smckusick  *
10621759Smckusick  *    w -> y -> x -> z -> y -> w -> y
10721759Smckusick  *    ^		     ^
10821759Smckusick  *    |		     |
10921759Smckusick  * duplist	  muldup
11021743Smckusick  */
11121743Smckusick struct dups {
11221743Smckusick 	struct dups *next;
11368548Smckusick 	ufs_daddr_t dup;
11421743Smckusick };
11521743Smckusick struct dups *duplist;		/* head of dup list */
11621743Smckusick struct dups *muldup;		/* end of unique duplicate dup block numbers */
11716260Smckusick 
11821759Smckusick /*
11921759Smckusick  * Linked list of inodes with zero link counts.
12021759Smckusick  */
12121759Smckusick struct zlncnt {
12221759Smckusick 	struct zlncnt *next;
12321759Smckusick 	ino_t zlncnt;
12421759Smckusick };
12521759Smckusick struct zlncnt *zlnhead;		/* head of zero link count list */
12616260Smckusick 
12740023Smckusick /*
12840023Smckusick  * Inode cache data structures.
12940023Smckusick  */
13040023Smckusick struct inoinfo {
13140023Smckusick 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
13240023Smckusick 	ino_t	i_number;		/* inode number of this entry */
13340023Smckusick 	ino_t	i_parent;		/* inode number of parent */
13440023Smckusick 	ino_t	i_dotdot;		/* inode number of `..' */
13540023Smckusick 	size_t	i_isize;		/* size of inode */
13640023Smckusick 	u_int	i_numblks;		/* size of block array in bytes */
13768548Smckusick 	ufs_daddr_t i_blks[1];		/* actually longer */
13840023Smckusick } **inphead, **inpsort;
13940023Smckusick long numdirs, listmax, inplast;
14040023Smckusick 
14161110Sbostic char	*cdevname;		/* name of device being checked */
14230518Smckusick long	dev_bsize;		/* computed value of DEV_BSIZE */
14330609Skarels long	secsize;		/* actual disk sector size */
14416260Smckusick char	nflag;			/* assume a no response */
14516260Smckusick char	yflag;			/* assume a yes response */
14616260Smckusick int	bflag;			/* location of alternate super block */
14716260Smckusick int	debug;			/* output debugging info */
14854503Smckusick int	cvtlevel;		/* convert to newer file system format */
14954503Smckusick int	doinglevel1;		/* converting to new cylinder group format */
15054503Smckusick int	doinglevel2;		/* converting to new inode format */
15154503Smckusick int	newinofmt;		/* filesystem has new inode format */
15216260Smckusick char	preen;			/* just fix normal inconsistencies */
15316260Smckusick char	hotroot;		/* checking root device */
15430859Skarels char	havesb;			/* superblock has been read */
15539973Smckusick int	fsmodified;		/* 1 => write done to file system */
15639973Smckusick int	fsreadfd;		/* file descriptor for reading file system */
15739973Smckusick int	fswritefd;		/* file descriptor for writing file system */
15816260Smckusick 
15968548Smckusick ufs_daddr_t maxfsblock;		/* number of blocks in the file system */
16016260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
16139973Smckusick ino_t	maxino;			/* number of inodes in file system */
16239973Smckusick ino_t	lastino;		/* last inode in use */
16316260Smckusick char	*statemap;		/* ptr to inode state table */
16468908Smckusick u_char	*typemap;		/* ptr to inode type table */
16516260Smckusick short	*lncntp;		/* ptr to link count table */
16616260Smckusick 
16717930Smckusick ino_t	lfdir;			/* lost & found directory inode number */
16817930Smckusick char	*lfname;		/* lost & found directory name */
16936827Smckusick int	lfmode;			/* lost & found directory creation mode */
17016260Smckusick 
17168548Smckusick ufs_daddr_t n_blks;		/* number of blocks in use */
17268548Smckusick ufs_daddr_t n_files;		/* number of files in use */
17316260Smckusick 
17439973Smckusick #define	clearinode(dp)	(*(dp) = zino)
17516260Smckusick struct	dinode zino;
17616260Smckusick 
17739973Smckusick #define	setbmap(blkno)	setbit(blockmap, blkno)
17839973Smckusick #define	testbmap(blkno)	isset(blockmap, blkno)
17939973Smckusick #define	clrbmap(blkno)	clrbit(blockmap, blkno)
18016260Smckusick 
18139973Smckusick #define	STOP	0x01
18239973Smckusick #define	SKIP	0x02
18339973Smckusick #define	KEEPON	0x04
18439973Smckusick #define	ALTERED	0x08
18539973Smckusick #define	FOUND	0x10
18616260Smckusick 
18768908Smckusick #define	EEXIT	8		/* Standard error exit. */
18868908Smckusick 
18968908Smckusick struct fstab;
19068908Smckusick 
19168908Smckusick void		adjust __P((struct inodesc *, int lcnt));
19268908Smckusick ufs_daddr_t	allocblk __P((long frags));
19368908Smckusick ino_t		allocdir __P((ino_t parent, ino_t request, int mode));
19468908Smckusick ino_t		allocino __P((ino_t request, int type));
19568908Smckusick void		blkerror __P((ino_t ino, char *type, ufs_daddr_t blk));
19668908Smckusick char	       *blockcheck __P((char *name));
19768908Smckusick int		bread __P((int fd, char *buf, ufs_daddr_t blk, long size));
19868908Smckusick void		bufinit __P((void));
19968908Smckusick void		bwrite __P((int fd, char *buf, ufs_daddr_t blk, long size));
20068908Smckusick void		cacheino __P((struct dinode *dp, ino_t inumber));
20168908Smckusick void		catch __P((int));
20268908Smckusick void		catchquit __P((int));
20368908Smckusick int		changeino __P((ino_t dir, char *name, ino_t newnum));
20468908Smckusick int		checkfstab __P((int preen, int maxrun,
20568908Smckusick 			int (*docheck)(struct fstab *),
20668908Smckusick 			int (*chkit)(char *, char *, long, int)));
20768908Smckusick int		chkrange __P((ufs_daddr_t blk, int cnt));
208*69319Smckusick void		ckfini __P((int markclean));
20968908Smckusick int		ckinode __P((struct dinode *dp, struct inodesc *));
21068908Smckusick void		clri __P((struct inodesc *, char *type, int flag));
21168908Smckusick void		direrror __P((ino_t ino, char *errmesg));
21268908Smckusick int		dirscan __P((struct inodesc *));
21368908Smckusick int		dofix __P((struct inodesc *, char *msg));
21468908Smckusick void		ffs_clrblock __P((struct fs *, u_char *, ufs_daddr_t));
21568908Smckusick void		ffs_fragacct __P((struct fs *, int, int32_t [], int));
21668908Smckusick int		ffs_isblock __P((struct fs *, u_char *, ufs_daddr_t));
21768908Smckusick void		ffs_setblock __P((struct fs *, u_char *, ufs_daddr_t));
21868908Smckusick void		fileerror __P((ino_t cwd, ino_t ino, char *errmesg));
21968908Smckusick int		findino __P((struct inodesc *));
22068908Smckusick int		findname __P((struct inodesc *));
22168908Smckusick void		flush __P((int fd, struct bufarea *bp));
22268908Smckusick void		freeblk __P((ufs_daddr_t blkno, long frags));
22368908Smckusick void		freeino __P((ino_t ino));
22468908Smckusick void		freeinodebuf __P((void));
22568908Smckusick int		ftypeok __P((struct dinode *dp));
22668908Smckusick void		getblk __P((struct bufarea *bp, ufs_daddr_t blk, long size));
22768908Smckusick struct bufarea *getdatablk __P((ufs_daddr_t blkno, long size));
22868908Smckusick struct inoinfo *getinoinfo __P((ino_t inumber));
22968908Smckusick struct dinode  *getnextinode __P((ino_t inumber));
23068908Smckusick void		getpathname __P((char *namebuf, ino_t curdir, ino_t ino));
23168908Smckusick struct dinode  *ginode __P((ino_t inumber));
23268908Smckusick void		inocleanup __P((void));
23368908Smckusick void		inodirty __P((void));
23468908Smckusick int		linkup __P((ino_t orphan, ino_t parentdir));
23568908Smckusick int		makeentry __P((ino_t parent, ino_t ino, char *name));
23668908Smckusick void		panic __P((const char *fmt, ...));
23768908Smckusick void		pass1 __P((void));
23868908Smckusick void		pass1b __P((void));
23968908Smckusick int		pass1check __P((struct inodesc *));
24068908Smckusick void		pass2 __P((void));
24168908Smckusick void		pass3 __P((void));
24268908Smckusick void		pass4 __P((void));
24368908Smckusick int		pass4check __P((struct inodesc *));
24468908Smckusick void		pass5 __P((void));
24568908Smckusick void		pfatal __P((const char *fmt, ...));
24668908Smckusick void		pinode __P((ino_t ino));
24768908Smckusick void		propagate __P((void));
24868908Smckusick void		pwarn __P((const char *fmt, ...));
24968908Smckusick int		reply __P((char *question));
25068908Smckusick void		resetinodebuf __P((void));
25168908Smckusick int		setup __P((char *dev));
25268908Smckusick void		voidquit __P((int));
253