2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #ifndef VFS_HAMMER2_DISK_H_
36 #define VFS_HAMMER2_DISK_H_
39 * The structures below represent the on-disk media structures for the HAMMER2
40 * filesystem. Note that all fields for on-disk structures are naturally
41 * aligned. The host endian format is typically used - compatibility is
42 * possible if the implementation detects reversed endian and adjusts accesses
45 * HAMMER2 primarily revolves around the directory topology: inodes,
46 * directory entries, and block tables. Block device buffer cache buffers
47 * are always 64KB. Logical file buffers are typically 16KB. All data
48 * references utilize 64-bit byte offsets.
50 * Free block management is handled independently using blocks reserved by
55 * The data at the end of a file or directory may be a fragment in order
56 * to optimize storage efficiency. The minimum fragment size is 64 bytes.
57 * Since allocations are in powers of 2 fragments must also be sized in
58 * powers of 2 (64, 128, 256, ... 65536).
60 * For the moment the maximum allocation size is HAMMER2_PBUFSIZE (64K),
61 * which is 2^16. Larger extents may be supported in the future.
63 * A full indirect block uses supports 1024 x 64-byte blockrefs.
65 * A maximally sized file (2^64-1 bytes) requires 5 indirect block levels.
66 * The hammer2_blockset in the volume header or file inode has another 8
67 * entries, giving us 66+3 = 69 bits of address space. However, some bits
68 * are taken up by (potentially) requests for redundant copies. HAMMER2
69 * currently supports up to 8 copies, which brings the address space down
70 * to 66 bits and gives us 2 bits of leeway.
72 #define HAMMER2_MIN_ALLOC 64 /* minimum allocation size */
73 #define HAMMER2_MIN_RADIX 6 /* minimum allocation size 2^N */
74 #define HAMMER2_MAX_RADIX 16 /* maximum allocation size 2^N */
75 #define HAMMER2_KEY_RADIX 64 /* number of bits in key */
78 * HAMMER2 utilizes 64K physical buffers and 16K logical filesystem buffers.
79 * The smaller logical filesystem buffers reduce ram waste when the OS is
80 * caching lots of small files.
82 #define HAMMER2_PBUFRADIX 16 /* physical buf (1<<16) bytes */
83 #define HAMMER2_PBUFSIZE 65536 /* fixed physical device buffer size */
84 #define HAMMER2_LBUFSIZE 16384 /* vnode/logical file buffer size */
87 * HAMMER2 processes blockrefs in sets of 8. The set is fully associative,
88 * is not sorted, and may contain holes.
90 * A full indirect block supports 1024 blockrefs.
92 * An inode embeds one set of blockrefs but may also use the data area for
93 * up to 512 bytes of direct data.
95 #define HAMMER2_SET_COUNT 8 /* direct entries & associativity */
96 #define HAMMER2_SET_RADIX 3
97 #define HAMMER2_IND_COUNT 1024 /* 1 << HAMMER2_IND_RADIX */
98 #define HAMMER2_IND_RADIX 10
99 #define HAMMER2_EMBEDDED_BYTES 512
100 #define HAMMER2_EMBEDDED_RADIX 9
102 #define HAMMER2_PBUFMASK (HAMMER2_PBUFSIZE - 1)
103 #define HAMMER2_LBUFMASK (HAMMER2_LBUFSIZE - 1)
105 #define HAMMER2_PBUFSIZE64 ((hammer2_off_t)HAMMER2_PBUFSIZE)
106 #define HAMMER2_PBUFMASK64 ((hammer2_off_t)HAMMER2_PBUFMASK)
107 #define HAMMER2_LBUFMASK64 ((hammer2_off_t)HAMMER2_LBUFMASK)
109 #define HAMMER2_UUID_STRING "5cbb9ad1-862d-11dc-a94d-01301bb8a9f5"
112 * A HAMMER2 filesystem is always sized in multiples of 8MB.
114 * A 4MB segment is reserved at the beginning of each 2GB zone. This segment
115 * contains the volume header, the free block table, and possibly other
116 * information in the future. 4MB = 64 x 64K blocks.
118 #define HAMMER2_VOLUME_ALIGN (8 * 1024 * 1024)
119 #define HAMMER2_VOLUME_ALIGN64 ((hammer2_off_t)HAMMER2_VOLUME_ALIGN)
120 #define HAMMER2_VOLUME_ALIGNMASK (HAMMER2_VOLUME_ALIGN - 1)
121 #define HAMMER2_VOLUME_ALIGNMASK64 ((hammer2_off_t)HAMMER2_VOLUME_ALIGNMASK)
123 #define HAMMER2_NEWFS_ALIGN (HAMMER2_VOLUME_ALIGN)
124 #define HAMMER2_NEWFS_ALIGN64 ((hammer2_off_t)HAMMER2_VOLUME_ALIGN)
125 #define HAMMER2_NEWFS_ALIGNMASK (HAMMER2_VOLUME_ALIGN - 1)
126 #define HAMMER2_NEWFS_ALIGNMASK64 ((hammer2_off_t)HAMMER2_NEWFS_ALIGNMASK)
128 #define HAMMER2_RESERVE_BYTES64 (2LLU * 1024 * 1024 * 1024)
129 #define HAMMER2_RESERVE_MASK64 (HAMMER2_RESERVE_BYTES64 - 1)
130 #define HAMMER2_RESERVE_SEG (4 * 1024 * 1024)
131 #define HAMMER2_RESERVE_SEG64 ((hammer2_off_t)HAMMER2_RESERVE_SEG)
132 #define HAMMER2_RESERVE_BLOCKS (HAMMER2_RESERVE_SEG / HAMMER2_PBUFSIZE)
135 * Two linear areas can be reserved after the initial 2MB segment in the base
136 * zone (the one starting at offset 0). These areas are NOT managed by the
137 * block allocator and do not fall under HAMMER2 crc checking rules based
138 * at the volume header (but can be self-CRCd internally, depending).
140 #define HAMMER2_BOOT_MIN_BYTES HAMMER2_VOLUME_ALIGN
141 #define HAMMER2_BOOT_NOM_BYTES (64*1024*1024)
142 #define HAMMER2_BOOT_MAX_BYTES (256*1024*1024)
144 #define HAMMER2_REDO_MIN_BYTES HAMMER2_VOLUME_ALIGN
145 #define HAMMER2_REDO_NOM_BYTES (256*1024*1024)
146 #define HAMMER2_REDO_MAX_BYTES (1024*1024*1024)
149 * Most HAMMER2 types are implemented as unsigned 64-bit integers.
150 * Transaction ids are monotonic.
152 * We utilize 32-bit iSCSI CRCs.
154 typedef uint64_t hammer2_tid_t;
155 typedef uint64_t hammer2_off_t;
156 typedef uint64_t hammer2_key_t;
157 typedef uint32_t hammer2_crc32_t;
160 * Miscellanious ranges (all are unsigned).
162 #define HAMMER2_MIN_TID 1ULL
163 #define HAMMER2_MAX_TID 0xFFFFFFFFFFFFFFFFULL
164 #define HAMMER2_MIN_KEY 0ULL
165 #define HAMMER2_MAX_KEY 0xFFFFFFFFFFFFFFFFULL
166 #define HAMMER2_MIN_OFFSET 0ULL
167 #define HAMMER2_MAX_OFFSET 0xFFFFFFFFFFFFFFFFULL
170 * HAMMER2 data offset special cases and masking.
172 * All HAMMER2 data offsets have to be broken down into a 64K buffer base
173 * offset (HAMMER2_OFF_MASK_HI) and a 64K buffer index (HAMMER2_OFF_MASK_LO).
175 * Indexes into physical buffers are always 64-byte aligned. The low 6 bits
176 * of the data offset field specifies how large the data chunk being pointed
177 * to as a power of 2. This value typically ranges from HAMMER2_MIN_RADIX
178 * to HAMMER2_MAX_RADIX (6-16). Larger values may be supported in the future
179 * to support file extents.
181 #define HAMMER2_OFF_BAD ((hammer2_off_t)-1)
182 #define HAMMER2_OFF_MASK 0xFFFFFFFFFFFFFFC0ULL
183 #define HAMMER2_OFF_MASK_LO (HAMMER2_OFF_MASK & HAMMER2_PBUFMASK64)
184 #define HAMMER2_OFF_MASK_HI (~HAMMER2_PBUFMASK64)
185 #define HAMMER2_OFF_MASK_RADIX 0x000000000000003FULL
186 #define HAMMER2_MAX_COPIES 6
189 * HAMMER2 directory support and pre-defined keys
191 #define HAMMER2_DIRHASH_VISIBLE 0x8000000000000000ULL
192 #define HAMMER2_DIRHASH_USERMSK 0x7FFFFFFFFFFFFFFFULL
193 #define HAMMER2_DIRHASH_LOMASK 0x0000000000007FFFULL
194 #define HAMMER2_DIRHASH_HIMASK 0xFFFFFFFFFFFF0000ULL
195 #define HAMMER2_DIRHASH_FORCED 0x0000000000008000ULL /* bit forced on */
197 #define HAMMER2_SROOT_KEY 0x0000000000000000ULL /* volume to sroot */
200 * The media block reference structure. This forms the core of the HAMMER2
201 * media topology recursion. This 64-byte data structure is embedded in the
202 * volume header, in inodes (which are also directory entries), and in
205 * A blockref references a single media item, which typically can be a
206 * directory entry (aka inode), indirect block, or data block.
208 * The primary feature a blockref represents is the ability to validate
209 * the entire tree underneath it via its check code. Any modification to
210 * anything propagates up the blockref tree all the way to the root, replacing
211 * the related blocks. Propagations can shortcut to the volume root to
212 * implement the 'fast syncing' feature but this only delays the eventual
215 * The check code can be a simple 32-bit iscsi code, a 64-bit crc,
216 * or as complex as a 192 bit cryptographic hash. 192 bits is the maximum
217 * supported check code size, which is not sufficient for unverified dedup
218 * UNLESS one doesn't mind once-in-a-blue-moon data corruption (such as when
219 * farming web data). HAMMER2 has an unverified dedup feature for just this
222 struct hammer2_blockref { /* MUST BE EXACTLY 64 BYTES */
223 uint8_t type; /* type of underlying item */
224 uint8_t methods; /* check method & compression method */
225 uint8_t copyid; /* specify which copy this is */
226 uint8_t keybits; /* #of keybits masked off 0=leaf */
227 uint8_t vradix; /* virtual data/meta-data size */
228 uint8_t flags; /* blockref flags */
231 hammer2_key_t key; /* key specification */
232 hammer2_tid_t mirror_tid; /* propagate for mirror scan */
233 hammer2_tid_t modify_tid; /* modifications sans propagation */
234 hammer2_off_t data_off; /* low 6 bits is phys size (radix)*/
235 union { /* check info */
251 typedef struct hammer2_blockref hammer2_blockref_t;
253 #define HAMMER2_BREF_SYNC1 0x01 /* modification synchronized */
254 #define HAMMER2_BREF_SYNC2 0x02 /* modification committed */
255 #define HAMMER2_BREF_DESYNCCHLD 0x04 /* desynchronize children */
256 #define HAMMER2_BREF_DELETED 0x80 /* indicates a deletion */
258 #define HAMMER2_BLOCKREF_BYTES 64 /* blockref struct in bytes */
260 #define HAMMER2_BREF_TYPE_EMPTY 0
261 #define HAMMER2_BREF_TYPE_INODE 1
262 #define HAMMER2_BREF_TYPE_INDIRECT 2
263 #define HAMMER2_BREF_TYPE_DATA 3
264 #define HAMMER2_BREF_TYPE_VOLUME 255 /* pseudo-type */
266 #define HAMMER2_ENC_COMPMETHOD(n) (n)
267 #define HAMMER2_ENC_CHECKMETHOD(n) ((n) << 4)
268 #define HAMMER2_DEC_COMPMETHOD(n) ((n) & 15)
269 #define HAMMER2_DEC_CHECKMETHOD(n) (((n) >> 4) & 15)
272 * HAMMER2 block references are collected into sets of 8 blockrefs. These
273 * sets are fully associative, meaning the elements making up a set are
274 * not sorted in any way and may contain duplicate entries, holes, or
275 * entries which shortcut multiple levels of indirection. Sets are used
278 * (1) When redundancy is desired a set may contain several duplicate
279 * entries pointing to different copies of the same data. Up to 8 copies
280 * are supported but the set structure becomes a bit inefficient once
283 * (2) The blockrefs in a set can shortcut multiple levels of indirections
284 * within the bounds imposed by the parent of set.
286 * When a set fills up another level of indirection is inserted, moving
287 * some or all of the set's contents into indirect blocks placed under the
288 * set. This is a top-down approach in that indirect blocks are not created
289 * until the set actually becomes full (that is, the entries in the set can
290 * shortcut the indirect blocks when the set is not full). Depending on how
291 * things are filled multiple indirect blocks will eventually be created.
293 struct hammer2_blockset {
294 hammer2_blockref_t blockref[HAMMER2_SET_COUNT];
297 typedef struct hammer2_blockset hammer2_blockset_t;
300 * Catch programmer snafus
302 #if (1 << HAMMER2_IND_RADIX) != HAMMER2_IND_COUNT
303 #error "hammer2 indirect radix is incorrect"
305 #if (HAMMER2_IND_COUNT * 64) != HAMMER2_PBUFSIZE
306 #error "hammer2 indirect entries is incorrect"
308 #if (1 << HAMMER2_SET_RADIX) != HAMMER2_SET_COUNT
309 #error "hammer2 direct radix is incorrect"
311 #if (1 << HAMMER2_PBUFRADIX) != HAMMER2_PBUFSIZE
312 #error "HAMMER2_PBUFRADIX and HAMMER2_PBUFSIZE are inconsistent"
314 #if (1 << HAMMER2_MIN_RADIX) != HAMMER2_MIN_ALLOC
315 #error "HAMMER2_MIN_RADIX and HAMMER2_MIN_ALLOC are inconsistent"
319 * The media indirect block structure.
321 struct hammer2_indblock_data {
322 hammer2_blockref_t blockref[HAMMER2_IND_COUNT];
325 typedef struct hammer2_indblock_data hammer2_indblock_data_t;
328 * In HAMMER2 inodes ARE directory entries, with a special exception for
329 * hardlinks. The inode number is stored in the inode rather than being
330 * based on the location of the inode (since the location moves every time
331 * the inode or anything underneath the inode is modified).
333 * The inode is 1024 bytes, made up of 256 bytes of meta-data, 256 bytes
334 * for the filename, and 512 bytes worth of direct file data OR an embedded
337 * Directories represent one inode per blockref. Inodes are not laid out
338 * as a file but instead are represented by the related blockrefs. The
339 * blockrefs, in turn, are indexed by the 64-bit directory hash key. Remember
340 * that blocksets are fully associative, so a certain degree efficiency is
341 * achieved just from that.
343 * Up to 512 bytes of direct data can be embedded in an inode, and since
344 * inodes are essentially directory entries this also means that small data
345 * files end up simply being laid out linearly in the directory, resulting
346 * in fewer seeks and highly optimal access.
348 * The compression mode can be changed at any time in the inode and is
349 * recorded on a blockref-by-blockref basis.
351 * Hardlinks are supported via the inode map. Essentially the way a hardlink
352 * works is that all individual directory entries representing the same file
353 * are special cased and specify the same inode number. The actual file
354 * is placed in the nearest parent directory that is parent to all instances
355 * of the hardlink. If all hardlinks to a file are in the same directory
356 * the actual file will also be placed in that directory. This file uses
357 * the inode number as the directory entry key and is invisible to normal
358 * directory scans. Real directory entry keys are differentiated from the
359 * inode number key via bit 63. Access to the hardlink silently looks up
360 * the real file and forwards all operations to that file. Removal of the
361 * last hardlink also removes the real file.
363 #define HAMMER2_INODE_BYTES 1024 /* (asserted by code) */
364 #define HAMMER2_INODE_MAXNAME 256 /* maximum name in bytes */
365 #define HAMMER2_INODE_VERSION_ONE 1
367 struct hammer2_inode_data {
368 uint16_t version; /* 0000 inode data version */
369 uint16_t reserved02; /* 0002 */
370 uint32_t uflags; /* 0004 chflags */
371 uint32_t rmajor; /* 0008 available for device nodes */
372 uint32_t rminor; /* 000C available for device nodes */
373 uint64_t ctime; /* 0010 inode change time */
374 uint64_t mtime; /* 0018 modified time */
375 uint64_t atime; /* 0020 access time (unsupported) */
376 uint64_t btime; /* 0028 birth time */
377 uuid_t uid; /* 0030 uid / degenerate unix uid */
378 uuid_t gid; /* 0040 gid / degenerate unix gid */
380 uint8_t type; /* 0050 object type */
381 uint8_t op_flags; /* 0051 operational flags */
382 uint16_t cap_flags; /* 0052 capability flags */
383 uint32_t mode; /* 0054 unix modes (typ low 16 bits) */
385 hammer2_tid_t inum; /* 0058 inode number */
386 hammer2_off_t size; /* 0060 size of file */
387 uint64_t nlinks; /* 0068 hard links (typ only dirs) */
388 hammer2_tid_t iparent; /* 0070 parent inum (recovery only) */
389 uint64_t reserved78; /* 0078 */
391 hammer2_off_t data_quota; /* 0080 subtree quota in bytes */
392 hammer2_off_t data_count; /* 0088 subtree byte count */
393 hammer2_off_t inode_quota; /* 0090 subtree quota inode count */
394 hammer2_off_t inode_count; /* 0098 subtree inode count */
395 uint16_t name_len; /* 00A0 filename length */
396 uint8_t comp_algo; /* 00A2 compression request & algo */
397 uint8_t reservedA3; /* 00A3 */
398 uint32_t reservedA4; /* 00A4 */
399 hammer2_key_t name_key; /* 00A8 full filename key */
400 uint8_t copyids[8]; /* 00B0 request copies to (up to 8) */
401 uuid_t pfsid; /* 00B8 pfs uuid if PFSROOT */
402 uint64_t pfsinum; /* 00C8 pfs inum allocator */
403 uint64_t reservedD0; /* 00D0 */
404 uint64_t reservedD8; /* 00D8 */
405 uint64_t reservedE0; /* 00E0 */
406 uint64_t reservedE8; /* 00E8 */
407 uint64_t reservedF0; /* 00F0 */
408 uint64_t reservedF8; /* 00F8 */
410 unsigned char filename[HAMMER2_INODE_MAXNAME];
411 /* 0100-01FF (256 char, unterminated) */
412 union { /* 0200-03FF (64x8 = 512 bytes) */
413 struct hammer2_blockset blockset;
414 char data[HAMMER2_EMBEDDED_BYTES];
418 typedef struct hammer2_inode_data hammer2_inode_data_t;
420 #define HAMMER2_OPFLAG_DIRECTDATA 0x01
421 #define HAMMER2_OPFLAG_PFSROOT 0x02
423 #define HAMMER2_OBJTYPE_UNKNOWN 0
424 #define HAMMER2_OBJTYPE_DIRECTORY 1
425 #define HAMMER2_OBJTYPE_REGFILE 2
426 #define HAMMER2_OBJTYPE_FIFO 4
427 #define HAMMER2_OBJTYPE_CDEV 5
428 #define HAMMER2_OBJTYPE_BDEV 6
429 #define HAMMER2_OBJTYPE_SOFTLINK 7
430 #define HAMMER2_OBJTYPE_HARDLINK 8 /* dummy entry for hardlink */
431 #define HAMMER2_OBJTYPE_SOCKET 9
432 #define HAMMER2_OBJTYPE_WHITEOUT 10
434 #define HAMMER2_COPYID_NONE 0
435 #define HAMMER2_COPYID_LOCAL ((uint8_t)-1)
437 #define HAMMER2_COMP_NONE 0
438 #define HAMMER2_COMP_AUTOZERO 1
440 #define HAMMER2_CHECK_NONE 0
441 #define HAMMER2_CHECK_ICRC 1
444 * The allocref structure represents the allocation table. One 64K block
445 * is broken down into 4096 x 16 byte entries. Each indirect block chops
446 * 11 bits off the 64-bit storage space, with leaf entries representing
447 * 64KB blocks. So: (12, 12, 12, 12, 16) = 64 bit storage space.
449 * Each 64K freemap block breaks the 4096 entries into a 64x64 tree with
450 * big_hint1 representing the top level every 64th entry and big_hint2
451 * representing the lower level in each entry. These fields specify the
452 * largest contiguous radix (1-63) available for allocation in the related
453 * sub-tree. The largest contiguous radix available for the entire block
454 * is saved in the parent (for the root this will be alloc_blockref in the
455 * volume header). The hints may be larger than actual and will be corrected
456 * on the fly but must not be smaller. The allocator uses the hints to
457 * very quickly locate nearby blocks of the desired size.
459 * In indirect blocks the 64-bit free[_or_mask] field stores the total free
460 * space for each of the 4096 sub-nodes in bytes. The total free space
461 * represented by the indirect block is stored in its parent.
463 * Each leaf element represents a 64K block. A bitmap replaces the free space
464 * count, giving us a 1KB allocation resolution. A micro-allocation append
465 * offset replaces the icrc field. The micro-allocation feature is not
466 * currently implemented and the field will be set to 65536.
468 * The allocation map uses reserved blocks so no data block reference is
469 * required, only a bit in the flags field to specify which of two possible
470 * reserved blocks to use. This allows the allocation map to be flushed to
471 * disk with minimal synchronization.
473 struct hammer2_allocref {
474 uint32_t icrc_or_app; /* node: icrc, leaf: append offset */
476 uint8_t big_hint1; /* upper level hint */
477 uint8_t big_hint2; /* lower level hint */
478 uint64_t free_or_mask; /* node: free bytes, leaf: bitmask */
481 typedef struct hammer2_allocref hammer2_allocref_t;
484 * WARNING - allocref size x entries must equate to the hammer buffer size,
485 * and 12 bits per recursion is assumed by the allocator.
487 * ALTA-D Since no data_offset is specified flags are needed to select
488 * which sub-block to recurse down into for root & internal nodes.
489 * (only ALTA and ALTB is currently supported).
491 * LEAF Terminal entry, always set for leafs. May be used to support
492 * 4MB extent allocations and early termination in the future.
493 * (not required to shortcut allocation scans as the big_hint1/2
494 * fields are used for this).
496 #define HAMMER2_ALLOCREF_BYTES 16 /* structure size */
497 #define HAMMER2_ALLOCREF_ENTRIES 4096 /* entries */
498 #define HAMMER2_ALLOCREF_RADIX 12 /* log2(entries) */
500 #if (HAMMER2_ALLOCREF_BYTES * HAMMER2_ALLOCREF_ENTRIES) != HAMMER2_PBUFSIZE
501 #error "allocref parameters do not fit in hammer buffer"
503 #if (1 << HAMMER2_ALLOCREF_RADIX) != HAMMER2_ALLOCREF_ENTRIES
504 #error "allocref parameters are inconsistent"
507 #define HAMMER2_ALLOCREF_ALTMASK 0x0003 /* select block for recurse */
508 #define HAMMER2_ALLOCREF_ALTA 0x0000
509 #define HAMMER2_ALLOCREF_ALTB 0x0001
510 #define HAMMER2_ALLOCREF_ALTC 0x0002 /* unsupported */
511 #define HAMMER2_ALLOCREF_ALTD 0x0003 /* unsupported */
512 #define HAMMER2_ALLOCREF_LEAF 0x0004
515 * Copies information stored in the volume header. Typically formatted
516 * e.g. like 'serno/A21343249.s1d'
518 * There are 8 copy_data[]'s in the volume header but up to 256 copyid's.
519 * When a copy is removed its copyid remains reserved in the copyid bitmap
520 * (copyexists[] bitmap in volume_data) until the copy references have
521 * been removed from the entire filesystem and cannot be reused until the
522 * removal is complete. However, new copy entries with other ids can be
523 * instantly added, replacing the original copy_data[]... which is fine as
524 * long as the copyid does not conflict.
526 * This structure must be exactly 64 bytes long.
528 struct hammer2_copy_data {
529 uint8_t copyid; /* 0-255 */
533 uint8_t path[60]; /* up to 59-char string, nul-terminated */
536 typedef struct hammer2_copy_data hammer2_copy_data_t;
538 #define COPYDATAF_OUTOFSYNC 0x0001
541 * The volume header eats a 64K block. There is currently an issue where
542 * we want to try to fit all nominal filesystem updates in a 512-byte section
543 * but it may be a lost cause due to the need for a blockset.
545 * All information is stored in host byte order. The volume header's magic
546 * number may be checked to determine the byte order. If you wish to mount
547 * between machines w/ different endian modes you'll need filesystem code
548 * which acts on the media data consistently (either all one way or all the
549 * other). Our code currently does not do that.
551 * A read-write mount may have to recover missing allocations by doing an
552 * incremental mirror scan looking for modifications made after alloc_tid.
553 * If alloc_tid == last_tid then no recovery operation is needed. Recovery
554 * operations are usually very, very fast.
556 * Read-only mounts do not need to do any recovery, access to the filesystem
557 * topology is always consistent after a crash (is always consistent, period).
558 * However, there may be shortcutted blockref updates present from deep in
559 * the tree which are stored in the volumeh eader and must be tracked on
562 * COPIES: Multiple copies may be specified on the mount line AND/OR you
563 * just specify one and the mount code tries to pick up the others
564 * from copyinfo[]. The copyid field in the volume header along
565 * with the fsid validates the copies.
567 * NOTE: root_blockref points to the super-root directory, not the root
568 * directory. The root directory will be a subdirectory under the
571 * The super-root directory contains all root directories and all
572 * snapshots (readonly or writable). It is possible to do a
573 * null-mount of the super-root using special path constructions
574 * relative to your mounted root.
576 * NOTE: HAMMER2 allows any subdirectory tree to be managed as if it were
577 * a PFS, including mirroring and storage quota operations, and this is
578 * prefered over creating discrete PFSs in the super-root. Instead
579 * the super-root is most typically used to create writable snapshots,
580 * alternative roots, and so forth. The super-root is also used by
581 * the automatic snapshotting mechanism.
583 #define HAMMER2_VOLUME_ID_HBO 0x48414d3205172011LLU
584 #define HAMMER2_VOLUME_ID_ABO 0x11201705324d4148LLU
586 struct hammer2_volume_data {
590 uint64_t magic; /* 0000 Signature */
591 hammer2_off_t boot_beg; /* 0008 Boot area (future) */
592 hammer2_off_t boot_end; /* 0010 (size = end - beg) */
593 hammer2_off_t redo_beg; /* 0018 Redo area (future) */
594 hammer2_off_t redo_end; /* 0020 (size = end - beg) */
595 hammer2_off_t volu_size; /* 0028 Volume size, bytes */
597 uint32_t version; /* 0030 */
598 uint32_t flags; /* 0034 */
599 uint8_t copyid; /* 0038 copyid of phys vol */
600 uint8_t freemap_version; /* 0039 freemap algorithm */
601 uint8_t reserved003A; /* 003A */
602 uint8_t reserved003B; /* 003B */
603 uint32_t reserved003C; /* 003C */
605 uuid_t fsid; /* 0040 */
606 uuid_t fstype; /* 0050 */
609 * allocator_size is precalculated at newfs time and does not include
610 * reserved blocks, boot, or redo areas.
612 * Initial non-reserved-area allocations do not use the allocation
613 * map but instead adjust alloc_iterator. Dynamic allocations take
614 * over starting at (allocator_beg). This makes newfs_hammer2's
615 * job a lot easier and can also serve as a testing jig.
617 hammer2_off_t allocator_size; /* 0060 Total data space */
618 hammer2_off_t allocator_free; /* 0068 Free space */
619 hammer2_tid_t allocator_beg; /* 0070 Initial allocations */
620 hammer2_tid_t last_tid; /* 0078 Last transaction id */
621 hammer2_tid_t alloc_tid; /* 0080 Alloctable modify tid */
622 hammer2_blockref_t alloc_blockref; /* 0088-00C7 */
625 * Copyids are allocated dynamically from the copyexists bitmap.
626 * An id from the active copies set (up to 8, see copyinfo later on)
627 * may still exist after the copy set has been removed from the
628 * volume header and its bit will remain active in the bitmap and
629 * cannot be reused until it is 100% removed from the hierarchy.
631 uint32_t copyexists[8]; /* 00C8-00E7 copy exists bmap */
632 char reserved0140[248]; /* 00E8-01DF */
635 * 32 bit CRC array at the end of the first 512 byte sector.
637 * icrc_sects[7] - First 512-4 bytes of volume header (including all
638 * the other icrc's except the last one).
640 * icrc_sects[6] - Second 512-4 bytes of volume header, which is
641 * the blockset for the root.
643 hammer2_crc32_t icrc_sects[8]; /* 01E0-01FF */
648 * The entire sector is used by a blockset.
650 hammer2_blockset_t sroot_blockset; /* 0200 Superroot directory */
653 * 512-byte sector #2-33
655 * Up to 256 copyinfo specifications can be configured. Note that
656 * any given subdirectory tree can only use 8 of the 256. Having
657 * up to 256 configurable in the volume header allows
659 * A specification takes 64 bytes. Each specification typically
660 * configures a device path such as 'serno/<serial>.s1d'.
662 struct hammer2_copy_data copyinfo[256]; /* 0400-43FF copyinfo config */
665 * Remaining sections are reserved for future use.
667 char reserved0400[0xBBFC]; /* 4400-FFFB reserved */
670 * icrc on entire volume header
672 hammer2_crc32_t icrc_volheader; /* FFFC-FFFF full volume icrc*/
675 typedef struct hammer2_volume_data hammer2_volume_data_t;
678 * Various parts of the volume header have their own iCRCs.
680 * The first 512 bytes has its own iCRC stored at the end of the 512 bytes
681 * and not included the icrc calculation.
683 * The second 512 bytes also has its own iCRC but it is stored in the first
684 * 512 bytes so it covers the entire second 512 bytes.
686 * The whole volume block (64KB) has an iCRC covering all but the last 4 bytes,
687 * which is where the iCRC for the whole volume is stored. This is currently
688 * a catch-all for anything not individually iCRCd.
690 #define HAMMER2_VOL_ICRC_SECT0 7
691 #define HAMMER2_VOL_ICRC_SECT1 6
693 #define HAMMER2_VOLUME_BYTES 65536
695 #define HAMMER2_VOLUME_ICRC0_OFF 0
696 #define HAMMER2_VOLUME_ICRC1_OFF 512
697 #define HAMMER2_VOLUME_ICRCVH_OFF 0
699 #define HAMMER2_VOLUME_ICRC0_SIZE (512 - 4)
700 #define HAMMER2_VOLUME_ICRC1_SIZE (512)
701 #define HAMMER2_VOLUME_ICRCVH_SIZE (65536 - 4)
703 #define HAMMER2_VOL_VERSION_MIN 1
704 #define HAMMER2_VOL_VERSION_DEFAULT 1
705 #define HAMMER2_VOL_VERSION_WIP 2
707 #define HAMMER2_NUM_VOLHDRS 4
709 union hammer2_media_data {
710 hammer2_inode_data_t ipdata;
711 hammer2_indblock_data_t npdata;
712 char buf[HAMMER2_PBUFSIZE];
715 typedef union hammer2_media_data hammer2_media_data_t;
718 * Prototypes for user & kernel functions. Kernel-only prototypes are
721 uint32_t hammer2_icrc32(const void *buf, size_t size);
722 uint32_t hammer2_icrc32c(const void *buf, size_t size, uint32_t crc);