Add quirk for SONY SMO drive. This (pre SCSI-2) drive returns a mystic
[dragonfly.git] / sys / vfs / hammer / hammer_disk.h
CommitLineData
8750964d
MD
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 *
66325755 34 * $DragonFly: src/sys/vfs/hammer/hammer_disk.h,v 1.5 2007/11/07 00:43:24 dillon Exp $
8750964d
MD
35 */
36
37#ifndef _SYS_UUID_H_
38#include <sys/uuid.h>
39#endif
40
41/*
42 * The structures below represent the on-disk format for a HAMMER
43 * filesystem. Note that all fields for on-disk structures are naturally
44 * aligned. The host endian format is used - compatibility is possible
45 * if the implementation detects reversed endian and adjusts data accordingly.
46 *
47 * Most of HAMMER revolves around the concept of an object identifier. An
48 * obj_id is a 64 bit quantity which uniquely identifies a filesystem object
49 * FOR THE ENTIRE LIFE OF THE FILESYSTEM. This uniqueness allows backups
50 * and mirrors to retain varying amounts of filesystem history by removing
51 * any possibility of conflict through identifier reuse.
52 *
53 * A HAMMER filesystem may spam multiple volumes.
54 *
55 * A HAMMER filesystem uses a 16K filesystem buffer size. All filesystem
c60bb2c5
MD
56 * I/O is done in multiples of 16K. Most buffer-sized headers such as those
57 * used by volumes, super-clusters, clusters, and basic filesystem buffers
58 * use fixed-sized A-lists which are heavily dependant on HAMMER_BUFSIZE.
8750964d
MD
59 */
60#define HAMMER_BUFSIZE 16384
61#define HAMMER_BUFMASK (HAMMER_BUFSIZE - 1)
62
63/*
64 * Hammer transction ids are 64 bit unsigned integers and are usually
65 * synchronized with the time of day in nanoseconds.
66 */
67typedef u_int64_t hammer_tid_t;
68
66325755
MD
69#define HAMMER_MAX_TID 0xFFFFFFFFFFFFFFFFULL
70
8750964d
MD
71/*
72 * Most HAMMER data structures are embedded in 16K filesystem buffers.
73 * All filesystem buffers except those designated as pure-data buffers
74 * contain this 128-byte header.
75 *
76 * This structure contains an embedded A-List used to manage space within
77 * the filesystem buffer. It is not used by volume or cluster header
78 * buffers, or by pure-data buffers. The granularity is variable and
79 * depends on the type of filesystem buffer. BLKSIZE is just a minimum.
80 */
81
82#define HAMMER_FSBUF_HEAD_SIZE 128
83#define HAMMER_FSBUF_MAXBLKS 256
9775c955 84#define HAMMER_FSBUF_BLKMASK (HAMMER_FSBUF_MAXBLKS - 1)
c60bb2c5 85#define HAMMER_FSBUF_METAELMS HAMMER_ALIST_METAELMS_256_1LYR /* 11 */
8750964d
MD
86
87struct hammer_fsbuf_head {
88 u_int64_t buf_type;
89 u_int32_t buf_crc;
90 u_int32_t buf_reserved07;
c60bb2c5 91 u_int32_t reserved[6];
8750964d
MD
92 struct hammer_almeta buf_almeta[HAMMER_FSBUF_METAELMS];
93};
94
95typedef struct hammer_fsbuf_head *hammer_fsbuf_head_t;
96
c60bb2c5
MD
97/*
98 * Note: Pure-data buffers contain pure-data and have no buf_type.
99 * Piecemeal data buffers do have a header and use HAMMER_FSBUF_DATA.
100 */
8750964d 101#define HAMMER_FSBUF_VOLUME 0xC8414D4DC5523031ULL /* HAMMER01 */
c60bb2c5 102#define HAMMER_FSBUF_SUPERCL 0xC8414D52C3555052ULL /* HAMRSUPR */
8750964d
MD
103#define HAMMER_FSBUF_CLUSTER 0xC8414D52C34C5553ULL /* HAMRCLUS */
104#define HAMMER_FSBUF_RECORDS 0xC8414D52D2454353ULL /* HAMRRECS */
105#define HAMMER_FSBUF_BTREE 0xC8414D52C2545245ULL /* HAMRBTRE */
106#define HAMMER_FSBUF_DATA 0xC8414D52C4415441ULL /* HAMRDATA */
107
108#define HAMMER_FSBUF_VOLUME_REV 0x313052C54D4D41C8ULL /* (reverse endian) */
109
110/*
111 * The B-Tree structures need hammer_fsbuf_head.
112 */
113#include "hammer_btree.h"
114
115/*
116 * HAMMER Volume header
117 *
118 * A HAMMER filesystem is built from any number of block devices, Each block
c60bb2c5
MD
119 * device contains a volume header followed by however many super-clusters
120 * and clusters fit into the volume. Clusters cannot be migrated but the
121 * data they contain can, so HAMMER can use a truncated cluster for any
122 * extra space at the end of the volume.
8750964d
MD
123 *
124 * The volume containing the root cluster is designated as the master volume.
125 * The root cluster designation can be moved to any volume.
126 *
127 * The volume header takes up an entire 16K filesystem buffer and includes
c60bb2c5
MD
128 * a one or two-layered A-list to manage the clusters making up the volume.
129 * A volume containing up to 32768 clusters (2TB) can be managed with a
130 * single-layered A-list. A two-layer A-list is capable of managing up
131 * to 16384 super-clusters with each super-cluster containing 32768 clusters
132 * (32768 TB per volume total). The number of volumes is limited to 32768
133 * but it only takes 512 to fill out a 64 bit address space so for all
134 * intents and purposes the filesystem has no limits.
135 *
136 * cluster addressing within a volume depends on whether a single or
137 * duel-layer A-list is used. If a duel-layer A-list is used a 16K
138 * super-cluster buffer is needed for every 16384 clusters in the volume.
139 * However, because the A-list's hinting is grouped in multiples of 16
140 * we group 16 super-cluster buffers together (starting just after the
141 * volume header), followed by 16384x16 clusters, and repeat.
142 *
143 * NOTE: A 32768-element single-layer and 16384-element duel-layer A-list
144 * is the same size.
8750964d 145 */
c60bb2c5
MD
146#define HAMMER_VOL_MAXCLUSTERS 32768 /* 1-layer */
147#define HAMMER_VOL_MAXSUPERCLUSTERS 16384 /* 2-layer */
148#define HAMMER_VOL_SUPERCLUSTER_GROUP 16
149#define HAMMER_VOL_METAELMS_1LYR HAMMER_ALIST_METAELMS_32K_1LYR
150#define HAMMER_VOL_METAELMS_2LYR HAMMER_ALIST_METAELMS_16K_2LYR
8750964d
MD
151
152struct hammer_volume_ondisk {
153 struct hammer_fsbuf_head head;
9775c955 154 int64_t vol_beg; /* byte offset of first cl/supercl in volume */
8750964d
MD
155 int64_t vol_end; /* byte offset of volume EOF */
156 int64_t vol_locked; /* reserved clusters are >= this offset */
157
158 uuid_t vol_fsid; /* identify filesystem */
159 uuid_t vol_fstype; /* identify filesystem type */
160 char vol_name[64]; /* Name of volume */
161
162 int32_t vol_no; /* volume number within filesystem */
163 int32_t vol_count; /* number of volumes making up FS */
164
165 u_int32_t vol_version; /* version control information */
9775c955 166 u_int32_t vol_reserved01;
8750964d
MD
167 u_int32_t vol_flags; /* volume flags */
168 u_int32_t vol_rootvol; /* which volume is the root volume? */
169
170 int32_t vol_clsize; /* cluster size (same for all volumes) */
9775c955 171 int32_t vol_nclusters;
8750964d
MD
172 u_int32_t vol_reserved06;
173 u_int32_t vol_reserved07;
174
27ea2398
MD
175 int32_t vol_stat_blocksize; /* for statfs only */
176 int64_t vol_stat_bytes; /* for statfs only */
177 int64_t vol_stat_inodes; /* for statfs only */
178
8750964d
MD
179 /*
180 * These fields are initialized and space is reserved in every
181 * volume making up a HAMMER filesytem, but only the master volume
182 * contains valid data.
183 */
427e5fc6
MD
184 int32_t vol0_root_clu_no; /* root cluster no (index) in rootvol */
185 hammer_tid_t vol0_root_clu_id; /* root cluster id */
8750964d
MD
186 hammer_tid_t vol0_nexttid; /* next TID */
187 u_int64_t vol0_recid; /* fs-wide record id allocator */
66325755 188 u_int64_t vol0_synchronized_rec_id; /* XXX */
8750964d
MD
189
190 char reserved[1024];
191
c60bb2c5
MD
192 /*
193 * Meta elements for the volume header's A-list, which is either a
194 * 1-layer A-list capable of managing 32768 clusters, or a 2-layer
195 * A-list capable of managing 16384 super-clusters (each of which
196 * can handle 32768 clusters).
197 */
198 union {
9775c955
MD
199 struct hammer_almeta super[HAMMER_VOL_METAELMS_2LYR];
200 struct hammer_almeta normal[HAMMER_VOL_METAELMS_1LYR];
c60bb2c5 201 } vol_almeta;
8750964d
MD
202 u_int32_t vol0_bitmap[1024];
203};
204
c60bb2c5
MD
205#define HAMMER_VOLF_VALID 0x0001 /* valid entry */
206#define HAMMER_VOLF_OPEN 0x0002 /* volume is open */
427e5fc6 207#define HAMMER_VOLF_USINGSUPERCL 0x0004 /* using superclusters */
c60bb2c5
MD
208
209/*
210 * HAMMER Super-cluster header
211 *
212 * A super-cluster is used to increase the maximum size of a volume.
213 * HAMMER's volume header can manage up to 32768 direct clusters or
214 * 16384 super-clusters. Each super-cluster (which is basically just
215 * a 16K filesystem buffer) can manage up to 32768 clusters. So adding
216 * a super-cluster layer allows a HAMMER volume to be sized upwards of
217 * around 32768TB instead of 2TB.
218 *
219 * Any volume initially formatted to be over 32G reserves space for the layer
220 * but the layer is only enabled if the volume exceeds 2TB.
221 */
222#define HAMMER_SUPERCL_METAELMS HAMMER_ALIST_METAELMS_32K_1LYR
9775c955 223#define HAMMER_SCL_MAXCLUSTERS HAMMER_VOL_MAXCLUSTERS
c60bb2c5
MD
224
225struct hammer_supercl_ondisk {
226 struct hammer_fsbuf_head head;
227 uuid_t vol_fsid; /* identify filesystem - sanity check */
228 uuid_t vol_fstype; /* identify filesystem type - sanity check */
229 int32_t reserved[1024];
230
9775c955 231 struct hammer_almeta scl_meta[HAMMER_SUPERCL_METAELMS];
c60bb2c5 232};
8750964d
MD
233
234/*
235 * HAMMER Cluster header
236 *
c60bb2c5
MD
237 * A cluster is limited to 64MB and is made up of 4096 16K filesystem
238 * buffers. The cluster header contains four A-lists to manage these
239 * buffers.
240 *
241 * master_alist - This is a non-layered A-list which manages pure-data
242 * allocations and allocations on behalf of other A-lists.
243 *
244 * btree_alist - This is a layered A-list which manages filesystem buffers
245 * containing B-Tree nodes.
8750964d 246 *
c60bb2c5
MD
247 * record_alist - This is a layered A-list which manages filesystem buffers
248 * containing records.
249 *
250 * mdata_alist - This is a layered A-list which manages filesystem buffers
251 * containing piecemeal record data.
252 *
253 * General storage management works like this: All the A-lists except the
254 * master start in an all-allocated state. Now lets say you wish to allocate
255 * a B-Tree node out the btree_alist. If the allocation fails you allocate
256 * a pure data block out of master_alist and then free that block in
257 * btree_alist, thereby assigning more space to the btree_alist, and then
258 * retry your allocation out of the btree_alist. In the reverse direction,
259 * filesystem buffers can be garbage collected back to master_alist simply
260 * by doing whole-buffer allocations in btree_alist and then freeing the
261 * space in master_alist. The whole-buffer-allocation approach to garbage
262 * collection works because A-list allocations are always power-of-2 sized
263 * and aligned.
8750964d 264 */
c60bb2c5
MD
265#define HAMMER_CLU_MAXBUFFERS 4096
266#define HAMMER_CLU_MASTER_METAELMS HAMMER_ALIST_METAELMS_4K_1LYR
267#define HAMMER_CLU_SLAVE_METAELMS HAMMER_ALIST_METAELMS_4K_2LYR
9775c955 268#define HAMMER_CLU_MAXBYTES (HAMMER_CLU_MAXBUFFERS * HAMMER_BUFSIZE)
8750964d
MD
269
270struct hammer_cluster_ondisk {
271 struct hammer_fsbuf_head head;
272 uuid_t vol_fsid; /* identify filesystem - sanity check */
273 uuid_t vol_fstype; /* identify filesystem type - sanity check */
274
275 u_int64_t clu_gen; /* identify generation number of cluster */
276 u_int64_t clu_unused01;
277
278 hammer_tid_t clu_id; /* unique cluster self identification */
279 int32_t vol_no; /* cluster contained in volume (sanity) */
280 u_int32_t clu_flags; /* cluster flags */
281
282 int32_t clu_start; /* start of data (byte offset) */
283 int32_t clu_limit; /* end of data (byte offset) */
284 int32_t clu_no; /* cluster index in volume (sanity) */
285 u_int32_t clu_reserved03;
286
287 u_int32_t clu_reserved04;
288 u_int32_t clu_reserved05;
289 u_int32_t clu_reserved06;
290 u_int32_t clu_reserved07;
291
9775c955
MD
292 int32_t idx_data; /* data append point (element no) */
293 int32_t idx_index; /* index append point (element no) */
294 int32_t idx_record; /* record prepend point (element no) */
8750964d
MD
295 u_int32_t idx_reserved03;
296
297 /*
c60bb2c5
MD
298 * Specify the range of information stored in this cluster as two
299 * btree elements. These elements exist as separate records that
300 * point to us in the parent cluster's B-Tree.
301 *
302 * Note that clu_btree_end is range-inclusive, not range-exclusive.
303 * i.e. 0-1023 instead of 0,1024.
8750964d 304 */
c60bb2c5
MD
305 struct hammer_base_elm clu_btree_beg;
306 struct hammer_base_elm clu_btree_end;
8750964d
MD
307
308 /*
c60bb2c5
MD
309 * The cluster's B-Tree root can change as a side effect of insertion
310 * and deletion operations so store an offset instead of embedding
311 * the root node.
8750964d 312 */
c60bb2c5
MD
313 int32_t clu_btree_root;
314 int32_t clu_btree_parent_vol_no;
315 int32_t clu_btree_parent_clu_no;
316 hammer_tid_t clu_btree_parent_clu_id;
8750964d 317
8750964d 318 u_int64_t synchronized_rec_id;
8750964d 319
9775c955
MD
320 struct hammer_almeta clu_master_meta[HAMMER_CLU_MASTER_METAELMS];
321 struct hammer_almeta clu_btree_meta[HAMMER_CLU_SLAVE_METAELMS];
322 struct hammer_almeta clu_record_meta[HAMMER_CLU_SLAVE_METAELMS];
323 struct hammer_almeta clu_mdata_meta[HAMMER_CLU_SLAVE_METAELMS];
8750964d
MD
324};
325
326/*
327 * HAMMER records are 96 byte entities encoded into 16K filesystem buffers.
328 * Each record has a 64 byte header and a 32 byte extension. 170 records
329 * fit into each buffer. Storage is managed by the buffer's A-List.
330 *
331 * Each record may have an explicit data reference to a block of data up
332 * to 2^31-1 bytes in size within the current cluster. Note that multiple
333 * records may share the same or overlapping data references.
334 */
335
336/*
337 * All HAMMER records have a common 64-byte base and a 32-byte extension.
338 *
339 * Many HAMMER record types reference out-of-band data within the cluster.
340 * This data can also be stored in-band in the record itself if it is small
341 * enough. Either way, (data_offset, data_len) points to it.
342 *
343 * Key comparison order: obj_id, rec_type, key, create_tid
344 */
345struct hammer_base_record {
427e5fc6
MD
346 /*
347 * 40 byte base element info - same base as used in B-Tree internal
348 * and leaf node element arrays.
349 *
350 * Fields: obj_id, key, create_tid, delete_tid, rec_type, obj_type,
351 * reserved07.
352 */
353 struct hammer_base_elm base; /* 00 base element info */
8750964d 354
8750964d
MD
355 int32_t data_len; /* 28 size of data (remainder zero-fill) */
356 u_int32_t data_crc; /* 2C data sanity check */
357 u_int64_t rec_id; /* 30 record id (iterator for recovery) */
427e5fc6
MD
358 int32_t data_offset; /* 38 cluster-relative data reference or 0 */
359 u_int32_t reserved07; /* 3C */
8750964d
MD
360 /* 40 */
361};
362
c60bb2c5
MD
363/*
364 * Record types are fairly straightforward. The B-Tree includes the record
365 * type in its index sort.
366 *
367 * In particular please note that it is possible to create a pseudo-
368 * filesystem within a HAMMER filesystem by creating a special object
369 * type within a directory. Pseudo-filesystems are used as replication
370 * targets and even though they are built within a HAMMER filesystem they
371 * get their own obj_id space (and thus can serve as a replication target)
372 * and look like a mount point to the system.
373 */
8750964d 374#define HAMMER_RECTYPE_UNKNOWN 0
66325755 375#define HAMMER_RECTYPE_LOWEST 1 /* lowest record type avail */
8750964d 376#define HAMMER_RECTYPE_INODE 1 /* inode in obj_id space */
c60bb2c5 377#define HAMMER_RECTYPE_PSEUDO_INODE 2 /* pseudo filesysem */
427e5fc6 378#define HAMMER_RECTYPE_CLUSTER 3 /* cluster reference */
66325755
MD
379#define HAMMER_RECTYPE_DATA 0x10
380#define HAMMER_RECTYPE_DIRENTRY 0x11
381#define HAMMER_RECTYPE_DB 0x12
382#define HAMMER_RECTYPE_EXT 0x13 /* ext attributes */
8750964d 383
66325755 384#define HAMMER_OBJTYPE_UNKNOWN 0 /* (never exists on-disk) */
8750964d
MD
385#define HAMMER_OBJTYPE_DIRECTORY 1
386#define HAMMER_OBJTYPE_REGFILE 2
387#define HAMMER_OBJTYPE_DBFILE 3
388#define HAMMER_OBJTYPE_FIFO 4
c60bb2c5
MD
389#define HAMMER_OBJTYPE_CDEV 5
390#define HAMMER_OBJTYPE_BDEV 6
391#define HAMMER_OBJTYPE_SOFTLINK 7
392#define HAMMER_OBJTYPE_PSEUDOFS 8 /* pseudo filesystem obj */
393
427e5fc6
MD
394#define HAMMER_OBJTYPE_CLUSTER_FLAG 0x20
395#define HAMMER_OBJTYPE_CLUSTER_BEG 0x20
396#define HAMMER_OBJTYPE_CLUSTER_END 0x21
8750964d
MD
397
398/*
399 * Generic full-sized record
400 */
401struct hammer_generic_record {
402 struct hammer_base_record base;
403 char filler[32];
404};
405
406/*
407 * A HAMMER inode record.
408 *
409 * This forms the basis for a filesystem object. obj_id is the inode number,
410 * key1 represents the pseudo filesystem id for security partitioning
411 * (preventing cross-links and/or restricting a NFS export and specifying the
412 * security policy), and key2 represents the data retention policy id.
413 *
414 * Inode numbers are 64 bit quantities which uniquely identify a filesystem
415 * object for the ENTIRE life of the filesystem, even after the object has
416 * been deleted. For all intents and purposes inode numbers are simply
417 * allocated by incrementing a sequence space.
418 *
419 * There is an important distinction between the data stored in the inode
420 * record and the record's data reference. The record references a
421 * hammer_inode_data structure but the filesystem object size and hard link
422 * count is stored in the inode record itself. This allows multiple inodes
423 * to share the same hammer_inode_data structure. This is possible because
424 * any modifications will lay out new data. The HAMMER implementation need
425 * not use the data-sharing ability when laying down new records.
426 *
427 * A HAMMER inode is subject to the same historical storage requirements
428 * as any other record. In particular any change in filesystem or hard link
429 * count will lay down a new inode record when the filesystem is synced to
430 * disk. This can lead to a lot of junk records which get cleaned up by
431 * the data retention policy.
432 *
433 * The ino_atime and ino_mtime fields are a special case. Modifications to
434 * these fields do NOT lay down a new record by default, though the values
435 * are effectively frozen for snapshots which access historical versions
436 * of the inode record due to other operations. This means that atime will
437 * not necessarily be accurate in snapshots, backups, or mirrors. mtime
438 * will be accurate in backups and mirrors since it can be regenerated from
439 * the mirroring stream.
440 *
441 * Because nlinks is historically retained the hardlink count will be
442 * accurate when accessing a HAMMER filesystem snapshot.
443 */
444struct hammer_inode_record {
445 struct hammer_base_record base;
446 u_int64_t ino_atime; /* last access time (not historical) */
447 u_int64_t ino_mtime; /* last modified time (not historical) */
448 u_int64_t ino_size; /* filesystem object size */
449 u_int64_t ino_nlinks; /* hard links */
450};
451
452/*
453 * Data records specify the entire contents of a regular file object,
454 * including attributes. Small amounts of data can theoretically be
455 * embedded in the record itself but the use of this ability verses using
456 * an out-of-band data reference depends on the implementation.
457 */
458struct hammer_data_record {
459 struct hammer_base_record base;
460 char filler[32];
461};
462
463/*
464 * A directory entry specifies the HAMMER filesystem object id, a copy of
465 * the file type, and file name (either embedded or as out-of-band data).
466 * If the file name is short enough to fit into den_name[] (including a
467 * terminating nul) then it will be embedded in the record, otherwise it
468 * is stored out-of-band. The base record's data reference always points
469 * to the nul-terminated filename regardless.
470 *
471 * Directory entries are indexed with a 128 bit namekey rather then an
472 * offset. A portion of the namekey is an iterator or randomizer to deal
473 * with collisions.
66325755
MD
474 *
475 * Note that base.base.obj_type holds the filesystem object type of obj_id,
476 * e.g. a den_type equivalent.
477 *
8750964d
MD
478 */
479struct hammer_entry_record {
480 struct hammer_base_record base;
481 u_int64_t obj_id; /* object being referenced */
482 u_int64_t reserved01;
66325755 483 char den_name[16]; /* short file names fit in record */
8750964d
MD
484};
485
486/*
487 * Hammer rollup record
488 */
c60bb2c5 489union hammer_record_ondisk {
8750964d
MD
490 struct hammer_base_record base;
491 struct hammer_generic_record generic;
492 struct hammer_inode_record inode;
493 struct hammer_data_record data;
494 struct hammer_entry_record entry;
495};
496
c60bb2c5 497typedef union hammer_record_ondisk *hammer_record_ondisk_t;
8750964d
MD
498
499/*
500 * Filesystem buffer for records
501 */
502#define HAMMER_RECORD_NODES \
503 ((HAMMER_BUFSIZE - sizeof(struct hammer_fsbuf_head)) / \
c60bb2c5 504 sizeof(union hammer_record_ondisk))
8750964d
MD
505
506struct hammer_fsbuf_recs {
507 struct hammer_fsbuf_head head;
508 char unused[32];
c60bb2c5 509 union hammer_record_ondisk recs[HAMMER_RECORD_NODES];
8750964d
MD
510};
511
512/*
513 * Filesystem buffer for piecemeal data. Note that this does not apply
514 * to dedicated pure-data buffers as such buffers do not have a header.
515 */
516
517#define HAMMER_DATA_SIZE (HAMMER_BUFSIZE - sizeof(struct hammer_fsbuf_head))
518#define HAMMER_DATA_BLKSIZE 64
9775c955 519#define HAMMER_DATA_BLKMASK (HAMMER_DATA_BLKSIZE-1)
8750964d
MD
520#define HAMMER_DATA_NODES (HAMMER_DATA_SIZE / HAMMER_DATA_BLKSIZE)
521
522struct hammer_fsbuf_data {
523 struct hammer_fsbuf_head head;
524 u_int8_t data[HAMMER_DATA_NODES][HAMMER_DATA_BLKSIZE];
525};
526
9775c955
MD
527/*
528 * Filesystem buffer rollup
529 */
530union hammer_fsbuf_ondisk {
531 struct hammer_fsbuf_head head;
532 struct hammer_fsbuf_btree btree;
533 struct hammer_fsbuf_recs record;
534 struct hammer_fsbuf_data data;
535};
536
537typedef union hammer_fsbuf_ondisk *hammer_fsbuf_ondisk_t;
8750964d
MD
538
539/*
540 * HAMMER UNIX Attribute data
541 *
542 * The data reference in a HAMMER inode record points to this structure. Any
543 * modifications to the contents of this structure will result in a record
544 * replacement operation.
545 *
546 * state_sum allows a filesystem object to be validated to a degree by
547 * generating a checksum of all of its pieces (in no particular order) and
548 * checking it against this field.
66325755
MD
549 *
550 * short_data_off allows a small amount of data to be embedded in the
551 * hammer_inode_data structure. HAMMER typically uses this to represent
552 * up to 64 bytes of data, or to hold symlinks. Remember that allocations
553 * are in powers of 2 so 64, 192, 448, or 960 bytes of embedded data is
554 * support (64+64, 64+192, 64+448 64+960).
555 *
556 * parent_obj_id is only valid for directories (which cannot be hard-linked),
557 * and specifies the parent directory obj_id. This field will also be set
558 * for non-directory inodes as a recovery aid, but can wind up specifying
559 * stale information. However, since object id's are not reused, the worse
560 * that happens is that the recovery code is unable to use it.
8750964d
MD
561 */
562struct hammer_inode_data {
563 u_int16_t version; /* inode data version */
564 u_int16_t mode; /* basic unix permissions */
565 u_int32_t uflags; /* chflags */
66325755
MD
566 u_int16_t short_data_off; /* degenerate data case */
567 u_int16_t short_data_len;
568 u_int32_t state_sum;
569 u_int64_t ctime;
570 u_int64_t parent_obj_id;/* parent directory obj_id */
8750964d
MD
571 uuid_t uid;
572 uuid_t gid;
573};
574
575#define HAMMER_INODE_DATA_VERSION 1
576
c60bb2c5
MD
577/*
578 * Rollup various structures embedded as record data
579 */
427e5fc6 580union hammer_data_ondisk {
c60bb2c5
MD
581 struct hammer_inode_data inode;
582};
583