2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
34 * $DragonFly: src/sys/vfs/hammer/hammer_disk.h,v 1.21 2008/02/05 01:44:04 dillon Exp $
37 #ifndef VFS_HAMMER_DISK_H_
38 #define VFS_HAMMER_DISK_H_
45 * The structures below represent the on-disk format for a HAMMER
46 * filesystem. Note that all fields for on-disk structures are naturally
47 * aligned. The host endian format is used - compatibility is possible
48 * if the implementation detects reversed endian and adjusts data accordingly.
50 * Most of HAMMER revolves around the concept of an object identifier. An
51 * obj_id is a 64 bit quantity which uniquely identifies a filesystem object
52 * FOR THE ENTIRE LIFE OF THE FILESYSTEM. This uniqueness allows backups
53 * and mirrors to retain varying amounts of filesystem history by removing
54 * any possibility of conflict through identifier reuse.
56 * A HAMMER filesystem may spam multiple volumes.
58 * A HAMMER filesystem uses a 16K filesystem buffer size. All filesystem
59 * I/O is done in multiples of 16K. Most buffer-sized headers such as those
60 * used by volumes, super-clusters, clusters, and basic filesystem buffers
61 * use fixed-sized A-lists which are heavily dependant on HAMMER_BUFSIZE.
63 #define HAMMER_BUFSIZE 16384
64 #define HAMMER_BUFMASK (HAMMER_BUFSIZE - 1)
65 #define HAMMER_MAXDATA (256*1024)
68 * Hammer transction ids are 64 bit unsigned integers and are usually
69 * synchronized with the time of day in nanoseconds.
71 typedef u_int64_t hammer_tid_t
;
73 #define HAMMER_MIN_TID 0ULL
74 #define HAMMER_MAX_TID 0xFFFFFFFFFFFFFFFFULL
75 #define HAMMER_MIN_KEY -0x8000000000000000LL
76 #define HAMMER_MAX_KEY 0x7FFFFFFFFFFFFFFFLL
77 #define HAMMER_MIN_OBJID HAMMER_MIN_KEY
78 #define HAMMER_MAX_OBJID HAMMER_MAX_KEY
79 #define HAMMER_MIN_RECTYPE 0x0U
80 #define HAMMER_MAX_RECTYPE 0xFFFFU
83 * Don't include the whole mess unless the caller also has included
84 * the hammer alist header. The ioctl code only needs hammer_tid_t.
86 #ifdef HAMMER_ALIST_METAELMS_256_1LYR
89 * Most HAMMER data structures are embedded in 16K filesystem buffers.
90 * All filesystem buffers except those designated as pure-data buffers
91 * contain this 128-byte header.
93 * This structure contains an embedded A-List used to manage space within
94 * the filesystem buffer. It is not used by volume or cluster header
95 * buffers, or by pure-data buffers. The granularity is variable and
96 * depends on the type of filesystem buffer. BLKSIZE is just a minimum.
99 #define HAMMER_FSBUF_HEAD_SIZE 128
100 #define HAMMER_FSBUF_MAXBLKS 256
101 #define HAMMER_FSBUF_BLKMASK (HAMMER_FSBUF_MAXBLKS - 1)
102 #define HAMMER_FSBUF_METAELMS HAMMER_ALIST_METAELMS_256_1LYR /* 11 */
104 struct hammer_fsbuf_head
{
107 u_int32_t buf_reserved07
;
108 u_int32_t reserved
[6];
109 struct hammer_almeta buf_almeta
[HAMMER_FSBUF_METAELMS
];
112 typedef struct hammer_fsbuf_head
*hammer_fsbuf_head_t
;
115 * Note: Pure-data buffers contain pure-data and have no buf_type.
116 * Piecemeal data buffers do have a header and use HAMMER_FSBUF_DATA.
118 #define HAMMER_FSBUF_VOLUME 0xC8414D4DC5523031ULL /* HAMMER01 */
119 #define HAMMER_FSBUF_SUPERCL 0xC8414D52C3555052ULL /* HAMRSUPR */
120 #define HAMMER_FSBUF_CLUSTER 0xC8414D52C34C5553ULL /* HAMRCLUS */
121 #define HAMMER_FSBUF_RECORDS 0xC8414D52D2454353ULL /* HAMRRECS */
122 #define HAMMER_FSBUF_BTREE 0xC8414D52C2545245ULL /* HAMRBTRE */
123 #define HAMMER_FSBUF_DATA 0xC8414D52C4415441ULL /* HAMRDATA */
125 #define HAMMER_FSBUF_VOLUME_REV 0x313052C54D4D41C8ULL /* (reverse endian) */
128 * The B-Tree structures need hammer_fsbuf_head.
130 #include "hammer_btree.h"
133 * HAMMER Volume header
135 * A HAMMER filesystem is built from any number of block devices, Each block
136 * device contains a volume header followed by however many super-clusters
137 * and clusters fit into the volume. Clusters cannot be migrated but the
138 * data they contain can, so HAMMER can use a truncated cluster for any
139 * extra space at the end of the volume.
141 * The volume containing the root cluster is designated as the master volume.
142 * The root cluster designation can be moved to any volume.
144 * The volume header takes up an entire 16K filesystem buffer and includes
145 * a one or two-layered A-list to manage the clusters making up the volume.
146 * A volume containing up to 32768 clusters (2TB) can be managed with a
147 * single-layered A-list. A two-layer A-list is capable of managing up
148 * to 4096 super-clusters with each super-cluster containing 32768 clusters
149 * (8192 TB per volume total). The number of volumes is limited to 32768
150 * but it only takes 512 to fill out a 64 bit address space so for all
151 * intents and purposes the filesystem has no limits.
153 * cluster addressing within a volume depends on whether a single or
154 * duel-layer A-list is used. If a duel-layer A-list is used a 16K
155 * super-cluster buffer is needed for every 32768 clusters in the volume.
156 * However, because the A-list's hinting is grouped in multiples of 16
157 * we group 16 super-cluster buffers together (starting just after the
158 * volume header), followed by 16384x16 clusters, and repeat.
160 * The number of super-clusters is limited to 4096 because the A-list's
161 * master radix is stored as a 32 bit signed quantity which will overflow
162 * if more then 4096*32768 elements is specified. XXX
164 * NOTE: A 32768-element single-layer and 16384-element duel-layer A-list
167 * Special field notes:
169 * vol_bot_beg - offset of boot area (mem_beg - bot_beg bytes)
170 * vol_mem_beg - offset of memory log (clu_beg - mem_beg bytes)
171 * vol_clo_beg - offset of cluster #0 in volume
173 * The memory log area allows a kernel to cache new records and data
174 * in memory without allocating space in the actual filesystem to hold
175 * the records and data. In the event that a filesystem becomes full,
176 * any records remaining in memory can be flushed to the memory log
177 * area. This allows the kernel to immediately return success.
179 #define HAMMER_VOL_MAXCLUSTERS 32768 /* 1-layer */
180 #define HAMMER_VOL_MAXSUPERCLUSTERS 4096 /* 2-layer */
181 #define HAMMER_VOL_SUPERCLUSTER_GROUP 16
182 #define HAMMER_VOL_METAELMS_1LYR HAMMER_ALIST_METAELMS_32K_1LYR
183 #define HAMMER_VOL_METAELMS_2LYR HAMMER_ALIST_METAELMS_16K_2LYR
185 #define HAMMER_BOOT_MINBYTES (32*1024)
186 #define HAMMER_BOOT_NOMBYTES (64LL*1024*1024)
187 #define HAMMER_BOOT_MAXBYTES (256LL*1024*1024)
189 #define HAMMER_MEM_MINBYTES (256*1024)
190 #define HAMMER_MEM_NOMBYTES (1LL*1024*1024*1024)
191 #define HAMMER_MEM_MAXBYTES (64LL*1024*1024*1024)
193 struct hammer_volume_ondisk
{
194 struct hammer_fsbuf_head head
;
195 int64_t vol_bot_beg
; /* byte offset of boot area or 0 */
196 int64_t vol_mem_beg
; /* byte offset of memory log or 0 */
197 int64_t vol_clo_beg
; /* byte offset of first cl/supercl in volume */
198 int64_t vol_clo_end
; /* byte offset of volume EOF */
199 int64_t vol_locked
; /* reserved clusters are >= this offset */
201 uuid_t vol_fsid
; /* identify filesystem */
202 uuid_t vol_fstype
; /* identify filesystem type */
203 char vol_name
[64]; /* Name of volume */
205 int32_t vol_no
; /* volume number within filesystem */
206 int32_t vol_count
; /* number of volumes making up FS */
208 u_int32_t vol_version
; /* version control information */
209 u_int32_t vol_reserved01
;
210 u_int32_t vol_flags
; /* volume flags */
211 u_int32_t vol_rootvol
; /* which volume is the root volume? */
213 int32_t vol_clsize
; /* cluster size (same for all volumes) */
214 int32_t vol_nclusters
;
215 u_int32_t vol_reserved06
;
216 u_int32_t vol_reserved07
;
218 int32_t vol_blocksize
; /* for statfs only */
219 int64_t vol_nblocks
; /* total allocatable hammer bufs */
222 * This statistical information can get out of sync after a crash
223 * and is recovered slowly.
225 int64_t vol_stat_bytes
; /* for statfs only */
226 int64_t unused08
; /* for statfs only */
227 int64_t vol_stat_data_bufs
; /* hammer bufs allocated to data */
228 int64_t vol_stat_rec_bufs
; /* hammer bufs allocated to records */
229 int64_t vol_stat_idx_bufs
; /* hammer bufs allocated to B-Tree */
232 * These fields are initialized and space is reserved in every
233 * volume making up a HAMMER filesytem, but only the master volume
234 * contains valid data.
236 int64_t vol0_stat_bytes
; /* for statfs only */
237 int64_t vol0_stat_inodes
; /* for statfs only */
238 int64_t vol0_stat_records
; /* total records in filesystem */
239 int64_t vol0_stat_data_bufs
; /* hammer bufs allocated to data */
240 int64_t vol0_stat_rec_bufs
; /* hammer bufs allocated to records */
241 int64_t vol0_stat_idx_bufs
; /* hammer bufs allocated to B-Tree */
243 int32_t vol0_root_clu_no
; /* root cluster no (index) in rootvol */
244 hammer_tid_t vol0_root_clu_id
; /* root cluster id */
245 hammer_tid_t vol0_nexttid
; /* next TID */
246 u_int64_t vol0_recid
; /* fs-wide record id allocator */
247 u_int64_t vol0_synchronized_rec_id
; /* XXX */
252 * Meta elements for the volume header's A-list, which is either a
253 * 1-layer A-list capable of managing 32768 clusters, or a 2-layer
254 * A-list capable of managing 16384 super-clusters (each of which
255 * can handle 32768 clusters).
258 struct hammer_almeta super
[HAMMER_VOL_METAELMS_2LYR
];
259 struct hammer_almeta normal
[HAMMER_VOL_METAELMS_1LYR
];
261 u_int32_t vol0_bitmap
[1024];
264 typedef struct hammer_volume_ondisk
*hammer_volume_ondisk_t
;
266 #define HAMMER_VOLF_VALID 0x0001 /* valid entry */
267 #define HAMMER_VOLF_OPEN 0x0002 /* volume is open */
268 #define HAMMER_VOLF_USINGSUPERCL 0x0004 /* using superclusters */
271 * HAMMER Super-cluster header
273 * A super-cluster is used to increase the maximum size of a volume.
274 * HAMMER's volume header can manage up to 32768 direct clusters or
275 * 16384 super-clusters. Each super-cluster (which is basically just
276 * a 16K filesystem buffer) can manage up to 32768 clusters. So adding
277 * a super-cluster layer allows a HAMMER volume to be sized upwards of
278 * around 32768TB instead of 2TB.
280 * Any volume initially formatted to be over 32G reserves space for the layer
281 * but the layer is only enabled if the volume exceeds 2TB.
283 #define HAMMER_SUPERCL_METAELMS HAMMER_ALIST_METAELMS_32K_1LYR
284 #define HAMMER_SCL_MAXCLUSTERS HAMMER_VOL_MAXCLUSTERS
286 struct hammer_supercl_ondisk
{
287 struct hammer_fsbuf_head head
;
288 uuid_t vol_fsid
; /* identify filesystem - sanity check */
289 uuid_t vol_fstype
; /* identify filesystem type - sanity check */
290 int32_t reserved
[1024];
292 struct hammer_almeta scl_meta
[HAMMER_SUPERCL_METAELMS
];
295 typedef struct hammer_supercl_ondisk
*hammer_supercl_ondisk_t
;
298 * HAMMER Cluster header
300 * A cluster is limited to 64MB and is made up of 4096 16K filesystem
301 * buffers. The cluster header contains four A-lists to manage these
304 * master_alist - This is a non-layered A-list which manages pure-data
305 * allocations and allocations on behalf of other A-lists.
307 * btree_alist - This is a layered A-list which manages filesystem buffers
308 * containing B-Tree nodes.
310 * record_alist - This is a layered A-list which manages filesystem buffers
311 * containing records.
313 * mdata_alist - This is a layered A-list which manages filesystem buffers
314 * containing piecemeal record data.
316 * General storage management works like this: All the A-lists except the
317 * master start in an all-allocated state. Now lets say you wish to allocate
318 * a B-Tree node out the btree_alist. If the allocation fails you allocate
319 * a pure data block out of master_alist and then free that block in
320 * btree_alist, thereby assigning more space to the btree_alist, and then
321 * retry your allocation out of the btree_alist. In the reverse direction,
322 * filesystem buffers can be garbage collected back to master_alist simply
323 * by doing whole-buffer allocations in btree_alist and then freeing the
324 * space in master_alist. The whole-buffer-allocation approach to garbage
325 * collection works because A-list allocations are always power-of-2 sized
328 #define HAMMER_CLU_MAXBUFFERS 4096
329 #define HAMMER_CLU_MASTER_METAELMS HAMMER_ALIST_METAELMS_4K_1LYR
330 #define HAMMER_CLU_SLAVE_METAELMS HAMMER_ALIST_METAELMS_4K_2LYR
331 #define HAMMER_CLU_MAXBYTES (HAMMER_CLU_MAXBUFFERS * HAMMER_BUFSIZE)
333 struct hammer_cluster_ondisk
{
334 struct hammer_fsbuf_head head
;
335 uuid_t vol_fsid
; /* identify filesystem - sanity check */
336 uuid_t vol_fstype
; /* identify filesystem type - sanity check */
338 hammer_tid_t clu_id
; /* unique cluster self identification */
339 hammer_tid_t clu_gen
; /* generation number */
340 int32_t vol_no
; /* cluster contained in volume (sanity) */
341 u_int32_t clu_flags
; /* cluster flags */
343 int32_t clu_start
; /* start of data (byte offset) */
344 int32_t clu_limit
; /* end of data (byte offset) */
345 int32_t clu_no
; /* cluster index in volume (sanity) */
346 u_int32_t clu_reserved03
;
348 u_int32_t clu_reserved04
;
349 u_int32_t clu_reserved05
;
350 u_int32_t clu_reserved06
;
351 u_int32_t clu_reserved07
;
354 * These fields are mostly heuristics to aid in locality of
355 * reference allocations.
357 int32_t idx_data
; /* data append point (element no) */
358 int32_t idx_index
; /* index append point (element no) */
359 int32_t idx_record
; /* record prepend point (element no) */
360 int32_t idx_ldata
; /* large block data append pt (buf_no) */
363 * These fields can become out of sync after a filesystem crash
364 * and are cleaned up in the background. They are used for
367 * NOTE: stat_records counts a spike as two records even though there
368 * is only one record. This is done so we can properly calculate
369 * the worst-case space needed to hold the B-Tree.
371 int32_t stat_inodes
; /* number of inodes in cluster */
372 int32_t stat_records
; /* number of records in cluster */
373 int32_t stat_data_bufs
; /* hammer bufs allocated to data */
374 int32_t stat_rec_bufs
; /* hammer bufs allocated to records */
375 int32_t stat_idx_bufs
; /* hammer bufs allocated to B-Tree */
378 * Specify the range of information stored in this cluster as two
379 * btree elements. These elements match the left and right
380 * boundary elements in the internal B-Tree node of the parent
381 * cluster that points to the root of our cluster. Because these
382 * are boundary elements, the right boundary is range-NONinclusive.
384 struct hammer_base_elm clu_btree_beg
;
385 struct hammer_base_elm clu_btree_end
;
388 * The cluster's B-Tree root can change as a side effect of insertion
389 * and deletion operations so store an offset instead of embedding
390 * the root node. The parent_offset is stale if the generation number
393 * Parent linkages are explicit.
395 int32_t clu_btree_root
;
396 int32_t clu_btree_parent_vol_no
;
397 int32_t clu_btree_parent_clu_no
;
398 int32_t clu_btree_parent_offset
;
399 hammer_tid_t clu_btree_parent_clu_gen
;
402 * The synchronized record id is used for recovery purposes.
404 * For recovery purposes, only clu_record_meta[] is recovered.
405 * The remaining a-list's are regenerated based on the records
408 u_int64_t synchronized_rec_id
;
409 u_int32_t reserved16
[510];
411 struct hammer_almeta clu_master_meta
[HAMMER_CLU_MASTER_METAELMS
];
412 struct hammer_almeta clu_btree_meta
[HAMMER_CLU_SLAVE_METAELMS
];
413 struct hammer_almeta clu_record_meta
[HAMMER_CLU_SLAVE_METAELMS
];
414 struct hammer_almeta clu_mdata_meta
[HAMMER_CLU_SLAVE_METAELMS
];
417 typedef struct hammer_cluster_ondisk
*hammer_cluster_ondisk_t
;
422 * OPEN - A cluster is marked open and synchronized to disk prior to any
423 * modifications being made to either the cluster header or any cluster
424 * buffers. If initial access to a cluster finds this flag set, the
425 * cluster is recovered before any further operations are performed on it.
427 #define HAMMER_CLUF_OPEN 0x0001 /* cluster is dirty */
430 * HAMMER records are 96 byte entities encoded into 16K filesystem buffers.
431 * Each record has a 64 byte header and a 32 byte extension. 170 records
432 * fit into each buffer. Storage is managed by the buffer's A-List.
434 * Each record may have an explicit data reference to a block of data up
435 * to 2^31-1 bytes in size within the current cluster. Note that multiple
436 * records may share the same or overlapping data references.
440 * All HAMMER records have a common 64-byte base and a 32-byte extension.
442 * Many HAMMER record types reference out-of-band data within the cluster.
443 * This data can also be stored in-band in the record itself if it is small
444 * enough. Either way, (data_offset, data_len) points to it.
446 * Key comparison order: obj_id, rec_type, key, delete_tid
448 struct hammer_base_record
{
450 * 40 byte base element info - same base as used in B-Tree internal
451 * and leaf node element arrays.
453 * Fields: obj_id, key, create_tid, delete_tid, rec_type, obj_type,
456 struct hammer_base_elm base
; /* 00 base element info */
458 int32_t data_len
; /* 28 size of data (remainder zero-fill) */
459 u_int32_t data_crc
; /* 2C data sanity check */
460 u_int64_t rec_id
; /* 30 record id (iterator for recovery) */
461 int32_t data_offset
; /* 38 cluster-relative data reference or 0 */
462 u_int32_t reserved07
; /* 3C */
467 * Record types are fairly straightforward. The B-Tree includes the record
468 * type in its index sort.
470 * In particular please note that it is possible to create a pseudo-
471 * filesystem within a HAMMER filesystem by creating a special object
472 * type within a directory. Pseudo-filesystems are used as replication
473 * targets and even though they are built within a HAMMER filesystem they
474 * get their own obj_id space (and thus can serve as a replication target)
475 * and look like a mount point to the system.
477 * Inter-cluster records are special-cased in the B-Tree. These records
478 * are referenced from a B-Tree INTERNAL node, NOT A LEAF. This means
479 * that the element in the B-Tree node is actually a boundary element whos
480 * base element fields, including rec_type, reflect the boundary, NOT
481 * the inter-cluster record type.
483 * HAMMER_RECTYPE_CLUSTER - only set in the actual inter-cluster record,
484 * not set in the left or right boundary elements around the inter-cluster
485 * reference of an internal node in the B-Tree (because doing so would
486 * interfere with the boundary tests).
488 * NOTE: hammer_ip_delete_range_all() deletes all record types greater
489 * then HAMMER_RECTYPE_INODE.
491 #define HAMMER_RECTYPE_UNKNOWN 0
492 #define HAMMER_RECTYPE_LOWEST 1 /* lowest record type avail */
493 #define HAMMER_RECTYPE_INODE 1 /* inode in obj_id space */
494 #define HAMMER_RECTYPE_PSEUDO_INODE 2 /* pseudo filesysem */
495 #define HAMMER_RECTYPE_CLUSTER 3 /* inter-cluster reference */
496 #define HAMMER_RECTYPE_DATA 0x10
497 #define HAMMER_RECTYPE_DIRENTRY 0x11
498 #define HAMMER_RECTYPE_DB 0x12
499 #define HAMMER_RECTYPE_EXT 0x13 /* ext attributes */
500 #define HAMMER_RECTYPE_FIX 0x14 /* fixed attribute */
502 #define HAMMER_FIXKEY_SYMLINK 1
504 #define HAMMER_OBJTYPE_UNKNOWN 0 /* (never exists on-disk) */
505 #define HAMMER_OBJTYPE_DIRECTORY 1
506 #define HAMMER_OBJTYPE_REGFILE 2
507 #define HAMMER_OBJTYPE_DBFILE 3
508 #define HAMMER_OBJTYPE_FIFO 4
509 #define HAMMER_OBJTYPE_CDEV 5
510 #define HAMMER_OBJTYPE_BDEV 6
511 #define HAMMER_OBJTYPE_SOFTLINK 7
512 #define HAMMER_OBJTYPE_PSEUDOFS 8 /* pseudo filesystem obj */
515 * Generic full-sized record
517 struct hammer_generic_record
{
518 struct hammer_base_record base
;
523 * A HAMMER inode record.
525 * This forms the basis for a filesystem object. obj_id is the inode number,
526 * key1 represents the pseudo filesystem id for security partitioning
527 * (preventing cross-links and/or restricting a NFS export and specifying the
528 * security policy), and key2 represents the data retention policy id.
530 * Inode numbers are 64 bit quantities which uniquely identify a filesystem
531 * object for the ENTIRE life of the filesystem, even after the object has
532 * been deleted. For all intents and purposes inode numbers are simply
533 * allocated by incrementing a sequence space.
535 * There is an important distinction between the data stored in the inode
536 * record and the record's data reference. The record references a
537 * hammer_inode_data structure but the filesystem object size and hard link
538 * count is stored in the inode record itself. This allows multiple inodes
539 * to share the same hammer_inode_data structure. This is possible because
540 * any modifications will lay out new data. The HAMMER implementation need
541 * not use the data-sharing ability when laying down new records.
543 * A HAMMER inode is subject to the same historical storage requirements
544 * as any other record. In particular any change in filesystem or hard link
545 * count will lay down a new inode record when the filesystem is synced to
546 * disk. This can lead to a lot of junk records which get cleaned up by
547 * the data retention policy.
549 * The ino_atime and ino_mtime fields are a special case. Modifications to
550 * these fields do NOT lay down a new record by default, though the values
551 * are effectively frozen for snapshots which access historical versions
552 * of the inode record due to other operations. This means that atime will
553 * not necessarily be accurate in snapshots, backups, or mirrors. mtime
554 * will be accurate in backups and mirrors since it can be regenerated from
555 * the mirroring stream.
557 * Because nlinks is historically retained the hardlink count will be
558 * accurate when accessing a HAMMER filesystem snapshot.
560 struct hammer_inode_record
{
561 struct hammer_base_record base
;
562 u_int64_t ino_atime
; /* last access time (not historical) */
563 u_int64_t ino_mtime
; /* last modified time (not historical) */
564 u_int64_t ino_size
; /* filesystem object size */
565 u_int64_t ino_nlinks
; /* hard links */
569 * Data records specify the entire contents of a regular file object,
570 * including attributes. Small amounts of data can theoretically be
571 * embedded in the record itself but the use of this ability verses using
572 * an out-of-band data reference depends on the implementation.
574 struct hammer_data_record
{
575 struct hammer_base_record base
;
580 * A directory entry specifies the HAMMER filesystem object id, a copy of
581 * the file type, and file name (either embedded or as out-of-band data).
582 * If the file name is short enough to fit into den_name[] (including a
583 * terminating nul) then it will be embedded in the record, otherwise it
584 * is stored out-of-band. The base record's data reference always points
585 * to the nul-terminated filename regardless.
587 * Directory entries are indexed with a 128 bit namekey rather then an
588 * offset. A portion of the namekey is an iterator or randomizer to deal
591 * NOTE: base.base.obj_type holds the filesystem object type of obj_id,
592 * e.g. a den_type equivalent.
594 * NOTE: den_name / the filename data reference is NOT terminated with \0.
597 struct hammer_entry_record
{
598 struct hammer_base_record base
;
599 u_int64_t obj_id
; /* object being referenced */
600 u_int64_t reserved01
;
601 char den_name
[16]; /* short file names fit in record */
607 struct hammer_spike_record
{
608 struct hammer_base_record base
;
616 * Hammer rollup record
618 union hammer_record_ondisk
{
619 struct hammer_base_record base
;
620 struct hammer_generic_record generic
;
621 struct hammer_spike_record spike
;
622 struct hammer_inode_record inode
;
623 struct hammer_data_record data
;
624 struct hammer_entry_record entry
;
627 typedef union hammer_record_ondisk
*hammer_record_ondisk_t
;
630 * Filesystem buffer for records
632 #define HAMMER_RECORD_NODES \
633 ((HAMMER_BUFSIZE - sizeof(struct hammer_fsbuf_head) - 32) / \
634 sizeof(union hammer_record_ondisk))
636 #define HAMMER_RECORD_SIZE (64+32)
638 struct hammer_fsbuf_recs
{
639 struct hammer_fsbuf_head head
;
641 union hammer_record_ondisk recs
[HAMMER_RECORD_NODES
];
645 * Filesystem buffer for piecemeal data. Note that this does not apply
646 * to dedicated pure-data buffers as such buffers do not have a header.
649 #define HAMMER_DATA_SIZE (HAMMER_BUFSIZE - sizeof(struct hammer_fsbuf_head))
650 #define HAMMER_DATA_BLKSIZE 64
651 #define HAMMER_DATA_BLKMASK (HAMMER_DATA_BLKSIZE-1)
652 #define HAMMER_DATA_NODES (HAMMER_DATA_SIZE / HAMMER_DATA_BLKSIZE)
654 struct hammer_fsbuf_data
{
655 struct hammer_fsbuf_head head
;
656 u_int8_t data
[HAMMER_DATA_NODES
][HAMMER_DATA_BLKSIZE
];
660 * Filesystem buffer rollup
662 union hammer_fsbuf_ondisk
{
663 struct hammer_fsbuf_head head
;
664 struct hammer_fsbuf_btree btree
;
665 struct hammer_fsbuf_recs record
;
666 struct hammer_fsbuf_data data
;
669 typedef union hammer_fsbuf_ondisk
*hammer_fsbuf_ondisk_t
;
672 * HAMMER UNIX Attribute data
674 * The data reference in a HAMMER inode record points to this structure. Any
675 * modifications to the contents of this structure will result in a record
676 * replacement operation.
678 * short_data_off allows a small amount of data to be embedded in the
679 * hammer_inode_data structure. HAMMER typically uses this to represent
680 * up to 64 bytes of data, or to hold symlinks. Remember that allocations
681 * are in powers of 2 so 64, 192, 448, or 960 bytes of embedded data is
682 * support (64+64, 64+192, 64+448 64+960).
684 * parent_obj_id is only valid for directories (which cannot be hard-linked),
685 * and specifies the parent directory obj_id. This field will also be set
686 * for non-directory inodes as a recovery aid, but can wind up specifying
687 * stale information. However, since object id's are not reused, the worse
688 * that happens is that the recovery code is unable to use it.
690 struct hammer_inode_data
{
691 u_int16_t version
; /* inode data version */
692 u_int16_t mode
; /* basic unix permissions */
693 u_int32_t uflags
; /* chflags */
694 u_int32_t rmajor
; /* used by device nodes */
695 u_int32_t rminor
; /* used by device nodes */
697 u_int64_t parent_obj_id
;/* parent directory obj_id */
700 /* XXX device, softlink extension */
703 #define HAMMER_INODE_DATA_VERSION 1
705 #define HAMMER_OBJID_ROOT 1
708 * Rollup various structures embedded as record data
710 union hammer_data_ondisk
{
711 struct hammer_inode_data inode
;
714 #endif /* HAMMER_ALIST_METAELMS_256_1LYR */