Home | History | Annotate | Line # | Download | only in fsck_ext2fs
fsck.h revision 1.8
      1 /*	$NetBSD: fsck.h,v 1.8 2003/08/07 10:04:16 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1980, 1986, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. Neither the name of the University nor the names of its contributors
     16  *    may be used to endorse or promote products derived from this software
     17  *    without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  *
     31  *	@(#)fsck.h	8.1 (Berkeley) 6/5/93
     32  */
     33 
     34 /*
     35  * Copyright (c) 1997 Manuel Bouyer.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  * 1. Redistributions of source code must retain the above copyright
     41  *    notice, this list of conditions and the following disclaimer.
     42  * 2. Redistributions in binary form must reproduce the above copyright
     43  *    notice, this list of conditions and the following disclaimer in the
     44  *    documentation and/or other materials provided with the distribution.
     45  * 3. All advertising materials mentioning features or use of this software
     46  *    must display the following acknowledgement:
     47  *	This product includes software developed by the University of
     48  *	California, Berkeley and its contributors.
     49  * 4. Neither the name of the University nor the names of its contributors
     50  *    may be used to endorse or promote products derived from this software
     51  *    without specific prior written permission.
     52  *
     53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     63  * SUCH DAMAGE.
     64  *
     65  *	@(#)fsck.h	8.1 (Berkeley) 6/5/93
     66  */
     67 
     68 #define	MAXDUP		10	/* limit on dup blks (per inode) */
     69 #define	MAXBAD		10	/* limit on bad blks (per inode) */
     70 #define	MAXBUFSPACE	80*1024	/* maximum space to allocate to buffers */
     71 #define	INOBUFSIZE	128*1024	/* size of buffer to read inodes in pass1 */
     72 
     73 #ifndef BUFSIZ
     74 #define BUFSIZ 1024
     75 #endif
     76 
     77 #define	USTATE	01		/* inode not allocated */
     78 #define	FSTATE	02		/* inode is file */
     79 #define	DSTATE	03		/* inode is directory */
     80 #define	DFOUND	04		/* directory found during descent */
     81 #define	DCLEAR	05		/* directory is to be cleared */
     82 #define	FCLEAR	06		/* file is to be cleared */
     83 
     84 /*
     85  * buffer cache structure.
     86  */
     87 struct bufarea {
     88 	struct bufarea	*b_next;		/* free list queue */
     89 	struct bufarea	*b_prev;		/* free list queue */
     90 	daddr_t	b_bno;
     91 	int	b_size;
     92 	int	b_errs;
     93 	int	b_flags;
     94 	union {
     95 		char	*b_buf;			/* buffer space */
     96 		/* XXX ondisk32 */
     97 		int32_t	*b_indir;		/* indirect block */
     98 		struct	ext2fs *b_fs;		/* super block */
     99 		struct	ext2_gd *b_cgd;		/* cylinder group descriptor */
    100 		struct	ext2fs_dinode *b_dinode;	/* inode block */
    101 	} b_un;
    102 	char	b_dirty;
    103 };
    104 
    105 #define	B_INUSE 1
    106 
    107 #define	MINBUFS		5	/* minimum number of buffers required */
    108 struct bufarea bufhead;		/* head of list of other blks in filesys */
    109 struct bufarea sblk;		/* file system superblock */
    110 struct bufarea asblk;		/* first alternate superblock */
    111 struct bufarea *pdirbp;		/* current directory contents */
    112 struct bufarea *pbp;		/* current inode block */
    113 struct bufarea *getdatablk __P((daddr_t, long));
    114 struct m_ext2fs sblock;
    115 
    116 #define	dirty(bp)	(bp)->b_dirty = 1
    117 #define	initbarea(bp) \
    118 	(bp)->b_dirty = 0; \
    119 	(bp)->b_bno = (daddr_t)-1; \
    120 	(bp)->b_flags = 0;
    121 
    122 #define	sbdirty()	copyback_sb(&sblk); sblk.b_dirty = 1
    123 
    124 enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
    125 
    126 struct inodesc {
    127 	enum fixstate id_fix;	/* policy on fixing errors */
    128 	int (*id_func)		/* function to be applied to blocks of inode */
    129 	    __P((struct inodesc *));
    130 	ino_t id_number;	/* inode number described */
    131 	ino_t id_parent;	/* for DATA nodes, their parent */
    132 	daddr_t id_blkno;	/* current block number being examined */
    133 	int id_numfrags;	/* number of frags contained in block */
    134 	quad_t id_filesize;	/* for DATA nodes, the size of the directory */
    135 	int id_loc;		/* for DATA nodes, current location in dir */
    136 	int id_entryno;		/* for DATA nodes, current entry number */
    137 	struct ext2fs_direct *id_dirp;	/* for DATA nodes, ptr to current entry */
    138 	char *id_name;		/* for DATA nodes, name to find or enter */
    139 	char id_type;		/* type of descriptor, DATA or ADDR */
    140 };
    141 /* file types */
    142 #define	DATA	1
    143 #define	ADDR	2
    144 
    145 /*
    146  * Linked list of duplicate blocks.
    147  *
    148  * The list is composed of two parts. The first part of the
    149  * list (from duplist through the node pointed to by muldup)
    150  * contains a single copy of each duplicate block that has been
    151  * found. The second part of the list (from muldup to the end)
    152  * contains duplicate blocks that have been found more than once.
    153  * To check if a block has been found as a duplicate it is only
    154  * necessary to search from duplist through muldup. To find the
    155  * total number of times that a block has been found as a duplicate
    156  * the entire list must be searched for occurrences of the block
    157  * in question. The following diagram shows a sample list where
    158  * w (found twice), x (found once), y (found three times), and z
    159  * (found once) are duplicate block numbers:
    160  *
    161  *    w -> y -> x -> z -> y -> w -> y
    162  *    ^		     ^
    163  *    |		     |
    164  * duplist	  muldup
    165  */
    166 struct dups {
    167 	struct dups *next;
    168 	daddr_t dup;
    169 };
    170 struct dups *duplist;		/* head of dup list */
    171 struct dups *muldup;		/* end of unique duplicate dup block numbers */
    172 
    173 /*
    174  * Linked list of inodes with zero link counts.
    175  */
    176 struct zlncnt {
    177 	struct zlncnt *next;
    178 	ino_t zlncnt;
    179 };
    180 struct zlncnt *zlnhead;		/* head of zero link count list */
    181 
    182 /*
    183  * Inode cache data structures.
    184  */
    185 struct inoinfo {
    186 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
    187 	struct	inoinfo	*i_child, *i_sibling, *i_parentp;
    188 	ino_t	i_number;		/* inode number of this entry */
    189 	ino_t	i_parent;		/* inode number of parent */
    190 	ino_t	i_dotdot;		/* inode number of `..' */
    191 	size_t	i_isize;		/* size of inode */
    192 	u_int	i_numblks;		/* size of block array in bytes */
    193 	/* XXX ondisk32 */
    194 	int32_t	i_blks[1];		/* actually longer */
    195 } **inphead, **inpsort;
    196 long numdirs, listmax, inplast;
    197 
    198 long	dev_bsize;		/* computed value of DEV_BSIZE */
    199 long	secsize;		/* actual disk sector size */
    200 char	nflag;			/* assume a no response */
    201 char	yflag;			/* assume a yes response */
    202 int	bflag;			/* location of alternate super block */
    203 int	debug;			/* output debugging info */
    204 int	preen;			/* just fix normal inconsistencies */
    205 char	havesb;			/* superblock has been read */
    206 char	skipclean;		/* skip clean file systems if preening */
    207 int	fsmodified;		/* 1 => write done to file system */
    208 int	fsreadfd;		/* file descriptor for reading file system */
    209 int	fswritefd;		/* file descriptor for writing file system */
    210 int	rerun;			/* rerun fsck.  Only used in non-preen mode */
    211 
    212 daddr_t	maxfsblock;		/* number of blocks in the file system */
    213 char	*blockmap;		/* ptr to primary blk allocation map */
    214 ino_t	maxino;			/* number of inodes in file system */
    215 ino_t	lastino;		/* last inode in use */
    216 char	*statemap;		/* ptr to inode state table */
    217 u_char	*typemap;		/* ptr to inode type table */
    218 int16_t	*lncntp;		/* ptr to link count table */
    219 
    220 ino_t	lfdir;			/* lost & found directory inode number */
    221 extern char	*lfname;	/* lost & found directory name */
    222 extern int	lfmode;		/* lost & found directory creation mode */
    223 
    224 daddr_t	n_blks;			/* number of blocks in use */
    225 daddr_t	n_files;		/* number of files in use */
    226 
    227 #define	clearinode(dp)	(*(dp) = zino)
    228 struct	ext2fs_dinode zino;
    229 
    230 #define	setbmap(blkno)	setbit(blockmap, blkno)
    231 #define	testbmap(blkno)	isset(blockmap, blkno)
    232 #define	clrbmap(blkno)	clrbit(blockmap, blkno)
    233 
    234 #define	STOP	0x01
    235 #define	SKIP	0x02
    236 #define	KEEPON	0x04
    237 #define	ALTERED	0x08
    238 #define	FOUND	0x10
    239 
    240 struct ext2fs_dinode *ginode __P((ino_t));
    241 struct inoinfo *getinoinfo __P((ino_t));
    242 void getblk __P((struct bufarea *, daddr_t, long));
    243 ino_t allocino __P((ino_t, int));
    244 void copyback_sb __P((struct bufarea*));
    245 daddr_t cgoverhead __P((int));	/* overhead per cg */
    246