Skip to contentSkip to conversation

btrfs: Move on-disk structure definition to btrfs_tree.h

PATCH Superseded Qu Wenruo 4 participants 4 messages Apr 8, 2020 – Apr 15, 2020 Btrfs file system

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v3 1/1 btrfs: Move on-disk structure definition to btrfs_tree.h

These structures all are on-disk format. Move them to btrfs_tree.h

This allows us to sync the header to different projects, who need to read btrfs filesystem, like U-boot, grub.

With this modification, all on-disk format is definite in btrfs_tree.h, and can be easily synced to other projects.

This move includes:
- btrfs magic
It's a surprise that it's not even definied in btrfs_tree.h

- tree block max level
Move it before btrfs_header definition.

- tree block backref revision
- btrfs_header structure
- btrfs_root_backup structure
- btrfs_super_block structure
- BTRFS_FEATURE_* flags
- BTRFS_(FSID|UUID|LABEL)_SIZE macros
- BTRFS_MAX_METADATA_BLOCKSIZE macro
- BTRFS_NAME_LEN macro

- btrfs_item structure
- btrfs_leaf structure
- btrfs_key_ptr structure
- btrfs_node structure

- btrfs_dev_stat_values
Since on-disk format btrfs_dev_stats_item needs it.

- BTRFS_INODE_* flags
- BTRFS_QGROUP_LIMIT_* flags

---
Changelog:
v2:
- Add the reason why we move the code

v3:
- Move more flags/enum shared with ioctl to btrfs_btree.h This makes ioctl header to rely on btree_btree.h.
But this makes btrfs_tree.h completely self-consistent. This problem is mostly exposed when syncing the header to btrfs-progs.

---
 fs/btrfs/ctree.h                | 246 ------------------------
 include/uapi/linux/btrfs.h      |  74 +------
 include/uapi/linux/btrfs_tree.h | 329 +++++++++++++++++++++++++++++++-
 3 files changed, 327 insertions(+), 322 deletions(-)
fs/btrfs/ctree.h +0 -246
index 8aa7b9dac405..4d787d749315 100644
@@ -49,8 +49,6 @@ extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
 struct btrfs_ordered_sum;
 struct btrfs_ref;
 
-#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
-
 /*
  * Maximum number of mirrors that can be available for all profiles counting
  * the target device of dev-replace as one. During an active device replace
@@ -62,22 +60,8 @@ struct btrfs_ref;
  */
 #define BTRFS_MAX_MIRRORS (4 + 1)
 
-#define BTRFS_MAX_LEVEL 8
-
 #define BTRFS_OLDEST_GENERATION	0ULL
 
