blob: d8eff0b9122215b97dfe0f4a4f571545ef742d52 [file] [log] [blame]
Qu Wenruo3b4b40c2020-06-24 18:02:47 +02001/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2/*
3 * Copied from kernel/include/uapi/linux/btrfs_btree.h.
4 *
5 * Only modified the header.
6 */
7/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
8#ifndef __BTRFS_TREE_H__
9#define __BTRFS_TREE_H__
10
11#include <linux/types.h>
12
13#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
14
15/*
16 * The max metadata block size (node size).
17 *
18 * This limit is somewhat artificial. The memmove and tree block locking cost
19 * go up with larger node size.
20 */
21#define BTRFS_MAX_METADATA_BLOCKSIZE 65536
22
23/*
24 * We can actually store much bigger names, but lets not confuse the rest
25 * of linux.
26 *
27 * btrfs_dir_item::name_len follows this limitation.
28 */
29#define BTRFS_NAME_LEN 255
30
31/*
32 * Objectids start from here.
33 *
34 * Check btrfs_disk_key for the meaning of objectids.
35 */
36
37/*
38 * Root tree holds pointers to all of the tree roots.
39 * Without special mention, the root tree contains the root bytenr of all other
40 * trees, except the chunk tree and the log tree.
41 *
42 * The super block contains the root bytenr of this tree.
43 */
44#define BTRFS_ROOT_TREE_OBJECTID 1ULL
45
46/*
47 * Extent tree stores information about which extents are in use, and backrefs
48 * for each extent.
49 */
50#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
51
52/*
53 * Chunk tree stores btrfs logical address -> physical address mapping.
54 *
55 * The super block contains part of chunk tree for bootstrap, and contains
56 * the root bytenr of this tree.
57 */
58#define BTRFS_CHUNK_TREE_OBJECTID 3ULL
59
60/*
61 * Device tree stores info about which areas of a given device are in use,
62 * and physical address -> btrfs logical address mapping.
63 */
64#define BTRFS_DEV_TREE_OBJECTID 4ULL
65
66/* The fs tree is the first subvolume tree, storing files and directories. */
67#define BTRFS_FS_TREE_OBJECTID 5ULL
68
69/* Shows the directory objectid inside the root tree. */
70#define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
71
72/* Csum tree holds checksums of all the data extents. */
73#define BTRFS_CSUM_TREE_OBJECTID 7ULL
74
75/* Quota tree holds quota configuration and tracking. */
76#define BTRFS_QUOTA_TREE_OBJECTID 8ULL
77
78/* UUID tree stores items that use the BTRFS_UUID_KEY* types. */
79#define BTRFS_UUID_TREE_OBJECTID 9ULL
80
81/* Free space cache tree (v2 space cache) tracks free space in block groups. */
82#define BTRFS_FREE_SPACE_TREE_OBJECTID 10ULL
83
84/* Indicates device stats in the device tree. */
85#define BTRFS_DEV_STATS_OBJECTID 0ULL
86
87/* For storing balance parameters in the root tree. */
88#define BTRFS_BALANCE_OBJECTID -4ULL
89
90/* Orhpan objectid for tracking unlinked/truncated files. */
91#define BTRFS_ORPHAN_OBJECTID -5ULL
92
93/* Does write ahead logging to speed up fsyncs. */
94#define BTRFS_TREE_LOG_OBJECTID -6ULL
95#define BTRFS_TREE_LOG_FIXUP_OBJECTID -7ULL
96
97/* For space balancing. */
98#define BTRFS_TREE_RELOC_OBJECTID -8ULL
99#define BTRFS_DATA_RELOC_TREE_OBJECTID -9ULL
100
101/* Extent checksums, shared between the csum tree and log trees. */
102#define BTRFS_EXTENT_CSUM_OBJECTID -10ULL
103
104/* For storing free space cache (v1 space cache). */
105#define BTRFS_FREE_SPACE_OBJECTID -11ULL
106
107/* The inode number assigned to the special inode for storing free ino cache. */
108#define BTRFS_FREE_INO_OBJECTID -12ULL
109
110/* Dummy objectid represents multiple objectids. */
111#define BTRFS_MULTIPLE_OBJECTIDS -255ULL
112
113/* All files have objectids in this range. */
114#define BTRFS_FIRST_FREE_OBJECTID 256ULL
115#define BTRFS_LAST_FREE_OBJECTID -256ULL
116#define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
117
118
119/*
120 * The device items go into the chunk tree.
121 *
122 * The key is in the form
123 * (BTRFS_DEV_ITEMS_OBJECTID, BTRFS_DEV_ITEM_KEY, <device_id>)
124 */
125#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
126
127#define BTRFS_BTREE_INODE_OBJECTID 1
128
129#define BTRFS_EMPTY_SUBVOL_DIR_OBJECTID 2
130
131#define BTRFS_DEV_REPLACE_DEVID 0ULL
132
133/*
134 * Types start from here.
135 *
136 * Check btrfs_disk_key for details about types.
137 */
138
139/*
140 * Inode items have the data typically returned from stat and store other
141 * info about object characteristics.
142 *
143 * There is one for every file and dir in the FS.
144 */
145#define BTRFS_INODE_ITEM_KEY 1
146/* reserve 2-11 close to the inode for later flexibility */
147#define BTRFS_INODE_REF_KEY 12
148#define BTRFS_INODE_EXTREF_KEY 13
149#define BTRFS_XATTR_ITEM_KEY 24
150#define BTRFS_ORPHAN_ITEM_KEY 48
151
152/*
153 * Dir items are the name -> inode pointers in a directory.
154 *
155 * There is one for every name in a directory.
156 */
157#define BTRFS_DIR_LOG_ITEM_KEY 60
158#define BTRFS_DIR_LOG_INDEX_KEY 72
159#define BTRFS_DIR_ITEM_KEY 84
160#define BTRFS_DIR_INDEX_KEY 96
161
162/* Stores info (position, size ...) about a data extent of a file */
163#define BTRFS_EXTENT_DATA_KEY 108
164
165/*
166 * Extent csums are stored in a separate tree and hold csums for
167 * an entire extent on disk.
168 */
169#define BTRFS_EXTENT_CSUM_KEY 128
170
171/*
172 * Root items point to tree roots.
173 *
174 * They are typically in the root tree used by the super block to find all the
175 * other trees.
176 */
177#define BTRFS_ROOT_ITEM_KEY 132
178
179/*
180 * Root backrefs tie subvols and snapshots to the directory entries that
181 * reference them.
182 */
183#define BTRFS_ROOT_BACKREF_KEY 144
184
185/*
186 * Root refs make a fast index for listing all of the snapshots and
187 * subvolumes referenced by a given root. They point directly to the
188 * directory item in the root that references the subvol.
189 */
190#define BTRFS_ROOT_REF_KEY 156
191
192/*
193 * Extent items are in the extent tree.
194 *
195 * These record which blocks are used, and how many references there are.
196 */
197#define BTRFS_EXTENT_ITEM_KEY 168
198
199/*
200 * The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know
201 * the length, so we save the level in key->offset instead of the length.
202 */
203#define BTRFS_METADATA_ITEM_KEY 169
204
205#define BTRFS_TREE_BLOCK_REF_KEY 176
206
207#define BTRFS_EXTENT_DATA_REF_KEY 178
208
209#define BTRFS_EXTENT_REF_V0_KEY 180
210
211#define BTRFS_SHARED_BLOCK_REF_KEY 182
212
213#define BTRFS_SHARED_DATA_REF_KEY 184
214
215/*
216 * Block groups give us hints into the extent allocation trees.
217 *
218 * Stores how many free space there is in a block group.
219 */
220#define BTRFS_BLOCK_GROUP_ITEM_KEY 192
221
222/*
223 * Every block group is represented in the free space tree by a free space info
224 * item, which stores some accounting information. It is keyed on
225 * (block_group_start, FREE_SPACE_INFO, block_group_length).
226 */
227#define BTRFS_FREE_SPACE_INFO_KEY 198
228
229/*
230 * A free space extent tracks an extent of space that is free in a block group.
231 * It is keyed on (start, FREE_SPACE_EXTENT, length).
232 */
233#define BTRFS_FREE_SPACE_EXTENT_KEY 199
234
235/*
236 * When a block group becomes very fragmented, we convert it to use bitmaps
237 * instead of extents.
238 *
239 * A free space bitmap is keyed on (start, FREE_SPACE_BITMAP, length).
240 * The corresponding item is a bitmap with (length / sectorsize) bits.
241 */
242#define BTRFS_FREE_SPACE_BITMAP_KEY 200
243
244#define BTRFS_DEV_EXTENT_KEY 204
245#define BTRFS_DEV_ITEM_KEY 216
246#define BTRFS_CHUNK_ITEM_KEY 228
247
248/*
249 * Records the overall state of the qgroups.
250 *
251 * There's only one instance of this key present,
252 * (0, BTRFS_QGROUP_STATUS_KEY, 0)
253 */
254#define BTRFS_QGROUP_STATUS_KEY 240
255/*
256 * Records the currently used space of the qgroup.
257 *
258 * One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid).
259 */
260#define BTRFS_QGROUP_INFO_KEY 242
261
262/*
263 * Contains the user configured limits for the qgroup.
264 *
265 * One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid).
266 */
267#define BTRFS_QGROUP_LIMIT_KEY 244
268
269/*
270 * Records the child-parent relationship of qgroups. For
271 * each relation, 2 keys are present:
272 * (childid, BTRFS_QGROUP_RELATION_KEY, parentid)
273 * (parentid, BTRFS_QGROUP_RELATION_KEY, childid)
274 */
275#define BTRFS_QGROUP_RELATION_KEY 246
276
277/* Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. */
278#define BTRFS_BALANCE_ITEM_KEY 248
279
280/*
281 * The key type for tree items that are stored persistently, but do not need to
282 * exist for extended period of time. The items can exist in any tree.
283 *
284 * [subtype, BTRFS_TEMPORARY_ITEM_KEY, data]
285 *
286 * Existing items:
287 *
288 * - balance status item
289 * (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0)
290 */
291#define BTRFS_TEMPORARY_ITEM_KEY 248
292
293/* Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY */
294#define BTRFS_DEV_STATS_KEY 249
295
296/*
297 * The key type for tree items that are stored persistently and usually exist
298 * for a long period, eg. filesystem lifetime. The item kinds can be status
299 * information, stats or preference values. The item can exist in any tree.
300 *
301 * [subtype, BTRFS_PERSISTENT_ITEM_KEY, data]
302 *
303 * Existing items:
304 *
305 * - device statistics, store IO stats in the device tree, one key for all
306 * stats
307 * (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0)
308 */
309#define BTRFS_PERSISTENT_ITEM_KEY 249
310
311/*
312 * Persistently stores the device replace state in the device tree.
313 *
314 * The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0).
315 */
316#define BTRFS_DEV_REPLACE_KEY 250
317
318/*
319 * Stores items that allow to quickly map UUIDs to something else.
320 *
321 * These items are part of the filesystem UUID tree.
322 * The key is built like this:
323 * (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits).
324 */
325#define BTRFS_UUID_KEY_SUBVOL 251 /* for UUIDs assigned to subvols */
326#define BTRFS_UUID_KEY_RECEIVED_SUBVOL 252 /* for UUIDs assigned to
327 * received subvols */
328
329/*
330 * String items are for debugging.
331 *
332 * They just store a short string of data in the FS.
333 */
334#define BTRFS_STRING_ITEM_KEY 253
335
336
Qu Wenruo3b4b40c2020-06-24 18:02:47 +0200337/* 32 bytes in various csum fields */
338#define BTRFS_CSUM_SIZE 32
339
340/* Csum types */
341enum btrfs_csum_type {
342 BTRFS_CSUM_TYPE_CRC32 = 0,
343 BTRFS_CSUM_TYPE_XXHASH = 1,
344 BTRFS_CSUM_TYPE_SHA256 = 2,
345 BTRFS_CSUM_TYPE_BLAKE2 = 3,
346};
347
348/*
349 * Flags definitions for directory entry item type.
350 *
351 * Used by:
352 * struct btrfs_dir_item.type
353 *
354 * Values 0..7 must match common file type values in fs_types.h.
355 */
356#define BTRFS_FT_UNKNOWN 0
357#define BTRFS_FT_REG_FILE 1
358#define BTRFS_FT_DIR 2
359#define BTRFS_FT_CHRDEV 3
360#define BTRFS_FT_BLKDEV 4
361#define BTRFS_FT_FIFO 5
362#define BTRFS_FT_SOCK 6
363#define BTRFS_FT_SYMLINK 7
364#define BTRFS_FT_XATTR 8
365#define BTRFS_FT_MAX 9
366
367#define BTRFS_FSID_SIZE 16
368#define BTRFS_UUID_SIZE 16
369
370/*
371 * The key defines the order in the tree, and so it also defines (optimal)
372 * block layout.
373 *
374 * Objectid and offset are interpreted based on type.
375 * While normally for objectid, it either represents a root number, or an
376 * inode number.
377 *
378 * Type tells us things about the object, and is a kind of stream selector.
379 * Check the following URL for full references about btrfs_disk_key/btrfs_key:
380 * https://btrfs.wiki.kernel.org/index.php/Btree_Items
381 *
382 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
383 * in cpu native order. Otherwise they are identical and their sizes
384 * should be the same (ie both packed)
385 */
386struct btrfs_disk_key {
387 __le64 objectid;
388 __u8 type;
389 __le64 offset;
390} __attribute__ ((__packed__));
391
392struct btrfs_key {
393 __u64 objectid;
394 __u8 type;
395 __u64 offset;
396} __attribute__ ((__packed__));
397
398struct btrfs_dev_item {
399 /* The internal btrfs device id */
400 __le64 devid;
401
402 /* Size of the device */
403 __le64 total_bytes;
404
405 /* Bytes used */
406 __le64 bytes_used;
407
408 /* Optimal io alignment for this device */
409 __le32 io_align;
410
411 /* Optimal io width for this device */
412 __le32 io_width;
413
414 /* Minimal io size for this device */
415 __le32 sector_size;
416
417 /* Type and info about this device */
418 __le64 type;
419
420 /* Expected generation for this device */
421 __le64 generation;
422
423 /*
424 * Starting byte of this partition on the device,
425 * to allow for stripe alignment in the future.
426 */
427 __le64 start_offset;
428
429 /* Grouping information for allocation decisions */
430 __le32 dev_group;
431
432 /* Optimal seek speed 0-100 where 100 is fastest */
433 __u8 seek_speed;
434
435 /* Optimal bandwidth 0-100 where 100 is fastest */
436 __u8 bandwidth;
437
438 /* Btrfs generated uuid for this device */
439 __u8 uuid[BTRFS_UUID_SIZE];
440
441 /* UUID of FS who owns this device */
442 __u8 fsid[BTRFS_UUID_SIZE];
443} __attribute__ ((__packed__));
444
445struct btrfs_stripe {
446 __le64 devid;
447 __le64 offset;
448 __u8 dev_uuid[BTRFS_UUID_SIZE];
449} __attribute__ ((__packed__));
450
451struct btrfs_chunk {
452 /* Size of this chunk in bytes */
453 __le64 length;
454
455 /* Objectid of the root referencing this chunk */
456 __le64 owner;
457
458 __le64 stripe_len;
459 __le64 type;
460
461 /* Optimal io alignment for this chunk */
462 __le32 io_align;
463
464 /* Optimal io width for this chunk */
465 __le32 io_width;
466
467 /* Minimal io size for this chunk */
468 __le32 sector_size;
469
470 /*
471 * 2^16 stripes is quite a lot, a second limit is the size of a single
472 * item in the btree.
473 */
474 __le16 num_stripes;
475
476 /* Sub stripes only matter for raid10 */
477 __le16 sub_stripes;
478 struct btrfs_stripe stripe;
479 /* additional stripes go here */
480} __attribute__ ((__packed__));
481
482#define BTRFS_FREE_SPACE_EXTENT 1
483#define BTRFS_FREE_SPACE_BITMAP 2
484
485struct btrfs_free_space_entry {
486 __le64 offset;
487 __le64 bytes;
488 __u8 type;
489} __attribute__ ((__packed__));
490
491struct btrfs_free_space_header {
492 struct btrfs_disk_key location;
493 __le64 generation;
494 __le64 num_entries;
495 __le64 num_bitmaps;
496} __attribute__ ((__packed__));
497
498#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
499#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
500
501/* Super block flags */
502/* Errors detected */
503#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
504
505#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
506#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
507#define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
508#define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
509#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
510
511
512/*
513 * Items in the extent tree are used to record the objectid of the
514 * owner of the block and the number of references.
515 */
516struct btrfs_extent_item {
517 __le64 refs;
518 __le64 generation;
519 __le64 flags;
520} __attribute__ ((__packed__));
521
522struct btrfs_extent_item_v0 {
523 __le32 refs;
524} __attribute__ ((__packed__));
525
526
527#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
528#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
529
530/* Use full backrefs for extent pointers in the block */
531#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
532
533/*
534 * This flag is only used internally by scrub and may be changed at any time
535 * it is only declared here to avoid collisions.
536 */
537#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
538
539struct btrfs_tree_block_info {
540 struct btrfs_disk_key key;
541 __u8 level;
542} __attribute__ ((__packed__));
543
544struct btrfs_extent_data_ref {
545 __le64 root;
546 __le64 objectid;
547 __le64 offset;
548 __le32 count;
549} __attribute__ ((__packed__));
550
551struct btrfs_shared_data_ref {
552 __le32 count;
553} __attribute__ ((__packed__));
554
555struct btrfs_extent_inline_ref {
556 __u8 type;
557 __le64 offset;
558} __attribute__ ((__packed__));
559
560/* Old style backrefs item */
561struct btrfs_extent_ref_v0 {
562 __le64 root;
563 __le64 generation;
564 __le64 objectid;
565 __le32 count;
566} __attribute__ ((__packed__));
567
568
569/* Dev extents record used space on individual devices.
570 *
571 * The owner field points back to the chunk allocation mapping tree that
572 * allocated the extent.
573 * The chunk tree uuid field is a way to double check the owner.
574 */
575struct btrfs_dev_extent {
576 __le64 chunk_tree;
577 __le64 chunk_objectid;
578 __le64 chunk_offset;
579 __le64 length;
580 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
581} __attribute__ ((__packed__));
582
583struct btrfs_inode_ref {
584 __le64 index;
585 __le16 name_len;
586 /* Name goes here */
587} __attribute__ ((__packed__));
588
589struct btrfs_inode_extref {
590 __le64 parent_objectid;
591 __le64 index;
592 __le16 name_len;
593 __u8 name[0];
594 /* Name goes here */
595} __attribute__ ((__packed__));
596
597struct btrfs_timespec {
598 __le64 sec;
599 __le32 nsec;
600} __attribute__ ((__packed__));
601
602/* Inode flags */
603#define BTRFS_INODE_NODATASUM (1 << 0)
604#define BTRFS_INODE_NODATACOW (1 << 1)
605#define BTRFS_INODE_READONLY (1 << 2)
606#define BTRFS_INODE_NOCOMPRESS (1 << 3)
607#define BTRFS_INODE_PREALLOC (1 << 4)
608#define BTRFS_INODE_SYNC (1 << 5)
609#define BTRFS_INODE_IMMUTABLE (1 << 6)
610#define BTRFS_INODE_APPEND (1 << 7)
611#define BTRFS_INODE_NODUMP (1 << 8)
612#define BTRFS_INODE_NOATIME (1 << 9)
613#define BTRFS_INODE_DIRSYNC (1 << 10)
614#define BTRFS_INODE_COMPRESS (1 << 11)
615
616#define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
617
618#define BTRFS_INODE_FLAG_MASK \
619 (BTRFS_INODE_NODATASUM | \
620 BTRFS_INODE_NODATACOW | \
621 BTRFS_INODE_READONLY | \
622 BTRFS_INODE_NOCOMPRESS | \
623 BTRFS_INODE_PREALLOC | \
624 BTRFS_INODE_SYNC | \
625 BTRFS_INODE_IMMUTABLE | \
626 BTRFS_INODE_APPEND | \
627 BTRFS_INODE_NODUMP | \
628 BTRFS_INODE_NOATIME | \
629 BTRFS_INODE_DIRSYNC | \
630 BTRFS_INODE_COMPRESS | \
631 BTRFS_INODE_ROOT_ITEM_INIT)
632
633struct btrfs_inode_item {
634 /* Nfs style generation number */
635 __le64 generation;
636 /* Transid that last touched this inode */
637 __le64 transid;
638 __le64 size;
639 __le64 nbytes;
640 __le64 block_group;
641 __le32 nlink;
642 __le32 uid;
643 __le32 gid;
644 __le32 mode;
645 __le64 rdev;
646 __le64 flags;
647
648 /* Modification sequence number for NFS */
649 __le64 sequence;
650
651 /*
652 * A little future expansion, for more than this we can just grow the
653 * inode item and version it
654 */
655 __le64 reserved[4];
656 struct btrfs_timespec atime;
657 struct btrfs_timespec ctime;
658 struct btrfs_timespec mtime;
659 struct btrfs_timespec otime;
660} __attribute__ ((__packed__));
661
662struct btrfs_dir_log_item {
663 __le64 end;
664} __attribute__ ((__packed__));
665
666struct btrfs_dir_item {
667 struct btrfs_disk_key location;
668 __le64 transid;
669 __le16 data_len;
670 __le16 name_len;
671 __u8 type;
672} __attribute__ ((__packed__));
673
674#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
675
676/*
677 * Internal in-memory flag that a subvolume has been marked for deletion but
678 * still visible as a directory
679 */
680#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
681
682struct btrfs_root_item {
683 struct btrfs_inode_item inode;
684 __le64 generation;
685 __le64 root_dirid;
686 __le64 bytenr;
687 __le64 byte_limit;
688 __le64 bytes_used;
689 __le64 last_snapshot;
690 __le64 flags;
691 __le32 refs;
692 struct btrfs_disk_key drop_progress;
693 __u8 drop_level;
694 __u8 level;
695
696 /*
697 * The following fields appear after subvol_uuids+subvol_times
698 * were introduced.
699 */
700
701 /*
702 * This generation number is used to test if the new fields are valid
703 * and up to date while reading the root item. Every time the root item
704 * is written out, the "generation" field is copied into this field. If
705 * anyone ever mounted the fs with an older kernel, we will have
706 * mismatching generation values here and thus must invalidate the
707 * new fields. See btrfs_update_root and btrfs_find_last_root for
708 * details.
709 * The offset of generation_v2 is also used as the start for the memset
710 * when invalidating the fields.
711 */
712 __le64 generation_v2;
713 __u8 uuid[BTRFS_UUID_SIZE];
714 __u8 parent_uuid[BTRFS_UUID_SIZE];
715 __u8 received_uuid[BTRFS_UUID_SIZE];
716 __le64 ctransid; /* Updated when an inode changes */
717 __le64 otransid; /* Trans when created */
718 __le64 stransid; /* Trans when sent. Non-zero for received subvol. */
719 __le64 rtransid; /* Trans when received. Non-zero for received subvol.*/
720 struct btrfs_timespec ctime;
721 struct btrfs_timespec otime;
722 struct btrfs_timespec stime;
723 struct btrfs_timespec rtime;
724 __le64 reserved[8]; /* For future */
725} __attribute__ ((__packed__));
726
727/* This is used for both forward and backward root refs */
728struct btrfs_root_ref {
729 __le64 dirid;
730 __le64 sequence;
731 __le16 name_len;
732} __attribute__ ((__packed__));
733
734struct btrfs_disk_balance_args {
735 /*
736 * Profiles to operate on.
737 *
738 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
739 */
740 __le64 profiles;
741
742 /*
743 * Usage filter
744 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
745 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
746 */
747 union {
748 __le64 usage;
749 struct {
750 __le32 usage_min;
751 __le32 usage_max;
752 };
753 };
754
755 /* Devid filter */
756 __le64 devid;
757
758 /* Devid subset filter [pstart..pend) */
759 __le64 pstart;
760 __le64 pend;
761
762 /* Btrfs virtual address space subset filter [vstart..vend) */
763 __le64 vstart;
764 __le64 vend;
765
766 /*
767 * Profile to convert to.
768 *
769 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
770 */
771 __le64 target;
772
773 /* BTRFS_BALANCE_ARGS_* */
774 __le64 flags;
775
776 /*
777 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'.
778 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
779 * and maximum.
780 */
781 union {
782 __le64 limit;
783 struct {
784 __le32 limit_min;
785 __le32 limit_max;
786 };
787 };
788
789 /*
790 * Process chunks that cross stripes_min..stripes_max devices,
791 * BTRFS_BALANCE_ARGS_STRIPES_RANGE.
792 */
793 __le32 stripes_min;
794 __le32 stripes_max;
795
796 __le64 unused[6];
797} __attribute__ ((__packed__));
798
799/*
800 * Stores balance parameters to disk so that balance can be properly
801 * resumed after crash or unmount.
802 */
803struct btrfs_balance_item {
804 /* BTRFS_BALANCE_* */
805 __le64 flags;
806
807 struct btrfs_disk_balance_args data;
808 struct btrfs_disk_balance_args meta;
809 struct btrfs_disk_balance_args sys;
810
811 __le64 unused[4];
812} __attribute__ ((__packed__));
813
814enum {
815 BTRFS_FILE_EXTENT_INLINE = 0,
816 BTRFS_FILE_EXTENT_REG = 1,
817 BTRFS_FILE_EXTENT_PREALLOC = 2,
818 BTRFS_NR_FILE_EXTENT_TYPES = 3,
819};
820
821enum btrfs_compression_type {
822 BTRFS_COMPRESS_NONE = 0,
823 BTRFS_COMPRESS_ZLIB = 1,
824 BTRFS_COMPRESS_LZO = 2,
825 BTRFS_COMPRESS_ZSTD = 3,
826 BTRFS_NR_COMPRESS_TYPES = 4,
827};
828
829struct btrfs_file_extent_item {
830 /* Transaction id that created this extent */
831 __le64 generation;
832 /*
833 * Max number of bytes to hold this extent in ram.
834 *
835 * When we split a compressed extent we can't know how big each of the
836 * resulting pieces will be. So, this is an upper limit on the size of
837 * the extent in ram instead of an exact limit.
838 */
839 __le64 ram_bytes;
840
841 /*
842 * 32 bits for the various ways we might encode the data,
843 * including compression and encryption. If any of these
844 * are set to something a given disk format doesn't understand
845 * it is treated like an incompat flag for reading and writing,
846 * but not for stat.
847 */
848 __u8 compression;
849 __u8 encryption;
850 __le16 other_encoding; /* Spare for later use */
851
852 /* Are we inline data or a real extent? */
853 __u8 type;
854
855 /*
856 * Disk space consumed by the extent, checksum blocks are not included
857 * in these numbers
858 *
859 * At this offset in the structure, the inline extent data start.
860 */
861 __le64 disk_bytenr;
862 __le64 disk_num_bytes;
863
864 /*
865 * The logical offset inside the file extent.
866 *
867 * This allows a file extent to point into the middle of an existing
868 * extent on disk, sharing it between two snapshots (useful if some
869 * bytes in the middle of the extent have changed).
870 */
871 __le64 offset;
872
873 /*
874 * The logical number of bytes this file extent is referencing (no
875 * csums included).
876 *
877 * This always reflects the size uncompressed and without encoding.
878 */
879 __le64 num_bytes;
880
881} __attribute__ ((__packed__));
882
883struct btrfs_csum_item {
884 __u8 csum;
885} __attribute__ ((__packed__));
886
887enum btrfs_dev_stat_values {
888 /* Disk I/O failure stats */
889 BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
890 BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
891 BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
892
893 /* Stats for indirect indications for I/O failures */
894 BTRFS_DEV_STAT_CORRUPTION_ERRS, /* Checksum error, bytenr error or
895 * contents is illegal: this is an
896 * indication that the block was damaged
897 * during read or write, or written to
898 * wrong location or read from wrong
899 * location */
900 BTRFS_DEV_STAT_GENERATION_ERRS, /* An indication that blocks have not
901 * been written */
902
903 BTRFS_DEV_STAT_VALUES_MAX
904};
905
906struct btrfs_dev_stats_item {
907 /*
908 * Grow this item struct at the end for future enhancements and keep
909 * the existing values unchanged.
910 */
911 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
912} __attribute__ ((__packed__));
913
914#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
915#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
916
917struct btrfs_dev_replace_item {
918 /*
919 * Grow this item struct at the end for future enhancements and keep
920 * the existing values unchanged.
921 */
922 __le64 src_devid;
923 __le64 cursor_left;
924 __le64 cursor_right;
925 __le64 cont_reading_from_srcdev_mode;
926
927 __le64 replace_state;
928 __le64 time_started;
929 __le64 time_stopped;
930 __le64 num_write_errors;
931 __le64 num_uncorrectable_read_errors;
932} __attribute__ ((__packed__));
933
934/* Different types of block groups (and chunks) */
935#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
936#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
937#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
938#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
939#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
940#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
941#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
942#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
943#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
944#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
945#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
946#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
947 BTRFS_SPACE_INFO_GLOBAL_RSV)
948
949enum btrfs_raid_types {
950 BTRFS_RAID_RAID10,
951 BTRFS_RAID_RAID1,
952 BTRFS_RAID_DUP,
953 BTRFS_RAID_RAID0,
954 BTRFS_RAID_SINGLE,
955 BTRFS_RAID_RAID5,
956 BTRFS_RAID_RAID6,
957 BTRFS_RAID_RAID1C3,
958 BTRFS_RAID_RAID1C4,
959 BTRFS_NR_RAID_TYPES
960};
961
962#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
963 BTRFS_BLOCK_GROUP_SYSTEM | \
964 BTRFS_BLOCK_GROUP_METADATA)
965
966#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
967 BTRFS_BLOCK_GROUP_RAID1 | \
968 BTRFS_BLOCK_GROUP_RAID1C3 | \
969 BTRFS_BLOCK_GROUP_RAID1C4 | \
970 BTRFS_BLOCK_GROUP_RAID5 | \
971 BTRFS_BLOCK_GROUP_RAID6 | \
972 BTRFS_BLOCK_GROUP_DUP | \
973 BTRFS_BLOCK_GROUP_RAID10)
974#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
975 BTRFS_BLOCK_GROUP_RAID6)
976
977#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
978 BTRFS_BLOCK_GROUP_RAID1C3 | \
979 BTRFS_BLOCK_GROUP_RAID1C4)
980
981/*
982 * We need a bit for restriper to be able to tell when chunks of type
983 * SINGLE are available. This "extended" profile format is used in
984 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
985 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
986 * to avoid remappings between two formats in future.
987 */
988#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
989
990/*
991 * A fake block group type that is used to communicate global block reserve
992 * size to userspace via the SPACE_INFO ioctl.
993 */
994#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
995
996#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
997 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
998
999static inline __u64 chunk_to_extended(__u64 flags)
1000{
1001 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1002 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1003
1004 return flags;
1005}
1006static inline __u64 extended_to_chunk(__u64 flags)
1007{
1008 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1009}
1010
1011struct btrfs_block_group_item {
1012 __le64 used;
1013 __le64 chunk_objectid;
1014 __le64 flags;
1015} __attribute__ ((__packed__));
1016
1017struct btrfs_free_space_info {
1018 __le32 extent_count;
1019 __le32 flags;
1020} __attribute__ ((__packed__));
1021
1022#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1023
1024#define BTRFS_QGROUP_LEVEL_SHIFT 48
1025static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
1026{
1027 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
1028}
1029
1030/* Is subvolume quota turned on? */
1031#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1032
1033/* Is qgroup rescan running? */
1034#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1035
1036/*
1037 * Some qgroup entries are known to be out of date, either because the
1038 * configuration has changed in a way that makes a rescan necessary, or
1039 * because the fs has been mounted with a non-qgroup-aware version.
1040 */
1041#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1042
1043#define BTRFS_QGROUP_STATUS_VERSION 1
1044
1045struct btrfs_qgroup_status_item {
1046 __le64 version;
1047 /*
1048 * The generation is updated during every commit. As older
1049 * versions of btrfs are not aware of qgroups, it will be
1050 * possible to detect inconsistencies by checking the
1051 * generation on mount time.
1052 */
1053 __le64 generation;
1054
1055 /* Flag definitions see above */
1056 __le64 flags;
1057
1058 /*
1059 * Only used during scanning to record the progress of the scan.
1060 * It contains a logical address.
1061 */
1062 __le64 rescan;
1063} __attribute__ ((__packed__));
1064
1065struct btrfs_qgroup_info_item {
1066 __le64 generation;
1067 __le64 rfer;
1068 __le64 rfer_cmpr;
1069 __le64 excl;
1070 __le64 excl_cmpr;
1071} __attribute__ ((__packed__));
1072
1073/*
1074 * Flags definition for qgroup limits
1075 *
1076 * Used by:
1077 * struct btrfs_qgroup_limit.flags
1078 * struct btrfs_qgroup_limit_item.flags
1079 */
1080#define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
1081#define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
1082#define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
1083#define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
1084#define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
1085#define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
1086
1087struct btrfs_qgroup_limit_item {
1088 /* Only updated when any of the other values change. */
1089 __le64 flags;
1090 __le64 max_rfer;
1091 __le64 max_excl;
1092 __le64 rsv_rfer;
1093 __le64 rsv_excl;
1094} __attribute__ ((__packed__));
1095
1096/*
1097 * Just in case we somehow lose the roots and are not able to mount,
1098 * we store an array of the roots from previous transactions in the super.
1099 */
1100#define BTRFS_NUM_BACKUP_ROOTS 4
1101struct btrfs_root_backup {
1102 __le64 tree_root;
1103 __le64 tree_root_gen;
1104
1105 __le64 chunk_root;
1106 __le64 chunk_root_gen;
1107
1108 __le64 extent_root;
1109 __le64 extent_root_gen;
1110
1111 __le64 fs_root;
1112 __le64 fs_root_gen;
1113
1114 __le64 dev_root;
1115 __le64 dev_root_gen;
1116
1117 __le64 csum_root;
1118 __le64 csum_root_gen;
1119
1120 __le64 total_bytes;
1121 __le64 bytes_used;
1122 __le64 num_devices;
1123 /* future */
1124 __le64 unused_64[4];
1125
1126 u8 tree_root_level;
1127 u8 chunk_root_level;
1128 u8 extent_root_level;
1129 u8 fs_root_level;
1130 u8 dev_root_level;
1131 u8 csum_root_level;
1132 /* future and to align */
1133 u8 unused_8[10];
1134} __attribute__ ((__packed__));
1135
1136/*
1137 * This is a very generous portion of the super block, giving us room to
1138 * translate 14 chunks with 3 stripes each.
1139 */
1140#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
1141
1142#define BTRFS_LABEL_SIZE 256
1143
1144/* The super block basically lists the main trees of the FS. */
1145struct btrfs_super_block {
1146 /* The first 4 fields must match struct btrfs_header */
1147 u8 csum[BTRFS_CSUM_SIZE];
1148 /* FS specific UUID, visible to user */
1149 u8 fsid[BTRFS_FSID_SIZE];
1150 __le64 bytenr; /* this block number */
1151 __le64 flags;
1152
1153 /* Allowed to be different from the btrfs_header from here own down. */
1154 __le64 magic;
1155 __le64 generation;
1156 __le64 root;
1157 __le64 chunk_root;
1158 __le64 log_root;
1159
1160 /* This will help find the new super based on the log root. */
1161 __le64 log_root_transid;
1162 __le64 total_bytes;
1163 __le64 bytes_used;
1164 __le64 root_dir_objectid;
1165 __le64 num_devices;
1166 __le32 sectorsize;
1167 __le32 nodesize;
1168 __le32 __unused_leafsize;
1169 __le32 stripesize;
1170 __le32 sys_chunk_array_size;
1171 __le64 chunk_root_generation;
1172 __le64 compat_flags;
1173 __le64 compat_ro_flags;
1174 __le64 incompat_flags;
1175 __le16 csum_type;
1176 u8 root_level;
1177 u8 chunk_root_level;
1178 u8 log_root_level;
1179 struct btrfs_dev_item dev_item;
1180
1181 char label[BTRFS_LABEL_SIZE];
1182
1183 __le64 cache_generation;
1184 __le64 uuid_tree_generation;
1185
1186 /* The UUID written into btree blocks */
1187 u8 metadata_uuid[BTRFS_FSID_SIZE];
1188
1189 /* Future expansion */
1190 __le64 reserved[28];
1191 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
1192 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
1193} __attribute__ ((__packed__));
1194
1195/*
1196 * Feature flags
1197 *
1198 * Used by:
1199 * struct btrfs_super_block::(compat|compat_ro|incompat)_flags
1200 * struct btrfs_ioctl_feature_flags
1201 */
1202#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
1203
1204/*
1205 * Older kernels (< 4.9) on big-endian systems produced broken free space tree
1206 * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
1207 * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted.
1208 * btrfs-progs can also intentionally clear this bit to ask the kernel to
1209 * rebuild the free space tree, however this might not work on older kernels
1210 * that do not know about this bit. If not sure, clear the cache manually on
1211 * first mount when booting older kernel versions.
1212 */
1213#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1)
1214
1215#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
1216#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
1217#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
1218#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
1219#define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4)
1220
1221/*
1222 * Older kernels tried to do bigger metadata blocks, but the
1223 * code was pretty buggy. Lets not let them try anymore.
1224 */
1225#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
1226
1227#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
1228#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
1229#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
1230#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
1231#define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10)
1232#define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)
1233
1234/*
1235 * Compat flags that we support.
1236 *
1237 * If any incompat flags are set other than the ones specified below then we
1238 * will fail to mount.
1239 */
1240#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
1241#define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
1242#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
1243
1244#define BTRFS_FEATURE_COMPAT_RO_SUPP \
1245 (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \
1246 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
1247
1248#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL
1249#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
1250
1251#define BTRFS_FEATURE_INCOMPAT_SUPP \
1252 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
1253 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
1254 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
1255 BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
1256 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
1257 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \
1258 BTRFS_FEATURE_INCOMPAT_RAID56 | \
1259 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
1260 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
1261 BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
1262 BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
1263 BTRFS_FEATURE_INCOMPAT_RAID1C34)
1264
1265#define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
1266 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
1267#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL
1268
1269#define BTRFS_BACKREF_REV_MAX 256
1270#define BTRFS_BACKREF_REV_SHIFT 56
1271#define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
1272 BTRFS_BACKREF_REV_SHIFT)
1273
1274#define BTRFS_OLD_BACKREF_REV 0
1275#define BTRFS_MIXED_BACKREF_REV 1
1276
1277#define BTRFS_MAX_LEVEL 8
1278
1279/* Every tree block (leaf or node) starts with this header. */
1280struct btrfs_header {
1281 /* These first four must match the super block */
1282 u8 csum[BTRFS_CSUM_SIZE];
1283 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
1284 __le64 bytenr; /* Which block this node is supposed to live in */
1285 __le64 flags;
1286
1287 /* Allowed to be different from the super from here on down. */
1288 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
1289 __le64 generation;
1290 __le64 owner;
1291 __le32 nritems;
1292 u8 level;
1293} __attribute__ ((__packed__));
1294
1295/*
1296 * A leaf is full of items. Offset and size tell us where to find
1297 * the item in the leaf (relative to the start of the data area).
1298 */
1299struct btrfs_item {
1300 struct btrfs_disk_key key;
1301 __le32 offset;
1302 __le32 size;
1303} __attribute__ ((__packed__));
1304
1305/*
1306 * leaves have an item area and a data area:
1307 * [item0, item1....itemN] [free space] [dataN...data1, data0]
1308 *
1309 * The data is separate from the items to get the keys closer together
1310 * during searches.
1311 */
1312struct btrfs_leaf {
1313 struct btrfs_header header;
1314 struct btrfs_item items[];
1315} __attribute__ ((__packed__));
1316
1317/*
1318 * All non-leaf blocks are nodes, they hold only keys and pointers to children
1319 * blocks.
1320 */
1321struct btrfs_key_ptr {
1322 struct btrfs_disk_key key;
1323 __le64 blockptr;
1324 __le64 generation;
1325} __attribute__ ((__packed__));
1326
1327struct btrfs_node {
1328 struct btrfs_header header;
1329 struct btrfs_key_ptr ptrs[];
1330} __attribute__ ((__packed__));
1331
1332#endif /* __BTRFS_TREE_H__ */