Home | History | Annotate | Line # | Download | only in fsck_ffs
fsck.h revision 1.29
      1 /*	$NetBSD: fsck.h,v 1.29 2002/09/28 20:11:06 dbj 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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the University of
     18  *	California, Berkeley and its contributors.
     19  * 4. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)fsck.h	8.4 (Berkeley) 5/9/95
     36  */
     37 
     38 #include <stdio.h>
     39 #include <machine/bswap.h>
     40 
     41 #define	MAXDUP		10	/* limit on dup blks (per inode) */
     42 #define	MAXBAD		10	/* limit on bad blks (per inode) */
     43 #define	MAXBUFSPACE	40*1024	/* maximum space to allocate to buffers */
     44 #define	INOBUFSIZE	56*1024	/* size of buffer to read inodes in pass1 */
     45 
     46 #ifndef BUFSIZ
     47 #define BUFSIZ 1024
     48 #endif
     49 
     50 #define	USTATE	01		/* inode not allocated */
     51 #define	FSTATE	02		/* inode is file */
     52 #define	DSTATE	03		/* inode is directory */
     53 #define	DFOUND	04		/* directory found during descent */
     54 #define	DCLEAR	05		/* directory is to be cleared */
     55 #define	FCLEAR	06		/* file is to be cleared */
     56 #define	DMARK	07		/* used in propagate()'s traversal algorithm */
     57 
     58 /*
     59  * buffer cache structure.
     60  */
     61 struct bufarea {
     62 	struct bufarea *b_next;		/* free list queue */
     63 	struct bufarea *b_prev;		/* free list queue */
     64 	ufs_daddr_t b_bno;
     65 	int b_size;
     66 	int b_errs;
     67 	int b_flags;
     68 	union {
     69 		char *b_buf;			/* buffer space */
     70 		ufs_daddr_t *b_indir;		/* indirect block */
     71 		struct fs *b_fs;		/* super block */
     72 		struct cg *b_cg;		/* cylinder group */
     73 		struct appleufslabel *b_appleufs;		/* Apple UFS volume label */
     74 	} b_un;
     75 	char b_dirty;
     76 };
     77 
     78 #define	B_INUSE 1
     79 
     80 #define	MINBUFS		5	/* minimum number of buffers required */
     81 struct bufarea bufhead;		/* head of list of other blks in filesys */
     82 struct bufarea sblk;		/* file system superblock */
     83 struct bufarea asblk;		/* file system superblock */
     84 struct bufarea cgblk;		/* cylinder group blocks */
     85 struct bufarea appleufsblk;		/* Apple UFS volume label */
     86 struct bufarea *pdirbp;		/* current directory contents */
     87 struct bufarea *pbp;		/* current inode block */
     88 
     89 #define	dirty(bp)	(bp)->b_dirty = 1
     90 #define	initbarea(bp) \
     91 	(bp)->b_dirty = 0; \
     92 	(bp)->b_bno = (ufs_daddr_t)-1; \
     93 	(bp)->b_flags = 0;
     94 
     95 struct fs *sblock;
     96 struct fs *altsblock;
     97 struct cg *cgrp;
     98 #define	sbdirty() \
     99 	do { \
    100 		memmove(sblk.b_un.b_fs, sblock, SBSIZE); \
    101 		if (needswap) \
    102 			ffs_sb_swap(sblock, sblk.b_un.b_fs); \
    103 		sblk.b_dirty = 1; \
    104 	} while (0)
    105 #define	cgdirty()	do {copyback_cg(&cgblk); cgblk.b_dirty = 1;} while (0)
    106 
    107 #define appleufsdirty() \
    108 	do { \
    109 		appleufsblk.b_un.b_appleufs->ul_checksum = 0; \
    110 		appleufsblk.b_un.b_appleufs->ul_checksum =  \
    111 			ffs_appleufs_cksum(appleufsblk.b_un.b_appleufs); \
    112 		appleufsblk.b_dirty = 1; \
    113 	} while (0)
    114 
    115 enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
    116 
    117 struct inodesc {
    118 	enum fixstate id_fix;	/* policy on fixing errors */
    119 	int (*id_func)		/* function to be applied to blocks of inode */
    120 	    __P((struct inodesc *));
    121 	ino_t id_number;	/* inode number described */
    122 	ino_t id_parent;	/* for DATA nodes, their parent */
    123 	ufs_daddr_t id_blkno;	/* current block number being examined */
    124 	int id_numfrags;	/* number of frags contained in block */
    125 	int64_t id_filesize;	/* for DATA nodes, the size of the directory */
    126 	int id_loc;		/* for DATA nodes, current location in dir */
    127 	int id_entryno;		/* for DATA nodes, current entry number */
    128 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
    129 	char *id_name;		/* for DATA nodes, name to find or enter */
    130 	char id_type;		/* type of descriptor, DATA or ADDR */
    131 };
    132 /* file types */
    133 #define	DATA	1
    134 #define	ADDR	2
    135 
    136 /*
    137  * Linked list of duplicate blocks.
    138  *
    139  * The list is composed of two parts. The first part of the
    140  * list (from duplist through the node pointed to by muldup)
    141  * contains a single copy of each duplicate block that has been
    142  * found. The second part of the list (from muldup to the end)
    143  * contains duplicate blocks that have been found more than once.
    144  * To check if a block has been found as a duplicate it is only
    145  * necessary to search from duplist through muldup. To find the
    146  * total number of times that a block has been found as a duplicate
    147  * the entire list must be searched for occurences of the block
    148  * in question. The following diagram shows a sample list where
    149  * w (found twice), x (found once), y (found three times), and z
    150  * (found once) are duplicate block numbers:
    151  *
    152  *    w -> y -> x -> z -> y -> w -> y
    153  *    ^		     ^
    154  *    |		     |
    155  * duplist	  muldup
    156  */
    157 struct dups {
    158 	struct dups *next;
    159 	ufs_daddr_t dup;
    160 };
    161 struct dups *duplist;		/* head of dup list */
    162 struct dups *muldup;		/* end of unique duplicate dup block numbers */
    163 
    164 /*
    165  * Linked list of inodes with zero link counts.
    166  */
    167 struct zlncnt {
    168 	struct zlncnt *next;
    169 	ino_t zlncnt;
    170 };
    171 struct zlncnt *zlnhead;		/* head of zero link count list */
    172 
    173 /*
    174  * Inode cache data structures.
    175  */
    176 struct inoinfo {
    177 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
    178 	struct	inoinfo	*i_child, *i_sibling, *i_parentp;
    179 	ino_t	i_number;		/* inode number of this entry */
    180 	ino_t	i_parent;		/* inode number of parent */
    181 	ino_t	i_dotdot;		/* inode number of `..' */
    182 	size_t	i_isize;		/* size of inode */
    183 	u_int	i_numblks;		/* size of block array in bytes */
    184 	ufs_daddr_t i_blks[1];		/* actually longer */
    185 } **inphead, **inpsort;
    186 long numdirs, listmax, inplast;
    187 
    188 long	dev_bsize;		/* computed value of DEV_BSIZE */
    189 long	secsize;		/* actual disk sector size */
    190 char	nflag;			/* assume a no response */
    191 char	yflag;			/* assume a yes response */
    192 int	bflag;			/* location of alternate super block */
    193 int	debug;			/* output debugging info */
    194 int	cvtlevel;		/* convert to newer file system format */
    195 int	doinglevel1;		/* converting to new cylinder group format */
    196 int	doinglevel2;		/* converting to new inode format */
    197 int	newinofmt;		/* filesystem has new inode format */
    198 char	usedsoftdep;		/* just fix soft dependency inconsistencies */
    199 int	preen;			/* just fix normal inconsistencies */
    200 int	forceimage;		/* file system is an image file */
    201 int	doswap;			/* convert byte order */
    202 int	needswap;		/* need to convert byte order in memory */
    203 int	do_blkswap;		/* need to do block addr byteswap */
    204 int	do_dirswap;		/* need to do dir entry byteswap */
    205 int	endian;			/* endian coversion */
    206 int	markclean;		/* mark file system clean when done */
    207 char	havesb;			/* superblock has been read */
    208 char	skipclean;		/* skip clean file systems if preening */
    209 int	fsmodified;		/* 1 => write done to file system */
    210 int	fsreadfd;		/* file descriptor for reading file system */
    211 int	fswritefd;		/* file descriptor for writing file system */
    212 int	rerun;			/* rerun fsck.  Only used in non-preen mode */
    213 char	resolved;		/* cleared if unresolved changes => not clean */
    214 int isappleufs;		/* filesystem is Apple UFS */
    215 
    216 ufs_daddr_t maxfsblock;		/* number of blocks in the file system */
    217 char	*blockmap;		/* ptr to primary blk allocation map */
    218 ino_t	maxino;			/* number of inodes in file system */
    219 ino_t	lastino;		/* last inode in use */
    220 char	*statemap;		/* ptr to inode state table */
    221 u_char	*typemap;		/* ptr to inode type table */
    222 int16_t	*lncntp;		/* ptr to link count table */
    223 
    224 int	dirblksiz;
    225 
    226 extern ino_t	lfdir;		/* lost & found directory inode number */
    227 extern char	*lfname;	/* lost & found directory name */
    228 extern int	lfmode;		/* lost & found directory creation mode */
    229 
    230 ufs_daddr_t n_blks;		/* number of blocks in use */
    231 ufs_daddr_t n_files;		/* number of files in use */
    232 
    233 int	got_siginfo;		/* received a SIGINFO */
    234 
    235 #define	clearinode(dp)	(*(dp) = zino)
    236 struct	dinode zino;
    237 
    238 #define	setbmap(blkno)	setbit(blockmap, blkno)
    239 #define	testbmap(blkno)	isset(blockmap, blkno)
    240 #define	clrbmap(blkno)	clrbit(blockmap, blkno)
    241 
    242 #define	STOP	0x01
    243 #define	SKIP	0x02
    244 #define	KEEPON	0x04
    245 #define	ALTERED	0x08
    246 #define	FOUND	0x10
    247 
    248 #define	EEXIT	8		/* Standard error exit. */
    249 
    250 /* some inline functs to help the byte-swapping mess */
    251 static __inline u_int16_t iswap16 __P((u_int16_t));
    252 static __inline u_int32_t iswap32 __P((u_int32_t));
    253 static __inline u_int64_t iswap64 __P((u_int64_t));
    254 
    255 static __inline u_int16_t iswap16(x)
    256 	u_int16_t x;
    257 {
    258 	if (needswap)
    259 		return bswap16(x);
    260 	else return x;
    261 }
    262 
    263 static __inline u_int32_t iswap32(x)
    264 	u_int32_t x;
    265 {
    266 	if (needswap)
    267 		return bswap32(x);
    268 	else return x;
    269 }
    270 
    271 static __inline u_int64_t iswap64(x)
    272 	u_int64_t x;
    273 {
    274 	if (needswap)
    275 		return bswap64(x);
    276 	else return x;
    277 }
    278 
    279 
    280