Fix a few casts for 32 bit compile
[btrfs-progs-unstable.git] / ctree.h
blob9c7f8a5dad937135ec7036b6955853501746e1f9
1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
19 #ifndef __BTRFS__
20 #define __BTRFS__
22 #include "list.h"
23 #include "kerncompat.h"
24 #include "radix-tree.h"
25 #include "extent-cache.h"
26 #include "extent_io.h"
28 struct btrfs_root;
29 struct btrfs_trans_handle;
30 #define BTRFS_MAGIC "_B5RfS_M"
32 #define BTRFS_MAX_LEVEL 8
34 /* holds pointers to all of the tree roots */
35 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
37 /* stores information about which extents are in use, and reference counts */
38 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
41 * chunk tree stores translations from logical -> physical block numbering
42 * the super block points to the chunk tree
44 #define BTRFS_CHUNK_TREE_OBJECTID 3ULL
47 * stores information about which areas of a given device are in use.
48 * one per device. The tree of tree roots points to the device tree
50 #define BTRFS_DEV_TREE_OBJECTID 4ULL
52 /* one per subvolume, storing files and directories */
53 #define BTRFS_FS_TREE_OBJECTID 5ULL
55 /* directory objectid inside the root tree */
56 #define BTRFS_ROOT_TREE_DIR_OBJECTID 6ULL
59 * All files have objectids higher than this.
61 #define BTRFS_FIRST_FREE_OBJECTID 256ULL
65 * the device items go into the chunk tree. The key is in the form
66 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
68 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
71 * we can actually store much bigger names, but lets not confuse the rest
72 * of linux
74 #define BTRFS_NAME_LEN 255
76 /* 32 bytes in various csum fields */
77 #define BTRFS_CSUM_SIZE 32
78 /* four bytes for CRC32 */
79 #define BTRFS_CRC32_SIZE 4
80 #define BTRFS_EMPTY_DIR_SIZE 0
82 #define BTRFS_FT_UNKNOWN 0
83 #define BTRFS_FT_REG_FILE 1
84 #define BTRFS_FT_DIR 2
85 #define BTRFS_FT_CHRDEV 3
86 #define BTRFS_FT_BLKDEV 4
87 #define BTRFS_FT_FIFO 5
88 #define BTRFS_FT_SOCK 6
89 #define BTRFS_FT_SYMLINK 7
90 #define BTRFS_FT_XATTR 8
91 #define BTRFS_FT_MAX 9
94 * the key defines the order in the tree, and so it also defines (optimal)
95 * block layout. objectid corresonds to the inode number. The flags
96 * tells us things about the object, and is a kind of stream selector.
97 * so for a given inode, keys with flags of 1 might refer to the inode
98 * data, flags of 2 may point to file data in the btree and flags == 3
99 * may point to extents.
101 * offset is the starting byte offset for this key in the stream.
103 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
104 * in cpu native order. Otherwise they are identical and their sizes
105 * should be the same (ie both packed)
107 struct btrfs_disk_key {
108 __le64 objectid;
109 u8 type;
110 __le64 offset;
111 } __attribute__ ((__packed__));
113 struct btrfs_key {
114 u64 objectid;
115 u8 type;
116 u64 offset;
117 } __attribute__ ((__packed__));
119 struct btrfs_mapping_tree {
120 struct cache_tree cache_tree;
123 #define BTRFS_DEV_UUID_SIZE 16
124 struct btrfs_dev_item {
125 /* the internal btrfs device id */
126 __le64 devid;
128 /* size of the device */
129 __le64 total_bytes;
131 /* bytes used */
132 __le64 bytes_used;
134 /* optimal io alignment for this device */
135 __le32 io_align;
137 /* optimal io width for this device */
138 __le32 io_width;
140 /* minimal io size for this device */
141 __le32 sector_size;
143 /* type and info about this device */
144 __le64 type;
146 /* btrfs generated uuid for this device */
147 u8 uuid[BTRFS_DEV_UUID_SIZE];
148 } __attribute__ ((__packed__));
150 struct btrfs_stripe {
151 __le64 devid;
152 __le64 offset;
153 } __attribute__ ((__packed__));
155 struct btrfs_chunk {
156 __le64 owner;
157 __le64 stripe_len;
158 __le64 type;
160 /* optimal io alignment for this chunk */
161 __le32 io_align;
163 /* optimal io width for this chunk */
164 __le32 io_width;
166 /* minimal io size for this chunk */
167 __le32 sector_size;
169 /* 2^16 stripes is quite a lot, a second limit is the size of a single
170 * item in the btree
172 __le16 num_stripes;
173 struct btrfs_stripe stripe;
174 /* additional stripes go here */
175 } __attribute__ ((__packed__));
177 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
179 BUG_ON(num_stripes == 0);
180 return sizeof(struct btrfs_chunk) +
181 sizeof(struct btrfs_stripe) * (num_stripes - 1);
184 #define BTRFS_FSID_SIZE 16
185 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
188 * every tree block (leaf or node) starts with this header.
190 struct btrfs_header {
191 u8 csum[BTRFS_CSUM_SIZE];
192 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
193 __le64 bytenr; /* which block this node is supposed to live in */
194 __le64 flags;
195 __le64 generation;
196 __le64 owner;
197 __le32 nritems;
198 u8 level;
199 } __attribute__ ((__packed__));
201 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
202 sizeof(struct btrfs_header)) / \
203 sizeof(struct btrfs_key_ptr))
204 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
205 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
206 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
207 sizeof(struct btrfs_item) - \
208 sizeof(struct btrfs_file_extent_item))
211 * this is a very generous portion of the super block, giving us
212 * room to translate 14 chunks with 3 stripes each.
214 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
217 * the super block basically lists the main trees of the FS
218 * it currently lacks any block count etc etc
220 struct btrfs_super_block {
221 u8 csum[BTRFS_CSUM_SIZE];
222 /* the first 3 fields must match struct btrfs_header */
223 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
224 __le64 bytenr; /* this block number */
225 __le64 flags;
226 __le64 magic;
227 __le64 generation;
228 __le64 root;
229 __le64 chunk_root;
230 __le64 total_bytes;
231 __le64 bytes_used;
232 __le64 root_dir_objectid;
233 __le64 num_devices;
234 __le32 sectorsize;
235 __le32 nodesize;
236 __le32 leafsize;
237 __le32 stripesize;
238 __le32 sys_chunk_array_size;
239 u8 root_level;
240 u8 chunk_root_level;
241 struct btrfs_dev_item dev_item;
242 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
243 } __attribute__ ((__packed__));
246 * A leaf is full of items. offset and size tell us where to find
247 * the item in the leaf (relative to the start of the data area)
249 struct btrfs_item {
250 struct btrfs_disk_key key;
251 __le32 offset;
252 __le32 size;
253 } __attribute__ ((__packed__));
256 * leaves have an item area and a data area:
257 * [item0, item1....itemN] [free space] [dataN...data1, data0]
259 * The data is separate from the items to get the keys closer together
260 * during searches.
262 struct btrfs_leaf {
263 struct btrfs_header header;
264 struct btrfs_item items[];
265 } __attribute__ ((__packed__));
268 * all non-leaf blocks are nodes, they hold only keys and pointers to
269 * other blocks
271 struct btrfs_key_ptr {
272 struct btrfs_disk_key key;
273 __le64 blockptr;
274 __le64 generation;
275 } __attribute__ ((__packed__));
277 struct btrfs_node {
278 struct btrfs_header header;
279 struct btrfs_key_ptr ptrs[];
280 } __attribute__ ((__packed__));
283 * btrfs_paths remember the path taken from the root down to the leaf.
284 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
285 * to any other levels that are present.
287 * The slots array records the index of the item or block pointer
288 * used while walking the tree.
290 struct btrfs_path {
291 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
292 int slots[BTRFS_MAX_LEVEL];
293 int reada;
294 int lowest_level;
298 * items in the extent btree are used to record the objectid of the
299 * owner of the block and the number of references
301 struct btrfs_extent_item {
302 __le32 refs;
303 } __attribute__ ((__packed__));
305 struct btrfs_extent_ref {
306 __le64 root;
307 __le64 generation;
308 __le64 objectid;
309 __le64 offset;
310 } __attribute__ ((__packed__));
312 /* dev extents record free space on individual devices. The owner
313 * field points back to the chunk allocation mapping tree that allocated
314 * the extent
316 struct btrfs_dev_extent {
317 __le64 owner;
318 __le64 length;
319 } __attribute__ ((__packed__));
322 struct btrfs_inode_ref {
323 __le16 name_len;
324 /* name goes here */
325 } __attribute__ ((__packed__));
327 struct btrfs_timespec {
328 __le64 sec;
329 __le32 nsec;
330 } __attribute__ ((__packed__));
333 * there is no padding here on purpose. If you want to extent the inode,
334 * make a new item type
336 struct btrfs_inode_item {
337 __le64 generation;
338 __le64 size;
339 __le64 nblocks;
340 __le64 block_group;
341 __le32 nlink;
342 __le32 uid;
343 __le32 gid;
344 __le32 mode;
345 __le64 rdev;
346 __le16 flags;
347 __le16 compat_flags;
348 struct btrfs_timespec atime;
349 struct btrfs_timespec ctime;
350 struct btrfs_timespec mtime;
351 struct btrfs_timespec otime;
352 } __attribute__ ((__packed__));
354 struct btrfs_dir_item {
355 struct btrfs_disk_key location;
356 __le16 data_len;
357 __le16 name_len;
358 u8 type;
359 } __attribute__ ((__packed__));
361 struct btrfs_root_item {
362 struct btrfs_inode_item inode;
363 __le64 root_dirid;
364 __le64 bytenr;
365 __le64 byte_limit;
366 __le64 bytes_used;
367 __le32 flags;
368 __le32 refs;
369 struct btrfs_disk_key drop_progress;
370 u8 drop_level;
371 u8 level;
372 } __attribute__ ((__packed__));
374 #define BTRFS_FILE_EXTENT_REG 0
375 #define BTRFS_FILE_EXTENT_INLINE 1
377 struct btrfs_file_extent_item {
378 __le64 generation;
379 u8 type;
381 * disk space consumed by the extent, checksum blocks are included
382 * in these numbers
384 __le64 disk_bytenr;
385 __le64 disk_num_bytes;
387 * the logical offset in file blocks (no csums)
388 * this extent record is for. This allows a file extent to point
389 * into the middle of an existing extent on disk, sharing it
390 * between two snapshots (useful if some bytes in the middle of the
391 * extent have changed
393 __le64 offset;
395 * the logical number of file blocks (no csums included)
397 __le64 num_bytes;
398 } __attribute__ ((__packed__));
400 struct btrfs_csum_item {
401 u8 csum;
402 } __attribute__ ((__packed__));
404 /* tag for the radix tree of block groups in ram */
405 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
406 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
407 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
408 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
409 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
410 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
412 struct btrfs_block_group_item {
413 __le64 used;
414 __le64 chunk_tree;
415 __le64 chunk_objectid;
416 __le64 flags;
417 } __attribute__ ((__packed__));
419 struct btrfs_space_info {
420 u64 flags;
421 u64 total_bytes;
422 u64 bytes_used;
423 u64 bytes_pinned;
424 int full;
425 struct list_head list;
428 struct btrfs_block_group_cache {
429 struct cache_extent cache;
430 struct btrfs_key key;
431 struct btrfs_block_group_item item;
432 struct btrfs_space_info *space_info;
433 u64 pinned;
434 u64 flags;
435 int cached;
438 struct btrfs_extent_ops {
439 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
440 u64 hint_byte, struct btrfs_key *ins);
441 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
442 u64 num_bytes);
445 struct btrfs_device;
446 struct btrfs_fs_devices;
447 struct btrfs_fs_info {
448 u8 fsid[BTRFS_FSID_SIZE];
449 struct btrfs_root *fs_root;
450 struct btrfs_root *extent_root;
451 struct btrfs_root *tree_root;
452 struct btrfs_root *chunk_root;
453 struct btrfs_root *dev_root;
455 struct extent_io_tree extent_cache;
456 struct extent_io_tree free_space_cache;
457 struct extent_io_tree block_group_cache;
458 struct extent_io_tree pinned_extents;
459 struct extent_io_tree pending_del;
460 struct extent_io_tree extent_ins;
462 /* logical->physical extent mapping */
463 struct btrfs_mapping_tree mapping_tree;
465 u64 generation;
466 u64 last_trans_committed;
468 u64 avail_data_alloc_bits;
469 u64 avail_metadata_alloc_bits;
470 u64 avail_system_alloc_bits;
471 u64 data_alloc_profile;
472 u64 metadata_alloc_profile;
473 u64 system_alloc_profile;
475 struct btrfs_trans_handle *running_transaction;
476 struct btrfs_super_block super_copy;
477 struct extent_buffer *sb_buffer;
478 struct mutex fs_mutex;
479 u64 total_pinned;
481 struct btrfs_extent_ops *extent_ops;
482 struct list_head dirty_cowonly_roots;
484 struct btrfs_fs_devices *fs_devices;
485 struct list_head space_info;
486 int fp;
487 int force_system_allocs;
488 void *priv_data;
492 * in ram representation of the tree. extent_root is used for all allocations
493 * and for the extent tree extent_root root.
495 struct btrfs_root {
496 struct extent_buffer *node;
497 struct extent_buffer *commit_root;
498 struct btrfs_root_item root_item;
499 struct btrfs_key root_key;
500 struct btrfs_fs_info *fs_info;
501 u64 objectid;
502 u64 last_trans;
504 /* data allocations are done in sectorsize units */
505 u32 sectorsize;
507 /* node allocations are done in nodesize units */
508 u32 nodesize;
510 /* leaf allocations are done in leafsize units */
511 u32 leafsize;
513 /* leaf allocations are done in leafsize units */
514 u32 stripesize;
516 int ref_cows;
517 int track_dirty;
520 u32 type;
521 u64 highest_inode;
522 u64 last_inode_alloc;
524 /* the dirty list is only used by non-reference counted roots */
525 struct list_head dirty_list;
529 * inode items have the data typically returned from stat and store other
530 * info about object characteristics. There is one for every file and dir in
531 * the FS
533 #define BTRFS_INODE_ITEM_KEY 1
534 #define BTRFS_INODE_REF_KEY 2
535 #define BTRFS_XATTR_ITEM_KEY 8
537 /* reserve 3-15 close to the inode for later flexibility */
540 * dir items are the name -> inode pointers in a directory. There is one
541 * for every name in a directory.
543 #define BTRFS_DIR_ITEM_KEY 16
544 #define BTRFS_DIR_INDEX_KEY 17
546 * extent data is for file data
548 #define BTRFS_EXTENT_DATA_KEY 18
550 * csum items have the checksums for data in the extents
552 #define BTRFS_CSUM_ITEM_KEY 19
554 /* reserve 20-31 for other file stuff */
557 * root items point to tree roots. There are typically in the root
558 * tree used by the super block to find all the other trees
560 #define BTRFS_ROOT_ITEM_KEY 32
562 * extent items are in the extent map tree. These record which blocks
563 * are used, and how many references there are to each block
565 #define BTRFS_EXTENT_ITEM_KEY 33
566 #define BTRFS_EXTENT_REF_KEY 34
569 * block groups give us hints into the extent allocation trees. Which
570 * blocks are free etc etc
572 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
574 #define BTRFS_DEV_EXTENT_KEY 75
575 #define BTRFS_DEV_ITEM_KEY 76
576 #define BTRFS_CHUNK_ITEM_KEY 77
579 * string items are for debugging. They just store a short string of
580 * data in the FS
582 #define BTRFS_STRING_ITEM_KEY 253
584 * Inode flags
586 #define BTRFS_INODE_NODATASUM (1 << 0)
587 #define BTRFS_INODE_NODATACOW (1 << 1)
588 #define BTRFS_INODE_READONLY (1 << 2)
590 #define read_eb_member(eb, ptr, type, member, result) ( \
591 read_extent_buffer(eb, (char *)(result), \
592 ((unsigned long)(ptr)) + \
593 offsetof(type, member), \
594 sizeof(((type *)0)->member)))
596 #define write_eb_member(eb, ptr, type, member, result) ( \
597 write_extent_buffer(eb, (char *)(result), \
598 ((unsigned long)(ptr)) + \
599 offsetof(type, member), \
600 sizeof(((type *)0)->member)))
602 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
603 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
605 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
606 return le##bits##_to_cpu(h->member); \
608 static inline void btrfs_set_##name(struct extent_buffer *eb, \
609 u##bits val) \
611 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
612 h->member = cpu_to_le##bits(val); \
615 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
616 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
617 type *s) \
619 unsigned long offset = (unsigned long)s; \
620 type *p = (type *) (eb->data + offset); \
621 return le##bits##_to_cpu(p->member); \
623 static inline void btrfs_set_##name(struct extent_buffer *eb, \
624 type *s, u##bits val) \
626 unsigned long offset = (unsigned long)s; \
627 type *p = (type *) (eb->data + offset); \
628 p->member = cpu_to_le##bits(val); \
631 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
632 static inline u##bits btrfs_##name(type *s) \
634 return le##bits##_to_cpu(s->member); \
636 static inline void btrfs_set_##name(type *s, u##bits val) \
638 s->member = cpu_to_le##bits(val); \
641 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
642 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
643 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
644 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
645 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
646 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
647 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
649 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
650 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
651 total_bytes, 64);
652 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
653 bytes_used, 64);
654 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
655 io_align, 32);
656 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
657 io_width, 32);
658 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
659 sector_size, 32);
660 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
662 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
664 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
667 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
668 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
669 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
670 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
671 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
672 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
673 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
674 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
675 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
677 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
678 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
679 stripe_len, 64);
680 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
681 io_align, 32);
682 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
683 io_width, 32);
684 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
685 sector_size, 32);
686 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
687 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
688 num_stripes, 16);
689 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
690 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
692 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
693 int nr)
695 unsigned long offset = (unsigned long)c;
696 offset += offsetof(struct btrfs_chunk, stripe);
697 offset += nr * sizeof(struct btrfs_stripe);
698 return (struct btrfs_stripe *)offset;
701 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
702 struct btrfs_chunk *c, int nr)
704 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
707 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
708 struct btrfs_chunk *c, int nr,
709 u64 val)
711 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
714 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
715 struct btrfs_chunk *c, int nr)
717 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
720 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
721 struct btrfs_chunk *c, int nr,
722 u64 val)
724 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
727 /* struct btrfs_block_group_item */
728 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
729 used, 64);
730 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
731 used, 64);
732 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_tree, struct btrfs_block_group_item,
733 chunk_tree, 64);
734 BTRFS_SETGET_FUNCS(disk_block_group_chunk_tree, struct btrfs_block_group_item,
735 chunk_tree, 64);
736 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
737 struct btrfs_block_group_item, chunk_objectid, 64);
738 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objecitd,
739 struct btrfs_block_group_item, chunk_objectid, 64);
740 BTRFS_SETGET_FUNCS(disk_block_group_flags,
741 struct btrfs_block_group_item, flags, 64);
742 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
743 struct btrfs_block_group_item, flags, 64);
745 /* struct btrfs_inode_ref */
746 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
748 /* struct btrfs_inode_item */
749 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
750 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
751 BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
752 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
753 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
754 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
755 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
756 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
757 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
758 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
759 BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
760 compat_flags, 16);
762 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
763 struct btrfs_inode_item, generation, 64);
764 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
765 struct btrfs_inode_item, size, 64);
766 BTRFS_SETGET_STACK_FUNCS(stack_inode_nblocks,
767 struct btrfs_inode_item, nblocks, 64);
768 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
769 struct btrfs_inode_item, block_group, 64);
770 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
771 struct btrfs_inode_item, nlink, 32);
772 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
773 struct btrfs_inode_item, uid, 32);
774 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
775 struct btrfs_inode_item, gid, 32);
776 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
777 struct btrfs_inode_item, mode, 32);
778 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
779 struct btrfs_inode_item, rdev, 64);
780 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
781 struct btrfs_inode_item, flags, 16);
782 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags,
783 struct btrfs_inode_item, compat_flags, 16);
785 static inline struct btrfs_timespec *
786 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
788 unsigned long ptr = (unsigned long)inode_item;
789 ptr += offsetof(struct btrfs_inode_item, atime);
790 return (struct btrfs_timespec *)ptr;
793 static inline struct btrfs_timespec *
794 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
796 unsigned long ptr = (unsigned long)inode_item;
797 ptr += offsetof(struct btrfs_inode_item, mtime);
798 return (struct btrfs_timespec *)ptr;
801 static inline struct btrfs_timespec *
802 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
804 unsigned long ptr = (unsigned long)inode_item;
805 ptr += offsetof(struct btrfs_inode_item, ctime);
806 return (struct btrfs_timespec *)ptr;
809 static inline struct btrfs_timespec *
810 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
812 unsigned long ptr = (unsigned long)inode_item;
813 ptr += offsetof(struct btrfs_inode_item, otime);
814 return (struct btrfs_timespec *)ptr;
817 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
818 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
819 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
820 sec, 64);
821 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
822 nsec, 32);
824 /* struct btrfs_dev_extent */
825 BTRFS_SETGET_FUNCS(dev_extent_owner, struct btrfs_dev_extent, owner, 64);
826 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
828 /* struct btrfs_extent_item */
829 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
831 /* struct btrfs_extent_ref */
832 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
833 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
834 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
835 BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
837 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
838 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
839 generation, 64);
840 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
841 objectid, 64);
842 BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
844 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
845 refs, 32);
847 /* struct btrfs_node */
848 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
849 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
851 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
853 unsigned long ptr;
854 ptr = offsetof(struct btrfs_node, ptrs) +
855 sizeof(struct btrfs_key_ptr) * nr;
856 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
859 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
860 int nr, u64 val)
862 unsigned long ptr;
863 ptr = offsetof(struct btrfs_node, ptrs) +
864 sizeof(struct btrfs_key_ptr) * nr;
865 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
868 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
870 unsigned long ptr;
871 ptr = offsetof(struct btrfs_node, ptrs) +
872 sizeof(struct btrfs_key_ptr) * nr;
873 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
876 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
877 int nr, u64 val)
879 unsigned long ptr;
880 ptr = offsetof(struct btrfs_node, ptrs) +
881 sizeof(struct btrfs_key_ptr) * nr;
882 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
885 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
887 return offsetof(struct btrfs_node, ptrs) +
888 sizeof(struct btrfs_key_ptr) * nr;
891 static inline void btrfs_node_key(struct extent_buffer *eb,
892 struct btrfs_disk_key *disk_key, int nr)
894 unsigned long ptr;
895 ptr = btrfs_node_key_ptr_offset(nr);
896 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
897 struct btrfs_key_ptr, key, disk_key);
900 static inline void btrfs_set_node_key(struct extent_buffer *eb,
901 struct btrfs_disk_key *disk_key, int nr)
903 unsigned long ptr;
904 ptr = btrfs_node_key_ptr_offset(nr);
905 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
906 struct btrfs_key_ptr, key, disk_key);
909 /* struct btrfs_item */
910 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
911 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
913 static inline unsigned long btrfs_item_nr_offset(int nr)
915 return offsetof(struct btrfs_leaf, items) +
916 sizeof(struct btrfs_item) * nr;
919 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
920 int nr)
922 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
925 static inline u32 btrfs_item_end(struct extent_buffer *eb,
926 struct btrfs_item *item)
928 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
931 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
933 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
936 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
938 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
941 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
943 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
946 static inline void btrfs_item_key(struct extent_buffer *eb,
947 struct btrfs_disk_key *disk_key, int nr)
949 struct btrfs_item *item = btrfs_item_nr(eb, nr);
950 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
953 static inline void btrfs_set_item_key(struct extent_buffer *eb,
954 struct btrfs_disk_key *disk_key, int nr)
956 struct btrfs_item *item = btrfs_item_nr(eb, nr);
957 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
960 /* struct btrfs_dir_item */
961 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
962 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
963 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
965 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
966 struct btrfs_dir_item *item,
967 struct btrfs_disk_key *key)
969 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
972 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
973 struct btrfs_dir_item *item,
974 struct btrfs_disk_key *key)
976 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
979 /* struct btrfs_disk_key */
980 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
981 objectid, 64);
982 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
983 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
985 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
986 struct btrfs_disk_key *disk)
988 cpu->offset = le64_to_cpu(disk->offset);
989 cpu->type = disk->type;
990 cpu->objectid = le64_to_cpu(disk->objectid);
993 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
994 struct btrfs_key *cpu)
996 disk->offset = cpu_to_le64(cpu->offset);
997 disk->type = cpu->type;
998 disk->objectid = cpu_to_le64(cpu->objectid);
1001 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1002 struct btrfs_key *key, int nr)
1004 struct btrfs_disk_key disk_key;
1005 btrfs_node_key(eb, &disk_key, nr);
1006 btrfs_disk_key_to_cpu(key, &disk_key);
1009 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1010 struct btrfs_key *key, int nr)
1012 struct btrfs_disk_key disk_key;
1013 btrfs_item_key(eb, &disk_key, nr);
1014 btrfs_disk_key_to_cpu(key, &disk_key);
1017 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1018 struct btrfs_dir_item *item,
1019 struct btrfs_key *key)
1021 struct btrfs_disk_key disk_key;
1022 btrfs_dir_item_key(eb, item, &disk_key);
1023 btrfs_disk_key_to_cpu(key, &disk_key);
1027 static inline u8 btrfs_key_type(struct btrfs_key *key)
1029 return key->type;
1032 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1034 key->type = val;
1037 /* struct btrfs_header */
1038 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1039 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1040 generation, 64);
1041 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1042 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1043 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1044 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1046 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1048 return (btrfs_header_flags(eb) & flag) == flag;
1051 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1053 u64 flags = btrfs_header_flags(eb);
1054 btrfs_set_header_flags(eb, flags | flag);
1055 return (flags & flag) == flag;
1058 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1060 u64 flags = btrfs_header_flags(eb);
1061 btrfs_set_header_flags(eb, flags & ~flag);
1062 return (flags & flag) == flag;
1065 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1067 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1068 return (u8 *)ptr;
1071 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1073 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1074 return (u8 *)ptr;
1077 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1079 unsigned long ptr = offsetof(struct btrfs_header, csum);
1080 return (u8 *)ptr;
1083 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1085 return NULL;
1088 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1090 return NULL;
1093 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1095 return NULL;
1098 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1100 return (btrfs_header_level(eb) == 0);
1103 /* struct btrfs_root_item */
1104 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1105 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1106 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1108 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1109 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1110 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1111 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1112 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
1113 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1114 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1116 /* struct btrfs_super_block */
1117 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1118 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1119 generation, 64);
1120 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1121 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1122 struct btrfs_super_block, sys_chunk_array_size, 32);
1123 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1124 root_level, 8);
1125 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1126 chunk_root, 64);
1127 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1128 chunk_root_level, 64);
1129 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1130 total_bytes, 64);
1131 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1132 bytes_used, 64);
1133 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1134 sectorsize, 32);
1135 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1136 nodesize, 32);
1137 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1138 leafsize, 32);
1139 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1140 stripesize, 32);
1141 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1142 root_dir_objectid, 64);
1143 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1144 num_devices, 64);
1146 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1148 return offsetof(struct btrfs_leaf, items);
1151 /* struct btrfs_file_extent_item */
1152 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1154 static inline unsigned long btrfs_file_extent_inline_start(struct
1155 btrfs_file_extent_item *e)
1157 unsigned long offset = (unsigned long)e;
1158 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1159 return offset;
1162 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1164 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1167 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1168 struct btrfs_item *e)
1170 unsigned long offset;
1171 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1172 return btrfs_item_size(eb, e) - offset;
1175 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1176 disk_bytenr, 64);
1177 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1178 generation, 64);
1179 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1180 disk_num_bytes, 64);
1181 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1182 offset, 64);
1183 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1184 num_bytes, 64);
1186 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1187 if (level == 0)
1188 return root->leafsize;
1189 return root->nodesize;
1192 /* helper function to cast into the data area of the leaf. */
1193 #define btrfs_item_ptr(leaf, slot, type) \
1194 ((type *)(btrfs_leaf_data(leaf) + \
1195 btrfs_item_offset_nr(leaf, slot)))
1197 #define btrfs_item_ptr_offset(leaf, slot) \
1198 ((unsigned long)(btrfs_leaf_data(leaf) + \
1199 btrfs_item_offset_nr(leaf, slot)))
1201 /* extent-tree.c */
1202 u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
1203 struct btrfs_path *count_path,
1204 u64 first_extent);
1205 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1206 struct btrfs_root *root);
1207 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1208 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1209 btrfs_fs_info *info,
1210 u64 bytenr);
1211 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1212 struct btrfs_block_group_cache
1213 *hint, u64 search_start,
1214 int data, int owner);
1215 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1216 struct btrfs_root *root, u64 owner_objectid);
1217 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1218 struct btrfs_root *root, u32 size,
1219 u64 root_objectid,
1220 u64 hint, u64 empty_size);
1221 struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1222 struct btrfs_root *root,
1223 u32 blocksize,
1224 u64 root_objectid,
1225 u64 ref_generation,
1226 u64 first_objectid,
1227 int level,
1228 u64 hint,
1229 u64 empty_size);
1230 int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
1231 struct btrfs_root *root, u64 new_size);
1232 int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
1233 int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1234 struct btrfs_root *root,
1235 struct btrfs_path *path, u64 bytenr,
1236 u64 root_objectid, u64 ref_generation,
1237 u64 owner, u64 owner_offset);
1238 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1239 struct btrfs_root *root,
1240 u64 num_bytes, u64 root_objectid, u64 ref_generation,
1241 u64 owner, u64 owner_offset,
1242 u64 empty_size, u64 hint_byte,
1243 u64 search_end, struct btrfs_key *ins, int data);
1244 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1245 struct extent_buffer *buf);
1246 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1247 *root, u64 bytenr, u64 num_bytes,
1248 u64 root_objectid, u64 ref_generation,
1249 u64 owner_objectid, u64 owner_offset, int pin);
1250 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1251 struct btrfs_root *root,
1252 struct extent_io_tree *unpin);
1253 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1254 struct btrfs_root *root,
1255 u64 bytenr, u64 num_bytes,
1256 u64 root_objectid, u64 ref_generation,
1257 u64 owner, u64 owner_offset);
1258 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1259 struct btrfs_root *root);
1260 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1261 int btrfs_read_block_groups(struct btrfs_root *root);
1262 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1263 struct btrfs_root *root, u64 bytes_used,
1264 u64 type, u64 chunk_tree, u64 chunk_objectid,
1265 u64 size);
1266 u64 btrfs_hash_extent_ref(u64 root_objectid, u64 ref_generation,
1267 u64 owner, u64 owner_offset);
1268 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1269 struct btrfs_root *root, u64 bytenr, u64 num,
1270 int alloc, int mark_free);
1271 /* ctree.c */
1272 int btrfs_previous_item(struct btrfs_root *root,
1273 struct btrfs_path *path, u64 min_objectid,
1274 int type);
1275 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1276 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1277 struct btrfs_root *root, struct extent_buffer *buf,
1278 struct extent_buffer *parent, int parent_slot,
1279 struct extent_buffer **cow_ret);
1280 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1281 struct btrfs_root *root,
1282 struct extent_buffer *buf,
1283 struct extent_buffer *parent, int parent_slot,
1284 struct extent_buffer **cow_ret,
1285 u64 search_start, u64 empty_size);
1286 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1287 struct btrfs_root *root,
1288 struct extent_buffer *buf,
1289 struct extent_buffer **cow_ret, u64 new_root_objectid);
1290 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1291 *root, struct btrfs_path *path, u32 data_size);
1292 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1293 struct btrfs_root *root,
1294 struct btrfs_path *path,
1295 u32 new_size, int from_end);
1296 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1297 *root, struct btrfs_key *key, struct btrfs_path *p, int
1298 ins_len, int cow);
1299 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1300 struct btrfs_root *root, struct extent_buffer *parent,
1301 int start_slot, int cache_only, u64 *last_ret,
1302 struct btrfs_key *progress);
1303 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1304 struct btrfs_path *btrfs_alloc_path(void);
1305 void btrfs_free_path(struct btrfs_path *p);
1306 void btrfs_init_path(struct btrfs_path *p);
1307 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1308 struct btrfs_path *path, int slot, int nr);
1310 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1311 struct btrfs_root *root,
1312 struct btrfs_path *path)
1314 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1317 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1318 *root, struct btrfs_key *key, void *data, u32 data_size);
1319 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1320 struct btrfs_root *root,
1321 struct btrfs_path *path,
1322 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1324 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1325 struct btrfs_root *root,
1326 struct btrfs_path *path,
1327 struct btrfs_key *key,
1328 u32 data_size)
1330 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1333 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1334 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1335 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1336 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1337 *root);
1340 /* root-item.c */
1341 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1342 struct btrfs_key *key);
1343 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1344 *root, struct btrfs_key *key, struct btrfs_root_item
1345 *item);
1346 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1347 *root, struct btrfs_key *key, struct btrfs_root_item
1348 *item);
1349 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1350 btrfs_root_item *item, struct btrfs_key *key);
1351 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1352 struct btrfs_root *latest_root);
1353 /* dir-item.c */
1354 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1355 *root, const char *name, int name_len, u64 dir,
1356 struct btrfs_key *location, u8 type);
1357 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1358 struct btrfs_root *root,
1359 struct btrfs_path *path, u64 dir,
1360 const char *name, int name_len,
1361 int mod);
1362 struct btrfs_dir_item *
1363 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1364 struct btrfs_root *root,
1365 struct btrfs_path *path, u64 dir,
1366 u64 objectid, const char *name, int name_len,
1367 int mod);
1368 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1369 struct btrfs_path *path,
1370 const char *name, int name_len);
1371 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1372 struct btrfs_root *root,
1373 struct btrfs_path *path,
1374 struct btrfs_dir_item *di);
1375 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1376 struct btrfs_root *root, const char *name,
1377 u16 name_len, const void *data, u16 data_len,
1378 u64 dir);
1379 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1380 struct btrfs_root *root,
1381 struct btrfs_path *path, u64 dir,
1382 const char *name, u16 name_len,
1383 int mod);
1384 /* inode-map.c */
1385 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1386 struct btrfs_root *fs_root,
1387 u64 dirid, u64 *objectid);
1388 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1390 /* inode-item.c */
1391 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1392 struct btrfs_root *root,
1393 const char *name, int name_len,
1394 u64 inode_objectid, u64 ref_objectid);
1395 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1396 struct btrfs_root *root,
1397 const char *name, int name_len,
1398 u64 inode_objectid, u64 ref_objectid);
1399 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1400 struct btrfs_root *root,
1401 struct btrfs_path *path, u64 objectid);
1402 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1403 *root, u64 objectid, struct btrfs_inode_item
1404 *inode_item);
1405 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1406 *root, struct btrfs_path *path,
1407 struct btrfs_key *location, int mod);
1409 /* file-item.c */
1410 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1411 struct btrfs_root *root,
1412 u64 objectid, u64 pos, u64 offset,
1413 u64 disk_num_bytes,
1414 u64 num_bytes);
1415 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1416 struct btrfs_root *root, u64 objectid,
1417 u64 offset, char *buffer, size_t size);
1418 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1419 struct btrfs_root *root,
1420 struct btrfs_path *path, u64 objectid,
1421 u64 bytenr, int mod);
1422 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1423 struct btrfs_root *root,
1424 struct btrfs_inode_item *inode,
1425 u64 objectid, u64 offset,
1426 char *data, size_t len);
1427 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1428 struct btrfs_root *root,
1429 struct btrfs_path *path,
1430 u64 objectid, u64 offset,
1431 int cow);
1432 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1433 struct btrfs_root *root, struct btrfs_path *path,
1434 u64 isize);
1435 #endif