1331722Seadler/*
298542Smckusick * Copyright (c) 2002 Networks Associates Technology, Inc.
398542Smckusick * All rights reserved.
498542Smckusick *
598542Smckusick * This software was developed for the FreeBSD Project by Marshall
698542Smckusick * Kirk McKusick and Network Associates Laboratories, the Security
798542Smckusick * Research Division of Network Associates, Inc. under DARPA/SPAWAR
898542Smckusick * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
9110884Smckusick * research program.
1098542Smckusick *
11136721Srwatson * Redistribution and use in source and binary forms, with or without
12136721Srwatson * modification, are permitted provided that the following conditions
13136721Srwatson * are met:
14136721Srwatson * 1. Redistributions of source code must retain the above copyright
15136721Srwatson *    notice, this list of conditions and the following disclaimer.
16136721Srwatson * 2. Redistributions in binary form must reproduce the above copyright
17136721Srwatson *    notice, this list of conditions and the following disclaimer in the
18136721Srwatson *    documentation and/or other materials provided with the distribution.
19136721Srwatson *
20136721Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21136721Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22136721Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23136721Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24136721Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25136721Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26136721Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27136721Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28136721Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29136721Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30136721Srwatson * SUCH DAMAGE.
31136721Srwatson *
321558Srgrimes * Copyright (c) 1980, 1986, 1993
331558Srgrimes *	The Regents of the University of California.  All rights reserved.
341558Srgrimes *
351558Srgrimes * Redistribution and use in source and binary forms, with or without
361558Srgrimes * modification, are permitted provided that the following conditions
371558Srgrimes * are met:
381558Srgrimes * 1. Redistributions of source code must retain the above copyright
391558Srgrimes *    notice, this list of conditions and the following disclaimer.
401558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
411558Srgrimes *    notice, this list of conditions and the following disclaimer in the
421558Srgrimes *    documentation and/or other materials provided with the distribution.
431558Srgrimes * 4. Neither the name of the University nor the names of its contributors
441558Srgrimes *    may be used to endorse or promote products derived from this software
451558Srgrimes *    without specific prior written permission.
461558Srgrimes *
471558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
481558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
491558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
501558Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
511558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
521558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
531558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
541558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
551558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
561558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
571558Srgrimes * SUCH DAMAGE.
581558Srgrimes *
5923675Speter *	@(#)fsck.h	8.4 (Berkeley) 5/9/95
6055724Speter * $FreeBSD: stable/11/sbin/fsck_ffs/fsck.h 359754 2020-04-09 20:38:36Z kevans $
611558Srgrimes */
621558Srgrimes
63207143Spjd#ifndef _FSCK_H_
64207143Spjd#define	_FSCK_H_
65207143Spjd
6623675Speter#include <unistd.h>
6723675Speter#include <stdlib.h>
6823675Speter#include <stdio.h>
6923675Speter
70246812Smckusick#include <sys/queue.h>
71246812Smckusick
721558Srgrimes#define	MAXDUP		10	/* limit on dup blks (per inode) */
731558Srgrimes#define	MAXBAD		10	/* limit on bad blks (per inode) */
74246812Smckusick#define	MINBUFS		10	/* minimum number of buffers required */
75246812Smckusick#define	MAXBUFS		40	/* maximum space to allocate to buffers */
76246812Smckusick#define	INOBUFSIZE	64*1024	/* size of buffer to read inodes in pass1 */
77250056Sdes#define	ZEROBUFSIZE	(dev_bsize * 128) /* size of zero buffer used by -Z */
781558Srgrimes
7998542Smckusickunion dinode {
8098542Smckusick	struct ufs1_dinode dp1;
8198542Smckusick	struct ufs2_dinode dp2;
8298542Smckusick};
8398542Smckusick#define	DIP(dp, field) \
8498542Smckusick	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
8598542Smckusick	(dp)->dp1.field : (dp)->dp2.field)
8698542Smckusick
87134589Sscottl#define DIP_SET(dp, field, val) do { \
88134589Sscottl	if (sblock.fs_magic == FS_UFS1_MAGIC) \
89134589Sscottl		(dp)->dp1.field = (val); \
90134589Sscottl	else \
91134589Sscottl		(dp)->dp2.field = (val); \
92134589Sscottl	} while (0)
93134589Sscottl
9441474Sjulian/*
95102231Strhodes * Each inode on the file system is described by the following structure.
9641474Sjulian * The linkcnt is initially set to the value in the inode. Each time it
9741474Sjulian * is found during the descent in passes 2, 3, and 4 the count is
9841474Sjulian * decremented. Any inodes whose count is non-zero after pass 4 needs to
9941474Sjulian * have its link count adjusted by the value remaining in ino_linkcnt.
10041474Sjulian */
10141474Sjulianstruct inostat {
10241474Sjulian	char	ino_state;	/* state of inode, see below */
10341474Sjulian	char	ino_type;	/* type of inode */
10441474Sjulian	short	ino_linkcnt;	/* number of links not found */
10541474Sjulian};
10641474Sjulian/*
10741474Sjulian * Inode states.
10841474Sjulian */
109136281Struckman#define	USTATE	0x1		/* inode not allocated */
110136281Struckman#define	FSTATE	0x2		/* inode is file */
111136281Struckman#define	FZLINK	0x3		/* inode is file with a link count of zero */
112136281Struckman#define	DSTATE	0x4		/* inode is directory */
113136281Struckman#define	DZLINK	0x5		/* inode is directory with a zero link count  */
114136281Struckman#define	DFOUND	0x6		/* directory found during descent */
115136281Struckman/*     		0x7		   UNUSED - see S_IS_DVALID() definition */
116136281Struckman#define	DCLEAR	0x8		/* directory is to be cleared */
117136281Struckman#define	FCLEAR	0x9		/* file is to be cleared */
118136281Struckman/*     	DUNFOUND === (state == DSTATE || state == DZLINK) */
119136281Struckman#define	S_IS_DUNFOUND(state)	(((state) & ~0x1) == DSTATE)
120136281Struckman/*     	DVALID   === (state == DSTATE || state == DZLINK || state == DFOUND) */
121136281Struckman#define	S_IS_DVALID(state)	(((state) & ~0x3) == DSTATE)
122136281Struckman#define	INO_IS_DUNFOUND(ino)	S_IS_DUNFOUND(inoinfo(ino)->ino_state)
123136281Struckman#define	INO_IS_DVALID(ino)	S_IS_DVALID(inoinfo(ino)->ino_state)
12441474Sjulian/*
12541474Sjulian * Inode state information is contained on per cylinder group lists
12641474Sjulian * which are described by the following structure.
12741474Sjulian */
128359754Skevansextern struct inostatlist {
12941474Sjulian	long	il_numalloced;	/* number of inodes allocated in this cg */
13041474Sjulian	struct inostat *il_stat;/* inostat info for this cylinder group */
13141474Sjulian} *inostathead;
1321558Srgrimes
1331558Srgrimes/*
1341558Srgrimes * buffer cache structure.
1351558Srgrimes */
1361558Srgrimesstruct bufarea {
137246812Smckusick	TAILQ_ENTRY(bufarea) b_list;		/* buffer list */
13898542Smckusick	ufs2_daddr_t b_bno;
13923675Speter	int b_size;
14023675Speter	int b_errs;
14123675Speter	int b_flags;
142247212Smckusick	int b_type;
1431558Srgrimes	union {
14423675Speter		char *b_buf;			/* buffer space */
14598542Smckusick		ufs1_daddr_t *b_indir1;		/* UFS1 indirect block */
14698542Smckusick		ufs2_daddr_t *b_indir2;		/* UFS2 indirect block */
14723675Speter		struct fs *b_fs;		/* super block */
14823675Speter		struct cg *b_cg;		/* cylinder group */
14998542Smckusick		struct ufs1_dinode *b_dinode1;	/* UFS1 inode block */
15098542Smckusick		struct ufs2_dinode *b_dinode2;	/* UFS2 inode block */
1511558Srgrimes	} b_un;
15223675Speter	char b_dirty;
1531558Srgrimes};
154134589Sscottl
15598542Smckusick#define	IBLK(bp, i) \
15698542Smckusick	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
15798542Smckusick	(bp)->b_un.b_indir1[i] : (bp)->b_un.b_indir2[i])
1581558Srgrimes
159134589Sscottl#define IBLK_SET(bp, i, val) do { \
160134589Sscottl	if (sblock.fs_magic == FS_UFS1_MAGIC) \
161134589Sscottl		(bp)->b_un.b_indir1[i] = (val); \
162134589Sscottl	else \
163134589Sscottl		(bp)->b_un.b_indir2[i] = (val); \
164134589Sscottl	} while (0)
165134589Sscottl
166246812Smckusick/*
167246812Smckusick * Buffer flags
168246812Smckusick */
169246812Smckusick#define	B_INUSE 	0x00000001	/* Buffer is in use */
170247212Smckusick/*
171247212Smckusick * Type of data in buffer
172247212Smckusick */
173247212Smckusick#define	BT_UNKNOWN 	 0	/* Buffer holds a superblock */
174247212Smckusick#define	BT_SUPERBLK 	 1	/* Buffer holds a superblock */
175247212Smckusick#define	BT_CYLGRP 	 2	/* Buffer holds a cylinder group map */
176247212Smckusick#define	BT_LEVEL1 	 3	/* Buffer holds single level indirect */
177247212Smckusick#define	BT_LEVEL2 	 4	/* Buffer holds double level indirect */
178247212Smckusick#define	BT_LEVEL3 	 5	/* Buffer holds triple level indirect */
179247212Smckusick#define	BT_EXTATTR 	 6	/* Buffer holds external attribute data */
180247212Smckusick#define	BT_INODES 	 7	/* Buffer holds external attribute data */
181247212Smckusick#define	BT_DIRDATA 	 8	/* Buffer holds directory data */
182247212Smckusick#define	BT_DATA	 	 9	/* Buffer holds user data */
183247212Smckusick#define BT_NUMBUFTYPES	10
184247212Smckusick#define BT_NAMES {			\
185247212Smckusick	"unknown",			\
186247212Smckusick	"Superblock",			\
187247212Smckusick	"Cylinder Group",		\
188247212Smckusick	"Single Level Indirect",	\
189247212Smckusick	"Double Level Indirect",	\
190247212Smckusick	"Triple Level Indirect",	\
191247212Smckusick	"External Attribute",		\
192247212Smckusick	"Inode Block",			\
193247212Smckusick	"Directory Contents",		\
194247212Smckusick	"User Data" }
195260068Sscottlextern long readcnt[BT_NUMBUFTYPES];
196260068Sscottlextern long totalreadcnt[BT_NUMBUFTYPES];
197260068Sscottlextern struct timespec readtime[BT_NUMBUFTYPES];
198260068Sscottlextern struct timespec totalreadtime[BT_NUMBUFTYPES];
199260068Sscottlextern struct timespec startprog;
2001558Srgrimes
201260068Sscottlextern struct bufarea sblk;		/* file system superblock */
202260068Sscottlextern struct bufarea *pdirbp;		/* current directory contents */
203260068Sscottlextern struct bufarea *pbp;		/* current inode block */
2041558Srgrimes
20586514Siedowse#define	dirty(bp) do { \
20674556Smckusick	if (fswritefd < 0) \
20774556Smckusick		pfatal("SETTING DIRTY FLAG IN READ_ONLY MODE\n"); \
20874556Smckusick	else \
20986514Siedowse		(bp)->b_dirty = 1; \
21086514Siedowse} while (0)
211247212Smckusick#define	initbarea(bp, type) do { \
2121558Srgrimes	(bp)->b_dirty = 0; \
21398542Smckusick	(bp)->b_bno = (ufs2_daddr_t)-1; \
21486514Siedowse	(bp)->b_flags = 0; \
215247212Smckusick	(bp)->b_type = type; \
21686514Siedowse} while (0)
2171558Srgrimes
21874556Smckusick#define	sbdirty()	dirty(&sblk)
2191558Srgrimes#define	sblock		(*sblk.b_un.b_fs)
2201558Srgrimes
2211558Srgrimesenum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
222260068Sscottlextern ino_t cursnapshot;
2231558Srgrimes
2241558Srgrimesstruct inodesc {
2251558Srgrimes	enum fixstate id_fix;	/* policy on fixing errors */
226100935Sphk	int (*id_func)(struct inodesc *);
227100935Sphk				/* function to be applied to blocks of inode */
2281558Srgrimes	ino_t id_number;	/* inode number described */
2291558Srgrimes	ino_t id_parent;	/* for DATA nodes, their parent */
23098542Smckusick	ufs_lbn_t id_lbn;	/* logical block number of current block */
23198542Smckusick	ufs2_daddr_t id_blkno;	/* current block number being examined */
232347200Smckusick	int id_level;		/* level of indirection of this block */
2331558Srgrimes	int id_numfrags;	/* number of frags contained in block */
234344861Smckusick	ufs_lbn_t id_lballoc;	/* pass1: last LBN that is allocated */
23598542Smckusick	off_t id_filesize;	/* for DATA nodes, the size of the directory */
23698542Smckusick	ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */
2371558Srgrimes	int id_loc;		/* for DATA nodes, current location in dir */
2381558Srgrimes	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
2391558Srgrimes	char *id_name;		/* for DATA nodes, name to find or enter */
2401558Srgrimes	char id_type;		/* type of descriptor, DATA or ADDR */
2411558Srgrimes};
2421558Srgrimes/* file types */
24362668Smckusick#define	DATA	1	/* a directory */
24462668Smckusick#define	SNAP	2	/* a snapshot */
24562668Smckusick#define	ADDR	3	/* anything but a directory or a snapshot */
2461558Srgrimes
2471558Srgrimes/*
2481558Srgrimes * Linked list of duplicate blocks.
2498871Srgrimes *
2501558Srgrimes * The list is composed of two parts. The first part of the
2511558Srgrimes * list (from duplist through the node pointed to by muldup)
2528871Srgrimes * contains a single copy of each duplicate block that has been
2531558Srgrimes * found. The second part of the list (from muldup to the end)
2541558Srgrimes * contains duplicate blocks that have been found more than once.
2551558Srgrimes * To check if a block has been found as a duplicate it is only
2568871Srgrimes * necessary to search from duplist through muldup. To find the
2571558Srgrimes * total number of times that a block has been found as a duplicate
258229778Suqs * the entire list must be searched for occurrences of the block
2591558Srgrimes * in question. The following diagram shows a sample list where
2601558Srgrimes * w (found twice), x (found once), y (found three times), and z
2611558Srgrimes * (found once) are duplicate block numbers:
2621558Srgrimes *
2631558Srgrimes *    w -> y -> x -> z -> y -> w -> y
2641558Srgrimes *    ^		     ^
2651558Srgrimes *    |		     |
2661558Srgrimes * duplist	  muldup
2671558Srgrimes */
2681558Srgrimesstruct dups {
2691558Srgrimes	struct dups *next;
27098542Smckusick	ufs2_daddr_t dup;
2711558Srgrimes};
272359754Skevansextern struct dups *duplist;		/* head of dup list */
273359754Skevansextern struct dups *muldup;		/* end of unique duplicate dup block numbers */
2741558Srgrimes
2751558Srgrimes/*
2761558Srgrimes * Inode cache data structures.
2771558Srgrimes */
278359754Skevansextern struct inoinfo {
2791558Srgrimes	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
2801558Srgrimes	ino_t	i_number;		/* inode number of this entry */
2811558Srgrimes	ino_t	i_parent;		/* inode number of parent */
2821558Srgrimes	ino_t	i_dotdot;		/* inode number of `..' */
2831558Srgrimes	size_t	i_isize;		/* size of inode */
2841558Srgrimes	u_int	i_numblks;		/* size of block array in bytes */
28598542Smckusick	ufs2_daddr_t i_blks[1];		/* actually longer */
2861558Srgrimes} **inphead, **inpsort;
287317860Spfgextern long dirhash, inplast;
288317860Spfgextern unsigned long numdirs, listmax;
289260068Sscottlextern long countdirs;		/* number of directories we actually found */
2901558Srgrimes
29174556Smckusick#define MIBSIZE	3		/* size of fsck sysctl MIBs */
292260068Sscottlextern int	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
293260068Sscottlextern int	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
294344861Smckusickextern int	setsize[MIBSIZE];	/* MIB command to set inode size */
295260068Sscottlextern int	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
296260068Sscottlextern int	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
297260068Sscottlextern int	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
298260068Sscottlextern int	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
299260068Sscottlextern int	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
300260068Sscottlextern int	freefiles[MIBSIZE];	/* MIB command to free a set of files */
301260068Sscottlextern int	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
302260068Sscottlextern int	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
303260068Sscottlextern struct	fsck_cmd cmd;		/* sysctl file system update commands */
304260068Sscottlextern char	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
305260068Sscottlextern char	*cdevname;		/* name of device being checked */
306260068Sscottlextern long	dev_bsize;		/* computed value of DEV_BSIZE */
307260068Sscottlextern long	secsize;		/* actual disk sector size */
308289677Seadlerextern u_int	real_dev_bsize;		/* actual disk sector size, not overridden */
309260068Sscottlextern char	nflag;			/* assume a no response */
310260068Sscottlextern char	yflag;			/* assume a yes response */
311260068Sscottlextern int	bkgrdflag;		/* use a snapshot to run on an active system */
312307535Smckusickextern ufs2_daddr_t bflag;		/* location of alternate super block */
313260068Sscottlextern int	debug;			/* output debugging info */
314260068Sscottlextern int	Eflag;			/* delete empty data blocks */
315260068Sscottlextern int	Zflag;			/* zero empty data blocks */
316347475Smckusickextern int	zflag;			/* zero unused directory space */
317260068Sscottlextern int	inoopt;			/* trim out unused inodes */
318260068Sscottlextern char	ckclean;		/* only do work if not cleanly unmounted */
319260068Sscottlextern int	cvtlevel;		/* convert to newer file system format */
320260068Sscottlextern int	bkgrdcheck;		/* determine if background check is possible */
321260068Sscottlextern int	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
322260068Sscottlextern char	usedsoftdep;		/* just fix soft dependency inconsistencies */
323260068Sscottlextern char	preen;			/* just fix normal inconsistencies */
324260068Sscottlextern char	rerun;			/* rerun fsck. Only used in non-preen mode */
325260068Sscottlextern int	returntosingle;		/* 1 => return to single user mode on exit */
326260068Sscottlextern char	resolved;		/* cleared if unresolved changes => not clean */
327260068Sscottlextern char	havesb;			/* superblock has been read */
328260068Sscottlextern char	skipclean;		/* skip clean file systems if preening */
329260068Sscottlextern int	fsmodified;		/* 1 => write done to file system */
330260068Sscottlextern int	fsreadfd;		/* file descriptor for reading file system */
331260068Sscottlextern int	fswritefd;		/* file descriptor for writing file system */
332260068Sscottlextern int	surrender;		/* Give up if reads fail */
333260068Sscottlextern int	wantrestart;		/* Restart fsck on early termination */
3341558Srgrimes
335260068Sscottlextern ufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
336260068Sscottlextern char	*blockmap;		/* ptr to primary blk allocation map */
337260068Sscottlextern ino_t	maxino;			/* number of inodes in file system */
3381558Srgrimes
339260068Sscottlextern ino_t	lfdir;			/* lost & found directory inode number */
340260068Sscottlextern const char *lfname;		/* lost & found directory name */
341260068Sscottlextern int	lfmode;			/* lost & found directory creation mode */
3421558Srgrimes
343260068Sscottlextern ufs2_daddr_t n_blks;		/* number of blocks in use */
344260068Sscottlextern ino_t n_files;			/* number of files in use */
3451558Srgrimes
346260068Sscottlextern volatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
347260068Sscottlextern volatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
34870050Siedowse
34998542Smckusick#define	clearinode(dp) \
35098542Smckusick	if (sblock.fs_magic == FS_UFS1_MAGIC) { \
35198542Smckusick		(dp)->dp1 = ufs1_zino; \
35298542Smckusick	} else { \
35398542Smckusick		(dp)->dp2 = ufs2_zino; \
35498542Smckusick	}
355260068Sscottlextern struct	ufs1_dinode ufs1_zino;
356260068Sscottlextern struct	ufs2_dinode ufs2_zino;
3571558Srgrimes
3581558Srgrimes#define	setbmap(blkno)	setbit(blockmap, blkno)
3591558Srgrimes#define	testbmap(blkno)	isset(blockmap, blkno)
3601558Srgrimes#define	clrbmap(blkno)	clrbit(blockmap, blkno)
3611558Srgrimes
3621558Srgrimes#define	STOP	0x01
3631558Srgrimes#define	SKIP	0x02
3641558Srgrimes#define	KEEPON	0x04
3651558Srgrimes#define	ALTERED	0x08
3661558Srgrimes#define	FOUND	0x10
3671558Srgrimes
36823675Speter#define	EEXIT	8		/* Standard error exit. */
369328604Sdab#define	ERERUN	16		/* fsck needs to be re-run. */
370260068Sscottl#define	ERESTART -1
3717585Sbde
372248658Smckusickint flushentry(void);
373248658Smckusick/*
374248658Smckusick * Wrapper for malloc() that flushes the cylinder group cache to try
375248658Smckusick * to get space.
376248658Smckusick */
377248658Smckusickstatic inline void*
378262488SmckusickMalloc(size_t size)
379248658Smckusick{
380248658Smckusick	void *retval;
381248658Smckusick
382248658Smckusick	while ((retval = malloc(size)) == NULL)
383248658Smckusick		if (flushentry() == 0)
384248658Smckusick			break;
385248658Smckusick	return (retval);
386248658Smckusick}
387248658Smckusick
388248658Smckusick/*
389248658Smckusick * Wrapper for calloc() that flushes the cylinder group cache to try
390248658Smckusick * to get space.
391248658Smckusick */
392248658Smckusickstatic inline void*
393262488SmckusickCalloc(size_t cnt, size_t size)
394248658Smckusick{
395248658Smckusick	void *retval;
396248658Smckusick
397248658Smckusick	while ((retval = calloc(cnt, size)) == NULL)
398248658Smckusick		if (flushentry() == 0)
399248658Smckusick			break;
400248658Smckusick	return (retval);
401248658Smckusick}
402248658Smckusick
40323675Speterstruct fstab;
4047585Sbde
40541474Sjulian
40692839Simpvoid		adjust(struct inodesc *, int lcnt);
40798542Smckusickufs2_daddr_t	allocblk(long frags);
40892839Simpino_t		allocdir(ino_t parent, ino_t request, int mode);
40992839Simpino_t		allocino(ino_t request, int type);
410100935Sphkvoid		blkerror(ino_t ino, const char *type, ufs2_daddr_t blk);
41192839Simpchar	       *blockcheck(char *name);
412163845Spjdint		blread(int fd, char *buf, ufs2_daddr_t blk, long size);
41392839Simpvoid		bufinit(void);
414240406Sobrienvoid		blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size);
415221233Sdesvoid		blerase(int fd, ufs2_daddr_t blk, long size);
416250056Sdesvoid		blzero(int fd, ufs2_daddr_t blk, long size);
41798542Smckusickvoid		cacheino(union dinode *dp, ino_t inumber);
41892839Simpvoid		catch(int);
41992839Simpvoid		catchquit(int);
420100935Sphkint		changeino(ino_t dir, const char *name, ino_t newnum);
421248658Smckusickint		check_cgmagic(int cg, struct bufarea *cgbp);
42298542Smckusickint		chkrange(ufs2_daddr_t blk, int cnt);
42392839Simpvoid		ckfini(int markclean);
42498542Smckusickint		ckinode(union dinode *dp, struct inodesc *);
425100935Sphkvoid		clri(struct inodesc *, const char *type, int flag);
42692839Simpint		clearentry(struct inodesc *);
427100935Sphkvoid		direrror(ino_t ino, const char *errmesg);
42892839Simpint		dirscan(struct inodesc *);
429100935Sphkint		dofix(struct inodesc *, const char *msg);
430103398Sphkint		eascan(struct inodesc *, struct ufs2_dinode *dp);
431100935Sphkvoid		fileerror(ino_t cwd, ino_t ino, const char *errmesg);
432247212Smckusickvoid		finalIOstats(void);
43392839Simpint		findino(struct inodesc *);
43492839Simpint		findname(struct inodesc *);
43592839Simpvoid		flush(int fd, struct bufarea *bp);
43698542Smckusickvoid		freeblk(ufs2_daddr_t blkno, long frags);
43792839Simpvoid		freeino(ino_t ino);
43892839Simpvoid		freeinodebuf(void);
439260068Sscottlvoid		fsutilinit(void);
44098542Smckusickint		ftypeok(union dinode *dp);
44198542Smckusickvoid		getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
442248658Smckusickstruct bufarea *cgget(int cg);
443247212Smckusickstruct bufarea *getdatablk(ufs2_daddr_t blkno, long size, int type);
44492839Simpstruct inoinfo *getinoinfo(ino_t inumber);
445188110Smckusickunion dinode   *getnextinode(ino_t inumber, int rebuildcg);
44692839Simpvoid		getpathname(char *namebuf, ino_t curdir, ino_t ino);
44798542Smckusickunion dinode   *ginode(ino_t inumber);
44892839Simpvoid		infohandler(int sig);
449126345Sscottlvoid		alarmhandler(int sig);
45092839Simpvoid		inocleanup(void);
451344887Skibvoid		inodirty(union dinode *);
45292839Simpstruct inostat *inoinfo(ino_t inum);
453247212Smckusickvoid		IOstats(char *what);
45492839Simpint		linkup(ino_t orphan, ino_t parentdir, char *name);
455100935Sphkint		makeentry(ino_t parent, ino_t ino, const char *name);
45692839Simpvoid		panic(const char *fmt, ...) __printflike(1, 2);
45792839Simpvoid		pass1(void);
45892839Simpvoid		pass1b(void);
45992839Simpint		pass1check(struct inodesc *);
46092839Simpvoid		pass2(void);
46192839Simpvoid		pass3(void);
46292839Simpvoid		pass4(void);
46392839Simpint		pass4check(struct inodesc *);
46492839Simpvoid		pass5(void);
46592839Simpvoid		pfatal(const char *fmt, ...) __printflike(1, 2);
46692839Simpvoid		pinode(ino_t ino);
46792839Simpvoid		propagate(void);
46892839Simpvoid		pwarn(const char *fmt, ...) __printflike(1, 2);
46992839Simpint		readsb(int listerr);
470100935Sphkint		reply(const char *question);
471100935Sphkvoid		rwerror(const char *mesg, ufs2_daddr_t blk);
47292839Simpvoid		sblock_init(void);
47392839Simpvoid		setinodebuf(ino_t);
47492839Simpint		setup(char *dev);
475163845Spjdvoid		gjournal_check(const char *filesys);
476207141Sjeffint		suj_check(const char *filesys);
477224059Smckusickvoid		update_maps(struct cg *, struct cg*, int);
478260068Sscottlvoid		fsckinit(void);
479207143Spjd
480207143Spjd#endif	/* !_FSCK_H_ */
481