]>
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; |
79154b1b | 327 | struct btrfs_transaction *running_transaction; |
4b52dff6 | 328 | struct btrfs_super_block super_copy; |
5f39d397 | 329 | struct extent_buffer *sb_buffer; |
e20d96d6 | 330 | struct super_block *sb; |
d98237b3 | 331 | struct inode *btree_inode; |
19c00ddc | 332 | spinlock_t hash_lock; |
79154b1b | 333 | struct mutex trans_mutex; |
d561c025 | 334 | struct mutex fs_mutex; |
8fd17795 | 335 | struct list_head trans_list; |
19c00ddc | 336 | struct list_head hashers; |
facda1e7 | 337 | struct list_head dead_roots; |
6da6abae CM |
338 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) |
339 | struct work_struct trans_work; | |
340 | #else | |
08607c1b | 341 | struct delayed_work trans_work; |
6da6abae | 342 | #endif |
58176a96 JB |
343 | struct kobject super_kobj; |
344 | struct completion kobj_unregister; | |
e66f709b | 345 | int do_barriers; |
facda1e7 | 346 | int closing; |
9f5fae2f | 347 | |
324ae4df Y |
348 | u64 total_pinned; |
349 | }; | |
9f5fae2f CM |
350 | /* |
351 | * in ram representation of the tree. extent_root is used for all allocations | |
f2458e1d | 352 | * and for the extent tree extent_root root. |
9f5fae2f CM |
353 | */ |
354 | struct btrfs_root { | |
5f39d397 CM |
355 | struct extent_buffer *node; |
356 | struct extent_buffer *commit_root; | |
62e2749e CM |
357 | struct btrfs_root_item root_item; |
358 | struct btrfs_key root_key; | |
9f5fae2f | 359 | struct btrfs_fs_info *fs_info; |
0f7d52f4 | 360 | struct inode *inode; |
58176a96 JB |
361 | struct kobject root_kobj; |
362 | struct completion kobj_unregister; | |
011410bd | 363 | struct rw_semaphore snap_sem; |
0f7d52f4 CM |
364 | u64 objectid; |
365 | u64 last_trans; | |
5f39d397 CM |
366 | |
367 | /* data allocations are done in sectorsize units */ | |
368 | u32 sectorsize; | |
369 | ||
370 | /* node allocations are done in nodesize units */ | |
371 | u32 nodesize; | |
372 | ||
373 | /* leaf allocations are done in leafsize units */ | |
374 | u32 leafsize; | |
375 | ||
87ee04eb CM |
376 | u32 stripesize; |
377 | ||
9f5fae2f | 378 | u32 type; |
1b05da2e CM |
379 | u64 highest_inode; |
380 | u64 last_inode_alloc; | |
9f3a7427 | 381 | int ref_cows; |
6702ed49 CM |
382 | struct btrfs_key defrag_progress; |
383 | int defrag_running; | |
384 | int defrag_level; | |
58176a96 | 385 | char *name; |
62e2749e CM |
386 | }; |
387 | ||
1e1d2701 CM |
388 | /* |
389 | * inode items have the data typically returned from stat and store other | |
390 | * info about object characteristics. There is one for every file and dir in | |
391 | * the FS | |
392 | */ | |
9078a3e1 | 393 | #define BTRFS_INODE_ITEM_KEY 1 |
3954401f CM |
394 | #define BTRFS_INODE_REF_KEY 2 |
395 | #define BTRFS_XATTR_ITEM_KEY 8 | |
9078a3e1 | 396 | /* reserve 2-15 close to the inode for later flexibility */ |
1e1d2701 CM |
397 | |
398 | /* | |
399 | * dir items are the name -> inode pointers in a directory. There is one | |
400 | * for every name in a directory. | |
401 | */ | |
9078a3e1 CM |
402 | #define BTRFS_DIR_ITEM_KEY 16 |
403 | #define BTRFS_DIR_INDEX_KEY 17 | |
1e1d2701 | 404 | /* |
9078a3e1 | 405 | * extent data is for file data |
1e1d2701 | 406 | */ |
9078a3e1 | 407 | #define BTRFS_EXTENT_DATA_KEY 18 |
f254e52c CM |
408 | /* |
409 | * csum items have the checksums for data in the extents | |
410 | */ | |
9078a3e1 CM |
411 | #define BTRFS_CSUM_ITEM_KEY 19 |
412 | ||
413 | /* reserve 20-31 for other file stuff */ | |
f254e52c | 414 | |
1e1d2701 CM |
415 | /* |
416 | * root items point to tree roots. There are typically in the root | |
417 | * tree used by the super block to find all the other trees | |
418 | */ | |
9078a3e1 | 419 | #define BTRFS_ROOT_ITEM_KEY 32 |
1e1d2701 CM |
420 | /* |
421 | * extent items are in the extent map tree. These record which blocks | |
422 | * are used, and how many references there are to each block | |
423 | */ | |
9078a3e1 | 424 | #define BTRFS_EXTENT_ITEM_KEY 33 |
74493f7a | 425 | #define BTRFS_EXTENT_REF_KEY 34 |
9078a3e1 CM |
426 | |
427 | /* | |
428 | * block groups give us hints into the extent allocation trees. Which | |
429 | * blocks are free etc etc | |
430 | */ | |
74493f7a | 431 | #define BTRFS_BLOCK_GROUP_ITEM_KEY 50 |
9f5fae2f | 432 | |
1e1d2701 CM |
433 | /* |
434 | * string items are for debugging. They just store a short string of | |
435 | * data in the FS | |
436 | */ | |
9078a3e1 CM |
437 | #define BTRFS_STRING_ITEM_KEY 253 |
438 | ||
b6cda9bc | 439 | #define BTRFS_MOUNT_NODATASUM 0x1 |
be20aa9d | 440 | #define BTRFS_MOUNT_NODATACOW 0x2 |
b6cda9bc CM |
441 | |
442 | #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt) | |
443 | #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt) | |
444 | #define btrfs_test_opt(root, opt) ((root)->fs_info->mount_opt & \ | |
445 | BTRFS_MOUNT_##opt) | |
446 | ||
5f39d397 CM |
447 | /* some macros to generate set/get funcs for the struct fields. This |
448 | * assumes there is a lefoo_to_cpu for every type, so lets make a simple | |
449 | * one for u8: | |
450 | */ | |
451 | #define le8_to_cpu(v) (v) | |
452 | #define cpu_to_le8(v) (v) | |
453 | #define __le8 u8 | |
454 | ||
455 | #define read_eb_member(eb, ptr, type, member, result) ( \ | |
456 | read_extent_buffer(eb, (char *)(result), \ | |
457 | ((unsigned long)(ptr)) + \ | |
458 | offsetof(type, member), \ | |
459 | sizeof(((type *)0)->member))) | |
460 | ||
461 | #define write_eb_member(eb, ptr, type, member, result) ( \ | |
462 | write_extent_buffer(eb, (char *)(result), \ | |
463 | ((unsigned long)(ptr)) + \ | |
464 | offsetof(type, member), \ | |
465 | sizeof(((type *)0)->member))) | |
466 | ||
0f82731f | 467 | #ifndef BTRFS_SETGET_FUNCS |
5f39d397 | 468 | #define BTRFS_SETGET_FUNCS(name, type, member, bits) \ |
0f82731f CM |
469 | u##bits btrfs_##name(struct extent_buffer *eb, type *s); \ |
470 | void btrfs_set_##name(struct extent_buffer *eb, type *s, u##bits val); | |
471 | #endif | |
5f39d397 CM |
472 | |
473 | #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \ | |
474 | static inline u##bits btrfs_##name(struct extent_buffer *eb) \ | |
475 | { \ | |
810191ff | 476 | char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \ |
6d36dcd4 | 477 | unsigned long offset = offsetof(type, member); \ |
810191ff CM |
478 | u##bits res; \ |
479 | __le##bits *tmp = (__le##bits *)(kaddr + offset); \ | |
480 | res = le##bits##_to_cpu(*tmp); \ | |
481 | kunmap_atomic(kaddr, KM_USER0); \ | |
482 | return res; \ | |
5f39d397 CM |
483 | } \ |
484 | static inline void btrfs_set_##name(struct extent_buffer *eb, \ | |
485 | u##bits val) \ | |
486 | { \ | |
810191ff | 487 | char *kaddr = kmap_atomic(eb->first_page, KM_USER0); \ |
6d36dcd4 | 488 | unsigned long offset = offsetof(type, member); \ |
810191ff CM |
489 | __le##bits *tmp = (__le##bits *)(kaddr + offset); \ |
490 | *tmp = cpu_to_le##bits(val); \ | |
491 | kunmap_atomic(kaddr, KM_USER0); \ | |
5f39d397 | 492 | } |
9078a3e1 | 493 | |
5f39d397 CM |
494 | #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ |
495 | static inline u##bits btrfs_##name(type *s) \ | |
496 | { \ | |
497 | return le##bits##_to_cpu(s->member); \ | |
498 | } \ | |
499 | static inline void btrfs_set_##name(type *s, u##bits val) \ | |
500 | { \ | |
501 | s->member = cpu_to_le##bits(val); \ | |
1e1d2701 CM |
502 | } |
503 | ||
5f39d397 CM |
504 | /* struct btrfs_block_group_item */ |
505 | BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item, | |
506 | used, 64); | |
507 | BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item, | |
508 | used, 64); | |
1e1d2701 | 509 | |
3954401f CM |
510 | /* struct btrfs_inode_ref */ |
511 | BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16); | |
512 | ||
5f39d397 CM |
513 | /* struct btrfs_inode_item */ |
514 | BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64); | |
515 | BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64); | |
516 | BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64); | |
517 | BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64); | |
518 | BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32); | |
519 | BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32); | |
520 | BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32); | |
521 | BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32); | |
522 | BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32); | |
523 | BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16); | |
524 | BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item, | |
525 | compat_flags, 16); | |
1e1d2701 | 526 | |
5f39d397 CM |
527 | static inline struct btrfs_inode_timespec * |
528 | btrfs_inode_atime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 529 | { |
5f39d397 CM |
530 | unsigned long ptr = (unsigned long)inode_item; |
531 | ptr += offsetof(struct btrfs_inode_item, atime); | |
532 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
533 | } |
534 | ||
5f39d397 CM |
535 | static inline struct btrfs_inode_timespec * |
536 | btrfs_inode_mtime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 537 | { |
5f39d397 CM |
538 | unsigned long ptr = (unsigned long)inode_item; |
539 | ptr += offsetof(struct btrfs_inode_item, mtime); | |
540 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
541 | } |
542 | ||
5f39d397 CM |
543 | static inline struct btrfs_inode_timespec * |
544 | btrfs_inode_ctime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 545 | { |
5f39d397 CM |
546 | unsigned long ptr = (unsigned long)inode_item; |
547 | ptr += offsetof(struct btrfs_inode_item, ctime); | |
548 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
549 | } |
550 | ||
5f39d397 CM |
551 | static inline struct btrfs_inode_timespec * |
552 | btrfs_inode_otime(struct btrfs_inode_item *inode_item) | |
1e1d2701 | 553 | { |
5f39d397 CM |
554 | unsigned long ptr = (unsigned long)inode_item; |
555 | ptr += offsetof(struct btrfs_inode_item, otime); | |
556 | return (struct btrfs_inode_timespec *)ptr; | |
1e1d2701 CM |
557 | } |
558 | ||
5f39d397 CM |
559 | BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64); |
560 | BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32); | |
e20d96d6 | 561 | |
5f39d397 CM |
562 | /* struct btrfs_extent_item */ |
563 | BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32); | |
74493f7a CM |
564 | |
565 | /* struct btrfs_extent_ref */ | |
566 | BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64); | |
567 | BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64); | |
568 | BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64); | |
569 | BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64); | |
570 | ||
7bb86316 CM |
571 | BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64); |
572 | BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref, | |
74493f7a | 573 | generation, 64); |
7bb86316 CM |
574 | BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref, |
575 | objectid, 64); | |
576 | BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64); | |
e20d96d6 | 577 | |
5f39d397 CM |
578 | BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item, |
579 | refs, 32); | |
e20d96d6 | 580 | |
5f39d397 CM |
581 | /* struct btrfs_node */ |
582 | BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64); | |
74493f7a | 583 | BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64); |
e20d96d6 | 584 | |
5f39d397 | 585 | static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr) |
cf27e1ee | 586 | { |
5f39d397 CM |
587 | unsigned long ptr; |
588 | ptr = offsetof(struct btrfs_node, ptrs) + | |
589 | sizeof(struct btrfs_key_ptr) * nr; | |
590 | return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr); | |
cf27e1ee CM |
591 | } |
592 | ||
5f39d397 CM |
593 | static inline void btrfs_set_node_blockptr(struct extent_buffer *eb, |
594 | int nr, u64 val) | |
cf27e1ee | 595 | { |
5f39d397 CM |
596 | unsigned long ptr; |
597 | ptr = offsetof(struct btrfs_node, ptrs) + | |
598 | sizeof(struct btrfs_key_ptr) * nr; | |
599 | btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val); | |
cf27e1ee CM |
600 | } |
601 | ||
74493f7a CM |
602 | static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr) |
603 | { | |
604 | unsigned long ptr; | |
605 | ptr = offsetof(struct btrfs_node, ptrs) + | |
606 | sizeof(struct btrfs_key_ptr) * nr; | |
607 | return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr); | |
608 | } | |
609 | ||
610 | static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb, | |
611 | int nr, u64 val) | |
612 | { | |
613 | unsigned long ptr; | |
614 | ptr = offsetof(struct btrfs_node, ptrs) + | |
615 | sizeof(struct btrfs_key_ptr) * nr; | |
616 | btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val); | |
617 | } | |
618 | ||
810191ff | 619 | static inline unsigned long btrfs_node_key_ptr_offset(int nr) |
4d775673 | 620 | { |
5f39d397 CM |
621 | return offsetof(struct btrfs_node, ptrs) + |
622 | sizeof(struct btrfs_key_ptr) * nr; | |
4d775673 CM |
623 | } |
624 | ||
e644d021 CM |
625 | void btrfs_node_key(struct extent_buffer *eb, |
626 | struct btrfs_disk_key *disk_key, int nr); | |
627 | ||
5f39d397 CM |
628 | static inline void btrfs_set_node_key(struct extent_buffer *eb, |
629 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f8a0c | 630 | { |
5f39d397 CM |
631 | unsigned long ptr; |
632 | ptr = btrfs_node_key_ptr_offset(nr); | |
633 | write_eb_member(eb, (struct btrfs_key_ptr *)ptr, | |
634 | struct btrfs_key_ptr, key, disk_key); | |
1d4f8a0c CM |
635 | } |
636 | ||
5f39d397 CM |
637 | /* struct btrfs_item */ |
638 | BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32); | |
639 | BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32); | |
4d775673 | 640 | |
5f39d397 | 641 | static inline unsigned long btrfs_item_nr_offset(int nr) |
1d4f8a0c | 642 | { |
5f39d397 CM |
643 | return offsetof(struct btrfs_leaf, items) + |
644 | sizeof(struct btrfs_item) * nr; | |
1d4f8a0c CM |
645 | } |
646 | ||
5f39d397 CM |
647 | static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb, |
648 | int nr) | |
0783fcfc | 649 | { |
5f39d397 | 650 | return (struct btrfs_item *)btrfs_item_nr_offset(nr); |
0783fcfc CM |
651 | } |
652 | ||
5f39d397 CM |
653 | static inline u32 btrfs_item_end(struct extent_buffer *eb, |
654 | struct btrfs_item *item) | |
0783fcfc | 655 | { |
5f39d397 | 656 | return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item); |
0783fcfc CM |
657 | } |
658 | ||
5f39d397 | 659 | static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 660 | { |
5f39d397 | 661 | return btrfs_item_end(eb, btrfs_item_nr(eb, nr)); |
0783fcfc CM |
662 | } |
663 | ||
5f39d397 | 664 | static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 665 | { |
5f39d397 | 666 | return btrfs_item_offset(eb, btrfs_item_nr(eb, nr)); |
0783fcfc CM |
667 | } |
668 | ||
5f39d397 | 669 | static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr) |
0783fcfc | 670 | { |
5f39d397 | 671 | return btrfs_item_size(eb, btrfs_item_nr(eb, nr)); |
0783fcfc CM |
672 | } |
673 | ||
5f39d397 CM |
674 | static inline void btrfs_item_key(struct extent_buffer *eb, |
675 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f6404 | 676 | { |
5f39d397 CM |
677 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
678 | read_eb_member(eb, item, struct btrfs_item, key, disk_key); | |
1d4f6404 CM |
679 | } |
680 | ||
5f39d397 CM |
681 | static inline void btrfs_set_item_key(struct extent_buffer *eb, |
682 | struct btrfs_disk_key *disk_key, int nr) | |
1d4f6404 | 683 | { |
5f39d397 CM |
684 | struct btrfs_item *item = btrfs_item_nr(eb, nr); |
685 | write_eb_member(eb, item, struct btrfs_item, key, disk_key); | |
1d4f6404 CM |
686 | } |
687 | ||
5f39d397 | 688 | /* struct btrfs_dir_item */ |
5103e947 | 689 | BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); |
5f39d397 CM |
690 | BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); |
691 | BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); | |
1d4f6404 | 692 | |
5f39d397 CM |
693 | static inline void btrfs_dir_item_key(struct extent_buffer *eb, |
694 | struct btrfs_dir_item *item, | |
695 | struct btrfs_disk_key *key) | |
1d4f6404 | 696 | { |
5f39d397 | 697 | read_eb_member(eb, item, struct btrfs_dir_item, location, key); |
1d4f6404 CM |
698 | } |
699 | ||
5f39d397 CM |
700 | static inline void btrfs_set_dir_item_key(struct extent_buffer *eb, |
701 | struct btrfs_dir_item *item, | |
702 | struct btrfs_disk_key *key) | |
a8a2ee0c | 703 | { |
5f39d397 | 704 | write_eb_member(eb, item, struct btrfs_dir_item, location, key); |
a8a2ee0c CM |
705 | } |
706 | ||
5f39d397 CM |
707 | /* struct btrfs_disk_key */ |
708 | BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key, | |
709 | objectid, 64); | |
710 | BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); | |
711 | BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); | |
1d4f6404 | 712 | |
e2fa7227 CM |
713 | static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, |
714 | struct btrfs_disk_key *disk) | |
715 | { | |
716 | cpu->offset = le64_to_cpu(disk->offset); | |
5f39d397 | 717 | cpu->type = disk->type; |
e2fa7227 CM |
718 | cpu->objectid = le64_to_cpu(disk->objectid); |
719 | } | |
720 | ||
721 | static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, | |
722 | struct btrfs_key *cpu) | |
723 | { | |
724 | disk->offset = cpu_to_le64(cpu->offset); | |
5f39d397 | 725 | disk->type = cpu->type; |
e2fa7227 CM |
726 | disk->objectid = cpu_to_le64(cpu->objectid); |
727 | } | |
728 | ||
5f39d397 CM |
729 | static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb, |
730 | struct btrfs_key *key, int nr) | |
7f5c1516 | 731 | { |
5f39d397 CM |
732 | struct btrfs_disk_key disk_key; |
733 | btrfs_node_key(eb, &disk_key, nr); | |
734 | btrfs_disk_key_to_cpu(key, &disk_key); | |
7f5c1516 CM |
735 | } |
736 | ||
5f39d397 CM |
737 | static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb, |
738 | struct btrfs_key *key, int nr) | |
7f5c1516 | 739 | { |
5f39d397 CM |
740 | struct btrfs_disk_key disk_key; |
741 | btrfs_item_key(eb, &disk_key, nr); | |
742 | btrfs_disk_key_to_cpu(key, &disk_key); | |
7f5c1516 CM |
743 | } |
744 | ||
5f39d397 CM |
745 | static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, |
746 | struct btrfs_dir_item *item, | |
747 | struct btrfs_key *key) | |
4d775673 | 748 | { |
5f39d397 CM |
749 | struct btrfs_disk_key disk_key; |
750 | btrfs_dir_item_key(eb, item, &disk_key); | |
751 | btrfs_disk_key_to_cpu(key, &disk_key); | |
4d775673 CM |
752 | } |
753 | ||
58176a96 | 754 | |
5f39d397 | 755 | static inline u8 btrfs_key_type(struct btrfs_key *key) |
3768f368 | 756 | { |
5f39d397 | 757 | return key->type; |
3768f368 CM |
758 | } |
759 | ||
5f39d397 | 760 | static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val) |
3768f368 | 761 | { |
5f39d397 | 762 | key->type = val; |
3768f368 CM |
763 | } |
764 | ||
5f39d397 | 765 | /* struct btrfs_header */ |
db94535d | 766 | BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64); |
5f39d397 CM |
767 | BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header, |
768 | generation, 64); | |
769 | BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64); | |
770 | BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32); | |
771 | BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16); | |
772 | BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8); | |
0f7d52f4 | 773 | |
5f39d397 | 774 | static inline u8 *btrfs_header_fsid(struct extent_buffer *eb) |
0f7d52f4 | 775 | { |
5f39d397 CM |
776 | unsigned long ptr = offsetof(struct btrfs_header, fsid); |
777 | return (u8 *)ptr; | |
0f7d52f4 CM |
778 | } |
779 | ||
5f39d397 | 780 | static inline u8 *btrfs_super_fsid(struct extent_buffer *eb) |
3768f368 | 781 | { |
5f39d397 CM |
782 | unsigned long ptr = offsetof(struct btrfs_super_block, fsid); |
783 | return (u8 *)ptr; | |
3768f368 CM |
784 | } |
785 | ||
5f39d397 | 786 | static inline u8 *btrfs_header_csum(struct extent_buffer *eb) |
3768f368 | 787 | { |
5f39d397 CM |
788 | unsigned long ptr = offsetof(struct btrfs_header, csum); |
789 | return (u8 *)ptr; | |
3768f368 CM |
790 | } |
791 | ||
5f39d397 | 792 | static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb) |
3768f368 | 793 | { |
5f39d397 | 794 | return NULL; |
3768f368 CM |
795 | } |
796 | ||
5f39d397 | 797 | static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb) |
3768f368 | 798 | { |
5f39d397 | 799 | return NULL; |
3768f368 CM |
800 | } |
801 | ||
5f39d397 | 802 | static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb) |
3768f368 | 803 | { |
5f39d397 | 804 | return NULL; |
3768f368 CM |
805 | } |
806 | ||
5f39d397 | 807 | static inline int btrfs_is_leaf(struct extent_buffer *eb) |
3768f368 | 808 | { |
5f39d397 | 809 | return (btrfs_header_level(eb) == 0); |
3768f368 CM |
810 | } |
811 | ||
5f39d397 CM |
812 | /* struct btrfs_root_item */ |
813 | BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32); | |
db94535d CM |
814 | BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64); |
815 | BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8); | |
3768f368 | 816 | |
db94535d CM |
817 | BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64); |
818 | BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8); | |
5f39d397 CM |
819 | BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64); |
820 | BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32); | |
821 | BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32); | |
db94535d CM |
822 | BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); |
823 | BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); | |
123abc88 | 824 | |
5f39d397 | 825 | /* struct btrfs_super_block */ |
db94535d | 826 | BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64); |
5f39d397 CM |
827 | BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block, |
828 | generation, 64); | |
829 | BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64); | |
db94535d CM |
830 | BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block, |
831 | root_level, 8); | |
832 | BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block, | |
833 | total_bytes, 64); | |
834 | BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block, | |
835 | bytes_used, 64); | |
5f39d397 CM |
836 | BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block, |
837 | sectorsize, 32); | |
838 | BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block, | |
839 | nodesize, 32); | |
840 | BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block, | |
841 | leafsize, 32); | |
87ee04eb CM |
842 | BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block, |
843 | stripesize, 32); | |
5f39d397 CM |
844 | BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block, |
845 | root_dir_objectid, 64); | |
2e635a27 | 846 | |
5f39d397 | 847 | static inline unsigned long btrfs_leaf_data(struct extent_buffer *l) |
2e635a27 | 848 | { |
5f39d397 | 849 | return offsetof(struct btrfs_leaf, items); |
2e635a27 CM |
850 | } |
851 | ||
5f39d397 CM |
852 | /* struct btrfs_file_extent_item */ |
853 | BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); | |
9f5fae2f | 854 | |
5f39d397 | 855 | static inline unsigned long btrfs_file_extent_inline_start(struct |
236454df CM |
856 | btrfs_file_extent_item *e) |
857 | { | |
5f39d397 | 858 | unsigned long offset = (unsigned long)e; |
db94535d | 859 | offset += offsetof(struct btrfs_file_extent_item, disk_bytenr); |
5f39d397 | 860 | return offset; |
236454df CM |
861 | } |
862 | ||
863 | static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) | |
864 | { | |
db94535d | 865 | return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize; |
9f5fae2f CM |
866 | } |
867 | ||
5f39d397 CM |
868 | static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb, |
869 | struct btrfs_item *e) | |
9f5fae2f | 870 | { |
5f39d397 | 871 | unsigned long offset; |
db94535d | 872 | offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); |
5f39d397 | 873 | return btrfs_item_size(eb, e) - offset; |
9f5fae2f CM |
874 | } |
875 | ||
db94535d CM |
876 | BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, |
877 | disk_bytenr, 64); | |
5f39d397 CM |
878 | BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item, |
879 | generation, 64); | |
db94535d CM |
880 | BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item, |
881 | disk_num_bytes, 64); | |
5f39d397 CM |
882 | BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item, |
883 | offset, 64); | |
db94535d CM |
884 | BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item, |
885 | num_bytes, 64); | |
9f5fae2f | 886 | |
e20d96d6 CM |
887 | static inline struct btrfs_root *btrfs_sb(struct super_block *sb) |
888 | { | |
889 | return sb->s_fs_info; | |
890 | } | |
891 | ||
58176a96 JB |
892 | static inline int btrfs_set_root_name(struct btrfs_root *root, |
893 | const char *name, int len) | |
894 | { | |
895 | /* if we already have a name just free it */ | |
896 | if (root->name) | |
897 | kfree(root->name); | |
898 | ||
899 | root->name = kmalloc(len+1, GFP_KERNEL); | |
900 | if (!root->name) | |
901 | return -ENOMEM; | |
902 | ||
903 | memcpy(root->name, name, len); | |
904 | root->name[len] ='\0'; | |
905 | ||
906 | return 0; | |
907 | } | |
908 | ||
db94535d CM |
909 | static inline u32 btrfs_level_size(struct btrfs_root *root, int level) { |
910 | if (level == 0) | |
911 | return root->leafsize; | |
912 | return root->nodesize; | |
913 | } | |
914 | ||
4beb1b8b CM |
915 | /* helper function to cast into the data area of the leaf. */ |
916 | #define btrfs_item_ptr(leaf, slot, type) \ | |
123abc88 | 917 | ((type *)(btrfs_leaf_data(leaf) + \ |
5f39d397 CM |
918 | btrfs_item_offset_nr(leaf, slot))) |
919 | ||
920 | #define btrfs_item_ptr_offset(leaf, slot) \ | |
921 | ((unsigned long)(btrfs_leaf_data(leaf) + \ | |
922 | btrfs_item_offset_nr(leaf, slot))) | |
4beb1b8b | 923 | |
6da6abae CM |
924 | static inline struct dentry *fdentry(struct file *file) { |
925 | #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18) | |
926 | return file->f_dentry; | |
927 | #else | |
928 | return file->f_path.dentry; | |
929 | #endif | |
930 | } | |
931 | ||
b18c6685 | 932 | /* extent-tree.c */ |
be20aa9d CM |
933 | u32 btrfs_count_snapshots_in_path(struct btrfs_root *root, |
934 | struct btrfs_path *count_path, | |
935 | u64 first_extent); | |
e9d0b13b CM |
936 | int btrfs_extent_post_op(struct btrfs_trans_handle *trans, |
937 | struct btrfs_root *root); | |
1a5bc167 | 938 | int btrfs_copy_pinned(struct btrfs_root *root, struct extent_map_tree *copy); |
5276aeda CM |
939 | struct btrfs_block_group_cache *btrfs_lookup_block_group(struct |
940 | btrfs_fs_info *info, | |
db94535d | 941 | u64 bytenr); |
31f3c99b CM |
942 | struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root, |
943 | struct btrfs_block_group_cache | |
be744175 | 944 | *hint, u64 search_start, |
de428b63 | 945 | int data, int owner); |
c5739bba | 946 | int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, |
7bb86316 | 947 | struct btrfs_root *root, u64 owner_objectid); |
5f39d397 | 948 | struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
db94535d | 949 | struct btrfs_root *root, u32 size, |
7bb86316 | 950 | u64 root_objectid, |
db94535d | 951 | u64 hint, u64 empty_size); |
7bb86316 CM |
952 | struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans, |
953 | struct btrfs_root *root, | |
954 | u32 blocksize, | |
955 | u64 root_objectid, | |
956 | u64 ref_generation, | |
957 | u64 first_objectid, | |
958 | int level, | |
959 | u64 hint, | |
960 | u64 empty_size); | |
961 | int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans, | |
962 | struct btrfs_root *root, | |
963 | struct btrfs_path *path, u64 bytenr, | |
964 | u64 root_objectid, u64 ref_generation, | |
965 | u64 owner, u64 owner_offset); | |
4d775673 | 966 | int btrfs_alloc_extent(struct btrfs_trans_handle *trans, |
7bb86316 CM |
967 | struct btrfs_root *root, |
968 | u64 num_bytes, u64 root_objectid, u64 ref_generation, | |
969 | u64 owner, u64 owner_offset, | |
970 | u64 empty_size, u64 hint_byte, | |
be08c1b9 | 971 | u64 search_end, struct btrfs_key *ins, int data); |
e089f05c | 972 | int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
5f39d397 | 973 | struct extent_buffer *buf); |
e089f05c | 974 | int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root |
7bb86316 CM |
975 | *root, u64 bytenr, u64 num_bytes, |
976 | u64 root_objectid, u64 ref_generation, | |
977 | u64 owner_objectid, u64 owner_offset, int pin); | |
ccd467d6 CM |
978 | int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, |
979 | struct btrfs_root *root, | |
1a5bc167 | 980 | struct extent_map_tree *unpin); |
b18c6685 CM |
981 | int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, |
982 | struct btrfs_root *root, | |
7bb86316 CM |
983 | u64 bytenr, u64 num_bytes, |
984 | u64 root_objectid, u64 ref_generation, | |
985 | u64 owner, u64 owner_offset); | |
9078a3e1 CM |
986 | int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, |
987 | struct btrfs_root *root); | |
988 | int btrfs_free_block_groups(struct btrfs_fs_info *info); | |
989 | int btrfs_read_block_groups(struct btrfs_root *root); | |
dee26a9f | 990 | /* ctree.c */ |
5f39d397 CM |
991 | int btrfs_cow_block(struct btrfs_trans_handle *trans, |
992 | struct btrfs_root *root, struct extent_buffer *buf, | |
993 | struct extent_buffer *parent, int parent_slot, | |
994 | struct extent_buffer **cow_ret); | |
be20aa9d CM |
995 | int btrfs_copy_root(struct btrfs_trans_handle *trans, |
996 | struct btrfs_root *root, | |
997 | struct extent_buffer *buf, | |
998 | struct extent_buffer **cow_ret, u64 new_root_objectid); | |
6567e837 CM |
999 | int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root |
1000 | *root, struct btrfs_path *path, u32 data_size); | |
b18c6685 CM |
1001 | int btrfs_truncate_item(struct btrfs_trans_handle *trans, |
1002 | struct btrfs_root *root, | |
1003 | struct btrfs_path *path, | |
179e29e4 | 1004 | u32 new_size, int from_end); |
e089f05c CM |
1005 | int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root |
1006 | *root, struct btrfs_key *key, struct btrfs_path *p, int | |
1007 | ins_len, int cow); | |
6702ed49 | 1008 | int btrfs_realloc_node(struct btrfs_trans_handle *trans, |
5f39d397 | 1009 | struct btrfs_root *root, struct extent_buffer *parent, |
a6b6e75e CM |
1010 | int start_slot, int cache_only, u64 *last_ret, |
1011 | struct btrfs_key *progress); | |
234b63a0 | 1012 | void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); |
2c90e5d6 CM |
1013 | struct btrfs_path *btrfs_alloc_path(void); |
1014 | void btrfs_free_path(struct btrfs_path *p); | |
234b63a0 | 1015 | void btrfs_init_path(struct btrfs_path *p); |
e089f05c CM |
1016 | int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1017 | struct btrfs_path *path); | |
1018 | int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
1019 | *root, struct btrfs_key *key, void *data, u32 data_size); | |
1020 | int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root | |
1021 | *root, struct btrfs_path *path, struct btrfs_key | |
1022 | *cpu_key, u32 data_size); | |
234b63a0 | 1023 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
7bb86316 | 1024 | int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path); |
5f39d397 | 1025 | int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf); |
e089f05c | 1026 | int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root |
9f3a7427 | 1027 | *root); |
dee26a9f | 1028 | /* root-item.c */ |
e089f05c CM |
1029 | int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, |
1030 | struct btrfs_key *key); | |
1031 | int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
1032 | *root, struct btrfs_key *key, struct btrfs_root_item | |
1033 | *item); | |
1034 | int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root | |
1035 | *root, struct btrfs_key *key, struct btrfs_root_item | |
1036 | *item); | |
1037 | int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct | |
1038 | btrfs_root_item *item, struct btrfs_key *key); | |
5ce14bbc CM |
1039 | int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid, |
1040 | struct btrfs_root *latest_root); | |
dee26a9f | 1041 | /* dir-item.c */ |
e089f05c | 1042 | int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
1043 | *root, const char *name, int name_len, u64 dir, |
1044 | struct btrfs_key *location, u8 type); | |
7e38180e CM |
1045 | struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, |
1046 | struct btrfs_root *root, | |
1047 | struct btrfs_path *path, u64 dir, | |
1048 | const char *name, int name_len, | |
1049 | int mod); | |
1050 | struct btrfs_dir_item * | |
1051 | btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans, | |
1052 | struct btrfs_root *root, | |
1053 | struct btrfs_path *path, u64 dir, | |
1054 | u64 objectid, const char *name, int name_len, | |
1055 | int mod); | |
1056 | struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root, | |
1057 | struct btrfs_path *path, | |
7f5c1516 | 1058 | const char *name, int name_len); |
7e38180e CM |
1059 | int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, |
1060 | struct btrfs_root *root, | |
1061 | struct btrfs_path *path, | |
1062 | struct btrfs_dir_item *di); | |
5103e947 JB |
1063 | int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, |
1064 | struct btrfs_root *root, const char *name, | |
1065 | u16 name_len, const void *data, u16 data_len, | |
1066 | u64 dir); | |
1067 | struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans, | |
1068 | struct btrfs_root *root, | |
1069 | struct btrfs_path *path, u64 dir, | |
1070 | const char *name, u16 name_len, | |
1071 | int mod); | |
dee26a9f | 1072 | /* inode-map.c */ |
9f5fae2f CM |
1073 | int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, |
1074 | struct btrfs_root *fs_root, | |
1075 | u64 dirid, u64 *objectid); | |
5be6f7f1 CM |
1076 | int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); |
1077 | ||
dee26a9f | 1078 | /* inode-item.c */ |
3954401f CM |
1079 | int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, |
1080 | struct btrfs_root *root, | |
1081 | const char *name, int name_len, | |
1082 | u64 inode_objectid, u64 ref_objectid); | |
1083 | int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, | |
1084 | struct btrfs_root *root, | |
1085 | const char *name, int name_len, | |
1086 | u64 inode_objectid, u64 ref_objectid); | |
5f39d397 CM |
1087 | int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans, |
1088 | struct btrfs_root *root, | |
1089 | struct btrfs_path *path, u64 objectid); | |
293ffd5f | 1090 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
1091 | *root, struct btrfs_path *path, |
1092 | struct btrfs_key *location, int mod); | |
dee26a9f CM |
1093 | |
1094 | /* file-item.c */ | |
b18c6685 | 1095 | int btrfs_insert_file_extent(struct btrfs_trans_handle *trans, |
dee26a9f | 1096 | struct btrfs_root *root, |
b18c6685 | 1097 | u64 objectid, u64 pos, u64 offset, |
db94535d CM |
1098 | u64 disk_num_bytes, |
1099 | u64 num_bytes); | |
dee26a9f CM |
1100 | int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans, |
1101 | struct btrfs_root *root, | |
1102 | struct btrfs_path *path, u64 objectid, | |
db94535d | 1103 | u64 bytenr, int mod); |
f254e52c CM |
1104 | int btrfs_csum_file_block(struct btrfs_trans_handle *trans, |
1105 | struct btrfs_root *root, | |
f578d4bd | 1106 | struct inode *inode, |
f254e52c CM |
1107 | u64 objectid, u64 offset, |
1108 | char *data, size_t len); | |
b18c6685 CM |
1109 | struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans, |
1110 | struct btrfs_root *root, | |
1111 | struct btrfs_path *path, | |
1112 | u64 objectid, u64 offset, | |
1113 | int cow); | |
1de037a4 CM |
1114 | int btrfs_csum_truncate(struct btrfs_trans_handle *trans, |
1115 | struct btrfs_root *root, struct btrfs_path *path, | |
1116 | u64 isize); | |
39279cc3 | 1117 | /* inode.c */ |
9ebefb18 CM |
1118 | int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page); |
1119 | int btrfs_readpage(struct file *file, struct page *page); | |
39279cc3 CM |
1120 | void btrfs_delete_inode(struct inode *inode); |
1121 | void btrfs_read_locked_inode(struct inode *inode); | |
1122 | int btrfs_write_inode(struct inode *inode, int wait); | |
1123 | void btrfs_dirty_inode(struct inode *inode); | |
1124 | struct inode *btrfs_alloc_inode(struct super_block *sb); | |
1125 | void btrfs_destroy_inode(struct inode *inode); | |
1126 | int btrfs_init_cachep(void); | |
1127 | void btrfs_destroy_cachep(void); | |
34287aa3 | 1128 | long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
39279cc3 CM |
1129 | struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid, |
1130 | struct btrfs_root *root); | |
1131 | int btrfs_commit_write(struct file *file, struct page *page, | |
1132 | unsigned from, unsigned to); | |
a52d9a80 CM |
1133 | struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, |
1134 | size_t page_offset, u64 start, u64 end, | |
1135 | int create); | |
1136 | int btrfs_update_inode(struct btrfs_trans_handle *trans, | |
1137 | struct btrfs_root *root, | |
1138 | struct inode *inode); | |
39279cc3 | 1139 | /* file.c */ |
a52d9a80 | 1140 | int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end); |
39279cc3 CM |
1141 | extern struct file_operations btrfs_file_operations; |
1142 | int btrfs_drop_extents(struct btrfs_trans_handle *trans, | |
1143 | struct btrfs_root *root, struct inode *inode, | |
00f5c795 | 1144 | u64 start, u64 end, u64 inline_limit, u64 *hint_block); |
6702ed49 CM |
1145 | /* tree-defrag.c */ |
1146 | int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, | |
1147 | struct btrfs_root *root, int cache_only); | |
58176a96 JB |
1148 | |
1149 | /* sysfs.c */ | |
1150 | int btrfs_init_sysfs(void); | |
1151 | void btrfs_exit_sysfs(void); | |
1152 | int btrfs_sysfs_add_super(struct btrfs_fs_info *fs); | |
1153 | int btrfs_sysfs_add_root(struct btrfs_root *root); | |
1154 | void btrfs_sysfs_del_root(struct btrfs_root *root); | |
1155 | void btrfs_sysfs_del_super(struct btrfs_fs_info *root); | |
1156 | ||
5103e947 JB |
1157 | /* xattr.c */ |
1158 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | |
1159 | int btrfs_delete_xattrs(struct btrfs_trans_handle *trans, | |
1160 | struct btrfs_root *root, struct inode *inode); | |
eb60ceac | 1161 | #endif |