1139825Simp/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
2922521Sdyson *	@(#)fs.h	8.13 (Berkeley) 3/21/95
3050477Speter * $FreeBSD: stable/10/sys/ufs/ffs/fs.h 322860 2017-08-24 21:44:23Z mckusick $
311541Srgrimes */
321541Srgrimes
332176Spaul#ifndef _UFS_FFS_FS_H_
34262779Spfg#define	_UFS_FFS_FS_H_
352176Spaul
36243245Strasz#include <sys/mount.h>
37243250Strasz#include <ufs/ufs/dinode.h>
38243245Strasz
391541Srgrimes/*
4096755Strhodes * Each disk drive contains some number of filesystems.
4196755Strhodes * A filesystem consists of a number of cylinder groups.
421541Srgrimes * Each cylinder group has inodes and data.
431541Srgrimes *
4496755Strhodes * A filesystem is described by its super-block, which in turn
451541Srgrimes * describes the cylinder groups.  The super-block is critical
461541Srgrimes * data and is replicated in each cylinder group to protect against
471541Srgrimes * catastrophic loss.  This is done at `newfs' time and the critical
481541Srgrimes * super-block data does not change, so the copies need not be
491541Srgrimes * referenced further unless disaster strikes.
501541Srgrimes *
5196755Strhodes * For filesystem fs, the offsets of the various blocks of interest
521541Srgrimes * are given in the super block as:
531541Srgrimes *	[fs->fs_sblkno]		Super-block
541541Srgrimes *	[fs->fs_cblkno]		Cylinder group block
551541Srgrimes *	[fs->fs_iblkno]		Inode blocks
561541Srgrimes *	[fs->fs_dblkno]		Data blocks
571541Srgrimes * The beginning of cylinder group cg in fs, is given by
581541Srgrimes * the ``cgbase(fs, cg)'' macro.
591541Srgrimes *
6098542Smckusick * Depending on the architecture and the media, the superblock may
6198542Smckusick * reside in any one of four places. For tiny media where every block
6298542Smckusick * counts, it is placed at the very front of the partition. Historically,
6398542Smckusick * UFS1 placed it 8K from the front to leave room for the disk label and
6498542Smckusick * a small bootstrap. For UFS2 it got moved to 64K from the front to leave
6598542Smckusick * room for the disk label and a bigger bootstrap, and for really piggy
6698542Smckusick * systems we check at 256K from the front if the first three fail. In
6798542Smckusick * all cases the size of the superblock will be SBLOCKSIZE. All values are
6898542Smckusick * given in byte-offset form, so they do not imply a sector size. The
6998542Smckusick * SBLOCKSEARCH specifies the order in which the locations should be searched.
701541Srgrimes */
71262779Spfg#define	SBLOCK_FLOPPY	     0
72262779Spfg#define	SBLOCK_UFS1	  8192
73262779Spfg#define	SBLOCK_UFS2	 65536
74262779Spfg#define	SBLOCK_PIGGY	262144
75262779Spfg#define	SBLOCKSIZE	  8192
76262779Spfg#define	SBLOCKSEARCH \
7798542Smckusick	{ SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
781541Srgrimes
7998542Smckusick/*
8098542Smckusick * Max number of fragments per block. This value is NOT tweakable.
8198542Smckusick */
82262779Spfg#define	MAXFRAG 	8
8398542Smckusick
841541Srgrimes/*
851541Srgrimes * Addresses stored in inodes are capable of addressing fragments
868876Srgrimes * of `blocks'. File system blocks of at most size MAXBSIZE can
871541Srgrimes * be optionally broken into 2, 4, or 8 pieces, each of which is
8813765Smpp * addressable; these pieces may be DEV_BSIZE, or some multiple of
891541Srgrimes * a DEV_BSIZE unit.
901541Srgrimes *
911541Srgrimes * Large files consist of exclusively large data blocks.  To avoid
921541Srgrimes * undue wasted disk space, the last data block of a small file may be
931541Srgrimes * allocated as only as many fragments of a large block as are
9496755Strhodes * necessary.  The filesystem format retains only a single pointer
951541Srgrimes * to such a fragment, which is a piece of a single large block that
961541Srgrimes * has been divided.  The size of such a fragment is determinable from
971541Srgrimes * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
981541Srgrimes *
9996755Strhodes * The filesystem records space availability at the fragment level;
1001541Srgrimes * to determine block availability, aligned fragments are examined.
1011541Srgrimes */
1021541Srgrimes
1031541Srgrimes/*
1041541Srgrimes * MINBSIZE is the smallest allowable block size.
1051541Srgrimes * In order to insure that it is possible to create files of size
1061541Srgrimes * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
1071541Srgrimes * MINBSIZE must be big enough to hold a cylinder group block,
1081541Srgrimes * thus changes to (struct cg) must keep its size within MINBSIZE.
109179295Srodrigc * Note that super blocks are always of size SBLOCKSIZE,
110179295Srodrigc * and that both SBLOCKSIZE and MAXBSIZE must be >= MINBSIZE.
1111541Srgrimes */
112262779Spfg#define	MINBSIZE	4096
1131541Srgrimes
1141541Srgrimes/*
11596755Strhodes * The path name on which the filesystem is mounted is maintained
1168876Srgrimes * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
1171541Srgrimes * the super block for this name.
11822521Sdyson */
119262779Spfg#define	MAXMNTLEN	468
12022521Sdyson
12122521Sdyson/*
122108970Sgordon * The volume name for this filesystem is maintained in fs_volname.
123108970Sgordon * MAXVOLLEN defines the length of the buffer allocated.
124108970Sgordon */
125262779Spfg#define	MAXVOLLEN	32
126108970Sgordon
127108970Sgordon/*
12871073Siedowse * There is a 128-byte region in the superblock reserved for in-core
12971073Siedowse * pointers to summary information. Originally this included an array
13088025Siedowse * of pointers to blocks of struct csum; now there are just a few
13171073Siedowse * pointers and the remaining space is padded with fs_ocsp[].
13271073Siedowse *
13371073Siedowse * NOCSPTRS determines the size of this padding. One pointer (fs_csp)
13471073Siedowse * is taken away to point to a contiguous array of struct csum for
13571073Siedowse * all cylinder groups; a second (fs_maxcluster) points to an array
13675377Smckusick * of cluster sizes that is computed as cylinder groups are inspected,
13775377Smckusick * and the third points to an array that tracks the creation of new
13888025Siedowse * directories. A fourth pointer, fs_active, is used when creating
13988025Siedowse * snapshots; it points to a bitmap of cylinder groups for which the
14088025Siedowse * free-block bitmap has changed since the snapshot operation began.
1411541Srgrimes */
14288025Siedowse#define	NOCSPTRS	((128 / sizeof(void *)) - 4)
1431541Srgrimes
1441541Srgrimes/*
1451541Srgrimes * A summary of contiguous blocks of various sizes is maintained
1461541Srgrimes * in each cylinder group. Normally this is set by the initial
1471541Srgrimes * value of fs_maxcontig. To conserve space, a maximum summary size
1481541Srgrimes * is set by FS_MAXCONTIG.
1491541Srgrimes */
150262779Spfg#define	FS_MAXCONTIG	16
1511541Srgrimes
1521541Srgrimes/*
15396755Strhodes * MINFREE gives the minimum acceptable percentage of filesystem
1541541Srgrimes * blocks which may be free. If the freelist drops below this level
1551541Srgrimes * only the superuser may continue to allocate blocks. This may
1561541Srgrimes * be set to 0 if no reserve of free blocks is deemed necessary,
15796755Strhodes * however throughput drops by fifty percent if the filesystem
1581541Srgrimes * is run at between 95% and 100% full; thus the minimum default
1591541Srgrimes * value of fs_minfree is 5%. However, to get good clustering
1601541Srgrimes * performance, 10% is a better choice. hence we use 10% as our
1611541Srgrimes * default value. With 10% free space, fragmentation is not a
1621541Srgrimes * problem, so we choose to optimize for time.
1631541Srgrimes */
164262779Spfg#define	MINFREE		8
165262779Spfg#define	DEFAULTOPT	FS_OPTTIME
1661541Srgrimes
1671541Srgrimes/*
16875377Smckusick * Grigoriy Orlov <gluk@ptci.ru> has done some extensive work to fine
16975377Smckusick * tune the layout preferences for directories within a filesystem.
17075377Smckusick * His algorithm can be tuned by adjusting the following parameters
17175377Smckusick * which tell the system the average file size and the average number
17275377Smckusick * of files per directory. These defaults are well selected for typical
17375377Smckusick * filesystems, but may need to be tuned for odd cases like filesystems
174129895Skrion * being used for squid caches or news spools.
17575377Smckusick */
176262779Spfg#define	AVFILESIZ	16384	/* expected average file size */
177262779Spfg#define	AFPDIR		64	/* expected number of files per directory */
17875377Smckusick
17975377Smckusick/*
18062553Smckusick * The maximum number of snapshot nodes that can be associated
18162553Smckusick * with each filesystem. This limit affects only the number of
18262553Smckusick * snapshot files that can be recorded within the superblock so
18362553Smckusick * that they can be found when the filesystem is mounted. However,
18462553Smckusick * maintaining too many will slow the filesystem performance, so
18562553Smckusick * having this limit is a good idea.
18662553Smckusick */
187262779Spfg#define	FSMAXSNAP 20
18862553Smckusick
18962553Smckusick/*
19062553Smckusick * Used to identify special blocks in snapshots:
19162553Smckusick *
19262553Smckusick * BLK_NOCOPY - A block that was unallocated at the time the snapshot
19362553Smckusick *	was taken, hence does not need to be copied when written.
19462553Smckusick * BLK_SNAP - A block held by another snapshot that is not needed by this
19562553Smckusick *	snapshot. When the other snapshot is freed, the BLK_SNAP entries
19662553Smckusick *	are converted to BLK_NOCOPY. These are needed to allow fsck to
19762553Smckusick *	identify blocks that are in use by other snapshots (which are
19862553Smckusick *	expunged from this snapshot).
19962553Smckusick */
200262779Spfg#define	BLK_NOCOPY ((ufs2_daddr_t)(1))
201262779Spfg#define	BLK_SNAP ((ufs2_daddr_t)(2))
20262553Smckusick
20362553Smckusick/*
20474548Smckusick * Sysctl values for the fast filesystem.
20574548Smckusick */
20674548Smckusick#define	FFS_ADJ_REFCNT		 1	/* adjust inode reference count */
20774548Smckusick#define	FFS_ADJ_BLKCNT		 2	/* adjust inode used block count */
20874548Smckusick#define	FFS_BLK_FREE		 3	/* free range of blocks in map */
20974548Smckusick#define	FFS_DIR_FREE		 4	/* free specified dir inodes in map */
21074548Smckusick#define	FFS_FILE_FREE		 5	/* free specified file inodes in map */
21174548Smckusick#define	FFS_SET_FLAGS		 6	/* set filesystem flags */
212142123Sdelphij#define	FFS_ADJ_NDIR		 7	/* adjust number of directories */
213142123Sdelphij#define	FFS_ADJ_NBFREE		 8	/* adjust number of free blocks */
214142123Sdelphij#define	FFS_ADJ_NIFREE		 9	/* adjust number of free inodes */
215142123Sdelphij#define	FFS_ADJ_NFFREE		10 	/* adjust number of free frags */
216142123Sdelphij#define	FFS_ADJ_NUMCLUSTERS	11	/* adjust number of free clusters */
217262779Spfg#define	FFS_SET_CWD		12	/* set current directory */
218202113Smckusick#define	FFS_SET_DOTDOT		13	/* set inode number for ".." */
219202113Smckusick#define	FFS_UNLINK		14	/* remove a name in the filesystem */
220224061Smckusick#define	FFS_SET_INODE		15	/* update an on-disk inode */
221224061Smckusick#define	FFS_SET_BUFOUTPUT	16	/* set buffered writing on descriptor */
222224061Smckusick#define	FFS_MAXID		16	/* number of valid ffs ids */
22374548Smckusick
22474548Smckusick/*
22574548Smckusick * Command structure passed in to the filesystem to adjust filesystem values.
22674548Smckusick */
22798542Smckusick#define	FFS_CMD_VERSION		0x19790518	/* version ID */
22874548Smckusickstruct fsck_cmd {
22998542Smckusick	int32_t	version;	/* version of command structure */
23098542Smckusick	int32_t	handle;		/* reference to filesystem to be changed */
23198542Smckusick	int64_t	value;		/* inode or block number to be affected */
23298542Smckusick	int64_t	size;		/* amount or range to be adjusted */
23398542Smckusick	int64_t	spare;		/* reserved for future use */
23474548Smckusick};
23574548Smckusick
23674548Smckusick/*
237322860Smckusick * A recovery structure placed at the end of the boot block area by newfs
238322860Smckusick * that can be used by fsck to search for alternate superblocks.
239322860Smckusick */
240322860Smckusick#define RESID	(4096 - 20)	/* disk sector size minus recovery area size */
241322860Smckusickstruct fsrecovery {
242322860Smckusick	char	block[RESID];	/* unused part of sector */
243322860Smckusick	int32_t	fsr_magic;	/* magic number */
244322860Smckusick	int32_t	fsr_fsbtodb;	/* fsbtodb and dbtofsb shift constant */
245322860Smckusick	int32_t	fsr_sblkno;	/* offset of super-block in filesys */
246322860Smckusick	int32_t	fsr_fpg;	/* blocks per group * fs_frag */
247322860Smckusick	u_int32_t fsr_ncg;	/* number of cylinder groups */
248322860Smckusick};
249322860Smckusick
250322860Smckusick/*
2511541Srgrimes * Per cylinder group information; summarized in blocks allocated
2521541Srgrimes * from first cylinder group data blocks.  These blocks have to be
2531541Srgrimes * read in from fs_csaddr (size fs_cssize) in addition to the
2541541Srgrimes * super block.
2551541Srgrimes */
2561541Srgrimesstruct csum {
25722521Sdyson	int32_t	cs_ndir;		/* number of directories */
25822521Sdyson	int32_t	cs_nbfree;		/* number of free blocks */
25922521Sdyson	int32_t	cs_nifree;		/* number of free inodes */
26022521Sdyson	int32_t	cs_nffree;		/* number of free frags */
2611541Srgrimes};
26298542Smckusickstruct csum_total {
26398542Smckusick	int64_t	cs_ndir;		/* number of directories */
26498542Smckusick	int64_t	cs_nbfree;		/* number of free blocks */
26598542Smckusick	int64_t	cs_nifree;		/* number of free inodes */
26698542Smckusick	int64_t	cs_nffree;		/* number of free frags */
26798542Smckusick	int64_t	cs_numclusters;		/* number of free clusters */
26898542Smckusick	int64_t	cs_spare[3];		/* future expansion */
26998542Smckusick};
2701541Srgrimes
2711541Srgrimes/*
27296755Strhodes * Super block for an FFS filesystem.
2731541Srgrimes */
2741541Srgrimesstruct fs {
27596755Strhodes	int32_t	 fs_firstfield;		/* historic filesystem linked list, */
27622521Sdyson	int32_t	 fs_unused_1;		/*     used for incore super blocks */
27798542Smckusick	int32_t	 fs_sblkno;		/* offset of super-block in filesys */
27898542Smckusick	int32_t	 fs_cblkno;		/* offset of cyl-block in filesys */
27998542Smckusick	int32_t	 fs_iblkno;		/* offset of inode-blocks in filesys */
28098542Smckusick	int32_t	 fs_dblkno;		/* offset of first data after cg */
28198542Smckusick	int32_t	 fs_old_cgoffset;	/* cylinder group offset in cylinder */
28298542Smckusick	int32_t	 fs_old_cgmask;		/* used to calc mod fs_ntrak */
28398542Smckusick	int32_t  fs_old_time;		/* last time written */
28498542Smckusick	int32_t	 fs_old_size;		/* number of blocks in fs */
28598542Smckusick	int32_t	 fs_old_dsize;		/* number of data blocks in fs */
286203763Smckusick	u_int32_t fs_ncg;		/* number of cylinder groups */
28722521Sdyson	int32_t	 fs_bsize;		/* size of basic blocks in fs */
28822521Sdyson	int32_t	 fs_fsize;		/* size of frag blocks in fs */
28922521Sdyson	int32_t	 fs_frag;		/* number of frags in a block in fs */
2901541Srgrimes/* these are configuration parameters */
29122521Sdyson	int32_t	 fs_minfree;		/* minimum percentage of free blocks */
29298542Smckusick	int32_t	 fs_old_rotdelay;	/* num of ms for optimal next block */
29398542Smckusick	int32_t	 fs_old_rps;		/* disk revolutions per second */
2941541Srgrimes/* these fields can be computed from the others */
29522521Sdyson	int32_t	 fs_bmask;		/* ``blkoff'' calc of blk offsets */
29622521Sdyson	int32_t	 fs_fmask;		/* ``fragoff'' calc of frag offsets */
29722521Sdyson	int32_t	 fs_bshift;		/* ``lblkno'' calc of logical blkno */
29822521Sdyson	int32_t	 fs_fshift;		/* ``numfrags'' calc number of frags */
2991541Srgrimes/* these are configuration parameters */
30022521Sdyson	int32_t	 fs_maxcontig;		/* max number of contiguous blks */
30122521Sdyson	int32_t	 fs_maxbpg;		/* max number of blks per cyl group */
3021541Srgrimes/* these fields can be computed from the others */
30322521Sdyson	int32_t	 fs_fragshift;		/* block to frag shift */
30422521Sdyson	int32_t	 fs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
30522521Sdyson	int32_t	 fs_sbsize;		/* actual size of super block */
30698542Smckusick	int32_t	 fs_spare1[2];		/* old fs_csmask */
30798542Smckusick					/* old fs_csshift */
30822521Sdyson	int32_t	 fs_nindir;		/* value of NINDIR */
309203784Smckusick	u_int32_t fs_inopb;		/* value of INOPB */
31098542Smckusick	int32_t	 fs_old_nspf;		/* value of NSPF */
3111541Srgrimes/* yet another configuration parameter */
31222521Sdyson	int32_t	 fs_optim;		/* optimization preference, see below */
31398542Smckusick	int32_t	 fs_old_npsect;		/* # sectors/track including spares */
31498542Smckusick	int32_t	 fs_old_interleave;	/* hardware sector interleave */
31598542Smckusick	int32_t	 fs_old_trackskew;	/* sector 0 skew, per track */
31624171Sbde	int32_t	 fs_id[2];		/* unique filesystem id */
3171541Srgrimes/* sizes determined by number of cylinder groups and their sizes */
31898542Smckusick	int32_t	 fs_old_csaddr;		/* blk addr of cyl grp summary area */
31922521Sdyson	int32_t	 fs_cssize;		/* size of cyl grp summary area */
32022521Sdyson	int32_t	 fs_cgsize;		/* cylinder group size */
32198542Smckusick	int32_t	 fs_spare2;		/* old fs_ntrak */
32298542Smckusick	int32_t	 fs_old_nsect;		/* sectors per track */
32398542Smckusick	int32_t  fs_old_spc;		/* sectors per cylinder */
32498542Smckusick	int32_t	 fs_old_ncyl;		/* cylinders in filesystem */
32598542Smckusick	int32_t	 fs_old_cpg;		/* cylinders per group */
326203763Smckusick	u_int32_t fs_ipg;		/* inodes per group */
32798542Smckusick	int32_t	 fs_fpg;		/* blocks per group * fs_frag */
3281541Srgrimes/* this data must be re-computed after crashes */
32998542Smckusick	struct	csum fs_old_cstotal;	/* cylinder summary information */
3301541Srgrimes/* these fields are cleared at mount time */
33122521Sdyson	int8_t   fs_fmod;		/* super block modified flag */
33296755Strhodes	int8_t   fs_clean;		/* filesystem is clean flag */
33322521Sdyson	int8_t 	 fs_ronly;		/* mounted read-only flag */
334107294Smckusick	int8_t   fs_old_flags;		/* old FS_ flags */
33522521Sdyson	u_char	 fs_fsmnt[MAXMNTLEN];	/* name mounted on */
336108970Sgordon	u_char	 fs_volname[MAXVOLLEN];	/* volume name */
337109034Sgordon	u_int64_t fs_swuid;		/* system-wide uid */
338109053Smarcel	int32_t  fs_pad;		/* due to alignment of fs_swuid */
3391541Srgrimes/* these fields retain the current block allocation info */
34022521Sdyson	int32_t	 fs_cgrotor;		/* last cg searched */
34171073Siedowse	void 	*fs_ocsp[NOCSPTRS];	/* padding; was list of fs_cs buffers */
342140702Sjeff	u_int8_t *fs_contigdirs;	/* (u) # of contig. allocated dirs */
343140702Sjeff	struct	csum *fs_csp;		/* (u) cg summary info buffer */
344140702Sjeff	int32_t	*fs_maxcluster;		/* (u) max cluster in each cyl group */
345140702Sjeff	u_int	*fs_active;		/* (u) used by snapshots to track fs */
34698542Smckusick	int32_t	 fs_old_cpc;		/* cyl per cycle in postbl */
34798542Smckusick	int32_t	 fs_maxbsize;		/* maximum blocking factor permitted */
348163841Spjd	int64_t	 fs_unrefs;		/* number of unreferenced inodes */
349242379Strasz	int64_t  fs_providersize;	/* size of underlying GEOM provider */
350248623Smckusick	int64_t	 fs_metaspace;		/* size of area reserved for metadata */
351248623Smckusick	int64_t	 fs_sparecon64[14];	/* old rotation block list head */
352107294Smckusick	int64_t	 fs_sblockloc;		/* byte offset of standard superblock */
353140702Sjeff	struct	csum_total fs_cstotal;	/* (u) cylinder summary information */
35498542Smckusick	ufs_time_t fs_time;		/* last time written */
35598542Smckusick	int64_t	 fs_size;		/* number of blocks in fs */
35698542Smckusick	int64_t	 fs_dsize;		/* number of data blocks in fs */
35798542Smckusick	ufs2_daddr_t fs_csaddr;		/* blk addr of cyl grp summary area */
358140702Sjeff	int64_t	 fs_pendingblocks;	/* (u) blocks being freed */
359203763Smckusick	u_int32_t fs_pendinginodes;	/* (u) inodes being freed */
360227382Sgleb	uint32_t fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */
361203763Smckusick	u_int32_t fs_avgfilesize;	/* expected average file size */
362203763Smckusick	u_int32_t fs_avgfpdir;		/* expected # of files per directory */
36398542Smckusick	int32_t	 fs_save_cgsize;	/* save real cg size to use fs_bsize */
364207141Sjeff	ufs_time_t fs_mtime;		/* Last mount or fsck time. */
365207141Sjeff	int32_t  fs_sujfree;		/* SUJ free list */
366207141Sjeff	int32_t	 fs_sparecon32[23];	/* reserved for future constants */
367107294Smckusick	int32_t  fs_flags;		/* see FS_ flags below */
36822521Sdyson	int32_t	 fs_contigsumsize;	/* size of cluster summary array */
36922521Sdyson	int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */
37098542Smckusick	int32_t	 fs_old_inodefmt;	/* format of on-disk inodes */
37122521Sdyson	u_int64_t fs_maxfilesize;	/* maximum representable file size */
37222521Sdyson	int64_t	 fs_qbmask;		/* ~fs_bmask for use with 64-bit size */
37322521Sdyson	int64_t	 fs_qfmask;		/* ~fs_fmask for use with 64-bit size */
37422521Sdyson	int32_t	 fs_state;		/* validate fs_clean field */
37598542Smckusick	int32_t	 fs_old_postblformat;	/* format of positional layout tables */
37698542Smckusick	int32_t	 fs_old_nrpos;		/* number of rotational positions */
37798542Smckusick	int32_t	 fs_spare5[2];		/* old fs_postbloff */
37898542Smckusick					/* old fs_rotbloff */
37922521Sdyson	int32_t	 fs_magic;		/* magic number */
3801541Srgrimes};
38122521Sdyson
382109053Smarcel/* Sanity checking. */
383109053Smarcel#ifdef CTASSERT
384109053SmarcelCTASSERT(sizeof(struct fs) == 1376);
385109053Smarcel#endif
386109053Smarcel
3871541Srgrimes/*
38813765Smpp * Filesystem identification
3891541Srgrimes */
39098542Smckusick#define	FS_UFS1_MAGIC	0x011954	/* UFS1 fast filesystem magic number */
39198542Smckusick#define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast filesystem magic number */
392134011Sjhb#define	FS_BAD_MAGIC	0x19960408	/* UFS incomplete newfs magic number */
3931541Srgrimes#define	FS_OKAY		0x7c269d38	/* superblock checksum */
394262779Spfg#define	FS_42INODEFMT	-1		/* 4.2BSD inode format */
395262779Spfg#define	FS_44INODEFMT	2		/* 4.4BSD inode format */
39634266Sjulian
3971541Srgrimes/*
3981541Srgrimes * Preference for optimization.
3991541Srgrimes */
400262779Spfg#define	FS_OPTTIME	0	/* minimize allocation time */
401262779Spfg#define	FS_OPTSPACE	1	/* minimize disk fragmentation */
4021541Srgrimes
4031541Srgrimes/*
40434266Sjulian * Filesystem flags.
40575503Smckusick *
40698542Smckusick * The FS_UNCLEAN flag is set by the kernel when the filesystem was
40798542Smckusick * mounted with fs_clean set to zero. The FS_DOSOFTDEP flag indicates
40898542Smckusick * that the filesystem should be managed by the soft updates code.
40975503Smckusick * Note that the FS_NEEDSFSCK flag is set and cleared only by the
41075503Smckusick * fsck utility. It is set when background fsck finds an unexpected
41175503Smckusick * inconsistency which requires a traditional foreground fsck to be
41275503Smckusick * run. Such inconsistencies should only be found after an uncorrectable
41375503Smckusick * disk error. A foreground fsck will clear the FS_NEEDSFSCK flag when
41475503Smckusick * it has successfully cleaned up the filesystem. The kernel uses this
41575503Smckusick * flag to enforce that inconsistent filesystems be mounted read-only.
41698542Smckusick * The FS_INDEXDIRS flag when set indicates that the kernel maintains
41798542Smckusick * on-disk auxiliary indexes (such as B-trees) for speeding directory
41898542Smckusick * accesses. Kernels that do not support auxiliary indicies clear the
41998542Smckusick * flag to indicate that the indicies need to be rebuilt (by fsck) before
42098542Smckusick * they can be used.
421105112Srwatson *
422200796Strasz * FS_ACLS indicates that POSIX.1e ACLs are administratively enabled
423200796Strasz * for the file system, so they should be loaded from extended attributes,
424105112Srwatson * observed for access control purposes, and be administered by object
425200796Strasz * owners.  FS_NFS4ACLS indicates that NFSv4 ACLs are administratively
426200796Strasz * enabled.  This flag is mutually exclusive with FS_ACLS.  FS_MULTILABEL
427200796Strasz * indicates that the TrustedBSD MAC Framework should attempt to back MAC
428200796Strasz * labels into extended attributes on the file system rather than maintain
429200796Strasz * a single mount label for all objects.
43034266Sjulian */
431262779Spfg#define	FS_UNCLEAN	0x0001	/* filesystem not clean at mount */
432262779Spfg#define	FS_DOSOFTDEP	0x0002	/* filesystem using soft dependencies */
433262779Spfg#define	FS_NEEDSFSCK	0x0004	/* filesystem needs sync fsck before mount */
434207141Sjeff#define	FS_SUJ       	0x0008	/* Filesystem using softupdate journal */
435262779Spfg#define	FS_ACLS		0x0010	/* file system has POSIX.1e ACLs enabled */
436262779Spfg#define	FS_MULTILABEL	0x0020	/* file system is MAC multi-label */
437262779Spfg#define	FS_GJOURNAL	0x0040	/* gjournaled file system */
438262779Spfg#define	FS_FLAGS_UPDATED 0x0080	/* flags have been moved to new location */
439262779Spfg#define	FS_NFS4ACLS	0x0100	/* file system has NFSv4 ACLs enabled */
440262779Spfg#define	FS_INDEXDIRS	0x0200	/* kernel supports indexed directories */
441216796Skib#define	FS_TRIM		0x0400	/* issue BIO_DELETE for deleted blocks */
44234266Sjulian
44334266Sjulian/*
44488138Smckusick * Macros to access bits in the fs_active array.
44588138Smckusick */
44688138Smckusick#define	ACTIVECGNUM(fs, cg)	((fs)->fs_active[(cg) / (NBBY * sizeof(int))])
44789450Smckusick#define	ACTIVECGOFF(cg)		(1 << ((cg) % (NBBY * sizeof(int))))
448140702Sjeff#define	ACTIVESET(fs, cg)	do {					\
449140702Sjeff	if ((fs)->fs_active)						\
450140702Sjeff		ACTIVECGNUM((fs), (cg)) |= ACTIVECGOFF((cg));		\
451140702Sjeff} while (0)
452140702Sjeff#define	ACTIVECLEAR(fs, cg)	do {					\
453140702Sjeff	if ((fs)->fs_active)						\
454140702Sjeff		ACTIVECGNUM((fs), (cg)) &= ~ACTIVECGOFF((cg));		\
455140702Sjeff} while (0)
45688138Smckusick
45788138Smckusick/*
4581541Srgrimes * The size of a cylinder group is calculated by CGSIZE. The maximum size
4591541Srgrimes * is limited by the fact that cylinder groups are at most one block.
4608876Srgrimes * Its size is derived from the size of the maps maintained in the
4611541Srgrimes * cylinder group and the (struct cg) size.
4621541Srgrimes */
463262779Spfg#define	CGSIZE(fs) \
46422521Sdyson    /* base cg */	(sizeof(struct cg) + sizeof(int32_t) + \
46598542Smckusick    /* old btotoff */	(fs)->fs_old_cpg * sizeof(int32_t) + \
46698542Smckusick    /* old boff */	(fs)->fs_old_cpg * sizeof(u_int16_t) + \
4671541Srgrimes    /* inode map */	howmany((fs)->fs_ipg, NBBY) + \
46898542Smckusick    /* block map */	howmany((fs)->fs_fpg, NBBY) +\
4691541Srgrimes    /* if present */	((fs)->fs_contigsumsize <= 0 ? 0 : \
47022521Sdyson    /* cluster sum */	(fs)->fs_contigsumsize * sizeof(int32_t) + \
47198542Smckusick    /* cluster map */	howmany(fragstoblks(fs, (fs)->fs_fpg), NBBY)))
4721541Srgrimes
4731541Srgrimes/*
47498542Smckusick * The minimal number of cylinder groups that should be created.
47598542Smckusick */
476262779Spfg#define	MINCYLGRPS	4
47798542Smckusick
47898542Smckusick/*
4791541Srgrimes * Convert cylinder group to base address of its global summary info.
4801541Srgrimes */
481262779Spfg#define	fs_cs(fs, indx) fs_csp[indx]
4821541Srgrimes
4831541Srgrimes/*
48496755Strhodes * Cylinder group block for a filesystem.
4851541Srgrimes */
4861541Srgrimes#define	CG_MAGIC	0x090255
48722521Sdysonstruct cg {
48822521Sdyson	int32_t	 cg_firstfield;		/* historic cyl groups linked list */
48922521Sdyson	int32_t	 cg_magic;		/* magic number */
49098542Smckusick	int32_t  cg_old_time;		/* time last written */
491203763Smckusick	u_int32_t cg_cgx;		/* we are the cgx'th cylinder group */
49298542Smckusick	int16_t	 cg_old_ncyl;		/* number of cyl's this cg */
49398542Smckusick	int16_t  cg_old_niblk;		/* number of inode blocks this cg */
494203763Smckusick	u_int32_t cg_ndblk;		/* number of data blocks this cg */
495203763Smckusick	struct	 csum cg_cs;		/* cylinder summary information */
496203763Smckusick	u_int32_t cg_rotor;		/* position of last used block */
497203763Smckusick	u_int32_t cg_frotor;		/* position of last used frag */
498203763Smckusick	u_int32_t cg_irotor;		/* position of last used inode */
499203763Smckusick	u_int32_t cg_frsum[MAXFRAG];	/* counts of available frags */
50098542Smckusick	int32_t	 cg_old_btotoff;	/* (int32) block totals per cylinder */
50198542Smckusick	int32_t	 cg_old_boff;		/* (u_int16) free block positions */
502203763Smckusick	u_int32_t cg_iusedoff;		/* (u_int8) used inode map */
503203763Smckusick	u_int32_t cg_freeoff;		/* (u_int8) free block map */
504203763Smckusick	u_int32_t cg_nextfreeoff;	/* (u_int8) next available space */
505203763Smckusick	u_int32_t cg_clustersumoff;	/* (u_int32) counts of avail clusters */
506203763Smckusick	u_int32_t cg_clusteroff;		/* (u_int8) free cluster map */
507203763Smckusick	u_int32_t cg_nclusterblks;	/* number of clusters this cg */
508203763Smckusick	u_int32_t cg_niblk;		/* number of inode blocks this cg */
509203763Smckusick	u_int32_t cg_initediblk;		/* last initialized inode */
510203763Smckusick	u_int32_t cg_unrefs;		/* number of unreferenced inodes */
511163841Spjd	int32_t	 cg_sparecon32[2];	/* reserved for future use */
51298542Smckusick	ufs_time_t cg_time;		/* time last written */
51398542Smckusick	int64_t	 cg_sparecon64[3];	/* reserved for future use */
51422521Sdyson	u_int8_t cg_space[1];		/* space for cylinder group maps */
5151541Srgrimes/* actually longer */
5161541Srgrimes};
51722521Sdyson
5181541Srgrimes/*
5191541Srgrimes * Macros for access to cylinder group array structures
5201541Srgrimes */
521262779Spfg#define	cg_chkmagic(cgp) ((cgp)->cg_magic == CG_MAGIC)
522262779Spfg#define	cg_inosused(cgp) \
52398542Smckusick    ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_iusedoff))
524262779Spfg#define	cg_blksfree(cgp) \
52598542Smckusick    ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_freeoff))
526262779Spfg#define	cg_clustersfree(cgp) \
52722521Sdyson    ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_clusteroff))
528262779Spfg#define	cg_clustersum(cgp) \
529127818Smux    ((int32_t *)((uintptr_t)(cgp) + (cgp)->cg_clustersumoff))
5301541Srgrimes
5311541Srgrimes/*
53296755Strhodes * Turn filesystem block numbers into disk block addresses.
53396755Strhodes * This maps filesystem blocks to device size blocks.
5341541Srgrimes */
535136336Snjl#define	fsbtodb(fs, b)	((daddr_t)(b) << (fs)->fs_fsbtodb)
5361541Srgrimes#define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)
5371541Srgrimes
5381541Srgrimes/*
5391541Srgrimes * Cylinder group macros to locate things in cylinder groups.
54096755Strhodes * They calc filesystem addresses of cylinder group data structures.
5411541Srgrimes */
542111238Smckusick#define	cgbase(fs, c)	(((ufs2_daddr_t)(fs)->fs_fpg) * (c))
543248623Smckusick#define	cgdata(fs, c)	(cgdmin(fs, c) + (fs)->fs_metaspace)	/* data zone */
544248623Smckusick#define	cgmeta(fs, c)	(cgdmin(fs, c))				/* meta data */
5451541Srgrimes#define	cgdmin(fs, c)	(cgstart(fs, c) + (fs)->fs_dblkno)	/* 1st data */
5461541Srgrimes#define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno)	/* inode blk */
5471541Srgrimes#define	cgsblock(fs, c)	(cgstart(fs, c) + (fs)->fs_sblkno)	/* super blk */
5481541Srgrimes#define	cgtod(fs, c)	(cgstart(fs, c) + (fs)->fs_cblkno)	/* cg block */
549262779Spfg#define	cgstart(fs, c)							\
55098542Smckusick       ((fs)->fs_magic == FS_UFS2_MAGIC ? cgbase(fs, c) :		\
55198542Smckusick       (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask))))
5521541Srgrimes
5531541Srgrimes/*
5541541Srgrimes * Macros for handling inode numbers:
55596755Strhodes *     inode number to filesystem block offset.
5561541Srgrimes *     inode number to cylinder group number.
55796755Strhodes *     inode number to filesystem block address.
5581541Srgrimes */
559203763Smckusick#define	ino_to_cg(fs, x)	(((ino_t)(x)) / (fs)->fs_ipg)
5601541Srgrimes#define	ino_to_fsba(fs, x)						\
561203763Smckusick	((ufs2_daddr_t)(cgimin(fs, ino_to_cg(fs, (ino_t)(x))) +		\
562203763Smckusick	    (blkstofrags((fs), ((((ino_t)(x)) % (fs)->fs_ipg) / INOPB(fs))))))
563203763Smckusick#define	ino_to_fsbo(fs, x)	(((ino_t)(x)) % INOPB(fs))
5641541Srgrimes
5651541Srgrimes/*
56696755Strhodes * Give cylinder group number for a filesystem block.
56796755Strhodes * Give cylinder group block number for a filesystem block.
5681541Srgrimes */
5691541Srgrimes#define	dtog(fs, d)	((d) / (fs)->fs_fpg)
5701541Srgrimes#define	dtogd(fs, d)	((d) % (fs)->fs_fpg)
5711541Srgrimes
5721541Srgrimes/*
5731541Srgrimes * Extract the bits for a block from a map.
5741541Srgrimes * Compute the cylinder and rotational position of a cyl block addr.
5751541Srgrimes */
576262779Spfg#define	blkmap(fs, map, loc) \
5771541Srgrimes    (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
5781541Srgrimes
5791541Srgrimes/*
5801541Srgrimes * The following macros optimize certain frequently calculated
5811541Srgrimes * quantities by using shifts and masks in place of divisions
5821541Srgrimes * modulos and multiplications.
5831541Srgrimes */
584262779Spfg#define	blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
5851541Srgrimes	((loc) & (fs)->fs_qbmask)
586262779Spfg#define	fragoff(fs, loc)	/* calculates (loc % fs->fs_fsize) */ \
5871541Srgrimes	((loc) & (fs)->fs_qfmask)
588262779Spfg#define	lfragtosize(fs, frag)	/* calculates ((off_t)frag * fs->fs_fsize) */ \
589111238Smckusick	(((off_t)(frag)) << (fs)->fs_fshift)
590262779Spfg#define	lblktosize(fs, blk)	/* calculates ((off_t)blk * fs->fs_bsize) */ \
591111238Smckusick	(((off_t)(blk)) << (fs)->fs_bshift)
59218899Sbde/* Use this only when `blk' is known to be small, e.g., < NDADDR. */
593262779Spfg#define	smalllblktosize(fs, blk)    /* calculates (blk * fs->fs_bsize) */ \
5941541Srgrimes	((blk) << (fs)->fs_bshift)
595262779Spfg#define	lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
5961541Srgrimes	((loc) >> (fs)->fs_bshift)
597262779Spfg#define	numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
5981541Srgrimes	((loc) >> (fs)->fs_fshift)
599262779Spfg#define	blkroundup(fs, size)	/* calculates roundup(size, fs->fs_bsize) */ \
6001541Srgrimes	(((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)
601262779Spfg#define	fragroundup(fs, size)	/* calculates roundup(size, fs->fs_fsize) */ \
6021541Srgrimes	(((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
603262779Spfg#define	fragstoblks(fs, frags)	/* calculates (frags / fs->fs_frag) */ \
6041541Srgrimes	((frags) >> (fs)->fs_fragshift)
605262779Spfg#define	blkstofrags(fs, blks)	/* calculates (blks * fs->fs_frag) */ \
6061541Srgrimes	((blks) << (fs)->fs_fragshift)
607262779Spfg#define	fragnum(fs, fsb)	/* calculates (fsb % fs->fs_frag) */ \
6081541Srgrimes	((fsb) & ((fs)->fs_frag - 1))
609262779Spfg#define	blknum(fs, fsb)		/* calculates rounddown(fsb, fs->fs_frag) */ \
6101541Srgrimes	((fsb) &~ ((fs)->fs_frag - 1))
6111541Srgrimes
6121541Srgrimes/*
6131541Srgrimes * Determine the number of available frags given a
61422521Sdyson * percentage to hold in reserve.
6151541Srgrimes */
616262779Spfg#define	freespace(fs, percentreserved) \
6171541Srgrimes	(blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
61858155Smckusick	(fs)->fs_cstotal.cs_nffree - \
619111238Smckusick	(((off_t)((fs)->fs_dsize)) * (percentreserved) / 100))
6201541Srgrimes
6211541Srgrimes/*
62296755Strhodes * Determining the size of a file block in the filesystem.
6231541Srgrimes */
624262779Spfg#define	blksize(fs, ip, lbn) \
62518899Sbde	(((lbn) >= NDADDR || (ip)->i_size >= smalllblktosize(fs, (lbn) + 1)) \
6261541Srgrimes	    ? (fs)->fs_bsize \
6271541Srgrimes	    : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
628262779Spfg#define	sblksize(fs, size, lbn) \
62934266Sjulian	(((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \
63034266Sjulian	  ? (fs)->fs_bsize \
63134266Sjulian	  : (fragroundup(fs, blkoff(fs, (size)))))
6321541Srgrimes
6331541Srgrimes/*
634215113Skib * Number of indirects in a filesystem block.
635215113Skib */
636215113Skib#define	NINDIR(fs)	((fs)->fs_nindir)
637215113Skib
638215113Skib/*
639207141Sjeff * Indirect lbns are aligned on NDADDR addresses where single indirects
640207141Sjeff * are the negated address of the lowest lbn reachable, double indirects
641207141Sjeff * are this lbn - 1 and triple indirects are this lbn - 2.  This yields
642207141Sjeff * an unusual bit order to determine level.
643207141Sjeff */
644207141Sjeffstatic inline int
645207141Sjefflbn_level(ufs_lbn_t lbn)
646207141Sjeff{
647207141Sjeff	if (lbn >= 0)
648207141Sjeff		return 0;
649207141Sjeff	switch (lbn & 0x3) {
650207141Sjeff	case 0:
651207141Sjeff		return (0);
652207141Sjeff	case 1:
653207141Sjeff		break;
654207141Sjeff	case 2:
655207141Sjeff		return (2);
656207141Sjeff	case 3:
657207141Sjeff		return (1);
658207141Sjeff	default:
659207141Sjeff		break;
660207141Sjeff	}
661207141Sjeff	return (-1);
662207141Sjeff}
663215113Skib
664215113Skibstatic inline ufs_lbn_t
665215113Skiblbn_offset(struct fs *fs, int level)
666215113Skib{
667215113Skib	ufs_lbn_t res;
668215113Skib
669215113Skib	for (res = 1; level > 0; level--)
670215113Skib		res *= NINDIR(fs);
671215113Skib	return (res);
672215113Skib}
673215113Skib
674207141Sjeff/*
67522521Sdyson * Number of inodes in a secondary storage block/fragment.
6761541Srgrimes */
6771541Srgrimes#define	INOPB(fs)	((fs)->fs_inopb)
6781541Srgrimes#define	INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)
6791541Srgrimes
6801541Srgrimes/*
681207141Sjeff * Softdep journal record format.
682207141Sjeff */
683207141Sjeff
684207141Sjeff#define	JOP_ADDREF	1	/* Add a reference to an inode. */
685207141Sjeff#define	JOP_REMREF	2	/* Remove a reference from an inode. */
686207141Sjeff#define	JOP_NEWBLK	3	/* Allocate a block. */
687207141Sjeff#define	JOP_FREEBLK	4	/* Free a block or a tree of blocks. */
688207141Sjeff#define	JOP_MVREF	5	/* Move a reference from one off to another. */
689207141Sjeff#define	JOP_TRUNC	6	/* Partial truncation record. */
690222958Sjeff#define	JOP_SYNC	7	/* fsync() complete record. */
691207141Sjeff
692207141Sjeff#define	JREC_SIZE	32	/* Record and segment header size. */
693207141Sjeff
694207141Sjeff#define	SUJ_MIN		(4 * 1024 * 1024)	/* Minimum journal size */
695207141Sjeff#define	SUJ_MAX		(32 * 1024 * 1024)	/* Maximum journal size */
696207141Sjeff#define	SUJ_FILE	".sujournal"		/* Journal file name */
697207141Sjeff
698207141Sjeff/*
699207141Sjeff * Size of the segment record header.  There is at most one for each disk
700212617Smckusick * block in the journal.  The segment header is followed by an array of
701207141Sjeff * records.  fsck depends on the first element in each record being 'op'
702207141Sjeff * and the second being 'ino'.  Segments may span multiple disk blocks but
703207141Sjeff * the header is present on each.
704207141Sjeff */
705207141Sjeffstruct jsegrec {
706207141Sjeff	uint64_t	jsr_seq;	/* Our sequence number */
707207141Sjeff	uint64_t	jsr_oldest;	/* Oldest valid sequence number */
708207141Sjeff	uint16_t	jsr_cnt;	/* Count of valid records */
709218602Skib	uint16_t	jsr_blocks;	/* Count of device bsize blocks. */
710207141Sjeff	uint32_t	jsr_crc;	/* 32bit crc of the valid space */
711207141Sjeff	ufs_time_t	jsr_time;	/* timestamp for mount instance */
712207141Sjeff};
713207141Sjeff
714207141Sjeff/*
715207141Sjeff * Reference record.  Records a single link count modification.
716207141Sjeff */
717207141Sjeffstruct jrefrec {
718207141Sjeff	uint32_t	jr_op;
719227382Sgleb	uint32_t	jr_ino;
720227382Sgleb	uint32_t	jr_parent;
721207141Sjeff	uint16_t	jr_nlink;
722207141Sjeff	uint16_t	jr_mode;
723227382Sgleb	int64_t		jr_diroff;
724207141Sjeff	uint64_t	jr_unused;
725207141Sjeff};
726207141Sjeff
727207141Sjeff/*
728207141Sjeff * Move record.  Records a reference moving within a directory block.  The
729207141Sjeff * nlink is unchanged but we must search both locations.
730207141Sjeff */
731207141Sjeffstruct jmvrec {
732207141Sjeff	uint32_t	jm_op;
733227382Sgleb	uint32_t	jm_ino;
734227382Sgleb	uint32_t	jm_parent;
735207141Sjeff	uint16_t	jm_unused;
736227382Sgleb	int64_t		jm_oldoff;
737227382Sgleb	int64_t		jm_newoff;
738207141Sjeff};
739207141Sjeff
740207141Sjeff/*
741207141Sjeff * Block record.  A set of frags or tree of blocks starting at an indirect are
742207141Sjeff * freed or a set of frags are allocated.
743207141Sjeff */
744207141Sjeffstruct jblkrec {
745207141Sjeff	uint32_t	jb_op;
746207141Sjeff	uint32_t	jb_ino;
747207141Sjeff	ufs2_daddr_t	jb_blkno;
748207141Sjeff	ufs_lbn_t	jb_lbn;
749207141Sjeff	uint16_t	jb_frags;
750207141Sjeff	uint16_t	jb_oldfrags;
751207141Sjeff	uint32_t	jb_unused;
752207141Sjeff};
753207141Sjeff
754207141Sjeff/*
755207141Sjeff * Truncation record.  Records a partial truncation so that it may be
756222958Sjeff * completed at check time.  Also used for sync records.
757207141Sjeff */
758207141Sjeffstruct jtrncrec {
759207141Sjeff	uint32_t	jt_op;
760207141Sjeff	uint32_t	jt_ino;
761227382Sgleb	int64_t		jt_size;
762207141Sjeff	uint32_t	jt_extsize;
763207141Sjeff	uint32_t	jt_pad[3];
764207141Sjeff};
765207141Sjeff
766207141Sjeffunion jrec {
767207141Sjeff	struct jsegrec	rec_jsegrec;
768207141Sjeff	struct jrefrec	rec_jrefrec;
769207141Sjeff	struct jmvrec	rec_jmvrec;
770207141Sjeff	struct jblkrec	rec_jblkrec;
771207141Sjeff	struct jtrncrec	rec_jtrncrec;
772207141Sjeff};
773207141Sjeff
774207141Sjeff#ifdef CTASSERT
775207141SjeffCTASSERT(sizeof(struct jsegrec) == JREC_SIZE);
776207141SjeffCTASSERT(sizeof(struct jrefrec) == JREC_SIZE);
777207141SjeffCTASSERT(sizeof(struct jmvrec) == JREC_SIZE);
778207141SjeffCTASSERT(sizeof(struct jblkrec) == JREC_SIZE);
779207141SjeffCTASSERT(sizeof(struct jtrncrec) == JREC_SIZE);
780207141SjeffCTASSERT(sizeof(union jrec) == JREC_SIZE);
781207141Sjeff#endif
782207141Sjeff
7831541Srgrimesextern int inside[], around[];
7841541Srgrimesextern u_char *fragtbl[];
7852176Spaul
786243245Strasz/*
787243245Strasz * IOCTLs used for filesystem write suspension.
788243245Strasz */
789243245Strasz#define	UFSSUSPEND	_IOW('U', 1, fsid_t)
790243245Strasz#define	UFSRESUME	_IO('U', 2)
791243245Strasz
7922176Spaul#endif
793