xref: /freebsd/sbin/fsck_ffs/fsck.h (revision 4a835375057bce31cfc1d0ff907c604000066cd5)
18fae3551SRodney W. Grimes /*
21c85e6a3SKirk McKusick  * Copyright (c) 2002 Networks Associates Technology, Inc.
31c85e6a3SKirk McKusick  * All rights reserved.
41c85e6a3SKirk McKusick  *
51c85e6a3SKirk McKusick  * This software was developed for the FreeBSD Project by Marshall
61c85e6a3SKirk McKusick  * Kirk McKusick and Network Associates Laboratories, the Security
71c85e6a3SKirk McKusick  * Research Division of Network Associates, Inc. under DARPA/SPAWAR
81c85e6a3SKirk McKusick  * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
9363c1852SKirk McKusick  * research program.
101c85e6a3SKirk McKusick  *
1160c97629SRobert Watson  * Redistribution and use in source and binary forms, with or without
1260c97629SRobert Watson  * modification, are permitted provided that the following conditions
1360c97629SRobert Watson  * are met:
1460c97629SRobert Watson  * 1. Redistributions of source code must retain the above copyright
1560c97629SRobert Watson  *    notice, this list of conditions and the following disclaimer.
1660c97629SRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
1760c97629SRobert Watson  *    notice, this list of conditions and the following disclaimer in the
1860c97629SRobert Watson  *    documentation and/or other materials provided with the distribution.
1960c97629SRobert Watson  *
2060c97629SRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2160c97629SRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2260c97629SRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2360c97629SRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2460c97629SRobert Watson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2560c97629SRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2660c97629SRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2760c97629SRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2860c97629SRobert Watson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2960c97629SRobert Watson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3060c97629SRobert Watson  * SUCH DAMAGE.
3160c97629SRobert Watson  *
328fae3551SRodney W. Grimes  * Copyright (c) 1980, 1986, 1993
338fae3551SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
348fae3551SRodney W. Grimes  *
358fae3551SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
368fae3551SRodney W. Grimes  * modification, are permitted provided that the following conditions
378fae3551SRodney W. Grimes  * are met:
388fae3551SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
398fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
408fae3551SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
418fae3551SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
428fae3551SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
438fae3551SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
448fae3551SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
458fae3551SRodney W. Grimes  *    without specific prior written permission.
468fae3551SRodney W. Grimes  *
478fae3551SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
488fae3551SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
498fae3551SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
508fae3551SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
518fae3551SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
528fae3551SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
538fae3551SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
548fae3551SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
558fae3551SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
568fae3551SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
578fae3551SRodney W. Grimes  * SUCH DAMAGE.
588fae3551SRodney W. Grimes  *
59780a5c1eSPeter Wemm  *	@(#)fsck.h	8.4 (Berkeley) 5/9/95
6069205369SPeter Wemm  * $FreeBSD$
618fae3551SRodney W. Grimes  */
628fae3551SRodney W. Grimes 
63d00690aeSPawel Jakub Dawidek #ifndef _FSCK_H_
64d00690aeSPawel Jakub Dawidek #define	_FSCK_H_
65d00690aeSPawel Jakub Dawidek 
66780a5c1eSPeter Wemm #include <unistd.h>
67780a5c1eSPeter Wemm #include <stdlib.h>
68780a5c1eSPeter Wemm #include <stdio.h>
69780a5c1eSPeter Wemm 
708fae3551SRodney W. Grimes #define	MAXDUP		10	/* limit on dup blks (per inode) */
718fae3551SRodney W. Grimes #define	MAXBAD		10	/* limit on bad blks (per inode) */
728fae3551SRodney W. Grimes #define	MAXBUFSPACE	40*1024	/* maximum space to allocate to buffers */
738fae3551SRodney W. Grimes #define	INOBUFSIZE	56*1024	/* size of buffer to read inodes in pass1 */
748fae3551SRodney W. Grimes 
751c85e6a3SKirk McKusick union dinode {
761c85e6a3SKirk McKusick 	struct ufs1_dinode dp1;
771c85e6a3SKirk McKusick 	struct ufs2_dinode dp2;
781c85e6a3SKirk McKusick };
791c85e6a3SKirk McKusick #define	DIP(dp, field) \
801c85e6a3SKirk McKusick 	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
811c85e6a3SKirk McKusick 	(dp)->dp1.field : (dp)->dp2.field)
821c85e6a3SKirk McKusick 
83c3b2344bSScott Long #define DIP_SET(dp, field, val) do { \
84c3b2344bSScott Long 	if (sblock.fs_magic == FS_UFS1_MAGIC) \
85c3b2344bSScott Long 		(dp)->dp1.field = (val); \
86c3b2344bSScott Long 	else \
87c3b2344bSScott Long 		(dp)->dp2.field = (val); \
88c3b2344bSScott Long 	} while (0)
89c3b2344bSScott Long 
90d33e92f9SJulian Elischer /*
91d33e92f9SJulian Elischer  * Each inode on the file system is described by the following structure.
92d33e92f9SJulian Elischer  * The linkcnt is initially set to the value in the inode. Each time it
93d33e92f9SJulian Elischer  * is found during the descent in passes 2, 3, and 4 the count is
94d33e92f9SJulian Elischer  * decremented. Any inodes whose count is non-zero after pass 4 needs to
95d33e92f9SJulian Elischer  * have its link count adjusted by the value remaining in ino_linkcnt.
96d33e92f9SJulian Elischer  */
97d33e92f9SJulian Elischer struct inostat {
98d33e92f9SJulian Elischer 	char	ino_state;	/* state of inode, see below */
99d33e92f9SJulian Elischer 	char	ino_type;	/* type of inode */
100d33e92f9SJulian Elischer 	short	ino_linkcnt;	/* number of links not found */
101d33e92f9SJulian Elischer };
102d33e92f9SJulian Elischer /*
103d33e92f9SJulian Elischer  * Inode states.
104d33e92f9SJulian Elischer  */
105af6726e6SDon Lewis #define	USTATE	0x1		/* inode not allocated */
106af6726e6SDon Lewis #define	FSTATE	0x2		/* inode is file */
107af6726e6SDon Lewis #define	FZLINK	0x3		/* inode is file with a link count of zero */
108af6726e6SDon Lewis #define	DSTATE	0x4		/* inode is directory */
109af6726e6SDon Lewis #define	DZLINK	0x5		/* inode is directory with a zero link count  */
110af6726e6SDon Lewis #define	DFOUND	0x6		/* directory found during descent */
111af6726e6SDon Lewis /*     		0x7		   UNUSED - see S_IS_DVALID() definition */
112af6726e6SDon Lewis #define	DCLEAR	0x8		/* directory is to be cleared */
113af6726e6SDon Lewis #define	FCLEAR	0x9		/* file is to be cleared */
114af6726e6SDon Lewis /*     	DUNFOUND === (state == DSTATE || state == DZLINK) */
115af6726e6SDon Lewis #define	S_IS_DUNFOUND(state)	(((state) & ~0x1) == DSTATE)
116af6726e6SDon Lewis /*     	DVALID   === (state == DSTATE || state == DZLINK || state == DFOUND) */
117af6726e6SDon Lewis #define	S_IS_DVALID(state)	(((state) & ~0x3) == DSTATE)
118af6726e6SDon Lewis #define	INO_IS_DUNFOUND(ino)	S_IS_DUNFOUND(inoinfo(ino)->ino_state)
119af6726e6SDon Lewis #define	INO_IS_DVALID(ino)	S_IS_DVALID(inoinfo(ino)->ino_state)
120d33e92f9SJulian Elischer /*
121d33e92f9SJulian Elischer  * Inode state information is contained on per cylinder group lists
122d33e92f9SJulian Elischer  * which are described by the following structure.
123d33e92f9SJulian Elischer  */
124d33e92f9SJulian Elischer struct inostatlist {
125d33e92f9SJulian Elischer 	long	il_numalloced;	/* number of inodes allocated in this cg */
126d33e92f9SJulian Elischer 	struct inostat *il_stat;/* inostat info for this cylinder group */
127d33e92f9SJulian Elischer } *inostathead;
1288fae3551SRodney W. Grimes 
1298fae3551SRodney W. Grimes /*
1308fae3551SRodney W. Grimes  * buffer cache structure.
1318fae3551SRodney W. Grimes  */
1328fae3551SRodney W. Grimes struct bufarea {
1338fae3551SRodney W. Grimes 	struct bufarea *b_next;		/* free list queue */
1348fae3551SRodney W. Grimes 	struct bufarea *b_prev;		/* free list queue */
1351c85e6a3SKirk McKusick 	ufs2_daddr_t b_bno;
1368fae3551SRodney W. Grimes 	int b_size;
1378fae3551SRodney W. Grimes 	int b_errs;
1388fae3551SRodney W. Grimes 	int b_flags;
1398fae3551SRodney W. Grimes 	union {
1408fae3551SRodney W. Grimes 		char *b_buf;			/* buffer space */
1411c85e6a3SKirk McKusick 		ufs1_daddr_t *b_indir1;		/* UFS1 indirect block */
1421c85e6a3SKirk McKusick 		ufs2_daddr_t *b_indir2;		/* UFS2 indirect block */
1438fae3551SRodney W. Grimes 		struct fs *b_fs;		/* super block */
1448fae3551SRodney W. Grimes 		struct cg *b_cg;		/* cylinder group */
1451c85e6a3SKirk McKusick 		struct ufs1_dinode *b_dinode1;	/* UFS1 inode block */
1461c85e6a3SKirk McKusick 		struct ufs2_dinode *b_dinode2;	/* UFS2 inode block */
1478fae3551SRodney W. Grimes 	} b_un;
1488fae3551SRodney W. Grimes 	char b_dirty;
1498fae3551SRodney W. Grimes };
150c3b2344bSScott Long 
1511c85e6a3SKirk McKusick #define	IBLK(bp, i) \
1521c85e6a3SKirk McKusick 	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
1531c85e6a3SKirk McKusick 	(bp)->b_un.b_indir1[i] : (bp)->b_un.b_indir2[i])
1548fae3551SRodney W. Grimes 
155c3b2344bSScott Long #define IBLK_SET(bp, i, val) do { \
156c3b2344bSScott Long 	if (sblock.fs_magic == FS_UFS1_MAGIC) \
157c3b2344bSScott Long 		(bp)->b_un.b_indir1[i] = (val); \
158c3b2344bSScott Long 	else \
159c3b2344bSScott Long 		(bp)->b_un.b_indir2[i] = (val); \
160c3b2344bSScott Long 	} while (0)
161c3b2344bSScott Long 
1628fae3551SRodney W. Grimes #define	B_INUSE 1
1638fae3551SRodney W. Grimes 
1648fae3551SRodney W. Grimes #define	MINBUFS		5	/* minimum number of buffers required */
1658fae3551SRodney W. Grimes struct bufarea bufhead;		/* head of list of other blks in filesys */
1668fae3551SRodney W. Grimes struct bufarea sblk;		/* file system superblock */
1678fae3551SRodney W. Grimes struct bufarea cgblk;		/* cylinder group blocks */
1688fae3551SRodney W. Grimes struct bufarea *pdirbp;		/* current directory contents */
1698fae3551SRodney W. Grimes struct bufarea *pbp;		/* current inode block */
1708fae3551SRodney W. Grimes 
171bf58d635SIan Dowse #define	dirty(bp) do { \
1727578c6abSKirk McKusick 	if (fswritefd < 0) \
1737578c6abSKirk McKusick 		pfatal("SETTING DIRTY FLAG IN READ_ONLY MODE\n"); \
1747578c6abSKirk McKusick 	else \
175bf58d635SIan Dowse 		(bp)->b_dirty = 1; \
176bf58d635SIan Dowse } while (0)
177bf58d635SIan Dowse #define	initbarea(bp) do { \
1788fae3551SRodney W. Grimes 	(bp)->b_dirty = 0; \
1791c85e6a3SKirk McKusick 	(bp)->b_bno = (ufs2_daddr_t)-1; \
180bf58d635SIan Dowse 	(bp)->b_flags = 0; \
181bf58d635SIan Dowse } while (0)
1828fae3551SRodney W. Grimes 
1837578c6abSKirk McKusick #define	sbdirty()	dirty(&sblk)
1847578c6abSKirk McKusick #define	cgdirty()	dirty(&cgblk)
1858fae3551SRodney W. Grimes #define	sblock		(*sblk.b_un.b_fs)
1868fae3551SRodney W. Grimes #define	cgrp		(*cgblk.b_un.b_cg)
1878fae3551SRodney W. Grimes 
1888fae3551SRodney W. Grimes enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
189142d8d2fSKirk McKusick ino_t cursnapshot;
1908fae3551SRodney W. Grimes 
1918fae3551SRodney W. Grimes struct inodesc {
1928fae3551SRodney W. Grimes 	enum fixstate id_fix;	/* policy on fixing errors */
193599304a4SPoul-Henning Kamp 	int (*id_func)(struct inodesc *);
194599304a4SPoul-Henning Kamp 				/* function to be applied to blocks of inode */
1958fae3551SRodney W. Grimes 	ino_t id_number;	/* inode number described */
1968fae3551SRodney W. Grimes 	ino_t id_parent;	/* for DATA nodes, their parent */
1971c85e6a3SKirk McKusick 	ufs_lbn_t id_lbn;	/* logical block number of current block */
1981c85e6a3SKirk McKusick 	ufs2_daddr_t id_blkno;	/* current block number being examined */
1998fae3551SRodney W. Grimes 	int id_numfrags;	/* number of frags contained in block */
2001c85e6a3SKirk McKusick 	off_t id_filesize;	/* for DATA nodes, the size of the directory */
2011c85e6a3SKirk McKusick 	ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */
2028fae3551SRodney W. Grimes 	int id_loc;		/* for DATA nodes, current location in dir */
2038fae3551SRodney W. Grimes 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
2048fae3551SRodney W. Grimes 	char *id_name;		/* for DATA nodes, name to find or enter */
2058fae3551SRodney W. Grimes 	char id_type;		/* type of descriptor, DATA or ADDR */
2068fae3551SRodney W. Grimes };
2078fae3551SRodney W. Grimes /* file types */
208142d8d2fSKirk McKusick #define	DATA	1	/* a directory */
209142d8d2fSKirk McKusick #define	SNAP	2	/* a snapshot */
210142d8d2fSKirk McKusick #define	ADDR	3	/* anything but a directory or a snapshot */
2118fae3551SRodney W. Grimes 
2128fae3551SRodney W. Grimes /*
2138fae3551SRodney W. Grimes  * Linked list of duplicate blocks.
2148fae3551SRodney W. Grimes  *
2158fae3551SRodney W. Grimes  * The list is composed of two parts. The first part of the
2168fae3551SRodney W. Grimes  * list (from duplist through the node pointed to by muldup)
2178fae3551SRodney W. Grimes  * contains a single copy of each duplicate block that has been
2188fae3551SRodney W. Grimes  * found. The second part of the list (from muldup to the end)
2198fae3551SRodney W. Grimes  * contains duplicate blocks that have been found more than once.
2208fae3551SRodney W. Grimes  * To check if a block has been found as a duplicate it is only
2218fae3551SRodney W. Grimes  * necessary to search from duplist through muldup. To find the
2228fae3551SRodney W. Grimes  * total number of times that a block has been found as a duplicate
2234b85a12fSUlrich Spörlein  * the entire list must be searched for occurrences of the block
2248fae3551SRodney W. Grimes  * in question. The following diagram shows a sample list where
2258fae3551SRodney W. Grimes  * w (found twice), x (found once), y (found three times), and z
2268fae3551SRodney W. Grimes  * (found once) are duplicate block numbers:
2278fae3551SRodney W. Grimes  *
2288fae3551SRodney W. Grimes  *    w -> y -> x -> z -> y -> w -> y
2298fae3551SRodney W. Grimes  *    ^		     ^
2308fae3551SRodney W. Grimes  *    |		     |
2318fae3551SRodney W. Grimes  * duplist	  muldup
2328fae3551SRodney W. Grimes  */
2338fae3551SRodney W. Grimes struct dups {
2348fae3551SRodney W. Grimes 	struct dups *next;
2351c85e6a3SKirk McKusick 	ufs2_daddr_t dup;
2368fae3551SRodney W. Grimes };
2378fae3551SRodney W. Grimes struct dups *duplist;		/* head of dup list */
2388fae3551SRodney W. Grimes struct dups *muldup;		/* end of unique duplicate dup block numbers */
2398fae3551SRodney W. Grimes 
2408fae3551SRodney W. Grimes /*
2418fae3551SRodney W. Grimes  * Inode cache data structures.
2428fae3551SRodney W. Grimes  */
2438fae3551SRodney W. Grimes struct inoinfo {
2448fae3551SRodney W. Grimes 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
2458fae3551SRodney W. Grimes 	ino_t	i_number;		/* inode number of this entry */
2468fae3551SRodney W. Grimes 	ino_t	i_parent;		/* inode number of parent */
2478fae3551SRodney W. Grimes 	ino_t	i_dotdot;		/* inode number of `..' */
2488fae3551SRodney W. Grimes 	size_t	i_isize;		/* size of inode */
2498fae3551SRodney W. Grimes 	u_int	i_numblks;		/* size of block array in bytes */
2501c85e6a3SKirk McKusick 	ufs2_daddr_t i_blks[1];		/* actually longer */
2518fae3551SRodney W. Grimes } **inphead, **inpsort;
252e50342e6SKirk McKusick long numdirs, dirhash, listmax, inplast;
253d33e92f9SJulian Elischer long countdirs;			/* number of directories we actually found */
2548fae3551SRodney W. Grimes 
2557578c6abSKirk McKusick #define MIBSIZE	3		/* size of fsck sysctl MIBs */
2567578c6abSKirk McKusick int	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
2577578c6abSKirk McKusick int	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
258a16baf37SXin LI int	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
259a16baf37SXin LI int	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
260a16baf37SXin LI int	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
261a16baf37SXin LI int	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
262a16baf37SXin LI int	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
2637578c6abSKirk McKusick int	freefiles[MIBSIZE];	/* MIB command to free a set of files */
2647578c6abSKirk McKusick int	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
2657578c6abSKirk McKusick int	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
2667578c6abSKirk McKusick struct	fsck_cmd cmd;		/* sysctl file system update commands */
2677578c6abSKirk McKusick char	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
2688fae3551SRodney W. Grimes char	*cdevname;		/* name of device being checked */
2698fae3551SRodney W. Grimes long	dev_bsize;		/* computed value of DEV_BSIZE */
2708fae3551SRodney W. Grimes long	secsize;		/* actual disk sector size */
2716f100596SKonstantin Belousov u_int	real_dev_bsize;		/* actual disk sector size, not overriden */
2728fae3551SRodney W. Grimes char	nflag;			/* assume a no response */
2738fae3551SRodney W. Grimes char	yflag;			/* assume a yes response */
2747578c6abSKirk McKusick int	bkgrdflag;		/* use a snapshot to run on an active system */
2758fae3551SRodney W. Grimes int	bflag;			/* location of alternate super block */
2768fae3551SRodney W. Grimes int	debug;			/* output debugging info */
2778d3dfc26SDag-Erling Smørgrav int	Eflag;			/* zero out empty data blocks */
278910b491eSKirk McKusick int	inoopt;			/* trim out unused inodes */
279111a5220SDavid E. O'Brien char	ckclean;		/* only do work if not cleanly unmounted */
2808fae3551SRodney W. Grimes int	cvtlevel;		/* convert to newer file system format */
28115fca934SKirk McKusick int	bkgrdcheck;		/* determine if background check is possible */
282c0ed8991SXin LI int	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
283b1897c19SJulian Elischer char	usedsoftdep;		/* just fix soft dependency inconsistencies */
2848fae3551SRodney W. Grimes char	preen;			/* just fix normal inconsistencies */
285d33e92f9SJulian Elischer char	rerun;			/* rerun fsck. Only used in non-preen mode */
286d33e92f9SJulian Elischer int	returntosingle;		/* 1 => return to single user mode on exit */
287d33e92f9SJulian Elischer char	resolved;		/* cleared if unresolved changes => not clean */
2888fae3551SRodney W. Grimes char	havesb;			/* superblock has been read */
2899ea6f4f0SAdrian Chadd char	skipclean;		/* skip clean file systems if preening */
2908fae3551SRodney W. Grimes int	fsmodified;		/* 1 => write done to file system */
2918fae3551SRodney W. Grimes int	fsreadfd;		/* file descriptor for reading file system */
2928fae3551SRodney W. Grimes int	fswritefd;		/* file descriptor for writing file system */
2938fae3551SRodney W. Grimes 
2941c85e6a3SKirk McKusick ufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
2958fae3551SRodney W. Grimes char	*blockmap;		/* ptr to primary blk allocation map */
2968fae3551SRodney W. Grimes ino_t	maxino;			/* number of inodes in file system */
2978fae3551SRodney W. Grimes 
2988fae3551SRodney W. Grimes ino_t	lfdir;			/* lost & found directory inode number */
299599304a4SPoul-Henning Kamp const char *lfname;		/* lost & found directory name */
3008fae3551SRodney W. Grimes int	lfmode;			/* lost & found directory creation mode */
3018fae3551SRodney W. Grimes 
3021c85e6a3SKirk McKusick ufs2_daddr_t n_blks;		/* number of blocks in use */
3031c85e6a3SKirk McKusick ino_t n_files;			/* number of files in use */
3048fae3551SRodney W. Grimes 
305fd02a3b5SUlf Lilleengen volatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
306fd02a3b5SUlf Lilleengen volatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
3076db798caSIan Dowse 
3081c85e6a3SKirk McKusick #define	clearinode(dp) \
3091c85e6a3SKirk McKusick 	if (sblock.fs_magic == FS_UFS1_MAGIC) { \
3101c85e6a3SKirk McKusick 		(dp)->dp1 = ufs1_zino; \
3111c85e6a3SKirk McKusick 	} else { \
3121c85e6a3SKirk McKusick 		(dp)->dp2 = ufs2_zino; \
3131c85e6a3SKirk McKusick 	}
3141c85e6a3SKirk McKusick struct	ufs1_dinode ufs1_zino;
3151c85e6a3SKirk McKusick struct	ufs2_dinode ufs2_zino;
3168fae3551SRodney W. Grimes 
3178fae3551SRodney W. Grimes #define	setbmap(blkno)	setbit(blockmap, blkno)
3188fae3551SRodney W. Grimes #define	testbmap(blkno)	isset(blockmap, blkno)
3198fae3551SRodney W. Grimes #define	clrbmap(blkno)	clrbit(blockmap, blkno)
3208fae3551SRodney W. Grimes 
3218fae3551SRodney W. Grimes #define	STOP	0x01
3228fae3551SRodney W. Grimes #define	SKIP	0x02
3238fae3551SRodney W. Grimes #define	KEEPON	0x04
3248fae3551SRodney W. Grimes #define	ALTERED	0x08
3258fae3551SRodney W. Grimes #define	FOUND	0x10
3268fae3551SRodney W. Grimes 
327780a5c1eSPeter Wemm #define	EEXIT	8		/* Standard error exit. */
328780a5c1eSPeter Wemm 
329780a5c1eSPeter Wemm struct fstab;
330780a5c1eSPeter Wemm 
331d33e92f9SJulian Elischer 
332b70cd7eeSWarner Losh void		adjust(struct inodesc *, int lcnt);
3331c85e6a3SKirk McKusick ufs2_daddr_t	allocblk(long frags);
334b70cd7eeSWarner Losh ino_t		allocdir(ino_t parent, ino_t request, int mode);
335b70cd7eeSWarner Losh ino_t		allocino(ino_t request, int type);
336599304a4SPoul-Henning Kamp void		blkerror(ino_t ino, const char *type, ufs2_daddr_t blk);
337b70cd7eeSWarner Losh char	       *blockcheck(char *name);
338aef8d244SPawel Jakub Dawidek int		blread(int fd, char *buf, ufs2_daddr_t blk, long size);
339b70cd7eeSWarner Losh void		bufinit(void);
340*4a835375SDavid E. O'Brien void		blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size);
3418d3dfc26SDag-Erling Smørgrav void		blerase(int fd, ufs2_daddr_t blk, long size);
3421c85e6a3SKirk McKusick void		cacheino(union dinode *dp, ino_t inumber);
343b70cd7eeSWarner Losh void		catch(int);
344b70cd7eeSWarner Losh void		catchquit(int);
345599304a4SPoul-Henning Kamp int		changeino(ino_t dir, const char *name, ino_t newnum);
346910b491eSKirk McKusick int		check_cgmagic(int cg, struct cg *cgp);
3471c85e6a3SKirk McKusick int		chkrange(ufs2_daddr_t blk, int cnt);
348b70cd7eeSWarner Losh void		ckfini(int markclean);
3491c85e6a3SKirk McKusick int		ckinode(union dinode *dp, struct inodesc *);
350599304a4SPoul-Henning Kamp void		clri(struct inodesc *, const char *type, int flag);
351b70cd7eeSWarner Losh int		clearentry(struct inodesc *);
352599304a4SPoul-Henning Kamp void		direrror(ino_t ino, const char *errmesg);
353b70cd7eeSWarner Losh int		dirscan(struct inodesc *);
354599304a4SPoul-Henning Kamp int		dofix(struct inodesc *, const char *msg);
35551869213SPoul-Henning Kamp int		eascan(struct inodesc *, struct ufs2_dinode *dp);
356599304a4SPoul-Henning Kamp void		fileerror(ino_t cwd, ino_t ino, const char *errmesg);
357b70cd7eeSWarner Losh int		findino(struct inodesc *);
358b70cd7eeSWarner Losh int		findname(struct inodesc *);
359b70cd7eeSWarner Losh void		flush(int fd, struct bufarea *bp);
3601c85e6a3SKirk McKusick void		freeblk(ufs2_daddr_t blkno, long frags);
361b70cd7eeSWarner Losh void		freeino(ino_t ino);
362b70cd7eeSWarner Losh void		freeinodebuf(void);
3631c85e6a3SKirk McKusick int		ftypeok(union dinode *dp);
3641c85e6a3SKirk McKusick void		getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
3651c85e6a3SKirk McKusick struct bufarea *getdatablk(ufs2_daddr_t blkno, long size);
366b70cd7eeSWarner Losh struct inoinfo *getinoinfo(ino_t inumber);
367910b491eSKirk McKusick union dinode   *getnextinode(ino_t inumber, int rebuildcg);
368b70cd7eeSWarner Losh void		getpathname(char *namebuf, ino_t curdir, ino_t ino);
3691c85e6a3SKirk McKusick union dinode   *ginode(ino_t inumber);
370b70cd7eeSWarner Losh void		infohandler(int sig);
3711660ae87SScott Long void		alarmhandler(int sig);
372b70cd7eeSWarner Losh void		inocleanup(void);
373b70cd7eeSWarner Losh void		inodirty(void);
374b70cd7eeSWarner Losh struct inostat *inoinfo(ino_t inum);
375b70cd7eeSWarner Losh int		linkup(ino_t orphan, ino_t parentdir, char *name);
376599304a4SPoul-Henning Kamp int		makeentry(ino_t parent, ino_t ino, const char *name);
377b70cd7eeSWarner Losh void		panic(const char *fmt, ...) __printflike(1, 2);
378b70cd7eeSWarner Losh void		pass1(void);
379b70cd7eeSWarner Losh void		pass1b(void);
380b70cd7eeSWarner Losh int		pass1check(struct inodesc *);
381b70cd7eeSWarner Losh void		pass2(void);
382b70cd7eeSWarner Losh void		pass3(void);
383b70cd7eeSWarner Losh void		pass4(void);
384b70cd7eeSWarner Losh int		pass4check(struct inodesc *);
385b70cd7eeSWarner Losh void		pass5(void);
386b70cd7eeSWarner Losh void		pfatal(const char *fmt, ...) __printflike(1, 2);
387b70cd7eeSWarner Losh void		pinode(ino_t ino);
388b70cd7eeSWarner Losh void		propagate(void);
389b70cd7eeSWarner Losh void		pwarn(const char *fmt, ...) __printflike(1, 2);
390b70cd7eeSWarner Losh int		readsb(int listerr);
391599304a4SPoul-Henning Kamp int		reply(const char *question);
392599304a4SPoul-Henning Kamp void		rwerror(const char *mesg, ufs2_daddr_t blk);
393b70cd7eeSWarner Losh void		sblock_init(void);
394b70cd7eeSWarner Losh void		setinodebuf(ino_t);
395b70cd7eeSWarner Losh int		setup(char *dev);
396aef8d244SPawel Jakub Dawidek void		gjournal_check(const char *filesys);
397113db2ddSJeff Roberson int		suj_check(const char *filesys);
398d2404f04SKirk McKusick void		update_maps(struct cg *, struct cg*, int);
399d00690aeSPawel Jakub Dawidek 
400d00690aeSPawel Jakub Dawidek #endif	/* !_FSCK_H_ */
401