xref: /dragonfly/sys/vfs/hammer/hammer_disk.h (revision 44753b81)
1 /*
2  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3  *
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $DragonFly: src/sys/vfs/hammer/hammer_disk.h,v 1.55 2008/11/13 02:18:43 dillon Exp $
35  */
36 
37 #ifndef VFS_HAMMER_DISK_H_
38 #define VFS_HAMMER_DISK_H_
39 
40 #include <sys/endian.h>
41 
42 #ifndef _SYS_UUID_H_
43 #include <sys/uuid.h>
44 #endif
45 
46 /*
47  * The structures below represent the on-disk format for a HAMMER
48  * filesystem.  Note that all fields for on-disk structures are naturally
49  * aligned.  HAMMER uses little endian for fields in on-disk structures.
50  * HAMMER doesn't support big endian arch, but is planned.
51  *
52  * Most of HAMMER revolves around the concept of an object identifier.  An
53  * obj_id is a 64 bit quantity which uniquely identifies a filesystem object
54  * FOR THE ENTIRE LIFE OF THE FILESYSTEM.  This uniqueness allows backups
55  * and mirrors to retain varying amounts of filesystem history by removing
56  * any possibility of conflict through identifier reuse.
57  *
58  * A HAMMER filesystem may span multiple volumes.
59  *
60  * A HAMMER filesystem uses a 16K filesystem buffer size.  All filesystem
61  * I/O is done in multiples of 16K.
62  *
63  * 64K X-bufs are used for blocks >= a file's 1MB mark.
64  *
65  * Per-volume storage limit: 52 bits		4096 TB
66  * Per-Zone storage limit: 60 bits		1 MTB
67  * Per-filesystem storage limit: 60 bits	1 MTB
68  */
69 #define HAMMER_BUFSIZE		16384
70 #define HAMMER_XBUFSIZE		65536
71 #define HAMMER_HBUFSIZE		(HAMMER_BUFSIZE / 2)
72 #define HAMMER_XDEMARC		(1024 * 1024)
73 #define HAMMER_BUFMASK		(HAMMER_BUFSIZE - 1)
74 #define HAMMER_XBUFMASK		(HAMMER_XBUFSIZE - 1)
75 
76 #define HAMMER_BUFSIZE64	((uint64_t)HAMMER_BUFSIZE)
77 #define HAMMER_BUFMASK64	((uint64_t)HAMMER_BUFMASK)
78 
79 #define HAMMER_XBUFSIZE64	((uint64_t)HAMMER_XBUFSIZE)
80 #define HAMMER_XBUFMASK64	((uint64_t)HAMMER_XBUFMASK)
81 
82 #define HAMMER_OFF_ZONE_MASK	0xF000000000000000ULL /* zone portion */
83 #define HAMMER_OFF_VOL_MASK	0x0FF0000000000000ULL /* volume portion */
84 #define HAMMER_OFF_SHORT_MASK	0x000FFFFFFFFFFFFFULL /* offset portion */
85 #define HAMMER_OFF_LONG_MASK	0x0FFFFFFFFFFFFFFFULL /* offset portion */
86 
87 #define HAMMER_OFF_BAD		((hammer_off_t)-1)
88 
89 /*
90  * The current limit of volumes that can make up a HAMMER FS
91  */
92 #define HAMMER_MAX_VOLUMES	256
93 
94 /*
95  * Reserved space for (future) header junk after the volume header.
96  */
97 #define HAMMER_VOL_ALLOC	(HAMMER_BUFSIZE * 16)
98 
99 /*
100  * Hammer transaction ids are 64 bit unsigned integers and are usually
101  * synchronized with the time of day in nanoseconds.
102  *
103  * Hammer offsets are used for FIFO indexing and embed a cycle counter
104  * and volume number in addition to the offset.  Most offsets are required
105  * to be 16 KB aligned.
106  */
107 typedef uint64_t hammer_tid_t;
108 typedef uint64_t hammer_off_t;
109 typedef uint32_t hammer_crc_t;
110 
111 #define HAMMER_MIN_TID		0ULL			/* unsigned */
112 #define HAMMER_MAX_TID		0xFFFFFFFFFFFFFFFFULL	/* unsigned */
113 #define HAMMER_MIN_KEY		-0x8000000000000000LL	/* signed */
114 #define HAMMER_MAX_KEY		0x7FFFFFFFFFFFFFFFLL	/* signed */
115 #define HAMMER_MIN_OBJID	HAMMER_MIN_KEY		/* signed */
116 #define HAMMER_MAX_OBJID	HAMMER_MAX_KEY		/* signed */
117 #define HAMMER_MIN_RECTYPE	0x0U			/* unsigned */
118 #define HAMMER_MAX_RECTYPE	0xFFFFU			/* unsigned */
119 #define HAMMER_MIN_OFFSET	0ULL			/* unsigned */
120 #define HAMMER_MAX_OFFSET	0xFFFFFFFFFFFFFFFFULL	/* unsigned */
121 
122 /*
123  * hammer_off_t has several different encodings.  Note that not all zones
124  * encode a vol_no.  Zone bits are not a part of filesystem capacity as
125  * the zone bits aren't directly or indirectly mapped to physical volumes.
126  *
127  * In other words, HAMMER's logical filesystem offset consists of 64 bits,
128  * but the filesystem is considered 60 bits filesystem, not 64 bits.
129  * The maximum filesystem capacity is 1EB, not 16EB.
130  *
131  * zone 0:		available, a big-block that contains the offset is unused
132  * zone 1 (z,v,o):	raw volume relative (offset 0 is the volume header)
133  * zone 2 (z,v,o):	raw buffer relative (offset 0 is the first buffer)
134  * zone 3 (z,o):	undo fifo	- actually zone-2 address, fixed phys array in vol hdr
135  * zone 4 (z,v,o):	freemap		- only real blockmap
136  * zone 8 (z,v,o):	B-Tree		- actually zone-2 address
137  * zone 9 (z,v,o):	meta		- actually zone-2 address
138  * zone 10 (z,v,o):	large-data	- actually zone-2 address
139  * zone 11 (z,v,o):	small-data	- actually zone-2 address
140  * zone 15:		unavailable, usually the offset is beyond volume size
141  *
142  * layer1/layer2 direct map:
143  *	     Maximum HAMMER filesystem capacity from volume aspect
144  *	     2^8(max volumes) * 2^52(max volume size) = 2^60 = 1EB
145  *	    <------------------------------------------------------------->
146  *	     8bits   52bits
147  *	    <------><----------------------------------------------------->
148  *	zzzzvvvvvvvvoooo oooooooooooooooo oooooooooooooooo oooooooooooooooo
149  *	----111111111111 1111112222222222 222222222ooooooo oooooooooooooooo
150  *	    <-----------------><------------------><---------------------->
151  *	     18bits             19bits              23bits
152  *	    <------------------------------------------------------------->
153  *	     2^18(layer1) * 2^19(layer2) * 2^23(big-block) = 2^60 = 1EB
154  *	     Maximum HAMMER filesystem capacity from blockmap aspect
155  */
156 
157 #define HAMMER_ZONE_RAW_VOLUME		0x1000000000000000ULL
158 #define HAMMER_ZONE_RAW_BUFFER		0x2000000000000000ULL
159 #define HAMMER_ZONE_UNDO		0x3000000000000000ULL
160 #define HAMMER_ZONE_FREEMAP		0x4000000000000000ULL
161 #define HAMMER_ZONE_RESERVED05		0x5000000000000000ULL  /* not used */
162 #define HAMMER_ZONE_RESERVED06		0x6000000000000000ULL  /* not used */
163 #define HAMMER_ZONE_RESERVED07		0x7000000000000000ULL  /* not used */
164 #define HAMMER_ZONE_BTREE		0x8000000000000000ULL
165 #define HAMMER_ZONE_META		0x9000000000000000ULL
166 #define HAMMER_ZONE_LARGE_DATA		0xA000000000000000ULL
167 #define HAMMER_ZONE_SMALL_DATA		0xB000000000000000ULL
168 #define HAMMER_ZONE_RESERVED0C		0xC000000000000000ULL  /* not used */
169 #define HAMMER_ZONE_RESERVED0D		0xD000000000000000ULL  /* not used */
170 #define HAMMER_ZONE_RESERVED0E		0xE000000000000000ULL  /* not used */
171 #define HAMMER_ZONE_UNAVAIL		0xF000000000000000ULL
172 
173 #define HAMMER_ZONE_RAW_VOLUME_INDEX	1
174 #define HAMMER_ZONE_RAW_BUFFER_INDEX	2
175 #define HAMMER_ZONE_UNDO_INDEX		3
176 #define HAMMER_ZONE_FREEMAP_INDEX	4
177 #define HAMMER_ZONE_BTREE_INDEX		8
178 #define HAMMER_ZONE_META_INDEX		9
179 #define HAMMER_ZONE_LARGE_DATA_INDEX	10
180 #define HAMMER_ZONE_SMALL_DATA_INDEX	11
181 #define HAMMER_ZONE_UNAVAIL_INDEX	15
182 
183 #define HAMMER_MAX_ZONES		16
184 
185 #define HAMMER_ZONE(offset)		((offset) & HAMMER_OFF_ZONE_MASK)
186 
187 #define hammer_is_zone_raw_volume(offset)		\
188 	(HAMMER_ZONE(offset) == HAMMER_ZONE_RAW_VOLUME)
189 #define hammer_is_zone_raw_buffer(offset)		\
190 	(HAMMER_ZONE(offset) == HAMMER_ZONE_RAW_BUFFER)
191 #define hammer_is_zone_undo(offset)			\
192 	(HAMMER_ZONE(offset) == HAMMER_ZONE_UNDO)
193 #define hammer_is_zone_freemap(offset)			\
194 	(HAMMER_ZONE(offset) == HAMMER_ZONE_FREEMAP)
195 #define hammer_is_zone_btree(offset)			\
196 	(HAMMER_ZONE(offset) == HAMMER_ZONE_BTREE)
197 #define hammer_is_zone_meta(offset)			\
198 	(HAMMER_ZONE(offset) == HAMMER_ZONE_META)
199 #define hammer_is_zone_large_data(offset)		\
200 	(HAMMER_ZONE(offset) == HAMMER_ZONE_LARGE_DATA)
201 #define hammer_is_zone_small_data(offset)		\
202 	(HAMMER_ZONE(offset) == HAMMER_ZONE_SMALL_DATA)
203 #define hammer_is_zone_unavail(offset)			\
204 	(HAMMER_ZONE(offset) == HAMMER_ZONE_UNAVAIL)
205 #define hammer_is_zone_data(offset)			\
206 	(hammer_is_zone_large_data(offset) || hammer_is_zone_small_data(offset))
207 
208 /*
209  * Test if the zone is directly mapped to zone-2 offset via freemap.
210  */
211 #define hammer_is_zone2_mapped_index(zone)		\
212 	((zone) >= HAMMER_ZONE_BTREE_INDEX &&		\
213 	 (zone) < HAMMER_MAX_ZONES)
214 /*
215  * Test if the zone is directly mapped to zone-2 offset. The word
216  * directly here means the zone is neither RAW_VOLUME nor UNDO zone.
217  */
218 #define hammer_is_direct_mapped_index(zone)		\
219 	(((zone) == HAMMER_ZONE_RAW_BUFFER_INDEX) ||	\
220 	 ((zone) == HAMMER_ZONE_FREEMAP_INDEX) ||	\
221 	 hammer_is_zone2_mapped_index(zone))
222 
223 #define HAMMER_ZONE_ENCODE(zone, ham_off)		\
224 	(((hammer_off_t)(zone) << 60) | (ham_off))
225 #define HAMMER_ZONE_DECODE(ham_off)			\
226 	((int)(((hammer_off_t)(ham_off) >> 60)))
227 
228 #define HAMMER_VOL_ENCODE(vol_no)			\
229 	((hammer_off_t)((vol_no) & 255) << 52)
230 #define HAMMER_VOL_DECODE(ham_off)			\
231 	((int)(((hammer_off_t)(ham_off) >> 52) & 255))
232 
233 #define HAMMER_OFF_SHORT_ENCODE(offset)			\
234 	((hammer_off_t)(offset) & HAMMER_OFF_SHORT_MASK)
235 #define HAMMER_OFF_LONG_ENCODE(offset)			\
236 	((hammer_off_t)(offset) & HAMMER_OFF_LONG_MASK)
237 
238 #define HAMMER_ENCODE(zone, vol_no, offset)		\
239 	(((hammer_off_t)(zone) << 60) |			\
240 	HAMMER_VOL_ENCODE(vol_no) |			\
241 	HAMMER_OFF_SHORT_ENCODE(offset))
242 #define HAMMER_ENCODE_RAW_VOLUME(vol_no, offset)	\
243 	HAMMER_ENCODE(HAMMER_ZONE_RAW_VOLUME_INDEX, vol_no, offset)
244 #define HAMMER_ENCODE_RAW_BUFFER(vol_no, offset)	\
245 	HAMMER_ENCODE(HAMMER_ZONE_RAW_BUFFER_INDEX, vol_no, offset)
246 #define HAMMER_ENCODE_FREEMAP(vol_no, offset)		\
247 	HAMMER_ENCODE(HAMMER_ZONE_FREEMAP_INDEX, vol_no, offset)
248 
249 /*
250  * Translate a zone address to zone-X address.
251  */
252 #define hammer_xlate_to_zoneX(zone, offset)		\
253 	HAMMER_ZONE_ENCODE((zone), (offset) & ~HAMMER_OFF_ZONE_MASK)
254 #define hammer_xlate_to_zone2(offset)			\
255 	hammer_xlate_to_zoneX(HAMMER_ZONE_RAW_BUFFER_INDEX, (offset))
256 
257 #define hammer_data_zone(data_len)			\
258 	(((data_len) >= HAMMER_BUFSIZE) ?		\
259 	 HAMMER_ZONE_LARGE_DATA :			\
260 	 HAMMER_ZONE_SMALL_DATA)
261 #define hammer_data_zone_index(data_len)		\
262 	(((data_len) >= HAMMER_BUFSIZE) ?		\
263 	 HAMMER_ZONE_LARGE_DATA_INDEX :			\
264 	 HAMMER_ZONE_SMALL_DATA_INDEX)
265 
266 /*
267  * Big-Block backing store
268  *
269  * A blockmap is a two-level map which translates a blockmap-backed zone
270  * offset into a raw zone 2 offset.  The layer 1 handles 18 bits and the
271  * layer 2 handles 19 bits.  The 8M big-block size is 23 bits so two
272  * layers gives us 18+19+23 = 60 bits of address space.
273  *
274  * When using hinting for a blockmap lookup, the hint is lost when the
275  * scan leaves the HINTBLOCK, which is typically several BIGBLOCK's.
276  * HINTBLOCK is a heuristic.
277  */
278 #define HAMMER_HINTBLOCK_SIZE		(HAMMER_BIGBLOCK_SIZE * 4)
279 #define HAMMER_HINTBLOCK_MASK64		((uint64_t)HAMMER_HINTBLOCK_SIZE - 1)
280 #define HAMMER_BIGBLOCK_SIZE		(8192 * 1024)
281 #define HAMMER_BIGBLOCK_SIZE64		((uint64_t)HAMMER_BIGBLOCK_SIZE)
282 #define HAMMER_BIGBLOCK_MASK		(HAMMER_BIGBLOCK_SIZE - 1)
283 #define HAMMER_BIGBLOCK_MASK64		((uint64_t)HAMMER_BIGBLOCK_SIZE - 1)
284 #define HAMMER_BIGBLOCK_BITS		23
285 #if 0
286 #define HAMMER_BIGBLOCK_OVERFILL	(6144 * 1024)
287 #endif
288 #if (1 << HAMMER_BIGBLOCK_BITS) != HAMMER_BIGBLOCK_SIZE
289 #error "HAMMER_BIGBLOCK_BITS BROKEN"
290 #endif
291 
292 #define HAMMER_BUFFERS_PER_BIGBLOCK			\
293 	(HAMMER_BIGBLOCK_SIZE / HAMMER_BUFSIZE)
294 #define HAMMER_BUFFERS_PER_BIGBLOCK_MASK		\
295 	(HAMMER_BUFFERS_PER_BIGBLOCK - 1)
296 #define HAMMER_BUFFERS_PER_BIGBLOCK_MASK64		\
297 	((hammer_off_t)HAMMER_BUFFERS_PER_BIGBLOCK_MASK)
298 
299 /*
300  * Maximum number of mirrors operating in master mode (multi-master
301  * clustering and mirroring). Note that HAMMER1 does not support
302  * multi-master clustering as of 2015.
303  */
304 #define HAMMER_MAX_MASTERS		16
305 
306 /*
307  * The blockmap is somewhat of a degenerate structure.  HAMMER only actually
308  * uses it in its original incarnation to implement the freemap.
309  *
310  * zone:1	raw volume (no blockmap)
311  * zone:2	raw buffer (no blockmap)
312  * zone:3	undomap    (direct layer2 array in volume header)
313  * zone:4	freemap    (the only real blockmap)
314  * zone:8-15	zone id used to classify big-block only, address is actually
315  *		a zone-2 address.
316  */
317 typedef struct hammer_blockmap {
318 	hammer_off_t	phys_offset;    /* zone-2 physical offset */
319 	hammer_off_t	first_offset;	/* zone-X logical offset (zone 3) */
320 	hammer_off_t	next_offset;	/* zone-X logical offset */
321 	hammer_off_t	alloc_offset;	/* zone-X logical offset */
322 	uint32_t	reserved01;
323 	hammer_crc_t	entry_crc;
324 } *hammer_blockmap_t;
325 
326 #define HAMMER_BLOCKMAP_CRCSIZE	\
327 	offsetof(struct hammer_blockmap, entry_crc)
328 
329 /*
330  * The blockmap is a 2-layer entity made up of big-blocks.  The first layer
331  * contains 262144 32-byte entries (18 bits), the second layer contains
332  * 524288 16-byte entries (19 bits), representing 8MB (23 bit) blockmaps.
333  * 18+19+23 = 60 bits.  The top four bits are the zone id.
334  *
335  * Currently only the freemap utilizes both layers in all their glory.
336  * All primary data/meta-data zones actually encode a zone-2 address
337  * requiring no real blockmap translation.
338  *
339  * The freemap uses the upper 8 bits of layer-1 to identify the volume,
340  * thus any space allocated via the freemap can be directly translated
341  * to a zone:2 (or zone:8-15) address.
342  *
343  * zone-X blockmap offset: [zone:4][layer1:18][layer2:19][big-block:23]
344  */
345 
346 /*
347  * 32 bytes layer1 entry for 8MB big-block.
348  * A big-block can hold 2^23 / 2^5 = 2^18 layer1 entries,
349  * which equals bits assigned for layer1 in zone-2 address.
350  */
351 typedef struct hammer_blockmap_layer1 {
352 	hammer_off_t	blocks_free;	/* big-blocks free */
353 	hammer_off_t	phys_offset;	/* UNAVAIL or zone-2 */
354 	hammer_off_t	reserved01;
355 	hammer_crc_t	layer2_crc;	/* xor'd crc's of HAMMER_BLOCKSIZE */
356 					/* (not yet used) */
357 	hammer_crc_t	layer1_crc;	/* MUST BE LAST FIELD OF STRUCTURE*/
358 } *hammer_blockmap_layer1_t;
359 
360 #define HAMMER_LAYER1_CRCSIZE	\
361 	offsetof(struct hammer_blockmap_layer1, layer1_crc)
362 
363 /*
364  * 16 bytes layer2 entry for 8MB big-blocks.
365  * A big-block can hold 2^23 / 2^4 = 2^19 layer2 entries,
366  * which equals bits assigned for layer2 in zone-2 address.
367  *
368  * NOTE: bytes_free is signed and can legally go negative if/when data
369  *	 de-dup occurs.  This field will never go higher than
370  *	 HAMMER_BIGBLOCK_SIZE.  If exactly HAMMER_BIGBLOCK_SIZE
371  *	 the big-block is completely free.
372  */
373 typedef struct hammer_blockmap_layer2 {
374 	uint8_t		zone;		/* typed allocation zone */
375 	uint8_t		reserved01;
376 	uint16_t	reserved02;
377 	uint32_t	append_off;	/* allocatable space index */
378 	int32_t		bytes_free;	/* bytes free within this big-block */
379 	hammer_crc_t	entry_crc;
380 } *hammer_blockmap_layer2_t;
381 
382 #define HAMMER_LAYER2_CRCSIZE	\
383 	offsetof(struct hammer_blockmap_layer2, entry_crc)
384 
385 #define HAMMER_BLOCKMAP_UNAVAIL	((hammer_off_t)-1LL)
386 
387 #define HAMMER_BLOCKMAP_RADIX1	/* 2^18 = 262144 */	\
388 	((int)(HAMMER_BIGBLOCK_SIZE / sizeof(struct hammer_blockmap_layer1)))
389 #define HAMMER_BLOCKMAP_RADIX2	/* 2^19 = 524288 */	\
390 	((int)(HAMMER_BIGBLOCK_SIZE / sizeof(struct hammer_blockmap_layer2)))
391 
392 #define HAMMER_BLOCKMAP_LAYER1	/* 2^(18+19+23) = 1EB */	\
393 	(HAMMER_BLOCKMAP_RADIX1 * HAMMER_BLOCKMAP_LAYER2)
394 #define HAMMER_BLOCKMAP_LAYER2	/* 2^(19+23) = 4TB */		\
395 	(HAMMER_BLOCKMAP_RADIX2 * HAMMER_BIGBLOCK_SIZE64)
396 
397 #define HAMMER_BLOCKMAP_LAYER1_MASK	(HAMMER_BLOCKMAP_LAYER1 - 1)
398 #define HAMMER_BLOCKMAP_LAYER2_MASK	(HAMMER_BLOCKMAP_LAYER2 - 1)
399 
400 /*
401  * Index within layer1 or layer2 big-block for the entry representing
402  * a zone-2 physical offset.
403  */
404 #define HAMMER_BLOCKMAP_LAYER1_INDEX(zone2_offset)		\
405 	((int)(((zone2_offset) & HAMMER_BLOCKMAP_LAYER1_MASK) /	\
406 	 HAMMER_BLOCKMAP_LAYER2))
407 
408 #define HAMMER_BLOCKMAP_LAYER2_INDEX(zone2_offset)		\
409 	((int)(((zone2_offset) & HAMMER_BLOCKMAP_LAYER2_MASK) /	\
410 	HAMMER_BIGBLOCK_SIZE64))
411 
412 /*
413  * Byte offset within layer1 or layer2 big-block for the entry representing
414  * a zone-2 physical offset.  Multiply the index by sizeof(blockmap_layer).
415  */
416 #define HAMMER_BLOCKMAP_LAYER1_OFFSET(zone2_offset)		\
417 	(HAMMER_BLOCKMAP_LAYER1_INDEX(zone2_offset) *		\
418 	 sizeof(struct hammer_blockmap_layer1))
419 
420 #define HAMMER_BLOCKMAP_LAYER2_OFFSET(zone2_offset)		\
421 	(HAMMER_BLOCKMAP_LAYER2_INDEX(zone2_offset) *		\
422 	 sizeof(struct hammer_blockmap_layer2))
423 
424 /*
425  * HAMMER UNDO parameters.  The UNDO fifo is mapped directly in the volume
426  * header with an array of layer2 structures.  A maximum of (128x8MB) = 1GB
427  * may be reserved.  The size of the undo fifo is usually set a newfs time
428  * but can be adjusted if the filesystem is taken offline.
429  */
430 #define HAMMER_UNDO_LAYER2	128	/* max layer2 undo mapping entries */
431 
432 /*
433  * All on-disk HAMMER structures which make up elements of the UNDO FIFO
434  * contain a hammer_fifo_head and hammer_fifo_tail structure.  This structure
435  * contains all the information required to validate the fifo element
436  * and to scan the fifo in either direction.  The head is typically embedded
437  * in higher level hammer on-disk structures while the tail is typically
438  * out-of-band.  hdr_size is the size of the whole mess, including the tail.
439  *
440  * All undo structures are guaranteed to not cross a 16K filesystem
441  * buffer boundary.  Most undo structures are fairly small.  Data spaces
442  * are not immediately reused by HAMMER so file data is not usually recorded
443  * as part of an UNDO.
444  *
445  * PAD elements are allowed to take up only 8 bytes of space as a special
446  * case, containing only hdr_signature, hdr_type, and hdr_size fields,
447  * and with the tail overloaded onto the head structure for 8 bytes total.
448  *
449  * Every undo record has a sequence number.  This number is unrelated to
450  * transaction ids and instead collects the undo transactions associated
451  * with a single atomic operation.  A larger transactional operation, such
452  * as a remove(), may consist of several smaller atomic operations
453  * representing raw meta-data operations.
454  *
455  *				HAMMER VERSION 4 CHANGES
456  *
457  * In HAMMER version 4 the undo structure alignment is reduced from 16384
458  * to 512 bytes in order to ensure that each 512 byte sector begins with
459  * a header.  The hdr_seq field in the header is a 32 bit sequence number
460  * which allows the recovery code to detect missing sectors
461  * without relying on the 32-bit crc and to definitively identify the current
462  * undo sequence space without having to rely on information from the volume
463  * header.  In addition, new REDO entries in the undo space are used to
464  * record write, write/extend, and transaction id updates.
465  *
466  * The grand result is:
467  *
468  * (1) The volume header no longer needs to be synchronized for most
469  *     flush and fsync operations.
470  *
471  * (2) Most fsync operations need only lay down REDO records
472  *
473  * (3) Data overwrite for nohistory operations covered by REDO records
474  *     can be supported (instead of rolling a new block allocation),
475  *     by rolling UNDO for the prior contents of the data.
476  *
477  *				HAMMER VERSION 5 CHANGES
478  *
479  * Hammer version 5 contains a minor adjustment making layer2's bytes_free
480  * field signed, allowing dedup to push it into the negative domain.
481  */
482 #define HAMMER_HEAD_ALIGN		8
483 #define HAMMER_HEAD_ALIGN_MASK		(HAMMER_HEAD_ALIGN - 1)
484 #define HAMMER_HEAD_DOALIGN(bytes)	\
485 	(((bytes) + HAMMER_HEAD_ALIGN_MASK) & ~HAMMER_HEAD_ALIGN_MASK)
486 
487 #define HAMMER_UNDO_ALIGN		512
488 #define HAMMER_UNDO_ALIGN64		((uint64_t)512)
489 #define HAMMER_UNDO_MASK		(HAMMER_UNDO_ALIGN - 1)
490 #define HAMMER_UNDO_MASK64		(HAMMER_UNDO_ALIGN64 - 1)
491 
492 typedef struct hammer_fifo_head {
493 	uint16_t hdr_signature;
494 	uint16_t hdr_type;
495 	uint32_t hdr_size;	/* Aligned size of the whole mess */
496 	uint32_t hdr_seq;	/* Sequence number */
497 	hammer_crc_t hdr_crc;	/* XOR crc up to field w/ crc after field */
498 } *hammer_fifo_head_t;
499 
500 #define HAMMER_FIFO_HEAD_CRCOFF	offsetof(struct hammer_fifo_head, hdr_crc)
501 
502 typedef struct hammer_fifo_tail {
503 	uint16_t tail_signature;
504 	uint16_t tail_type;
505 	uint32_t tail_size;	/* aligned size of the whole mess */
506 } *hammer_fifo_tail_t;
507 
508 /*
509  * Fifo header types.
510  *
511  * NOTE: 0x8000U part of HAMMER_HEAD_TYPE_PAD can be removed if the HAMMER
512  * version ever gets bumped again. It exists only to keep compatibility with
513  * older versions.
514  */
515 #define HAMMER_HEAD_TYPE_PAD	(0x0040U | 0x8000U)
516 #define HAMMER_HEAD_TYPE_DUMMY	0x0041U		/* dummy entry w/seqno */
517 #define HAMMER_HEAD_TYPE_UNDO	0x0043U		/* random UNDO information */
518 #define HAMMER_HEAD_TYPE_REDO	0x0044U		/* data REDO / fast fsync */
519 
520 #define HAMMER_HEAD_SIGNATURE	0xC84EU
521 #define HAMMER_TAIL_SIGNATURE	0xC74FU
522 
523 /*
524  * Misc FIFO structures.
525  *
526  * UNDO - Raw meta-data media updates.
527  */
528 typedef struct hammer_fifo_undo {
529 	struct hammer_fifo_head	head;
530 	hammer_off_t		undo_offset;	/* zone-1,2 offset */
531 	int32_t			undo_data_bytes;
532 	int32_t			undo_reserved01;
533 	/* followed by data */
534 } *hammer_fifo_undo_t;
535 
536 /*
537  * REDO (HAMMER version 4+) - Logical file writes/truncates.
538  *
539  * REDOs contain information which will be duplicated in a later meta-data
540  * update, allowing fast write()+fsync() operations.  REDOs can be ignored
541  * without harming filesystem integrity but must be processed if fsync()
542  * semantics are desired.
543  *
544  * Unlike UNDOs which are processed backwards within the recovery span,
545  * REDOs must be processed forwards starting further back (starting outside
546  * the recovery span).
547  *
548  *	WRITE	- Write logical file (with payload).  Executed both
549  *		  out-of-span and in-span.  Out-of-span WRITEs may be
550  *		  filtered out by TERMs.
551  *
552  *	TRUNC	- Truncate logical file (no payload).  Executed both
553  *		  out-of-span and in-span.  Out-of-span WRITEs may be
554  *		  filtered out by TERMs.
555  *
556  *	TERM_*	- Indicates meta-data was committed (if out-of-span) or
557  *		  will be rolled-back (in-span).  Any out-of-span TERMs
558  *		  matching earlier WRITEs remove those WRITEs from
559  *		  consideration as they might conflict with a later data
560  *		  commit (which is not being rolled-back).
561  *
562  *	SYNC	- The earliest in-span SYNC (the last one when scanning
563  *		  backwards) tells the recovery code how far out-of-span
564  *		  it must go to run REDOs.
565  *
566  * NOTE: WRITEs do not always have matching TERMs even under
567  *	 perfect conditions because truncations might remove the
568  *	 buffers from consideration.  I/O problems can also remove
569  *	 buffers from consideration.
570  *
571  *	 TRUNCSs do not always have matching TERMs because several
572  *	 truncations may be aggregated together into a single TERM.
573  */
574 typedef struct hammer_fifo_redo {
575 	struct hammer_fifo_head	head;
576 	int64_t			redo_objid;	/* file being written */
577 	hammer_off_t		redo_offset;	/* logical offset in file */
578 	int32_t			redo_data_bytes;
579 	uint32_t		redo_flags;
580 	uint32_t		redo_localization;
581 	uint32_t		redo_reserved;
582 	uint64_t		redo_mtime;	/* set mtime */
583 } *hammer_fifo_redo_t;
584 
585 #define HAMMER_REDO_WRITE	0x00000001
586 #define HAMMER_REDO_TRUNC	0x00000002
587 #define HAMMER_REDO_TERM_WRITE	0x00000004
588 #define HAMMER_REDO_TERM_TRUNC	0x00000008
589 #define HAMMER_REDO_SYNC	0x00000010
590 
591 typedef union hammer_fifo_any {
592 	struct hammer_fifo_head	head;
593 	struct hammer_fifo_undo	undo;
594 	struct hammer_fifo_redo	redo;
595 } *hammer_fifo_any_t;
596 
597 /*
598  * Volume header types
599  */
600 #define HAMMER_FSBUF_VOLUME	0xC8414D4DC5523031ULL	/* HAMMER01 */
601 #define HAMMER_FSBUF_VOLUME_REV	0x313052C54D4D41C8ULL	/* (reverse endian) */
602 
603 /*
604  * HAMMER Volume header
605  *
606  * A HAMMER filesystem can be built from 1-256 block devices, each block
607  * device contains a volume header followed by however many buffers fit
608  * into the volume.
609  *
610  * One of the volumes making up a HAMMER filesystem is the root volume.
611  * The root volume is always volume #0 which is the first block device path
612  * specified by newfs_hammer(8).  All HAMMER volumes have a volume header,
613  * however the root volume may be the only volume that has valid values for
614  * some fields in the header.
615  *
616  * Special field notes:
617  *
618  *	vol_bot_beg - offset of boot area (mem_beg - bot_beg bytes)
619  *	vol_mem_beg - offset of memory log (buf_beg - mem_beg bytes)
620  *	vol_buf_beg - offset of the first buffer in volume
621  *	vol_buf_end - offset of volume EOF (on buffer boundary)
622  *
623  *	The memory log area allows a kernel to cache new records and data
624  *	in memory without allocating space in the actual filesystem to hold
625  *	the records and data.  In the event that a filesystem becomes full,
626  *	any records remaining in memory can be flushed to the memory log
627  *	area.  This allows the kernel to immediately return success.
628  *
629  *	The buffer offset is a physical offset of zone-2 offset. The lower
630  *	52 bits of the zone-2 offset is added to the buffer offset of each
631  *	volume to generate an actual I/O offset within the block device.
632  *
633  *	NOTE: boot area and memory log are currently not used.
634  */
635 
636 /*
637  * Filesystem type string
638  */
639 #define HAMMER_FSTYPE_STRING		"DragonFly HAMMER"
640 
641 /*
642  * These macros are only used by userspace when userspace commands either
643  * initialize or add a new HAMMER volume.
644  */
645 #define HAMMER_BOOT_MINBYTES		(32*1024)
646 #define HAMMER_BOOT_NOMBYTES		(64LL*1024*1024)
647 #define HAMMER_BOOT_MAXBYTES		(256LL*1024*1024)
648 
649 #define HAMMER_MEM_MINBYTES		(256*1024)
650 #define HAMMER_MEM_NOMBYTES		(1LL*1024*1024*1024)
651 #define HAMMER_MEM_MAXBYTES		(64LL*1024*1024*1024)
652 
653 typedef struct hammer_volume_ondisk {
654 	uint64_t vol_signature;	/* HAMMER_FSBUF_VOLUME for a valid header */
655 
656 	/*
657 	 * These are relative to block device offset, not zone offsets.
658 	 */
659 	int64_t vol_bot_beg;	/* offset of boot area */
660 	int64_t vol_mem_beg;	/* offset of memory log */
661 	int64_t vol_buf_beg;	/* offset of the first buffer in volume */
662 	int64_t vol_buf_end;	/* offset of volume EOF (on buffer boundary) */
663 	int64_t vol_reserved01;
664 
665 	uuid_t    vol_fsid;	/* identify filesystem */
666 	uuid_t    vol_fstype;	/* identify filesystem type */
667 	char vol_label[64];	/* filesystem label */
668 
669 	int32_t vol_no;		/* volume number within filesystem */
670 	int32_t vol_count;	/* number of volumes making up filesystem */
671 
672 	uint32_t vol_version;	/* version control information */
673 	hammer_crc_t vol_crc;	/* header crc */
674 	uint32_t vol_flags;	/* volume flags */
675 	uint32_t vol_rootvol;	/* the root volume number (must be 0) */
676 
677 	uint32_t vol_reserved[8];
678 
679 	/*
680 	 * These fields are initialized and space is reserved in every
681 	 * volume making up a HAMMER filesytem, but only the root volume
682 	 * contains valid data.  Note that vol0_stat_bigblocks does not
683 	 * include big-blocks for freemap and undomap initially allocated
684 	 * by newfs_hammer(8).
685 	 */
686 	int64_t vol0_stat_bigblocks;	/* total big-blocks when fs is empty */
687 	int64_t vol0_stat_freebigblocks;/* number of free big-blocks */
688 	int64_t	vol0_reserved01;
689 	int64_t vol0_stat_inodes;	/* for statfs only */
690 	int64_t vol0_reserved02;
691 	hammer_off_t vol0_btree_root;	/* B-Tree root offset in zone-8 */
692 	hammer_tid_t vol0_next_tid;	/* highest partially synchronized TID */
693 	hammer_off_t vol0_reserved03;
694 
695 	/*
696 	 * Blockmaps for zones.  Not all zones use a blockmap.  Note that
697 	 * the entire root blockmap is cached in the hammer_mount structure.
698 	 */
699 	struct hammer_blockmap	vol0_blockmap[HAMMER_MAX_ZONES];
700 
701 	/*
702 	 * Array of zone-2 addresses for undo FIFO.
703 	 */
704 	hammer_off_t		vol0_undo_array[HAMMER_UNDO_LAYER2];
705 } *hammer_volume_ondisk_t;
706 
707 #define HAMMER_ROOT_VOLNO		0
708 
709 #define HAMMER_VOLF_NEEDFLUSH		0x0004	/* volume needs flush */
710 
711 #define HAMMER_VOL_CRCSIZE1	\
712 	offsetof(struct hammer_volume_ondisk, vol_crc)
713 #define HAMMER_VOL_CRCSIZE2	\
714 	(sizeof(struct hammer_volume_ondisk) - HAMMER_VOL_CRCSIZE1 -	\
715 	 sizeof(hammer_crc_t))
716 
717 #define HAMMER_VOL_VERSION_MIN		1	/* minimum supported version */
718 #define HAMMER_VOL_VERSION_DEFAULT	6	/* newfs default version */
719 #define HAMMER_VOL_VERSION_WIP		7	/* version >= this is WIP */
720 #define HAMMER_VOL_VERSION_MAX		6	/* maximum supported version */
721 
722 #define HAMMER_VOL_VERSION_ONE		1
723 #define HAMMER_VOL_VERSION_TWO		2	/* new dirent layout (2.3+) */
724 #define HAMMER_VOL_VERSION_THREE	3	/* new snapshot layout (2.5+) */
725 #define HAMMER_VOL_VERSION_FOUR		4	/* new undo/flush (2.5+) */
726 #define HAMMER_VOL_VERSION_FIVE		5	/* dedup (2.9+) */
727 #define HAMMER_VOL_VERSION_SIX		6	/* DIRHASH_ALG1 */
728 
729 /*
730  * Translate a zone-2 address to physical address
731  */
732 #define hammer_xlate_to_phys(volume, zone2_offset)	\
733 	((volume)->vol_buf_beg +			\
734 	 ((zone2_offset) & HAMMER_OFF_SHORT_MASK))
735 
736 /*
737  * Effective per-volume filesystem capacity including big-blocks for layer1/2
738  */
739 #define HAMMER_VOL_BUF_SIZE(volume)			\
740 	((volume)->vol_buf_end - (volume)->vol_buf_beg)
741 
742 /*
743  * Record types are fairly straightforward.  The B-Tree includes the record
744  * type in its index sort.
745  */
746 #define HAMMER_RECTYPE_UNKNOWN		0x0000
747 #define HAMMER_RECTYPE_INODE		0x0001	/* inode in obj_id space */
748 #define HAMMER_RECTYPE_DATA		0x0010
749 #define HAMMER_RECTYPE_DIRENTRY		0x0011
750 #define HAMMER_RECTYPE_DB		0x0012
751 #define HAMMER_RECTYPE_EXT		0x0013	/* ext attributes */
752 #define HAMMER_RECTYPE_FIX		0x0014	/* fixed attribute */
753 #define HAMMER_RECTYPE_PFS		0x0015	/* PFS management */
754 #define HAMMER_RECTYPE_SNAPSHOT		0x0016	/* Snapshot management */
755 #define HAMMER_RECTYPE_CONFIG		0x0017	/* hammer cleanup config */
756 #define HAMMER_RECTYPE_MAX		0xFFFF
757 
758 #define HAMMER_RECTYPE_ENTRY_START	(HAMMER_RECTYPE_INODE + 1)
759 #define HAMMER_RECTYPE_CLEAN_START	HAMMER_RECTYPE_EXT
760 
761 #define HAMMER_FIXKEY_SYMLINK		1
762 
763 #define HAMMER_OBJTYPE_UNKNOWN		0	/* never exists on-disk as unknown */
764 #define HAMMER_OBJTYPE_DIRECTORY	1
765 #define HAMMER_OBJTYPE_REGFILE		2
766 #define HAMMER_OBJTYPE_DBFILE		3
767 #define HAMMER_OBJTYPE_FIFO		4
768 #define HAMMER_OBJTYPE_CDEV		5
769 #define HAMMER_OBJTYPE_BDEV		6
770 #define HAMMER_OBJTYPE_SOFTLINK		7
771 #define HAMMER_OBJTYPE_PSEUDOFS		8	/* pseudo filesystem obj */
772 #define HAMMER_OBJTYPE_SOCKET		9
773 
774 /*
775  * HAMMER inode attribute data
776  *
777  * The data reference for a HAMMER inode points to this structure.  Any
778  * modifications to the contents of this structure will result in a
779  * replacement operation.
780  *
781  * parent_obj_id is only valid for directories (which cannot be hard-linked),
782  * and specifies the parent directory obj_id.  This field will also be set
783  * for non-directory inodes as a recovery aid, but can wind up holding
784  * stale information.  However, since object id's are not reused, the worse
785  * that happens is that the recovery code is unable to use it.
786  * A parent_obj_id of 0 means it's a root inode of root or non-root PFS.
787  *
788  * NOTE: Future note on directory hardlinks.  We can implement a record type
789  * which allows us to point to multiple parent directories.
790  */
791 typedef struct hammer_inode_data {
792 	uint16_t version;	/* inode data version */
793 	uint16_t mode;		/* basic unix permissions */
794 	uint32_t uflags;	/* chflags */
795 	uint32_t rmajor;	/* used by device nodes */
796 	uint32_t rminor;	/* used by device nodes */
797 	uint64_t ctime;
798 	int64_t parent_obj_id;	/* parent directory obj_id */
799 	uuid_t	  uid;
800 	uuid_t	  gid;
801 
802 	uint8_t obj_type;
803 	uint8_t cap_flags;	/* capability support flags (extension) */
804 	uint16_t reserved01;
805 	uint32_t reserved02;
806 	uint64_t nlinks;	/* hard links */
807 	uint64_t size;		/* filesystem object size */
808 	union {
809 		char	symlink[24];	/* HAMMER_INODE_BASESYMLEN */
810 	} ext;
811 	uint64_t mtime;	/* mtime must be second-to-last */
812 	uint64_t atime;	/* atime must be last */
813 } *hammer_inode_data_t;
814 
815 /*
816  * Neither mtime nor atime upates are CRCd by the B-Tree element.
817  * mtime updates have UNDO, atime updates do not.
818  */
819 #define HAMMER_INODE_CRCSIZE	\
820 	offsetof(struct hammer_inode_data, mtime)
821 
822 #define HAMMER_INODE_DATA_VERSION	1
823 #define HAMMER_OBJID_ROOT		1	/* root inodes # */
824 #define HAMMER_INODE_BASESYMLEN		24	/* see ext.symlink */
825 
826 /*
827  * Capability & implementation flags.
828  *
829  * HAMMER_INODE_CAP_DIR_LOCAL_INO - Use inode B-Tree localization
830  * for directory entries.  Also see HAMMER_DIR_INODE_LOCALIZATION().
831  */
832 #define HAMMER_INODE_CAP_DIRHASH_MASK	0x03	/* directory: hash algorithm */
833 #define HAMMER_INODE_CAP_DIRHASH_ALG0	0x00
834 #define HAMMER_INODE_CAP_DIRHASH_ALG1	0x01
835 #define HAMMER_INODE_CAP_DIRHASH_ALG2	0x02
836 #define HAMMER_INODE_CAP_DIRHASH_ALG3	0x03
837 #define HAMMER_INODE_CAP_DIR_LOCAL_INO	0x04	/* use inode localization */
838 
839 /*
840  * A HAMMER directory entry associates a HAMMER filesystem object with a
841  * namespace.  It is hooked into a pseudo-filesystem (with its own inode
842  * numbering space) in the filesystem by setting the high 16 bits of the
843  * localization field.  The low 16 bits must be 0 and are reserved for
844  * future use.
845  *
846  * Directory entries are indexed with a 128 bit namekey rather then an
847  * offset.  A portion of the namekey is an iterator/randomizer to deal
848  * with collisions.
849  *
850  * NOTE: leaf.base.obj_type from the related B-Tree leaf entry holds
851  * the filesystem object type of obj_id, e.g. a den_type equivalent.
852  * It is not stored in hammer_direntry_data.
853  *
854  * NOTE: name field / the filename data reference is NOT terminated with \0.
855  */
856 typedef struct hammer_direntry_data {
857 	int64_t obj_id;			/* object being referenced */
858 	uint32_t localization;		/* identify pseudo-filesystem */
859 	uint32_t reserved01;
860 	char	name[16];		/* name (extended) */
861 } *hammer_direntry_data_t;
862 
863 #define HAMMER_ENTRY_NAME_OFF	offsetof(struct hammer_direntry_data, name[0])
864 #define HAMMER_ENTRY_SIZE(nlen)	offsetof(struct hammer_direntry_data, name[nlen])
865 
866 /*
867  * Symlink data which does not fit in the inode is stored in a separate
868  * FIX type record.
869  */
870 typedef struct hammer_symlink_data {
871 	char	name[16];		/* name (extended) */
872 } *hammer_symlink_data_t;
873 
874 #define HAMMER_SYMLINK_NAME_OFF	offsetof(struct hammer_symlink_data, name[0])
875 
876 /*
877  * The root inode for the primary filesystem and root inode for any
878  * pseudo-fs may be tagged with an optional data structure using
879  * HAMMER_RECTYPE_PFS and localization id.  This structure allows
880  * the node to be used as a mirroring master or slave.
881  *
882  * When operating as a slave CD's into the node automatically become read-only
883  * and as-of sync_end_tid.
884  *
885  * When operating as a master the read PFSD info sets sync_end_tid to
886  * the most recently flushed TID.
887  *
888  * sync_low_tid is not yet used but will represent the highest pruning
889  * end-point, after which full history is available.
890  *
891  * We need to pack this structure making it equally sized on both 32-bit and
892  * 64-bit machines as it is part of struct hammer_ioc_mrecord_pfs which is
893  * send over the wire in hammer mirror operations. Only on 64-bit machines
894  * the size of this struct differ when packed or not. This leads us to the
895  * situation where old 64-bit systems (using the non-packed structure),
896  * which were never able to mirror to/from 32-bit systems, are now no longer
897  * able to mirror to/from newer 64-bit systems (using the packed structure).
898  */
899 struct hammer_pseudofs_data {
900 	hammer_tid_t	sync_low_tid;	/* full history beyond this point */
901 	hammer_tid_t	sync_beg_tid;	/* earliest tid w/ full history avail */
902 	hammer_tid_t	sync_end_tid;	/* current synchronizatoin point */
903 	uint64_t	sync_beg_ts;	/* real-time of last completed sync */
904 	uint64_t	sync_end_ts;	/* initiation of current sync cycle */
905 	uuid_t		shared_uuid;	/* shared uuid (match required) */
906 	uuid_t		unique_uuid;	/* unique uuid of this master/slave */
907 	int32_t		reserved01;	/* reserved for future master_id */
908 	int32_t		mirror_flags;	/* misc flags */
909 	char		label[64];	/* filesystem space label */
910 	char		snapshots[64];	/* softlink dir for pruning */
911 	int32_t		reserved02;	/* was prune_{time,freq} */
912 	int32_t		reserved03;	/* was reblock_{time,freq} */
913 	int32_t		reserved04;	/* was snapshot_freq */
914 	int32_t		prune_min;	/* do not prune recent history */
915 	int32_t		prune_max;	/* do not retain history beyond here */
916 	int32_t		reserved[16];
917 } __packed;
918 
919 typedef struct hammer_pseudofs_data *hammer_pseudofs_data_t;
920 
921 #define HAMMER_PFSD_SLAVE	0x00000001
922 #define HAMMER_PFSD_DELETED	0x80000000
923 
924 #define hammer_is_pfs_slave(pfsd)			\
925 	(((pfsd)->mirror_flags & HAMMER_PFSD_SLAVE) != 0)
926 #define hammer_is_pfs_master(pfsd)			\
927 	(!hammer_is_pfs_slave(pfsd))
928 #define hammer_is_pfs_deleted(pfsd)			\
929 	(((pfsd)->mirror_flags & HAMMER_PFSD_DELETED) != 0)
930 
931 #define HAMMER_MAX_PFS		65536
932 #define HAMMER_MAX_PFSID	(HAMMER_MAX_PFS - 1)
933 #define HAMMER_ROOT_PFSID	0
934 
935 /*
936  * Snapshot meta-data { Objid = HAMMER_OBJID_ROOT, Key = tid, rectype = SNAPSHOT }.
937  *
938  * Snapshot records replace the old <fs>/snapshots/<softlink> methodology.  Snapshot
939  * records are mirrored but may be independantly managed once they are laid down on
940  * a slave.
941  *
942  * NOTE: The b-tree key is signed, the tid is not, so callers must still sort the
943  *	 results.
944  *
945  * NOTE: Reserved fields must be zero (as usual)
946  */
947 typedef struct hammer_snapshot_data {
948 	hammer_tid_t	tid;		/* the snapshot TID itself (== key) */
949 	uint64_t	ts;		/* real-time when snapshot was made */
950 	uint64_t	reserved01;
951 	uint64_t	reserved02;
952 	char		label[64];	/* user-supplied description */
953 	uint64_t	reserved03[4];
954 } *hammer_snapshot_data_t;
955 
956 /*
957  * Config meta-data { ObjId = HAMMER_OBJID_ROOT, Key = 0, rectype = CONFIG }.
958  *
959  * Used to store the hammer cleanup config.  This data is not mirrored.
960  */
961 typedef struct hammer_config_data {
962 	char		text[1024];
963 } *hammer_config_data_t;
964 
965 /*
966  * Rollup various structures embedded as record data
967  */
968 typedef union hammer_data_ondisk {
969 	struct hammer_direntry_data entry;
970 	struct hammer_inode_data inode;
971 	struct hammer_symlink_data symlink;
972 	struct hammer_pseudofs_data pfsd;
973 	struct hammer_snapshot_data snap;
974 	struct hammer_config_data config;
975 } *hammer_data_ondisk_t;
976 
977 /*
978  * Ondisk layout of B-Tree related structures
979  */
980 #include "hammer_btree.h"
981 
982 #define HAMMER_DIR_INODE_LOCALIZATION(ino_data)				\
983 	(((ino_data)->cap_flags & HAMMER_INODE_CAP_DIR_LOCAL_INO) ?	\
984 	 HAMMER_LOCALIZE_INODE :					\
985 	 HAMMER_LOCALIZE_MISC)
986 
987 #endif /* !VFS_HAMMER_DISK_H_ */
988