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