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