-/*
- * the max metadata block size.  This limit is somewhat artificial,
- * but the memmove costs go through the roof for larger blocks.
- */
-#define BTRFS_MAX_METADATA_BLOCKSIZE 65536
-
-/*
- * we can actually store much bigger names, but lets not confuse the rest
- * of linux
- */
-#define BTRFS_NAME_LEN 255
-
 /*
  * Theoretical limit is larger, but we keep this down to a sane
  * value. That should limit greatly the possibility of collisions on
@@ -148,203 +132,6 @@ enum {
 	BTRFS_FS_STATE_DUMMY_FS_INFO,
 };
 
-#define BTRFS_BACKREF_REV_MAX		256
-#define BTRFS_BACKREF_REV_SHIFT		56
-#define BTRFS_BACKREF_REV_MASK		(((u64)BTRFS_BACKREF_REV_MAX - 1) << \
-					 BTRFS_BACKREF_REV_SHIFT)
-
-#define BTRFS_OLD_BACKREF_REV		0
-#define BTRFS_MIXED_BACKREF_REV		1
-
-/*
- * every tree block (leaf or node) starts with this header.
- */
-struct btrfs_header {
-	/* these first four must match the super block */
-	u8 csum[BTRFS_CSUM_SIZE];
-	u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
-	__le64 bytenr; /* which block this node is supposed to live in */
-	__le64 flags;
-
-	/* allowed to be different from the super from here on down */
-	u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
-	__le64 generation;
-	__le64 owner;
-	__le32 nritems;
-	u8 level;
-} __attribute__ ((__packed__));
-
-/*
- * this is a very generous portion of the super block, giving us
- * room to translate 14 chunks with 3 stripes each.
- */
-#define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
-
-/*
- * just in case we somehow lose the roots and are not able to mount,
- * we store an array of the roots from previous transactions
- * in the super.
- */
-#define BTRFS_NUM_BACKUP_ROOTS 4
-struct btrfs_root_backup {
-	__le64 tree_root;
-	__le64 tree_root_gen;
-
-	__le64 chunk_root;
-	__le64 chunk_root_gen;
-
-	__le64 extent_root;
-	__le64 extent_root_gen;
-
-	__le64 fs_root;
-	__le64 fs_root_gen;
-
-	__le64 dev_root;
-	__le64 dev_root_gen;
-
-	__le64 csum_root;
-	__le64 csum_root_gen;
-
-	__le64 total_bytes;
-	__le64 bytes_used;
-	__le64 num_devices;
-	/* future */
-	__le64 unused_64[4];
-
-	u8 tree_root_level;
-	u8 chunk_root_level;
-	u8 extent_root_level;
-	u8 fs_root_level;
-	u8 dev_root_level;
-	u8 csum_root_level;
-	/* future and to align */
-	u8 unused_8[10];
-} __attribute__ ((__packed__));
-
-/*
- * the super block basically lists the main trees of the FS
- * it currently lacks any block count etc etc
- */
-struct btrfs_super_block {
-	/* the first 4 fields must match struct btrfs_header */
-	u8 csum[BTRFS_CSUM_SIZE];
-	/* FS specific UUID, visible to user */
-	u8 fsid[BTRFS_FSID_SIZE];
-	__le64 bytenr; /* this block number */
-	__le64 flags;
-
-	/* allowed to be different from the btrfs_header from here own down */
-	__le64 magic;
-	__le64 generation;
-	__le64 root;
-	__le64 chunk_root;
-	__le64 log_root;
-
-	/* this will help find the new super based on the log root */
-	__le64 log_root_transid;
-	__le64 total_bytes;
-	__le64 bytes_used;
-	__le64 root_dir_objectid;
-	__le64 num_devices;
-	__le32 sectorsize;
-	__le32 nodesize;
-	__le32 __unused_leafsize;
-	__le32 stripesize;
-	__le32 sys_chunk_array_size;
-	__le64 chunk_root_generation;
-	__le64 compat_flags;
-	__le64 compat_ro_flags;
-	__le64 incompat_flags;
-	__le16 csum_type;
-	u8 root_level;
-	u8 chunk_root_level;
-	u8 log_root_level;
-	struct btrfs_dev_item dev_item;
-
-	char label[BTRFS_LABEL_SIZE];
-
-	__le64 cache_generation;
-	__le64 uuid_tree_generation;
-
-	/* the UUID written into btree blocks */
-	u8 metadata_uuid[BTRFS_FSID_SIZE];
-
-	/* future expansion */
-	__le64 reserved[28];
-	u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
-	struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
-} __attribute__ ((__packed__));
-
-/*
- * Compat flags that we support.  If any incompat flags are set other than the
- * ones specified below then we will fail to mount
- */
-#define BTRFS_FEATURE_COMPAT_SUPP		0ULL
-#define BTRFS_FEATURE_COMPAT_SAFE_SET		0ULL
-#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR		0ULL
-
-#define BTRFS_FEATURE_COMPAT_RO_SUPP			\
-	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
-	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID)
-
-#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET	0ULL
-#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR	0ULL
-
-#define BTRFS_FEATURE_INCOMPAT_SUPP			\
-	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
-	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
-	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
-	 BTRFS_FEATURE_INCOMPAT_BIG_METADATA |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD |		\
-	 BTRFS_FEATURE_INCOMPAT_RAID56 |		\
-	 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |		\
-	 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |	\
-	 BTRFS_FEATURE_INCOMPAT_NO_HOLES	|	\
-	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID	|	\
-	 BTRFS_FEATURE_INCOMPAT_RAID1C34)
-
-#define BTRFS_FEATURE_INCOMPAT_SAFE_SET			\
-	(BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
-#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR		0ULL
-
-/*
- * A leaf is full of items. offset and size tell us where to find
- * the item in the leaf (relative to the start of the data area)
- */
-struct btrfs_item {
-	struct btrfs_disk_key key;
-	__le32 offset;
-	__le32 size;
-} __attribute__ ((__packed__));
-
-/*
- * leaves have an item area and a data area:
- * [item0, item1....itemN] [free space] [dataN...data1, data0]
- *
- * The data is separate from the items to get the keys closer together
- * during searches.
- */
-struct btrfs_leaf {
-	struct btrfs_header header;
-	struct btrfs_item items[];
-} __attribute__ ((__packed__));
-
-/*
- * all non-leaf blocks are nodes, they hold only keys and pointers to
- * other blocks
- */
-struct btrfs_key_ptr {
-	struct btrfs_disk_key key;
-	__le64 blockptr;
-	__le64 generation;
-} __attribute__ ((__packed__));
-
-struct btrfs_node {
-	struct btrfs_header header;
-	struct btrfs_key_ptr ptrs[];
-} __attribute__ ((__packed__));
-
 /*
  * btrfs_paths remember the path taken from the root down to the leaf.
  * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
@@ -1307,39 +1094,6 @@ do {                                                                   \
        }                                                               \
 } while(0)
 
-/*
- * Inode flags
- */
-#define BTRFS_INODE_NODATASUM		(1 << 0)
-#define BTRFS_INODE_NODATACOW		(1 << 1)
-#define BTRFS_INODE_READONLY		(1 << 2)
-#define BTRFS_INODE_NOCOMPRESS		(1 << 3)
-#define BTRFS_INODE_PREALLOC		(1 << 4)
-#define BTRFS_INODE_SYNC		(1 << 5)
-#define BTRFS_INODE_IMMUTABLE		(1 << 6)
-#define BTRFS_INODE_APPEND		(1 << 7)
-#define BTRFS_INODE_NODUMP		(1 << 8)
-#define BTRFS_INODE_NOATIME		(1 << 9)
-#define BTRFS_INODE_DIRSYNC		(1 << 10)
-#define BTRFS_INODE_COMPRESS		(1 << 11)
-
-#define BTRFS_INODE_ROOT_ITEM_INIT	(1 << 31)
-
-#define BTRFS_INODE_FLAG_MASK						\
-	(BTRFS_INODE_NODATASUM |					\
-	 BTRFS_INODE_NODATACOW |					\
-	 BTRFS_INODE_READONLY |						\
-	 BTRFS_INODE_NOCOMPRESS |					\
-	 BTRFS_INODE_PREALLOC |						\
-	 BTRFS_INODE_SYNC |						\
-	 BTRFS_INODE_IMMUTABLE |					\
-	 BTRFS_INODE_APPEND |						\
-	 BTRFS_INODE_NODUMP |						\
-	 BTRFS_INODE_NOATIME |						\
-	 BTRFS_INODE_DIRSYNC |						\
-	 BTRFS_INODE_COMPRESS |						\
-	 BTRFS_INODE_ROOT_ITEM_INIT)
-
 struct btrfs_map_token {
 	const struct extent_buffer *eb;
 	char *kaddr;
include/uapi/linux/btrfs.h +1 -73

103 lines not on this page · raw message

include/uapi/linux/btrfs_tree.h +326 -3

369 lines not on this page · raw message

Signature · 1 line
2.26.0
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Qu,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on next-20200408]
[also build test ERROR on v5.6]
[cannot apply to btrfs/next v5.6 v5.6-rc7 v5.6-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Qu-Wenruo/btrfs-Move-on-disk-structure-definition-to-btrfs_tree-h/20200408-162128
base:    5798bd75ab137611da5c4cb11b6795d14cb60ba2
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from ./usr/include/linux/btrfs_tree.h:5:0,

                    from <command-line>:32:
>> ./usr/include/linux/btrfs.h:225:12: error: 'BTRFS_UUID_SIZE' undeclared here (not in a function); did you mean 'BTRFS_UUID_UNPARSED_SIZE'?
     __u8 uuid[BTRFS_UUID_SIZE];  /* in/out */
               ^~~~~~~~~~~~~~~
               BTRFS_UUID_UNPARSED_SIZE
>> ./usr/include/linux/btrfs.h:235:12: error: 'BTRFS_FSID_SIZE' undeclared here (not in a function); did you mean 'BTRFS_UUID_SIZE'?
     __u8 fsid[BTRFS_FSID_SIZE];  /* out */
               ^~~~~~~~~~~~~~~
               BTRFS_UUID_SIZE
>> ./usr/include/linux/btrfs.h:616:15: error: 'BTRFS_DEV_STAT_VALUES_MAX' undeclared here (not in a function); did you mean 'BTRFS_DEV_STATS_RESET'?
     __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
                  ^~~~~~~~~~~~~~~~~~~~~~~~~
                  BTRFS_DEV_STATS_RESET
   In file included from <command-line>:32:0:
>> ./usr/include/linux/btrfs_tree.h:1103:2: error: unknown type name 'u8'
     u8 tree_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1104:2: error: unknown type name 'u8'
     u8 chunk_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1105:2: error: unknown type name 'u8'
     u8 extent_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1106:2: error: unknown type name 'u8'
     u8 fs_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1107:2: error: unknown type name 'u8'
     u8 dev_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1108:2: error: unknown type name 'u8'
     u8 csum_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1110:2: error: unknown type name 'u8'
     u8 unused_8[10];
     ^~
   ./usr/include/linux/btrfs_tree.h:1126:2: error: unknown type name 'u8'
     u8 csum[BTRFS_CSUM_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1128:2: error: unknown type name 'u8'
     u8 fsid[BTRFS_FSID_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1155:2: error: unknown type name 'u8'
     u8 root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1156:2: error: unknown type name 'u8'
     u8 chunk_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1157:2: error: unknown type name 'u8'
     u8 log_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1166:2: error: unknown type name 'u8'
     u8 metadata_uuid[BTRFS_FSID_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1170:2: error: unknown type name 'u8'
     u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1261:2: error: unknown type name 'u8'
     u8 csum[BTRFS_CSUM_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1262:2: error: unknown type name 'u8'
     u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
     ^~
   ./usr/include/linux/btrfs_tree.h:1267:2: error: unknown type name 'u8'
     u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1271:2: error: unknown type name 'u8'
     u8 level;
     ^~
--
   In file included from ./usr/include/linux/btrfs.h:24:0,
                    from <command-line>:32:
>> ./usr/include/linux/btrfs_tree.h:1103:2: error: unknown type name 'u8'
     u8 tree_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1104:2: error: unknown type name 'u8'
     u8 chunk_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1105:2: error: unknown type name 'u8'
     u8 extent_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1106:2: error: unknown type name 'u8'
     u8 fs_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1107:2: error: unknown type name 'u8'
     u8 dev_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1108:2: error: unknown type name 'u8'
     u8 csum_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1110:2: error: unknown type name 'u8'
     u8 unused_8[10];
     ^~
   ./usr/include/linux/btrfs_tree.h:1126:2: error: unknown type name 'u8'
     u8 csum[BTRFS_CSUM_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1128:2: error: unknown type name 'u8'
     u8 fsid[BTRFS_FSID_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1155:2: error: unknown type name 'u8'
     u8 root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1156:2: error: unknown type name 'u8'
     u8 chunk_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1157:2: error: unknown type name 'u8'
     u8 log_root_level;
     ^~
   ./usr/include/linux/btrfs_tree.h:1166:2: error: unknown type name 'u8'
     u8 metadata_uuid[BTRFS_FSID_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1170:2: error: unknown type name 'u8'
     u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1261:2: error: unknown type name 'u8'
     u8 csum[BTRFS_CSUM_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1262:2: error: unknown type name 'u8'
     u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
     ^~
   ./usr/include/linux/btrfs_tree.h:1267:2: error: unknown type name 'u8'
     u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
     ^~
   ./usr/include/linux/btrfs_tree.h:1271:2: error: unknown type name 'u8'
     u8 level;
     ^~

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Qu Wenruo
Quoted 11 lines · Qu Wenruo

These structures all are on-disk format. Move them to btrfs_tree.h

This allows us to sync the header to different projects, who need to read btrfs filesystem, like U-boot, grub.

With this modification, all on-disk format is definite in btrfs_tree.h, and can be easily synced to other projects.

This move includes:
- btrfs magic
It's a surprise that it's not even definied in btrfs_tree.h

There was no need for it so far, blkid has its own definition and f_type in stat provides the raw bytes. I don't find it surprising :)

Quoted 56 lines

- tree block max level
Move it before btrfs_header definition.

- tree block backref revision
- btrfs_header structure
- btrfs_root_backup structure
- btrfs_super_block structure
- BTRFS_FEATURE_* flags
- BTRFS_(FSID|UUID|LABEL)_SIZE macros
- BTRFS_MAX_METADATA_BLOCKSIZE macro
- BTRFS_NAME_LEN macro

- btrfs_item structure
- btrfs_leaf structure
- btrfs_key_ptr structure
- btrfs_node structure

- btrfs_dev_stat_values
Since on-disk format btrfs_dev_stats_item needs it.

- BTRFS_INODE_* flags
- BTRFS_QGROUP_LIMIT_* flags

---
Changelog:
v2:
- Add the reason why we move the code

v3:
- Move more flags/enum shared with ioctl to btrfs_btree.h This makes ioctl header to rely on btree_btree.h.
But this makes btrfs_tree.h completely self-consistent. This problem is mostly exposed when syncing the header to btrfs-progs.

---
 fs/btrfs/ctree.h                | 246 ------------------------
 include/uapi/linux/btrfs.h      |  74 +------
 include/uapi/linux/btrfs_tree.h | 329 +++++++++++++++++++++++++++++++-
 3 files changed, 327 insertions(+), 322 deletions(-)
fs/btrfs/ctree.h +0 -2
index 8aa7b9dac405..4d787d749315 100644
@@ -49,8 +49,6 @@ extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
 struct btrfs_ordered_sum;
 struct btrfs_ref;
 
-#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
-
 /*
  * Maximum number of mirrors that can be available for all profiles counting
  * the target device of dev-replace as one. During an active device replace
@@ -62,22 +60,8 @@ struct btrfs_ref;
  */
 #define BTRFS_MAX_MIRRORS (4 + 1)

fs/btrfs/ctree.h struct btrfs_ref; · line 73

Quoted 10 lines
fs/btrfs/ctree.h +0 -7
 
-#define BTRFS_MAX_LEVEL 8
-
 #define BTRFS_OLDEST_GENERATION	0ULL
 
-/*
- * the max metadata block size.  This limit is somewhat artificial,
- * but the memmove costs go through the roof for larger blocks.
- */
-#define BTRFS_MAX_METADATA_BLOCKSIZE 65536

So lots of comments and defines get moved, please take the opportunity to actually unify the formatting to the current preferred style.

#3 lore raw
Quoted 9 lines · David Sterba
Quoted 8 lines · Qu Wenruo

These structures all are on-disk format. Move them to btrfs_tree.h

This allows us to sync the header to different projects, who need to read btrfs filesystem, like U-boot, grub.

With this modification, all on-disk format is definite in btrfs_tree.h, and can be easily synced to other projects.

Quoted 6 lines
Quoted 3 lines

This move includes:
- btrfs magic
It's a surprise that it's not even definied in btrfs_tree.h

There was no need for it so far, blkid has its own definition and f_type in stat provides the raw bytes. I don't find it surprising :)

Since magic number is part of the super block definition, IMHO it should be included for btrfs on-disk format.

BTW, for btrfs_tree.h, it should contain:
- All on-disk structures (Check)
- All special flags used in on-disk structures
Like the magic in this patch, and compression algo flags are still missing.

Quoted 62 lines
Quoted 62 lines

- tree block max level
Move it before btrfs_header definition.

- tree block backref revision
- btrfs_header structure
- btrfs_root_backup structure
- btrfs_super_block structure
- BTRFS_FEATURE_* flags
- BTRFS_(FSID|UUID|LABEL)_SIZE macros
- BTRFS_MAX_METADATA_BLOCKSIZE macro
- BTRFS_NAME_LEN macro

- btrfs_item structure
- btrfs_leaf structure
- btrfs_key_ptr structure
- btrfs_node structure

- btrfs_dev_stat_values
Since on-disk format btrfs_dev_stats_item needs it.

- BTRFS_INODE_* flags
- BTRFS_QGROUP_LIMIT_* flags

---
Changelog:
v2:
- Add the reason why we move the code

v3:
- Move more flags/enum shared with ioctl to btrfs_btree.h This makes ioctl header to rely on btree_btree.h.
But this makes btrfs_tree.h completely self-consistent. This problem is mostly exposed when syncing the header to btrfs-progs.

---
 fs/btrfs/ctree.h                | 246 ------------------------
 include/uapi/linux/btrfs.h      |  74 +------
 include/uapi/linux/btrfs_tree.h | 329 +++++++++++++++++++++++++++++++-
 3 files changed, 327 insertions(+), 322 deletions(-)
fs/btrfs/ctree.h +0 -4
index 8aa7b9dac405..4d787d749315 100644
@@ -49,8 +49,6 @@ extern struct kmem_cache *btrfs_free_space_bitmap_cachep;
 struct btrfs_ordered_sum;
 struct btrfs_ref;
 
-#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
-
 /*
  * Maximum number of mirrors that can be available for all profiles counting
  * the target device of dev-replace as one. During an active device replace
@@ -62,22 +60,8 @@ struct btrfs_ref;
  */
 #define BTRFS_MAX_MIRRORS (4 + 1)
 
-#define BTRFS_MAX_LEVEL 8
-
 #define BTRFS_OLDEST_GENERATION	0ULL
 
Quoted 9 lines

fs/btrfs/ctree.h struct btrfs_ref; · line 73

Quoted 5 lines
fs/btrfs/ctree.h +0 -5
-/*
- * the max metadata block size.  This limit is somewhat artificial,
- * but the memmove costs go through the roof for larger blocks.
- */
-#define BTRFS_MAX_METADATA_BLOCKSIZE 65536

So lots of comments and defines get moved, please take the opportunity to actually unify the formatting to the current preferred style.

Sure, and I'll also update all the existing comments to the current style in next version.

Thanks,
Qu