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