xref: /freebsd/sbin/fsck_ffs/fsck.h (revision 81fbded23f378af5d15b45c7f477d91774807572)
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 
702ec5c914SKirk McKusick #include <sys/queue.h>
712ec5c914SKirk McKusick 
728fae3551SRodney W. Grimes #define	MAXDUP		10	/* limit on dup blks (per inode) */
738fae3551SRodney W. Grimes #define	MAXBAD		10	/* limit on bad blks (per inode) */
742ec5c914SKirk McKusick #define	MINBUFS		10	/* minimum number of buffers required */
752ec5c914SKirk McKusick #define	MAXBUFS		40	/* maximum space to allocate to buffers */
762ec5c914SKirk McKusick #define	INOBUFSIZE	64*1024	/* size of buffer to read inodes in pass1 */
778fae3551SRodney W. Grimes 
781c85e6a3SKirk McKusick union dinode {
791c85e6a3SKirk McKusick 	struct ufs1_dinode dp1;
801c85e6a3SKirk McKusick 	struct ufs2_dinode dp2;
811c85e6a3SKirk McKusick };
821c85e6a3SKirk McKusick #define	DIP(dp, field) \
831c85e6a3SKirk McKusick 	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
841c85e6a3SKirk McKusick 	(dp)->dp1.field : (dp)->dp2.field)
851c85e6a3SKirk McKusick 
86c3b2344bSScott Long #define DIP_SET(dp, field, val) do { \
87c3b2344bSScott Long 	if (sblock.fs_magic == FS_UFS1_MAGIC) \
88c3b2344bSScott Long 		(dp)->dp1.field = (val); \
89c3b2344bSScott Long 	else \
90c3b2344bSScott Long 		(dp)->dp2.field = (val); \
91c3b2344bSScott Long 	} while (0)
92c3b2344bSScott Long 
93d33e92f9SJulian Elischer /*
94d33e92f9SJulian Elischer  * Each inode on the file system is described by the following structure.
95d33e92f9SJulian Elischer  * The linkcnt is initially set to the value in the inode. Each time it
96d33e92f9SJulian Elischer  * is found during the descent in passes 2, 3, and 4 the count is
97d33e92f9SJulian Elischer  * decremented. Any inodes whose count is non-zero after pass 4 needs to
98d33e92f9SJulian Elischer  * have its link count adjusted by the value remaining in ino_linkcnt.
99d33e92f9SJulian Elischer  */
100d33e92f9SJulian Elischer struct inostat {
101d33e92f9SJulian Elischer 	char	ino_state;	/* state of inode, see below */
102d33e92f9SJulian Elischer 	char	ino_type;	/* type of inode */
103d33e92f9SJulian Elischer 	short	ino_linkcnt;	/* number of links not found */
104d33e92f9SJulian Elischer };
105d33e92f9SJulian Elischer /*
106d33e92f9SJulian Elischer  * Inode states.
107d33e92f9SJulian Elischer  */
108af6726e6SDon Lewis #define	USTATE	0x1		/* inode not allocated */
109af6726e6SDon Lewis #define	FSTATE	0x2		/* inode is file */
110af6726e6SDon Lewis #define	FZLINK	0x3		/* inode is file with a link count of zero */
111af6726e6SDon Lewis #define	DSTATE	0x4		/* inode is directory */
112af6726e6SDon Lewis #define	DZLINK	0x5		/* inode is directory with a zero link count  */
113af6726e6SDon Lewis #define	DFOUND	0x6		/* directory found during descent */
114af6726e6SDon Lewis /*     		0x7		   UNUSED - see S_IS_DVALID() definition */
115af6726e6SDon Lewis #define	DCLEAR	0x8		/* directory is to be cleared */
116af6726e6SDon Lewis #define	FCLEAR	0x9		/* file is to be cleared */
117af6726e6SDon Lewis /*     	DUNFOUND === (state == DSTATE || state == DZLINK) */
118af6726e6SDon Lewis #define	S_IS_DUNFOUND(state)	(((state) & ~0x1) == DSTATE)
119af6726e6SDon Lewis /*     	DVALID   === (state == DSTATE || state == DZLINK || state == DFOUND) */
120af6726e6SDon Lewis #define	S_IS_DVALID(state)	(((state) & ~0x3) == DSTATE)
121af6726e6SDon Lewis #define	INO_IS_DUNFOUND(ino)	S_IS_DUNFOUND(inoinfo(ino)->ino_state)
122af6726e6SDon Lewis #define	INO_IS_DVALID(ino)	S_IS_DVALID(inoinfo(ino)->ino_state)
123d33e92f9SJulian Elischer /*
124d33e92f9SJulian Elischer  * Inode state information is contained on per cylinder group lists
125d33e92f9SJulian Elischer  * which are described by the following structure.
126d33e92f9SJulian Elischer  */
127d33e92f9SJulian Elischer struct inostatlist {
128d33e92f9SJulian Elischer 	long	il_numalloced;	/* number of inodes allocated in this cg */
129d33e92f9SJulian Elischer 	struct inostat *il_stat;/* inostat info for this cylinder group */
130d33e92f9SJulian Elischer } *inostathead;
1318fae3551SRodney W. Grimes 
1328fae3551SRodney W. Grimes /*
1338fae3551SRodney W. Grimes  * buffer cache structure.
1348fae3551SRodney W. Grimes  */
1358fae3551SRodney W. Grimes struct bufarea {
1362ec5c914SKirk McKusick 	TAILQ_ENTRY(bufarea) b_list;		/* buffer list */
1371c85e6a3SKirk McKusick 	ufs2_daddr_t b_bno;
1388fae3551SRodney W. Grimes 	int b_size;
1398fae3551SRodney W. Grimes 	int b_errs;
1408fae3551SRodney W. Grimes 	int b_flags;
141ed75b5a1SKirk McKusick 	int b_type;
1428fae3551SRodney W. Grimes 	union {
1438fae3551SRodney W. Grimes 		char *b_buf;			/* buffer space */
1441c85e6a3SKirk McKusick 		ufs1_daddr_t *b_indir1;		/* UFS1 indirect block */
1451c85e6a3SKirk McKusick 		ufs2_daddr_t *b_indir2;		/* UFS2 indirect block */
1468fae3551SRodney W. Grimes 		struct fs *b_fs;		/* super block */
1478fae3551SRodney W. Grimes 		struct cg *b_cg;		/* cylinder group */
1481c85e6a3SKirk McKusick 		struct ufs1_dinode *b_dinode1;	/* UFS1 inode block */
1491c85e6a3SKirk McKusick 		struct ufs2_dinode *b_dinode2;	/* UFS2 inode block */
1508fae3551SRodney W. Grimes 	} b_un;
1518fae3551SRodney W. Grimes 	char b_dirty;
1528fae3551SRodney W. Grimes };
153c3b2344bSScott Long 
1541c85e6a3SKirk McKusick #define	IBLK(bp, i) \
1551c85e6a3SKirk McKusick 	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
1561c85e6a3SKirk McKusick 	(bp)->b_un.b_indir1[i] : (bp)->b_un.b_indir2[i])
1578fae3551SRodney W. Grimes 
158c3b2344bSScott Long #define IBLK_SET(bp, i, val) do { \
159c3b2344bSScott Long 	if (sblock.fs_magic == FS_UFS1_MAGIC) \
160c3b2344bSScott Long 		(bp)->b_un.b_indir1[i] = (val); \
161c3b2344bSScott Long 	else \
162c3b2344bSScott Long 		(bp)->b_un.b_indir2[i] = (val); \
163c3b2344bSScott Long 	} while (0)
164c3b2344bSScott Long 
1652ec5c914SKirk McKusick /*
1662ec5c914SKirk McKusick  * Buffer flags
1672ec5c914SKirk McKusick  */
1682ec5c914SKirk McKusick #define	B_INUSE 	0x00000001	/* Buffer is in use */
169ed75b5a1SKirk McKusick /*
170ed75b5a1SKirk McKusick  * Type of data in buffer
171ed75b5a1SKirk McKusick  */
172ed75b5a1SKirk McKusick #define	BT_UNKNOWN 	 0	/* Buffer holds a superblock */
173ed75b5a1SKirk McKusick #define	BT_SUPERBLK 	 1	/* Buffer holds a superblock */
174ed75b5a1SKirk McKusick #define	BT_CYLGRP 	 2	/* Buffer holds a cylinder group map */
175ed75b5a1SKirk McKusick #define	BT_LEVEL1 	 3	/* Buffer holds single level indirect */
176ed75b5a1SKirk McKusick #define	BT_LEVEL2 	 4	/* Buffer holds double level indirect */
177ed75b5a1SKirk McKusick #define	BT_LEVEL3 	 5	/* Buffer holds triple level indirect */
178ed75b5a1SKirk McKusick #define	BT_EXTATTR 	 6	/* Buffer holds external attribute data */
179ed75b5a1SKirk McKusick #define	BT_INODES 	 7	/* Buffer holds external attribute data */
180ed75b5a1SKirk McKusick #define	BT_DIRDATA 	 8	/* Buffer holds directory data */
181ed75b5a1SKirk McKusick #define	BT_DATA	 	 9	/* Buffer holds user data */
182ed75b5a1SKirk McKusick #define BT_NUMBUFTYPES	10
183ed75b5a1SKirk McKusick #define BT_NAMES {			\
184ed75b5a1SKirk McKusick 	"unknown",			\
185ed75b5a1SKirk McKusick 	"Superblock",			\
186ed75b5a1SKirk McKusick 	"Cylinder Group",		\
187ed75b5a1SKirk McKusick 	"Single Level Indirect",	\
188ed75b5a1SKirk McKusick 	"Double Level Indirect",	\
189ed75b5a1SKirk McKusick 	"Triple Level Indirect",	\
190ed75b5a1SKirk McKusick 	"External Attribute",		\
191ed75b5a1SKirk McKusick 	"Inode Block",			\
192ed75b5a1SKirk McKusick 	"Directory Contents",		\
193ed75b5a1SKirk McKusick 	"User Data" }
194ed75b5a1SKirk McKusick long readcnt[BT_NUMBUFTYPES];
195ed75b5a1SKirk McKusick long totalreadcnt[BT_NUMBUFTYPES];
196ed75b5a1SKirk McKusick struct timespec readtime[BT_NUMBUFTYPES];
197ed75b5a1SKirk McKusick struct timespec totalreadtime[BT_NUMBUFTYPES];
198ed75b5a1SKirk McKusick struct timespec startprog;
1998fae3551SRodney W. Grimes 
2008fae3551SRodney W. Grimes struct bufarea sblk;		/* file system superblock */
2018fae3551SRodney W. Grimes struct bufarea *pdirbp;		/* current directory contents */
2028fae3551SRodney W. Grimes struct bufarea *pbp;		/* current inode block */
2038fae3551SRodney W. Grimes 
204bf58d635SIan Dowse #define	dirty(bp) do { \
2057578c6abSKirk McKusick 	if (fswritefd < 0) \
2067578c6abSKirk McKusick 		pfatal("SETTING DIRTY FLAG IN READ_ONLY MODE\n"); \
2077578c6abSKirk McKusick 	else \
208bf58d635SIan Dowse 		(bp)->b_dirty = 1; \
209bf58d635SIan Dowse } while (0)
210ed75b5a1SKirk McKusick #define	initbarea(bp, type) do { \
2118fae3551SRodney W. Grimes 	(bp)->b_dirty = 0; \
2121c85e6a3SKirk McKusick 	(bp)->b_bno = (ufs2_daddr_t)-1; \
213bf58d635SIan Dowse 	(bp)->b_flags = 0; \
214ed75b5a1SKirk McKusick 	(bp)->b_type = type; \
215bf58d635SIan Dowse } while (0)
2168fae3551SRodney W. Grimes 
2177578c6abSKirk McKusick #define	sbdirty()	dirty(&sblk)
2188fae3551SRodney W. Grimes #define	sblock		(*sblk.b_un.b_fs)
2198fae3551SRodney W. Grimes 
2208fae3551SRodney W. Grimes enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
221142d8d2fSKirk McKusick ino_t cursnapshot;
2228fae3551SRodney W. Grimes 
2238fae3551SRodney W. Grimes struct inodesc {
2248fae3551SRodney W. Grimes 	enum fixstate id_fix;	/* policy on fixing errors */
225599304a4SPoul-Henning Kamp 	int (*id_func)(struct inodesc *);
226599304a4SPoul-Henning Kamp 				/* function to be applied to blocks of inode */
2278fae3551SRodney W. Grimes 	ino_t id_number;	/* inode number described */
2288fae3551SRodney W. Grimes 	ino_t id_parent;	/* for DATA nodes, their parent */
2291c85e6a3SKirk McKusick 	ufs_lbn_t id_lbn;	/* logical block number of current block */
2301c85e6a3SKirk McKusick 	ufs2_daddr_t id_blkno;	/* current block number being examined */
2318fae3551SRodney W. Grimes 	int id_numfrags;	/* number of frags contained in block */
2321c85e6a3SKirk McKusick 	off_t id_filesize;	/* for DATA nodes, the size of the directory */
2331c85e6a3SKirk McKusick 	ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */
2348fae3551SRodney W. Grimes 	int id_loc;		/* for DATA nodes, current location in dir */
2358fae3551SRodney W. Grimes 	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
2368fae3551SRodney W. Grimes 	char *id_name;		/* for DATA nodes, name to find or enter */
2378fae3551SRodney W. Grimes 	char id_type;		/* type of descriptor, DATA or ADDR */
2388fae3551SRodney W. Grimes };
2398fae3551SRodney W. Grimes /* file types */
240142d8d2fSKirk McKusick #define	DATA	1	/* a directory */
241142d8d2fSKirk McKusick #define	SNAP	2	/* a snapshot */
242142d8d2fSKirk McKusick #define	ADDR	3	/* anything but a directory or a snapshot */
2438fae3551SRodney W. Grimes 
2448fae3551SRodney W. Grimes /*
2458fae3551SRodney W. Grimes  * Linked list of duplicate blocks.
2468fae3551SRodney W. Grimes  *
2478fae3551SRodney W. Grimes  * The list is composed of two parts. The first part of the
2488fae3551SRodney W. Grimes  * list (from duplist through the node pointed to by muldup)
2498fae3551SRodney W. Grimes  * contains a single copy of each duplicate block that has been
2508fae3551SRodney W. Grimes  * found. The second part of the list (from muldup to the end)
2518fae3551SRodney W. Grimes  * contains duplicate blocks that have been found more than once.
2528fae3551SRodney W. Grimes  * To check if a block has been found as a duplicate it is only
2538fae3551SRodney W. Grimes  * necessary to search from duplist through muldup. To find the
2548fae3551SRodney W. Grimes  * total number of times that a block has been found as a duplicate
2554b85a12fSUlrich Spörlein  * the entire list must be searched for occurrences of the block
2568fae3551SRodney W. Grimes  * in question. The following diagram shows a sample list where
2578fae3551SRodney W. Grimes  * w (found twice), x (found once), y (found three times), and z
2588fae3551SRodney W. Grimes  * (found once) are duplicate block numbers:
2598fae3551SRodney W. Grimes  *
2608fae3551SRodney W. Grimes  *    w -> y -> x -> z -> y -> w -> y
2618fae3551SRodney W. Grimes  *    ^		     ^
2628fae3551SRodney W. Grimes  *    |		     |
2638fae3551SRodney W. Grimes  * duplist	  muldup
2648fae3551SRodney W. Grimes  */
2658fae3551SRodney W. Grimes struct dups {
2668fae3551SRodney W. Grimes 	struct dups *next;
2671c85e6a3SKirk McKusick 	ufs2_daddr_t dup;
2688fae3551SRodney W. Grimes };
2698fae3551SRodney W. Grimes struct dups *duplist;		/* head of dup list */
2708fae3551SRodney W. Grimes struct dups *muldup;		/* end of unique duplicate dup block numbers */
2718fae3551SRodney W. Grimes 
2728fae3551SRodney W. Grimes /*
2738fae3551SRodney W. Grimes  * Inode cache data structures.
2748fae3551SRodney W. Grimes  */
2758fae3551SRodney W. Grimes struct inoinfo {
2768fae3551SRodney W. Grimes 	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
2778fae3551SRodney W. Grimes 	ino_t	i_number;		/* inode number of this entry */
2788fae3551SRodney W. Grimes 	ino_t	i_parent;		/* inode number of parent */
2798fae3551SRodney W. Grimes 	ino_t	i_dotdot;		/* inode number of `..' */
2808fae3551SRodney W. Grimes 	size_t	i_isize;		/* size of inode */
2818fae3551SRodney W. Grimes 	u_int	i_numblks;		/* size of block array in bytes */
2821c85e6a3SKirk McKusick 	ufs2_daddr_t i_blks[1];		/* actually longer */
2838fae3551SRodney W. Grimes } **inphead, **inpsort;
284e50342e6SKirk McKusick long numdirs, dirhash, listmax, inplast;
285d33e92f9SJulian Elischer long countdirs;			/* number of directories we actually found */
2868fae3551SRodney W. Grimes 
2877578c6abSKirk McKusick #define MIBSIZE	3		/* size of fsck sysctl MIBs */
2887578c6abSKirk McKusick int	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
2897578c6abSKirk McKusick int	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
290a16baf37SXin LI int	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
291a16baf37SXin LI int	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
292a16baf37SXin LI int	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
293a16baf37SXin LI int	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
294a16baf37SXin LI int	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
2957578c6abSKirk McKusick int	freefiles[MIBSIZE];	/* MIB command to free a set of files */
2967578c6abSKirk McKusick int	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
2977578c6abSKirk McKusick int	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
2987578c6abSKirk McKusick struct	fsck_cmd cmd;		/* sysctl file system update commands */
2997578c6abSKirk McKusick char	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
3008fae3551SRodney W. Grimes char	*cdevname;		/* name of device being checked */
3018fae3551SRodney W. Grimes long	dev_bsize;		/* computed value of DEV_BSIZE */
3028fae3551SRodney W. Grimes long	secsize;		/* actual disk sector size */
3036f100596SKonstantin Belousov u_int	real_dev_bsize;		/* actual disk sector size, not overriden */
3048fae3551SRodney W. Grimes char	nflag;			/* assume a no response */
3058fae3551SRodney W. Grimes char	yflag;			/* assume a yes response */
3067578c6abSKirk McKusick int	bkgrdflag;		/* use a snapshot to run on an active system */
3078fae3551SRodney W. Grimes int	bflag;			/* location of alternate super block */
3088fae3551SRodney W. Grimes int	debug;			/* output debugging info */
3098d3dfc26SDag-Erling Smørgrav int	Eflag;			/* zero out empty data blocks */
310910b491eSKirk McKusick int	inoopt;			/* trim out unused inodes */
311111a5220SDavid E. O'Brien char	ckclean;		/* only do work if not cleanly unmounted */
3128fae3551SRodney W. Grimes int	cvtlevel;		/* convert to newer file system format */
31315fca934SKirk McKusick int	bkgrdcheck;		/* determine if background check is possible */
314c0ed8991SXin LI int	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
315b1897c19SJulian Elischer char	usedsoftdep;		/* just fix soft dependency inconsistencies */
3168fae3551SRodney W. Grimes char	preen;			/* just fix normal inconsistencies */
317d33e92f9SJulian Elischer char	rerun;			/* rerun fsck. Only used in non-preen mode */
318d33e92f9SJulian Elischer int	returntosingle;		/* 1 => return to single user mode on exit */
319d33e92f9SJulian Elischer char	resolved;		/* cleared if unresolved changes => not clean */
3208fae3551SRodney W. Grimes char	havesb;			/* superblock has been read */
3219ea6f4f0SAdrian Chadd char	skipclean;		/* skip clean file systems if preening */
3228fae3551SRodney W. Grimes int	fsmodified;		/* 1 => write done to file system */
3238fae3551SRodney W. Grimes int	fsreadfd;		/* file descriptor for reading file system */
3248fae3551SRodney W. Grimes int	fswritefd;		/* file descriptor for writing file system */
3258fae3551SRodney W. Grimes 
3261c85e6a3SKirk McKusick ufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
3278fae3551SRodney W. Grimes char	*blockmap;		/* ptr to primary blk allocation map */
3288fae3551SRodney W. Grimes ino_t	maxino;			/* number of inodes in file system */
3298fae3551SRodney W. Grimes 
3308fae3551SRodney W. Grimes ino_t	lfdir;			/* lost & found directory inode number */
331599304a4SPoul-Henning Kamp const char *lfname;		/* lost & found directory name */
3328fae3551SRodney W. Grimes int	lfmode;			/* lost & found directory creation mode */
3338fae3551SRodney W. Grimes 
3341c85e6a3SKirk McKusick ufs2_daddr_t n_blks;		/* number of blocks in use */
3351c85e6a3SKirk McKusick ino_t n_files;			/* number of files in use */
3368fae3551SRodney W. Grimes 
337fd02a3b5SUlf Lilleengen volatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
338fd02a3b5SUlf Lilleengen volatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
3396db798caSIan Dowse 
3401c85e6a3SKirk McKusick #define	clearinode(dp) \
3411c85e6a3SKirk McKusick 	if (sblock.fs_magic == FS_UFS1_MAGIC) { \
3421c85e6a3SKirk McKusick 		(dp)->dp1 = ufs1_zino; \
3431c85e6a3SKirk McKusick 	} else { \
3441c85e6a3SKirk McKusick 		(dp)->dp2 = ufs2_zino; \
3451c85e6a3SKirk McKusick 	}
3461c85e6a3SKirk McKusick struct	ufs1_dinode ufs1_zino;
3471c85e6a3SKirk McKusick struct	ufs2_dinode ufs2_zino;
3488fae3551SRodney W. Grimes 
3498fae3551SRodney W. Grimes #define	setbmap(blkno)	setbit(blockmap, blkno)
3508fae3551SRodney W. Grimes #define	testbmap(blkno)	isset(blockmap, blkno)
3518fae3551SRodney W. Grimes #define	clrbmap(blkno)	clrbit(blockmap, blkno)
3528fae3551SRodney W. Grimes 
3538fae3551SRodney W. Grimes #define	STOP	0x01
3548fae3551SRodney W. Grimes #define	SKIP	0x02
3558fae3551SRodney W. Grimes #define	KEEPON	0x04
3568fae3551SRodney W. Grimes #define	ALTERED	0x08
3578fae3551SRodney W. Grimes #define	FOUND	0x10
3588fae3551SRodney W. Grimes 
359780a5c1eSPeter Wemm #define	EEXIT	8		/* Standard error exit. */
360780a5c1eSPeter Wemm 
361*81fbded2SKirk McKusick int flushentry(void);
362*81fbded2SKirk McKusick /*
363*81fbded2SKirk McKusick  * Wrapper for malloc() that flushes the cylinder group cache to try
364*81fbded2SKirk McKusick  * to get space.
365*81fbded2SKirk McKusick  */
366*81fbded2SKirk McKusick static inline void*
367*81fbded2SKirk McKusick Malloc(int size)
368*81fbded2SKirk McKusick {
369*81fbded2SKirk McKusick 	void *retval;
370*81fbded2SKirk McKusick 
371*81fbded2SKirk McKusick 	while ((retval = malloc(size)) == NULL)
372*81fbded2SKirk McKusick 		if (flushentry() == 0)
373*81fbded2SKirk McKusick 			break;
374*81fbded2SKirk McKusick 	return (retval);
375*81fbded2SKirk McKusick }
376*81fbded2SKirk McKusick 
377*81fbded2SKirk McKusick /*
378*81fbded2SKirk McKusick  * Wrapper for calloc() that flushes the cylinder group cache to try
379*81fbded2SKirk McKusick  * to get space.
380*81fbded2SKirk McKusick  */
381*81fbded2SKirk McKusick static inline void*
382*81fbded2SKirk McKusick Calloc(int cnt, int size)
383*81fbded2SKirk McKusick {
384*81fbded2SKirk McKusick 	void *retval;
385*81fbded2SKirk McKusick 
386*81fbded2SKirk McKusick 	while ((retval = calloc(cnt, size)) == NULL)
387*81fbded2SKirk McKusick 		if (flushentry() == 0)
388*81fbded2SKirk McKusick 			break;
389*81fbded2SKirk McKusick 	return (retval);
390*81fbded2SKirk McKusick }
391*81fbded2SKirk McKusick 
392780a5c1eSPeter Wemm struct fstab;
393780a5c1eSPeter Wemm 
394d33e92f9SJulian Elischer 
395b70cd7eeSWarner Losh void		adjust(struct inodesc *, int lcnt);
3961c85e6a3SKirk McKusick ufs2_daddr_t	allocblk(long frags);
397b70cd7eeSWarner Losh ino_t		allocdir(ino_t parent, ino_t request, int mode);
398b70cd7eeSWarner Losh ino_t		allocino(ino_t request, int type);
399599304a4SPoul-Henning Kamp void		blkerror(ino_t ino, const char *type, ufs2_daddr_t blk);
400b70cd7eeSWarner Losh char	       *blockcheck(char *name);
401aef8d244SPawel Jakub Dawidek int		blread(int fd, char *buf, ufs2_daddr_t blk, long size);
402b70cd7eeSWarner Losh void		bufinit(void);
4034a835375SDavid E. O'Brien void		blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size);
4048d3dfc26SDag-Erling Smørgrav void		blerase(int fd, ufs2_daddr_t blk, long size);
4051c85e6a3SKirk McKusick void		cacheino(union dinode *dp, ino_t inumber);
406b70cd7eeSWarner Losh void		catch(int);
407b70cd7eeSWarner Losh void		catchquit(int);
408599304a4SPoul-Henning Kamp int		changeino(ino_t dir, const char *name, ino_t newnum);
409*81fbded2SKirk McKusick int		check_cgmagic(int cg, struct bufarea *cgbp);
4101c85e6a3SKirk McKusick int		chkrange(ufs2_daddr_t blk, int cnt);
411b70cd7eeSWarner Losh void		ckfini(int markclean);
4121c85e6a3SKirk McKusick int		ckinode(union dinode *dp, struct inodesc *);
413599304a4SPoul-Henning Kamp void		clri(struct inodesc *, const char *type, int flag);
414b70cd7eeSWarner Losh int		clearentry(struct inodesc *);
415599304a4SPoul-Henning Kamp void		direrror(ino_t ino, const char *errmesg);
416b70cd7eeSWarner Losh int		dirscan(struct inodesc *);
417599304a4SPoul-Henning Kamp int		dofix(struct inodesc *, const char *msg);
41851869213SPoul-Henning Kamp int		eascan(struct inodesc *, struct ufs2_dinode *dp);
419599304a4SPoul-Henning Kamp void		fileerror(ino_t cwd, ino_t ino, const char *errmesg);
420ed75b5a1SKirk McKusick void		finalIOstats(void);
421b70cd7eeSWarner Losh int		findino(struct inodesc *);
422b70cd7eeSWarner Losh int		findname(struct inodesc *);
423b70cd7eeSWarner Losh void		flush(int fd, struct bufarea *bp);
4241c85e6a3SKirk McKusick void		freeblk(ufs2_daddr_t blkno, long frags);
425b70cd7eeSWarner Losh void		freeino(ino_t ino);
426b70cd7eeSWarner Losh void		freeinodebuf(void);
4271c85e6a3SKirk McKusick int		ftypeok(union dinode *dp);
4281c85e6a3SKirk McKusick void		getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
429*81fbded2SKirk McKusick struct bufarea *cgget(int cg);
430ed75b5a1SKirk McKusick struct bufarea *getdatablk(ufs2_daddr_t blkno, long size, int type);
431b70cd7eeSWarner Losh struct inoinfo *getinoinfo(ino_t inumber);
432910b491eSKirk McKusick union dinode   *getnextinode(ino_t inumber, int rebuildcg);
433b70cd7eeSWarner Losh void		getpathname(char *namebuf, ino_t curdir, ino_t ino);
4341c85e6a3SKirk McKusick union dinode   *ginode(ino_t inumber);
435b70cd7eeSWarner Losh void		infohandler(int sig);
4361660ae87SScott Long void		alarmhandler(int sig);
437b70cd7eeSWarner Losh void		inocleanup(void);
438b70cd7eeSWarner Losh void		inodirty(void);
439b70cd7eeSWarner Losh struct inostat *inoinfo(ino_t inum);
440ed75b5a1SKirk McKusick void		IOstats(char *what);
441b70cd7eeSWarner Losh int		linkup(ino_t orphan, ino_t parentdir, char *name);
442599304a4SPoul-Henning Kamp int		makeentry(ino_t parent, ino_t ino, const char *name);
443b70cd7eeSWarner Losh void		panic(const char *fmt, ...) __printflike(1, 2);
444b70cd7eeSWarner Losh void		pass1(void);
445b70cd7eeSWarner Losh void		pass1b(void);
446b70cd7eeSWarner Losh int		pass1check(struct inodesc *);
447b70cd7eeSWarner Losh void		pass2(void);
448b70cd7eeSWarner Losh void		pass3(void);
449b70cd7eeSWarner Losh void		pass4(void);
450b70cd7eeSWarner Losh int		pass4check(struct inodesc *);
451b70cd7eeSWarner Losh void		pass5(void);
452b70cd7eeSWarner Losh void		pfatal(const char *fmt, ...) __printflike(1, 2);
453b70cd7eeSWarner Losh void		pinode(ino_t ino);
454b70cd7eeSWarner Losh void		propagate(void);
455b70cd7eeSWarner Losh void		pwarn(const char *fmt, ...) __printflike(1, 2);
456b70cd7eeSWarner Losh int		readsb(int listerr);
457599304a4SPoul-Henning Kamp int		reply(const char *question);
458599304a4SPoul-Henning Kamp void		rwerror(const char *mesg, ufs2_daddr_t blk);
459b70cd7eeSWarner Losh void		sblock_init(void);
460b70cd7eeSWarner Losh void		setinodebuf(ino_t);
461b70cd7eeSWarner Losh int		setup(char *dev);
462aef8d244SPawel Jakub Dawidek void		gjournal_check(const char *filesys);
463113db2ddSJeff Roberson int		suj_check(const char *filesys);
464d2404f04SKirk McKusick void		update_maps(struct cg *, struct cg*, int);
465d00690aeSPawel Jakub Dawidek 
466d00690aeSPawel Jakub Dawidek #endif	/* !_FSCK_H_ */
467