xref: /freebsd/sys/ufs/ffs/fs.h (revision 661ca921e8cd56b17fc6615bc7e596e56e0e7c31)
160727d8bSWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1993
5df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6df8bae1dSRodney W. Grimes  *
7df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
8df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
9df8bae1dSRodney W. Grimes  * are met:
10df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
12df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
13df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
14df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15949b56baSWarner Losh  * 3. Neither the name of the University nor the names of its contributors
16df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
17df8bae1dSRodney W. Grimes  *    without specific prior written permission.
18df8bae1dSRodney W. Grimes  *
19df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
30df8bae1dSRodney W. Grimes  */
31df8bae1dSRodney W. Grimes 
32eb9fb78cSPaul Richards #ifndef _UFS_FFS_FS_H_
33eb9fb78cSPaul Richards #define	_UFS_FFS_FS_H_
34eb9fb78cSPaul Richards 
351848286aSEdward Tomasz Napierala #include <sys/mount.h>
36213a71c6SEdward Tomasz Napierala #include <ufs/ufs/dinode.h>
371848286aSEdward Tomasz Napierala 
38df8bae1dSRodney W. Grimes /*
39df8bae1dSRodney W. Grimes  * Each disk drive contains some number of filesystems.
40df8bae1dSRodney W. Grimes  * A filesystem consists of a number of cylinder groups.
41df8bae1dSRodney W. Grimes  * Each cylinder group has inodes and data.
42df8bae1dSRodney W. Grimes  *
43df8bae1dSRodney W. Grimes  * A filesystem is described by its super-block, which in turn
44df8bae1dSRodney W. Grimes  * describes the cylinder groups.  The super-block is critical
45df8bae1dSRodney W. Grimes  * data and is replicated in each cylinder group to protect against
46df8bae1dSRodney W. Grimes  * catastrophic loss.  This is done at `newfs' time and the critical
47df8bae1dSRodney W. Grimes  * super-block data does not change, so the copies need not be
48df8bae1dSRodney W. Grimes  * referenced further unless disaster strikes.
49df8bae1dSRodney W. Grimes  *
50df8bae1dSRodney W. Grimes  * For filesystem fs, the offsets of the various blocks of interest
51df8bae1dSRodney W. Grimes  * are given in the super block as:
52df8bae1dSRodney W. Grimes  *	[fs->fs_sblkno]		Super-block
53df8bae1dSRodney W. Grimes  *	[fs->fs_cblkno]		Cylinder group block
54df8bae1dSRodney W. Grimes  *	[fs->fs_iblkno]		Inode blocks
55df8bae1dSRodney W. Grimes  *	[fs->fs_dblkno]		Data blocks
56df8bae1dSRodney W. Grimes  * The beginning of cylinder group cg in fs, is given by
57df8bae1dSRodney W. Grimes  * the ``cgbase(fs, cg)'' macro.
58df8bae1dSRodney W. Grimes  *
591c85e6a3SKirk McKusick  * Depending on the architecture and the media, the superblock may
601c85e6a3SKirk McKusick  * reside in any one of four places. For tiny media where every block
611c85e6a3SKirk McKusick  * counts, it is placed at the very front of the partition. Historically,
621c85e6a3SKirk McKusick  * UFS1 placed it 8K from the front to leave room for the disk label and
631c85e6a3SKirk McKusick  * a small bootstrap. For UFS2 it got moved to 64K from the front to leave
641c85e6a3SKirk McKusick  * room for the disk label and a bigger bootstrap, and for really piggy
651c85e6a3SKirk McKusick  * systems we check at 256K from the front if the first three fail. In
661c85e6a3SKirk McKusick  * all cases the size of the superblock will be SBLOCKSIZE. All values are
671c85e6a3SKirk McKusick  * given in byte-offset form, so they do not imply a sector size. The
681c85e6a3SKirk McKusick  * SBLOCKSEARCH specifies the order in which the locations should be searched.
69df8bae1dSRodney W. Grimes  */
701c85e6a3SKirk McKusick #define	SBLOCK_FLOPPY	     0
711c85e6a3SKirk McKusick #define	SBLOCK_UFS1	  8192
721c85e6a3SKirk McKusick #define	SBLOCK_UFS2	 65536
731c85e6a3SKirk McKusick #define	SBLOCK_PIGGY	262144
741c85e6a3SKirk McKusick #define	SBLOCKSIZE	  8192
751c85e6a3SKirk McKusick #define	SBLOCKSEARCH \
761c85e6a3SKirk McKusick 	{ SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
77b366ee48SKirk McKusick /*
78b366ee48SKirk McKusick  * Request standard superblock location in ffs_sbget().
79b366ee48SKirk McKusick  */
80b21582eeSKirk McKusick #define	UFS_STDSB	-1	/* Search standard places for superblock */
81b21582eeSKirk McKusick 
82b21582eeSKirk McKusick /*
83b21582eeSKirk McKusick  * UFS_NOMSG indicates that superblock inconsistency error messages
84b21582eeSKirk McKusick  *    should not be printed. It is used by programs like fsck that
85b21582eeSKirk McKusick  *    want to print their own error message.
86b21582eeSKirk McKusick  *
87b21582eeSKirk McKusick  * UFS_NOCSUM causes only the superblock itself to be returned, but does
88b21582eeSKirk McKusick  *    not read in any auxiliary data structures like the cylinder group
89b21582eeSKirk McKusick  *    summary information. It is used by clients like glabel that just
90b21582eeSKirk McKusick  *    want to check for possible filesystem types. Using UFS_NOCSUM
91b21582eeSKirk McKusick  *    skips the superblock checks for csum data which allows superblocks
92b21582eeSKirk McKusick  *    that have corrupted csum data to be read and used.
93b21582eeSKirk McKusick  *
94b21582eeSKirk McKusick  * UFS_NOHASHFAIL will note that the check hash is wrong but will still
95b21582eeSKirk McKusick  *    return the superblock. This is used by the bootstrap code to
96b21582eeSKirk McKusick  *    give the system a chance to come up so that fsck can be run to
97b21582eeSKirk McKusick  *    correct the problem.
98d22531d5SKirk McKusick  *
99d22531d5SKirk McKusick  * UFS_NOWARNFAIL will warn about inconsistencies but still return the
100d22531d5SKirk McKusick  *    superblock. It includes UFS_NOHASHFAIL. UFS_NOWARNFAIL is used by
101d22531d5SKirk McKusick  *    programs like fsck_ffs(8) to debug broken filesystems.
102e6886616SKirk McKusick  *
103e6886616SKirk McKusick  * UFS_FSRONLY will only validate the superblock fields needed to
104e6886616SKirk McKusick  *    calculate where the backup filesystem superblocks are located.
105e6886616SKirk McKusick  *    If these values pass their validation tests, then the superblock
106e6886616SKirk McKusick  *    is returned. This flag is used as part of the attempt to find
107e6886616SKirk McKusick  *    alternate superblocks when using ffs_sbsearch().
108b21582eeSKirk McKusick  */
109b21582eeSKirk McKusick #define	UFS_NOHASHFAIL	0x0001	/* Ignore check-hash failure */
110d22531d5SKirk McKusick #define	UFS_NOWARNFAIL	0x0003	/* Ignore non-fatal inconsistencies */
111b21582eeSKirk McKusick #define	UFS_NOMSG	0x0004	/* Print no error message */
112b21582eeSKirk McKusick #define	UFS_NOCSUM	0x0008	/* Read just the superblock without csum */
113e6886616SKirk McKusick #define	UFS_FSRONLY	0x0010	/* Validate only values needed for recovery
114e6886616SKirk McKusick 				   of alternate superblocks */
115b21582eeSKirk McKusick #define	UFS_ALTSBLK	0x1000	/* Flag used internally */
116df8bae1dSRodney W. Grimes 
1171c85e6a3SKirk McKusick /*
1181c85e6a3SKirk McKusick  * Max number of fragments per block. This value is NOT tweakable.
1191c85e6a3SKirk McKusick  */
120a463023dSPoul-Henning Kamp #define	MAXFRAG 	8
1211c85e6a3SKirk McKusick 
122df8bae1dSRodney W. Grimes /*
123df8bae1dSRodney W. Grimes  * Addresses stored in inodes are capable of addressing fragments
124df8bae1dSRodney W. Grimes  * of `blocks'. File system blocks of at most size MAXBSIZE can
125df8bae1dSRodney W. Grimes  * be optionally broken into 2, 4, or 8 pieces, each of which is
1266c5e9bbdSMike Pritchard  * addressable; these pieces may be DEV_BSIZE, or some multiple of
127df8bae1dSRodney W. Grimes  * a DEV_BSIZE unit.
128df8bae1dSRodney W. Grimes  *
129df8bae1dSRodney W. Grimes  * Large files consist of exclusively large data blocks.  To avoid
130df8bae1dSRodney W. Grimes  * undue wasted disk space, the last data block of a small file may be
131df8bae1dSRodney W. Grimes  * allocated as only as many fragments of a large block as are
132df8bae1dSRodney W. Grimes  * necessary.  The filesystem format retains only a single pointer
133df8bae1dSRodney W. Grimes  * to such a fragment, which is a piece of a single large block that
134df8bae1dSRodney W. Grimes  * has been divided.  The size of such a fragment is determinable from
135df8bae1dSRodney W. Grimes  * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
136df8bae1dSRodney W. Grimes  *
137df8bae1dSRodney W. Grimes  * The filesystem records space availability at the fragment level;
138df8bae1dSRodney W. Grimes  * to determine block availability, aligned fragments are examined.
139df8bae1dSRodney W. Grimes  */
140df8bae1dSRodney W. Grimes 
141df8bae1dSRodney W. Grimes /*
142df8bae1dSRodney W. Grimes  * MINBSIZE is the smallest allowable block size.
143df8bae1dSRodney W. Grimes  * In order to insure that it is possible to create files of size
144df8bae1dSRodney W. Grimes  * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
145df8bae1dSRodney W. Grimes  * MINBSIZE must be big enough to hold a cylinder group block,
146df8bae1dSRodney W. Grimes  * thus changes to (struct cg) must keep its size within MINBSIZE.
1478e7a2353SCraig Rodrigues  * Note that super blocks are always of size SBLOCKSIZE,
1488e7a2353SCraig Rodrigues  * and that both SBLOCKSIZE and MAXBSIZE must be >= MINBSIZE.
149df8bae1dSRodney W. Grimes  */
150df8bae1dSRodney W. Grimes #define	MINBSIZE	4096
151df8bae1dSRodney W. Grimes 
152df8bae1dSRodney W. Grimes /*
153df8bae1dSRodney W. Grimes  * The path name on which the filesystem is mounted is maintained
154df8bae1dSRodney W. Grimes  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
155df8bae1dSRodney W. Grimes  * the super block for this name.
156df8bae1dSRodney W. Grimes  */
157963cae78SGordon Tetlow #define	MAXMNTLEN	468
158291871daSGordon Tetlow 
159291871daSGordon Tetlow /*
160291871daSGordon Tetlow  * The volume name for this filesystem is maintained in fs_volname.
161291871daSGordon Tetlow  * MAXVOLLEN defines the length of the buffer allocated.
162291871daSGordon Tetlow  */
163291871daSGordon Tetlow #define	MAXVOLLEN	32
164996c772fSJohn Dyson 
165996c772fSJohn Dyson /*
166f55ff3f3SIan Dowse  * There is a 128-byte region in the superblock reserved for in-core
167f55ff3f3SIan Dowse  * pointers to summary information. Originally this included an array
1683fa4044eSIan Dowse  * of pointers to blocks of struct csum; now there are just a few
169f55ff3f3SIan Dowse  * pointers and the remaining space is padded with fs_ocsp[].
170f55ff3f3SIan Dowse  *
17134816cb9SKirk McKusick  * NOCSPTRS determines the size of this padding. Historically this
17234816cb9SKirk McKusick  * space was used to store pointers to structures that summaried
17334816cb9SKirk McKusick  * filesystem usage and layout information. However, these pointers
17434816cb9SKirk McKusick  * left various kernel pointers in the superblock which made otherwise
17534816cb9SKirk McKusick  * identical superblocks appear to have differences. So, all the
17634816cb9SKirk McKusick  * pointers in the superblock were moved to a fs_summary_info structure
17734816cb9SKirk McKusick  * reducing the superblock to having only a single pointer to this
17834816cb9SKirk McKusick  * structure. When writing the superblock to disk, this pointer is
17934816cb9SKirk McKusick  * temporarily NULL'ed out so that the kernel pointer will not appear
18034816cb9SKirk McKusick  * in the on-disk copy of the superblock.
181996c772fSJohn Dyson  */
18234816cb9SKirk McKusick #define	NOCSPTRS	((128 / sizeof(void *)) - 1)
183df8bae1dSRodney W. Grimes 
184df8bae1dSRodney W. Grimes /*
185df8bae1dSRodney W. Grimes  * A summary of contiguous blocks of various sizes is maintained
186df8bae1dSRodney W. Grimes  * in each cylinder group. Normally this is set by the initial
187df8bae1dSRodney W. Grimes  * value of fs_maxcontig. To conserve space, a maximum summary size
188df8bae1dSRodney W. Grimes  * is set by FS_MAXCONTIG.
189df8bae1dSRodney W. Grimes  */
190df8bae1dSRodney W. Grimes #define	FS_MAXCONTIG	16
191df8bae1dSRodney W. Grimes 
192df8bae1dSRodney W. Grimes /*
193df8bae1dSRodney W. Grimes  * MINFREE gives the minimum acceptable percentage of filesystem
194df8bae1dSRodney W. Grimes  * blocks which may be free. If the freelist drops below this level
195df8bae1dSRodney W. Grimes  * only the superuser may continue to allocate blocks. This may
196df8bae1dSRodney W. Grimes  * be set to 0 if no reserve of free blocks is deemed necessary,
197df8bae1dSRodney W. Grimes  * however throughput drops by fifty percent if the filesystem
198df8bae1dSRodney W. Grimes  * is run at between 95% and 100% full; thus the minimum default
199df8bae1dSRodney W. Grimes  * value of fs_minfree is 5%. However, to get good clustering
200df8bae1dSRodney W. Grimes  * performance, 10% is a better choice. hence we use 10% as our
201df8bae1dSRodney W. Grimes  * default value. With 10% free space, fragmentation is not a
202df8bae1dSRodney W. Grimes  * problem, so we choose to optimize for time.
203df8bae1dSRodney W. Grimes  */
20407be9bd4SDavid Greenman #define	MINFREE		8
205df8bae1dSRodney W. Grimes #define	DEFAULTOPT	FS_OPTTIME
206df8bae1dSRodney W. Grimes 
207df8bae1dSRodney W. Grimes /*
208a61ab64aSKirk McKusick  * Grigoriy Orlov <gluk@ptci.ru> has done some extensive work to fine
209a61ab64aSKirk McKusick  * tune the layout preferences for directories within a filesystem.
210a61ab64aSKirk McKusick  * His algorithm can be tuned by adjusting the following parameters
211a61ab64aSKirk McKusick  * which tell the system the average file size and the average number
212a61ab64aSKirk McKusick  * of files per directory. These defaults are well selected for typical
213a61ab64aSKirk McKusick  * filesystems, but may need to be tuned for odd cases like filesystems
214b4a1d929SKirill Ponomarev  * being used for squid caches or news spools.
215a61ab64aSKirk McKusick  */
216a61ab64aSKirk McKusick #define	AVFILESIZ	16384	/* expected average file size */
217a61ab64aSKirk McKusick #define	AFPDIR		64	/* expected number of files per directory */
218a61ab64aSKirk McKusick 
219a61ab64aSKirk McKusick /*
22022e5a623SKirk McKusick  * The maximum number of snapshot nodes that can be associated
22122e5a623SKirk McKusick  * with each filesystem. This limit affects only the number of
22222e5a623SKirk McKusick  * snapshot files that can be recorded within the superblock so
22322e5a623SKirk McKusick  * that they can be found when the filesystem is mounted. However,
22422e5a623SKirk McKusick  * maintaining too many will slow the filesystem performance, so
22522e5a623SKirk McKusick  * having this limit is a good idea.
22622e5a623SKirk McKusick  */
22722e5a623SKirk McKusick #define	FSMAXSNAP 20
22822e5a623SKirk McKusick 
22922e5a623SKirk McKusick /*
23022e5a623SKirk McKusick  * Used to identify special blocks in snapshots:
23122e5a623SKirk McKusick  *
23222e5a623SKirk McKusick  * BLK_NOCOPY - A block that was unallocated at the time the snapshot
23322e5a623SKirk McKusick  *	was taken, hence does not need to be copied when written.
23422e5a623SKirk McKusick  * BLK_SNAP - A block held by another snapshot that is not needed by this
23522e5a623SKirk McKusick  *	snapshot. When the other snapshot is freed, the BLK_SNAP entries
23622e5a623SKirk McKusick  *	are converted to BLK_NOCOPY. These are needed to allow fsck to
23722e5a623SKirk McKusick  *	identify blocks that are in use by other snapshots (which are
23822e5a623SKirk McKusick  *	expunged from this snapshot).
23922e5a623SKirk McKusick  */
2401c85e6a3SKirk McKusick #define	BLK_NOCOPY ((ufs2_daddr_t)(1))
2411c85e6a3SKirk McKusick #define	BLK_SNAP ((ufs2_daddr_t)(2))
24222e5a623SKirk McKusick 
24322e5a623SKirk McKusick /*
244812b1d41SKirk McKusick  * Sysctl values for the fast filesystem.
245812b1d41SKirk McKusick  */
246812b1d41SKirk McKusick #define	FFS_ADJ_REFCNT		 1	/* adjust inode reference count */
247812b1d41SKirk McKusick #define	FFS_ADJ_BLKCNT		 2	/* adjust inode used block count */
248812b1d41SKirk McKusick #define	FFS_BLK_FREE		 3	/* free range of blocks in map */
249812b1d41SKirk McKusick #define	FFS_DIR_FREE		 4	/* free specified dir inodes in map */
250812b1d41SKirk McKusick #define	FFS_FILE_FREE		 5	/* free specified file inodes in map */
251812b1d41SKirk McKusick #define	FFS_SET_FLAGS		 6	/* set filesystem flags */
252a16baf37SXin LI #define	FFS_ADJ_NDIR		 7	/* adjust number of directories */
253a16baf37SXin LI #define	FFS_ADJ_NBFREE		 8	/* adjust number of free blocks */
254a16baf37SXin LI #define	FFS_ADJ_NIFREE		 9	/* adjust number of free inodes */
255a16baf37SXin LI #define	FFS_ADJ_NFFREE		10 	/* adjust number of free frags */
256a16baf37SXin LI #define	FFS_ADJ_NUMCLUSTERS	11	/* adjust number of free clusters */
257e268f54cSKirk McKusick #define	FFS_SET_CWD		12	/* set current directory */
258e268f54cSKirk McKusick #define	FFS_SET_DOTDOT		13	/* set inode number for ".." */
259e268f54cSKirk McKusick #define	FFS_UNLINK		14	/* remove a name in the filesystem */
260f2620e9cSJohn Baldwin /* Was FFS_SET_INODE		15 */
261f2620e9cSJohn Baldwin /* Was FFS_SET_BUFOUTPUT	16 */
262ac4b20a0SKirk McKusick #define	FFS_SET_SIZE		17	/* set inode size */
263e4a905d1SKirk McKusick #define	FFS_ADJ_DEPTH		18	/* adjust directory inode depth */
264e4a905d1SKirk McKusick #define	FFS_MAXID		18	/* number of valid ffs ids */
265812b1d41SKirk McKusick 
266812b1d41SKirk McKusick /*
267812b1d41SKirk McKusick  * Command structure passed in to the filesystem to adjust filesystem values.
268812b1d41SKirk McKusick  */
2691c85e6a3SKirk McKusick #define	FFS_CMD_VERSION		0x19790518	/* version ID */
270812b1d41SKirk McKusick struct fsck_cmd {
2711c85e6a3SKirk McKusick 	int32_t	version;	/* version of command structure */
2721c85e6a3SKirk McKusick 	int32_t	handle;		/* reference to filesystem to be changed */
2731c85e6a3SKirk McKusick 	int64_t	value;		/* inode or block number to be affected */
2741c85e6a3SKirk McKusick 	int64_t	size;		/* amount or range to be adjusted */
2751c85e6a3SKirk McKusick 	int64_t	spare;		/* reserved for future use */
276812b1d41SKirk McKusick };
277812b1d41SKirk McKusick 
278812b1d41SKirk McKusick /*
27977b63aa0SKirk McKusick  * A recovery structure placed at the end of the boot block area by newfs
28077b63aa0SKirk McKusick  * that can be used by fsck to search for alternate superblocks.
28177b63aa0SKirk McKusick  */
28277b63aa0SKirk McKusick struct fsrecovery {
28377b63aa0SKirk McKusick 	int32_t	fsr_magic;	/* magic number */
28477b63aa0SKirk McKusick 	int32_t	fsr_fsbtodb;	/* fsbtodb and dbtofsb shift constant */
28577b63aa0SKirk McKusick 	int32_t	fsr_sblkno;	/* offset of super-block in filesys */
28677b63aa0SKirk McKusick 	int32_t	fsr_fpg;	/* blocks per group * fs_frag */
287831b1ff7SKirk McKusick 	uint32_t fsr_ncg;	/* number of cylinder groups */
28877b63aa0SKirk McKusick };
28977b63aa0SKirk McKusick 
29077b63aa0SKirk McKusick /*
291df8bae1dSRodney W. Grimes  * Per cylinder group information; summarized in blocks allocated
292df8bae1dSRodney W. Grimes  * from first cylinder group data blocks.  These blocks have to be
293df8bae1dSRodney W. Grimes  * read in from fs_csaddr (size fs_cssize) in addition to the
294df8bae1dSRodney W. Grimes  * super block.
295df8bae1dSRodney W. Grimes  */
296df8bae1dSRodney W. Grimes struct csum {
297996c772fSJohn Dyson 	int32_t	cs_ndir;		/* number of directories */
298996c772fSJohn Dyson 	int32_t	cs_nbfree;		/* number of free blocks */
299996c772fSJohn Dyson 	int32_t	cs_nifree;		/* number of free inodes */
300996c772fSJohn Dyson 	int32_t	cs_nffree;		/* number of free frags */
301df8bae1dSRodney W. Grimes };
3021c85e6a3SKirk McKusick struct csum_total {
3031c85e6a3SKirk McKusick 	int64_t	cs_ndir;		/* number of directories */
3041c85e6a3SKirk McKusick 	int64_t	cs_nbfree;		/* number of free blocks */
3051c85e6a3SKirk McKusick 	int64_t	cs_nifree;		/* number of free inodes */
3061c85e6a3SKirk McKusick 	int64_t	cs_nffree;		/* number of free frags */
3071c85e6a3SKirk McKusick 	int64_t	cs_numclusters;		/* number of free clusters */
3081c85e6a3SKirk McKusick 	int64_t	cs_spare[3];		/* future expansion */
3091c85e6a3SKirk McKusick };
310df8bae1dSRodney W. Grimes 
311df8bae1dSRodney W. Grimes /*
31234816cb9SKirk McKusick  * Pointers to super block summary information. Placed in a separate
31334816cb9SKirk McKusick  * structure so there is just one pointer in the superblock.
31434816cb9SKirk McKusick  *
31534816cb9SKirk McKusick  * The pointers in this structure are used as follows:
31634816cb9SKirk McKusick  *   fs_contigdirs references an array that tracks the creation of new
31734816cb9SKirk McKusick  *	directories
31834816cb9SKirk McKusick  *   fs_csp references a contiguous array of struct csum for
31934816cb9SKirk McKusick  *	all cylinder groups
32034816cb9SKirk McKusick  *   fs_maxcluster references an array of cluster sizes that is computed
32134816cb9SKirk McKusick  *	as cylinder groups are inspected
32234816cb9SKirk McKusick  *   fs_active is used when creating snapshots; it points to a bitmap
32334816cb9SKirk McKusick  *	of cylinder groups for which the free-block bitmap has changed
32434816cb9SKirk McKusick  *	since the snapshot operation began.
32534816cb9SKirk McKusick  */
32634816cb9SKirk McKusick struct fs_summary_info {
32734816cb9SKirk McKusick 	uint8_t	*si_contigdirs;		/* (u) # of contig. allocated dirs */
32834816cb9SKirk McKusick 	struct	csum *si_csp;		/* (u) cg summary info buffer */
32934816cb9SKirk McKusick 	int32_t	*si_maxcluster;		/* (u) max cluster in each cyl group */
330831b1ff7SKirk McKusick 	uint64_t *si_active;		/* (u) used by snapshots to track fs */
33134816cb9SKirk McKusick };
33234816cb9SKirk McKusick #define fs_contigdirs	fs_si->si_contigdirs
33334816cb9SKirk McKusick #define fs_csp		fs_si->si_csp
33434816cb9SKirk McKusick #define fs_maxcluster	fs_si->si_maxcluster
33534816cb9SKirk McKusick #define fs_active	fs_si->si_active
33634816cb9SKirk McKusick 
33734816cb9SKirk McKusick /*
338996c772fSJohn Dyson  * Super block for an FFS filesystem.
339df8bae1dSRodney W. Grimes  */
340df8bae1dSRodney W. Grimes struct fs {
341996c772fSJohn Dyson 	int32_t	 fs_firstfield;		/* historic filesystem linked list, */
342996c772fSJohn Dyson 	int32_t	 fs_unused_1;		/*     used for incore super blocks */
3431c85e6a3SKirk McKusick 	int32_t	 fs_sblkno;		/* offset of super-block in filesys */
3441c85e6a3SKirk McKusick 	int32_t	 fs_cblkno;		/* offset of cyl-block in filesys */
3451c85e6a3SKirk McKusick 	int32_t	 fs_iblkno;		/* offset of inode-blocks in filesys */
3461c85e6a3SKirk McKusick 	int32_t	 fs_dblkno;		/* offset of first data after cg */
3471c85e6a3SKirk McKusick 	int32_t	 fs_old_cgoffset;	/* cylinder group offset in cylinder */
3481c85e6a3SKirk McKusick 	int32_t	 fs_old_cgmask;		/* used to calc mod fs_ntrak */
3491c85e6a3SKirk McKusick 	int32_t  fs_old_time;		/* last time written */
3501c85e6a3SKirk McKusick 	int32_t	 fs_old_size;		/* number of blocks in fs */
3511c85e6a3SKirk McKusick 	int32_t	 fs_old_dsize;		/* number of data blocks in fs */
352831b1ff7SKirk McKusick 	uint32_t fs_ncg;		/* number of cylinder groups */
353996c772fSJohn Dyson 	int32_t	 fs_bsize;		/* size of basic blocks in fs */
354996c772fSJohn Dyson 	int32_t	 fs_fsize;		/* size of frag blocks in fs */
355996c772fSJohn Dyson 	int32_t	 fs_frag;		/* number of frags in a block in fs */
356df8bae1dSRodney W. Grimes /* these are configuration parameters */
357996c772fSJohn Dyson 	int32_t	 fs_minfree;		/* minimum percentage of free blocks */
3581c85e6a3SKirk McKusick 	int32_t	 fs_old_rotdelay;	/* num of ms for optimal next block */
3591c85e6a3SKirk McKusick 	int32_t	 fs_old_rps;		/* disk revolutions per second */
360df8bae1dSRodney W. Grimes /* these fields can be computed from the others */
361996c772fSJohn Dyson 	int32_t	 fs_bmask;		/* ``blkoff'' calc of blk offsets */
362996c772fSJohn Dyson 	int32_t	 fs_fmask;		/* ``fragoff'' calc of frag offsets */
363996c772fSJohn Dyson 	int32_t	 fs_bshift;		/* ``lblkno'' calc of logical blkno */
364996c772fSJohn Dyson 	int32_t	 fs_fshift;		/* ``numfrags'' calc number of frags */
365df8bae1dSRodney W. Grimes /* these are configuration parameters */
366996c772fSJohn Dyson 	int32_t	 fs_maxcontig;		/* max number of contiguous blks */
367996c772fSJohn Dyson 	int32_t	 fs_maxbpg;		/* max number of blks per cyl group */
368df8bae1dSRodney W. Grimes /* these fields can be computed from the others */
369996c772fSJohn Dyson 	int32_t	 fs_fragshift;		/* block to frag shift */
370996c772fSJohn Dyson 	int32_t	 fs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
371996c772fSJohn Dyson 	int32_t	 fs_sbsize;		/* actual size of super block */
3721c85e6a3SKirk McKusick 	int32_t	 fs_spare1[2];		/* old fs_csmask */
3731c85e6a3SKirk McKusick 					/* old fs_csshift */
374996c772fSJohn Dyson 	int32_t	 fs_nindir;		/* value of NINDIR */
375831b1ff7SKirk McKusick 	uint32_t fs_inopb;		/* value of INOPB */
3761c85e6a3SKirk McKusick 	int32_t	 fs_old_nspf;		/* value of NSPF */
377df8bae1dSRodney W. Grimes /* yet another configuration parameter */
378996c772fSJohn Dyson 	int32_t	 fs_optim;		/* optimization preference, see below */
3791c85e6a3SKirk McKusick 	int32_t	 fs_old_npsect;		/* # sectors/track including spares */
3801c85e6a3SKirk McKusick 	int32_t	 fs_old_interleave;	/* hardware sector interleave */
3811c85e6a3SKirk McKusick 	int32_t	 fs_old_trackskew;	/* sector 0 skew, per track */
38290b42d7eSBruce Evans 	int32_t	 fs_id[2];		/* unique filesystem id */
383df8bae1dSRodney W. Grimes /* sizes determined by number of cylinder groups and their sizes */
3841c85e6a3SKirk McKusick 	int32_t	 fs_old_csaddr;		/* blk addr of cyl grp summary area */
385996c772fSJohn Dyson 	int32_t	 fs_cssize;		/* size of cyl grp summary area */
386996c772fSJohn Dyson 	int32_t	 fs_cgsize;		/* cylinder group size */
3871c85e6a3SKirk McKusick 	int32_t	 fs_spare2;		/* old fs_ntrak */
3881c85e6a3SKirk McKusick 	int32_t	 fs_old_nsect;		/* sectors per track */
3891c85e6a3SKirk McKusick 	int32_t  fs_old_spc;		/* sectors per cylinder */
3901c85e6a3SKirk McKusick 	int32_t	 fs_old_ncyl;		/* cylinders in filesystem */
3911c85e6a3SKirk McKusick 	int32_t	 fs_old_cpg;		/* cylinders per group */
392831b1ff7SKirk McKusick 	uint32_t fs_ipg;		/* inodes per group */
393996c772fSJohn Dyson 	int32_t	 fs_fpg;		/* blocks per group * fs_frag */
394df8bae1dSRodney W. Grimes /* this data must be re-computed after crashes */
3951c85e6a3SKirk McKusick 	struct	csum fs_old_cstotal;	/* cylinder summary information */
396df8bae1dSRodney W. Grimes /* these fields are cleared at mount time */
397996c772fSJohn Dyson 	int8_t   fs_fmod;		/* super block modified flag */
398996c772fSJohn Dyson 	int8_t   fs_clean;		/* filesystem is clean flag */
399996c772fSJohn Dyson 	int8_t 	 fs_ronly;		/* mounted read-only flag */
400ada981b2SKirk McKusick 	int8_t   fs_old_flags;		/* old FS_ flags */
401831b1ff7SKirk McKusick 	uint8_t	 fs_fsmnt[MAXMNTLEN];	/* name mounted on */
402831b1ff7SKirk McKusick 	uint8_t	 fs_volname[MAXVOLLEN];	/* volume name */
403831b1ff7SKirk McKusick 	uint64_t fs_swuid;		/* system-wide uid */
404cc4a8583SMarcel Moolenaar 	int32_t  fs_pad;		/* due to alignment of fs_swuid */
405df8bae1dSRodney W. Grimes /* these fields retain the current block allocation info */
406996c772fSJohn Dyson 	int32_t	 fs_cgrotor;		/* last cg searched */
407f55ff3f3SIan Dowse 	void 	*fs_ocsp[NOCSPTRS];	/* padding; was list of fs_cs buffers */
40834816cb9SKirk McKusick 	struct	 fs_summary_info *fs_si;/* In-core pointer to summary info */
4091c85e6a3SKirk McKusick 	int32_t	 fs_old_cpc;		/* cyl per cycle in postbl */
4101c85e6a3SKirk McKusick 	int32_t	 fs_maxbsize;		/* maximum blocking factor permitted */
4111a60c7fcSPawel Jakub Dawidek 	int64_t	 fs_unrefs;		/* number of unreferenced inodes */
412549f62faSEdward Tomasz Napierala 	int64_t  fs_providersize;	/* size of underlying GEOM provider */
413baa12a84SKirk McKusick 	int64_t	 fs_metaspace;		/* size of area reserved for metadata */
414*661ca921SKirk McKusick 	uint64_t fs_save_maxfilesize;	/* save old UFS1 maxfilesize */
415*661ca921SKirk McKusick 	int64_t	 fs_sparecon64[12];	/* old rotation block list head */
416dffce215SKirk McKusick 	int64_t	 fs_sblockactualloc;	/* byte offset of this superblock */
417ada981b2SKirk McKusick 	int64_t	 fs_sblockloc;		/* byte offset of standard superblock */
418f2aa1113SJeff Roberson 	struct	csum_total fs_cstotal;	/* (u) cylinder summary information */
4191c85e6a3SKirk McKusick 	ufs_time_t fs_time;		/* last time written */
4201c85e6a3SKirk McKusick 	int64_t	 fs_size;		/* number of blocks in fs */
4211c85e6a3SKirk McKusick 	int64_t	 fs_dsize;		/* number of data blocks in fs */
4221c85e6a3SKirk McKusick 	ufs2_daddr_t fs_csaddr;		/* blk addr of cyl grp summary area */
423f2aa1113SJeff Roberson 	int64_t	 fs_pendingblocks;	/* (u) blocks being freed */
424831b1ff7SKirk McKusick 	uint32_t fs_pendinginodes;	/* (u) inodes being freed */
42558b1333aSGleb Kurtsou 	uint32_t fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */
426831b1ff7SKirk McKusick 	uint32_t fs_avgfilesize;	/* expected average file size */
427831b1ff7SKirk McKusick 	uint32_t fs_avgfpdir;		/* expected # of files per directory */
428*661ca921SKirk McKusick 	uint32_t fs_available_spare;	/* old scratch space */
429113db2ddSJeff Roberson 	ufs_time_t fs_mtime;		/* Last mount or fsck time. */
430113db2ddSJeff Roberson 	int32_t  fs_sujfree;		/* SUJ free list */
431ec888383SKirk McKusick 	int32_t	 fs_sparecon32[21];	/* reserved for future constants */
432831b1ff7SKirk McKusick 	uint32_t fs_ckhash;		/* if CK_SUPERBLOCK, its check-hash */
433831b1ff7SKirk McKusick 	uint32_t fs_metackhash;	/* metadata check-hash, see CK_ below */
434ada981b2SKirk McKusick 	int32_t  fs_flags;		/* see FS_ flags below */
435996c772fSJohn Dyson 	int32_t	 fs_contigsumsize;	/* size of cluster summary array */
436996c772fSJohn Dyson 	int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */
4371c85e6a3SKirk McKusick 	int32_t	 fs_old_inodefmt;	/* format of on-disk inodes */
438831b1ff7SKirk McKusick 	uint64_t fs_maxfilesize;	/* maximum representable file size */
439996c772fSJohn Dyson 	int64_t	 fs_qbmask;		/* ~fs_bmask for use with 64-bit size */
440996c772fSJohn Dyson 	int64_t	 fs_qfmask;		/* ~fs_fmask for use with 64-bit size */
441996c772fSJohn Dyson 	int32_t	 fs_state;		/* validate fs_clean field */
4421c85e6a3SKirk McKusick 	int32_t	 fs_old_postblformat;	/* format of positional layout tables */
4431c85e6a3SKirk McKusick 	int32_t	 fs_old_nrpos;		/* number of rotational positions */
4441c85e6a3SKirk McKusick 	int32_t	 fs_spare5[2];		/* old fs_postbloff */
4451c85e6a3SKirk McKusick 					/* old fs_rotbloff */
446996c772fSJohn Dyson 	int32_t	 fs_magic;		/* magic number */
447df8bae1dSRodney W. Grimes };
448996c772fSJohn Dyson 
449cc4a8583SMarcel Moolenaar /* Sanity checking. */
450cc4a8583SMarcel Moolenaar #ifdef CTASSERT
451cc4a8583SMarcel Moolenaar CTASSERT(sizeof(struct fs) == 1376);
452cc4a8583SMarcel Moolenaar #endif
453cc4a8583SMarcel Moolenaar 
454df8bae1dSRodney W. Grimes /*
4556c5e9bbdSMike Pritchard  * Filesystem identification
456df8bae1dSRodney W. Grimes  */
4571c85e6a3SKirk McKusick #define	FS_UFS1_MAGIC	0x011954	/* UFS1 fast filesystem magic number */
4581c85e6a3SKirk McKusick #define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast filesystem magic number */
459b72ea57fSJohn Baldwin #define	FS_BAD_MAGIC	0x19960408	/* UFS incomplete newfs magic number */
460df8bae1dSRodney W. Grimes #define	FS_42INODEFMT	-1		/* 4.2BSD inode format */
461df8bae1dSRodney W. Grimes #define	FS_44INODEFMT	2		/* 4.4BSD inode format */
462b1897c19SJulian Elischer 
463df8bae1dSRodney W. Grimes /*
464df8bae1dSRodney W. Grimes  * Preference for optimization.
465df8bae1dSRodney W. Grimes  */
466df8bae1dSRodney W. Grimes #define	FS_OPTTIME	0	/* minimize allocation time */
467df8bae1dSRodney W. Grimes #define	FS_OPTSPACE	1	/* minimize disk fragmentation */
468df8bae1dSRodney W. Grimes 
469df8bae1dSRodney W. Grimes /*
470b1897c19SJulian Elischer  * Filesystem flags.
4711a6a6610SKirk McKusick  *
4721c85e6a3SKirk McKusick  * The FS_UNCLEAN flag is set by the kernel when the filesystem was
4731c85e6a3SKirk McKusick  * mounted with fs_clean set to zero. The FS_DOSOFTDEP flag indicates
4741c85e6a3SKirk McKusick  * that the filesystem should be managed by the soft updates code.
4755a0d467fSKirk McKusick  * Note that the FS_NEEDSFSCK flag is set and cleared by the fsck
4765a0d467fSKirk McKusick  * utility. It is set when background fsck finds an unexpected
4771a6a6610SKirk McKusick  * inconsistency which requires a traditional foreground fsck to be
4781a6a6610SKirk McKusick  * run. Such inconsistencies should only be found after an uncorrectable
4795a0d467fSKirk McKusick  * disk error. The FS_NEEDSFSCK can also be set when a mounted filesystem
4805a0d467fSKirk McKusick  * discovers an internal inconsistency such as freeing a freed inode.
4815a0d467fSKirk McKusick  * A foreground fsck will clear the FS_NEEDSFSCK flag when it has
4825a0d467fSKirk McKusick  * successfully cleaned up the filesystem. The kernel uses this
4831a6a6610SKirk McKusick  * flag to enforce that inconsistent filesystems be mounted read-only.
4845a0d467fSKirk McKusick  *
4855a0d467fSKirk McKusick  * The FS_METACKHASH flag when set indicates that the kernel maintains
4865a0d467fSKirk McKusick  * one or more check hashes. The actual set of supported check hashes
4875a0d467fSKirk McKusick  * is stored in the fs_metackhash field. Kernels that do not support
4885a0d467fSKirk McKusick  * check hashes clear the FS_METACKHASH flag to indicate that the
4895a0d467fSKirk McKusick  * check hashes need to be rebuilt (by fsck) before they can be used.
4905a0d467fSKirk McKusick  *
4915a0d467fSKirk McKusick  * When a filesystem is mounted, any flags not included in FS_SUPPORTED
4925a0d467fSKirk McKusick  * are cleared. This lets newer features know that the filesystem has
4935a0d467fSKirk McKusick  * been run on an older version of the filesystem and thus that data
4945a0d467fSKirk McKusick  * structures associated with those features are out-of-date and need
4955a0d467fSKirk McKusick  * to be rebuilt.
4963ceef565SRobert Watson  *
4979340fc72SEdward Tomasz Napierala  * FS_ACLS indicates that POSIX.1e ACLs are administratively enabled
4989340fc72SEdward Tomasz Napierala  * for the file system, so they should be loaded from extended attributes,
4993ceef565SRobert Watson  * observed for access control purposes, and be administered by object
5009340fc72SEdward Tomasz Napierala  * owners.  FS_NFS4ACLS indicates that NFSv4 ACLs are administratively
5019340fc72SEdward Tomasz Napierala  * enabled.  This flag is mutually exclusive with FS_ACLS.  FS_MULTILABEL
5029340fc72SEdward Tomasz Napierala  * indicates that the TrustedBSD MAC Framework should attempt to back MAC
5039340fc72SEdward Tomasz Napierala  * labels into extended attributes on the file system rather than maintain
5049340fc72SEdward Tomasz Napierala  * a single mount label for all objects.
505b1897c19SJulian Elischer  */
506068beacfSKirk McKusick #define	FS_UNCLEAN	0x00000001 /* filesystem not clean at mount */
507068beacfSKirk McKusick #define	FS_DOSOFTDEP	0x00000002 /* filesystem using soft dependencies */
508068beacfSKirk McKusick #define	FS_NEEDSFSCK	0x00000004 /* filesystem needs sync fsck before mount */
509068beacfSKirk McKusick #define	FS_SUJ       	0x00000008 /* Filesystem using softupdate journal */
510068beacfSKirk McKusick #define	FS_ACLS		0x00000010 /* file system has POSIX.1e ACLs enabled */
511068beacfSKirk McKusick #define	FS_MULTILABEL	0x00000020 /* file system is MAC multi-label */
512068beacfSKirk McKusick #define	FS_GJOURNAL	0x00000040 /* gjournaled file system */
513068beacfSKirk McKusick #define	FS_FLAGS_UPDATED 0x0000080 /* flags have been moved to new location */
514068beacfSKirk McKusick #define	FS_NFS4ACLS	0x00000100 /* file system has NFSv4 ACLs enabled */
515068beacfSKirk McKusick #define	FS_METACKHASH	0x00000200 /* kernel supports metadata check hashes */
516068beacfSKirk McKusick #define	FS_TRIM		0x00000400 /* issue BIO_DELETE for deleted blocks */
517068beacfSKirk McKusick #define	FS_SUPPORTED	0x00FFFFFF /* supported flags, others cleared at mount*/
518068beacfSKirk McKusick /*
519068beacfSKirk McKusick  * Things that we may someday support, but currently do not.
520068beacfSKirk McKusick  * These flags are all cleared so we know if we ran on a kernel
521068beacfSKirk McKusick  * that does not support them.
522068beacfSKirk McKusick  */
523068beacfSKirk McKusick #define	FS_INDEXDIRS	0x01000000 /* kernel supports indexed directories */
524068beacfSKirk McKusick #define	FS_VARBLKSIZE	0x02000000 /* kernel supports variable block sizes */
525068beacfSKirk McKusick #define	FS_COOLOPT1	0x04000000 /* kernel supports cool option 1 */
526068beacfSKirk McKusick #define	FS_COOLOPT2	0x08000000 /* kernel supports cool option 2 */
527068beacfSKirk McKusick #define	FS_COOLOPT3	0x10000000 /* kernel supports cool option 3 */
528068beacfSKirk McKusick #define	FS_COOLOPT4	0x20000000 /* kernel supports cool option 4 */
529068beacfSKirk McKusick #define	FS_COOLOPT5	0x40000000 /* kernel supports cool option 5 */
530068beacfSKirk McKusick #define	FS_COOLOPT6	0x80000000 /* kernel supports cool option 6 */
53175e3597aSKirk McKusick 
53275e3597aSKirk McKusick /*
53375e3597aSKirk McKusick  * The fs_metackhash field indicates the types of metadata check-hash
53475e3597aSKirk McKusick  * that are maintained for a filesystem. Not all filesystems check-hash
53575e3597aSKirk McKusick  * all metadata.
53675e3597aSKirk McKusick  */
53775e3597aSKirk McKusick #define	CK_SUPERBLOCK	0x0001	/* the superblock */
53875e3597aSKirk McKusick #define	CK_CYLGRP	0x0002	/* the cylinder groups */
53975e3597aSKirk McKusick #define	CK_INODE	0x0004	/* inodes */
54075e3597aSKirk McKusick #define	CK_INDIR	0x0008	/* indirect blocks */
54175e3597aSKirk McKusick #define	CK_DIR		0x0010	/* directory contents */
542996d40f9SKirk McKusick #define	CK_SUPPORTED	0x0007	/* supported flags, others cleared at mount */
54375e3597aSKirk McKusick /*
54475e3597aSKirk McKusick  * The BX_FSPRIV buffer b_xflags are used to track types of data in buffers.
54575e3597aSKirk McKusick  */
54675e3597aSKirk McKusick #define	BX_SUPERBLOCK	0x00010000	/* superblock */
54775e3597aSKirk McKusick #define	BX_CYLGRP	0x00020000	/* cylinder groups */
54875e3597aSKirk McKusick #define	BX_INODE	0x00040000	/* inodes */
54975e3597aSKirk McKusick #define	BX_INDIR	0x00080000	/* indirect blocks */
55075e3597aSKirk McKusick #define	BX_DIR		0x00100000	/* directory contents */
55175e3597aSKirk McKusick 
55275e3597aSKirk McKusick #define	PRINT_UFS_BUF_XFLAGS "\20\25dir\24indir\23inode\22cylgrp\21superblock"
553df8bae1dSRodney W. Grimes 
554df8bae1dSRodney W. Grimes /*
555f305c5d1SKirk McKusick  * Macros to access bits in the fs_active array.
556f305c5d1SKirk McKusick  */
557831b1ff7SKirk McKusick #define	ACTIVECGNUM(fs, cg)  ((fs)->fs_active[(cg) / (NBBY * sizeof(uint64_t))])
558831b1ff7SKirk McKusick #define	ACTIVECGOFF(cg)	     (1 << ((cg) % (NBBY * sizeof(uint64_t))))
559f2aa1113SJeff Roberson #define	ACTIVESET(fs, cg)    do {					\
560f2aa1113SJeff Roberson 	if ((fs)->fs_active)						\
561f2aa1113SJeff Roberson 		ACTIVECGNUM((fs), (cg)) |= ACTIVECGOFF((cg));		\
562f2aa1113SJeff Roberson } while (0)
563f2aa1113SJeff Roberson #define	ACTIVECLEAR(fs, cg)	do {					\
564f2aa1113SJeff Roberson 	if ((fs)->fs_active)						\
565f2aa1113SJeff Roberson 		ACTIVECGNUM((fs), (cg)) &= ~ACTIVECGOFF((cg));		\
566f2aa1113SJeff Roberson } while (0)
567f305c5d1SKirk McKusick 
568f305c5d1SKirk McKusick /*
569df8bae1dSRodney W. Grimes  * The size of a cylinder group is calculated by CGSIZE. The maximum size
570df8bae1dSRodney W. Grimes  * is limited by the fact that cylinder groups are at most one block.
571df8bae1dSRodney W. Grimes  * Its size is derived from the size of the maps maintained in the
572df8bae1dSRodney W. Grimes  * cylinder group and the (struct cg) size.
573df8bae1dSRodney W. Grimes  */
574df8bae1dSRodney W. Grimes #define	CGSIZE(fs) \
5750a6e34e9SKirk McKusick     /* base cg */	(sizeof(struct cg) + \
5761c85e6a3SKirk McKusick     /* old btotoff */	(fs)->fs_old_cpg * sizeof(int32_t) + \
577831b1ff7SKirk McKusick     /* old boff */	(fs)->fs_old_cpg * sizeof(uint16_t) + \
578df8bae1dSRodney W. Grimes     /* inode map */	howmany((fs)->fs_ipg, NBBY) + \
5790a6e34e9SKirk McKusick     /* block map */	howmany((fs)->fs_fpg, NBBY) + sizeof(int32_t) + \
580df8bae1dSRodney W. Grimes     /* if present */	((fs)->fs_contigsumsize <= 0 ? 0 : \
581996c772fSJohn Dyson     /* cluster sum */	(fs)->fs_contigsumsize * sizeof(int32_t) + \
5821c85e6a3SKirk McKusick     /* cluster map */	howmany(fragstoblks(fs, (fs)->fs_fpg), NBBY)))
5831c85e6a3SKirk McKusick 
5841c85e6a3SKirk McKusick /*
5851c85e6a3SKirk McKusick  * The minimal number of cylinder groups that should be created.
5861c85e6a3SKirk McKusick  */
5871c85e6a3SKirk McKusick #define	MINCYLGRPS	4
588df8bae1dSRodney W. Grimes 
589df8bae1dSRodney W. Grimes /*
590df8bae1dSRodney W. Grimes  * Convert cylinder group to base address of its global summary info.
591df8bae1dSRodney W. Grimes  */
592f55ff3f3SIan Dowse #define	fs_cs(fs, indx) fs_csp[indx]
593df8bae1dSRodney W. Grimes 
594df8bae1dSRodney W. Grimes /*
595df8bae1dSRodney W. Grimes  * Cylinder group block for a filesystem.
596df8bae1dSRodney W. Grimes  */
597df8bae1dSRodney W. Grimes #define	CG_MAGIC	0x090255
598df8bae1dSRodney W. Grimes struct cg {
599996c772fSJohn Dyson 	int32_t	 cg_firstfield;		/* historic cyl groups linked list */
600996c772fSJohn Dyson 	int32_t	 cg_magic;		/* magic number */
6011c85e6a3SKirk McKusick 	int32_t  cg_old_time;		/* time last written */
602831b1ff7SKirk McKusick 	uint32_t cg_cgx;		/* we are the cgx'th cylinder group */
6031c85e6a3SKirk McKusick 	int16_t	 cg_old_ncyl;		/* number of cyl's this cg */
6041c85e6a3SKirk McKusick 	int16_t  cg_old_niblk;		/* number of inode blocks this cg */
605831b1ff7SKirk McKusick 	uint32_t cg_ndblk;		/* number of data blocks this cg */
606df8bae1dSRodney W. Grimes 	struct	 csum cg_cs;		/* cylinder summary information */
607831b1ff7SKirk McKusick 	uint32_t cg_rotor;		/* position of last used block */
608831b1ff7SKirk McKusick 	uint32_t cg_frotor;		/* position of last used frag */
609831b1ff7SKirk McKusick 	uint32_t cg_irotor;		/* position of last used inode */
610831b1ff7SKirk McKusick 	uint32_t cg_frsum[MAXFRAG];	/* counts of available frags */
6111c85e6a3SKirk McKusick 	int32_t	 cg_old_btotoff;	/* (int32) block totals per cylinder */
612831b1ff7SKirk McKusick 	int32_t	 cg_old_boff;		/* (uint16) free block positions */
613831b1ff7SKirk McKusick 	uint32_t cg_iusedoff;		/* (uint8) used inode map */
614831b1ff7SKirk McKusick 	uint32_t cg_freeoff;		/* (uint8) free block map */
615831b1ff7SKirk McKusick 	uint32_t cg_nextfreeoff;	/* (uint8) next available space */
616831b1ff7SKirk McKusick 	uint32_t cg_clustersumoff;	/* (uint32) counts of avail clusters */
617831b1ff7SKirk McKusick 	uint32_t cg_clusteroff;		/* (uint8) free cluster map */
618831b1ff7SKirk McKusick 	uint32_t cg_nclusterblks;	/* number of clusters this cg */
619831b1ff7SKirk McKusick 	uint32_t cg_niblk;		/* number of inode blocks this cg */
620831b1ff7SKirk McKusick 	uint32_t cg_initediblk;		/* last initialized inode */
621831b1ff7SKirk McKusick 	uint32_t cg_unrefs;		/* number of unreferenced inodes */
62275e3597aSKirk McKusick 	int32_t	 cg_sparecon32[1];	/* reserved for future use */
623831b1ff7SKirk McKusick 	uint32_t cg_ckhash;		/* check-hash of this cg */
6241c85e6a3SKirk McKusick 	ufs_time_t cg_time;		/* time last written */
6251c85e6a3SKirk McKusick 	int64_t	 cg_sparecon64[3];	/* reserved for future use */
6260a6e34e9SKirk McKusick 	/* actually longer - space used for cylinder group maps */
627df8bae1dSRodney W. Grimes };
628996c772fSJohn Dyson 
629df8bae1dSRodney W. Grimes /*
630df8bae1dSRodney W. Grimes  * Macros for access to cylinder group array structures
631df8bae1dSRodney W. Grimes  */
6321c85e6a3SKirk McKusick #define	cg_chkmagic(cgp) ((cgp)->cg_magic == CG_MAGIC)
633df8bae1dSRodney W. Grimes #define	cg_inosused(cgp) \
634831b1ff7SKirk McKusick     ((uint8_t *)((uint8_t *)(cgp) + (cgp)->cg_iusedoff))
635df8bae1dSRodney W. Grimes #define	cg_blksfree(cgp) \
636831b1ff7SKirk McKusick     ((uint8_t *)((uint8_t *)(cgp) + (cgp)->cg_freeoff))
637df8bae1dSRodney W. Grimes #define	cg_clustersfree(cgp) \
638831b1ff7SKirk McKusick     ((uint8_t *)((uint8_t *)(cgp) + (cgp)->cg_clusteroff))
639df8bae1dSRodney W. Grimes #define	cg_clustersum(cgp) \
640b1fddb23SMaxime Henrion     ((int32_t *)((uintptr_t)(cgp) + (cgp)->cg_clustersumoff))
641df8bae1dSRodney W. Grimes 
642df8bae1dSRodney W. Grimes /*
643df8bae1dSRodney W. Grimes  * Turn filesystem block numbers into disk block addresses.
644df8bae1dSRodney W. Grimes  * This maps filesystem blocks to device size blocks.
645df8bae1dSRodney W. Grimes  */
646894d8d3cSNate Lawson #define	fsbtodb(fs, b)	((daddr_t)(b) << (fs)->fs_fsbtodb)
647df8bae1dSRodney W. Grimes #define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)
648df8bae1dSRodney W. Grimes 
649df8bae1dSRodney W. Grimes /*
650df8bae1dSRodney W. Grimes  * Cylinder group macros to locate things in cylinder groups.
651df8bae1dSRodney W. Grimes  * They calc filesystem addresses of cylinder group data structures.
652df8bae1dSRodney W. Grimes  */
653d60682c2SKirk McKusick #define	cgbase(fs, c)	(((ufs2_daddr_t)(fs)->fs_fpg) * (c))
654baa12a84SKirk McKusick #define	cgdata(fs, c)	(cgdmin(fs, c) + (fs)->fs_metaspace)	/* data zone */
655baa12a84SKirk McKusick #define	cgmeta(fs, c)	(cgdmin(fs, c))				/* meta data */
656df8bae1dSRodney W. Grimes #define	cgdmin(fs, c)	(cgstart(fs, c) + (fs)->fs_dblkno)	/* 1st data */
657df8bae1dSRodney W. Grimes #define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno)	/* inode blk */
658df8bae1dSRodney W. Grimes #define	cgsblock(fs, c)	(cgstart(fs, c) + (fs)->fs_sblkno)	/* super blk */
659df8bae1dSRodney W. Grimes #define	cgtod(fs, c)	(cgstart(fs, c) + (fs)->fs_cblkno)	/* cg block */
660df8bae1dSRodney W. Grimes #define	cgstart(fs, c)							\
6611c85e6a3SKirk McKusick        ((fs)->fs_magic == FS_UFS2_MAGIC ? cgbase(fs, c) :		\
6621c85e6a3SKirk McKusick        (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask))))
663df8bae1dSRodney W. Grimes 
664df8bae1dSRodney W. Grimes /*
665df8bae1dSRodney W. Grimes  * Macros for handling inode numbers:
666df8bae1dSRodney W. Grimes  *     inode number to filesystem block offset.
667df8bae1dSRodney W. Grimes  *     inode number to cylinder group number.
668df8bae1dSRodney W. Grimes  *     inode number to filesystem block address.
669df8bae1dSRodney W. Grimes  */
670e870d1e6SKirk McKusick #define	ino_to_cg(fs, x)	(((ino_t)(x)) / (fs)->fs_ipg)
671df8bae1dSRodney W. Grimes #define	ino_to_fsba(fs, x)						\
672e870d1e6SKirk McKusick 	((ufs2_daddr_t)(cgimin(fs, ino_to_cg(fs, (ino_t)(x))) +		\
673e870d1e6SKirk McKusick 	    (blkstofrags((fs), ((((ino_t)(x)) % (fs)->fs_ipg) / INOPB(fs))))))
674e870d1e6SKirk McKusick #define	ino_to_fsbo(fs, x)	(((ino_t)(x)) % INOPB(fs))
675df8bae1dSRodney W. Grimes 
676df8bae1dSRodney W. Grimes /*
677df8bae1dSRodney W. Grimes  * Give cylinder group number for a filesystem block.
678df8bae1dSRodney W. Grimes  * Give cylinder group block number for a filesystem block.
679df8bae1dSRodney W. Grimes  */
680df8bae1dSRodney W. Grimes #define	dtog(fs, d)	((d) / (fs)->fs_fpg)
681df8bae1dSRodney W. Grimes #define	dtogd(fs, d)	((d) % (fs)->fs_fpg)
682df8bae1dSRodney W. Grimes 
683df8bae1dSRodney W. Grimes /*
684df8bae1dSRodney W. Grimes  * Extract the bits for a block from a map.
685df8bae1dSRodney W. Grimes  * Compute the cylinder and rotational position of a cyl block addr.
686df8bae1dSRodney W. Grimes  */
687df8bae1dSRodney W. Grimes #define	blkmap(fs, map, loc) \
688df8bae1dSRodney W. Grimes     (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
689df8bae1dSRodney W. Grimes 
690df8bae1dSRodney W. Grimes /*
691df8bae1dSRodney W. Grimes  * The following macros optimize certain frequently calculated
692df8bae1dSRodney W. Grimes  * quantities by using shifts and masks in place of divisions
693df8bae1dSRodney W. Grimes  * modulos and multiplications.
694df8bae1dSRodney W. Grimes  */
695df8bae1dSRodney W. Grimes #define	blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
696df8bae1dSRodney W. Grimes 	((loc) & (fs)->fs_qbmask)
697df8bae1dSRodney W. Grimes #define	fragoff(fs, loc)	/* calculates (loc % fs->fs_fsize) */ \
698df8bae1dSRodney W. Grimes 	((loc) & (fs)->fs_qfmask)
6991c85e6a3SKirk McKusick #define	lfragtosize(fs, frag)	/* calculates ((off_t)frag * fs->fs_fsize) */ \
700d60682c2SKirk McKusick 	(((off_t)(frag)) << (fs)->fs_fshift)
701ccb17497SBruce Evans #define	lblktosize(fs, blk)	/* calculates ((off_t)blk * fs->fs_bsize) */ \
702d60682c2SKirk McKusick 	(((off_t)(blk)) << (fs)->fs_bshift)
7031dc349abSEd Maste /* Use this only when `blk' is known to be small, e.g., < UFS_NDADDR. */
704ccb17497SBruce Evans #define	smalllblktosize(fs, blk)    /* calculates (blk * fs->fs_bsize) */ \
705df8bae1dSRodney W. Grimes 	((blk) << (fs)->fs_bshift)
706df8bae1dSRodney W. Grimes #define	lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
707df8bae1dSRodney W. Grimes 	((loc) >> (fs)->fs_bshift)
708df8bae1dSRodney W. Grimes #define	numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
709df8bae1dSRodney W. Grimes 	((loc) >> (fs)->fs_fshift)
710df8bae1dSRodney W. Grimes #define	blkroundup(fs, size)	/* calculates roundup(size, fs->fs_bsize) */ \
711df8bae1dSRodney W. Grimes 	(((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)
712df8bae1dSRodney W. Grimes #define	fragroundup(fs, size)	/* calculates roundup(size, fs->fs_fsize) */ \
713df8bae1dSRodney W. Grimes 	(((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
714df8bae1dSRodney W. Grimes #define	fragstoblks(fs, frags)	/* calculates (frags / fs->fs_frag) */ \
715df8bae1dSRodney W. Grimes 	((frags) >> (fs)->fs_fragshift)
716df8bae1dSRodney W. Grimes #define	blkstofrags(fs, blks)	/* calculates (blks * fs->fs_frag) */ \
717df8bae1dSRodney W. Grimes 	((blks) << (fs)->fs_fragshift)
718df8bae1dSRodney W. Grimes #define	fragnum(fs, fsb)	/* calculates (fsb % fs->fs_frag) */ \
719df8bae1dSRodney W. Grimes 	((fsb) & ((fs)->fs_frag - 1))
720df8bae1dSRodney W. Grimes #define	blknum(fs, fsb)		/* calculates rounddown(fsb, fs->fs_frag) */ \
721df8bae1dSRodney W. Grimes 	((fsb) &~ ((fs)->fs_frag - 1))
722df8bae1dSRodney W. Grimes 
723df8bae1dSRodney W. Grimes /*
724df8bae1dSRodney W. Grimes  * Determine the number of available frags given a
725996c772fSJohn Dyson  * percentage to hold in reserve.
726df8bae1dSRodney W. Grimes  */
727df8bae1dSRodney W. Grimes #define	freespace(fs, percentreserved) \
728df8bae1dSRodney W. Grimes 	(blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
729584508a7SKirk McKusick 	(fs)->fs_cstotal.cs_nffree - \
730d60682c2SKirk McKusick 	(((off_t)((fs)->fs_dsize)) * (percentreserved) / 100))
731df8bae1dSRodney W. Grimes 
732df8bae1dSRodney W. Grimes /*
733df8bae1dSRodney W. Grimes  * Determining the size of a file block in the filesystem.
734df8bae1dSRodney W. Grimes  */
735df8bae1dSRodney W. Grimes #define	blksize(fs, ip, lbn) \
7363cf259c3SEd Maste 	(((lbn) >= UFS_NDADDR || (ip)->i_size >= \
7373cf259c3SEd Maste 	    (uint64_t)smalllblktosize(fs, (lbn) + 1)) \
738df8bae1dSRodney W. Grimes 	    ? (fs)->fs_bsize \
739df8bae1dSRodney W. Grimes 	    : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
740b1897c19SJulian Elischer #define	sblksize(fs, size, lbn) \
7411dc349abSEd Maste 	(((lbn) >= UFS_NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \
742b1897c19SJulian Elischer 	  ? (fs)->fs_bsize \
743b1897c19SJulian Elischer 	  : (fragroundup(fs, blkoff(fs, (size)))))
744b1897c19SJulian Elischer 
745113db2ddSJeff Roberson /*
746fae5c47dSKonstantin Belousov  * Number of indirects in a filesystem block.
747fae5c47dSKonstantin Belousov  */
748fae5c47dSKonstantin Belousov #define	NINDIR(fs)	((fs)->fs_nindir)
749fae5c47dSKonstantin Belousov 
750fae5c47dSKonstantin Belousov /*
7511dc349abSEd Maste  * Indirect lbns are aligned on UFS_NDADDR addresses where single indirects
752113db2ddSJeff Roberson  * are the negated address of the lowest lbn reachable, double indirects
753113db2ddSJeff Roberson  * are this lbn - 1 and triple indirects are this lbn - 2.  This yields
754113db2ddSJeff Roberson  * an unusual bit order to determine level.
755113db2ddSJeff Roberson  */
756113db2ddSJeff Roberson static inline int
757113db2ddSJeff Roberson lbn_level(ufs_lbn_t lbn)
758113db2ddSJeff Roberson {
759113db2ddSJeff Roberson 	if (lbn >= 0)
760113db2ddSJeff Roberson 		return 0;
761113db2ddSJeff Roberson 	switch (lbn & 0x3) {
762113db2ddSJeff Roberson 	case 0:
763113db2ddSJeff Roberson 		return (0);
764113db2ddSJeff Roberson 	case 1:
765113db2ddSJeff Roberson 		break;
766113db2ddSJeff Roberson 	case 2:
767113db2ddSJeff Roberson 		return (2);
768113db2ddSJeff Roberson 	case 3:
769113db2ddSJeff Roberson 		return (1);
770113db2ddSJeff Roberson 	default:
771113db2ddSJeff Roberson 		break;
772113db2ddSJeff Roberson 	}
773113db2ddSJeff Roberson 	return (-1);
774113db2ddSJeff Roberson }
775fae5c47dSKonstantin Belousov 
776fae5c47dSKonstantin Belousov static inline ufs_lbn_t
777fae5c47dSKonstantin Belousov lbn_offset(struct fs *fs, int level)
778fae5c47dSKonstantin Belousov {
779fae5c47dSKonstantin Belousov 	ufs_lbn_t res;
780fae5c47dSKonstantin Belousov 
781fae5c47dSKonstantin Belousov 	for (res = 1; level > 0; level--)
782fae5c47dSKonstantin Belousov 		res *= NINDIR(fs);
783fae5c47dSKonstantin Belousov 	return (res);
784fae5c47dSKonstantin Belousov }
785fae5c47dSKonstantin Belousov 
786df8bae1dSRodney W. Grimes /*
787996c772fSJohn Dyson  * Number of inodes in a secondary storage block/fragment.
788df8bae1dSRodney W. Grimes  */
789df8bae1dSRodney W. Grimes #define	INOPB(fs)	((fs)->fs_inopb)
790df8bae1dSRodney W. Grimes #define	INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)
791df8bae1dSRodney W. Grimes 
792df8bae1dSRodney W. Grimes /*
793113db2ddSJeff Roberson  * Softdep journal record format.
794113db2ddSJeff Roberson  */
7956f0ca273SKirk McKusick #define	JOP_UNKNOWN	0	/* JOP operation is unknown */
796113db2ddSJeff Roberson #define	JOP_ADDREF	1	/* Add a reference to an inode. */
797113db2ddSJeff Roberson #define	JOP_REMREF	2	/* Remove a reference from an inode. */
798113db2ddSJeff Roberson #define	JOP_NEWBLK	3	/* Allocate a block. */
799113db2ddSJeff Roberson #define	JOP_FREEBLK	4	/* Free a block or a tree of blocks. */
800113db2ddSJeff Roberson #define	JOP_MVREF	5	/* Move a reference from one off to another. */
801113db2ddSJeff Roberson #define	JOP_TRUNC	6	/* Partial truncation record. */
802280e091aSJeff Roberson #define	JOP_SYNC	7	/* fsync() complete record. */
8036f0ca273SKirk McKusick #define	JOP_NUMJOPTYPES	8
8046f0ca273SKirk McKusick #define JOP_NAMES {	\
8056f0ca273SKirk McKusick         "unknown",	\
8066f0ca273SKirk McKusick 	"JOP_ADDREF",	\
8076f0ca273SKirk McKusick 	"JOP_REMREF",	\
8086f0ca273SKirk McKusick 	"JOP_NEWBLK",	\
8096f0ca273SKirk McKusick 	"JOP_FREEBLK",	\
8106f0ca273SKirk McKusick 	"JOP_MVREF",	\
8116f0ca273SKirk McKusick 	"JOP_TRUNC",	\
8126f0ca273SKirk McKusick 	"JOP_SYNC" }
8136f0ca273SKirk McKusick #define JOP_OPTYPE(op) \
8146f0ca273SKirk McKusick 	(op) < JOP_NUMJOPTYPES ? joptype[op] : joptype[JOP_UNKNOWN]
815113db2ddSJeff Roberson 
816113db2ddSJeff Roberson #define	JREC_SIZE	32	/* Record and segment header size. */
817113db2ddSJeff Roberson 
818113db2ddSJeff Roberson #define	SUJ_MIN		(4 * 1024 * 1024)	/* Minimum journal size */
819113db2ddSJeff Roberson #define	SUJ_FILE	".sujournal"		/* Journal file name */
820113db2ddSJeff Roberson 
821113db2ddSJeff Roberson /*
822113db2ddSJeff Roberson  * Size of the segment record header.  There is at most one for each disk
823c0b2efceSKirk McKusick  * block in the journal.  The segment header is followed by an array of
824113db2ddSJeff Roberson  * records.  fsck depends on the first element in each record being 'op'
825113db2ddSJeff Roberson  * and the second being 'ino'.  Segments may span multiple disk blocks but
826113db2ddSJeff Roberson  * the header is present on each.
827113db2ddSJeff Roberson  */
828113db2ddSJeff Roberson struct jsegrec {
829113db2ddSJeff Roberson 	uint64_t	jsr_seq;	/* Our sequence number */
830113db2ddSJeff Roberson 	uint64_t	jsr_oldest;	/* Oldest valid sequence number */
831113db2ddSJeff Roberson 	uint16_t	jsr_cnt;	/* Count of valid records */
832455a6e0fSKonstantin Belousov 	uint16_t	jsr_blocks;	/* Count of device bsize blocks. */
833113db2ddSJeff Roberson 	uint32_t	jsr_crc;	/* 32bit crc of the valid space */
834113db2ddSJeff Roberson 	ufs_time_t	jsr_time;	/* timestamp for mount instance */
835113db2ddSJeff Roberson };
836113db2ddSJeff Roberson 
837113db2ddSJeff Roberson /*
838113db2ddSJeff Roberson  * Reference record.  Records a single link count modification.
839113db2ddSJeff Roberson  */
840113db2ddSJeff Roberson struct jrefrec {
841113db2ddSJeff Roberson 	uint32_t	jr_op;
84258b1333aSGleb Kurtsou 	uint32_t	jr_ino;
84358b1333aSGleb Kurtsou 	uint32_t	jr_parent;
844113db2ddSJeff Roberson 	uint16_t	jr_nlink;
845113db2ddSJeff Roberson 	uint16_t	jr_mode;
84658b1333aSGleb Kurtsou 	int64_t		jr_diroff;
847113db2ddSJeff Roberson 	uint64_t	jr_unused;
848113db2ddSJeff Roberson };
849113db2ddSJeff Roberson 
850113db2ddSJeff Roberson /*
851113db2ddSJeff Roberson  * Move record.  Records a reference moving within a directory block.  The
852113db2ddSJeff Roberson  * nlink is unchanged but we must search both locations.
853113db2ddSJeff Roberson  */
854113db2ddSJeff Roberson struct jmvrec {
855113db2ddSJeff Roberson 	uint32_t	jm_op;
85658b1333aSGleb Kurtsou 	uint32_t	jm_ino;
85758b1333aSGleb Kurtsou 	uint32_t	jm_parent;
858113db2ddSJeff Roberson 	uint16_t	jm_unused;
85958b1333aSGleb Kurtsou 	int64_t		jm_oldoff;
86058b1333aSGleb Kurtsou 	int64_t		jm_newoff;
861113db2ddSJeff Roberson };
862113db2ddSJeff Roberson 
863113db2ddSJeff Roberson /*
864113db2ddSJeff Roberson  * Block record.  A set of frags or tree of blocks starting at an indirect are
865113db2ddSJeff Roberson  * freed or a set of frags are allocated.
866113db2ddSJeff Roberson  */
867113db2ddSJeff Roberson struct jblkrec {
868113db2ddSJeff Roberson 	uint32_t	jb_op;
869113db2ddSJeff Roberson 	uint32_t	jb_ino;
870113db2ddSJeff Roberson 	ufs2_daddr_t	jb_blkno;
871113db2ddSJeff Roberson 	ufs_lbn_t	jb_lbn;
872113db2ddSJeff Roberson 	uint16_t	jb_frags;
873113db2ddSJeff Roberson 	uint16_t	jb_oldfrags;
874113db2ddSJeff Roberson 	uint32_t	jb_unused;
875113db2ddSJeff Roberson };
876113db2ddSJeff Roberson 
877113db2ddSJeff Roberson /*
878113db2ddSJeff Roberson  * Truncation record.  Records a partial truncation so that it may be
879280e091aSJeff Roberson  * completed at check time.  Also used for sync records.
880113db2ddSJeff Roberson  */
881113db2ddSJeff Roberson struct jtrncrec {
882113db2ddSJeff Roberson 	uint32_t	jt_op;
883113db2ddSJeff Roberson 	uint32_t	jt_ino;
88458b1333aSGleb Kurtsou 	int64_t		jt_size;
885113db2ddSJeff Roberson 	uint32_t	jt_extsize;
886113db2ddSJeff Roberson 	uint32_t	jt_pad[3];
887113db2ddSJeff Roberson };
888113db2ddSJeff Roberson 
889113db2ddSJeff Roberson union jrec {
890113db2ddSJeff Roberson 	struct jsegrec	rec_jsegrec;
891113db2ddSJeff Roberson 	struct jrefrec	rec_jrefrec;
892113db2ddSJeff Roberson 	struct jmvrec	rec_jmvrec;
893113db2ddSJeff Roberson 	struct jblkrec	rec_jblkrec;
894113db2ddSJeff Roberson 	struct jtrncrec	rec_jtrncrec;
895113db2ddSJeff Roberson };
896113db2ddSJeff Roberson 
897113db2ddSJeff Roberson #ifdef CTASSERT
898113db2ddSJeff Roberson CTASSERT(sizeof(struct jsegrec) == JREC_SIZE);
899113db2ddSJeff Roberson CTASSERT(sizeof(struct jrefrec) == JREC_SIZE);
900113db2ddSJeff Roberson CTASSERT(sizeof(struct jmvrec) == JREC_SIZE);
901113db2ddSJeff Roberson CTASSERT(sizeof(struct jblkrec) == JREC_SIZE);
902113db2ddSJeff Roberson CTASSERT(sizeof(struct jtrncrec) == JREC_SIZE);
903113db2ddSJeff Roberson CTASSERT(sizeof(union jrec) == JREC_SIZE);
904113db2ddSJeff Roberson #endif
905113db2ddSJeff Roberson 
906df8bae1dSRodney W. Grimes extern int inside[], around[];
907831b1ff7SKirk McKusick extern uint8_t *fragtbl[];
908eb9fb78cSPaul Richards 
9091848286aSEdward Tomasz Napierala /*
9101848286aSEdward Tomasz Napierala  * IOCTLs used for filesystem write suspension.
9111848286aSEdward Tomasz Napierala  */
9121848286aSEdward Tomasz Napierala #define	UFSSUSPEND	_IOW('U', 1, fsid_t)
9131848286aSEdward Tomasz Napierala #define	UFSRESUME	_IO('U', 2)
9141848286aSEdward Tomasz Napierala 
915eb9fb78cSPaul Richards #endif
916