]>
Commit | Line | Data |
---|---|---|
6cbd5570 CM |
1 | /* |
2 | * Copyright (C) 2007 Oracle. All rights reserved. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public | |
6 | * License v2 as published by the Free Software Foundation. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | * General Public License for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU General Public | |
14 | * License along with this program; if not, write to the | |
15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
16 | * Boston, MA 021110-1307, USA. | |
17 | */ | |
18 | ||
234b63a0 CM |
19 | #ifndef __BTRFS__ |
20 | #define __BTRFS__ | |
eb60ceac | 21 | |
6da6abae | 22 | #include <linux/version.h> |
810191ff CM |
23 | #include <linux/mm.h> |
24 | #include <linux/highmem.h> | |
e20d96d6 | 25 | #include <linux/fs.h> |
08607c1b | 26 | #include <linux/workqueue.h> |
58176a96 | 27 | #include <linux/completion.h> |
479965d6 | 28 | #include <asm/kmap_types.h> |
8ef97622 | 29 | #include "bit-radix.h" |
5f39d397 | 30 | #include "extent_map.h" |
e20d96d6 | 31 | |
e089f05c | 32 | struct btrfs_trans_handle; |
79154b1b | 33 | struct btrfs_transaction; |
35b7e476 CM |
34 | extern struct kmem_cache *btrfs_trans_handle_cachep; |
35 | extern struct kmem_cache *btrfs_transaction_cachep; | |
36 | extern struct kmem_cache *btrfs_bit_radix_cachep; | |
2c90e5d6 | 37 | extern struct kmem_cache *btrfs_path_cachep; |
e089f05c | 38 | |
5f39d397 | 39 | #define BTRFS_MAGIC "_B2RfS_M" |
eb60ceac | 40 | |
f6dbff55 | 41 | #define BTRFS_MAX_LEVEL 8 |
6407bf6d | 42 | #define BTRFS_ROOT_TREE_OBJECTID 1ULL |
0cf6c620 CM |
43 | #define BTRFS_EXTENT_TREE_OBJECTID 2ULL |
44 | #define BTRFS_FS_TREE_OBJECTID 3ULL | |
45 | #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL | |
f6dbff55 | 46 | #define BTRFS_FIRST_FREE_OBJECTID 256ULL |
3768f368 | 47 | |
e20d96d6 CM |
48 | /* |
49 | * we can actually store much bigger names, but lets not confuse the rest | |
50 | * of linux | |
51 | */ | |
52 | #define BTRFS_NAME_LEN 255 | |
53 | ||
f254e52c CM |
54 | /* 32 bytes in various csum fields */ |
55 | #define BTRFS_CSUM_SIZE 32 | |
509659cd CM |
56 | /* four bytes for CRC32 */ |
57 | #define BTRFS_CRC32_SIZE 4 | |
3954401f | 58 | #define BTRFS_EMPTY_DIR_SIZE 0 |
f254e52c | 59 | |
fabb5681 CM |
60 | #define BTRFS_FT_UNKNOWN 0 |
61 | #define BTRFS_FT_REG_FILE 1 | |
62 | #define BTRFS_FT_DIR 2 | |
63 | #define BTRFS_FT_CHRDEV 3 | |
64 | #define BTRFS_FT_BLKDEV 4 | |
65 | #define BTRFS_FT_FIFO 5 | |
66 | #define BTRFS_FT_SOCK 6 | |
67 | #define BTRFS_FT_SYMLINK 7 | |
5103e947 JB |
68 | #define BTRFS_FT_XATTR 8 |
69 | #define BTRFS_FT_MAX 9 | |
fabb5681 | 70 | |
fec577fb CM |
71 | /* |
72 | * the key defines the order in the tree, and so it also defines (optimal) | |
73 | * block layout. objectid corresonds to the inode number. The flags | |
74 | * tells us things about the object, and is a kind of stream selector. | |
75 | * so for a given inode, keys with flags of 1 might refer to the inode | |
76 | * data, flags of 2 may point to file data in the btree and flags == 3 | |
77 | * may point to extents. | |
78 | * | |
79 | * offset is the starting byte offset for this key in the stream. | |
e2fa7227 CM |
80 | * |
81 | * btrfs_disk_key is in disk byte order. struct btrfs_key is always | |
82 | * in cpu native order. Otherwise they are identical and their sizes | |
83 | * should be the same (ie both packed) | |
fec577fb | 84 | */ |
e2fa7227 CM |
85 | struct btrfs_disk_key { |
86 | __le64 objectid; | |
5f39d397 | 87 | u8 type; |
70b2befd | 88 | __le64 offset; |
e2fa7227 CM |
89 | } __attribute__ ((__packed__)); |
90 | ||
91 | struct btrfs_key { | |
eb60ceac | 92 | u64 objectid; |
5f39d397 | 93 | u8 type; |
70b2befd | 94 | u64 offset; |
eb60ceac CM |
95 | } __attribute__ ((__packed__)); |
96 | ||
5f39d397 | 97 | #define BTRFS_FSID_SIZE 16 |
fec577fb CM |
98 | /* |
99 | * every tree block (leaf or node) starts with this header. | |
100 | */ | |
bb492bb0 | 101 | struct btrfs_header { |
f254e52c | 102 | u8 csum[BTRFS_CSUM_SIZE]; |
5f39d397 | 103 | u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */ |
db94535d | 104 | __le64 bytenr; /* which block this node is supposed to live in */ |
7f5c1516 | 105 | __le64 generation; |
4d775673 | 106 | __le64 owner; |
5f39d397 | 107 | __le32 nritems; |
bb492bb0 | 108 | __le16 flags; |
9a6f11ed | 109 | u8 level; |
eb60ceac CM |
110 | } __attribute__ ((__packed__)); |
111 | ||
5f39d397 | 112 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \ |
123abc88 | 113 | sizeof(struct btrfs_header)) / \ |
74493f7a | 114 | sizeof(struct btrfs_key_ptr)) |
123abc88 | 115 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) |
5f39d397 | 116 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize)) |
236454df CM |
117 | #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ |
118 | sizeof(struct btrfs_item) - \ | |
119 | sizeof(struct btrfs_file_extent_item)) | |
eb60ceac | 120 | |
fec577fb CM |
121 | /* |
122 | * the super block basically lists the main trees of the FS | |
123 | * it currently lacks any block count etc etc | |
124 | */ | |
234b63a0 | 125 | struct btrfs_super_block { |
f254e52c | 126 | u8 csum[BTRFS_CSUM_SIZE]; |
87cbda5c | 127 | /* the first 3 fields must match struct btrfs_header */ |
3768f368 | 128 | u8 fsid[16]; /* FS specific uuid */ |
db94535d | 129 | __le64 bytenr; /* this block number */ |
3768f368 | 130 | __le64 magic; |
3768f368 CM |
131 | __le64 generation; |
132 | __le64 root; | |
db94535d CM |
133 | __le64 total_bytes; |
134 | __le64 bytes_used; | |
2e635a27 | 135 | __le64 root_dir_objectid; |
5f39d397 CM |
136 | __le32 sectorsize; |
137 | __le32 nodesize; | |
138 | __le32 leafsize; | |
87ee04eb | 139 | __le32 stripesize; |
db94535d | 140 | u8 root_level; |
cfaa7295 CM |
141 | } __attribute__ ((__packed__)); |
142 | ||
fec577fb | 143 | /* |
62e2749e | 144 | * A leaf is full of items. offset and size tell us where to find |
fec577fb CM |
145 | * the item in the leaf (relative to the start of the data area) |
146 | */ | |
0783fcfc | 147 | struct btrfs_item { |
e2fa7227 | 148 | struct btrfs_disk_key key; |
123abc88 | 149 | __le32 offset; |
5f39d397 | 150 | __le32 size; |
eb60ceac CM |
151 | } __attribute__ ((__packed__)); |
152 | ||
fec577fb CM |
153 | /* |
154 | * leaves have an item area and a data area: | |
155 | * [item0, item1....itemN] [free space] [dataN...data1, data0] | |
156 | * | |
157 | * The data is separate from the items to get the keys closer together | |
158 | * during searches. | |
159 | */ | |
234b63a0 | 160 | struct btrfs_leaf { |
bb492bb0 | 161 | struct btrfs_header header; |
123abc88 | 162 | struct btrfs_item items[]; |
eb60ceac CM |
163 | } __attribute__ ((__packed__)); |
164 | ||
fec577fb CM |
165 | /* |
166 | * all non-leaf blocks are nodes, they hold only keys and pointers to | |
167 | * other blocks | |
168 | */ | |
123abc88 CM |
169 | struct btrfs_key_ptr { |
170 | struct btrfs_disk_key key; | |
171 | __le64 blockptr; | |
74493f7a | 172 | __le64 generation; |
123abc88 CM |
173 | } __attribute__ ((__packed__)); |
174 | ||
234b63a0 | 175 | struct btrfs_node { |
bb492bb0 | 176 | struct btrfs_header header; |
123abc88 | 177 | struct btrfs_key_ptr ptrs[]; |
eb60ceac CM |
178 | } __attribute__ ((__packed__)); |
179 | ||
fec577fb | 180 | /* |
234b63a0 CM |
181 | * btrfs_paths remember the path taken from the root down to the leaf. |
182 | * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point | |
fec577fb CM |
183 | * to any other levels that are present. |
184 | * | |
185 | * The slots array records the index of the item or block pointer | |
186 | * used while walking the tree. | |
187 | */ | |
234b63a0 | 188 | struct btrfs_path { |
5f39d397 | 189 | struct extent_buffer *nodes[BTRFS_MAX_LEVEL]; |
234b63a0 | 190 | int slots[BTRFS_MAX_LEVEL]; |
3c69faec | 191 | int reada; |
6702ed49 | 192 | int lowest_level; |
eb60ceac | 193 | }; |
5de08d7d | 194 | |
62e2749e CM |
195 | /* |
196 | * items in the extent btree are used to record the objectid of the | |
197 | * owner of the block and the number of references | |
198 | */ | |
199 | struct btrfs_extent_item { | |
200 | __le32 refs; | |
74493f7a CM |
201 | } __attribute__ ((__packed__)); |
202 | ||
203 | struct btrfs_extent_ref { | |
204 | __le64 root; | |
205 | __le64 generation; | |
206 | __le64 objectid; | |
207 | __le64 offset; | |
62e2749e CM |
208 | } __attribute__ ((__packed__)); |
209 | ||
3954401f CM |
210 | struct btrfs_inode_ref { |
211 | __le16 name_len; | |
212 | /* name goes here */ | |
213 | } __attribute__ ((__packed__)); | |
214 | ||
1e1d2701 | 215 | struct btrfs_inode_timespec { |
f254e52c | 216 | __le64 sec; |
1e1d2701 CM |
217 | __le32 nsec; |
218 | } __attribute__ ((__packed__)); | |
219 | ||
220 | /* | |
221 | * there is no padding here on purpose. If you want to extent the inode, | |
222 | * make a new item type | |
223 | */ | |
224 | struct btrfs_inode_item { | |
225 | __le64 generation; | |
226 | __le64 size; | |
227 | __le64 nblocks; | |
31f3c99b | 228 | __le64 block_group; |
1e1d2701 CM |
229 | __le32 nlink; |
230 | __le32 uid; | |
231 | __le32 gid; | |
232 | __le32 mode; | |
233 | __le32 rdev; | |
234 | __le16 flags; | |
235 | __le16 compat_flags; | |
236 | struct btrfs_inode_timespec atime; | |
237 | struct btrfs_inode_timespec ctime; | |
238 | struct btrfs_inode_timespec mtime; | |
239 | struct btrfs_inode_timespec otime; | |
240 | } __attribute__ ((__packed__)); | |
241 | ||
62e2749e | 242 | struct btrfs_dir_item { |
d6e4a428 | 243 | struct btrfs_disk_key location; |
5103e947 | 244 | __le16 data_len; |
a8a2ee0c | 245 | __le16 name_len; |
62e2749e CM |
246 | u8 type; |
247 | } __attribute__ ((__packed__)); | |
248 | ||
249 | struct btrfs_root_item { | |
d6e4a428 CM |
250 | struct btrfs_inode_item inode; |
251 | __le64 root_dirid; | |
db94535d CM |
252 | __le64 bytenr; |
253 | __le64 byte_limit; | |
254 | __le64 bytes_used; | |
5eda7b5e | 255 | __le32 flags; |
62e2749e | 256 | __le32 refs; |
5eda7b5e CM |
257 | struct btrfs_disk_key drop_progress; |
258 | u8 drop_level; | |
db94535d | 259 | u8 level; |
9f5fae2f | 260 | } __attribute__ ((__packed__)); |
62e2749e | 261 | |
236454df CM |
262 | #define BTRFS_FILE_EXTENT_REG 0 |
263 | #define BTRFS_FILE_EXTENT_INLINE 1 | |
264 | ||
9f5fae2f | 265 | struct btrfs_file_extent_item { |
71951f35 | 266 | __le64 generation; |
236454df | 267 | u8 type; |
9f5fae2f CM |
268 | /* |
269 | * disk space consumed by the extent, checksum blocks are included | |
270 | * in these numbers | |
271 | */ | |
db94535d CM |
272 | __le64 disk_bytenr; |
273 | __le64 disk_num_bytes; | |
9f5fae2f | 274 | /* |
dee26a9f | 275 | * the logical offset in file blocks (no csums) |
9f5fae2f CM |
276 | * this extent record is for. This allows a file extent to point |
277 | * into the middle of an existing extent on disk, sharing it | |
278 | * between two snapshots (useful if some bytes in the middle of the | |
279 | * extent have changed | |
280 | */ | |
281 | __le64 offset; | |
282 | /* | |
283 | * the logical number of file blocks (no csums included) | |
284 | */ | |
db94535d | 285 | __le64 num_bytes; |
9f5fae2f CM |
286 | } __attribute__ ((__packed__)); |
287 | ||
f254e52c | 288 | struct btrfs_csum_item { |
509659cd | 289 | u8 csum; |
f254e52c CM |
290 | } __attribute__ ((__packed__)); |
291 | ||
9078a3e1 | 292 | /* tag for the radix tree of block groups in ram */ |
9078a3e1 | 293 | #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024) |
1e2677e0 CM |
294 | |
295 | ||
296 | #define BTRFS_BLOCK_GROUP_DATA 1 | |
f84a8b36 CM |
297 | #define BTRFS_BLOCK_GROUP_MIXED 2 |
298 | ||
9078a3e1 CM |
299 | struct btrfs_block_group_item { |
300 | __le64 used; | |
1e2677e0 | 301 | u8 flags; |
9078a3e1 CM |
302 | } __attribute__ ((__packed__)); |
303 | ||
304 | struct btrfs_block_group_cache { | |
305 | struct btrfs_key key; | |
306 | struct btrfs_block_group_item item; | |
be744175 | 307 | int data; |
e37c9e69 | 308 | int cached; |
324ae4df | 309 | u64 pinned; |
9078a3e1 | 310 | }; |
9f5fae2f | 311 | struct btrfs_fs_info { |
5f39d397 | 312 | u8 fsid[BTRFS_FSID_SIZE]; |
62e2749e CM |
313 | struct btrfs_root *extent_root; |
314 | struct btrfs_root *tree_root; | |
0f7d52f4 | 315 | struct radix_tree_root fs_roots_radix; |
1a5bc167 | 316 | |
f510cfec | 317 | struct extent_map_tree free_space_cache; |
96b5179d | 318 | struct extent_map_tree block_group_cache; |
1a5bc167 CM |
319 | struct extent_map_tree pinned_extents; |
320 | struct extent_map_tree pending_del; | |
321 | struct extent_map_tree extent_ins; | |
322 | ||
293ffd5f | 323 | u64 generation; |
15ee9bc7 | 324 | u64 last_trans_committed; |
b6cda9bc | 325 | unsigned long mount_opt; |
c59f8951 | 326 | u64 max_extent; |
8f662a76 | 327 | u64 alloc_start; |
79154b1b | 328 | struct btrfs_transaction *running_transaction; |
4b52dff6 | 329 | struct btrfs_super_block super_copy; |
5f39d397 | 330 | struct extent_buffer *sb_buffer; |
e20d96d6 | 331 | struct super_block *sb; |
d98237b3 | 332 | struct inode *btree_inode; |
19c00ddc | 333 | spinlock_t hash_lock; |
79154b1b | 334 | struct mutex trans_mutex; |
d561c025 | 335 | struct mutex fs_mutex; |
8fd17795 | 336 | struct list_head trans_list; |
19c00ddc | 337 | struct list_head hashers; |
facda1e7 | 338 | struct list_head dead_roots; |
6da6abae CM |
339 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) |
340 | struct work_struct trans_work; | |
341 | #else | |
08607c1b | 342 | struct delayed_work trans_work; |
6da6abae | 343 | #endif |
58176a96 JB |
344 | struct kobject super_kobj; |
345 | struct completion kobj_unregister; | |
e66f709b | 346 | int do_barriers; |
facda1e7 | 347 | int closing; |
9f5fae2f | 348 | |
324ae4df | 349 | u64 total_pinned; |
1832a6d5 CM |
350 | spinlock_t delalloc_lock; |
351 | u64 delalloc_bytes; | |
324ae4df | 352 | }; |
9f5fae2f CM |
353 | /* |
354 | * in ram representation of the tree. extent_root is used for all allocations | |
f2458e1d | 355 | * and for the extent tree extent_root root. |
9f5fae2f CM |
356 | */ |
357 | struct btrfs_root { | |
5f39d397 CM |
358 | struct extent_buffer *node; |
359 | struct extent_buffer *commit_root; | |
62e2749e CM |
360 | struct btrfs_root_item root_item; |
361 | struct btrfs_key root_key; | |
9f5fae2f | 362 | struct btrfs_fs_info *fs_info; |
0f7d52f4 | 363 | struct inode *inode; |
58176a96 JB |
364 | struct kobject root_kobj; |
365 | struct completion kobj_unregister; | |
011410bd | 366 | struct rw_semaphore snap_sem; |
0f7d52f4 CM |
367 | u64 objectid; |
368 | u64 last_trans; | |
5f39d397 CM |
369 | |
370 | /* data allocations are done in sectorsize units */ | |
371 | u32 sectorsize; | |
372 | ||
373 | /* node allocations are done in nodesize units */ | |
374 | u32 nodesize; | |
375 | ||
376 | /* leaf allocations are done in leafsize units */ | |
377 | u32 leafsize; | |
378 | ||
87ee04eb CM |
379 | u32 stripesize; |
380 | ||
9f5fae2f | 381 | u32 type; |
1b05da2e CM |
382 | u64 highest_inode; |
383 | u64 last_inode_alloc; | |
9f3a7427 | 384 | int ref_cows; |
6702ed49 CM |
385 | struct btrfs_key defrag_progress; |
386 | int defrag_running; | |
387 | int defrag_level; | |
58176a96 | 388 | char *name; |
62e2749e CM |
389 | }; |
390 | ||
1e1d2701 CM |
391 | /* |
392 | * inode items have the data typically returned from stat and store other | |
393 | * info about object characteristics. There is one for every file and dir in | |
394 | * the FS | |
395 | */ | |
9078a3e1 | 396 | #define BTRFS_INODE_ITEM_KEY 1 |
3954401f CM |
397 | #define BTRFS_INODE_REF_KEY 2 |
398 | #define BTRFS_XATTR_ITEM_KEY 8 | |
9078a3e1 | 399 | /* reserve 2-15 close to the inode for later flexibility */ |
1e1d2701 CM |
400 | |
401 | /* | |
402 | * dir items are the name -> inode pointers in a directory. There is one | |
403 | * for every name in a directory. | |
404 | */ | |
9078a3e1 CM |
405 | #define BTRFS_DIR_ITEM_KEY 16 |
406 | #define BTRFS_DIR_INDEX_KEY 17 | |
1e1d2701 | 407 | /* |
9078a3e1 | 408 | * extent data is for file data |
1e1d2701 | 409 | */ |
9078a3e1 | 410 | #define BTRFS_EXTENT_DATA_KEY 18 |
f254e52c CM |
411 | /* |
412 | * csum items have the checksums for data in the extents | |
413 | */ | |
9078a3e1 CM |
414 | #define BTRFS_CSUM_ITEM_KEY 19 |
415 | ||
416 | /* reserve 20-31 for other file stuff */ | |
f254e52c | 417 | |
1e1d2701 CM |
418 | /* |
419 | * root items point to tree roots. There are typically in the root | |
420 | * tree used by the super block to find all the other trees | |
421 | */ | |
9078a3e1 | 422 | #define BTRFS_ROOT_ITEM_KEY 32 |
1e1d2701 CM |
423 | /* |
424 | * extent items are in the extent map tree. These record which blocks | |
425 | * are used, and how many references there are to each block | |
426 | */ | |
9078a3e1 | 427 | #define BTRFS_EXTENT_ITEM_KEY 33 |
74493f7a | 428 | #define BTRFS_EXTENT_REF_KEY 34 |
9078a3e1 CM |
429 | |
430 | /* | |
431 | * block groups give us hints into the extent allocation trees. Which | |
432 | * blocks are free etc etc | |
433 | */ | |
74493f7a | 434 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 50 |
9f5fae2f | 435 | |
1e1d2701 CM |
436 | /* |
437 | * string items are for debugging. They just store a short string of | |
438 | * data in the FS | |
439 | */ | |
9078a3e1 CM |
440 | #define BTRFS_STRING_ITEM_KEY 253 |
441 | ||
b6cda9bc | 442 | #define BTRFS_MOUNT_NODATASUM 0x1 |
be20aa9d | 443 | #define BTRFS_MOUNT_NODATACOW 0x2 |
b6cda9bc CM |
444 | |
445 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | |
446 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | |
447 | #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \ | |
448 | BTRFS_MOUNT_##opt) | |
449 | ||
5f39d397 CM |
450 | /* some macros to generate set/get funcs for the struct fields. This |
451 | * assumes there is a lefoo_to_cpu for every type, so lets make a simple | |
452 | * one for u8: | |
453 | */ | |
454 | #define le8_to_cpu(v) (v) | |
455 | #define cpu_to_le8(v) (v) | |
456 | #define __le8 u8 | |
457 | ||
458 | #define read_eb_member(eb, ptr, type, member, result) ( \ | |
459 | read_extent_buffer(eb, (char *)(result), \ | |
460 | ((unsigned long)(ptr)) + \ | |
461 | offsetof(type, member), \ | |
462 | sizeof(((type *)0)->member))) | |
463 | ||
464 | #define write_eb_member(eb, ptr, type, member, result) ( \ | |
465 | write_extent_buffer(eb, (char *)(result), \ | |
466 | ((unsigned long)(ptr)) + \ | |
467 | offsetof(type, member), \ | |
468 | sizeof(((type *)0)->member))) | |
469 | ||
0f82731f | 470 | #ifndef BTRFS_SETGET_FUNCS |
5f39d397 | 471 | #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ |
0f82731f CM |
472 | u##bits btrfs_##name(struct extent_buffer *eb, type *s); \ |
473 | void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val); | |
474 | #endif | |
5f39d397 CM |
475 | |
476 | #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ | |
477 | static inline u##bits btrfs_##name(struct extent_buffer *eb) \ | |
478 | { \ | |
810191ff | 479 | char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \ |
6d36dcd4 | 480 | unsigned long offset = offsetof(type, member); \ |
810191ff CM |
481 | u##bits res; \ |
482 | __le##bits *tmp = (__le##bits *)(kaddr + offset); \ | |
483 | res = le##bits##_to_cpu(*tmp); \ | |
484 | kunmap_atomic(kaddr, KM_USER0); \ | |
485 | return res; \ | |
5f39d397 CM |
486 | } \ |
487 | static inline void btrfs_set_##name(struct extent_buffer *eb, \ | |
488 | u##bits val) \ | |
489 | { \ | |
810191ff | 490 | char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \ |
6d36dcd4 | 491 | unsigned long offset = offsetof(type, member); \ |
810191ff CM |
492 | __le##bits *tmp = (__le##bits *)(kaddr + offset); \ |
493 | *tmp = cpu_to_le##bits(val); \ | |
494 | kunmap_atomic(kaddr, KM_USER0); \ | |
5f39d397 | 495 | } |
9078a3e1 | 496 | |
5f39d397 CM |
497 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
498 | static inline u##bits btrfs_##name(type *s) \ | |
499 | { \ | |
500 | return le##bits##_to_cpu(s->member); \ | |
501 | } \ | |
502 | static inline void btrfs_set_##name(type *s, u##bits val) \ | |
503 | { \ | |
504 | s->member = cpu_to_le##bits(val); \ | |
1e1d2701 CM |
505 | } |
506 | ||
5f39d397 CM |
507 | /* struct btrfs_block_group_item */ |
508 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, | |
509 | used, 64); | |
510 | BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, | |
511 | used, 64); | |
edbd8d4e CM |
512 | BTRFS_SETGET_FUNCS(disk_block_group_flags, struct btrfs_block_group_item, |
513 | flags, 8); | |
1e1d2701 | 514 | |
3954401f CM |
515 | /* struct btrfs_inode_ref */ |
516 | BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); | |
517 | ||
5f39d397 CM |
518 | /* struct btrfs_inode_item */ |
519 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); | |
520 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); | |
521 | BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64); | |
522 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); | |
523 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); | |
524 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); | |
525 | BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); | |
526 | BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); | |
527 | BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32); | |
528 | BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16); | |
529 | BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item, | |
530 | compat_flags, 16); | |
1e1d2701 | 531 | |
5f39d397 CM |
532 | static inline struct btrfs_inode_timespec * |
533 | btrfs_inode_atime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 534 | { |
5f39d397 CM |
535 | unsigned long ptr = (unsigned long)inode_item; |
536 | ptr += offsetof(struct btrfs_inode_item, atime); | |
537 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
538 | } |
539 | ||
5f39d397 CM |
540 | static inline struct btrfs_inode_timespec * |
541 | btrfs_inode_mtime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 542 | { |
5f39d397 CM |
543 | unsigned long ptr = (unsigned long)inode_item; |
544 | ptr += offsetof(struct btrfs_inode_item, mtime); | |
545 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
546 | } |
547 | ||
5f39d397 CM |
548 | static inline struct btrfs_inode_timespec * |
549 | btrfs_inode_ctime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 550 | { |
5f39d397 CM |
551 | unsigned long ptr = (unsigned long)inode_item; |
552 | ptr += offsetof(struct btrfs_inode_item, ctime); | |
553 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
554 | } |
555 | ||
5f39d397 CM |
556 | static inline struct btrfs_inode_timespec * |
557 | btrfs_inode_otime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 558 | { |
5f39d397 CM |
559 | unsigned long ptr = (unsigned long)inode_item; |
560 | ptr += offsetof(struct btrfs_inode_item, otime); | |
561 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
562 | } |
563 | ||
5f39d397 CM |
564 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64); |
565 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32); | |
e20d96d6 | 566 | |
5f39d397 CM |
567 | /* struct btrfs_extent_item */ |
568 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32); | |
74493f7a CM |
569 | |
570 | /* struct btrfs_extent_ref */ | |
571 | BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64); | |
572 | BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64); | |
573 | BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64); | |
574 | BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64); | |
575 | ||
7bb86316 CM |
576 | BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64); |
577 | BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref, | |
74493f7a | 578 | generation, 64); |
7bb86316 CM |
579 | BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref, |
580 | objectid, 64); | |
581 | BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64); | |
e20d96d6 | 582 | |
5f39d397 CM |
583 | BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item, |
584 | refs, 32); | |
e20d96d6 | 585 | |
5f39d397 CM |
586 | /* struct btrfs_node */ |
587 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); | |
74493f7a | 588 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
e20d96d6 | 589 | |
5f39d397 | 590 | static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) |
cf27e1ee | 591 | { |
5f39d397 CM |
592 | unsigned long ptr; |
593 | ptr = offsetof(struct btrfs_node, ptrs) + | |
594 | sizeof(struct btrfs_key_ptr) * nr; | |
595 | return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); | |
cf27e1ee CM |
596 | } |
597 | ||
5f39d397 CM |
598 | static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, |
599 | int nr, u64 val) | |
cf27e1ee | 600 | { |
5f39d397 CM |
601 | unsigned long ptr; |
602 | ptr = offsetof(struct btrfs_node, ptrs) + | |
603 | sizeof(struct btrfs_key_ptr) * nr; | |
604 | btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); | |
cf27e1ee CM |
605 | } |
606 | ||
74493f7a CM |
607 | static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) |
608 | { | |
609 | unsigned long ptr; | |
610 | ptr = offsetof(struct btrfs_node, ptrs) + | |
611 | sizeof(struct btrfs_key_ptr) * nr; | |
612 | return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); | |
613 | } | |
614 | ||
615 | static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, | |
616 | int nr, u64 val) | |
617 | { | |
618 | unsigned long ptr; | |
619 | ptr = offsetof(struct btrfs_node, ptrs) + | |
620 | sizeof(struct btrfs_key_ptr) * nr; | |
621 | btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); | |
622 | } | |
623 | ||
810191ff | 624 | static inline unsigned long btrfs_node_key_ptr_offset(int nr) |
4d775673 | 625 | { |
5f39d397 CM |
626 | return offsetof(struct btrfs_node, ptrs) + |
627 | sizeof(struct btrfs_key_ptr) * nr; | |
4d775673 CM |
628 | } |
629 | ||
e644d021 CM |
630 | void btrfs_node_key(struct extent_buffer *eb, |
631 | struct btrfs_disk_key *disk_key, int nr); | |
632 | ||
5f39d397 CM |
633 | static inline void btrfs_set_node_key(struct extent_buffer *eb, |
634 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f8a0c | 635 | { |
5f39d397 CM |
636 | unsigned long ptr; |
637 | ptr = btrfs_node_key_ptr_offset(nr); | |
638 | write_eb_member(eb, (struct btrfs_key_ptr *)ptr, | |
639 | struct btrfs_key_ptr, key, disk_key); | |
1d4f8a0c CM |
640 | } |
641 | ||
5f39d397 CM |
642 | /* struct btrfs_item */ |
643 | BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32); | |
644 | BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32); | |
4d775673 | 645 | |
5f39d397 | 646 | static inline unsigned long btrfs_item_nr_offset(int nr) |
1d4f8a0c | 647 | { |
5f39d397 CM |
648 | return offsetof(struct btrfs_leaf, items) + |
649 | sizeof(struct btrfs_item) * nr; | |
1d4f8a0c CM |
650 | } |
651 | ||
5f39d397 CM |
652 | static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb, |
653 | int nr) | |
0783fcfc | 654 | { |
5f39d397 | 655 | return (struct btrfs_item *)btrfs_item_nr_offset(nr); |
0783fcfc CM |
656 | } |
657 | ||
5f39d397 CM |
658 | static inline u32 btrfs_item_end(struct extent_buffer *eb, |
659 | struct btrfs_item *item) | |
0783fcfc | 660 | { |
5f39d397 | 661 | return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item); |
0783fcfc CM |
662 | } |
663 | ||
5f39d397 | 664 | static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 665 | { |
5f39d397 | 666 | return btrfs_item_end(eb, btrfs_item_nr(eb, nr)); |
0783fcfc CM |
667 | } |
668 | ||
5f39d397 | 669 | static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 670 | { |
5f39d397 | 671 | return btrfs_item_offset(eb, btrfs_item_nr(eb, nr)); |
0783fcfc CM |
672 | } |
673 | ||
5f39d397 | 674 | static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 675 | { |
5f39d397 | 676 | return btrfs_item_size(eb, btrfs_item_nr(eb, nr)); |
0783fcfc CM |
677 | } |
678 | ||
5f39d397 CM |
679 | static inline void btrfs_item_key(struct extent_buffer *eb, |
680 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f6404 | 681 | { |
5f39d397 CM |
682 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
683 | read_eb_member(eb, item, struct btrfs_item, key, disk_key); | |
1d4f6404 CM |
684 | } |
685 | ||
5f39d397 CM |
686 | static inline void btrfs_set_item_key(struct extent_buffer *eb, |
687 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f6404 | 688 | { |
5f39d397 CM |
689 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
690 | write_eb_member(eb, item, struct btrfs_item, key, disk_key); | |
1d4f6404 CM |
691 | } |
692 | ||
5f39d397 | 693 | /* struct btrfs_dir_item */ |
5103e947 | 694 | BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); |
5f39d397 CM |
695 | BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); |
696 | BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); | |
1d4f6404 | 697 | |
5f39d397 CM |
698 | static inline void btrfs_dir_item_key(struct extent_buffer *eb, |
699 | struct btrfs_dir_item *item, | |
700 | struct btrfs_disk_key *key) | |
1d4f6404 | 701 | { |
5f39d397 | 702 | read_eb_member(eb, item, struct btrfs_dir_item, location, key); |
1d4f6404 CM |
703 | } |
704 | ||
5f39d397 CM |
705 | static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, |
706 | struct btrfs_dir_item *item, | |
707 | struct btrfs_disk_key *key) | |
a8a2ee0c | 708 | { |
5f39d397 | 709 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
a8a2ee0c CM |
710 | } |
711 | ||
5f39d397 CM |
712 | /* struct btrfs_disk_key */ |
713 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, | |
714 | objectid, 64); | |
715 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); | |
716 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); | |
1d4f6404 | 717 | |
e2fa7227 CM |
718 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
719 | struct btrfs_disk_key *disk) | |
720 | { | |
721 | cpu->offset = le64_to_cpu(disk->offset); | |
5f39d397 | 722 | cpu->type = disk->type; |
e2fa7227 CM |
723 | cpu->objectid = le64_to_cpu(disk->objectid); |
724 | } | |
725 | ||
726 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |
727 | struct btrfs_key *cpu) | |
728 | { | |
729 | disk->offset = cpu_to_le64(cpu->offset); | |
5f39d397 | 730 | disk->type = cpu->type; |
e2fa7227 CM |
731 | disk->objectid = cpu_to_le64(cpu->objectid); |
732 | } | |
733 | ||
5f39d397 CM |
734 | static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb, |
735 | struct btrfs_key *key, int nr) | |
7f5c1516 | 736 | { |
5f39d397 CM |
737 | struct btrfs_disk_key disk_key; |
738 | btrfs_node_key(eb, &disk_key, nr); | |
739 | btrfs_disk_key_to_cpu(key, &disk_key); | |
7f5c1516 CM |
740 | } |
741 | ||
5f39d397 CM |
742 | static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb, |
743 | struct btrfs_key *key, int nr) | |
7f5c1516 | 744 | { |
5f39d397 CM |
745 | struct btrfs_disk_key disk_key; |
746 | btrfs_item_key(eb, &disk_key, nr); | |
747 | btrfs_disk_key_to_cpu(key, &disk_key); | |
7f5c1516 CM |
748 | } |
749 | ||
5f39d397 CM |
750 | static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, |
751 | struct btrfs_dir_item *item, | |
752 | struct btrfs_key *key) | |
4d775673 | 753 | { |
5f39d397 CM |
754 | struct btrfs_disk_key disk_key; |
755 | btrfs_dir_item_key(eb, item, &disk_key); | |
756 | btrfs_disk_key_to_cpu(key, &disk_key); | |
4d775673 CM |
757 | } |
758 | ||
58176a96 | 759 | |
5f39d397 | 760 | static inline u8 btrfs_key_type(struct btrfs_key *key) |
3768f368 | 761 | { |
5f39d397 | 762 | return key->type; |
3768f368 CM |
763 | } |
764 | ||
5f39d397 | 765 | static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val) |
3768f368 | 766 | { |
5f39d397 | 767 | key->type = val; |
3768f368 CM |
768 | } |
769 | ||
5f39d397 | 770 | /* struct btrfs_header */ |
db94535d | 771 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
5f39d397 CM |
772 | BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, |
773 | generation, 64); | |
774 | BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); | |
775 | BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); | |
776 | BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16); | |
777 | BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); | |
0f7d52f4 | 778 | |
5f39d397 | 779 | static inline u8 *btrfs_header_fsid(struct extent_buffer *eb) |
0f7d52f4 | 780 | { |
5f39d397 CM |
781 | unsigned long ptr = offsetof(struct btrfs_header, fsid); |
782 | return (u8 *)ptr; | |
0f7d52f4 CM |
783 | } |
784 | ||
5f39d397 | 785 | static inline u8 *btrfs_super_fsid(struct extent_buffer *eb) |
3768f368 | 786 | { |
5f39d397 CM |
787 | unsigned long ptr = offsetof(struct btrfs_super_block, fsid); |
788 | return (u8 *)ptr; | |
3768f368 CM |
789 | } |
790 | ||
5f39d397 | 791 | static inline u8 *btrfs_header_csum(struct extent_buffer *eb) |
3768f368 | 792 | { |
5f39d397 CM |
793 | unsigned long ptr = offsetof(struct btrfs_header, csum); |
794 | return (u8 *)ptr; | |
3768f368 CM |
795 | } |
796 | ||
5f39d397 | 797 | static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb) |
3768f368 | 798 | { |
5f39d397 | 799 | return NULL; |
3768f368 CM |
800 | } |
801 | ||
5f39d397 | 802 | static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb) |
3768f368 | 803 | { |
5f39d397 | 804 | return NULL; |
3768f368 CM |
805 | } |
806 | ||
5f39d397 | 807 | static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb) |
3768f368 | 808 | { |
5f39d397 | 809 | return NULL; |
3768f368 CM |
810 | } |
811 | ||
5f39d397 | 812 | static inline int btrfs_is_leaf(struct extent_buffer *eb) |
3768f368 | 813 | { |
5f39d397 | 814 | return (btrfs_header_level(eb) == 0); |
3768f368 CM |
815 | } |
816 | ||
5f39d397 CM |
817 | /* struct btrfs_root_item */ |
818 | BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); | |
db94535d CM |
819 | BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); |
820 | BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); | |
3768f368 | 821 | |
db94535d CM |
822 | BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); |
823 | BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); | |
5f39d397 CM |
824 | BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); |
825 | BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); | |
826 | BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32); | |
db94535d CM |
827 | BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); |
828 | BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); | |
123abc88 | 829 | |
5f39d397 | 830 | /* struct btrfs_super_block */ |
db94535d | 831 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |
5f39d397 CM |
832 | BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, |
833 | generation, 64); | |
834 | BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); | |
db94535d CM |
835 | BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, |
836 | root_level, 8); | |
837 | BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, | |
838 | total_bytes, 64); | |
839 | BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, | |
840 | bytes_used, 64); | |
5f39d397 CM |
841 | BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, |
842 | sectorsize, 32); | |
843 | BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, | |
844 | nodesize, 32); | |
845 | BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block, | |
846 | leafsize, 32); | |
87ee04eb CM |
847 | BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, |
848 | stripesize, 32); | |
5f39d397 CM |
849 | BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, |
850 | root_dir_objectid, 64); | |
2e635a27 | 851 | |
5f39d397 | 852 | static inline unsigned long btrfs_leaf_data(struct extent_buffer *l) |
2e635a27 | 853 | { |
5f39d397 | 854 | return offsetof(struct btrfs_leaf, items); |
2e635a27 CM |
855 | } |
856 | ||
5f39d397 CM |
857 | /* struct btrfs_file_extent_item */ |
858 | BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); | |
9f5fae2f | 859 | |
5f39d397 | 860 | static inline unsigned long btrfs_file_extent_inline_start(struct |
236454df CM |
861 | btrfs_file_extent_item *e) |
862 | { | |
5f39d397 | 863 | unsigned long offset = (unsigned long)e; |
db94535d | 864 | offset += offsetof(struct btrfs_file_extent_item, disk_bytenr); |
5f39d397 | 865 | return offset; |
236454df CM |
866 | } |
867 | ||
868 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) | |
869 | { | |
db94535d | 870 | return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize; |
9f5fae2f CM |
871 | } |
872 | ||
5f39d397 CM |
873 | static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb, |
874 | struct btrfs_item *e) | |
9f5fae2f | 875 | { |
5f39d397 | 876 | unsigned long offset; |
db94535d | 877 | offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); |
5f39d397 | 878 | return btrfs_item_size(eb, e) - offset; |
9f5fae2f CM |
879 | } |
880 | ||
db94535d CM |
881 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
882 | disk_bytenr, 64); | |
5f39d397 CM |
883 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
884 | generation, 64); | |
db94535d CM |
885 | BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, |
886 | disk_num_bytes, 64); | |
5f39d397 CM |
887 | BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, |
888 | offset, 64); | |
db94535d CM |
889 | BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, |
890 | num_bytes, 64); | |
9f5fae2f | 891 | |
e20d96d6 CM |
892 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
893 | { | |
894 | return sb->s_fs_info; | |
895 | } | |
896 | ||
58176a96 JB |
897 | static inline int btrfs_set_root_name(struct btrfs_root *root, |
898 | const char *name, int len) | |
899 | { | |
900 | /* if we already have a name just free it */ | |
901 | if (root->name) | |
902 | kfree(root->name); | |
903 | ||
904 | root->name = kmalloc(len+1, GFP_KERNEL); | |
905 | if (!root->name) | |
906 | return -ENOMEM; | |
907 | ||
908 | memcpy(root->name, name, len); | |
909 | root->name[len] ='\0'; | |
910 | ||
911 | return 0; | |
912 | } | |
913 | ||
db94535d CM |
914 | static inline u32 btrfs_level_size(struct btrfs_root *root, int level) { |
915 | if (level == 0) | |
916 | return root->leafsize; | |
917 | return root->nodesize; | |
918 | } | |
919 | ||
4beb1b8b CM |
920 | /* helper function to cast into the data area of the leaf. */ |
921 | #define btrfs_item_ptr(leaf, slot, type) \ | |
123abc88 | 922 | ((type *)(btrfs_leaf_data(leaf) + \ |
5f39d397 CM |
923 | btrfs_item_offset_nr(leaf, slot))) |
924 | ||
925 | #define btrfs_item_ptr_offset(leaf, slot) \ | |
926 | ((unsigned long)(btrfs_leaf_data(leaf) + \ | |
927 | btrfs_item_offset_nr(leaf, slot))) | |
4beb1b8b | 928 | |
6da6abae CM |
929 | static inline struct dentry *fdentry(struct file *file) { |
930 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) | |
931 | return file->f_dentry; | |
932 | #else | |
933 | return file->f_path.dentry; | |
934 | #endif | |
935 | } | |
936 | ||
b18c6685 | 937 | /* extent-tree.c */ |
be20aa9d CM |
938 | u32 btrfs_count_snapshots_in_path(struct btrfs_root *root, |
939 | struct btrfs_path *count_path, | |
940 | u64 first_extent); | |
e9d0b13b CM |
941 | int btrfs_extent_post_op(struct btrfs_trans_handle *trans, |
942 | struct btrfs_root *root); | |
1a5bc167 | 943 | int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy); |
5276aeda CM |
944 | struct btrfs_block_group_cache *btrfs_lookup_block_group(struct |
945 | btrfs_fs_info *info, | |
db94535d | 946 | u64 bytenr); |
31f3c99b CM |
947 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, |
948 | struct btrfs_block_group_cache | |
be744175 | 949 | *hint, u64 search_start, |
de428b63 | 950 | int data, int owner); |
c5739bba | 951 | int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, |
7bb86316 | 952 | struct btrfs_root *root, u64 owner_objectid); |
5f39d397 | 953 | struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
db94535d | 954 | struct btrfs_root *root, u32 size, |
7bb86316 | 955 | u64 root_objectid, |
db94535d | 956 | u64 hint, u64 empty_size); |
7bb86316 CM |
957 | struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
958 | struct btrfs_root *root, | |
959 | u32 blocksize, | |
960 | u64 root_objectid, | |
961 | u64 ref_generation, | |
962 | u64 first_objectid, | |
963 | int level, | |
964 | u64 hint, | |
965 | u64 empty_size); | |
edbd8d4e CM |
966 | int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans, |
967 | struct btrfs_root *root, u64 new_size); | |
968 | int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size); | |
7bb86316 CM |
969 | int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans, |
970 | struct btrfs_root *root, | |
971 | struct btrfs_path *path, u64 bytenr, | |
972 | u64 root_objectid, u64 ref_generation, | |
973 | u64 owner, u64 owner_offset); | |
4d775673 | 974 | int btrfs_alloc_extent(struct btrfs_trans_handle *trans, |
7bb86316 CM |
975 | struct btrfs_root *root, |
976 | u64 num_bytes, u64 root_objectid, u64 ref_generation, | |
977 | u64 owner, u64 owner_offset, | |
978 | u64 empty_size, u64 hint_byte, | |
be08c1b9 | 979 | u64 search_end, struct btrfs_key *ins, int data); |
e089f05c | 980 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
5f39d397 | 981 | struct extent_buffer *buf); |
e089f05c | 982 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
7bb86316 CM |
983 | *root, u64 bytenr, u64 num_bytes, |
984 | u64 root_objectid, u64 ref_generation, | |
985 | u64 owner_objectid, u64 owner_offset, int pin); | |
ccd467d6 CM |
986 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, |
987 | struct btrfs_root *root, | |
1a5bc167 | 988 | struct extent_map_tree *unpin); |
b18c6685 CM |
989 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
990 | struct btrfs_root *root, | |
7bb86316 CM |
991 | u64 bytenr, u64 num_bytes, |
992 | u64 root_objectid, u64 ref_generation, | |
993 | u64 owner, u64 owner_offset); | |
9078a3e1 CM |
994 | int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, |
995 | struct btrfs_root *root); | |
996 | int btrfs_free_block_groups(struct btrfs_fs_info *info); | |
997 | int btrfs_read_block_groups(struct btrfs_root *root); | |
dee26a9f | 998 | /* ctree.c */ |
5f39d397 CM |
999 | int btrfs_cow_block(struct btrfs_trans_handle *trans, |
1000 | struct btrfs_root *root, struct extent_buffer *buf, | |
1001 | struct extent_buffer *parent, int parent_slot, | |
1002 | struct extent_buffer **cow_ret); | |
be20aa9d CM |
1003 | int btrfs_copy_root(struct btrfs_trans_handle *trans, |
1004 | struct btrfs_root *root, | |
1005 | struct extent_buffer *buf, | |
1006 | struct extent_buffer **cow_ret, u64 new_root_objectid); | |
6567e837 CM |
1007 | int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root |
1008 | *root, struct btrfs_path *path, u32 data_size); | |
b18c6685 CM |
1009 | int btrfs_truncate_item(struct btrfs_trans_handle *trans, |
1010 | struct btrfs_root *root, | |
1011 | struct btrfs_path *path, | |
179e29e4 | 1012 | u32 new_size, int from_end); |
e089f05c CM |
1013 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
1014 | *root, struct btrfs_key *key, struct btrfs_path *p, int | |
1015 | ins_len, int cow); | |
6702ed49 | 1016 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
5f39d397 | 1017 | struct btrfs_root *root, struct extent_buffer *parent, |
a6b6e75e CM |
1018 | int start_slot, int cache_only, u64 *last_ret, |
1019 | struct btrfs_key *progress); | |
234b63a0 | 1020 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
2c90e5d6 CM |
1021 | struct btrfs_path *btrfs_alloc_path(void); |
1022 | void btrfs_free_path(struct btrfs_path *p); | |
234b63a0 | 1023 | void btrfs_init_path(struct btrfs_path *p); |
e089f05c CM |
1024 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1025 | struct btrfs_path *path); | |
1026 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
1027 | *root, struct btrfs_key *key, void *data, u32 data_size); | |
1028 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
1029 | *root, struct btrfs_path *path, struct btrfs_key | |
1030 | *cpu_key, u32 data_size); | |
234b63a0 | 1031 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
7bb86316 | 1032 | int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); |
5f39d397 | 1033 | int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); |
e089f05c | 1034 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
9f3a7427 | 1035 | *root); |
dee26a9f | 1036 | /* root-item.c */ |
e089f05c CM |
1037 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1038 | struct btrfs_key *key); | |
1039 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
1040 | *root, struct btrfs_key *key, struct btrfs_root_item | |
1041 | *item); | |
1042 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
1043 | *root, struct btrfs_key *key, struct btrfs_root_item | |
1044 | *item); | |
1045 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct | |
1046 | btrfs_root_item *item, struct btrfs_key *key); | |
5ce14bbc CM |
1047 | int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid, |
1048 | struct btrfs_root *latest_root); | |
dee26a9f | 1049 | /* dir-item.c */ |
e089f05c | 1050 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
1051 | *root, const char *name, int name_len, u64 dir, |
1052 | struct btrfs_key *location, u8 type); | |
7e38180e CM |
1053 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
1054 | struct btrfs_root *root, | |
1055 | struct btrfs_path *path, u64 dir, | |
1056 | const char *name, int name_len, | |
1057 | int mod); | |
1058 | struct btrfs_dir_item * | |
1059 | btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, | |
1060 | struct btrfs_root *root, | |
1061 | struct btrfs_path *path, u64 dir, | |
1062 | u64 objectid, const char *name, int name_len, | |
1063 | int mod); | |
1064 | struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, | |
1065 | struct btrfs_path *path, | |
7f5c1516 | 1066 | const char *name, int name_len); |
7e38180e CM |
1067 | int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
1068 | struct btrfs_root *root, | |
1069 | struct btrfs_path *path, | |
1070 | struct btrfs_dir_item *di); | |
5103e947 JB |
1071 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
1072 | struct btrfs_root *root, const char *name, | |
1073 | u16 name_len, const void *data, u16 data_len, | |
1074 | u64 dir); | |
1075 | struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, | |
1076 | struct btrfs_root *root, | |
1077 | struct btrfs_path *path, u64 dir, | |
1078 | const char *name, u16 name_len, | |
1079 | int mod); | |
dee26a9f | 1080 | /* inode-map.c */ |
9f5fae2f CM |
1081 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
1082 | struct btrfs_root *fs_root, | |
1083 | u64 dirid, u64 *objectid); | |
5be6f7f1 CM |
1084 | int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); |
1085 | ||
dee26a9f | 1086 | /* inode-item.c */ |
3954401f CM |
1087 | int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, |
1088 | struct btrfs_root *root, | |
1089 | const char *name, int name_len, | |
1090 | u64 inode_objectid, u64 ref_objectid); | |
1091 | int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, | |
1092 | struct btrfs_root *root, | |
1093 | const char *name, int name_len, | |
1094 | u64 inode_objectid, u64 ref_objectid); | |
5f39d397 CM |
1095 | int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, |
1096 | struct btrfs_root *root, | |
1097 | struct btrfs_path *path, u64 objectid); | |
293ffd5f | 1098 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
1099 | *root, struct btrfs_path *path, |
1100 | struct btrfs_key *location, int mod); | |
dee26a9f CM |
1101 | |
1102 | /* file-item.c */ | |
b18c6685 | 1103 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
dee26a9f | 1104 | struct btrfs_root *root, |
b18c6685 | 1105 | u64 objectid, u64 pos, u64 offset, |
db94535d CM |
1106 | u64 disk_num_bytes, |
1107 | u64 num_bytes); | |
dee26a9f CM |
1108 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
1109 | struct btrfs_root *root, | |
1110 | struct btrfs_path *path, u64 objectid, | |
db94535d | 1111 | u64 bytenr, int mod); |
f254e52c CM |
1112 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
1113 | struct btrfs_root *root, | |
f578d4bd | 1114 | struct inode *inode, |
f254e52c CM |
1115 | u64 objectid, u64 offset, |
1116 | char *data, size_t len); | |
b18c6685 CM |
1117 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
1118 | struct btrfs_root *root, | |
1119 | struct btrfs_path *path, | |
1120 | u64 objectid, u64 offset, | |
1121 | int cow); | |
1de037a4 CM |
1122 | int btrfs_csum_truncate(struct btrfs_trans_handle *trans, |
1123 | struct btrfs_root *root, struct btrfs_path *path, | |
1124 | u64 isize); | |
39279cc3 | 1125 | /* inode.c */ |
edbd8d4e CM |
1126 | unsigned long btrfs_force_ra(struct address_space *mapping, |
1127 | struct file_ra_state *ra, struct file *file, | |
1128 | pgoff_t offset, pgoff_t last_index); | |
1832a6d5 CM |
1129 | int btrfs_check_free_space(struct btrfs_root *root, u64 num_required, |
1130 | int for_del); | |
9ebefb18 CM |
1131 | int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page); |
1132 | int btrfs_readpage(struct file *file, struct page *page); | |
39279cc3 CM |
1133 | void btrfs_delete_inode(struct inode *inode); |
1134 | void btrfs_read_locked_inode(struct inode *inode); | |
1135 | int btrfs_write_inode(struct inode *inode, int wait); | |
1136 | void btrfs_dirty_inode(struct inode *inode); | |
1137 | struct inode *btrfs_alloc_inode(struct super_block *sb); | |
1138 | void btrfs_destroy_inode(struct inode *inode); | |
1139 | int btrfs_init_cachep(void); | |
1140 | void btrfs_destroy_cachep(void); | |
34287aa3 | 1141 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
39279cc3 CM |
1142 | struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid, |
1143 | struct btrfs_root *root); | |
1144 | int btrfs_commit_write(struct file *file, struct page *page, | |
1145 | unsigned from, unsigned to); | |
a52d9a80 CM |
1146 | struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, |
1147 | size_t page_offset, u64 start, u64 end, | |
1148 | int create); | |
1149 | int btrfs_update_inode(struct btrfs_trans_handle *trans, | |
1150 | struct btrfs_root *root, | |
1151 | struct inode *inode); | |
39279cc3 | 1152 | /* file.c */ |
a52d9a80 | 1153 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end); |
39279cc3 CM |
1154 | extern struct file_operations btrfs_file_operations; |
1155 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, | |
1156 | struct btrfs_root *root, struct inode *inode, | |
00f5c795 | 1157 | u64 start, u64 end, u64 inline_limit, u64 *hint_block); |
6702ed49 CM |
1158 | /* tree-defrag.c */ |
1159 | int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, | |
1160 | struct btrfs_root *root, int cache_only); | |
58176a96 JB |
1161 | |
1162 | /* sysfs.c */ | |
1163 | int btrfs_init_sysfs(void); | |
1164 | void btrfs_exit_sysfs(void); | |
1165 | int btrfs_sysfs_add_super(struct btrfs_fs_info *fs); | |
1166 | int btrfs_sysfs_add_root(struct btrfs_root *root); | |
1167 | void btrfs_sysfs_del_root(struct btrfs_root *root); | |
1168 | void btrfs_sysfs_del_super(struct btrfs_fs_info *root); | |
1169 | ||
5103e947 JB |
1170 | /* xattr.c */ |
1171 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | |
1172 | int btrfs_delete_xattrs(struct btrfs_trans_handle *trans, | |
1173 | struct btrfs_root *root, struct inode *inode); | |
edbd8d4e CM |
1174 | /* super.c */ |
1175 | u64 btrfs_parse_size(char *str); | |
eb60ceac | 1176 | #endif |