btrfs: Fix stack smash with node size > 4K
[syslinux.git] / core / fs / btrfs / btrfs.h
blobc39490a9f48f165846587b961b15729ef31f32ae
1 #ifndef _BTRFS_H_
2 #define _BTRFS_H_
4 #include <stdint.h>
5 #include <zconf.h>
7 typedef uint8_t u8;
8 typedef uint16_t u16;
9 typedef uint32_t u32;
10 typedef uint64_t u64;
11 /* type that store on disk, but it is same as cpu type for i386 arch */
12 typedef u16 __le16;
13 typedef u32 __le32;
14 typedef u64 __le64;
16 #include "crc32c.h"
17 #define btrfs_crc32c crc32c_le
19 #define BTRFS_SUPER_INFO_OFFSET (64 * 1024)
20 #define BTRFS_SUPER_INFO_SIZE 4096
21 #define BTRFS_MAX_LEAF_SIZE 4096
22 #define BTRFS_BLOCK_SHIFT 12
23 #define BTRFS_BLOCK_SIZE (1 << BTRFS_BLOCK_SHIFT)
25 #define BTRFS_SUPER_MIRROR_MAX 3
26 #define BTRFS_SUPER_MIRROR_SHIFT 12
27 #define BTRFS_CSUM_SIZE 32
28 #define BTRFS_FSID_SIZE 16
29 #define BTRFS_LABEL_SIZE 256
30 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
31 #define BTRFS_UUID_SIZE 16
33 #define BTRFS_MAGIC "_BHRfS_M"
35 #define BTRFS_SUPER_FLAG_METADUMP (1ULL << 33)
37 #define BTRFS_DEV_ITEM_KEY 216
38 #define BTRFS_CHUNK_ITEM_KEY 228
39 #define BTRFS_ROOT_REF_KEY 156
40 #define BTRFS_ROOT_ITEM_KEY 132
41 #define BTRFS_EXTENT_DATA_KEY 108
42 #define BTRFS_DIR_ITEM_KEY 84
43 #define BTRFS_INODE_ITEM_KEY 1
45 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
46 #define BTRFS_FS_TREE_OBJECTID 5ULL
48 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
50 #define BTRFS_FILE_EXTENT_INLINE 0
51 #define BTRFS_FILE_EXTENT_REG 1
52 #define BTRFS_FILE_EXTENT_PREALLOC 2
54 #define BTRFS_MAX_LEVEL 8
55 #define BTRFS_MAX_CHUNK_ENTRIES 256
57 #define BTRFS_FT_REG_FILE 1
58 #define BTRFS_FT_DIR 2
59 #define BTRFS_FT_SYMLINK 7
61 #define ROOT_DIR_WORD 0x002f
63 struct btrfs_dev_item {
64 __le64 devid;
65 __le64 total_bytes;
66 __le64 bytes_used;
67 __le32 io_align;
68 __le32 io_width;
69 __le32 sector_size;
70 __le64 type;
71 __le64 generation;
72 __le64 start_offset;
73 __le32 dev_group;
74 u8 seek_speed;
75 u8 bandwidth;
76 u8 uuid[BTRFS_UUID_SIZE];
77 u8 fsid[BTRFS_UUID_SIZE];
78 } __attribute__ ((__packed__));
80 struct btrfs_super_block {
81 u8 csum[BTRFS_CSUM_SIZE];
82 /* the first 3 fields must match struct btrfs_header */
83 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
84 __le64 bytenr; /* this block number */
85 __le64 flags;
87 /* allowed to be different from the btrfs_header from here own down */
88 __le64 magic;
89 __le64 generation;
90 __le64 root;
91 __le64 chunk_root;
92 __le64 log_root;
94 /* this will help find the new super based on the log root */
95 __le64 log_root_transid;
96 __le64 total_bytes;
97 __le64 bytes_used;
98 __le64 root_dir_objectid;
99 __le64 num_devices;
100 __le32 sectorsize;
101 __le32 nodesize;
102 __le32 leafsize;
103 __le32 stripesize;
104 __le32 sys_chunk_array_size;
105 __le64 chunk_root_generation;
106 __le64 compat_flags;
107 __le64 compat_ro_flags;
108 __le64 incompat_flags;
109 __le16 csum_type;
110 u8 root_level;
111 u8 chunk_root_level;
112 u8 log_root_level;
113 struct btrfs_dev_item dev_item;
115 char label[BTRFS_LABEL_SIZE];
117 /* future expansion */
118 __le64 reserved[32];
119 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
120 } __attribute__ ((__packed__));
122 struct btrfs_disk_key {
123 __le64 objectid;
124 u8 type;
125 __le64 offset;
126 } __attribute__ ((__packed__));
128 struct btrfs_stripe {
129 __le64 devid;
130 __le64 offset;
131 u8 dev_uuid[BTRFS_UUID_SIZE];
132 } __attribute__ ((__packed__));
134 struct btrfs_chunk {
135 __le64 length;
136 __le64 owner;
137 __le64 stripe_len;
138 __le64 type;
139 __le32 io_align;
140 __le32 io_width;
141 __le32 sector_size;
142 __le16 num_stripes;
143 __le16 sub_stripes;
144 struct btrfs_stripe stripe;
145 } __attribute__ ((__packed__));
147 struct btrfs_header {
148 /* these first four must match the super block */
149 u8 csum[BTRFS_CSUM_SIZE];
150 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
151 __le64 bytenr; /* which block this node is supposed to live in */
152 __le64 flags;
154 /* allowed to be different from the super from here on down */
155 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
156 __le64 generation;
157 __le64 owner;
158 __le32 nritems;
159 u8 level;
160 } __attribute__ ((__packed__));
162 struct btrfs_item {
163 struct btrfs_disk_key key;
164 __le32 offset;
165 __le32 size;
166 } __attribute__ ((__packed__));
168 struct btrfs_leaf {
169 struct btrfs_header header;
170 struct btrfs_item items[];
171 } __attribute__ ((__packed__));
173 struct btrfs_key_ptr {
174 struct btrfs_disk_key key;
175 __le64 blockptr;
176 __le64 generation;
177 } __attribute__ ((__packed__));
179 struct btrfs_node {
180 struct btrfs_header header;
181 struct btrfs_key_ptr ptrs[];
182 } __attribute__ ((__packed__));
184 /* remember how we get to a node/leaf */
185 struct btrfs_path {
186 u64 offsets[BTRFS_MAX_LEVEL];
187 int itemsnr[BTRFS_MAX_LEVEL];
188 int slots[BTRFS_MAX_LEVEL];
189 /* remember last slot's item and data */
190 struct btrfs_item item;
191 u8 data[BTRFS_MAX_LEAF_SIZE];
194 /* store logical offset to physical offset mapping */
195 struct btrfs_chunk_map_item {
196 u64 logical;
197 u64 length;
198 u64 devid;
199 u64 physical;
202 struct btrfs_chunk_map {
203 struct btrfs_chunk_map_item *map;
204 u32 map_length;
205 u32 cur_length;
208 struct btrfs_timespec {
209 __le64 sec;
210 __le32 nsec;
211 } __attribute__ ((__packed__));
213 struct btrfs_inode_item {
214 /* nfs style generation number */
215 __le64 generation;
216 /* transid that last touched this inode */
217 __le64 transid;
218 __le64 size;
219 __le64 nbytes;
220 __le64 block_group;
221 __le32 nlink;
222 __le32 uid;
223 __le32 gid;
224 __le32 mode;
225 __le64 rdev;
226 __le64 flags;
228 /* modification sequence number for NFS */
229 __le64 sequence;
232 * a little future expansion, for more than this we can
233 * just grow the inode item and version it
235 __le64 reserved[4];
236 struct btrfs_timespec atime;
237 struct btrfs_timespec ctime;
238 struct btrfs_timespec mtime;
239 struct btrfs_timespec otime;
240 } __attribute__ ((__packed__));
242 struct btrfs_root_item {
243 struct btrfs_inode_item inode;
244 __le64 generation;
245 __le64 root_dirid;
246 __le64 bytenr;
247 __le64 byte_limit;
248 __le64 bytes_used;
249 __le64 last_snapshot;
250 __le64 flags;
251 __le32 refs;
252 struct btrfs_disk_key drop_progress;
253 u8 drop_level;
254 u8 level;
255 } __attribute__ ((__packed__));
257 struct btrfs_dir_item {
258 struct btrfs_disk_key location;
259 __le64 transid;
260 __le16 data_len;
261 __le16 name_len;
262 u8 type;
263 } __attribute__ ((__packed__));
265 struct btrfs_file_extent_item {
266 __le64 generation;
267 __le64 ram_bytes;
268 u8 compression;
269 u8 encryption;
270 __le16 other_encoding; /* spare for later use */
271 u8 type;
272 __le64 disk_bytenr;
273 __le64 disk_num_bytes;
274 __le64 offset;
275 __le64 num_bytes;
276 } __attribute__ ((__packed__));
278 struct btrfs_root_ref {
279 __le64 dirid;
280 __le64 sequence;
281 __le16 name_len;
282 } __attribute__ ((__packed__));
285 * btrfs private inode information
287 struct btrfs_pvt_inode {
288 uint64_t offset;
291 #define PVT(i) ((struct btrfs_pvt_inode *)((i)->pvt))
293 #endif