xref: /csrg-svn/sbin/fsck/fsck.h (revision 40650)
122057Sdist /*
239976Smckusick  * Copyright (c) 1980, 1986 The Regents of the University of California.
339976Smckusick  * All rights reserved.
422057Sdist  *
539976Smckusick  * Redistribution and use in source and binary forms are permitted
639976Smckusick  * provided that the above copyright notice and this paragraph are
739976Smckusick  * duplicated in all such forms and that any documentation,
839976Smckusick  * advertising materials, and other materials related to such
939976Smckusick  * distribution and use acknowledge that the software was developed
1039976Smckusick  * by the University of California, Berkeley.  The name of the
1139976Smckusick  * University may not be used to endorse or promote products derived
1239976Smckusick  * from this software without specific prior written permission.
1339976Smckusick  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1439976Smckusick  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1539976Smckusick  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1639976Smckusick  *
17*40650Smckusick  *	@(#)fsck.h	5.14 (Berkeley) 03/27/90
1822057Sdist  */
1916260Smckusick 
2040023Smckusick #define	MAXDUP		10	/* limit on dup blks (per inode) */
2140023Smckusick #define	MAXBAD		10	/* limit on bad blks (per inode) */
2240023Smckusick #define	MAXBUFSPACE	40*1024	/* maximum space to allocate to buffers */
2340023Smckusick #define	INOBUFSIZE	56*1024	/* size of buffer to read inodes in pass1 */
2416260Smckusick 
2516260Smckusick #ifndef BUFSIZ
2616260Smckusick #define BUFSIZ 1024
2716260Smckusick #endif
2816260Smckusick 
2917936Smckusick #define	USTATE	01		/* inode not allocated */
3017936Smckusick #define	FSTATE	02		/* inode is file */
3117936Smckusick #define	DSTATE	03		/* inode is directory */
3217936Smckusick #define	DFOUND	04		/* directory found during descent */
3317936Smckusick #define	DCLEAR	05		/* directory is to be cleared */
3417936Smckusick #define	FCLEAR	06		/* file is to be cleared */
3516260Smckusick 
3634225Smckusick /*
3734225Smckusick  * buffer cache structure.
3834225Smckusick  */
3916260Smckusick struct bufarea {
4034225Smckusick 	struct bufarea	*b_next;		/* free list queue */
4134225Smckusick 	struct bufarea	*b_prev;		/* free list queue */
4216260Smckusick 	daddr_t	b_bno;
4316260Smckusick 	int	b_size;
4421540Smckusick 	int	b_errs;
4534225Smckusick 	int	b_flags;
4616260Smckusick 	union {
4734225Smckusick 		char	*b_buf;			/* buffer space */
4834225Smckusick 		daddr_t	*b_indir;		/* indirect block */
4934225Smckusick 		struct	fs *b_fs;		/* super block */
5034225Smckusick 		struct	cg *b_cg;		/* cylinder group */
5139973Smckusick 		struct	dinode *b_dinode;	/* inode block */
5216260Smckusick 	} b_un;
5316260Smckusick 	char	b_dirty;
5416260Smckusick };
5516260Smckusick 
5634225Smckusick #define	B_INUSE 1
5716260Smckusick 
5834225Smckusick #define	MINBUFS		5	/* minimum number of buffers required */
5939973Smckusick struct bufarea bufhead;		/* head of list of other blks in filesys */
6039973Smckusick struct bufarea sblk;		/* file system superblock */
6139973Smckusick struct bufarea cgblk;		/* cylinder group blocks */
62*40650Smckusick struct bufarea *pdirbp;		/* current directory contents */
63*40650Smckusick struct bufarea *pbp;		/* current inode block */
6439973Smckusick struct bufarea *getdatablk();
6516260Smckusick 
6639973Smckusick #define	dirty(bp)	(bp)->b_dirty = 1
6739973Smckusick #define	initbarea(bp) \
6839973Smckusick 	(bp)->b_dirty = 0; \
6939973Smckusick 	(bp)->b_bno = (daddr_t)-1; \
7039973Smckusick 	(bp)->b_flags = 0;
7134225Smckusick 
7216260Smckusick #define	sbdirty()	sblk.b_dirty = 1
7316260Smckusick #define	cgdirty()	cgblk.b_dirty = 1
7434225Smckusick #define	sblock		(*sblk.b_un.b_fs)
7534225Smckusick #define	cgrp		(*cgblk.b_un.b_cg)
7616260Smckusick 
7717930Smckusick enum fixstate {DONTKNOW, NOFIX, FIX};
7817930Smckusick 
7916260Smckusick struct inodesc {
8017930Smckusick 	enum fixstate id_fix;	/* policy on fixing errors */
8116260Smckusick 	int (*id_func)();	/* function to be applied to blocks of inode */
8216260Smckusick 	ino_t id_number;	/* inode number described */
8316260Smckusick 	ino_t id_parent;	/* for DATA nodes, their parent */
8416260Smckusick 	daddr_t id_blkno;	/* current block number being examined */
8516260Smckusick 	int id_numfrags;	/* number of frags contained in block */
8616260Smckusick 	long id_filesize;	/* for DATA nodes, the size of the directory */
8716260Smckusick 	int id_loc;		/* for DATA nodes, current location in dir */
8816260Smckusick 	int id_entryno;		/* for DATA nodes, current entry number */
8939973Smckusick 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
9017930Smckusick 	char *id_name;		/* for DATA nodes, name to find or enter */
9117930Smckusick 	char id_type;		/* type of descriptor, DATA or ADDR */
9216260Smckusick };
9316260Smckusick /* file types */
9416260Smckusick #define	DATA	1
9516260Smckusick #define	ADDR	2
9616260Smckusick 
9721743Smckusick /*
9821759Smckusick  * Linked list of duplicate blocks.
9921759Smckusick  *
10021759Smckusick  * The list is composed of two parts. The first part of the
10121759Smckusick  * list (from duplist through the node pointed to by muldup)
10221759Smckusick  * contains a single copy of each duplicate block that has been
10321759Smckusick  * found. The second part of the list (from muldup to the end)
10421759Smckusick  * contains duplicate blocks that have been found more than once.
10521759Smckusick  * To check if a block has been found as a duplicate it is only
10621759Smckusick  * necessary to search from duplist through muldup. To find the
10721759Smckusick  * total number of times that a block has been found as a duplicate
10821759Smckusick  * the entire list must be searched for occurences of the block
10921759Smckusick  * in question. The following diagram shows a sample list where
11021759Smckusick  * w (found twice), x (found once), y (found three times), and z
11121759Smckusick  * (found once) are duplicate block numbers:
11221759Smckusick  *
11321759Smckusick  *    w -> y -> x -> z -> y -> w -> y
11421759Smckusick  *    ^		     ^
11521759Smckusick  *    |		     |
11621759Smckusick  * duplist	  muldup
11721743Smckusick  */
11821743Smckusick struct dups {
11921743Smckusick 	struct dups *next;
12021743Smckusick 	daddr_t dup;
12121743Smckusick };
12221743Smckusick struct dups *duplist;		/* head of dup list */
12321743Smckusick struct dups *muldup;		/* end of unique duplicate dup block numbers */
12416260Smckusick 
12521759Smckusick /*
12621759Smckusick  * Linked list of inodes with zero link counts.
12721759Smckusick  */
12821759Smckusick struct zlncnt {
12921759Smckusick 	struct zlncnt *next;
13021759Smckusick 	ino_t zlncnt;
13121759Smckusick };
13221759Smckusick struct zlncnt *zlnhead;		/* head of zero link count list */
13316260Smckusick 
13440023Smckusick /*
13540023Smckusick  * Inode cache data structures.
13640023Smckusick  */
13740023Smckusick struct inoinfo {
13840023Smckusick 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
13940023Smckusick 	ino_t	i_number;		/* inode number of this entry */
14040023Smckusick 	ino_t	i_parent;		/* inode number of parent */
14140023Smckusick 	ino_t	i_dotdot;		/* inode number of `..' */
14240023Smckusick 	size_t	i_isize;		/* size of inode */
14340023Smckusick 	u_int	i_numblks;		/* size of block array in bytes */
14440023Smckusick 	daddr_t	i_blks[1];		/* actually longer */
14540023Smckusick } **inphead, **inpsort;
14640023Smckusick long numdirs, listmax, inplast;
14740023Smckusick 
14839973Smckusick char	*devname;		/* name of device being checked */
14930518Smckusick long	dev_bsize;		/* computed value of DEV_BSIZE */
15030609Skarels long	secsize;		/* actual disk sector size */
15116260Smckusick char	nflag;			/* assume a no response */
15216260Smckusick char	yflag;			/* assume a yes response */
15316260Smckusick int	bflag;			/* location of alternate super block */
15416260Smckusick int	debug;			/* output debugging info */
15534139Smckusick int	cvtflag;		/* convert to old file system format */
15616260Smckusick char	preen;			/* just fix normal inconsistencies */
15716260Smckusick char	hotroot;		/* checking root device */
15830859Skarels char	havesb;			/* superblock has been read */
15939973Smckusick int	fsmodified;		/* 1 => write done to file system */
16039973Smckusick int	fsreadfd;		/* file descriptor for reading file system */
16139973Smckusick int	fswritefd;		/* file descriptor for writing file system */
16216260Smckusick 
16339973Smckusick daddr_t	maxfsblock;		/* number of blocks in the file system */
16416260Smckusick char	*blockmap;		/* ptr to primary blk allocation map */
16539973Smckusick ino_t	maxino;			/* number of inodes in file system */
16639973Smckusick ino_t	lastino;		/* last inode in use */
16716260Smckusick char	*statemap;		/* ptr to inode state table */
16816260Smckusick short	*lncntp;		/* ptr to link count table */
16916260Smckusick 
17017930Smckusick ino_t	lfdir;			/* lost & found directory inode number */
17117930Smckusick char	*lfname;		/* lost & found directory name */
17236827Smckusick int	lfmode;			/* lost & found directory creation mode */
17316260Smckusick 
17439973Smckusick daddr_t	n_blks;			/* number of blocks in use */
17539973Smckusick daddr_t	n_files;		/* number of files in use */
17616260Smckusick 
17739973Smckusick #define	clearinode(dp)	(*(dp) = zino)
17816260Smckusick struct	dinode zino;
17916260Smckusick 
18039973Smckusick #define	setbmap(blkno)	setbit(blockmap, blkno)
18139973Smckusick #define	testbmap(blkno)	isset(blockmap, blkno)
18239973Smckusick #define	clrbmap(blkno)	clrbit(blockmap, blkno)
18316260Smckusick 
18439973Smckusick #define	STOP	0x01
18539973Smckusick #define	SKIP	0x02
18639973Smckusick #define	KEEPON	0x04
18739973Smckusick #define	ALTERED	0x08
18839973Smckusick #define	FOUND	0x10
18916260Smckusick 
19039973Smckusick time_t time();
19139973Smckusick struct dinode *ginode();
19240023Smckusick struct inoinfo *getinoinfo();
19339973Smckusick struct bufarea *getblk();
19439973Smckusick ino_t allocino();
19539973Smckusick int findino();
196