1 | #ifndef _BTRFS_H_ |
---|
2 | #define _BTRFS_H_ |
---|
3 | |
---|
4 | #include <asm/types.h> |
---|
5 | #include <linux/ioctl.h> |
---|
6 | |
---|
7 | #define BTRFS_SUPER_MAGIC 0x9123683E |
---|
8 | #define BTRFS_SUPER_INFO_OFFSET (64 * 1024) |
---|
9 | #define BTRFS_SUPER_INFO_SIZE 4096 |
---|
10 | #define BTRFS_MAGIC "_BHRfS_M" |
---|
11 | #define BTRFS_MAGIC_L 8 |
---|
12 | #define BTRFS_CSUM_SIZE 32 |
---|
13 | #define BTRFS_FSID_SIZE 16 |
---|
14 | #define BTRFS_UUID_SIZE 16 |
---|
15 | |
---|
16 | /* Fixed areas reserved for the boot loader */ |
---|
17 | #define BTRFS_BOOT_AREA_A_OFFSET 0 |
---|
18 | #define BTRFS_BOOT_AREA_A_SIZE BTRFS_SUPER_INFO_OFFSET |
---|
19 | #define BTRFS_BOOT_AREA_B_OFFSET (256 * 1024) |
---|
20 | #define BTRFS_BOOT_AREA_B_SIZE ((1024-256) * 1024) |
---|
21 | |
---|
22 | typedef __u64 u64; |
---|
23 | typedef __u32 u32; |
---|
24 | typedef __u16 u16; |
---|
25 | typedef __u8 u8; |
---|
26 | typedef u64 __le64; |
---|
27 | typedef u16 __le16; |
---|
28 | |
---|
29 | #define BTRFS_ROOT_BACKREF_KEY 144 |
---|
30 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL |
---|
31 | #define BTRFS_DIR_ITEM_KEY 84 |
---|
32 | |
---|
33 | /* |
---|
34 | * * this is used for both forward and backward root refs |
---|
35 | * */ |
---|
36 | struct btrfs_root_ref { |
---|
37 | __le64 dirid; |
---|
38 | __le64 sequence; |
---|
39 | __le16 name_len; |
---|
40 | } __attribute__ ((__packed__)); |
---|
41 | |
---|
42 | struct btrfs_disk_key { |
---|
43 | __le64 objectid; |
---|
44 | u8 type; |
---|
45 | __le64 offset; |
---|
46 | } __attribute__ ((__packed__)); |
---|
47 | |
---|
48 | struct btrfs_dir_item { |
---|
49 | struct btrfs_disk_key location; |
---|
50 | __le64 transid; |
---|
51 | __le16 data_len; |
---|
52 | __le16 name_len; |
---|
53 | u8 type; |
---|
54 | } __attribute__ ((__packed__)); |
---|
55 | |
---|
56 | struct btrfs_super_block { |
---|
57 | uint8_t csum[32]; |
---|
58 | uint8_t fsid[16]; |
---|
59 | uint64_t bytenr; |
---|
60 | uint64_t flags; |
---|
61 | uint8_t magic[8]; |
---|
62 | uint64_t generation; |
---|
63 | uint64_t root; |
---|
64 | uint64_t chunk_root; |
---|
65 | uint64_t log_root; |
---|
66 | uint64_t log_root_transid; |
---|
67 | uint64_t total_bytes; |
---|
68 | uint64_t bytes_used; |
---|
69 | uint64_t root_dir_objectid; |
---|
70 | uint64_t num_devices; |
---|
71 | uint32_t sectorsize; |
---|
72 | uint32_t nodesize; |
---|
73 | uint32_t leafsize; |
---|
74 | uint32_t stripesize; |
---|
75 | uint32_t sys_chunk_array_size; |
---|
76 | uint64_t chunk_root_generation; |
---|
77 | uint64_t compat_flags; |
---|
78 | uint64_t compat_ro_flags; |
---|
79 | uint64_t incompat_flags; |
---|
80 | uint16_t csum_type; |
---|
81 | uint8_t root_level; |
---|
82 | uint8_t chunk_root_level; |
---|
83 | uint8_t log_root_level; |
---|
84 | struct btrfs_dev_item { |
---|
85 | uint64_t devid; |
---|
86 | uint64_t total_bytes; |
---|
87 | uint64_t bytes_used; |
---|
88 | uint32_t io_align; |
---|
89 | uint32_t io_width; |
---|
90 | uint32_t sector_size; |
---|
91 | uint64_t type; |
---|
92 | uint64_t generation; |
---|
93 | uint64_t start_offset; |
---|
94 | uint32_t dev_group; |
---|
95 | uint8_t seek_speed; |
---|
96 | uint8_t bandwidth; |
---|
97 | uint8_t uuid[16]; |
---|
98 | uint8_t fsid[16]; |
---|
99 | } __attribute__ ((__packed__)) dev_item; |
---|
100 | uint8_t label[256]; |
---|
101 | } __attribute__ ((__packed__)); |
---|
102 | |
---|
103 | #define BTRFS_IOCTL_MAGIC 0x94 |
---|
104 | #define BTRFS_VOL_NAME_MAX 255 |
---|
105 | #define BTRFS_PATH_NAME_MAX 4087 |
---|
106 | |
---|
107 | struct btrfs_ioctl_vol_args { |
---|
108 | __s64 fd; |
---|
109 | char name[BTRFS_PATH_NAME_MAX + 1]; |
---|
110 | }; |
---|
111 | |
---|
112 | struct btrfs_ioctl_search_key { |
---|
113 | /* which root are we searching. 0 is the tree of tree roots */ |
---|
114 | __u64 tree_id; |
---|
115 | |
---|
116 | /* keys returned will be >= min and <= max */ |
---|
117 | __u64 min_objectid; |
---|
118 | __u64 max_objectid; |
---|
119 | |
---|
120 | /* keys returned will be >= min and <= max */ |
---|
121 | __u64 min_offset; |
---|
122 | __u64 max_offset; |
---|
123 | |
---|
124 | /* max and min transids to search for */ |
---|
125 | __u64 min_transid; |
---|
126 | __u64 max_transid; |
---|
127 | |
---|
128 | /* keys returned will be >= min and <= max */ |
---|
129 | __u32 min_type; |
---|
130 | __u32 max_type; |
---|
131 | |
---|
132 | /* |
---|
133 | * how many items did userland ask for, and how many are we |
---|
134 | * returning |
---|
135 | */ |
---|
136 | __u32 nr_items; |
---|
137 | |
---|
138 | /* align to 64 bits */ |
---|
139 | __u32 unused; |
---|
140 | |
---|
141 | /* some extra for later */ |
---|
142 | __u64 unused1; |
---|
143 | __u64 unused2; |
---|
144 | __u64 unused3; |
---|
145 | __u64 unused4; |
---|
146 | }; |
---|
147 | |
---|
148 | struct btrfs_ioctl_search_header { |
---|
149 | __u64 transid; |
---|
150 | __u64 objectid; |
---|
151 | __u64 offset; |
---|
152 | __u32 type; |
---|
153 | __u32 len; |
---|
154 | } __attribute__((may_alias)); |
---|
155 | |
---|
156 | #define BTRFS_DEVICE_PATH_NAME_MAX 1024 |
---|
157 | struct btrfs_ioctl_dev_info_args { |
---|
158 | __u64 devid; /* in/out */ |
---|
159 | __u8 uuid[BTRFS_UUID_SIZE]; /* in/out */ |
---|
160 | __u64 bytes_used; /* out */ |
---|
161 | __u64 total_bytes; /* out */ |
---|
162 | __u64 unused[379]; /* pad to 4k */ |
---|
163 | __u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */ |
---|
164 | }; |
---|
165 | |
---|
166 | struct btrfs_ioctl_fs_info_args { |
---|
167 | __u64 max_id; /* out */ |
---|
168 | __u64 num_devices; /* out */ |
---|
169 | __u8 fsid[BTRFS_FSID_SIZE]; /* out */ |
---|
170 | __u64 reserved[124]; /* pad to 1k */ |
---|
171 | }; |
---|
172 | |
---|
173 | #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) |
---|
174 | /* |
---|
175 | * the buf is an array of search headers where |
---|
176 | * each header is followed by the actual item |
---|
177 | * the type field is expanded to 32 bits for alignment |
---|
178 | */ |
---|
179 | struct btrfs_ioctl_search_args { |
---|
180 | struct btrfs_ioctl_search_key key; |
---|
181 | char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; |
---|
182 | }; |
---|
183 | |
---|
184 | #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ |
---|
185 | struct btrfs_ioctl_search_args) |
---|
186 | #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \ |
---|
187 | struct btrfs_ioctl_dev_info_args) |
---|
188 | #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \ |
---|
189 | struct btrfs_ioctl_fs_info_args) |
---|
190 | |
---|
191 | #endif |
---|