blob: 6a76d1e456fb3e9102143d376cd57bf08d0879d8 [file] [log] [blame]
Qu Wenruo07d977f2020-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
337
338/* 32 bytes in various csum fields */
339#define BTRFS_CSUM_SIZE 32
340
341/* Csum types */
342enum btrfs_csum_type {
343 BTRFS_CSUM_TYPE_CRC32 = 0,
344 BTRFS_CSUM_TYPE_XXHASH = 1,
345 BTRFS_CSUM_TYPE_SHA256 = 2,
346 BTRFS_CSUM_TYPE_BLAKE2 = 3,
347};
348
349/*
350 * Flags definitions for directory entry item type.
351 *
352 * Used by:
353 * struct btrfs_dir_item.type
354 *
355 * Values 0..7 must match common file type values in fs_types.h.
356 */
357#define BTRFS_FT_UNKNOWN 0
358#define BTRFS_FT_REG_FILE 1
359#define BTRFS_FT_DIR 2
360#define BTRFS_FT_CHRDEV 3
361#define BTRFS_FT_BLKDEV 4
362#define BTRFS_FT_FIFO 5
363#define BTRFS_FT_SOCK 6
364#define BTRFS_FT_SYMLINK 7
365#define BTRFS_FT_XATTR 8
366#define BTRFS_FT_MAX 9
367
368#define BTRFS_FSID_SIZE 16
369#define BTRFS_UUID_SIZE 16
370
371/*
372 * The key defines the order in the tree, and so it also defines (optimal)
373 * block layout.
374 *
375 * Objectid and offset are interpreted based on type.
376 * While normally for objectid, it either represents a root number, or an
377 * inode number.
378 *
379 * Type tells us things about the object, and is a kind of stream selector.
380 * Check the following URL for full references about btrfs_disk_key/btrfs_key:
381 * https://btrfs.wiki.kernel.org/index.php/Btree_Items
382 *
383 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
384 * in cpu native order. Otherwise they are identical and their sizes
385 * should be the same (ie both packed)
386 */
387struct btrfs_disk_key {
388 __le64 objectid;
389 __u8 type;
390 __le64 offset;
391} __attribute__ ((__packed__));
392
393struct btrfs_key {
394 __u64 objectid;
395 __u8 type;
396 __u64 offset;
397} __attribute__ ((__packed__));
398
399struct btrfs_dev_item {
400 /* The internal btrfs device id */
401 __le64 devid;
402
403 /* Size of the device */
404 __le64 total_bytes;
405
406 /* Bytes used */
407 __le64 bytes_used;
408
409 /* Optimal io alignment for this device */
410 __le32 io_align;
411
412 /* Optimal io width for this device */
413 __le32 io_width;
414
415 /* Minimal io size for this device */
416 __le32 sector_size;
417
418 /* Type and info about this device */
419 __le64 type;
420
421 /* Expected generation for this device */
422 __le64 generation;
423
424 /*
425 * Starting byte of this partition on the device,
426 * to allow for stripe alignment in the future.
427 */
428 __le64 start_offset;
429
430 /* Grouping information for allocation decisions */
431 __le32 dev_group;
432
433 /* Optimal seek speed 0-100 where 100 is fastest */
434 __u8 seek_speed;
435
436 /* Optimal bandwidth 0-100 where 100 is fastest */
437 __u8 bandwidth;
438
439 /* Btrfs generated uuid for this device */
440 __u8 uuid[BTRFS_UUID_SIZE];
441
442 /* UUID of FS who owns this device */
443 __u8 fsid[BTRFS_UUID_SIZE];
444} __attribute__ ((__packed__));
445
446struct btrfs_stripe {
447 __le64 devid;
448 __le64 offset;
449 __u8 dev_uuid[BTRFS_UUID_SIZE];
450} __attribute__ ((__packed__));
451
452struct btrfs_chunk {
453 /* Size of this chunk in bytes */
454 __le64 length;
455
456 /* Objectid of the root referencing this chunk */
457 __le64 owner;
458
459 __le64 stripe_len;
460 __le64 type;
461
462 /* Optimal io alignment for this chunk */
463 __le32 io_align;
464
465 /* Optimal io width for this chunk */
466 __le32 io_width;
467
468 /* Minimal io size for this chunk */
469 __le32 sector_size;
470
471 /*
472 * 2^16 stripes is quite a lot, a second limit is the size of a single
473 * item in the btree.
474 */
475 __le16 num_stripes;
476
477 /* Sub stripes only matter for raid10 */
478 __le16 sub_stripes;
479 struct btrfs_stripe stripe;
480 /* additional stripes go here */
481} __attribute__ ((__packed__));
482
483#define BTRFS_FREE_SPACE_EXTENT 1
484#define BTRFS_FREE_SPACE_BITMAP 2
485
486struct btrfs_free_space_entry {
487 __le64 offset;
488 __le64 bytes;
489 __u8 type;
490} __attribute__ ((__packed__));
491
492struct btrfs_free_space_header {
493 struct btrfs_disk_key location;
494 __le64 generation;
495 __le64 num_entries;
496 __le64 num_bitmaps;
497} __attribute__ ((__packed__));
498
499#define BTRFS_HEADER_FLAG_WRITTEN (1ULL << 0)
500#define BTRFS_HEADER_FLAG_RELOC (1ULL << 1)
501
502/* Super block flags */
503/* Errors detected */
504#define BTRFS_SUPER_FLAG_ERROR (1ULL << 2)
505
506#define BTRFS_SUPER_FLAG_SEEDING (1ULL << 32)
507#define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
508#define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
509#define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)
510#define BTRFS_SUPER_FLAG_CHANGING_FSID_V2 (1ULL << 36)
511
512
513/*
514 * Items in the extent tree are used to record the objectid of the
515 * owner of the block and the number of references.
516 */
517struct btrfs_extent_item {
518 __le64 refs;
519 __le64 generation;
520 __le64 flags;
521} __attribute__ ((__packed__));
522
523struct btrfs_extent_item_v0 {
524 __le32 refs;
525} __attribute__ ((__packed__));
526
527
528#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0)
529#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1)
530
531/* Use full backrefs for extent pointers in the block */
532#define BTRFS_BLOCK_FLAG_FULL_BACKREF (1ULL << 8)
533
534/*
535 * This flag is only used internally by scrub and may be changed at any time
536 * it is only declared here to avoid collisions.
537 */
538#define BTRFS_EXTENT_FLAG_SUPER (1ULL << 48)
539
540struct btrfs_tree_block_info {
541 struct btrfs_disk_key key;
542 __u8 level;
543} __attribute__ ((__packed__));
544
545struct btrfs_extent_data_ref {
546 __le64 root;
547 __le64 objectid;
548 __le64 offset;
549 __le32 count;
550} __attribute__ ((__packed__));
551
552struct btrfs_shared_data_ref {
553 __le32 count;
554} __attribute__ ((__packed__));
555
556struct btrfs_extent_inline_ref {
557 __u8 type;
558 __le64 offset;
559} __attribute__ ((__packed__));
560
561/* Old style backrefs item */
562struct btrfs_extent_ref_v0 {
563 __le64 root;
564 __le64 generation;
565 __le64 objectid;
566 __le32 count;
567} __attribute__ ((__packed__));
568
569
570/* Dev extents record used space on individual devices.
571 *
572 * The owner field points back to the chunk allocation mapping tree that
573 * allocated the extent.
574 * The chunk tree uuid field is a way to double check the owner.
575 */
576struct btrfs_dev_extent {
577 __le64 chunk_tree;
578 __le64 chunk_objectid;
579 __le64 chunk_offset;
580 __le64 length;
581 __u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
582} __attribute__ ((__packed__));
583
584struct btrfs_inode_ref {
585 __le64 index;
586 __le16 name_len;
587 /* Name goes here */
588} __attribute__ ((__packed__));
589
590struct btrfs_inode_extref {
591 __le64 parent_objectid;
592 __le64 index;
593 __le16 name_len;
594 __u8 name[0];
595 /* Name goes here */
596} __attribute__ ((__packed__));
597
598struct btrfs_timespec {
599 __le64 sec;
600 __le32 nsec;
601} __attribute__ ((__packed__));
602
603/* Inode flags */
604#define BTRFS_INODE_NODATASUM (1 << 0)
605#define BTRFS_INODE_NODATACOW (1 << 1)
606#define BTRFS_INODE_READONLY (1 << 2)
607#define BTRFS_INODE_NOCOMPRESS (1 << 3)
608#define BTRFS_INODE_PREALLOC (1 << 4)
609#define BTRFS_INODE_SYNC (1 << 5)
610#define BTRFS_INODE_IMMUTABLE (1 << 6)
611#define BTRFS_INODE_APPEND (1 << 7)
612#define BTRFS_INODE_NODUMP (1 << 8)
613#define BTRFS_INODE_NOATIME (1 << 9)
614#define BTRFS_INODE_DIRSYNC (1 << 10)
615#define BTRFS_INODE_COMPRESS (1 << 11)
616
617#define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
618
619#define BTRFS_INODE_FLAG_MASK \
620 (BTRFS_INODE_NODATASUM | \
621 BTRFS_INODE_NODATACOW | \
622 BTRFS_INODE_READONLY | \
623 BTRFS_INODE_NOCOMPRESS | \
624 BTRFS_INODE_PREALLOC | \
625 BTRFS_INODE_SYNC | \
626 BTRFS_INODE_IMMUTABLE | \
627 BTRFS_INODE_APPEND | \
628 BTRFS_INODE_NODUMP | \
629 BTRFS_INODE_NOATIME | \
630 BTRFS_INODE_DIRSYNC | \
631 BTRFS_INODE_COMPRESS | \
632 BTRFS_INODE_ROOT_ITEM_INIT)
633
634struct btrfs_inode_item {
635 /* Nfs style generation number */
636 __le64 generation;
637 /* Transid that last touched this inode */
638 __le64 transid;
639 __le64 size;
640 __le64 nbytes;
641 __le64 block_group;
642 __le32 nlink;
643 __le32 uid;
644 __le32 gid;
645 __le32 mode;
646 __le64 rdev;
647 __le64 flags;
648
649 /* Modification sequence number for NFS */
650 __le64 sequence;
651
652 /*
653 * A little future expansion, for more than this we can just grow the
654 * inode item and version it
655 */
656 __le64 reserved[4];
657 struct btrfs_timespec atime;
658 struct btrfs_timespec ctime;
659 struct btrfs_timespec mtime;
660 struct btrfs_timespec otime;
661} __attribute__ ((__packed__));
662
663struct btrfs_dir_log_item {
664 __le64 end;
665} __attribute__ ((__packed__));
666
667struct btrfs_dir_item {
668 struct btrfs_disk_key location;
669 __le64 transid;
670 __le16 data_len;
671 __le16 name_len;
672 __u8 type;
673} __attribute__ ((__packed__));
674
675#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
676
677/*
678 * Internal in-memory flag that a subvolume has been marked for deletion but
679 * still visible as a directory
680 */
681#define BTRFS_ROOT_SUBVOL_DEAD (1ULL << 48)
682
683struct btrfs_root_item {
684 struct btrfs_inode_item inode;
685 __le64 generation;
686 __le64 root_dirid;
687 __le64 bytenr;
688 __le64 byte_limit;
689 __le64 bytes_used;
690 __le64 last_snapshot;
691 __le64 flags;
692 __le32 refs;
693 struct btrfs_disk_key drop_progress;
694 __u8 drop_level;
695 __u8 level;
696
697 /*
698 * The following fields appear after subvol_uuids+subvol_times
699 * were introduced.
700 */
701
702 /*
703 * This generation number is used to test if the new fields are valid
704 * and up to date while reading the root item. Every time the root item
705 * is written out, the "generation" field is copied into this field. If
706 * anyone ever mounted the fs with an older kernel, we will have
707 * mismatching generation values here and thus must invalidate the
708 * new fields. See btrfs_update_root and btrfs_find_last_root for
709 * details.
710 * The offset of generation_v2 is also used as the start for the memset
711 * when invalidating the fields.
712 */
713 __le64 generation_v2;
714 __u8 uuid[BTRFS_UUID_SIZE];
715 __u8 parent_uuid[BTRFS_UUID_SIZE];
716 __u8 received_uuid[BTRFS_UUID_SIZE];
717 __le64 ctransid; /* Updated when an inode changes */
718 __le64 otransid; /* Trans when created */
719 __le64 stransid; /* Trans when sent. Non-zero for received subvol. */
720 __le64 rtransid; /* Trans when received. Non-zero for received subvol.*/
721 struct btrfs_timespec ctime;
722 struct btrfs_timespec otime;
723 struct btrfs_timespec stime;
724 struct btrfs_timespec rtime;
725 __le64 reserved[8]; /* For future */
726} __attribute__ ((__packed__));
727
728/* This is used for both forward and backward root refs */
729struct btrfs_root_ref {
730 __le64 dirid;
731 __le64 sequence;
732 __le16 name_len;
733} __attribute__ ((__packed__));
734
735struct btrfs_disk_balance_args {
736 /*
737 * Profiles to operate on.
738 *
739 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
740 */
741 __le64 profiles;
742
743 /*
744 * Usage filter
745 * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N'
746 * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max
747 */
748 union {
749 __le64 usage;
750 struct {
751 __le32 usage_min;
752 __le32 usage_max;
753 };
754 };
755
756 /* Devid filter */
757 __le64 devid;
758
759 /* Devid subset filter [pstart..pend) */
760 __le64 pstart;
761 __le64 pend;
762
763 /* Btrfs virtual address space subset filter [vstart..vend) */
764 __le64 vstart;
765 __le64 vend;
766
767 /*
768 * Profile to convert to.
769 *
770 * SINGLE is denoted by BTRFS_AVAIL_ALLOC_BIT_SINGLE.
771 */
772 __le64 target;
773
774 /* BTRFS_BALANCE_ARGS_* */
775 __le64 flags;
776
777 /*
778 * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'.
779 * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
780 * and maximum.
781 */
782 union {
783 __le64 limit;
784 struct {
785 __le32 limit_min;
786 __le32 limit_max;
787 };
788 };
789
790 /*
791 * Process chunks that cross stripes_min..stripes_max devices,
792 * BTRFS_BALANCE_ARGS_STRIPES_RANGE.
793 */
794 __le32 stripes_min;
795 __le32 stripes_max;
796
797 __le64 unused[6];
798} __attribute__ ((__packed__));
799
800/*
801 * Stores balance parameters to disk so that balance can be properly
802 * resumed after crash or unmount.
803 */
804struct btrfs_balance_item {
805 /* BTRFS_BALANCE_* */
806 __le64 flags;
807
808 struct btrfs_disk_balance_args data;
809 struct btrfs_disk_balance_args meta;
810 struct btrfs_disk_balance_args sys;
811
812 __le64 unused[4];
813} __attribute__ ((__packed__));
814
815enum {
816 BTRFS_FILE_EXTENT_INLINE = 0,
817 BTRFS_FILE_EXTENT_REG = 1,
818 BTRFS_FILE_EXTENT_PREALLOC = 2,
819 BTRFS_NR_FILE_EXTENT_TYPES = 3,
820};
821
822enum btrfs_compression_type {
823 BTRFS_COMPRESS_NONE = 0,
824 BTRFS_COMPRESS_ZLIB = 1,
825 BTRFS_COMPRESS_LZO = 2,
826 BTRFS_COMPRESS_ZSTD = 3,
827 BTRFS_NR_COMPRESS_TYPES = 4,
828};
829
830struct btrfs_file_extent_item {
831 /* Transaction id that created this extent */
832 __le64 generation;
833 /*
834 * Max number of bytes to hold this extent in ram.
835 *
836 * When we split a compressed extent we can't know how big each of the
837 * resulting pieces will be. So, this is an upper limit on the size of
838 * the extent in ram instead of an exact limit.
839 */
840 __le64 ram_bytes;
841
842 /*
843 * 32 bits for the various ways we might encode the data,
844 * including compression and encryption. If any of these
845 * are set to something a given disk format doesn't understand
846 * it is treated like an incompat flag for reading and writing,
847 * but not for stat.
848 */
849 __u8 compression;
850 __u8 encryption;
851 __le16 other_encoding; /* Spare for later use */
852
853 /* Are we inline data or a real extent? */
854 __u8 type;
855
856 /*
857 * Disk space consumed by the extent, checksum blocks are not included
858 * in these numbers
859 *
860 * At this offset in the structure, the inline extent data start.
861 */
862 __le64 disk_bytenr;
863 __le64 disk_num_bytes;
864
865 /*
866 * The logical offset inside the file extent.
867 *
868 * This allows a file extent to point into the middle of an existing
869 * extent on disk, sharing it between two snapshots (useful if some
870 * bytes in the middle of the extent have changed).
871 */
872 __le64 offset;
873
874 /*
875 * The logical number of bytes this file extent is referencing (no
876 * csums included).
877 *
878 * This always reflects the size uncompressed and without encoding.
879 */
880 __le64 num_bytes;
881
882} __attribute__ ((__packed__));
883
884struct btrfs_csum_item {
885 __u8 csum;
886} __attribute__ ((__packed__));
887
888enum btrfs_dev_stat_values {
889 /* Disk I/O failure stats */
890 BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
891 BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
892 BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
893
894 /* Stats for indirect indications for I/O failures */
895 BTRFS_DEV_STAT_CORRUPTION_ERRS, /* Checksum error, bytenr error or
896 * contents is illegal: this is an
897 * indication that the block was damaged
898 * during read or write, or written to
899 * wrong location or read from wrong
900 * location */
901 BTRFS_DEV_STAT_GENERATION_ERRS, /* An indication that blocks have not
902 * been written */
903
904 BTRFS_DEV_STAT_VALUES_MAX
905};
906
907struct btrfs_dev_stats_item {
908 /*
909 * Grow this item struct at the end for future enhancements and keep
910 * the existing values unchanged.
911 */
912 __le64 values[BTRFS_DEV_STAT_VALUES_MAX];
913} __attribute__ ((__packed__));
914
915#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0
916#define BTRFS_DEV_REPLACE_ITEM_CONT_READING_FROM_SRCDEV_MODE_AVOID 1
917
918struct btrfs_dev_replace_item {
919 /*
920 * Grow this item struct at the end for future enhancements and keep
921 * the existing values unchanged.
922 */
923 __le64 src_devid;
924 __le64 cursor_left;
925 __le64 cursor_right;
926 __le64 cont_reading_from_srcdev_mode;
927
928 __le64 replace_state;
929 __le64 time_started;
930 __le64 time_stopped;
931 __le64 num_write_errors;
932 __le64 num_uncorrectable_read_errors;
933} __attribute__ ((__packed__));
934
935/* Different types of block groups (and chunks) */
936#define BTRFS_BLOCK_GROUP_DATA (1ULL << 0)
937#define BTRFS_BLOCK_GROUP_SYSTEM (1ULL << 1)
938#define BTRFS_BLOCK_GROUP_METADATA (1ULL << 2)
939#define BTRFS_BLOCK_GROUP_RAID0 (1ULL << 3)
940#define BTRFS_BLOCK_GROUP_RAID1 (1ULL << 4)
941#define BTRFS_BLOCK_GROUP_DUP (1ULL << 5)
942#define BTRFS_BLOCK_GROUP_RAID10 (1ULL << 6)
943#define BTRFS_BLOCK_GROUP_RAID5 (1ULL << 7)
944#define BTRFS_BLOCK_GROUP_RAID6 (1ULL << 8)
945#define BTRFS_BLOCK_GROUP_RAID1C3 (1ULL << 9)
946#define BTRFS_BLOCK_GROUP_RAID1C4 (1ULL << 10)
947#define BTRFS_BLOCK_GROUP_RESERVED (BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
948 BTRFS_SPACE_INFO_GLOBAL_RSV)
949
950enum btrfs_raid_types {
951 BTRFS_RAID_RAID10,
952 BTRFS_RAID_RAID1,
953 BTRFS_RAID_DUP,
954 BTRFS_RAID_RAID0,
955 BTRFS_RAID_SINGLE,
956 BTRFS_RAID_RAID5,
957 BTRFS_RAID_RAID6,
958 BTRFS_RAID_RAID1C3,
959 BTRFS_RAID_RAID1C4,
960 BTRFS_NR_RAID_TYPES
961};
962
963#define BTRFS_BLOCK_GROUP_TYPE_MASK (BTRFS_BLOCK_GROUP_DATA | \
964 BTRFS_BLOCK_GROUP_SYSTEM | \
965 BTRFS_BLOCK_GROUP_METADATA)
966
967#define BTRFS_BLOCK_GROUP_PROFILE_MASK (BTRFS_BLOCK_GROUP_RAID0 | \
968 BTRFS_BLOCK_GROUP_RAID1 | \
969 BTRFS_BLOCK_GROUP_RAID1C3 | \
970 BTRFS_BLOCK_GROUP_RAID1C4 | \
971 BTRFS_BLOCK_GROUP_RAID5 | \
972 BTRFS_BLOCK_GROUP_RAID6 | \
973 BTRFS_BLOCK_GROUP_DUP | \
974 BTRFS_BLOCK_GROUP_RAID10)
975#define BTRFS_BLOCK_GROUP_RAID56_MASK (BTRFS_BLOCK_GROUP_RAID5 | \
976 BTRFS_BLOCK_GROUP_RAID6)
977
978#define BTRFS_BLOCK_GROUP_RAID1_MASK (BTRFS_BLOCK_GROUP_RAID1 | \
979 BTRFS_BLOCK_GROUP_RAID1C3 | \
980 BTRFS_BLOCK_GROUP_RAID1C4)
981
982/*
983 * We need a bit for restriper to be able to tell when chunks of type
984 * SINGLE are available. This "extended" profile format is used in
985 * fs_info->avail_*_alloc_bits (in-memory) and balance item fields
986 * (on-disk). The corresponding on-disk bit in chunk.type is reserved
987 * to avoid remappings between two formats in future.
988 */
989#define BTRFS_AVAIL_ALLOC_BIT_SINGLE (1ULL << 48)
990
991/*
992 * A fake block group type that is used to communicate global block reserve
993 * size to userspace via the SPACE_INFO ioctl.
994 */
995#define BTRFS_SPACE_INFO_GLOBAL_RSV (1ULL << 49)
996
997#define BTRFS_EXTENDED_PROFILE_MASK (BTRFS_BLOCK_GROUP_PROFILE_MASK | \
998 BTRFS_AVAIL_ALLOC_BIT_SINGLE)
999
1000static inline __u64 chunk_to_extended(__u64 flags)
1001{
1002 if ((flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0)
1003 flags |= BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1004
1005 return flags;
1006}
1007static inline __u64 extended_to_chunk(__u64 flags)
1008{
1009 return flags & ~BTRFS_AVAIL_ALLOC_BIT_SINGLE;
1010}
1011
1012struct btrfs_block_group_item {
1013 __le64 used;
1014 __le64 chunk_objectid;
1015 __le64 flags;
1016} __attribute__ ((__packed__));
1017
1018struct btrfs_free_space_info {
1019 __le32 extent_count;
1020 __le32 flags;
1021} __attribute__ ((__packed__));
1022
1023#define BTRFS_FREE_SPACE_USING_BITMAPS (1ULL << 0)
1024
1025#define BTRFS_QGROUP_LEVEL_SHIFT 48
1026static inline __u64 btrfs_qgroup_level(__u64 qgroupid)
1027{
1028 return qgroupid >> BTRFS_QGROUP_LEVEL_SHIFT;
1029}
1030
1031/* Is subvolume quota turned on? */
1032#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0)
1033
1034/* Is qgroup rescan running? */
1035#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1)
1036
1037/*
1038 * Some qgroup entries are known to be out of date, either because the
1039 * configuration has changed in a way that makes a rescan necessary, or
1040 * because the fs has been mounted with a non-qgroup-aware version.
1041 */
1042#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2)
1043
1044#define BTRFS_QGROUP_STATUS_VERSION 1
1045
1046struct btrfs_qgroup_status_item {
1047 __le64 version;
1048 /*
1049 * The generation is updated during every commit. As older
1050 * versions of btrfs are not aware of qgroups, it will be
1051 * possible to detect inconsistencies by checking the
1052 * generation on mount time.
1053 */
1054 __le64 generation;
1055
1056 /* Flag definitions see above */
1057 __le64 flags;
1058
1059 /*
1060 * Only used during scanning to record the progress of the scan.
1061 * It contains a logical address.
1062 */
1063 __le64 rescan;
1064} __attribute__ ((__packed__));
1065
1066struct btrfs_qgroup_info_item {
1067 __le64 generation;
1068 __le64 rfer;
1069 __le64 rfer_cmpr;
1070 __le64 excl;
1071 __le64 excl_cmpr;
1072} __attribute__ ((__packed__));
1073
1074/*
1075 * Flags definition for qgroup limits
1076 *
1077 * Used by:
1078 * struct btrfs_qgroup_limit.flags
1079 * struct btrfs_qgroup_limit_item.flags
1080 */
1081#define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0)
1082#define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1)
1083#define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2)
1084#define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3)
1085#define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4)
1086#define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5)
1087
1088struct btrfs_qgroup_limit_item {
1089 /* Only updated when any of the other values change. */
1090 __le64 flags;
1091 __le64 max_rfer;
1092 __le64 max_excl;
1093 __le64 rsv_rfer;
1094 __le64 rsv_excl;
1095} __attribute__ ((__packed__));
1096
1097/*
1098 * Just in case we somehow lose the roots and are not able to mount,
1099 * we store an array of the roots from previous transactions in the super.
1100 */
1101#define BTRFS_NUM_BACKUP_ROOTS 4
1102struct btrfs_root_backup {
1103 __le64 tree_root;
1104 __le64 tree_root_gen;
1105
1106 __le64 chunk_root;
1107 __le64 chunk_root_gen;
1108
1109 __le64 extent_root;
1110 __le64 extent_root_gen;
1111
1112 __le64 fs_root;
1113 __le64 fs_root_gen;
1114
1115 __le64 dev_root;
1116 __le64 dev_root_gen;
1117
1118 __le64 csum_root;
1119 __le64 csum_root_gen;
1120
1121 __le64 total_bytes;
1122 __le64 bytes_used;
1123 __le64 num_devices;
1124 /* future */
1125 __le64 unused_64[4];
1126
1127 u8 tree_root_level;
1128 u8 chunk_root_level;
1129 u8 extent_root_level;
1130 u8 fs_root_level;
1131 u8 dev_root_level;
1132 u8 csum_root_level;
1133 /* future and to align */
1134 u8 unused_8[10];
1135} __attribute__ ((__packed__));
1136
1137/*
1138 * This is a very generous portion of the super block, giving us room to
1139 * translate 14 chunks with 3 stripes each.
1140 */
1141#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
1142
1143#define BTRFS_LABEL_SIZE 256
1144
1145/* The super block basically lists the main trees of the FS. */
1146struct btrfs_super_block {
1147 /* The first 4 fields must match struct btrfs_header */
1148 u8 csum[BTRFS_CSUM_SIZE];
1149 /* FS specific UUID, visible to user */
1150 u8 fsid[BTRFS_FSID_SIZE];
1151 __le64 bytenr; /* this block number */
1152 __le64 flags;
1153
1154 /* Allowed to be different from the btrfs_header from here own down. */
1155 __le64 magic;
1156 __le64 generation;
1157 __le64 root;
1158 __le64 chunk_root;
1159 __le64 log_root;
1160
1161 /* This will help find the new super based on the log root. */
1162 __le64 log_root_transid;
1163 __le64 total_bytes;
1164 __le64 bytes_used;
1165 __le64 root_dir_objectid;
1166 __le64 num_devices;
1167 __le32 sectorsize;
1168 __le32 nodesize;
1169 __le32 __unused_leafsize;
1170 __le32 stripesize;
1171 __le32 sys_chunk_array_size;
1172 __le64 chunk_root_generation;
1173 __le64 compat_flags;
1174 __le64 compat_ro_flags;
1175 __le64 incompat_flags;
1176 __le16 csum_type;
1177 u8 root_level;
1178 u8 chunk_root_level;
1179 u8 log_root_level;
1180 struct btrfs_dev_item dev_item;
1181
1182 char label[BTRFS_LABEL_SIZE];
1183
1184 __le64 cache_generation;
1185 __le64 uuid_tree_generation;
1186
1187 /* The UUID written into btree blocks */
1188 u8 metadata_uuid[BTRFS_FSID_SIZE];
1189
1190 /* Future expansion */
1191 __le64 reserved[28];
1192 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
1193 struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
1194} __attribute__ ((__packed__));
1195
1196/*
1197 * Feature flags
1198 *
1199 * Used by:
1200 * struct btrfs_super_block::(compat|compat_ro|incompat)_flags
1201 * struct btrfs_ioctl_feature_flags
1202 */
1203#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0)
1204
1205/*
1206 * Older kernels (< 4.9) on big-endian systems produced broken free space tree
1207 * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
1208 * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted.
1209 * btrfs-progs can also intentionally clear this bit to ask the kernel to
1210 * rebuild the free space tree, however this might not work on older kernels
1211 * that do not know about this bit. If not sure, clear the cache manually on
1212 * first mount when booting older kernel versions.
1213 */
1214#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1)
1215
1216#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0)
1217#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1)
1218#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2)
1219#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3)
1220#define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4)
1221
1222/*
1223 * Older kernels tried to do bigger metadata blocks, but the
1224 * code was pretty buggy. Lets not let them try anymore.
1225 */
1226#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5)
1227
1228#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6)
1229#define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7)
1230#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)
1231#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9)
1232#define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10)
1233#define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11)
1234
1235/*
1236 * Compat flags that we support.
1237 *
1238 * If any incompat flags are set other than the ones specified below then we
1239 * will fail to mount.
1240 */
1241#define BTRFS_FEATURE_COMPAT_SUPP 0ULL
1242#define BTRFS_FEATURE_COMPAT_SAFE_SET 0ULL
1243#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR 0ULL
1244
1245#define BTRFS_FEATURE_COMPAT_RO_SUPP \
1246 (BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE | \
1247 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
1248
1249#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET 0ULL
1250#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR 0ULL
1251
1252#define BTRFS_FEATURE_INCOMPAT_SUPP \
1253 (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \
1254 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
1255 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS | \
1256 BTRFS_FEATURE_INCOMPAT_BIG_METADATA | \
1257 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO | \
1258 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD | \
1259 BTRFS_FEATURE_INCOMPAT_RAID56 | \
1260 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF | \
1261 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA | \
1262 BTRFS_FEATURE_INCOMPAT_NO_HOLES | \
1263 BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \
1264 BTRFS_FEATURE_INCOMPAT_RAID1C34)
1265
1266#define BTRFS_FEATURE_INCOMPAT_SAFE_SET \
1267 (BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
1268#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR 0ULL
1269
1270#define BTRFS_BACKREF_REV_MAX 256
1271#define BTRFS_BACKREF_REV_SHIFT 56
1272#define BTRFS_BACKREF_REV_MASK (((u64)BTRFS_BACKREF_REV_MAX - 1) << \
1273 BTRFS_BACKREF_REV_SHIFT)
1274
1275#define BTRFS_OLD_BACKREF_REV 0
1276#define BTRFS_MIXED_BACKREF_REV 1
1277
1278#define BTRFS_MAX_LEVEL 8
1279
1280/* Every tree block (leaf or node) starts with this header. */
1281struct btrfs_header {
1282 /* These first four must match the super block */
1283 u8 csum[BTRFS_CSUM_SIZE];
1284 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
1285 __le64 bytenr; /* Which block this node is supposed to live in */
1286 __le64 flags;
1287
1288 /* Allowed to be different from the super from here on down. */
1289 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
1290 __le64 generation;
1291 __le64 owner;
1292 __le32 nritems;
1293 u8 level;
1294} __attribute__ ((__packed__));
1295
1296/*
1297 * A leaf is full of items. Offset and size tell us where to find
1298 * the item in the leaf (relative to the start of the data area).
1299 */
1300struct btrfs_item {
1301 struct btrfs_disk_key key;
1302 __le32 offset;
1303 __le32 size;
1304} __attribute__ ((__packed__));
1305
1306/*
1307 * leaves have an item area and a data area:
1308 * [item0, item1....itemN] [free space] [dataN...data1, data0]
1309 *
1310 * The data is separate from the items to get the keys closer together
1311 * during searches.
1312 */
1313struct btrfs_leaf {
1314 struct btrfs_header header;
1315 struct btrfs_item items[];
1316} __attribute__ ((__packed__));
1317
1318/*
1319 * All non-leaf blocks are nodes, they hold only keys and pointers to children
1320 * blocks.
1321 */
1322struct btrfs_key_ptr {
1323 struct btrfs_disk_key key;
1324 __le64 blockptr;
1325 __le64 generation;
1326} __attribute__ ((__packed__));
1327
1328struct btrfs_node {
1329 struct btrfs_header header;
1330 struct btrfs_key_ptr ptrs[];
1331} __attribute__ ((__packed__));
1332
1333#endif /* __BTRFS_TREE_H__ */