xref: /netbsd-src/sbin/fsck_ext2fs/fsck.h (revision 6ce4f404a1d437cb901a1e5b3c8e8533783799cd)
1*6ce4f404Sjoerg /*	$NetBSD: fsck.h,v 1.17 2020/04/05 15:25:39 joerg Exp $	*/
2bf07c871Sagc 
3bf07c871Sagc /*
4bf07c871Sagc  * Copyright (c) 1980, 1986, 1993
5bf07c871Sagc  *	The Regents of the University of California.  All rights reserved.
6bf07c871Sagc  *
7bf07c871Sagc  * Redistribution and use in source and binary forms, with or without
8bf07c871Sagc  * modification, are permitted provided that the following conditions
9bf07c871Sagc  * are met:
10bf07c871Sagc  * 1. Redistributions of source code must retain the above copyright
11bf07c871Sagc  *    notice, this list of conditions and the following disclaimer.
12bf07c871Sagc  * 2. Redistributions in binary form must reproduce the above copyright
13bf07c871Sagc  *    notice, this list of conditions and the following disclaimer in the
14bf07c871Sagc  *    documentation and/or other materials provided with the distribution.
15bf07c871Sagc  * 3. Neither the name of the University nor the names of its contributors
16bf07c871Sagc  *    may be used to endorse or promote products derived from this software
17bf07c871Sagc  *    without specific prior written permission.
18bf07c871Sagc  *
19bf07c871Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20bf07c871Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21bf07c871Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22bf07c871Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23bf07c871Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24bf07c871Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25bf07c871Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26bf07c871Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27bf07c871Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28bf07c871Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29bf07c871Sagc  * SUCH DAMAGE.
30bf07c871Sagc  *
31bf07c871Sagc  *	@(#)fsck.h	8.1 (Berkeley) 6/5/93
32bf07c871Sagc  */
338f7c2b37Sbouyer 
348f7c2b37Sbouyer /*
358f7c2b37Sbouyer  * Copyright (c) 1997 Manuel Bouyer.
368f7c2b37Sbouyer  *
378f7c2b37Sbouyer  * Redistribution and use in source and binary forms, with or without
388f7c2b37Sbouyer  * modification, are permitted provided that the following conditions
398f7c2b37Sbouyer  * are met:
408f7c2b37Sbouyer  * 1. Redistributions of source code must retain the above copyright
418f7c2b37Sbouyer  *    notice, this list of conditions and the following disclaimer.
428f7c2b37Sbouyer  * 2. Redistributions in binary form must reproduce the above copyright
438f7c2b37Sbouyer  *    notice, this list of conditions and the following disclaimer in the
448f7c2b37Sbouyer  *    documentation and/or other materials provided with the distribution.
458f7c2b37Sbouyer  *
462f853da9Sbouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
472f853da9Sbouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
482f853da9Sbouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
492f853da9Sbouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
502f853da9Sbouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
512f853da9Sbouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
522f853da9Sbouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
532f853da9Sbouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
542f853da9Sbouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
552f853da9Sbouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
568f7c2b37Sbouyer  *
578f7c2b37Sbouyer  *	@(#)fsck.h	8.1 (Berkeley) 6/5/93
588f7c2b37Sbouyer  */
598f7c2b37Sbouyer 
608f7c2b37Sbouyer #define	MAXDUP		10	/* limit on dup blks (per inode) */
618f7c2b37Sbouyer #define	MAXBAD		10	/* limit on bad blks (per inode) */
628f7c2b37Sbouyer #define	MAXBUFSPACE	80*1024	/* maximum space to allocate to buffers */
638f7c2b37Sbouyer #define	INOBUFSIZE	128*1024	/* size of buffer to read inodes in pass1 */
648f7c2b37Sbouyer 
658f7c2b37Sbouyer #ifndef BUFSIZ
668f7c2b37Sbouyer #define BUFSIZ 1024
678f7c2b37Sbouyer #endif
688f7c2b37Sbouyer 
698f7c2b37Sbouyer #define	USTATE	01		/* inode not allocated */
708f7c2b37Sbouyer #define	FSTATE	02		/* inode is file */
718f7c2b37Sbouyer #define	DSTATE	03		/* inode is directory */
728f7c2b37Sbouyer #define	DFOUND	04		/* directory found during descent */
738f7c2b37Sbouyer #define	DCLEAR	05		/* directory is to be cleared */
748f7c2b37Sbouyer #define	FCLEAR	06		/* file is to be cleared */
758f7c2b37Sbouyer 
768f7c2b37Sbouyer /*
778f7c2b37Sbouyer  * buffer cache structure.
788f7c2b37Sbouyer  */
798f7c2b37Sbouyer struct bufarea {
808f7c2b37Sbouyer 	struct bufarea	*b_next;		/* free list queue */
818f7c2b37Sbouyer 	struct bufarea	*b_prev;		/* free list queue */
828f7c2b37Sbouyer 	daddr_t	b_bno;
838f7c2b37Sbouyer 	int	b_size;
848f7c2b37Sbouyer 	int	b_errs;
858f7c2b37Sbouyer 	int	b_flags;
868f7c2b37Sbouyer 	union {
878f7c2b37Sbouyer 		char	*b_buf;			/* buffer space */
88a3ff3a30Sfvdl 		/* XXX ondisk32 */
89a3ff3a30Sfvdl 		int32_t	*b_indir;		/* indirect block */
907052d78bSbouyer 		struct	ext2fs *b_fs;		/* super block */
918f7c2b37Sbouyer 		struct	ext2_gd *b_cgd;		/* cylinder group descriptor */
928f7c2b37Sbouyer 		struct	ext2fs_dinode *b_dinode;	/* inode block */
938f7c2b37Sbouyer 	} b_un;
948f7c2b37Sbouyer 	char	b_dirty;
958f7c2b37Sbouyer };
968f7c2b37Sbouyer 
978f7c2b37Sbouyer #define	B_INUSE 1
988f7c2b37Sbouyer 
998f7c2b37Sbouyer #define	MINBUFS		5	/* minimum number of buffers required */
100*6ce4f404Sjoerg extern struct bufarea bufhead;		/* head of list of other blks in filesys */
101*6ce4f404Sjoerg extern struct bufarea sblk;		/* file system superblock */
102*6ce4f404Sjoerg extern struct bufarea asblk;		/* first alternate superblock */
103*6ce4f404Sjoerg extern struct bufarea *pdirbp;		/* current directory contents */
104*6ce4f404Sjoerg extern struct bufarea *pbp;		/* current inode block */
105*6ce4f404Sjoerg extern struct bufarea *getdatablk(daddr_t, long);
106*6ce4f404Sjoerg extern struct m_ext2fs sblock;
1078f7c2b37Sbouyer 
1088f7c2b37Sbouyer #define	dirty(bp)	(bp)->b_dirty = 1
1098f7c2b37Sbouyer #define	initbarea(bp) \
1108f7c2b37Sbouyer 	(bp)->b_dirty = 0; \
1118f7c2b37Sbouyer 	(bp)->b_bno = (daddr_t)-1; \
1128f7c2b37Sbouyer 	(bp)->b_flags = 0;
1138f7c2b37Sbouyer 
1147052d78bSbouyer #define	sbdirty()	copyback_sb(&sblk); sblk.b_dirty = 1
1158f7c2b37Sbouyer 
1168f7c2b37Sbouyer enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
1178f7c2b37Sbouyer 
1188f7c2b37Sbouyer struct inodesc {
1198f7c2b37Sbouyer 	enum fixstate id_fix;	/* policy on fixing errors */
1208f7c2b37Sbouyer 	int (*id_func)		/* function to be applied to blocks of inode */
121ccde05f0Sxtraeme 	    (struct inodesc *);
1228f7c2b37Sbouyer 	ino_t id_number;	/* inode number described */
1238f7c2b37Sbouyer 	ino_t id_parent;	/* for DATA nodes, their parent */
1248f7c2b37Sbouyer 	daddr_t id_blkno;	/* current block number being examined */
1258f7c2b37Sbouyer 	int id_numfrags;	/* number of frags contained in block */
1268f7c2b37Sbouyer 	quad_t id_filesize;	/* for DATA nodes, the size of the directory */
1278f7c2b37Sbouyer 	int id_loc;		/* for DATA nodes, current location in dir */
1288f7c2b37Sbouyer 	int id_entryno;		/* for DATA nodes, current entry number */
1298f7c2b37Sbouyer 	struct ext2fs_direct *id_dirp;	/* for DATA nodes, ptr to current entry */
13097880e96Schristos 	const char *id_name;	/* for DATA nodes, name to find or enter */
1318f7c2b37Sbouyer 	char id_type;		/* type of descriptor, DATA or ADDR */
1328f7c2b37Sbouyer };
1338f7c2b37Sbouyer /* file types */
1348f7c2b37Sbouyer #define	DATA	1
1358f7c2b37Sbouyer #define	ADDR	2
1368f7c2b37Sbouyer 
1378f7c2b37Sbouyer /*
1388f7c2b37Sbouyer  * Linked list of duplicate blocks.
1398f7c2b37Sbouyer  *
1408f7c2b37Sbouyer  * The list is composed of two parts. The first part of the
1418f7c2b37Sbouyer  * list (from duplist through the node pointed to by muldup)
1428f7c2b37Sbouyer  * contains a single copy of each duplicate block that has been
1438f7c2b37Sbouyer  * found. The second part of the list (from muldup to the end)
1448f7c2b37Sbouyer  * contains duplicate blocks that have been found more than once.
1458f7c2b37Sbouyer  * To check if a block has been found as a duplicate it is only
1468f7c2b37Sbouyer  * necessary to search from duplist through muldup. To find the
1478f7c2b37Sbouyer  * total number of times that a block has been found as a duplicate
1480acfa3bbSwiz  * the entire list must be searched for occurrences of the block
1498f7c2b37Sbouyer  * in question. The following diagram shows a sample list where
1508f7c2b37Sbouyer  * w (found twice), x (found once), y (found three times), and z
1518f7c2b37Sbouyer  * (found once) are duplicate block numbers:
1528f7c2b37Sbouyer  *
1538f7c2b37Sbouyer  *    w -> y -> x -> z -> y -> w -> y
1548f7c2b37Sbouyer  *    ^		     ^
1558f7c2b37Sbouyer  *    |		     |
1568f7c2b37Sbouyer  * duplist	  muldup
1578f7c2b37Sbouyer  */
1588f7c2b37Sbouyer struct dups {
1598f7c2b37Sbouyer 	struct dups *next;
1608f7c2b37Sbouyer 	daddr_t dup;
1618f7c2b37Sbouyer };
162*6ce4f404Sjoerg extern struct dups *duplist;	/* head of dup list */
163*6ce4f404Sjoerg extern struct dups *muldup;	/* end of unique duplicate dup block numbers */
1648f7c2b37Sbouyer 
1658f7c2b37Sbouyer /*
1668f7c2b37Sbouyer  * Linked list of inodes with zero link counts.
1678f7c2b37Sbouyer  */
1688f7c2b37Sbouyer struct zlncnt {
1698f7c2b37Sbouyer 	struct zlncnt *next;
1708f7c2b37Sbouyer 	ino_t zlncnt;
1718f7c2b37Sbouyer };
172*6ce4f404Sjoerg extern struct zlncnt *zlnhead;	/* head of zero link count list */
1738f7c2b37Sbouyer 
1748f7c2b37Sbouyer /*
1758f7c2b37Sbouyer  * Inode cache data structures.
1768f7c2b37Sbouyer  */
177*6ce4f404Sjoerg extern struct inoinfo {
1788f7c2b37Sbouyer 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
1798f7c2b37Sbouyer 	struct	inoinfo	*i_child, *i_sibling, *i_parentp;
1808f7c2b37Sbouyer 	ino_t	i_number;		/* inode number of this entry */
1818f7c2b37Sbouyer 	ino_t	i_parent;		/* inode number of parent */
1828f7c2b37Sbouyer 	ino_t	i_dotdot;		/* inode number of `..' */
183d53c382dSws 	u_int64_t i_isize;		/* size of inode */
1848f7c2b37Sbouyer 	u_int	i_numblks;		/* size of block array in bytes */
185a3ff3a30Sfvdl 	/* XXX ondisk32 */
186a3ff3a30Sfvdl 	int32_t	i_blks[1];		/* actually longer */
1878f7c2b37Sbouyer } **inphead, **inpsort;
188*6ce4f404Sjoerg extern long numdirs, listmax, inplast;
1898f7c2b37Sbouyer 
190*6ce4f404Sjoerg extern long	dev_bsize;	/* computed value of DEV_BSIZE */
191*6ce4f404Sjoerg extern long	secsize;	/* actual disk sector size */
192*6ce4f404Sjoerg extern char	nflag;		/* assume a no response */
193*6ce4f404Sjoerg extern char	yflag;		/* assume a yes response */
194*6ce4f404Sjoerg extern int	bflag;		/* location of alternate super block */
195*6ce4f404Sjoerg extern int	Uflag;		/* resolve user names */
196*6ce4f404Sjoerg extern int	debug;		/* output debugging info */
197*6ce4f404Sjoerg extern int	preen;		/* just fix normal inconsistencies */
198*6ce4f404Sjoerg extern char	havesb;		/* superblock has been read */
199*6ce4f404Sjoerg extern char	skipclean;	/* skip clean file systems if preening */
200*6ce4f404Sjoerg extern int	fsmodified;	/* 1 => write done to file system */
201*6ce4f404Sjoerg extern int	fsreadfd;	/* file descriptor for reading file system */
202*6ce4f404Sjoerg extern int	fswritefd;	/* file descriptor for writing file system */
203*6ce4f404Sjoerg extern int	rerun;		/* rerun fsck.  Only used in non-preen mode */
2048f7c2b37Sbouyer 
205*6ce4f404Sjoerg extern daddr_t	maxfsblock;	/* number of blocks in the file system */
206*6ce4f404Sjoerg extern char	*blockmap;	/* ptr to primary blk allocation map */
207*6ce4f404Sjoerg extern ino_t	maxino;		/* number of inodes in file system */
208*6ce4f404Sjoerg extern ino_t	lastino;	/* last inode in use */
209*6ce4f404Sjoerg extern char	*statemap;	/* ptr to inode state table */
210*6ce4f404Sjoerg extern u_char	*typemap;	/* ptr to inode type table */
211*6ce4f404Sjoerg extern int16_t	*lncntp;	/* ptr to link count table */
2128f7c2b37Sbouyer 
213*6ce4f404Sjoerg extern ino_t	lfdir;		/* lost & found directory inode number */
21497880e96Schristos extern const char *lfname;	/* lost & found directory name */
215422d6866Schristos extern int	lfmode;		/* lost & found directory creation mode */
2168f7c2b37Sbouyer 
217*6ce4f404Sjoerg extern daddr_t	n_blks;		/* number of blocks in use */
218*6ce4f404Sjoerg extern daddr_t	n_files;	/* number of files in use */
2198f7c2b37Sbouyer 
2208f7c2b37Sbouyer #define	clearinode(dp)	(*(dp) = zino)
221*6ce4f404Sjoerg extern struct	ext2fs_dinode zino;
2228f7c2b37Sbouyer 
2238f7c2b37Sbouyer #define	setbmap(blkno)	setbit(blockmap, blkno)
2248f7c2b37Sbouyer #define	testbmap(blkno)	isset(blockmap, blkno)
2258f7c2b37Sbouyer #define	clrbmap(blkno)	clrbit(blockmap, blkno)
2268f7c2b37Sbouyer 
2278f7c2b37Sbouyer #define	STOP	0x01
2288f7c2b37Sbouyer #define	SKIP	0x02
2298f7c2b37Sbouyer #define	KEEPON	0x04
2308f7c2b37Sbouyer #define	ALTERED	0x08
2318f7c2b37Sbouyer #define	FOUND	0x10
2328f7c2b37Sbouyer 
233d2d8cddeSjdolecek /*
234d2d8cddeSjdolecek  * Kernel support for features doesn't imply fsck support
235d2d8cddeSjdolecek  */
236d2d8cddeSjdolecek #define EXT2F_COMPAT_SUPP_FSCK		0x00
237d2d8cddeSjdolecek #define EXT2F_ROCOMPAT_SUPP_FSCK	(EXT2F_ROCOMPAT_SPARSESUPER \
238d2d8cddeSjdolecek                                          | EXT2F_ROCOMPAT_LARGEFILE \
239d2d8cddeSjdolecek                                          | EXT2F_ROCOMPAT_HUGE_FILE \
240d2d8cddeSjdolecek 					)
241d2d8cddeSjdolecek #define EXT2F_INCOMPAT_SUPP_FSCK	(EXT2F_INCOMPAT_FTYPE \
242d2d8cddeSjdolecek 					)
243d2d8cddeSjdolecek 
244ccde05f0Sxtraeme struct ext2fs_dinode *ginode(ino_t);
245ccde05f0Sxtraeme struct inoinfo *getinoinfo(ino_t);
246ccde05f0Sxtraeme void getblk(struct bufarea *, daddr_t, long);
247ccde05f0Sxtraeme ino_t allocino(ino_t, int);
248ccde05f0Sxtraeme void copyback_sb(struct bufarea*);
249ccde05f0Sxtraeme daddr_t cgoverhead(int);	/* overhead per cg */
250