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