]>
Commit | Line | Data |
---|---|---|
234b63a0 CM |
1 | #ifndef __BTRFS__ |
2 | #define __BTRFS__ | |
eb60ceac | 3 | |
e20d96d6 | 4 | #include <linux/fs.h> |
d6025579 | 5 | #include <linux/buffer_head.h> |
d6e4a428 | 6 | #include <linux/kobject.h> |
8ef97622 | 7 | #include "bit-radix.h" |
e20d96d6 | 8 | |
e089f05c | 9 | struct btrfs_trans_handle; |
79154b1b | 10 | struct btrfs_transaction; |
35b7e476 CM |
11 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
12 | extern struct kmem_cache *btrfs_transaction_cachep; | |
13 | extern struct kmem_cache *btrfs_bit_radix_cachep; | |
2c90e5d6 | 14 | extern struct kmem_cache *btrfs_path_cachep; |
e089f05c | 15 | |
3768f368 | 16 | #define BTRFS_MAGIC "_BtRfS_M" |
eb60ceac | 17 | |
6407bf6d | 18 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
0bd93ba0 CM |
19 | #define BTRFS_DEV_TREE_OBJECTID 2ULL |
20 | #define BTRFS_EXTENT_TREE_OBJECTID 3ULL | |
21 | #define BTRFS_FS_TREE_OBJECTID 4ULL | |
22 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL | |
23 | #define BTRFS_FIRST_FREE_OBJECTID 6ULL | |
3768f368 | 24 | |
e20d96d6 CM |
25 | /* |
26 | * we can actually store much bigger names, but lets not confuse the rest | |
27 | * of linux | |
28 | */ | |
29 | #define BTRFS_NAME_LEN 255 | |
30 | ||
f254e52c CM |
31 | /* 32 bytes in various csum fields */ |
32 | #define BTRFS_CSUM_SIZE 32 | |
509659cd CM |
33 | /* four bytes for CRC32 */ |
34 | #define BTRFS_CRC32_SIZE 4 | |
f254e52c | 35 | |
fec577fb CM |
36 | /* |
37 | * the key defines the order in the tree, and so it also defines (optimal) | |
38 | * block layout. objectid corresonds to the inode number. The flags | |
39 | * tells us things about the object, and is a kind of stream selector. | |
40 | * so for a given inode, keys with flags of 1 might refer to the inode | |
41 | * data, flags of 2 may point to file data in the btree and flags == 3 | |
42 | * may point to extents. | |
43 | * | |
44 | * offset is the starting byte offset for this key in the stream. | |
e2fa7227 CM |
45 | * |
46 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always | |
47 | * in cpu native order. Otherwise they are identical and their sizes | |
48 | * should be the same (ie both packed) | |
fec577fb | 49 | */ |
e2fa7227 CM |
50 | struct btrfs_disk_key { |
51 | __le64 objectid; | |
f254e52c | 52 | __le32 flags; |
70b2befd | 53 | __le64 offset; |
e2fa7227 CM |
54 | } __attribute__ ((__packed__)); |
55 | ||
56 | struct btrfs_key { | |
eb60ceac | 57 | u64 objectid; |
f254e52c | 58 | u32 flags; |
70b2befd | 59 | u64 offset; |
eb60ceac CM |
60 | } __attribute__ ((__packed__)); |
61 | ||
fec577fb CM |
62 | /* |
63 | * every tree block (leaf or node) starts with this header. | |
64 | */ | |
bb492bb0 | 65 | struct btrfs_header { |
f254e52c | 66 | u8 csum[BTRFS_CSUM_SIZE]; |
3768f368 | 67 | u8 fsid[16]; /* FS specific uuid */ |
bb492bb0 | 68 | __le64 blocknr; /* which block this node is supposed to live in */ |
7f5c1516 | 69 | __le64 generation; |
4d775673 | 70 | __le64 owner; |
bb492bb0 CM |
71 | __le16 nritems; |
72 | __le16 flags; | |
9a6f11ed | 73 | u8 level; |
eb60ceac CM |
74 | } __attribute__ ((__packed__)); |
75 | ||
234b63a0 | 76 | #define BTRFS_MAX_LEVEL 8 |
123abc88 CM |
77 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ |
78 | sizeof(struct btrfs_header)) / \ | |
79 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) | |
80 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) | |
81 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) | |
236454df CM |
82 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
83 | sizeof(struct btrfs_item) - \ | |
84 | sizeof(struct btrfs_file_extent_item)) | |
eb60ceac | 85 | |
e20d96d6 | 86 | struct buffer_head; |
fec577fb CM |
87 | /* |
88 | * the super block basically lists the main trees of the FS | |
89 | * it currently lacks any block count etc etc | |
90 | */ | |
234b63a0 | 91 | struct btrfs_super_block { |
f254e52c | 92 | u8 csum[BTRFS_CSUM_SIZE]; |
87cbda5c | 93 | /* the first 3 fields must match struct btrfs_header */ |
3768f368 CM |
94 | u8 fsid[16]; /* FS specific uuid */ |
95 | __le64 blocknr; /* this block number */ | |
3768f368 | 96 | __le64 magic; |
123abc88 | 97 | __le32 blocksize; |
3768f368 CM |
98 | __le64 generation; |
99 | __le64 root; | |
100 | __le64 total_blocks; | |
101 | __le64 blocks_used; | |
2e635a27 | 102 | __le64 root_dir_objectid; |
b4100d64 | 103 | __le64 last_device_id; |
0bd93ba0 CM |
104 | /* fields below here vary with the underlying disk */ |
105 | __le64 device_block_start; | |
106 | __le64 device_num_blocks; | |
107 | __le64 device_root; | |
b4100d64 | 108 | __le64 device_id; |
cfaa7295 CM |
109 | } __attribute__ ((__packed__)); |
110 | ||
fec577fb | 111 | /* |
62e2749e | 112 | * A leaf is full of items. offset and size tell us where to find |
fec577fb CM |
113 | * the item in the leaf (relative to the start of the data area) |
114 | */ | |
0783fcfc | 115 | struct btrfs_item { |
e2fa7227 | 116 | struct btrfs_disk_key key; |
123abc88 | 117 | __le32 offset; |
0783fcfc | 118 | __le16 size; |
eb60ceac CM |
119 | } __attribute__ ((__packed__)); |
120 | ||
fec577fb CM |
121 | /* |
122 | * leaves have an item area and a data area: | |
123 | * [item0, item1....itemN] [free space] [dataN...data1, data0] | |
124 | * | |
125 | * The data is separate from the items to get the keys closer together | |
126 | * during searches. | |
127 | */ | |
234b63a0 | 128 | struct btrfs_leaf { |
bb492bb0 | 129 | struct btrfs_header header; |
123abc88 | 130 | struct btrfs_item items[]; |
eb60ceac CM |
131 | } __attribute__ ((__packed__)); |
132 | ||
fec577fb CM |
133 | /* |
134 | * all non-leaf blocks are nodes, they hold only keys and pointers to | |
135 | * other blocks | |
136 | */ | |
123abc88 CM |
137 | struct btrfs_key_ptr { |
138 | struct btrfs_disk_key key; | |
139 | __le64 blockptr; | |
140 | } __attribute__ ((__packed__)); | |
141 | ||
234b63a0 | 142 | struct btrfs_node { |
bb492bb0 | 143 | struct btrfs_header header; |
123abc88 | 144 | struct btrfs_key_ptr ptrs[]; |
eb60ceac CM |
145 | } __attribute__ ((__packed__)); |
146 | ||
fec577fb | 147 | /* |
234b63a0 CM |
148 | * btrfs_paths remember the path taken from the root down to the leaf. |
149 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | |
fec577fb CM |
150 | * to any other levels that are present. |
151 | * | |
152 | * The slots array records the index of the item or block pointer | |
153 | * used while walking the tree. | |
154 | */ | |
234b63a0 | 155 | struct btrfs_path { |
e20d96d6 | 156 | struct buffer_head *nodes[BTRFS_MAX_LEVEL]; |
234b63a0 | 157 | int slots[BTRFS_MAX_LEVEL]; |
eb60ceac | 158 | }; |
5de08d7d | 159 | |
62e2749e CM |
160 | /* |
161 | * items in the extent btree are used to record the objectid of the | |
162 | * owner of the block and the number of references | |
163 | */ | |
164 | struct btrfs_extent_item { | |
165 | __le32 refs; | |
4d775673 | 166 | __le64 owner; |
62e2749e CM |
167 | } __attribute__ ((__packed__)); |
168 | ||
1e1d2701 | 169 | struct btrfs_inode_timespec { |
f254e52c | 170 | __le64 sec; |
1e1d2701 CM |
171 | __le32 nsec; |
172 | } __attribute__ ((__packed__)); | |
173 | ||
174 | /* | |
175 | * there is no padding here on purpose. If you want to extent the inode, | |
176 | * make a new item type | |
177 | */ | |
178 | struct btrfs_inode_item { | |
179 | __le64 generation; | |
180 | __le64 size; | |
181 | __le64 nblocks; | |
31f3c99b | 182 | __le64 block_group; |
1e1d2701 CM |
183 | __le32 nlink; |
184 | __le32 uid; | |
185 | __le32 gid; | |
186 | __le32 mode; | |
187 | __le32 rdev; | |
188 | __le16 flags; | |
189 | __le16 compat_flags; | |
190 | struct btrfs_inode_timespec atime; | |
191 | struct btrfs_inode_timespec ctime; | |
192 | struct btrfs_inode_timespec mtime; | |
193 | struct btrfs_inode_timespec otime; | |
194 | } __attribute__ ((__packed__)); | |
195 | ||
62e2749e | 196 | struct btrfs_dir_item { |
d6e4a428 | 197 | struct btrfs_disk_key location; |
62e2749e | 198 | __le16 flags; |
a8a2ee0c | 199 | __le16 name_len; |
62e2749e CM |
200 | u8 type; |
201 | } __attribute__ ((__packed__)); | |
202 | ||
203 | struct btrfs_root_item { | |
d6e4a428 CM |
204 | struct btrfs_inode_item inode; |
205 | __le64 root_dirid; | |
62e2749e CM |
206 | __le64 blocknr; |
207 | __le32 flags; | |
208 | __le64 block_limit; | |
209 | __le64 blocks_used; | |
210 | __le32 refs; | |
9f5fae2f | 211 | } __attribute__ ((__packed__)); |
62e2749e | 212 | |
236454df CM |
213 | #define BTRFS_FILE_EXTENT_REG 0 |
214 | #define BTRFS_FILE_EXTENT_INLINE 1 | |
215 | ||
9f5fae2f | 216 | struct btrfs_file_extent_item { |
71951f35 | 217 | __le64 generation; |
236454df | 218 | u8 type; |
9f5fae2f CM |
219 | /* |
220 | * disk space consumed by the extent, checksum blocks are included | |
221 | * in these numbers | |
222 | */ | |
223 | __le64 disk_blocknr; | |
224 | __le64 disk_num_blocks; | |
225 | /* | |
dee26a9f | 226 | * the logical offset in file blocks (no csums) |
9f5fae2f CM |
227 | * this extent record is for. This allows a file extent to point |
228 | * into the middle of an existing extent on disk, sharing it | |
229 | * between two snapshots (useful if some bytes in the middle of the | |
230 | * extent have changed | |
231 | */ | |
232 | __le64 offset; | |
233 | /* | |
234 | * the logical number of file blocks (no csums included) | |
235 | */ | |
236 | __le64 num_blocks; | |
237 | } __attribute__ ((__packed__)); | |
238 | ||
f254e52c | 239 | struct btrfs_csum_item { |
509659cd | 240 | u8 csum; |
f254e52c CM |
241 | } __attribute__ ((__packed__)); |
242 | ||
0bd93ba0 CM |
243 | struct btrfs_device_item { |
244 | __le16 pathlen; | |
b4100d64 | 245 | __le64 device_id; |
0bd93ba0 CM |
246 | } __attribute__ ((__packed__)); |
247 | ||
9078a3e1 CM |
248 | /* tag for the radix tree of block groups in ram */ |
249 | #define BTRFS_BLOCK_GROUP_DIRTY 0 | |
31f3c99b | 250 | #define BTRFS_BLOCK_GROUP_AVAIL 1 |
9078a3e1 CM |
251 | #define BTRFS_BLOCK_GROUP_HINTS 8 |
252 | #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024) | |
253 | struct btrfs_block_group_item { | |
254 | __le64 used; | |
255 | } __attribute__ ((__packed__)); | |
256 | ||
257 | struct btrfs_block_group_cache { | |
258 | struct btrfs_key key; | |
259 | struct btrfs_block_group_item item; | |
3e1ad54f | 260 | struct radix_tree_root *radix; |
cd1bc465 CM |
261 | u64 first_free; |
262 | u64 last_alloc; | |
be744175 | 263 | u64 pinned; |
e37c9e69 | 264 | u64 last_prealloc; |
be744175 | 265 | int data; |
e37c9e69 | 266 | int cached; |
9078a3e1 CM |
267 | }; |
268 | ||
87cbda5c | 269 | struct crypto_hash; |
9f5fae2f | 270 | struct btrfs_fs_info { |
62e2749e CM |
271 | struct btrfs_root *extent_root; |
272 | struct btrfs_root *tree_root; | |
0bd93ba0 | 273 | struct btrfs_root *dev_root; |
0f7d52f4 | 274 | struct radix_tree_root fs_roots_radix; |
8ef97622 | 275 | struct radix_tree_root pending_del_radix; |
62e2749e | 276 | struct radix_tree_root pinned_radix; |
7eccb903 | 277 | struct radix_tree_root dev_radix; |
9078a3e1 | 278 | struct radix_tree_root block_group_radix; |
be744175 | 279 | struct radix_tree_root block_group_data_radix; |
e37c9e69 | 280 | struct radix_tree_root extent_map_radix; |
f2458e1d CM |
281 | |
282 | u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3]; | |
283 | int extent_tree_insert_nr; | |
284 | u64 extent_tree_prealloc[BTRFS_MAX_LEVEL * 3]; | |
285 | int extent_tree_prealloc_nr; | |
286 | ||
293ffd5f | 287 | u64 generation; |
79154b1b | 288 | struct btrfs_transaction *running_transaction; |
1261ec42 | 289 | struct btrfs_super_block *disk_super; |
e20d96d6 CM |
290 | struct buffer_head *sb_buffer; |
291 | struct super_block *sb; | |
d98237b3 | 292 | struct inode *btree_inode; |
79154b1b | 293 | struct mutex trans_mutex; |
d561c025 | 294 | struct mutex fs_mutex; |
8fd17795 | 295 | struct list_head trans_list; |
87cbda5c CM |
296 | struct crypto_hash *hash_tfm; |
297 | spinlock_t hash_lock; | |
e66f709b | 298 | int do_barriers; |
d6e4a428 | 299 | struct kobject kobj; |
9f5fae2f CM |
300 | }; |
301 | ||
302 | /* | |
303 | * in ram representation of the tree. extent_root is used for all allocations | |
f2458e1d | 304 | * and for the extent tree extent_root root. |
9f5fae2f CM |
305 | */ |
306 | struct btrfs_root { | |
e20d96d6 CM |
307 | struct buffer_head *node; |
308 | struct buffer_head *commit_root; | |
62e2749e CM |
309 | struct btrfs_root_item root_item; |
310 | struct btrfs_key root_key; | |
9f5fae2f | 311 | struct btrfs_fs_info *fs_info; |
0f7d52f4 CM |
312 | struct inode *inode; |
313 | u64 objectid; | |
314 | u64 last_trans; | |
62e2749e | 315 | u32 blocksize; |
9f5fae2f CM |
316 | int ref_cows; |
317 | u32 type; | |
1b05da2e CM |
318 | u64 highest_inode; |
319 | u64 last_inode_alloc; | |
62e2749e CM |
320 | }; |
321 | ||
62e2749e CM |
322 | /* the lower bits in the key flags defines the item type */ |
323 | #define BTRFS_KEY_TYPE_MAX 256 | |
a429e513 CM |
324 | #define BTRFS_KEY_TYPE_SHIFT 24 |
325 | #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \ | |
326 | BTRFS_KEY_TYPE_SHIFT) | |
1e1d2701 CM |
327 | |
328 | /* | |
329 | * inode items have the data typically returned from stat and store other | |
330 | * info about object characteristics. There is one for every file and dir in | |
331 | * the FS | |
332 | */ | |
9078a3e1 CM |
333 | #define BTRFS_INODE_ITEM_KEY 1 |
334 | ||
335 | /* reserve 2-15 close to the inode for later flexibility */ | |
1e1d2701 CM |
336 | |
337 | /* | |
338 | * dir items are the name -> inode pointers in a directory. There is one | |
339 | * for every name in a directory. | |
340 | */ | |
9078a3e1 CM |
341 | #define BTRFS_DIR_ITEM_KEY 16 |
342 | #define BTRFS_DIR_INDEX_KEY 17 | |
1e1d2701 | 343 | /* |
9078a3e1 | 344 | * extent data is for file data |
1e1d2701 | 345 | */ |
9078a3e1 | 346 | #define BTRFS_EXTENT_DATA_KEY 18 |
f254e52c CM |
347 | /* |
348 | * csum items have the checksums for data in the extents | |
349 | */ | |
9078a3e1 CM |
350 | #define BTRFS_CSUM_ITEM_KEY 19 |
351 | ||
352 | /* reserve 20-31 for other file stuff */ | |
f254e52c | 353 | |
1e1d2701 CM |
354 | /* |
355 | * root items point to tree roots. There are typically in the root | |
356 | * tree used by the super block to find all the other trees | |
357 | */ | |
9078a3e1 | 358 | #define BTRFS_ROOT_ITEM_KEY 32 |
1e1d2701 CM |
359 | /* |
360 | * extent items are in the extent map tree. These record which blocks | |
361 | * are used, and how many references there are to each block | |
362 | */ | |
9078a3e1 CM |
363 | #define BTRFS_EXTENT_ITEM_KEY 33 |
364 | ||
365 | /* | |
366 | * block groups give us hints into the extent allocation trees. Which | |
367 | * blocks are free etc etc | |
368 | */ | |
369 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 34 | |
9f5fae2f | 370 | |
0bd93ba0 CM |
371 | /* |
372 | * dev items list the devices that make up the FS | |
373 | */ | |
9078a3e1 | 374 | #define BTRFS_DEV_ITEM_KEY 35 |
0bd93ba0 | 375 | |
1e1d2701 CM |
376 | /* |
377 | * string items are for debugging. They just store a short string of | |
378 | * data in the FS | |
379 | */ | |
9078a3e1 CM |
380 | #define BTRFS_STRING_ITEM_KEY 253 |
381 | ||
382 | ||
383 | static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi) | |
384 | { | |
385 | return le64_to_cpu(bi->used); | |
386 | } | |
387 | ||
388 | static inline void btrfs_set_block_group_used(struct | |
389 | btrfs_block_group_item *bi, | |
390 | u64 val) | |
391 | { | |
392 | bi->used = cpu_to_le64(val); | |
393 | } | |
1e1d2701 CM |
394 | |
395 | static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) | |
396 | { | |
397 | return le64_to_cpu(i->generation); | |
398 | } | |
399 | ||
400 | static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i, | |
401 | u64 val) | |
402 | { | |
403 | i->generation = cpu_to_le64(val); | |
404 | } | |
405 | ||
406 | static inline u64 btrfs_inode_size(struct btrfs_inode_item *i) | |
407 | { | |
408 | return le64_to_cpu(i->size); | |
409 | } | |
410 | ||
411 | static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val) | |
412 | { | |
413 | i->size = cpu_to_le64(val); | |
414 | } | |
415 | ||
416 | static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i) | |
417 | { | |
418 | return le64_to_cpu(i->nblocks); | |
419 | } | |
420 | ||
421 | static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val) | |
422 | { | |
423 | i->nblocks = cpu_to_le64(val); | |
424 | } | |
425 | ||
31f3c99b CM |
426 | static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i) |
427 | { | |
428 | return le64_to_cpu(i->block_group); | |
429 | } | |
430 | ||
431 | static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i, | |
432 | u64 val) | |
433 | { | |
434 | i->block_group = cpu_to_le64(val); | |
435 | } | |
436 | ||
1e1d2701 CM |
437 | static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i) |
438 | { | |
439 | return le32_to_cpu(i->nlink); | |
440 | } | |
441 | ||
442 | static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val) | |
443 | { | |
444 | i->nlink = cpu_to_le32(val); | |
445 | } | |
446 | ||
447 | static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i) | |
448 | { | |
449 | return le32_to_cpu(i->uid); | |
450 | } | |
451 | ||
452 | static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val) | |
453 | { | |
454 | i->uid = cpu_to_le32(val); | |
455 | } | |
456 | ||
457 | static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i) | |
458 | { | |
459 | return le32_to_cpu(i->gid); | |
460 | } | |
461 | ||
462 | static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val) | |
463 | { | |
464 | i->gid = cpu_to_le32(val); | |
465 | } | |
466 | ||
467 | static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i) | |
468 | { | |
469 | return le32_to_cpu(i->mode); | |
470 | } | |
471 | ||
472 | static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val) | |
473 | { | |
474 | i->mode = cpu_to_le32(val); | |
475 | } | |
476 | ||
477 | static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i) | |
478 | { | |
479 | return le32_to_cpu(i->rdev); | |
480 | } | |
481 | ||
482 | static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val) | |
483 | { | |
484 | i->rdev = cpu_to_le32(val); | |
485 | } | |
486 | ||
487 | static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i) | |
488 | { | |
489 | return le16_to_cpu(i->flags); | |
490 | } | |
491 | ||
492 | static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val) | |
493 | { | |
494 | i->flags = cpu_to_le16(val); | |
495 | } | |
496 | ||
497 | static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i) | |
498 | { | |
499 | return le16_to_cpu(i->compat_flags); | |
500 | } | |
501 | ||
502 | static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i, | |
503 | u16 val) | |
504 | { | |
505 | i->compat_flags = cpu_to_le16(val); | |
506 | } | |
507 | ||
f254e52c | 508 | static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts) |
e20d96d6 | 509 | { |
f254e52c | 510 | return le64_to_cpu(ts->sec); |
e20d96d6 CM |
511 | } |
512 | ||
513 | static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts, | |
f254e52c | 514 | u64 val) |
e20d96d6 | 515 | { |
f254e52c | 516 | ts->sec = cpu_to_le64(val); |
e20d96d6 CM |
517 | } |
518 | ||
519 | static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts) | |
520 | { | |
521 | return le32_to_cpu(ts->nsec); | |
522 | } | |
523 | ||
524 | static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts, | |
525 | u32 val) | |
526 | { | |
527 | ts->nsec = cpu_to_le32(val); | |
528 | } | |
529 | ||
234b63a0 | 530 | static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei) |
cf27e1ee CM |
531 | { |
532 | return le32_to_cpu(ei->refs); | |
533 | } | |
534 | ||
234b63a0 | 535 | static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) |
cf27e1ee CM |
536 | { |
537 | ei->refs = cpu_to_le32(val); | |
538 | } | |
539 | ||
4d775673 CM |
540 | static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) |
541 | { | |
542 | return le64_to_cpu(ei->owner); | |
543 | } | |
544 | ||
545 | static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val) | |
546 | { | |
547 | ei->owner = cpu_to_le64(val); | |
548 | } | |
549 | ||
234b63a0 | 550 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) |
1d4f8a0c | 551 | { |
123abc88 | 552 | return le64_to_cpu(n->ptrs[nr].blockptr); |
1d4f8a0c CM |
553 | } |
554 | ||
4d775673 | 555 | |
234b63a0 CM |
556 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, |
557 | u64 val) | |
1d4f8a0c | 558 | { |
123abc88 | 559 | n->ptrs[nr].blockptr = cpu_to_le64(val); |
1d4f8a0c CM |
560 | } |
561 | ||
123abc88 | 562 | static inline u32 btrfs_item_offset(struct btrfs_item *item) |
0783fcfc | 563 | { |
123abc88 | 564 | return le32_to_cpu(item->offset); |
0783fcfc CM |
565 | } |
566 | ||
123abc88 | 567 | static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val) |
0783fcfc | 568 | { |
123abc88 | 569 | item->offset = cpu_to_le32(val); |
0783fcfc CM |
570 | } |
571 | ||
123abc88 | 572 | static inline u32 btrfs_item_end(struct btrfs_item *item) |
0783fcfc | 573 | { |
123abc88 | 574 | return le32_to_cpu(item->offset) + le16_to_cpu(item->size); |
0783fcfc CM |
575 | } |
576 | ||
577 | static inline u16 btrfs_item_size(struct btrfs_item *item) | |
578 | { | |
579 | return le16_to_cpu(item->size); | |
580 | } | |
581 | ||
582 | static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val) | |
583 | { | |
584 | item->size = cpu_to_le16(val); | |
585 | } | |
586 | ||
1d4f6404 CM |
587 | static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) |
588 | { | |
589 | return le16_to_cpu(d->flags); | |
590 | } | |
591 | ||
592 | static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) | |
593 | { | |
594 | d->flags = cpu_to_le16(val); | |
595 | } | |
596 | ||
597 | static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) | |
598 | { | |
599 | return d->type; | |
600 | } | |
601 | ||
602 | static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) | |
603 | { | |
604 | d->type = val; | |
605 | } | |
606 | ||
a8a2ee0c CM |
607 | static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d) |
608 | { | |
609 | return le16_to_cpu(d->name_len); | |
610 | } | |
611 | ||
612 | static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val) | |
1d4f6404 | 613 | { |
a8a2ee0c | 614 | d->name_len = cpu_to_le16(val); |
1d4f6404 CM |
615 | } |
616 | ||
e2fa7227 CM |
617 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
618 | struct btrfs_disk_key *disk) | |
619 | { | |
620 | cpu->offset = le64_to_cpu(disk->offset); | |
621 | cpu->flags = le32_to_cpu(disk->flags); | |
622 | cpu->objectid = le64_to_cpu(disk->objectid); | |
623 | } | |
624 | ||
625 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |
626 | struct btrfs_key *cpu) | |
627 | { | |
628 | disk->offset = cpu_to_le64(cpu->offset); | |
629 | disk->flags = cpu_to_le32(cpu->flags); | |
630 | disk->objectid = cpu_to_le64(cpu->objectid); | |
631 | } | |
632 | ||
62e2749e | 633 | static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) |
e2fa7227 CM |
634 | { |
635 | return le64_to_cpu(disk->objectid); | |
636 | } | |
637 | ||
62e2749e CM |
638 | static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk, |
639 | u64 val) | |
e2fa7227 CM |
640 | { |
641 | disk->objectid = cpu_to_le64(val); | |
642 | } | |
643 | ||
62e2749e | 644 | static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk) |
e2fa7227 CM |
645 | { |
646 | return le64_to_cpu(disk->offset); | |
647 | } | |
648 | ||
62e2749e CM |
649 | static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk, |
650 | u64 val) | |
e2fa7227 CM |
651 | { |
652 | disk->offset = cpu_to_le64(val); | |
653 | } | |
654 | ||
62e2749e | 655 | static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk) |
e2fa7227 CM |
656 | { |
657 | return le32_to_cpu(disk->flags); | |
658 | } | |
659 | ||
62e2749e CM |
660 | static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk, |
661 | u32 val) | |
e2fa7227 CM |
662 | { |
663 | disk->flags = cpu_to_le32(val); | |
664 | } | |
665 | ||
a429e513 | 666 | static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key) |
7fcde0e3 | 667 | { |
a429e513 | 668 | return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT; |
7fcde0e3 CM |
669 | } |
670 | ||
a429e513 CM |
671 | static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, |
672 | u32 val) | |
7fcde0e3 | 673 | { |
a429e513 CM |
674 | u32 flags = btrfs_disk_key_flags(key); |
675 | BUG_ON(val >= BTRFS_KEY_TYPE_MAX); | |
676 | val = val << BTRFS_KEY_TYPE_SHIFT; | |
677 | flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val; | |
678 | btrfs_set_disk_key_flags(key, flags); | |
7fcde0e3 CM |
679 | } |
680 | ||
62e2749e CM |
681 | static inline u32 btrfs_key_type(struct btrfs_key *key) |
682 | { | |
a429e513 | 683 | return key->flags >> BTRFS_KEY_TYPE_SHIFT; |
62e2749e CM |
684 | } |
685 | ||
a429e513 | 686 | static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val) |
62e2749e | 687 | { |
a429e513 CM |
688 | BUG_ON(val >= BTRFS_KEY_TYPE_MAX); |
689 | val = val << BTRFS_KEY_TYPE_SHIFT; | |
690 | key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val; | |
62e2749e CM |
691 | } |
692 | ||
bb492bb0 | 693 | static inline u64 btrfs_header_blocknr(struct btrfs_header *h) |
7518a238 | 694 | { |
bb492bb0 | 695 | return le64_to_cpu(h->blocknr); |
7518a238 CM |
696 | } |
697 | ||
bb492bb0 | 698 | static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr) |
7518a238 | 699 | { |
bb492bb0 | 700 | h->blocknr = cpu_to_le64(blocknr); |
7518a238 CM |
701 | } |
702 | ||
7f5c1516 CM |
703 | static inline u64 btrfs_header_generation(struct btrfs_header *h) |
704 | { | |
705 | return le64_to_cpu(h->generation); | |
706 | } | |
707 | ||
708 | static inline void btrfs_set_header_generation(struct btrfs_header *h, | |
709 | u64 val) | |
710 | { | |
711 | h->generation = cpu_to_le64(val); | |
712 | } | |
713 | ||
4d775673 CM |
714 | static inline u64 btrfs_header_owner(struct btrfs_header *h) |
715 | { | |
716 | return le64_to_cpu(h->owner); | |
717 | } | |
718 | ||
719 | static inline void btrfs_set_header_owner(struct btrfs_header *h, | |
720 | u64 val) | |
721 | { | |
722 | h->owner = cpu_to_le64(val); | |
723 | } | |
724 | ||
bb492bb0 | 725 | static inline u16 btrfs_header_nritems(struct btrfs_header *h) |
7518a238 | 726 | { |
bb492bb0 | 727 | return le16_to_cpu(h->nritems); |
7518a238 CM |
728 | } |
729 | ||
bb492bb0 | 730 | static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val) |
7518a238 | 731 | { |
bb492bb0 | 732 | h->nritems = cpu_to_le16(val); |
7518a238 CM |
733 | } |
734 | ||
bb492bb0 | 735 | static inline u16 btrfs_header_flags(struct btrfs_header *h) |
7518a238 | 736 | { |
bb492bb0 | 737 | return le16_to_cpu(h->flags); |
7518a238 CM |
738 | } |
739 | ||
bb492bb0 | 740 | static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val) |
7518a238 | 741 | { |
bb492bb0 | 742 | h->flags = cpu_to_le16(val); |
7518a238 CM |
743 | } |
744 | ||
bb492bb0 | 745 | static inline int btrfs_header_level(struct btrfs_header *h) |
7518a238 | 746 | { |
9a6f11ed | 747 | return h->level; |
7518a238 CM |
748 | } |
749 | ||
bb492bb0 | 750 | static inline void btrfs_set_header_level(struct btrfs_header *h, int level) |
7518a238 | 751 | { |
234b63a0 | 752 | BUG_ON(level > BTRFS_MAX_LEVEL); |
9a6f11ed | 753 | h->level = level; |
7518a238 CM |
754 | } |
755 | ||
234b63a0 | 756 | static inline int btrfs_is_leaf(struct btrfs_node *n) |
7518a238 CM |
757 | { |
758 | return (btrfs_header_level(&n->header) == 0); | |
759 | } | |
760 | ||
3768f368 CM |
761 | static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item) |
762 | { | |
763 | return le64_to_cpu(item->blocknr); | |
764 | } | |
765 | ||
766 | static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val) | |
767 | { | |
768 | item->blocknr = cpu_to_le64(val); | |
769 | } | |
770 | ||
d6e4a428 CM |
771 | static inline u64 btrfs_root_dirid(struct btrfs_root_item *item) |
772 | { | |
773 | return le64_to_cpu(item->root_dirid); | |
774 | } | |
775 | ||
776 | static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val) | |
777 | { | |
778 | item->root_dirid = cpu_to_le64(val); | |
779 | } | |
780 | ||
3768f368 CM |
781 | static inline u32 btrfs_root_refs(struct btrfs_root_item *item) |
782 | { | |
783 | return le32_to_cpu(item->refs); | |
784 | } | |
785 | ||
786 | static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val) | |
787 | { | |
788 | item->refs = cpu_to_le32(val); | |
789 | } | |
790 | ||
791 | static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) | |
792 | { | |
793 | return le64_to_cpu(s->blocknr); | |
794 | } | |
795 | ||
796 | static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val) | |
797 | { | |
798 | s->blocknr = cpu_to_le64(val); | |
799 | } | |
800 | ||
0f7d52f4 CM |
801 | static inline u64 btrfs_super_generation(struct btrfs_super_block *s) |
802 | { | |
803 | return le64_to_cpu(s->generation); | |
804 | } | |
805 | ||
806 | static inline void btrfs_set_super_generation(struct btrfs_super_block *s, | |
807 | u64 val) | |
808 | { | |
809 | s->generation = cpu_to_le64(val); | |
810 | } | |
811 | ||
3768f368 CM |
812 | static inline u64 btrfs_super_root(struct btrfs_super_block *s) |
813 | { | |
814 | return le64_to_cpu(s->root); | |
815 | } | |
816 | ||
817 | static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val) | |
818 | { | |
819 | s->root = cpu_to_le64(val); | |
820 | } | |
821 | ||
822 | static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s) | |
823 | { | |
824 | return le64_to_cpu(s->total_blocks); | |
825 | } | |
826 | ||
827 | static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s, | |
828 | u64 val) | |
829 | { | |
830 | s->total_blocks = cpu_to_le64(val); | |
831 | } | |
832 | ||
833 | static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s) | |
834 | { | |
835 | return le64_to_cpu(s->blocks_used); | |
836 | } | |
837 | ||
838 | static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, | |
839 | u64 val) | |
840 | { | |
841 | s->blocks_used = cpu_to_le64(val); | |
842 | } | |
843 | ||
123abc88 | 844 | static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) |
3768f368 | 845 | { |
123abc88 | 846 | return le32_to_cpu(s->blocksize); |
3768f368 CM |
847 | } |
848 | ||
849 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, | |
123abc88 CM |
850 | u32 val) |
851 | { | |
852 | s->blocksize = cpu_to_le32(val); | |
853 | } | |
854 | ||
2e635a27 CM |
855 | static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s) |
856 | { | |
857 | return le64_to_cpu(s->root_dir_objectid); | |
858 | } | |
859 | ||
860 | static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64 | |
861 | val) | |
862 | { | |
863 | s->root_dir_objectid = cpu_to_le64(val); | |
864 | } | |
865 | ||
b4100d64 CM |
866 | static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s) |
867 | { | |
868 | return le64_to_cpu(s->last_device_id); | |
869 | } | |
870 | ||
871 | static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s, | |
872 | u64 val) | |
873 | { | |
874 | s->last_device_id = cpu_to_le64(val); | |
875 | } | |
876 | ||
877 | static inline u64 btrfs_super_device_id(struct btrfs_super_block *s) | |
878 | { | |
879 | return le64_to_cpu(s->device_id); | |
880 | } | |
881 | ||
882 | static inline void btrfs_set_super_device_id(struct btrfs_super_block *s, | |
883 | u64 val) | |
884 | { | |
885 | s->device_id = cpu_to_le64(val); | |
886 | } | |
887 | ||
0bd93ba0 CM |
888 | static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s) |
889 | { | |
890 | return le64_to_cpu(s->device_block_start); | |
891 | } | |
892 | ||
893 | static inline void btrfs_set_super_device_block_start(struct btrfs_super_block | |
894 | *s, u64 val) | |
895 | { | |
896 | s->device_block_start = cpu_to_le64(val); | |
897 | } | |
898 | ||
899 | static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s) | |
900 | { | |
901 | return le64_to_cpu(s->device_num_blocks); | |
902 | } | |
903 | ||
904 | static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block | |
905 | *s, u64 val) | |
906 | { | |
907 | s->device_num_blocks = cpu_to_le64(val); | |
908 | } | |
909 | ||
910 | static inline u64 btrfs_super_device_root(struct btrfs_super_block *s) | |
911 | { | |
912 | return le64_to_cpu(s->device_root); | |
913 | } | |
914 | ||
915 | static inline void btrfs_set_super_device_root(struct btrfs_super_block | |
916 | *s, u64 val) | |
917 | { | |
918 | s->device_root = cpu_to_le64(val); | |
919 | } | |
920 | ||
921 | ||
123abc88 | 922 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) |
3768f368 | 923 | { |
123abc88 | 924 | return (u8 *)l->items; |
3768f368 | 925 | } |
9f5fae2f | 926 | |
236454df CM |
927 | static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e) |
928 | { | |
929 | return e->type; | |
930 | } | |
931 | static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e, | |
932 | u8 val) | |
933 | { | |
934 | e->type = val; | |
935 | } | |
936 | ||
937 | static inline char *btrfs_file_extent_inline_start(struct | |
938 | btrfs_file_extent_item *e) | |
939 | { | |
940 | return (char *)(&e->disk_blocknr); | |
941 | } | |
942 | ||
943 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) | |
944 | { | |
945 | return (unsigned long)(&((struct | |
946 | btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize; | |
947 | } | |
948 | ||
949 | static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e) | |
950 | { | |
951 | struct btrfs_file_extent_item *fe = NULL; | |
952 | return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr); | |
953 | } | |
954 | ||
9f5fae2f CM |
955 | static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item |
956 | *e) | |
957 | { | |
958 | return le64_to_cpu(e->disk_blocknr); | |
959 | } | |
960 | ||
961 | static inline void btrfs_set_file_extent_disk_blocknr(struct | |
962 | btrfs_file_extent_item | |
963 | *e, u64 val) | |
964 | { | |
965 | e->disk_blocknr = cpu_to_le64(val); | |
966 | } | |
967 | ||
71951f35 CM |
968 | static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e) |
969 | { | |
970 | return le64_to_cpu(e->generation); | |
971 | } | |
972 | ||
973 | static inline void btrfs_set_file_extent_generation(struct | |
974 | btrfs_file_extent_item *e, | |
975 | u64 val) | |
976 | { | |
977 | e->generation = cpu_to_le64(val); | |
978 | } | |
979 | ||
9f5fae2f CM |
980 | static inline u64 btrfs_file_extent_disk_num_blocks(struct |
981 | btrfs_file_extent_item *e) | |
982 | { | |
983 | return le64_to_cpu(e->disk_num_blocks); | |
984 | } | |
985 | ||
986 | static inline void btrfs_set_file_extent_disk_num_blocks(struct | |
987 | btrfs_file_extent_item | |
988 | *e, u64 val) | |
989 | { | |
990 | e->disk_num_blocks = cpu_to_le64(val); | |
991 | } | |
992 | ||
993 | static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e) | |
994 | { | |
995 | return le64_to_cpu(e->offset); | |
996 | } | |
997 | ||
998 | static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item | |
999 | *e, u64 val) | |
1000 | { | |
1001 | e->offset = cpu_to_le64(val); | |
1002 | } | |
1003 | ||
1004 | static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item | |
1005 | *e) | |
1006 | { | |
1007 | return le64_to_cpu(e->num_blocks); | |
1008 | } | |
1009 | ||
1010 | static inline void btrfs_set_file_extent_num_blocks(struct | |
1011 | btrfs_file_extent_item *e, | |
1012 | u64 val) | |
1013 | { | |
1014 | e->num_blocks = cpu_to_le64(val); | |
1015 | } | |
1016 | ||
0bd93ba0 CM |
1017 | static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d) |
1018 | { | |
1019 | return le16_to_cpu(d->pathlen); | |
1020 | } | |
1021 | ||
1022 | static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d, | |
1023 | u16 val) | |
1024 | { | |
1025 | d->pathlen = cpu_to_le16(val); | |
1026 | } | |
1027 | ||
b4100d64 CM |
1028 | static inline u64 btrfs_device_id(struct btrfs_device_item *d) |
1029 | { | |
1030 | return le64_to_cpu(d->device_id); | |
1031 | } | |
1032 | ||
1033 | static inline void btrfs_set_device_id(struct btrfs_device_item *d, | |
1034 | u64 val) | |
1035 | { | |
1036 | d->device_id = cpu_to_le64(val); | |
1037 | } | |
1038 | ||
e20d96d6 CM |
1039 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
1040 | { | |
1041 | return sb->s_fs_info; | |
1042 | } | |
1043 | ||
d6025579 CM |
1044 | static inline void btrfs_check_bounds(void *vptr, size_t len, |
1045 | void *vcontainer, size_t container_len) | |
1046 | { | |
1047 | char *ptr = vptr; | |
1048 | char *container = vcontainer; | |
1049 | WARN_ON(ptr < container); | |
1050 | WARN_ON(ptr + len > container + container_len); | |
1051 | } | |
1052 | ||
1053 | static inline void btrfs_memcpy(struct btrfs_root *root, | |
1054 | void *dst_block, | |
1055 | void *dst, const void *src, size_t nr) | |
1056 | { | |
1057 | btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize); | |
1058 | memcpy(dst, src, nr); | |
1059 | } | |
1060 | ||
1061 | static inline void btrfs_memmove(struct btrfs_root *root, | |
1062 | void *dst_block, | |
1063 | void *dst, void *src, size_t nr) | |
1064 | { | |
1065 | btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize); | |
1066 | memmove(dst, src, nr); | |
1067 | } | |
1068 | ||
1069 | static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh) | |
1070 | { | |
1071 | WARN_ON(!atomic_read(&bh->b_count)); | |
1072 | mark_buffer_dirty(bh); | |
1073 | } | |
1074 | ||
4beb1b8b CM |
1075 | /* helper function to cast into the data area of the leaf. */ |
1076 | #define btrfs_item_ptr(leaf, slot, type) \ | |
123abc88 CM |
1077 | ((type *)(btrfs_leaf_data(leaf) + \ |
1078 | btrfs_item_offset((leaf)->items + (slot)))) | |
4beb1b8b | 1079 | |
b18c6685 | 1080 | /* extent-tree.c */ |
31f3c99b CM |
1081 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, |
1082 | struct btrfs_block_group_cache | |
be744175 CM |
1083 | *hint, u64 search_start, |
1084 | int data); | |
c5739bba CM |
1085 | int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, |
1086 | struct btrfs_root *root); | |
e20d96d6 | 1087 | struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
31f3c99b | 1088 | struct btrfs_root *root, u64 hint); |
4d775673 CM |
1089 | int btrfs_alloc_extent(struct btrfs_trans_handle *trans, |
1090 | struct btrfs_root *root, u64 owner, | |
c62a1920 | 1091 | u64 num_blocks, u64 search_start, |
be08c1b9 | 1092 | u64 search_end, struct btrfs_key *ins, int data); |
e089f05c | 1093 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
e20d96d6 | 1094 | struct buffer_head *buf); |
e089f05c CM |
1095 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
1096 | *root, u64 blocknr, u64 num_blocks, int pin); | |
dee26a9f CM |
1097 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct |
1098 | btrfs_root *root); | |
b18c6685 CM |
1099 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
1100 | struct btrfs_root *root, | |
1101 | u64 blocknr, u64 num_blocks); | |
9078a3e1 CM |
1102 | int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, |
1103 | struct btrfs_root *root); | |
1104 | int btrfs_free_block_groups(struct btrfs_fs_info *info); | |
1105 | int btrfs_read_block_groups(struct btrfs_root *root); | |
dee26a9f | 1106 | /* ctree.c */ |
6567e837 CM |
1107 | int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root |
1108 | *root, struct btrfs_path *path, u32 data_size); | |
b18c6685 CM |
1109 | int btrfs_truncate_item(struct btrfs_trans_handle *trans, |
1110 | struct btrfs_root *root, | |
1111 | struct btrfs_path *path, | |
1112 | u32 new_size); | |
e089f05c CM |
1113 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
1114 | *root, struct btrfs_key *key, struct btrfs_path *p, int | |
1115 | ins_len, int cow); | |
234b63a0 | 1116 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
2c90e5d6 CM |
1117 | struct btrfs_path *btrfs_alloc_path(void); |
1118 | void btrfs_free_path(struct btrfs_path *p); | |
234b63a0 | 1119 | void btrfs_init_path(struct btrfs_path *p); |
e089f05c CM |
1120 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1121 | struct btrfs_path *path); | |
1122 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
1123 | *root, struct btrfs_key *key, void *data, u32 data_size); | |
1124 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
1125 | *root, struct btrfs_path *path, struct btrfs_key | |
1126 | *cpu_key, u32 data_size); | |
234b63a0 | 1127 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
123abc88 | 1128 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
e089f05c | 1129 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
e20d96d6 | 1130 | *root, struct buffer_head *snap); |
dee26a9f | 1131 | /* root-item.c */ |
e089f05c CM |
1132 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1133 | struct btrfs_key *key); | |
1134 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
1135 | *root, struct btrfs_key *key, struct btrfs_root_item | |
1136 | *item); | |
1137 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
1138 | *root, struct btrfs_key *key, struct btrfs_root_item | |
1139 | *item); | |
1140 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct | |
1141 | btrfs_root_item *item, struct btrfs_key *key); | |
dee26a9f | 1142 | /* dir-item.c */ |
e089f05c | 1143 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
1144 | *root, const char *name, int name_len, u64 dir, |
1145 | struct btrfs_key *location, u8 type); | |
7e38180e CM |
1146 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
1147 | struct btrfs_root *root, | |
1148 | struct btrfs_path *path, u64 dir, | |
1149 | const char *name, int name_len, | |
1150 | int mod); | |
1151 | struct btrfs_dir_item * | |
1152 | btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, | |
1153 | struct btrfs_root *root, | |
1154 | struct btrfs_path *path, u64 dir, | |
1155 | u64 objectid, const char *name, int name_len, | |
1156 | int mod); | |
1157 | struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, | |
1158 | struct btrfs_path *path, | |
7f5c1516 | 1159 | const char *name, int name_len); |
7e38180e CM |
1160 | int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
1161 | struct btrfs_root *root, | |
1162 | struct btrfs_path *path, | |
1163 | struct btrfs_dir_item *di); | |
dee26a9f | 1164 | /* inode-map.c */ |
9f5fae2f CM |
1165 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
1166 | struct btrfs_root *fs_root, | |
1167 | u64 dirid, u64 *objectid); | |
5be6f7f1 CM |
1168 | int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); |
1169 | ||
dee26a9f | 1170 | /* inode-item.c */ |
293ffd5f CM |
1171 | int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
1172 | *root, u64 objectid, struct btrfs_inode_item | |
1173 | *inode_item); | |
1174 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root | |
d6e4a428 CM |
1175 | *root, struct btrfs_path *path, |
1176 | struct btrfs_key *location, int mod); | |
dee26a9f CM |
1177 | |
1178 | /* file-item.c */ | |
b18c6685 | 1179 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
dee26a9f | 1180 | struct btrfs_root *root, |
b18c6685 CM |
1181 | u64 objectid, u64 pos, u64 offset, |
1182 | u64 num_blocks); | |
dee26a9f CM |
1183 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
1184 | struct btrfs_root *root, | |
1185 | struct btrfs_path *path, u64 objectid, | |
9773a788 | 1186 | u64 blocknr, int mod); |
f254e52c CM |
1187 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
1188 | struct btrfs_root *root, | |
1189 | u64 objectid, u64 offset, | |
1190 | char *data, size_t len); | |
1191 | int btrfs_csum_verify_file_block(struct btrfs_root *root, | |
1192 | u64 objectid, u64 offset, | |
1193 | char *data, size_t len); | |
b18c6685 CM |
1194 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
1195 | struct btrfs_root *root, | |
1196 | struct btrfs_path *path, | |
1197 | u64 objectid, u64 offset, | |
1198 | int cow); | |
d6e4a428 CM |
1199 | /* super.c */ |
1200 | extern struct subsystem btrfs_subsys; | |
1201 | ||
eb60ceac | 1202 | #endif |