xref: /freebsd/sbin/fsck_ffs/fsck.h (revision 8fae3551ec46402adf7ab034cf9e02bcbc7ca8ee)
18fae3551SRodney W. Grimes /*
28fae3551SRodney W. Grimes  * Copyright (c) 1980, 1986, 1993
38fae3551SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
48fae3551SRodney W. Grimes  *
58fae3551SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
68fae3551SRodney W. Grimes  * modification, are permitted provided that the following conditions
78fae3551SRodney W. Grimes  * are met:
88fae3551SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
98fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
108fae3551SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
118fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
128fae3551SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
138fae3551SRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
148fae3551SRodney W. Grimes  *    must display the following acknowledgement:
158fae3551SRodney W. Grimes  *	This product includes software developed by the University of
168fae3551SRodney W. Grimes  *	California, Berkeley and its contributors.
178fae3551SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
188fae3551SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
198fae3551SRodney W. Grimes  *    without specific prior written permission.
208fae3551SRodney W. Grimes  *
218fae3551SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
228fae3551SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238fae3551SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248fae3551SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
258fae3551SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
268fae3551SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
278fae3551SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
288fae3551SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
298fae3551SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
308fae3551SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318fae3551SRodney W. Grimes  * SUCH DAMAGE.
328fae3551SRodney W. Grimes  *
338fae3551SRodney W. Grimes  *	@(#)fsck.h	8.1 (Berkeley) 6/5/93
348fae3551SRodney W. Grimes  */
358fae3551SRodney W. Grimes 
368fae3551SRodney W. Grimes #define	MAXDUP		10	/* limit on dup blks (per inode) */
378fae3551SRodney W. Grimes #define	MAXBAD		10	/* limit on bad blks (per inode) */
388fae3551SRodney W. Grimes #define	MAXBUFSPACE	40*1024	/* maximum space to allocate to buffers */
398fae3551SRodney W. Grimes #define	INOBUFSIZE	56*1024	/* size of buffer to read inodes in pass1 */
408fae3551SRodney W. Grimes 
418fae3551SRodney W. Grimes #ifndef BUFSIZ
428fae3551SRodney W. Grimes #define BUFSIZ 1024
438fae3551SRodney W. Grimes #endif
448fae3551SRodney W. Grimes 
458fae3551SRodney W. Grimes #define	USTATE	01		/* inode not allocated */
468fae3551SRodney W. Grimes #define	FSTATE	02		/* inode is file */
478fae3551SRodney W. Grimes #define	DSTATE	03		/* inode is directory */
488fae3551SRodney W. Grimes #define	DFOUND	04		/* directory found during descent */
498fae3551SRodney W. Grimes #define	DCLEAR	05		/* directory is to be cleared */
508fae3551SRodney W. Grimes #define	FCLEAR	06		/* file is to be cleared */
518fae3551SRodney W. Grimes 
528fae3551SRodney W. Grimes /*
538fae3551SRodney W. Grimes  * buffer cache structure.
548fae3551SRodney W. Grimes  */
558fae3551SRodney W. Grimes struct bufarea {
568fae3551SRodney W. Grimes 	struct bufarea	*b_next;		/* free list queue */
578fae3551SRodney W. Grimes 	struct bufarea	*b_prev;		/* free list queue */
588fae3551SRodney W. Grimes 	daddr_t	b_bno;
598fae3551SRodney W. Grimes 	int	b_size;
608fae3551SRodney W. Grimes 	int	b_errs;
618fae3551SRodney W. Grimes 	int	b_flags;
628fae3551SRodney W. Grimes 	union {
638fae3551SRodney W. Grimes 		char	*b_buf;			/* buffer space */
648fae3551SRodney W. Grimes 		daddr_t	*b_indir;		/* indirect block */
658fae3551SRodney W. Grimes 		struct	fs *b_fs;		/* super block */
668fae3551SRodney W. Grimes 		struct	cg *b_cg;		/* cylinder group */
678fae3551SRodney W. Grimes 		struct	dinode *b_dinode;	/* inode block */
688fae3551SRodney W. Grimes 	} b_un;
698fae3551SRodney W. Grimes 	char	b_dirty;
708fae3551SRodney W. Grimes };
718fae3551SRodney W. Grimes 
728fae3551SRodney W. Grimes #define	B_INUSE 1
738fae3551SRodney W. Grimes 
748fae3551SRodney W. Grimes #define	MINBUFS		5	/* minimum number of buffers required */
758fae3551SRodney W. Grimes struct bufarea bufhead;		/* head of list of other blks in filesys */
768fae3551SRodney W. Grimes struct bufarea sblk;		/* file system superblock */
778fae3551SRodney W. Grimes struct bufarea cgblk;		/* cylinder group blocks */
788fae3551SRodney W. Grimes struct bufarea *pdirbp;		/* current directory contents */
798fae3551SRodney W. Grimes struct bufarea *pbp;		/* current inode block */
808fae3551SRodney W. Grimes struct bufarea *getdatablk();
818fae3551SRodney W. Grimes 
828fae3551SRodney W. Grimes #define	dirty(bp)	(bp)->b_dirty = 1
838fae3551SRodney W. Grimes #define	initbarea(bp) \
848fae3551SRodney W. Grimes 	(bp)->b_dirty = 0; \
858fae3551SRodney W. Grimes 	(bp)->b_bno = (daddr_t)-1; \
868fae3551SRodney W. Grimes 	(bp)->b_flags = 0;
878fae3551SRodney W. Grimes 
888fae3551SRodney W. Grimes #define	sbdirty()	sblk.b_dirty = 1
898fae3551SRodney W. Grimes #define	cgdirty()	cgblk.b_dirty = 1
908fae3551SRodney W. Grimes #define	sblock		(*sblk.b_un.b_fs)
918fae3551SRodney W. Grimes #define	cgrp		(*cgblk.b_un.b_cg)
928fae3551SRodney W. Grimes 
938fae3551SRodney W. Grimes enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
948fae3551SRodney W. Grimes 
958fae3551SRodney W. Grimes struct inodesc {
968fae3551SRodney W. Grimes 	enum fixstate id_fix;	/* policy on fixing errors */
978fae3551SRodney W. Grimes 	int (*id_func)();	/* function to be applied to blocks of inode */
988fae3551SRodney W. Grimes 	ino_t id_number;	/* inode number described */
998fae3551SRodney W. Grimes 	ino_t id_parent;	/* for DATA nodes, their parent */
1008fae3551SRodney W. Grimes 	daddr_t id_blkno;	/* current block number being examined */
1018fae3551SRodney W. Grimes 	int id_numfrags;	/* number of frags contained in block */
1028fae3551SRodney W. Grimes 	quad_t id_filesize;	/* for DATA nodes, the size of the directory */
1038fae3551SRodney W. Grimes 	int id_loc;		/* for DATA nodes, current location in dir */
1048fae3551SRodney W. Grimes 	int id_entryno;		/* for DATA nodes, current entry number */
1058fae3551SRodney W. Grimes 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
1068fae3551SRodney W. Grimes 	char *id_name;		/* for DATA nodes, name to find or enter */
1078fae3551SRodney W. Grimes 	char id_type;		/* type of descriptor, DATA or ADDR */
1088fae3551SRodney W. Grimes };
1098fae3551SRodney W. Grimes /* file types */
1108fae3551SRodney W. Grimes #define	DATA	1
1118fae3551SRodney W. Grimes #define	ADDR	2
1128fae3551SRodney W. Grimes 
1138fae3551SRodney W. Grimes /*
1148fae3551SRodney W. Grimes  * Linked list of duplicate blocks.
1158fae3551SRodney W. Grimes  *
1168fae3551SRodney W. Grimes  * The list is composed of two parts. The first part of the
1178fae3551SRodney W. Grimes  * list (from duplist through the node pointed to by muldup)
1188fae3551SRodney W. Grimes  * contains a single copy of each duplicate block that has been
1198fae3551SRodney W. Grimes  * found. The second part of the list (from muldup to the end)
1208fae3551SRodney W. Grimes  * contains duplicate blocks that have been found more than once.
1218fae3551SRodney W. Grimes  * To check if a block has been found as a duplicate it is only
1228fae3551SRodney W. Grimes  * necessary to search from duplist through muldup. To find the
1238fae3551SRodney W. Grimes  * total number of times that a block has been found as a duplicate
1248fae3551SRodney W. Grimes  * the entire list must be searched for occurences of the block
1258fae3551SRodney W. Grimes  * in question. The following diagram shows a sample list where
1268fae3551SRodney W. Grimes  * w (found twice), x (found once), y (found three times), and z
1278fae3551SRodney W. Grimes  * (found once) are duplicate block numbers:
1288fae3551SRodney W. Grimes  *
1298fae3551SRodney W. Grimes  *    w -> y -> x -> z -> y -> w -> y
1308fae3551SRodney W. Grimes  *    ^		     ^
1318fae3551SRodney W. Grimes  *    |		     |
1328fae3551SRodney W. Grimes  * duplist	  muldup
1338fae3551SRodney W. Grimes  */
1348fae3551SRodney W. Grimes struct dups {
1358fae3551SRodney W. Grimes 	struct dups *next;
1368fae3551SRodney W. Grimes 	daddr_t dup;
1378fae3551SRodney W. Grimes };
1388fae3551SRodney W. Grimes struct dups *duplist;		/* head of dup list */
1398fae3551SRodney W. Grimes struct dups *muldup;		/* end of unique duplicate dup block numbers */
1408fae3551SRodney W. Grimes 
1418fae3551SRodney W. Grimes /*
1428fae3551SRodney W. Grimes  * Linked list of inodes with zero link counts.
1438fae3551SRodney W. Grimes  */
1448fae3551SRodney W. Grimes struct zlncnt {
1458fae3551SRodney W. Grimes 	struct zlncnt *next;
1468fae3551SRodney W. Grimes 	ino_t zlncnt;
1478fae3551SRodney W. Grimes };
1488fae3551SRodney W. Grimes struct zlncnt *zlnhead;		/* head of zero link count list */
1498fae3551SRodney W. Grimes 
1508fae3551SRodney W. Grimes /*
1518fae3551SRodney W. Grimes  * Inode cache data structures.
1528fae3551SRodney W. Grimes  */
1538fae3551SRodney W. Grimes struct inoinfo {
1548fae3551SRodney W. Grimes 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
1558fae3551SRodney W. Grimes 	ino_t	i_number;		/* inode number of this entry */
1568fae3551SRodney W. Grimes 	ino_t	i_parent;		/* inode number of parent */
1578fae3551SRodney W. Grimes 	ino_t	i_dotdot;		/* inode number of `..' */
1588fae3551SRodney W. Grimes 	size_t	i_isize;		/* size of inode */
1598fae3551SRodney W. Grimes 	u_int	i_numblks;		/* size of block array in bytes */
1608fae3551SRodney W. Grimes 	daddr_t	i_blks[1];		/* actually longer */
1618fae3551SRodney W. Grimes } **inphead, **inpsort;
1628fae3551SRodney W. Grimes long numdirs, listmax, inplast;
1638fae3551SRodney W. Grimes 
1648fae3551SRodney W. Grimes char	*cdevname;		/* name of device being checked */
1658fae3551SRodney W. Grimes long	dev_bsize;		/* computed value of DEV_BSIZE */
1668fae3551SRodney W. Grimes long	secsize;		/* actual disk sector size */
1678fae3551SRodney W. Grimes char	nflag;			/* assume a no response */
1688fae3551SRodney W. Grimes char	yflag;			/* assume a yes response */
1698fae3551SRodney W. Grimes int	bflag;			/* location of alternate super block */
1708fae3551SRodney W. Grimes int	debug;			/* output debugging info */
1718fae3551SRodney W. Grimes int	cvtlevel;		/* convert to newer file system format */
1728fae3551SRodney W. Grimes int	doinglevel1;		/* converting to new cylinder group format */
1738fae3551SRodney W. Grimes int	doinglevel2;		/* converting to new inode format */
1748fae3551SRodney W. Grimes int	newinofmt;		/* filesystem has new inode format */
1758fae3551SRodney W. Grimes char	preen;			/* just fix normal inconsistencies */
1768fae3551SRodney W. Grimes char	hotroot;		/* checking root device */
1778fae3551SRodney W. Grimes char	havesb;			/* superblock has been read */
1788fae3551SRodney W. Grimes int	fsmodified;		/* 1 => write done to file system */
1798fae3551SRodney W. Grimes int	fsreadfd;		/* file descriptor for reading file system */
1808fae3551SRodney W. Grimes int	fswritefd;		/* file descriptor for writing file system */
1818fae3551SRodney W. Grimes 
1828fae3551SRodney W. Grimes daddr_t	maxfsblock;		/* number of blocks in the file system */
1838fae3551SRodney W. Grimes char	*blockmap;		/* ptr to primary blk allocation map */
1848fae3551SRodney W. Grimes ino_t	maxino;			/* number of inodes in file system */
1858fae3551SRodney W. Grimes ino_t	lastino;		/* last inode in use */
1868fae3551SRodney W. Grimes char	*statemap;		/* ptr to inode state table */
1878fae3551SRodney W. Grimes char	*typemap;		/* ptr to inode type table */
1888fae3551SRodney W. Grimes short	*lncntp;		/* ptr to link count table */
1898fae3551SRodney W. Grimes 
1908fae3551SRodney W. Grimes ino_t	lfdir;			/* lost & found directory inode number */
1918fae3551SRodney W. Grimes char	*lfname;		/* lost & found directory name */
1928fae3551SRodney W. Grimes int	lfmode;			/* lost & found directory creation mode */
1938fae3551SRodney W. Grimes 
1948fae3551SRodney W. Grimes daddr_t	n_blks;			/* number of blocks in use */
1958fae3551SRodney W. Grimes daddr_t	n_files;		/* number of files in use */
1968fae3551SRodney W. Grimes 
1978fae3551SRodney W. Grimes #define	clearinode(dp)	(*(dp) = zino)
1988fae3551SRodney W. Grimes struct	dinode zino;
1998fae3551SRodney W. Grimes 
2008fae3551SRodney W. Grimes #define	setbmap(blkno)	setbit(blockmap, blkno)
2018fae3551SRodney W. Grimes #define	testbmap(blkno)	isset(blockmap, blkno)
2028fae3551SRodney W. Grimes #define	clrbmap(blkno)	clrbit(blockmap, blkno)
2038fae3551SRodney W. Grimes 
2048fae3551SRodney W. Grimes #define	STOP	0x01
2058fae3551SRodney W. Grimes #define	SKIP	0x02
2068fae3551SRodney W. Grimes #define	KEEPON	0x04
2078fae3551SRodney W. Grimes #define	ALTERED	0x08
2088fae3551SRodney W. Grimes #define	FOUND	0x10
2098fae3551SRodney W. Grimes 
2108fae3551SRodney W. Grimes time_t time();
2118fae3551SRodney W. Grimes struct dinode *ginode();
2128fae3551SRodney W. Grimes struct inoinfo *getinoinfo();
2138fae3551SRodney W. Grimes void getblk();
2148fae3551SRodney W. Grimes ino_t allocino();
2158fae3551SRodney W. Grimes int findino();
216