Commit | Line | Data |
---|---|---|
234b63a0 CM |
1 | #ifndef __BTRFS__ |
2 | #define __BTRFS__ | |
eb60ceac | 3 | |
e20d96d6 | 4 | #include <linux/fs.h> |
8ef97622 | 5 | #include "bit-radix.h" |
e20d96d6 | 6 | |
e089f05c | 7 | struct btrfs_trans_handle; |
79154b1b | 8 | struct btrfs_transaction; |
e089f05c | 9 | |
3768f368 | 10 | #define BTRFS_MAGIC "_BtRfS_M" |
eb60ceac | 11 | |
6407bf6d CM |
12 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
13 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL | |
14 | #define BTRFS_INODE_MAP_OBJECTID 3ULL | |
15 | #define BTRFS_FS_TREE_OBJECTID 4ULL | |
16 | #define BTRFS_FIRST_FREE_OBJECTID 5ULL | |
3768f368 | 17 | |
e20d96d6 CM |
18 | /* |
19 | * we can actually store much bigger names, but lets not confuse the rest | |
20 | * of linux | |
21 | */ | |
22 | #define BTRFS_NAME_LEN 255 | |
23 | ||
fec577fb CM |
24 | /* |
25 | * the key defines the order in the tree, and so it also defines (optimal) | |
26 | * block layout. objectid corresonds to the inode number. The flags | |
27 | * tells us things about the object, and is a kind of stream selector. | |
28 | * so for a given inode, keys with flags of 1 might refer to the inode | |
29 | * data, flags of 2 may point to file data in the btree and flags == 3 | |
30 | * may point to extents. | |
31 | * | |
32 | * offset is the starting byte offset for this key in the stream. | |
e2fa7227 CM |
33 | * |
34 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always | |
35 | * in cpu native order. Otherwise they are identical and their sizes | |
36 | * should be the same (ie both packed) | |
fec577fb | 37 | */ |
e2fa7227 CM |
38 | struct btrfs_disk_key { |
39 | __le64 objectid; | |
a1516c89 | 40 | __le32 flags; |
a8a2ee0c | 41 | __le64 offset; |
e2fa7227 CM |
42 | } __attribute__ ((__packed__)); |
43 | ||
44 | struct btrfs_key { | |
eb60ceac | 45 | u64 objectid; |
a1516c89 | 46 | u32 flags; |
a8a2ee0c | 47 | u64 offset; |
eb60ceac CM |
48 | } __attribute__ ((__packed__)); |
49 | ||
fec577fb CM |
50 | /* |
51 | * every tree block (leaf or node) starts with this header. | |
52 | */ | |
bb492bb0 | 53 | struct btrfs_header { |
3768f368 | 54 | u8 fsid[16]; /* FS specific uuid */ |
bb492bb0 | 55 | __le64 blocknr; /* which block this node is supposed to live in */ |
7f5c1516 | 56 | __le64 generation; |
bb492bb0 CM |
57 | __le64 parentid; /* objectid of the tree root */ |
58 | __le32 csum; | |
59 | __le32 ham; | |
60 | __le16 nritems; | |
61 | __le16 flags; | |
9a6f11ed | 62 | u8 level; |
eb60ceac CM |
63 | } __attribute__ ((__packed__)); |
64 | ||
234b63a0 | 65 | #define BTRFS_MAX_LEVEL 8 |
123abc88 CM |
66 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ |
67 | sizeof(struct btrfs_header)) / \ | |
68 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) | |
69 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) | |
70 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) | |
eb60ceac | 71 | |
e20d96d6 | 72 | struct buffer_head; |
fec577fb CM |
73 | /* |
74 | * the super block basically lists the main trees of the FS | |
75 | * it currently lacks any block count etc etc | |
76 | */ | |
234b63a0 | 77 | struct btrfs_super_block { |
3768f368 CM |
78 | u8 fsid[16]; /* FS specific uuid */ |
79 | __le64 blocknr; /* this block number */ | |
80 | __le32 csum; | |
81 | __le64 magic; | |
123abc88 | 82 | __le32 blocksize; |
3768f368 CM |
83 | __le64 generation; |
84 | __le64 root; | |
85 | __le64 total_blocks; | |
86 | __le64 blocks_used; | |
2e635a27 | 87 | __le64 root_dir_objectid; |
cfaa7295 CM |
88 | } __attribute__ ((__packed__)); |
89 | ||
fec577fb | 90 | /* |
62e2749e | 91 | * A leaf is full of items. offset and size tell us where to find |
fec577fb CM |
92 | * the item in the leaf (relative to the start of the data area) |
93 | */ | |
0783fcfc | 94 | struct btrfs_item { |
e2fa7227 | 95 | struct btrfs_disk_key key; |
123abc88 | 96 | __le32 offset; |
0783fcfc | 97 | __le16 size; |
eb60ceac CM |
98 | } __attribute__ ((__packed__)); |
99 | ||
fec577fb CM |
100 | /* |
101 | * leaves have an item area and a data area: | |
102 | * [item0, item1....itemN] [free space] [dataN...data1, data0] | |
103 | * | |
104 | * The data is separate from the items to get the keys closer together | |
105 | * during searches. | |
106 | */ | |
234b63a0 | 107 | struct btrfs_leaf { |
bb492bb0 | 108 | struct btrfs_header header; |
123abc88 | 109 | struct btrfs_item items[]; |
eb60ceac CM |
110 | } __attribute__ ((__packed__)); |
111 | ||
fec577fb CM |
112 | /* |
113 | * all non-leaf blocks are nodes, they hold only keys and pointers to | |
114 | * other blocks | |
115 | */ | |
123abc88 CM |
116 | struct btrfs_key_ptr { |
117 | struct btrfs_disk_key key; | |
118 | __le64 blockptr; | |
119 | } __attribute__ ((__packed__)); | |
120 | ||
234b63a0 | 121 | struct btrfs_node { |
bb492bb0 | 122 | struct btrfs_header header; |
123abc88 | 123 | struct btrfs_key_ptr ptrs[]; |
eb60ceac CM |
124 | } __attribute__ ((__packed__)); |
125 | ||
fec577fb | 126 | /* |
234b63a0 CM |
127 | * btrfs_paths remember the path taken from the root down to the leaf. |
128 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | |
fec577fb CM |
129 | * to any other levels that are present. |
130 | * | |
131 | * The slots array records the index of the item or block pointer | |
132 | * used while walking the tree. | |
133 | */ | |
234b63a0 | 134 | struct btrfs_path { |
e20d96d6 | 135 | struct buffer_head *nodes[BTRFS_MAX_LEVEL]; |
234b63a0 | 136 | int slots[BTRFS_MAX_LEVEL]; |
eb60ceac | 137 | }; |
5de08d7d | 138 | |
62e2749e CM |
139 | /* |
140 | * items in the extent btree are used to record the objectid of the | |
141 | * owner of the block and the number of references | |
142 | */ | |
143 | struct btrfs_extent_item { | |
144 | __le32 refs; | |
145 | __le64 owner; | |
146 | } __attribute__ ((__packed__)); | |
147 | ||
1e1d2701 CM |
148 | struct btrfs_inode_timespec { |
149 | __le32 sec; | |
150 | __le32 nsec; | |
151 | } __attribute__ ((__packed__)); | |
152 | ||
153 | /* | |
154 | * there is no padding here on purpose. If you want to extent the inode, | |
155 | * make a new item type | |
156 | */ | |
157 | struct btrfs_inode_item { | |
158 | __le64 generation; | |
159 | __le64 size; | |
160 | __le64 nblocks; | |
161 | __le32 nlink; | |
162 | __le32 uid; | |
163 | __le32 gid; | |
164 | __le32 mode; | |
165 | __le32 rdev; | |
166 | __le16 flags; | |
167 | __le16 compat_flags; | |
168 | struct btrfs_inode_timespec atime; | |
169 | struct btrfs_inode_timespec ctime; | |
170 | struct btrfs_inode_timespec mtime; | |
171 | struct btrfs_inode_timespec otime; | |
172 | } __attribute__ ((__packed__)); | |
173 | ||
174 | /* inline data is just a blob of bytes */ | |
175 | struct btrfs_inline_data_item { | |
176 | u8 data; | |
177 | } __attribute__ ((__packed__)); | |
178 | ||
62e2749e CM |
179 | struct btrfs_dir_item { |
180 | __le64 objectid; | |
181 | __le16 flags; | |
a8a2ee0c | 182 | __le16 name_len; |
62e2749e CM |
183 | u8 type; |
184 | } __attribute__ ((__packed__)); | |
185 | ||
186 | struct btrfs_root_item { | |
187 | __le64 blocknr; | |
188 | __le32 flags; | |
189 | __le64 block_limit; | |
190 | __le64 blocks_used; | |
191 | __le32 refs; | |
9f5fae2f | 192 | } __attribute__ ((__packed__)); |
62e2749e | 193 | |
9f5fae2f | 194 | struct btrfs_file_extent_item { |
71951f35 | 195 | __le64 generation; |
9f5fae2f CM |
196 | /* |
197 | * disk space consumed by the extent, checksum blocks are included | |
198 | * in these numbers | |
199 | */ | |
200 | __le64 disk_blocknr; | |
201 | __le64 disk_num_blocks; | |
202 | /* | |
dee26a9f | 203 | * the logical offset in file blocks (no csums) |
9f5fae2f CM |
204 | * this extent record is for. This allows a file extent to point |
205 | * into the middle of an existing extent on disk, sharing it | |
206 | * between two snapshots (useful if some bytes in the middle of the | |
207 | * extent have changed | |
208 | */ | |
209 | __le64 offset; | |
210 | /* | |
211 | * the logical number of file blocks (no csums included) | |
212 | */ | |
213 | __le64 num_blocks; | |
214 | } __attribute__ ((__packed__)); | |
215 | ||
216 | struct btrfs_inode_map_item { | |
217 | struct btrfs_disk_key key; | |
218 | } __attribute__ ((__packed__)); | |
219 | ||
220 | struct btrfs_fs_info { | |
221 | struct btrfs_root *fs_root; | |
62e2749e CM |
222 | struct btrfs_root *extent_root; |
223 | struct btrfs_root *tree_root; | |
9f5fae2f | 224 | struct btrfs_root *inode_root; |
62e2749e CM |
225 | struct btrfs_key current_insert; |
226 | struct btrfs_key last_insert; | |
8ef97622 | 227 | struct radix_tree_root pending_del_radix; |
62e2749e | 228 | struct radix_tree_root pinned_radix; |
9f5fae2f CM |
229 | u64 last_inode_alloc; |
230 | u64 last_inode_alloc_dirid; | |
293ffd5f | 231 | u64 generation; |
79154b1b | 232 | struct btrfs_transaction *running_transaction; |
1261ec42 | 233 | struct btrfs_super_block *disk_super; |
e20d96d6 CM |
234 | struct buffer_head *sb_buffer; |
235 | struct super_block *sb; | |
79154b1b | 236 | struct mutex trans_mutex; |
d561c025 | 237 | struct mutex fs_mutex; |
9f5fae2f CM |
238 | }; |
239 | ||
240 | /* | |
241 | * in ram representation of the tree. extent_root is used for all allocations | |
242 | * and for the extent tree extent_root root. current_insert is used | |
243 | * only for the extent tree. | |
244 | */ | |
245 | struct btrfs_root { | |
e20d96d6 CM |
246 | struct buffer_head *node; |
247 | struct buffer_head *commit_root; | |
62e2749e CM |
248 | struct btrfs_root_item root_item; |
249 | struct btrfs_key root_key; | |
9f5fae2f | 250 | struct btrfs_fs_info *fs_info; |
62e2749e | 251 | u32 blocksize; |
9f5fae2f CM |
252 | int ref_cows; |
253 | u32 type; | |
62e2749e CM |
254 | }; |
255 | ||
62e2749e CM |
256 | /* the lower bits in the key flags defines the item type */ |
257 | #define BTRFS_KEY_TYPE_MAX 256 | |
258 | #define BTRFS_KEY_TYPE_MASK (BTRFS_KEY_TYPE_MAX - 1) | |
1e1d2701 CM |
259 | |
260 | /* | |
261 | * inode items have the data typically returned from stat and store other | |
262 | * info about object characteristics. There is one for every file and dir in | |
263 | * the FS | |
264 | */ | |
62e2749e | 265 | #define BTRFS_INODE_ITEM_KEY 1 |
1e1d2701 CM |
266 | |
267 | /* | |
268 | * dir items are the name -> inode pointers in a directory. There is one | |
269 | * for every name in a directory. | |
270 | */ | |
62e2749e | 271 | #define BTRFS_DIR_ITEM_KEY 2 |
1e1d2701 CM |
272 | /* |
273 | * inline data is file data that fits in the btree. | |
274 | */ | |
275 | #define BTRFS_INLINE_DATA_KEY 3 | |
276 | /* | |
277 | * extent data is for data that can't fit in the btree. It points to | |
278 | * a (hopefully) huge chunk of disk | |
279 | */ | |
280 | #define BTRFS_EXTENT_DATA_KEY 4 | |
281 | /* | |
282 | * root items point to tree roots. There are typically in the root | |
283 | * tree used by the super block to find all the other trees | |
284 | */ | |
285 | #define BTRFS_ROOT_ITEM_KEY 5 | |
286 | /* | |
287 | * extent items are in the extent map tree. These record which blocks | |
288 | * are used, and how many references there are to each block | |
289 | */ | |
290 | #define BTRFS_EXTENT_ITEM_KEY 6 | |
9f5fae2f CM |
291 | |
292 | /* | |
293 | * the inode map records which inode numbers are in use and where | |
294 | * they actually live on disk | |
295 | */ | |
296 | #define BTRFS_INODE_MAP_ITEM_KEY 7 | |
1e1d2701 CM |
297 | /* |
298 | * string items are for debugging. They just store a short string of | |
299 | * data in the FS | |
300 | */ | |
9f5fae2f | 301 | #define BTRFS_STRING_ITEM_KEY 8 |
1e1d2701 CM |
302 | |
303 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) | |
304 | { | |
305 | return le64_to_cpu(i->generation); | |
306 | } | |
307 | ||
308 | static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i, | |
309 | u64 val) | |
310 | { | |
311 | i->generation = cpu_to_le64(val); | |
312 | } | |
313 | ||
314 | static inline u64 btrfs_inode_size(struct btrfs_inode_item *i) | |
315 | { | |
316 | return le64_to_cpu(i->size); | |
317 | } | |
318 | ||
319 | static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val) | |
320 | { | |
321 | i->size = cpu_to_le64(val); | |
322 | } | |
323 | ||
324 | static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i) | |
325 | { | |
326 | return le64_to_cpu(i->nblocks); | |
327 | } | |
328 | ||
329 | static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val) | |
330 | { | |
331 | i->nblocks = cpu_to_le64(val); | |
332 | } | |
333 | ||
334 | static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i) | |
335 | { | |
336 | return le32_to_cpu(i->nlink); | |
337 | } | |
338 | ||
339 | static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val) | |
340 | { | |
341 | i->nlink = cpu_to_le32(val); | |
342 | } | |
343 | ||
344 | static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i) | |
345 | { | |
346 | return le32_to_cpu(i->uid); | |
347 | } | |
348 | ||
349 | static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val) | |
350 | { | |
351 | i->uid = cpu_to_le32(val); | |
352 | } | |
353 | ||
354 | static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i) | |
355 | { | |
356 | return le32_to_cpu(i->gid); | |
357 | } | |
358 | ||
359 | static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val) | |
360 | { | |
361 | i->gid = cpu_to_le32(val); | |
362 | } | |
363 | ||
364 | static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i) | |
365 | { | |
366 | return le32_to_cpu(i->mode); | |
367 | } | |
368 | ||
369 | static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val) | |
370 | { | |
371 | i->mode = cpu_to_le32(val); | |
372 | } | |
373 | ||
374 | static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i) | |
375 | { | |
376 | return le32_to_cpu(i->rdev); | |
377 | } | |
378 | ||
379 | static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val) | |
380 | { | |
381 | i->rdev = cpu_to_le32(val); | |
382 | } | |
383 | ||
384 | static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i) | |
385 | { | |
386 | return le16_to_cpu(i->flags); | |
387 | } | |
388 | ||
389 | static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val) | |
390 | { | |
391 | i->flags = cpu_to_le16(val); | |
392 | } | |
393 | ||
394 | static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i) | |
395 | { | |
396 | return le16_to_cpu(i->compat_flags); | |
397 | } | |
398 | ||
399 | static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i, | |
400 | u16 val) | |
401 | { | |
402 | i->compat_flags = cpu_to_le16(val); | |
403 | } | |
404 | ||
e20d96d6 CM |
405 | static inline u32 btrfs_timespec_sec(struct btrfs_inode_timespec *ts) |
406 | { | |
407 | return le32_to_cpu(ts->sec); | |
408 | } | |
409 | ||
410 | static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts, | |
411 | u32 val) | |
412 | { | |
413 | ts->sec = cpu_to_le32(val); | |
414 | } | |
415 | ||
416 | static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts) | |
417 | { | |
418 | return le32_to_cpu(ts->nsec); | |
419 | } | |
420 | ||
421 | static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts, | |
422 | u32 val) | |
423 | { | |
424 | ts->nsec = cpu_to_le32(val); | |
425 | } | |
426 | ||
427 | ||
62e2749e | 428 | |
234b63a0 | 429 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
cf27e1ee CM |
430 | { |
431 | return le64_to_cpu(ei->owner); | |
432 | } | |
433 | ||
234b63a0 | 434 | static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val) |
cf27e1ee CM |
435 | { |
436 | ei->owner = cpu_to_le64(val); | |
437 | } | |
438 | ||
234b63a0 | 439 | static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei) |
cf27e1ee CM |
440 | { |
441 | return le32_to_cpu(ei->refs); | |
442 | } | |
443 | ||
234b63a0 | 444 | static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) |
cf27e1ee CM |
445 | { |
446 | ei->refs = cpu_to_le32(val); | |
447 | } | |
448 | ||
234b63a0 | 449 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) |
1d4f8a0c | 450 | { |
123abc88 | 451 | return le64_to_cpu(n->ptrs[nr].blockptr); |
1d4f8a0c CM |
452 | } |
453 | ||
234b63a0 CM |
454 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, |
455 | u64 val) | |
1d4f8a0c | 456 | { |
123abc88 | 457 | n->ptrs[nr].blockptr = cpu_to_le64(val); |
1d4f8a0c CM |
458 | } |
459 | ||
123abc88 | 460 | static inline u32 btrfs_item_offset(struct btrfs_item *item) |
0783fcfc | 461 | { |
123abc88 | 462 | return le32_to_cpu(item->offset); |
0783fcfc CM |
463 | } |
464 | ||
123abc88 | 465 | static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val) |
0783fcfc | 466 | { |
123abc88 | 467 | item->offset = cpu_to_le32(val); |
0783fcfc CM |
468 | } |
469 | ||
123abc88 | 470 | static inline u32 btrfs_item_end(struct btrfs_item *item) |
0783fcfc | 471 | { |
123abc88 | 472 | return le32_to_cpu(item->offset) + le16_to_cpu(item->size); |
0783fcfc CM |
473 | } |
474 | ||
475 | static inline u16 btrfs_item_size(struct btrfs_item *item) | |
476 | { | |
477 | return le16_to_cpu(item->size); | |
478 | } | |
479 | ||
480 | static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val) | |
481 | { | |
482 | item->size = cpu_to_le16(val); | |
483 | } | |
484 | ||
1d4f6404 CM |
485 | static inline u64 btrfs_dir_objectid(struct btrfs_dir_item *d) |
486 | { | |
487 | return le64_to_cpu(d->objectid); | |
488 | } | |
489 | ||
490 | static inline void btrfs_set_dir_objectid(struct btrfs_dir_item *d, u64 val) | |
491 | { | |
492 | d->objectid = cpu_to_le64(val); | |
493 | } | |
494 | ||
495 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) | |
496 | { | |
497 | return le16_to_cpu(d->flags); | |
498 | } | |
499 | ||
500 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) | |
501 | { | |
502 | d->flags = cpu_to_le16(val); | |
503 | } | |
504 | ||
505 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) | |
506 | { | |
507 | return d->type; | |
508 | } | |
509 | ||
510 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) | |
511 | { | |
512 | d->type = val; | |
513 | } | |
514 | ||
a8a2ee0c CM |
515 | static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d) |
516 | { | |
517 | return le16_to_cpu(d->name_len); | |
518 | } | |
519 | ||
520 | static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val) | |
1d4f6404 | 521 | { |
a8a2ee0c | 522 | d->name_len = cpu_to_le16(val); |
1d4f6404 CM |
523 | } |
524 | ||
e2fa7227 CM |
525 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
526 | struct btrfs_disk_key *disk) | |
527 | { | |
528 | cpu->offset = le64_to_cpu(disk->offset); | |
529 | cpu->flags = le32_to_cpu(disk->flags); | |
530 | cpu->objectid = le64_to_cpu(disk->objectid); | |
531 | } | |
532 | ||
533 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |
534 | struct btrfs_key *cpu) | |
535 | { | |
536 | disk->offset = cpu_to_le64(cpu->offset); | |
537 | disk->flags = cpu_to_le32(cpu->flags); | |
538 | disk->objectid = cpu_to_le64(cpu->objectid); | |
539 | } | |
540 | ||
62e2749e | 541 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
e2fa7227 CM |
542 | { |
543 | return le64_to_cpu(disk->objectid); | |
544 | } | |
545 | ||
62e2749e CM |
546 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
547 | u64 val) | |
e2fa7227 CM |
548 | { |
549 | disk->objectid = cpu_to_le64(val); | |
550 | } | |
551 | ||
62e2749e | 552 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
e2fa7227 CM |
553 | { |
554 | return le64_to_cpu(disk->offset); | |
555 | } | |
556 | ||
62e2749e CM |
557 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
558 | u64 val) | |
e2fa7227 CM |
559 | { |
560 | disk->offset = cpu_to_le64(val); | |
561 | } | |
562 | ||
62e2749e | 563 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
e2fa7227 CM |
564 | { |
565 | return le32_to_cpu(disk->flags); | |
566 | } | |
567 | ||
62e2749e CM |
568 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
569 | u32 val) | |
e2fa7227 CM |
570 | { |
571 | disk->flags = cpu_to_le32(val); | |
572 | } | |
573 | ||
62e2749e CM |
574 | static inline u32 btrfs_key_type(struct btrfs_key *key) |
575 | { | |
576 | return key->flags & BTRFS_KEY_TYPE_MASK; | |
577 | } | |
578 | ||
579 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) | |
580 | { | |
581 | return le32_to_cpu(key->flags) & BTRFS_KEY_TYPE_MASK; | |
582 | } | |
583 | ||
584 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 type) | |
585 | { | |
586 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | |
587 | key->flags = (key->flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | |
588 | } | |
589 | ||
590 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u32 type) | |
591 | { | |
592 | u32 flags = btrfs_disk_key_flags(key); | |
593 | BUG_ON(type >= BTRFS_KEY_TYPE_MAX); | |
594 | flags = (flags & ~((u64)BTRFS_KEY_TYPE_MASK)) | type; | |
595 | btrfs_set_disk_key_flags(key, flags); | |
596 | } | |
597 | ||
bb492bb0 | 598 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
7518a238 | 599 | { |
bb492bb0 | 600 | return le64_to_cpu(h->blocknr); |
7518a238 CM |
601 | } |
602 | ||
bb492bb0 | 603 | static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr) |
7518a238 | 604 | { |
bb492bb0 | 605 | h->blocknr = cpu_to_le64(blocknr); |
7518a238 CM |
606 | } |
607 | ||
7f5c1516 CM |
608 | static inline u64 btrfs_header_generation(struct btrfs_header *h) |
609 | { | |
610 | return le64_to_cpu(h->generation); | |
611 | } | |
612 | ||
613 | static inline void btrfs_set_header_generation(struct btrfs_header *h, | |
614 | u64 val) | |
615 | { | |
616 | h->generation = cpu_to_le64(val); | |
617 | } | |
618 | ||
bb492bb0 | 619 | static inline u64 btrfs_header_parentid(struct btrfs_header *h) |
7518a238 | 620 | { |
bb492bb0 | 621 | return le64_to_cpu(h->parentid); |
7518a238 CM |
622 | } |
623 | ||
bb492bb0 CM |
624 | static inline void btrfs_set_header_parentid(struct btrfs_header *h, |
625 | u64 parentid) | |
7518a238 | 626 | { |
bb492bb0 | 627 | h->parentid = cpu_to_le64(parentid); |
7518a238 CM |
628 | } |
629 | ||
bb492bb0 | 630 | static inline u16 btrfs_header_nritems(struct btrfs_header *h) |
7518a238 | 631 | { |
bb492bb0 | 632 | return le16_to_cpu(h->nritems); |
7518a238 CM |
633 | } |
634 | ||
bb492bb0 | 635 | static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val) |
7518a238 | 636 | { |
bb492bb0 | 637 | h->nritems = cpu_to_le16(val); |
7518a238 CM |
638 | } |
639 | ||
bb492bb0 | 640 | static inline u16 btrfs_header_flags(struct btrfs_header *h) |
7518a238 | 641 | { |
bb492bb0 | 642 | return le16_to_cpu(h->flags); |
7518a238 CM |
643 | } |
644 | ||
bb492bb0 | 645 | static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val) |
7518a238 | 646 | { |
bb492bb0 | 647 | h->flags = cpu_to_le16(val); |
7518a238 CM |
648 | } |
649 | ||
bb492bb0 | 650 | static inline int btrfs_header_level(struct btrfs_header *h) |
7518a238 | 651 | { |
9a6f11ed | 652 | return h->level; |
7518a238 CM |
653 | } |
654 | ||
bb492bb0 | 655 | static inline void btrfs_set_header_level(struct btrfs_header *h, int level) |
7518a238 | 656 | { |
234b63a0 | 657 | BUG_ON(level > BTRFS_MAX_LEVEL); |
9a6f11ed | 658 | h->level = level; |
7518a238 CM |
659 | } |
660 | ||
234b63a0 | 661 | static inline int btrfs_is_leaf(struct btrfs_node *n) |
7518a238 CM |
662 | { |
663 | return (btrfs_header_level(&n->header) == 0); | |
664 | } | |
665 | ||
3768f368 CM |
666 | static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item) |
667 | { | |
668 | return le64_to_cpu(item->blocknr); | |
669 | } | |
670 | ||
671 | static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val) | |
672 | { | |
673 | item->blocknr = cpu_to_le64(val); | |
674 | } | |
675 | ||
676 | static inline u32 btrfs_root_refs(struct btrfs_root_item *item) | |
677 | { | |
678 | return le32_to_cpu(item->refs); | |
679 | } | |
680 | ||
681 | static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val) | |
682 | { | |
683 | item->refs = cpu_to_le32(val); | |
684 | } | |
685 | ||
686 | static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) | |
687 | { | |
688 | return le64_to_cpu(s->blocknr); | |
689 | } | |
690 | ||
691 | static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val) | |
692 | { | |
693 | s->blocknr = cpu_to_le64(val); | |
694 | } | |
695 | ||
696 | static inline u64 btrfs_super_root(struct btrfs_super_block *s) | |
697 | { | |
698 | return le64_to_cpu(s->root); | |
699 | } | |
700 | ||
701 | static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val) | |
702 | { | |
703 | s->root = cpu_to_le64(val); | |
704 | } | |
705 | ||
706 | static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s) | |
707 | { | |
708 | return le64_to_cpu(s->total_blocks); | |
709 | } | |
710 | ||
711 | static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s, | |
712 | u64 val) | |
713 | { | |
714 | s->total_blocks = cpu_to_le64(val); | |
715 | } | |
716 | ||
717 | static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s) | |
718 | { | |
719 | return le64_to_cpu(s->blocks_used); | |
720 | } | |
721 | ||
722 | static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, | |
723 | u64 val) | |
724 | { | |
725 | s->blocks_used = cpu_to_le64(val); | |
726 | } | |
727 | ||
123abc88 | 728 | static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) |
3768f368 | 729 | { |
123abc88 | 730 | return le32_to_cpu(s->blocksize); |
3768f368 CM |
731 | } |
732 | ||
733 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, | |
123abc88 CM |
734 | u32 val) |
735 | { | |
736 | s->blocksize = cpu_to_le32(val); | |
737 | } | |
738 | ||
2e635a27 CM |
739 | static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s) |
740 | { | |
741 | return le64_to_cpu(s->root_dir_objectid); | |
742 | } | |
743 | ||
744 | static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64 | |
745 | val) | |
746 | { | |
747 | s->root_dir_objectid = cpu_to_le64(val); | |
748 | } | |
749 | ||
123abc88 | 750 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) |
3768f368 | 751 | { |
123abc88 | 752 | return (u8 *)l->items; |
3768f368 | 753 | } |
9f5fae2f CM |
754 | |
755 | static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item | |
756 | *e) | |
757 | { | |
758 | return le64_to_cpu(e->disk_blocknr); | |
759 | } | |
760 | ||
761 | static inline void btrfs_set_file_extent_disk_blocknr(struct | |
762 | btrfs_file_extent_item | |
763 | *e, u64 val) | |
764 | { | |
765 | e->disk_blocknr = cpu_to_le64(val); | |
766 | } | |
767 | ||
71951f35 CM |
768 | static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e) |
769 | { | |
770 | return le64_to_cpu(e->generation); | |
771 | } | |
772 | ||
773 | static inline void btrfs_set_file_extent_generation(struct | |
774 | btrfs_file_extent_item *e, | |
775 | u64 val) | |
776 | { | |
777 | e->generation = cpu_to_le64(val); | |
778 | } | |
779 | ||
9f5fae2f CM |
780 | static inline u64 btrfs_file_extent_disk_num_blocks(struct |
781 | btrfs_file_extent_item *e) | |
782 | { | |
783 | return le64_to_cpu(e->disk_num_blocks); | |
784 | } | |
785 | ||
786 | static inline void btrfs_set_file_extent_disk_num_blocks(struct | |
787 | btrfs_file_extent_item | |
788 | *e, u64 val) | |
789 | { | |
790 | e->disk_num_blocks = cpu_to_le64(val); | |
791 | } | |
792 | ||
793 | static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e) | |
794 | { | |
795 | return le64_to_cpu(e->offset); | |
796 | } | |
797 | ||
798 | static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item | |
799 | *e, u64 val) | |
800 | { | |
801 | e->offset = cpu_to_le64(val); | |
802 | } | |
803 | ||
804 | static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item | |
805 | *e) | |
806 | { | |
807 | return le64_to_cpu(e->num_blocks); | |
808 | } | |
809 | ||
810 | static inline void btrfs_set_file_extent_num_blocks(struct | |
811 | btrfs_file_extent_item *e, | |
812 | u64 val) | |
813 | { | |
814 | e->num_blocks = cpu_to_le64(val); | |
815 | } | |
816 | ||
e20d96d6 CM |
817 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
818 | { | |
819 | return sb->s_fs_info; | |
820 | } | |
821 | ||
4beb1b8b CM |
822 | /* helper function to cast into the data area of the leaf. */ |
823 | #define btrfs_item_ptr(leaf, slot, type) \ | |
123abc88 CM |
824 | ((type *)(btrfs_leaf_data(leaf) + \ |
825 | btrfs_item_offset((leaf)->items + (slot)))) | |
4beb1b8b | 826 | |
dee26a9f | 827 | /* extent-item.c */ |
e20d96d6 | 828 | struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
e089f05c | 829 | struct btrfs_root *root); |
dee26a9f CM |
830 | int btrfs_alloc_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
831 | *root, u64 num_blocks, u64 search_start, u64 | |
832 | search_end, u64 owner, struct btrfs_key *ins); | |
e089f05c | 833 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
e20d96d6 | 834 | struct buffer_head *buf); |
e089f05c CM |
835 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
836 | *root, u64 blocknr, u64 num_blocks, int pin); | |
dee26a9f CM |
837 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct |
838 | btrfs_root *root); | |
839 | /* ctree.c */ | |
e089f05c CM |
840 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
841 | *root, struct btrfs_key *key, struct btrfs_path *p, int | |
842 | ins_len, int cow); | |
234b63a0 CM |
843 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
844 | void btrfs_init_path(struct btrfs_path *p); | |
e089f05c CM |
845 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
846 | struct btrfs_path *path); | |
847 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
848 | *root, struct btrfs_key *key, void *data, u32 data_size); | |
849 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
850 | *root, struct btrfs_path *path, struct btrfs_key | |
851 | *cpu_key, u32 data_size); | |
234b63a0 | 852 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
123abc88 | 853 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
e089f05c | 854 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
e20d96d6 | 855 | *root, struct buffer_head *snap); |
dee26a9f | 856 | /* root-item.c */ |
e089f05c CM |
857 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
858 | struct btrfs_key *key); | |
859 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
860 | *root, struct btrfs_key *key, struct btrfs_root_item | |
861 | *item); | |
862 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
863 | *root, struct btrfs_key *key, struct btrfs_root_item | |
864 | *item); | |
865 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct | |
866 | btrfs_root_item *item, struct btrfs_key *key); | |
dee26a9f | 867 | /* dir-item.c */ |
e089f05c | 868 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
d5719762 | 869 | *root, const char *name, int name_len, u64 dir, u64 |
e089f05c CM |
870 | objectid, u8 type); |
871 | int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
e20d96d6 CM |
872 | *root, struct btrfs_path *path, u64 dir, |
873 | const char *name, int name_len, int mod); | |
1d4f6404 | 874 | int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path, |
7f5c1516 | 875 | const char *name, int name_len); |
dee26a9f | 876 | /* inode-map.c */ |
9f5fae2f CM |
877 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
878 | struct btrfs_root *fs_root, | |
879 | u64 dirid, u64 *objectid); | |
880 | int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, | |
881 | struct btrfs_root *root, | |
882 | u64 objectid, struct btrfs_key *location); | |
883 | int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, | |
884 | struct btrfs_root *root, struct btrfs_path *path, | |
885 | u64 objectid, int mod); | |
dee26a9f | 886 | /* inode-item.c */ |
293ffd5f CM |
887 | int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
888 | *root, u64 objectid, struct btrfs_inode_item | |
889 | *inode_item); | |
890 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root | |
891 | *root, struct btrfs_path *path, u64 objectid, int mod); | |
dee26a9f CM |
892 | |
893 | /* file-item.c */ | |
894 | int btrfs_alloc_file_extent(struct btrfs_trans_handle *trans, | |
895 | struct btrfs_root *root, | |
896 | u64 objectid, u64 offset, | |
897 | u64 num_blocks, u64 hint_block, | |
898 | u64 *result); | |
899 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, | |
900 | struct btrfs_root *root, | |
901 | struct btrfs_path *path, u64 objectid, | |
902 | u64 blocknr, u64 num_blocks, int mod); | |
eb60ceac | 903 | #endif |