Commit | Line | Data |
---|---|---|
234b63a0 CM |
1 | #ifndef __BTRFS__ |
2 | #define __BTRFS__ | |
eb60ceac | 3 | |
ed2ff2cb | 4 | #include "list.h" |
e2fa7227 | 5 | #include "kerncompat.h" |
ed2ff2cb | 6 | |
e089f05c CM |
7 | struct btrfs_trans_handle; |
8 | ||
3768f368 | 9 | #define BTRFS_MAGIC "_BtRfS_M" |
eb60ceac | 10 | |
3768f368 CM |
11 | #define BTRFS_ROOT_TREE_OBJECTID 1 |
12 | #define BTRFS_EXTENT_TREE_OBJECTID 2 | |
13 | #define BTRFS_FS_TREE_OBJECTID 3 | |
14 | ||
fec577fb CM |
15 | /* |
16 | * the key defines the order in the tree, and so it also defines (optimal) | |
17 | * block layout. objectid corresonds to the inode number. The flags | |
18 | * tells us things about the object, and is a kind of stream selector. | |
19 | * so for a given inode, keys with flags of 1 might refer to the inode | |
20 | * data, flags of 2 may point to file data in the btree and flags == 3 | |
21 | * may point to extents. | |
22 | * | |
23 | * offset is the starting byte offset for this key in the stream. | |
e2fa7227 CM |
24 | * |
25 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always | |
26 | * in cpu native order. Otherwise they are identical and their sizes | |
27 | * should be the same (ie both packed) | |
fec577fb | 28 | */ |
e2fa7227 CM |
29 | struct btrfs_disk_key { |
30 | __le64 objectid; | |
a1516c89 | 31 | __le32 flags; |
a8a2ee0c | 32 | __le64 offset; |
e2fa7227 CM |
33 | } __attribute__ ((__packed__)); |
34 | ||
35 | struct btrfs_key { | |
eb60ceac | 36 | u64 objectid; |
a1516c89 | 37 | u32 flags; |
a8a2ee0c | 38 | u64 offset; |
eb60ceac CM |
39 | } __attribute__ ((__packed__)); |
40 | ||
fec577fb CM |
41 | /* |
42 | * every tree block (leaf or node) starts with this header. | |
43 | */ | |
bb492bb0 | 44 | struct btrfs_header { |
3768f368 | 45 | u8 fsid[16]; /* FS specific uuid */ |
bb492bb0 CM |
46 | __le64 blocknr; /* which block this node is supposed to live in */ |
47 | __le64 parentid; /* objectid of the tree root */ | |
48 | __le32 csum; | |
49 | __le32 ham; | |
50 | __le16 nritems; | |
51 | __le16 flags; | |
fec577fb | 52 | /* generation flags to be added */ |
eb60ceac CM |
53 | } __attribute__ ((__packed__)); |
54 | ||
234b63a0 | 55 | #define BTRFS_MAX_LEVEL 8 |
123abc88 CM |
56 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ |
57 | sizeof(struct btrfs_header)) / \ | |
58 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) | |
59 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) | |
60 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) | |
eb60ceac | 61 | |
234b63a0 | 62 | struct btrfs_buffer; |
fec577fb CM |
63 | /* |
64 | * the super block basically lists the main trees of the FS | |
65 | * it currently lacks any block count etc etc | |
66 | */ | |
234b63a0 | 67 | struct btrfs_super_block { |
3768f368 CM |
68 | u8 fsid[16]; /* FS specific uuid */ |
69 | __le64 blocknr; /* this block number */ | |
70 | __le32 csum; | |
71 | __le64 magic; | |
123abc88 | 72 | __le32 blocksize; |
3768f368 CM |
73 | __le64 generation; |
74 | __le64 root; | |
75 | __le64 total_blocks; | |
76 | __le64 blocks_used; | |
cfaa7295 CM |
77 | } __attribute__ ((__packed__)); |
78 | ||
fec577fb | 79 | /* |
62e2749e | 80 | * A leaf is full of items. offset and size tell us where to find |
fec577fb CM |
81 | * the item in the leaf (relative to the start of the data area) |
82 | */ | |
0783fcfc | 83 | struct btrfs_item { |
e2fa7227 | 84 | struct btrfs_disk_key key; |
123abc88 | 85 | __le32 offset; |
0783fcfc | 86 | __le16 size; |
eb60ceac CM |
87 | } __attribute__ ((__packed__)); |
88 | ||
fec577fb CM |
89 | /* |
90 | * leaves have an item area and a data area: | |
91 | * [item0, item1....itemN] [free space] [dataN...data1, data0] | |
92 | * | |
93 | * The data is separate from the items to get the keys closer together | |
94 | * during searches. | |
95 | */ | |
234b63a0 | 96 | struct btrfs_leaf { |
bb492bb0 | 97 | struct btrfs_header header; |
123abc88 | 98 | struct btrfs_item items[]; |
eb60ceac CM |
99 | } __attribute__ ((__packed__)); |
100 | ||
fec577fb CM |
101 | /* |
102 | * all non-leaf blocks are nodes, they hold only keys and pointers to | |
103 | * other blocks | |
104 | */ | |
123abc88 CM |
105 | struct btrfs_key_ptr { |
106 | struct btrfs_disk_key key; | |
107 | __le64 blockptr; | |
108 | } __attribute__ ((__packed__)); | |
109 | ||
234b63a0 | 110 | struct btrfs_node { |
bb492bb0 | 111 | struct btrfs_header header; |
123abc88 | 112 | struct btrfs_key_ptr ptrs[]; |
eb60ceac CM |
113 | } __attribute__ ((__packed__)); |
114 | ||
fec577fb | 115 | /* |
234b63a0 CM |
116 | * btrfs_paths remember the path taken from the root down to the leaf. |
117 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | |
fec577fb CM |
118 | * to any other levels that are present. |
119 | * | |
120 | * The slots array records the index of the item or block pointer | |
121 | * used while walking the tree. | |
122 | */ | |
234b63a0 CM |
123 | struct btrfs_path { |
124 | struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL]; | |
125 | int slots[BTRFS_MAX_LEVEL]; | |
eb60ceac | 126 | }; |
5de08d7d | 127 | |
62e2749e CM |
128 | /* |
129 | * items in the extent btree are used to record the objectid of the | |
130 | * owner of the block and the number of references | |
131 | */ | |
132 | struct btrfs_extent_item { | |
133 | __le32 refs; | |
134 | __le64 owner; | |
135 | } __attribute__ ((__packed__)); | |
136 | ||
1e1d2701 CM |
137 | struct btrfs_inode_timespec { |
138 | __le32 sec; | |
139 | __le32 nsec; | |
140 | } __attribute__ ((__packed__)); | |
141 | ||
142 | /* | |
143 | * there is no padding here on purpose. If you want to extent the inode, | |
144 | * make a new item type | |
145 | */ | |
146 | struct btrfs_inode_item { | |
147 | __le64 generation; | |
148 | __le64 size; | |
149 | __le64 nblocks; | |
150 | __le32 nlink; | |
151 | __le32 uid; | |
152 | __le32 gid; | |
153 | __le32 mode; | |
154 | __le32 rdev; | |
155 | __le16 flags; | |
156 | __le16 compat_flags; | |
157 | struct btrfs_inode_timespec atime; | |
158 | struct btrfs_inode_timespec ctime; | |
159 | struct btrfs_inode_timespec mtime; | |
160 | struct btrfs_inode_timespec otime; | |
161 | } __attribute__ ((__packed__)); | |
162 | ||
163 | /* inline data is just a blob of bytes */ | |
164 | struct btrfs_inline_data_item { | |
165 | u8 data; | |
166 | } __attribute__ ((__packed__)); | |
167 | ||
62e2749e CM |
168 | struct btrfs_dir_item { |
169 | __le64 objectid; | |
170 | __le16 flags; | |
a8a2ee0c | 171 | __le16 name_len; |
62e2749e CM |
172 | u8 type; |
173 | } __attribute__ ((__packed__)); | |
174 | ||
175 | struct btrfs_root_item { | |
176 | __le64 blocknr; | |
177 | __le32 flags; | |
178 | __le64 block_limit; | |
179 | __le64 blocks_used; | |
180 | __le32 refs; | |
181 | }; | |
182 | ||
183 | /* | |
184 | * in ram representation of the tree. extent_root is used for all allocations | |
185 | * and for the extent tree extent_root root. current_insert is used | |
186 | * only for the extent tree. | |
187 | */ | |
188 | struct btrfs_root { | |
189 | struct btrfs_buffer *node; | |
190 | struct btrfs_buffer *commit_root; | |
191 | struct btrfs_root *extent_root; | |
192 | struct btrfs_root *tree_root; | |
193 | struct btrfs_key current_insert; | |
194 | struct btrfs_key last_insert; | |
195 | int fp; | |
196 | struct radix_tree_root cache_radix; | |
197 | struct radix_tree_root pinned_radix; | |
198 | struct list_head trans; | |
199 | struct list_head cache; | |
200 | int cache_size; | |
201 | int ref_cows; | |
202 | struct btrfs_root_item root_item; | |
203 | struct btrfs_key root_key; | |
204 | u32 blocksize; | |
e089f05c | 205 | struct btrfs_trans_handle *running_transaction; |
62e2749e CM |
206 | }; |
207 | ||
62e2749e CM |
208 | /* the lower bits in the key flags defines the item type */ |
209 | #define BTRFS_KEY_TYPE_MAX 256 | |
210 | #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1) | |
1e1d2701 CM |
211 | |
212 | /* | |
213 | * inode items have the data typically returned from stat and store other | |
214 | * info about object characteristics. There is one for every file and dir in | |
215 | * the FS | |
216 | */ | |
62e2749e | 217 | #define BTRFS_INODE_ITEM_KEY 1 |
1e1d2701 CM |
218 | |
219 | /* | |
220 | * dir items are the name -> inode pointers in a directory. There is one | |
221 | * for every name in a directory. | |
222 | */ | |
62e2749e | 223 | #define BTRFS_DIR_ITEM_KEY 2 |
1e1d2701 CM |
224 | /* |
225 | * inline data is file data that fits in the btree. | |
226 | */ | |
227 | #define BTRFS_INLINE_DATA_KEY 3 | |
228 | /* | |
229 | * extent data is for data that can't fit in the btree. It points to | |
230 | * a (hopefully) huge chunk of disk | |
231 | */ | |
232 | #define BTRFS_EXTENT_DATA_KEY 4 | |
233 | /* | |
234 | * root items point to tree roots. There are typically in the root | |
235 | * tree used by the super block to find all the other trees | |
236 | */ | |
237 | #define BTRFS_ROOT_ITEM_KEY 5 | |
238 | /* | |
239 | * extent items are in the extent map tree. These record which blocks | |
240 | * are used, and how many references there are to each block | |
241 | */ | |
242 | #define BTRFS_EXTENT_ITEM_KEY 6 | |
243 | /* | |
244 | * string items are for debugging. They just store a short string of | |
245 | * data in the FS | |
246 | */ | |
247 | #define BTRFS_STRING_ITEM_KEY 7 | |
248 | ||
249 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) | |
250 | { | |
251 | return le64_to_cpu(i->generation); | |
252 | } | |
253 | ||
254 | static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i, | |
255 | u64 val) | |
256 | { | |
257 | i->generation = cpu_to_le64(val); | |
258 | } | |
259 | ||
260 | static inline u64 btrfs_inode_size(struct btrfs_inode_item *i) | |
261 | { | |
262 | return le64_to_cpu(i->size); | |
263 | } | |
264 | ||
265 | static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val) | |
266 | { | |
267 | i->size = cpu_to_le64(val); | |
268 | } | |
269 | ||
270 | static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i) | |
271 | { | |
272 | return le64_to_cpu(i->nblocks); | |
273 | } | |
274 | ||
275 | static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val) | |
276 | { | |
277 | i->nblocks = cpu_to_le64(val); | |
278 | } | |
279 | ||
280 | static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i) | |
281 | { | |
282 | return le32_to_cpu(i->nlink); | |
283 | } | |
284 | ||
285 | static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val) | |
286 | { | |
287 | i->nlink = cpu_to_le32(val); | |
288 | } | |
289 | ||
290 | static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i) | |
291 | { | |
292 | return le32_to_cpu(i->uid); | |
293 | } | |
294 | ||
295 | static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val) | |
296 | { | |
297 | i->uid = cpu_to_le32(val); | |
298 | } | |
299 | ||
300 | static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i) | |
301 | { | |
302 | return le32_to_cpu(i->gid); | |
303 | } | |
304 | ||
305 | static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val) | |
306 | { | |
307 | i->gid = cpu_to_le32(val); | |
308 | } | |
309 | ||
310 | static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i) | |
311 | { | |
312 | return le32_to_cpu(i->mode); | |
313 | } | |
314 | ||
315 | static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val) | |
316 | { | |
317 | i->mode = cpu_to_le32(val); | |
318 | } | |
319 | ||
320 | static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i) | |
321 | { | |
322 | return le32_to_cpu(i->rdev); | |
323 | } | |
324 | ||
325 | static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val) | |
326 | { | |
327 | i->rdev = cpu_to_le32(val); | |
328 | } | |
329 | ||
330 | static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i) | |
331 | { | |
332 | return le16_to_cpu(i->flags); | |
333 | } | |
334 | ||
335 | static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val) | |
336 | { | |
337 | i->flags = cpu_to_le16(val); | |
338 | } | |
339 | ||
340 | static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i) | |
341 | { | |
342 | return le16_to_cpu(i->compat_flags); | |
343 | } | |
344 | ||
345 | static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i, | |
346 | u16 val) | |
347 | { | |
348 | i->compat_flags = cpu_to_le16(val); | |
349 | } | |
350 | ||
62e2749e | 351 | |
234b63a0 | 352 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
cf27e1ee CM |
353 | { |
354 | return le64_to_cpu(ei->owner); | |
355 | } | |
356 | ||
234b63a0 | 357 | static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val) |
cf27e1ee CM |
358 | { |
359 | ei->owner = cpu_to_le64(val); | |
360 | } | |
361 | ||
234b63a0 | 362 | static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei) |
cf27e1ee CM |
363 | { |
364 | return le32_to_cpu(ei->refs); | |
365 | } | |
366 | ||
234b63a0 | 367 | static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) |
cf27e1ee CM |
368 | { |
369 | ei->refs = cpu_to_le32(val); | |
370 | } | |
371 | ||
234b63a0 | 372 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) |
1d4f8a0c | 373 | { |
123abc88 | 374 | return le64_to_cpu(n->ptrs[nr].blockptr); |
1d4f8a0c CM |
375 | } |
376 | ||
234b63a0 CM |
377 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, |
378 | u64 val) | |
1d4f8a0c | 379 | { |
123abc88 | 380 | n->ptrs[nr].blockptr = cpu_to_le64(val); |
1d4f8a0c CM |
381 | } |
382 | ||
123abc88 | 383 | static inline u32 btrfs_item_offset(struct btrfs_item *item) |
0783fcfc | 384 | { |
123abc88 | 385 | return le32_to_cpu(item->offset); |
0783fcfc CM |
386 | } |
387 | ||
123abc88 | 388 | static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val) |
0783fcfc | 389 | { |
123abc88 | 390 | item->offset = cpu_to_le32(val); |
0783fcfc CM |
391 | } |
392 | ||
123abc88 | 393 | static inline u32 btrfs_item_end(struct btrfs_item *item) |
0783fcfc | 394 | { |
123abc88 | 395 | return le32_to_cpu(item->offset) + le16_to_cpu(item->size); |
0783fcfc CM |
396 | } |
397 | ||
398 | static inline u16 btrfs_item_size(struct btrfs_item *item) | |
399 | { | |
400 | return le16_to_cpu(item->size); | |
401 | } | |
402 | ||
403 | static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val) | |
404 | { | |
405 | item->size = cpu_to_le16(val); | |
406 | } | |
407 | ||
1d4f6404 CM |
408 | static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d) |
409 | { | |
410 | return le64_to_cpu(d->objectid); | |
411 | } | |
412 | ||
413 | static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val) | |
414 | { | |
415 | d->objectid = cpu_to_le64(val); | |
416 | } | |
417 | ||
418 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) | |
419 | { | |
420 | return le16_to_cpu(d->flags); | |
421 | } | |
422 | ||
423 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) | |
424 | { | |
425 | d->flags = cpu_to_le16(val); | |
426 | } | |
427 | ||
428 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) | |
429 | { | |
430 | return d->type; | |
431 | } | |
432 | ||
433 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) | |
434 | { | |
435 | d->type = val; | |
436 | } | |
437 | ||
a8a2ee0c CM |
438 | static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d) |
439 | { | |
440 | return le16_to_cpu(d->name_len); | |
441 | } | |
442 | ||
443 | static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val) | |
1d4f6404 | 444 | { |
a8a2ee0c | 445 | d->name_len = cpu_to_le16(val); |
1d4f6404 CM |
446 | } |
447 | ||
e2fa7227 CM |
448 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
449 | struct btrfs_disk_key *disk) | |
450 | { | |
451 | cpu->offset = le64_to_cpu(disk->offset); | |
452 | cpu->flags = le32_to_cpu(disk->flags); | |
453 | cpu->objectid = le64_to_cpu(disk->objectid); | |
454 | } | |
455 | ||
456 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |
457 | struct btrfs_key *cpu) | |
458 | { | |
459 | disk->offset = cpu_to_le64(cpu->offset); | |
460 | disk->flags = cpu_to_le32(cpu->flags); | |
461 | disk->objectid = cpu_to_le64(cpu->objectid); | |
462 | } | |
463 | ||
62e2749e | 464 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
e2fa7227 CM |
465 | { |
466 | return le64_to_cpu(disk->objectid); | |
467 | } | |
468 | ||
62e2749e CM |
469 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
470 | u64 val) | |
e2fa7227 CM |
471 | { |
472 | disk->objectid = cpu_to_le64(val); | |
473 | } | |
474 | ||
62e2749e | 475 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
e2fa7227 CM |
476 | { |
477 | return le64_to_cpu(disk->offset); | |
478 | } | |
479 | ||
62e2749e CM |
480 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
481 | u64 val) | |
e2fa7227 CM |
482 | { |
483 | disk->offset = cpu_to_le64(val); | |
484 | } | |
485 | ||
62e2749e | 486 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
e2fa7227 CM |
487 | { |
488 | return le32_to_cpu(disk->flags); | |
489 | } | |
490 | ||
62e2749e CM |
491 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
492 | u32 val) | |
e2fa7227 CM |
493 | { |
494 | disk->flags = cpu_to_le32(val); | |
495 | } | |
496 | ||
62e2749e CM |
497 | static inline u32 btrfs_key_type(struct btrfs_key *key) |
498 | { | |
499 | return key->flags & BTRFS_KEY_TYPE_MASK; | |
500 | } | |
501 | ||
502 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) | |
503 | { | |
504 | return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK; | |
505 | } | |
506 | ||
507 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type) | |
508 | { | |
509 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | |
510 | key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | |
511 | } | |
512 | ||
513 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type) | |
514 | { | |
515 | u32 flags = btrfs_disk_key_flags(key); | |
516 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | |
517 | flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | |
518 | btrfs_set_disk_key_flags(key, flags); | |
519 | } | |
520 | ||
bb492bb0 | 521 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
7518a238 | 522 | { |
bb492bb0 | 523 | return le64_to_cpu(h->blocknr); |
7518a238 CM |
524 | } |
525 | ||
bb492bb0 | 526 | static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr) |
7518a238 | 527 | { |
bb492bb0 | 528 | h->blocknr = cpu_to_le64(blocknr); |
7518a238 CM |
529 | } |
530 | ||
bb492bb0 | 531 | static inline u64 btrfs_header_parentid(struct btrfs_header *h) |
7518a238 | 532 | { |
bb492bb0 | 533 | return le64_to_cpu(h->parentid); |
7518a238 CM |
534 | } |
535 | ||
bb492bb0 CM |
536 | static inline void btrfs_set_header_parentid(struct btrfs_header *h, |
537 | u64 parentid) | |
7518a238 | 538 | { |
bb492bb0 | 539 | h->parentid = cpu_to_le64(parentid); |
7518a238 CM |
540 | } |
541 | ||
bb492bb0 | 542 | static inline u16 btrfs_header_nritems(struct btrfs_header *h) |
7518a238 | 543 | { |
bb492bb0 | 544 | return le16_to_cpu(h->nritems); |
7518a238 CM |
545 | } |
546 | ||
bb492bb0 | 547 | static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val) |
7518a238 | 548 | { |
bb492bb0 | 549 | h->nritems = cpu_to_le16(val); |
7518a238 CM |
550 | } |
551 | ||
bb492bb0 | 552 | static inline u16 btrfs_header_flags(struct btrfs_header *h) |
7518a238 | 553 | { |
bb492bb0 | 554 | return le16_to_cpu(h->flags); |
7518a238 CM |
555 | } |
556 | ||
bb492bb0 | 557 | static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val) |
7518a238 | 558 | { |
bb492bb0 | 559 | h->flags = cpu_to_le16(val); |
7518a238 CM |
560 | } |
561 | ||
bb492bb0 | 562 | static inline int btrfs_header_level(struct btrfs_header *h) |
7518a238 | 563 | { |
234b63a0 | 564 | return btrfs_header_flags(h) & (BTRFS_MAX_LEVEL - 1); |
7518a238 CM |
565 | } |
566 | ||
bb492bb0 | 567 | static inline void btrfs_set_header_level(struct btrfs_header *h, int level) |
7518a238 | 568 | { |
bb492bb0 | 569 | u16 flags; |
234b63a0 CM |
570 | BUG_ON(level > BTRFS_MAX_LEVEL); |
571 | flags = btrfs_header_flags(h) & ~(BTRFS_MAX_LEVEL - 1); | |
7518a238 CM |
572 | btrfs_set_header_flags(h, flags | level); |
573 | } | |
574 | ||
234b63a0 | 575 | static inline int btrfs_is_leaf(struct btrfs_node *n) |
7518a238 CM |
576 | { |
577 | return (btrfs_header_level(&n->header) == 0); | |
578 | } | |
579 | ||
3768f368 CM |
580 | static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item) |
581 | { | |
582 | return le64_to_cpu(item->blocknr); | |
583 | } | |
584 | ||
585 | static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val) | |
586 | { | |
587 | item->blocknr = cpu_to_le64(val); | |
588 | } | |
589 | ||
590 | static inline u32 btrfs_root_refs(struct btrfs_root_item *item) | |
591 | { | |
592 | return le32_to_cpu(item->refs); | |
593 | } | |
594 | ||
595 | static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val) | |
596 | { | |
597 | item->refs = cpu_to_le32(val); | |
598 | } | |
599 | ||
600 | static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) | |
601 | { | |
602 | return le64_to_cpu(s->blocknr); | |
603 | } | |
604 | ||
605 | static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val) | |
606 | { | |
607 | s->blocknr = cpu_to_le64(val); | |
608 | } | |
609 | ||
610 | static inline u64 btrfs_super_root(struct btrfs_super_block *s) | |
611 | { | |
612 | return le64_to_cpu(s->root); | |
613 | } | |
614 | ||
615 | static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val) | |
616 | { | |
617 | s->root = cpu_to_le64(val); | |
618 | } | |
619 | ||
620 | static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s) | |
621 | { | |
622 | return le64_to_cpu(s->total_blocks); | |
623 | } | |
624 | ||
625 | static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s, | |
626 | u64 val) | |
627 | { | |
628 | s->total_blocks = cpu_to_le64(val); | |
629 | } | |
630 | ||
631 | static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s) | |
632 | { | |
633 | return le64_to_cpu(s->blocks_used); | |
634 | } | |
635 | ||
636 | static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, | |
637 | u64 val) | |
638 | { | |
639 | s->blocks_used = cpu_to_le64(val); | |
640 | } | |
641 | ||
123abc88 | 642 | static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) |
3768f368 | 643 | { |
123abc88 | 644 | return le32_to_cpu(s->blocksize); |
3768f368 CM |
645 | } |
646 | ||
647 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, | |
123abc88 CM |
648 | u32 val) |
649 | { | |
650 | s->blocksize = cpu_to_le32(val); | |
651 | } | |
652 | ||
653 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) | |
3768f368 | 654 | { |
123abc88 | 655 | return (u8 *)l->items; |
3768f368 | 656 | } |
4beb1b8b CM |
657 | /* helper function to cast into the data area of the leaf. */ |
658 | #define btrfs_item_ptr(leaf, slot, type) \ | |
123abc88 CM |
659 | ((type *)(btrfs_leaf_data(leaf) + \ |
660 | btrfs_item_offset((leaf)->items + (slot)))) | |
4beb1b8b | 661 | |
e089f05c CM |
662 | struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
663 | struct btrfs_root *root); | |
664 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |
665 | struct btrfs_buffer *buf); | |
666 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root | |
667 | *root, u64 blocknr, u64 num_blocks, int pin); | |
668 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root | |
669 | *root, struct btrfs_key *key, struct btrfs_path *p, int | |
670 | ins_len, int cow); | |
234b63a0 CM |
671 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
672 | void btrfs_init_path(struct btrfs_path *p); | |
e089f05c CM |
673 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
674 | struct btrfs_path *path); | |
675 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
676 | *root, struct btrfs_key *key, void *data, u32 data_size); | |
677 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
678 | *root, struct btrfs_path *path, struct btrfs_key | |
679 | *cpu_key, u32 data_size); | |
234b63a0 | 680 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
123abc88 | 681 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
e089f05c CM |
682 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
683 | *root, struct btrfs_buffer *snap); | |
684 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct | |
685 | btrfs_root *root); | |
686 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, | |
687 | struct btrfs_key *key); | |
688 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
689 | *root, struct btrfs_key *key, struct btrfs_root_item | |
690 | *item); | |
691 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
692 | *root, struct btrfs_key *key, struct btrfs_root_item | |
693 | *item); | |
694 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct | |
695 | btrfs_root_item *item, struct btrfs_key *key); | |
696 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
697 | *root, char *name, int name_len, u64 dir, u64 | |
698 | objectid, u8 type); | |
699 | int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
700 | *root, struct btrfs_path *path, u64 dir, char *name, | |
701 | int name_len, int mod); | |
1d4f6404 CM |
702 | int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, |
703 | char *name, int name_len); | |
eb60ceac | 704 | #endif |