fsck.h revision 248658
11558Srgrimes/*
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: head/sbin/fsck_ffs/fsck.h 248658 2013-03-23 20:00:02Z mckusick $
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 */
771558Srgrimes
7898542Smckusickunion dinode {
7998542Smckusick	struct ufs1_dinode dp1;
8098542Smckusick	struct ufs2_dinode dp2;
8198542Smckusick};
8298542Smckusick#define	DIP(dp, field) \
8398542Smckusick	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
8498542Smckusick	(dp)->dp1.field : (dp)->dp2.field)
8598542Smckusick
86134589Sscottl#define DIP_SET(dp, field, val) do { \
87134589Sscottl	if (sblock.fs_magic == FS_UFS1_MAGIC) \
88134589Sscottl		(dp)->dp1.field = (val); \
89134589Sscottl	else \
90134589Sscottl		(dp)->dp2.field = (val); \
91134589Sscottl	} while (0)
92134589Sscottl
9341474Sjulian/*
94102231Strhodes * Each inode on the file system is described by the following structure.
9541474Sjulian * The linkcnt is initially set to the value in the inode. Each time it
9641474Sjulian * is found during the descent in passes 2, 3, and 4 the count is
9741474Sjulian * decremented. Any inodes whose count is non-zero after pass 4 needs to
9841474Sjulian * have its link count adjusted by the value remaining in ino_linkcnt.
9941474Sjulian */
10041474Sjulianstruct inostat {
10141474Sjulian	char	ino_state;	/* state of inode, see below */
10241474Sjulian	char	ino_type;	/* type of inode */
10341474Sjulian	short	ino_linkcnt;	/* number of links not found */
10441474Sjulian};
10541474Sjulian/*
10641474Sjulian * Inode states.
10741474Sjulian */
108136281Struckman#define	USTATE	0x1		/* inode not allocated */
109136281Struckman#define	FSTATE	0x2		/* inode is file */
110136281Struckman#define	FZLINK	0x3		/* inode is file with a link count of zero */
111136281Struckman#define	DSTATE	0x4		/* inode is directory */
112136281Struckman#define	DZLINK	0x5		/* inode is directory with a zero link count  */
113136281Struckman#define	DFOUND	0x6		/* directory found during descent */
114136281Struckman/*     		0x7		   UNUSED - see S_IS_DVALID() definition */
115136281Struckman#define	DCLEAR	0x8		/* directory is to be cleared */
116136281Struckman#define	FCLEAR	0x9		/* file is to be cleared */
117136281Struckman/*     	DUNFOUND === (state == DSTATE || state == DZLINK) */
118136281Struckman#define	S_IS_DUNFOUND(state)	(((state) & ~0x1) == DSTATE)
119136281Struckman/*     	DVALID   === (state == DSTATE || state == DZLINK || state == DFOUND) */
120136281Struckman#define	S_IS_DVALID(state)	(((state) & ~0x3) == DSTATE)
121136281Struckman#define	INO_IS_DUNFOUND(ino)	S_IS_DUNFOUND(inoinfo(ino)->ino_state)
122136281Struckman#define	INO_IS_DVALID(ino)	S_IS_DVALID(inoinfo(ino)->ino_state)
12341474Sjulian/*
12441474Sjulian * Inode state information is contained on per cylinder group lists
12541474Sjulian * which are described by the following structure.
12641474Sjulian */
12741474Sjulianstruct inostatlist {
12841474Sjulian	long	il_numalloced;	/* number of inodes allocated in this cg */
12941474Sjulian	struct inostat *il_stat;/* inostat info for this cylinder group */
13041474Sjulian} *inostathead;
1311558Srgrimes
1321558Srgrimes/*
1331558Srgrimes * buffer cache structure.
1341558Srgrimes */
1351558Srgrimesstruct bufarea {
136246812Smckusick	TAILQ_ENTRY(bufarea) b_list;		/* buffer list */
13798542Smckusick	ufs2_daddr_t b_bno;
13823675Speter	int b_size;
13923675Speter	int b_errs;
14023675Speter	int b_flags;
141247212Smckusick	int b_type;
1421558Srgrimes	union {
14323675Speter		char *b_buf;			/* buffer space */
14498542Smckusick		ufs1_daddr_t *b_indir1;		/* UFS1 indirect block */
14598542Smckusick		ufs2_daddr_t *b_indir2;		/* UFS2 indirect block */
14623675Speter		struct fs *b_fs;		/* super block */
14723675Speter		struct cg *b_cg;		/* cylinder group */
14898542Smckusick		struct ufs1_dinode *b_dinode1;	/* UFS1 inode block */
14998542Smckusick		struct ufs2_dinode *b_dinode2;	/* UFS2 inode block */
1501558Srgrimes	} b_un;
15123675Speter	char b_dirty;
1521558Srgrimes};
153134589Sscottl
15498542Smckusick#define	IBLK(bp, i) \
15598542Smckusick	((sblock.fs_magic == FS_UFS1_MAGIC) ? \
15698542Smckusick	(bp)->b_un.b_indir1[i] : (bp)->b_un.b_indir2[i])
1571558Srgrimes
158134589Sscottl#define IBLK_SET(bp, i, val) do { \
159134589Sscottl	if (sblock.fs_magic == FS_UFS1_MAGIC) \
160134589Sscottl		(bp)->b_un.b_indir1[i] = (val); \
161134589Sscottl	else \
162134589Sscottl		(bp)->b_un.b_indir2[i] = (val); \
163134589Sscottl	} while (0)
164134589Sscottl
165246812Smckusick/*
166246812Smckusick * Buffer flags
167246812Smckusick */
168246812Smckusick#define	B_INUSE 	0x00000001	/* Buffer is in use */
169247212Smckusick/*
170247212Smckusick * Type of data in buffer
171247212Smckusick */
172247212Smckusick#define	BT_UNKNOWN 	 0	/* Buffer holds a superblock */
173247212Smckusick#define	BT_SUPERBLK 	 1	/* Buffer holds a superblock */
174247212Smckusick#define	BT_CYLGRP 	 2	/* Buffer holds a cylinder group map */
175247212Smckusick#define	BT_LEVEL1 	 3	/* Buffer holds single level indirect */
176247212Smckusick#define	BT_LEVEL2 	 4	/* Buffer holds double level indirect */
177247212Smckusick#define	BT_LEVEL3 	 5	/* Buffer holds triple level indirect */
178247212Smckusick#define	BT_EXTATTR 	 6	/* Buffer holds external attribute data */
179247212Smckusick#define	BT_INODES 	 7	/* Buffer holds external attribute data */
180247212Smckusick#define	BT_DIRDATA 	 8	/* Buffer holds directory data */
181247212Smckusick#define	BT_DATA	 	 9	/* Buffer holds user data */
182247212Smckusick#define BT_NUMBUFTYPES	10
183247212Smckusick#define BT_NAMES {			\
184247212Smckusick	"unknown",			\
185247212Smckusick	"Superblock",			\
186247212Smckusick	"Cylinder Group",		\
187247212Smckusick	"Single Level Indirect",	\
188247212Smckusick	"Double Level Indirect",	\
189247212Smckusick	"Triple Level Indirect",	\
190247212Smckusick	"External Attribute",		\
191247212Smckusick	"Inode Block",			\
192247212Smckusick	"Directory Contents",		\
193247212Smckusick	"User Data" }
194247212Smckusicklong readcnt[BT_NUMBUFTYPES];
195247212Smckusicklong totalreadcnt[BT_NUMBUFTYPES];
196247212Smckusickstruct timespec readtime[BT_NUMBUFTYPES];
197247212Smckusickstruct timespec totalreadtime[BT_NUMBUFTYPES];
198247212Smckusickstruct timespec startprog;
1991558Srgrimes
200102231Strhodesstruct bufarea sblk;		/* file system superblock */
2011558Srgrimesstruct bufarea *pdirbp;		/* current directory contents */
2021558Srgrimesstruct bufarea *pbp;		/* current inode block */
2031558Srgrimes
20486514Siedowse#define	dirty(bp) do { \
20574556Smckusick	if (fswritefd < 0) \
20674556Smckusick		pfatal("SETTING DIRTY FLAG IN READ_ONLY MODE\n"); \
20774556Smckusick	else \
20886514Siedowse		(bp)->b_dirty = 1; \
20986514Siedowse} while (0)
210247212Smckusick#define	initbarea(bp, type) do { \
2111558Srgrimes	(bp)->b_dirty = 0; \
21298542Smckusick	(bp)->b_bno = (ufs2_daddr_t)-1; \
21386514Siedowse	(bp)->b_flags = 0; \
214247212Smckusick	(bp)->b_type = type; \
21586514Siedowse} while (0)
2161558Srgrimes
21774556Smckusick#define	sbdirty()	dirty(&sblk)
2181558Srgrimes#define	sblock		(*sblk.b_un.b_fs)
2191558Srgrimes
2201558Srgrimesenum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
22162668Smckusickino_t cursnapshot;
2221558Srgrimes
2231558Srgrimesstruct inodesc {
2241558Srgrimes	enum fixstate id_fix;	/* policy on fixing errors */
225100935Sphk	int (*id_func)(struct inodesc *);
226100935Sphk				/* function to be applied to blocks of inode */
2271558Srgrimes	ino_t id_number;	/* inode number described */
2281558Srgrimes	ino_t id_parent;	/* for DATA nodes, their parent */
22998542Smckusick	ufs_lbn_t id_lbn;	/* logical block number of current block */
23098542Smckusick	ufs2_daddr_t id_blkno;	/* current block number being examined */
2311558Srgrimes	int id_numfrags;	/* number of frags contained in block */
23298542Smckusick	off_t id_filesize;	/* for DATA nodes, the size of the directory */
23398542Smckusick	ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */
2341558Srgrimes	int id_loc;		/* for DATA nodes, current location in dir */
2351558Srgrimes	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
2361558Srgrimes	char *id_name;		/* for DATA nodes, name to find or enter */
2371558Srgrimes	char id_type;		/* type of descriptor, DATA or ADDR */
2381558Srgrimes};
2391558Srgrimes/* file types */
24062668Smckusick#define	DATA	1	/* a directory */
24162668Smckusick#define	SNAP	2	/* a snapshot */
24262668Smckusick#define	ADDR	3	/* anything but a directory or a snapshot */
2431558Srgrimes
2441558Srgrimes/*
2451558Srgrimes * Linked list of duplicate blocks.
2468871Srgrimes *
2471558Srgrimes * The list is composed of two parts. The first part of the
2481558Srgrimes * list (from duplist through the node pointed to by muldup)
2498871Srgrimes * contains a single copy of each duplicate block that has been
2501558Srgrimes * found. The second part of the list (from muldup to the end)
2511558Srgrimes * contains duplicate blocks that have been found more than once.
2521558Srgrimes * To check if a block has been found as a duplicate it is only
2538871Srgrimes * necessary to search from duplist through muldup. To find the
2541558Srgrimes * total number of times that a block has been found as a duplicate
255229778Suqs * the entire list must be searched for occurrences of the block
2561558Srgrimes * in question. The following diagram shows a sample list where
2571558Srgrimes * w (found twice), x (found once), y (found three times), and z
2581558Srgrimes * (found once) are duplicate block numbers:
2591558Srgrimes *
2601558Srgrimes *    w -> y -> x -> z -> y -> w -> y
2611558Srgrimes *    ^		     ^
2621558Srgrimes *    |		     |
2631558Srgrimes * duplist	  muldup
2641558Srgrimes */
2651558Srgrimesstruct dups {
2661558Srgrimes	struct dups *next;
26798542Smckusick	ufs2_daddr_t dup;
2681558Srgrimes};
2691558Srgrimesstruct dups *duplist;		/* head of dup list */
2701558Srgrimesstruct dups *muldup;		/* end of unique duplicate dup block numbers */
2711558Srgrimes
2721558Srgrimes/*
2731558Srgrimes * Inode cache data structures.
2741558Srgrimes */
2751558Srgrimesstruct inoinfo {
2761558Srgrimes	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
2771558Srgrimes	ino_t	i_number;		/* inode number of this entry */
2781558Srgrimes	ino_t	i_parent;		/* inode number of parent */
2791558Srgrimes	ino_t	i_dotdot;		/* inode number of `..' */
2801558Srgrimes	size_t	i_isize;		/* size of inode */
2811558Srgrimes	u_int	i_numblks;		/* size of block array in bytes */
28298542Smckusick	ufs2_daddr_t i_blks[1];		/* actually longer */
2831558Srgrimes} **inphead, **inpsort;
28457573Smckusicklong numdirs, dirhash, listmax, inplast;
28541474Sjulianlong countdirs;			/* number of directories we actually found */
2861558Srgrimes
28774556Smckusick#define MIBSIZE	3		/* size of fsck sysctl MIBs */
28874556Smckusickint	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
28974556Smckusickint	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
290142123Sdelphijint	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
291142123Sdelphijint	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
292142123Sdelphijint	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
293142123Sdelphijint	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
294142123Sdelphijint	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
29574556Smckusickint	freefiles[MIBSIZE];	/* MIB command to free a set of files */
29674556Smckusickint	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
29774556Smckusickint	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
298102231Strhodesstruct	fsck_cmd cmd;		/* sysctl file system update commands */
29974556Smckusickchar	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
3001558Srgrimeschar	*cdevname;		/* name of device being checked */
3011558Srgrimeslong	dev_bsize;		/* computed value of DEV_BSIZE */
3021558Srgrimeslong	secsize;		/* actual disk sector size */
303228751Skibu_int	real_dev_bsize;		/* actual disk sector size, not overriden */
3041558Srgrimeschar	nflag;			/* assume a no response */
3051558Srgrimeschar	yflag;			/* assume a yes response */
30674556Smckusickint	bkgrdflag;		/* use a snapshot to run on an active system */
3071558Srgrimesint	bflag;			/* location of alternate super block */
3081558Srgrimesint	debug;			/* output debugging info */
309221233Sdesint	Eflag;			/* zero out empty data blocks */
310188110Smckusickint	inoopt;			/* trim out unused inodes */
311187931Sobrienchar	ckclean;		/* only do work if not cleanly unmounted */
312102231Strhodesint	cvtlevel;		/* convert to newer file system format */
31375927Smckusickint	bkgrdcheck;		/* determine if background check is possible */
314143235Sdelphijint	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
31534266Sjulianchar	usedsoftdep;		/* just fix soft dependency inconsistencies */
31641474Sjulianchar	preen;			/* just fix normal inconsistencies */
31741474Sjulianchar	rerun;			/* rerun fsck. Only used in non-preen mode */
31841474Sjulianint	returntosingle;		/* 1 => return to single user mode on exit */
31934266Sjulianchar	resolved;		/* cleared if unresolved changes => not clean */
3201558Srgrimeschar	havesb;			/* superblock has been read */
321102231Strhodeschar	skipclean;		/* skip clean file systems if preening */
322102231Strhodesint	fsmodified;		/* 1 => write done to file system */
323102231Strhodesint	fsreadfd;		/* file descriptor for reading file system */
324102231Strhodesint	fswritefd;		/* file descriptor for writing file system */
3251558Srgrimes
326102231Strhodesufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
3271558Srgrimeschar	*blockmap;		/* ptr to primary blk allocation map */
328102231Strhodesino_t	maxino;			/* number of inodes in file system */
3291558Srgrimes
3301558Srgrimesino_t	lfdir;			/* lost & found directory inode number */
331100935Sphkconst char *lfname;		/* lost & found directory name */
3321558Srgrimesint	lfmode;			/* lost & found directory creation mode */
3331558Srgrimes
33498542Smckusickufs2_daddr_t n_blks;		/* number of blocks in use */
33598542Smckusickino_t n_files;			/* number of files in use */
3361558Srgrimes
337193325Slulfvolatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
338193325Slulfvolatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
33970050Siedowse
34098542Smckusick#define	clearinode(dp) \
34198542Smckusick	if (sblock.fs_magic == FS_UFS1_MAGIC) { \
34298542Smckusick		(dp)->dp1 = ufs1_zino; \
34398542Smckusick	} else { \
34498542Smckusick		(dp)->dp2 = ufs2_zino; \
34598542Smckusick	}
34698542Smckusickstruct	ufs1_dinode ufs1_zino;
34798542Smckusickstruct	ufs2_dinode ufs2_zino;
3481558Srgrimes
3491558Srgrimes#define	setbmap(blkno)	setbit(blockmap, blkno)
3501558Srgrimes#define	testbmap(blkno)	isset(blockmap, blkno)
3511558Srgrimes#define	clrbmap(blkno)	clrbit(blockmap, blkno)
3521558Srgrimes
3531558Srgrimes#define	STOP	0x01
3541558Srgrimes#define	SKIP	0x02
3551558Srgrimes#define	KEEPON	0x04
3561558Srgrimes#define	ALTERED	0x08
3571558Srgrimes#define	FOUND	0x10
3581558Srgrimes
35923675Speter#define	EEXIT	8		/* Standard error exit. */
3607585Sbde
361248658Smckusickint flushentry(void);
362248658Smckusick/*
363248658Smckusick * Wrapper for malloc() that flushes the cylinder group cache to try
364248658Smckusick * to get space.
365248658Smckusick */
366248658Smckusickstatic inline void*
367248658SmckusickMalloc(int size)
368248658Smckusick{
369248658Smckusick	void *retval;
370248658Smckusick
371248658Smckusick	while ((retval = malloc(size)) == NULL)
372248658Smckusick		if (flushentry() == 0)
373248658Smckusick			break;
374248658Smckusick	return (retval);
375248658Smckusick}
376248658Smckusick
377248658Smckusick/*
378248658Smckusick * Wrapper for calloc() that flushes the cylinder group cache to try
379248658Smckusick * to get space.
380248658Smckusick */
381248658Smckusickstatic inline void*
382248658SmckusickCalloc(int cnt, int size)
383248658Smckusick{
384248658Smckusick	void *retval;
385248658Smckusick
386248658Smckusick	while ((retval = calloc(cnt, size)) == NULL)
387248658Smckusick		if (flushentry() == 0)
388248658Smckusick			break;
389248658Smckusick	return (retval);
390248658Smckusick}
391248658Smckusick
39223675Speterstruct fstab;
3937585Sbde
39441474Sjulian
39592839Simpvoid		adjust(struct inodesc *, int lcnt);
39698542Smckusickufs2_daddr_t	allocblk(long frags);
39792839Simpino_t		allocdir(ino_t parent, ino_t request, int mode);
39892839Simpino_t		allocino(ino_t request, int type);
399100935Sphkvoid		blkerror(ino_t ino, const char *type, ufs2_daddr_t blk);
40092839Simpchar	       *blockcheck(char *name);
401163845Spjdint		blread(int fd, char *buf, ufs2_daddr_t blk, long size);
40292839Simpvoid		bufinit(void);
403240406Sobrienvoid		blwrite(int fd, char *buf, ufs2_daddr_t blk, ssize_t size);
404221233Sdesvoid		blerase(int fd, ufs2_daddr_t blk, long size);
40598542Smckusickvoid		cacheino(union dinode *dp, ino_t inumber);
40692839Simpvoid		catch(int);
40792839Simpvoid		catchquit(int);
408100935Sphkint		changeino(ino_t dir, const char *name, ino_t newnum);
409248658Smckusickint		check_cgmagic(int cg, struct bufarea *cgbp);
41098542Smckusickint		chkrange(ufs2_daddr_t blk, int cnt);
41192839Simpvoid		ckfini(int markclean);
41298542Smckusickint		ckinode(union dinode *dp, struct inodesc *);
413100935Sphkvoid		clri(struct inodesc *, const char *type, int flag);
41492839Simpint		clearentry(struct inodesc *);
415100935Sphkvoid		direrror(ino_t ino, const char *errmesg);
41692839Simpint		dirscan(struct inodesc *);
417100935Sphkint		dofix(struct inodesc *, const char *msg);
418103398Sphkint		eascan(struct inodesc *, struct ufs2_dinode *dp);
419100935Sphkvoid		fileerror(ino_t cwd, ino_t ino, const char *errmesg);
420247212Smckusickvoid		finalIOstats(void);
42192839Simpint		findino(struct inodesc *);
42292839Simpint		findname(struct inodesc *);
42392839Simpvoid		flush(int fd, struct bufarea *bp);
42498542Smckusickvoid		freeblk(ufs2_daddr_t blkno, long frags);
42592839Simpvoid		freeino(ino_t ino);
42692839Simpvoid		freeinodebuf(void);
42798542Smckusickint		ftypeok(union dinode *dp);
42898542Smckusickvoid		getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
429248658Smckusickstruct bufarea *cgget(int cg);
430247212Smckusickstruct bufarea *getdatablk(ufs2_daddr_t blkno, long size, int type);
43192839Simpstruct inoinfo *getinoinfo(ino_t inumber);
432188110Smckusickunion dinode   *getnextinode(ino_t inumber, int rebuildcg);
43392839Simpvoid		getpathname(char *namebuf, ino_t curdir, ino_t ino);
43498542Smckusickunion dinode   *ginode(ino_t inumber);
43592839Simpvoid		infohandler(int sig);
436126345Sscottlvoid		alarmhandler(int sig);
43792839Simpvoid		inocleanup(void);
43892839Simpvoid		inodirty(void);
43992839Simpstruct inostat *inoinfo(ino_t inum);
440247212Smckusickvoid		IOstats(char *what);
44192839Simpint		linkup(ino_t orphan, ino_t parentdir, char *name);
442100935Sphkint		makeentry(ino_t parent, ino_t ino, const char *name);
44392839Simpvoid		panic(const char *fmt, ...) __printflike(1, 2);
44492839Simpvoid		pass1(void);
44592839Simpvoid		pass1b(void);
44692839Simpint		pass1check(struct inodesc *);
44792839Simpvoid		pass2(void);
44892839Simpvoid		pass3(void);
44992839Simpvoid		pass4(void);
45092839Simpint		pass4check(struct inodesc *);
45192839Simpvoid		pass5(void);
45292839Simpvoid		pfatal(const char *fmt, ...) __printflike(1, 2);
45392839Simpvoid		pinode(ino_t ino);
45492839Simpvoid		propagate(void);
45592839Simpvoid		pwarn(const char *fmt, ...) __printflike(1, 2);
45692839Simpint		readsb(int listerr);
457100935Sphkint		reply(const char *question);
458100935Sphkvoid		rwerror(const char *mesg, ufs2_daddr_t blk);
45992839Simpvoid		sblock_init(void);
46092839Simpvoid		setinodebuf(ino_t);
46192839Simpint		setup(char *dev);
462163845Spjdvoid		gjournal_check(const char *filesys);
463207141Sjeffint		suj_check(const char *filesys);
464224059Smckusickvoid		update_maps(struct cg *, struct cg*, int);
465207143Spjd
466207143Spjd#endif	/* !_FSCK_H_ */
467