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$
611558Srgrimes */
621558Srgrimes
63207143Spjd#ifndef _FSCK_H_
64207143Spjd#define	_FSCK_H_
65207143Spjd
6623675Speter#include <unistd.h>
6723675Speter#include <stdlib.h>
6823675Speter#include <stdio.h>
6923675Speter
70248628Smckusick#include <sys/queue.h>
71248628Smckusick
721558Srgrimes#define	MAXDUP		10	/* limit on dup blks (per inode) */
731558Srgrimes#define	MAXBAD		10	/* limit on bad blks (per inode) */
74248628Smckusick#define	MINBUFS		10	/* minimum number of buffers required */
75248628Smckusick#define	MAXBUFS		40	/* maximum space to allocate to buffers */
76248628Smckusick#define	INOBUFSIZE	64*1024	/* size of buffer to read inodes in pass1 */
77253155Sdes#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 */
12841474Sjulianstruct 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 {
137248628Smckusick	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;
142249788Smckusick	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
166248628Smckusick/*
167248628Smckusick * Buffer flags
168248628Smckusick */
169248628Smckusick#define	B_INUSE 	0x00000001	/* Buffer is in use */
170249788Smckusick/*
171249788Smckusick * Type of data in buffer
172249788Smckusick */
173249788Smckusick#define	BT_UNKNOWN 	 0	/* Buffer holds a superblock */
174249788Smckusick#define	BT_SUPERBLK 	 1	/* Buffer holds a superblock */
175249788Smckusick#define	BT_CYLGRP 	 2	/* Buffer holds a cylinder group map */
176249788Smckusick#define	BT_LEVEL1 	 3	/* Buffer holds single level indirect */
177249788Smckusick#define	BT_LEVEL2 	 4	/* Buffer holds double level indirect */
178249788Smckusick#define	BT_LEVEL3 	 5	/* Buffer holds triple level indirect */
179249788Smckusick#define	BT_EXTATTR 	 6	/* Buffer holds external attribute data */
180249788Smckusick#define	BT_INODES 	 7	/* Buffer holds external attribute data */
181249788Smckusick#define	BT_DIRDATA 	 8	/* Buffer holds directory data */
182249788Smckusick#define	BT_DATA	 	 9	/* Buffer holds user data */
183249788Smckusick#define BT_NUMBUFTYPES	10
184249788Smckusick#define BT_NAMES {			\
185249788Smckusick	"unknown",			\
186249788Smckusick	"Superblock",			\
187249788Smckusick	"Cylinder Group",		\
188249788Smckusick	"Single Level Indirect",	\
189249788Smckusick	"Double Level Indirect",	\
190249788Smckusick	"Triple Level Indirect",	\
191249788Smckusick	"External Attribute",		\
192249788Smckusick	"Inode Block",			\
193249788Smckusick	"Directory Contents",		\
194249788Smckusick	"User Data" }
195249788Smckusicklong readcnt[BT_NUMBUFTYPES];
196249788Smckusicklong totalreadcnt[BT_NUMBUFTYPES];
197249788Smckusickstruct timespec readtime[BT_NUMBUFTYPES];
198249788Smckusickstruct timespec totalreadtime[BT_NUMBUFTYPES];
199249788Smckusickstruct timespec startprog;
2001558Srgrimes
201102231Strhodesstruct bufarea sblk;		/* file system superblock */
2021558Srgrimesstruct bufarea *pdirbp;		/* current directory contents */
2031558Srgrimesstruct 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)
211249788Smckusick#define	initbarea(bp, type) do { \
2121558Srgrimes	(bp)->b_dirty = 0; \
21398542Smckusick	(bp)->b_bno = (ufs2_daddr_t)-1; \
21486514Siedowse	(bp)->b_flags = 0; \
215249788Smckusick	(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};
22262668Smckusickino_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 */
2321558Srgrimes	int id_numfrags;	/* number of frags contained in block */
23398542Smckusick	off_t id_filesize;	/* for DATA nodes, the size of the directory */
23498542Smckusick	ufs2_daddr_t id_entryno;/* for DATA nodes, current entry number */
2351558Srgrimes	int id_loc;		/* for DATA nodes, current location in dir */
2361558Srgrimes	struct direct *id_dirp;	/* for DATA nodes, ptr to current entry */
2371558Srgrimes	char *id_name;		/* for DATA nodes, name to find or enter */
2381558Srgrimes	char id_type;		/* type of descriptor, DATA or ADDR */
2391558Srgrimes};
2401558Srgrimes/* file types */
24162668Smckusick#define	DATA	1	/* a directory */
24262668Smckusick#define	SNAP	2	/* a snapshot */
24362668Smckusick#define	ADDR	3	/* anything but a directory or a snapshot */
2441558Srgrimes
2451558Srgrimes/*
2461558Srgrimes * Linked list of duplicate blocks.
2478871Srgrimes *
2481558Srgrimes * The list is composed of two parts. The first part of the
2491558Srgrimes * list (from duplist through the node pointed to by muldup)
2508871Srgrimes * contains a single copy of each duplicate block that has been
2511558Srgrimes * found. The second part of the list (from muldup to the end)
2521558Srgrimes * contains duplicate blocks that have been found more than once.
2531558Srgrimes * To check if a block has been found as a duplicate it is only
2548871Srgrimes * necessary to search from duplist through muldup. To find the
2551558Srgrimes * total number of times that a block has been found as a duplicate
2561558Srgrimes * the entire list must be searched for occurences of the block
2571558Srgrimes * in question. The following diagram shows a sample list where
2581558Srgrimes * w (found twice), x (found once), y (found three times), and z
2591558Srgrimes * (found once) are duplicate block numbers:
2601558Srgrimes *
2611558Srgrimes *    w -> y -> x -> z -> y -> w -> y
2621558Srgrimes *    ^		     ^
2631558Srgrimes *    |		     |
2641558Srgrimes * duplist	  muldup
2651558Srgrimes */
2661558Srgrimesstruct dups {
2671558Srgrimes	struct dups *next;
26898542Smckusick	ufs2_daddr_t dup;
2691558Srgrimes};
2701558Srgrimesstruct dups *duplist;		/* head of dup list */
2711558Srgrimesstruct dups *muldup;		/* end of unique duplicate dup block numbers */
2721558Srgrimes
2731558Srgrimes/*
2741558Srgrimes * Inode cache data structures.
2751558Srgrimes */
2761558Srgrimesstruct inoinfo {
2771558Srgrimes	struct	inoinfo *i_nexthash;	/* next entry in hash chain */
2781558Srgrimes	ino_t	i_number;		/* inode number of this entry */
2791558Srgrimes	ino_t	i_parent;		/* inode number of parent */
2801558Srgrimes	ino_t	i_dotdot;		/* inode number of `..' */
2811558Srgrimes	size_t	i_isize;		/* size of inode */
2821558Srgrimes	u_int	i_numblks;		/* size of block array in bytes */
28398542Smckusick	ufs2_daddr_t i_blks[1];		/* actually longer */
2841558Srgrimes} **inphead, **inpsort;
28557573Smckusicklong numdirs, dirhash, listmax, inplast;
28641474Sjulianlong countdirs;			/* number of directories we actually found */
2871558Srgrimes
28874556Smckusick#define MIBSIZE	3		/* size of fsck sysctl MIBs */
28974556Smckusickint	adjrefcnt[MIBSIZE];	/* MIB command to adjust inode reference cnt */
29074556Smckusickint	adjblkcnt[MIBSIZE];	/* MIB command to adjust inode block count */
291142123Sdelphijint	adjndir[MIBSIZE];	/* MIB command to adjust number of directories */
292142123Sdelphijint	adjnbfree[MIBSIZE];	/* MIB command to adjust number of free blocks */
293142123Sdelphijint	adjnifree[MIBSIZE];	/* MIB command to adjust number of free inodes */
294142123Sdelphijint	adjnffree[MIBSIZE];	/* MIB command to adjust number of free frags */
295142123Sdelphijint	adjnumclusters[MIBSIZE];	/* MIB command to adjust number of free clusters */
29674556Smckusickint	freefiles[MIBSIZE];	/* MIB command to free a set of files */
29774556Smckusickint	freedirs[MIBSIZE];	/* MIB command to free a set of directories */
29874556Smckusickint	freeblks[MIBSIZE];	/* MIB command to free a set of data blocks */
299102231Strhodesstruct	fsck_cmd cmd;		/* sysctl file system update commands */
30074556Smckusickchar	snapname[BUFSIZ];	/* when doing snapshots, the name of the file */
3011558Srgrimeschar	*cdevname;		/* name of device being checked */
3021558Srgrimeslong	dev_bsize;		/* computed value of DEV_BSIZE */
3031558Srgrimeslong	secsize;		/* actual disk sector size */
304229256Skibu_int	real_dev_bsize;		/* actual disk sector size, not overriden */
3051558Srgrimeschar	nflag;			/* assume a no response */
3061558Srgrimeschar	yflag;			/* assume a yes response */
30774556Smckusickint	bkgrdflag;		/* use a snapshot to run on an active system */
3081558Srgrimesint	bflag;			/* location of alternate super block */
3091558Srgrimesint	debug;			/* output debugging info */
310253155Sdesint	Eflag;			/* delete empty data blocks */
311253155Sdesint	Zflag;			/* zero empty data blocks */
312188110Smckusickint	inoopt;			/* trim out unused inodes */
313187931Sobrienchar	ckclean;		/* only do work if not cleanly unmounted */
314102231Strhodesint	cvtlevel;		/* convert to newer file system format */
31575927Smckusickint	bkgrdcheck;		/* determine if background check is possible */
316143235Sdelphijint	bkgrdsumadj;		/* whether the kernel have ability to adjust superblock summary */
31734266Sjulianchar	usedsoftdep;		/* just fix soft dependency inconsistencies */
31841474Sjulianchar	preen;			/* just fix normal inconsistencies */
31941474Sjulianchar	rerun;			/* rerun fsck. Only used in non-preen mode */
32041474Sjulianint	returntosingle;		/* 1 => return to single user mode on exit */
32134266Sjulianchar	resolved;		/* cleared if unresolved changes => not clean */
3221558Srgrimeschar	havesb;			/* superblock has been read */
323102231Strhodeschar	skipclean;		/* skip clean file systems if preening */
324102231Strhodesint	fsmodified;		/* 1 => write done to file system */
325102231Strhodesint	fsreadfd;		/* file descriptor for reading file system */
326102231Strhodesint	fswritefd;		/* file descriptor for writing file system */
3271558Srgrimes
328102231Strhodesufs2_daddr_t maxfsblock;	/* number of blocks in the file system */
3291558Srgrimeschar	*blockmap;		/* ptr to primary blk allocation map */
330102231Strhodesino_t	maxino;			/* number of inodes in file system */
3311558Srgrimes
3321558Srgrimesino_t	lfdir;			/* lost & found directory inode number */
333100935Sphkconst char *lfname;		/* lost & found directory name */
3341558Srgrimesint	lfmode;			/* lost & found directory creation mode */
3351558Srgrimes
33698542Smckusickufs2_daddr_t n_blks;		/* number of blocks in use */
33798542Smckusickino_t n_files;			/* number of files in use */
3381558Srgrimes
339193325Slulfvolatile sig_atomic_t	got_siginfo;	/* received a SIGINFO */
340193325Slulfvolatile sig_atomic_t	got_sigalarm;	/* received a SIGALRM */
34170050Siedowse
34298542Smckusick#define	clearinode(dp) \
34398542Smckusick	if (sblock.fs_magic == FS_UFS1_MAGIC) { \
34498542Smckusick		(dp)->dp1 = ufs1_zino; \
34598542Smckusick	} else { \
34698542Smckusick		(dp)->dp2 = ufs2_zino; \
34798542Smckusick	}
34898542Smckusickstruct	ufs1_dinode ufs1_zino;
34998542Smckusickstruct	ufs2_dinode ufs2_zino;
3501558Srgrimes
3511558Srgrimes#define	setbmap(blkno)	setbit(blockmap, blkno)
3521558Srgrimes#define	testbmap(blkno)	isset(blockmap, blkno)
3531558Srgrimes#define	clrbmap(blkno)	clrbit(blockmap, blkno)
3541558Srgrimes
3551558Srgrimes#define	STOP	0x01
3561558Srgrimes#define	SKIP	0x02
3571558Srgrimes#define	KEEPON	0x04
3581558Srgrimes#define	ALTERED	0x08
3591558Srgrimes#define	FOUND	0x10
3601558Srgrimes
36123675Speter#define	EEXIT	8		/* Standard error exit. */
3627585Sbde
363249788Smckusickint flushentry(void);
364249788Smckusick/*
365249788Smckusick * Wrapper for malloc() that flushes the cylinder group cache to try
366249788Smckusick * to get space.
367249788Smckusick */
368249788Smckusickstatic inline void*
369263630SmckusickMalloc(size_t size)
370249788Smckusick{
371249788Smckusick	void *retval;
372249788Smckusick
373249788Smckusick	while ((retval = malloc(size)) == NULL)
374249788Smckusick		if (flushentry() == 0)
375249788Smckusick			break;
376249788Smckusick	return (retval);
377249788Smckusick}
378249788Smckusick
379249788Smckusick/*
380249788Smckusick * Wrapper for calloc() that flushes the cylinder group cache to try
381249788Smckusick * to get space.
382249788Smckusick */
383249788Smckusickstatic inline void*
384263630SmckusickCalloc(size_t cnt, size_t size)
385249788Smckusick{
386249788Smckusick	void *retval;
387249788Smckusick
388249788Smckusick	while ((retval = calloc(cnt, size)) == NULL)
389249788Smckusick		if (flushentry() == 0)
390249788Smckusick			break;
391249788Smckusick	return (retval);
392249788Smckusick}
393249788Smckusick
39423675Speterstruct fstab;
3957585Sbde
39641474Sjulian
39792839Simpvoid		adjust(struct inodesc *, int lcnt);
39898542Smckusickufs2_daddr_t	allocblk(long frags);
39992839Simpino_t		allocdir(ino_t parent, ino_t request, int mode);
40092839Simpino_t		allocino(ino_t request, int type);
401100935Sphkvoid		blkerror(ino_t ino, const char *type, ufs2_daddr_t blk);
40292839Simpchar	       *blockcheck(char *name);
403163845Spjdint		blread(int fd, char *buf, ufs2_daddr_t blk, long size);
40492839Simpvoid		bufinit(void);
405163845Spjdvoid		blwrite(int fd, char *buf, ufs2_daddr_t blk, long size);
406221233Sdesvoid		blerase(int fd, ufs2_daddr_t blk, long size);
407253155Sdesvoid		blzero(int fd, ufs2_daddr_t blk, long size);
40898542Smckusickvoid		cacheino(union dinode *dp, ino_t inumber);
40992839Simpvoid		catch(int);
41092839Simpvoid		catchquit(int);
411100935Sphkint		changeino(ino_t dir, const char *name, ino_t newnum);
412249788Smckusickint		check_cgmagic(int cg, struct bufarea *cgbp);
41398542Smckusickint		chkrange(ufs2_daddr_t blk, int cnt);
41492839Simpvoid		ckfini(int markclean);
41598542Smckusickint		ckinode(union dinode *dp, struct inodesc *);
416100935Sphkvoid		clri(struct inodesc *, const char *type, int flag);
41792839Simpint		clearentry(struct inodesc *);
418100935Sphkvoid		direrror(ino_t ino, const char *errmesg);
41992839Simpint		dirscan(struct inodesc *);
420100935Sphkint		dofix(struct inodesc *, const char *msg);
421103398Sphkint		eascan(struct inodesc *, struct ufs2_dinode *dp);
422100935Sphkvoid		fileerror(ino_t cwd, ino_t ino, const char *errmesg);
423249788Smckusickvoid		finalIOstats(void);
42492839Simpint		findino(struct inodesc *);
42592839Simpint		findname(struct inodesc *);
42692839Simpvoid		flush(int fd, struct bufarea *bp);
42798542Smckusickvoid		freeblk(ufs2_daddr_t blkno, long frags);
42892839Simpvoid		freeino(ino_t ino);
42992839Simpvoid		freeinodebuf(void);
43098542Smckusickint		ftypeok(union dinode *dp);
43198542Smckusickvoid		getblk(struct bufarea *bp, ufs2_daddr_t blk, long size);
432249788Smckusickstruct bufarea *cgget(int cg);
433249788Smckusickstruct bufarea *getdatablk(ufs2_daddr_t blkno, long size, int type);
43492839Simpstruct inoinfo *getinoinfo(ino_t inumber);
435188110Smckusickunion dinode   *getnextinode(ino_t inumber, int rebuildcg);
43692839Simpvoid		getpathname(char *namebuf, ino_t curdir, ino_t ino);
43798542Smckusickunion dinode   *ginode(ino_t inumber);
43892839Simpvoid		infohandler(int sig);
439126345Sscottlvoid		alarmhandler(int sig);
44092839Simpvoid		inocleanup(void);
44192839Simpvoid		inodirty(void);
44292839Simpstruct inostat *inoinfo(ino_t inum);
443249788Smckusickvoid		IOstats(char *what);
44492839Simpint		linkup(ino_t orphan, ino_t parentdir, char *name);
445100935Sphkint		makeentry(ino_t parent, ino_t ino, const char *name);
44692839Simpvoid		panic(const char *fmt, ...) __printflike(1, 2);
44792839Simpvoid		pass1(void);
44892839Simpvoid		pass1b(void);
44992839Simpint		pass1check(struct inodesc *);
45092839Simpvoid		pass2(void);
45192839Simpvoid		pass3(void);
45292839Simpvoid		pass4(void);
45392839Simpint		pass4check(struct inodesc *);
45492839Simpvoid		pass5(void);
45592839Simpvoid		pfatal(const char *fmt, ...) __printflike(1, 2);
45692839Simpvoid		pinode(ino_t ino);
45792839Simpvoid		propagate(void);
45892839Simpvoid		pwarn(const char *fmt, ...) __printflike(1, 2);
45992839Simpint		readsb(int listerr);
460100935Sphkint		reply(const char *question);
461100935Sphkvoid		rwerror(const char *mesg, ufs2_daddr_t blk);
46292839Simpvoid		sblock_init(void);
46392839Simpvoid		setinodebuf(ino_t);
46492839Simpint		setup(char *dev);
465163845Spjdvoid		gjournal_check(const char *filesys);
466207141Sjeffint		suj_check(const char *filesys);
467224059Smckusickvoid		update_maps(struct cg *, struct cg*, int);
468207143Spjd
469207143Spjd#endif	/* !_FSCK_H_ */
470