5 #include <linux/buffer_head.h>
6 #include <linux/kobject.h>
9 struct btrfs_trans_handle;
10 struct btrfs_transaction;
11 extern struct kmem_cache *btrfs_trans_handle_cachep;
12 extern struct kmem_cache *btrfs_transaction_cachep;
13 extern struct kmem_cache *btrfs_bit_radix_cachep;
14 extern struct kmem_cache *btrfs_path_cachep;
16 #define BTRFS_MAGIC "_BtRfS_M"
18 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
19 #define BTRFS_DEV_TREE_OBJECTID 2ULL
20 #define BTRFS_EXTENT_TREE_OBJECTID 3ULL
21 #define BTRFS_FS_TREE_OBJECTID 4ULL
22 #define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
23 #define BTRFS_FIRST_FREE_OBJECTID 6ULL
26 * we can actually store much bigger names, but lets not confuse the rest
29 #define BTRFS_NAME_LEN 255
31 /* 32 bytes in various csum fields */
32 #define BTRFS_CSUM_SIZE 32
33 /* four bytes for CRC32 */
34 #define BTRFS_CRC32_SIZE 4
37 * the key defines the order in the tree, and so it also defines (optimal)
38 * block layout. objectid corresonds to the inode number. The flags
39 * tells us things about the object, and is a kind of stream selector.
40 * so for a given inode, keys with flags of 1 might refer to the inode
41 * data, flags of 2 may point to file data in the btree and flags == 3
42 * may point to extents.
44 * offset is the starting byte offset for this key in the stream.
46 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
47 * in cpu native order. Otherwise they are identical and their sizes
48 * should be the same (ie both packed)
50 struct btrfs_disk_key {
54 } __attribute__ ((__packed__));
60 } __attribute__ ((__packed__));
63 * every tree block (leaf or node) starts with this header.
66 u8 csum[BTRFS_CSUM_SIZE];
67 u8 fsid[16]; /* FS specific uuid */
68 __le64 blocknr; /* which block this node is supposed to live in */
74 } __attribute__ ((__packed__));
76 #define BTRFS_MAX_LEVEL 8
77 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
78 sizeof(struct btrfs_header)) / \
79 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
80 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
81 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
82 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
83 sizeof(struct btrfs_item) - \
84 sizeof(struct btrfs_file_extent_item))
88 * the super block basically lists the main trees of the FS
89 * it currently lacks any block count etc etc
91 struct btrfs_super_block {
92 u8 csum[BTRFS_CSUM_SIZE];
93 /* the first 3 fields must match struct btrfs_header */
94 u8 fsid[16]; /* FS specific uuid */
95 __le64 blocknr; /* this block number */
102 __le64 root_dir_objectid;
103 __le64 last_device_id;
104 /* fields below here vary with the underlying disk */
105 __le64 device_block_start;
106 __le64 device_num_blocks;
109 } __attribute__ ((__packed__));
112 * A leaf is full of items. offset and size tell us where to find
113 * the item in the leaf (relative to the start of the data area)
116 struct btrfs_disk_key key;
119 } __attribute__ ((__packed__));
122 * leaves have an item area and a data area:
123 * [item0, item1....itemN] [free space] [dataN...data1, data0]
125 * The data is separate from the items to get the keys closer together
129 struct btrfs_header header;
130 struct btrfs_item items[];
131 } __attribute__ ((__packed__));
134 * all non-leaf blocks are nodes, they hold only keys and pointers to
137 struct btrfs_key_ptr {
138 struct btrfs_disk_key key;
140 } __attribute__ ((__packed__));
143 struct btrfs_header header;
144 struct btrfs_key_ptr ptrs[];
145 } __attribute__ ((__packed__));
148 * btrfs_paths remember the path taken from the root down to the leaf.
149 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
150 * to any other levels that are present.
152 * The slots array records the index of the item or block pointer
153 * used while walking the tree.
156 struct buffer_head *nodes[BTRFS_MAX_LEVEL];
157 int slots[BTRFS_MAX_LEVEL];
161 * items in the extent btree are used to record the objectid of the
162 * owner of the block and the number of references
164 struct btrfs_extent_item {
167 } __attribute__ ((__packed__));
169 struct btrfs_inode_timespec {
172 } __attribute__ ((__packed__));
175 * there is no padding here on purpose. If you want to extent the inode,
176 * make a new item type
178 struct btrfs_inode_item {
190 struct btrfs_inode_timespec atime;
191 struct btrfs_inode_timespec ctime;
192 struct btrfs_inode_timespec mtime;
193 struct btrfs_inode_timespec otime;
194 } __attribute__ ((__packed__));
196 struct btrfs_dir_item {
197 struct btrfs_disk_key location;
201 } __attribute__ ((__packed__));
203 struct btrfs_root_item {
204 struct btrfs_inode_item inode;
211 } __attribute__ ((__packed__));
213 #define BTRFS_FILE_EXTENT_REG 0
214 #define BTRFS_FILE_EXTENT_INLINE 1
216 struct btrfs_file_extent_item {
220 * disk space consumed by the extent, checksum blocks are included
224 __le64 disk_num_blocks;
226 * the logical offset in file blocks (no csums)
227 * this extent record is for. This allows a file extent to point
228 * into the middle of an existing extent on disk, sharing it
229 * between two snapshots (useful if some bytes in the middle of the
230 * extent have changed
234 * the logical number of file blocks (no csums included)
237 } __attribute__ ((__packed__));
239 struct btrfs_csum_item {
241 } __attribute__ ((__packed__));
243 struct btrfs_device_item {
246 } __attribute__ ((__packed__));
248 /* tag for the radix tree of block groups in ram */
249 #define BTRFS_BLOCK_GROUP_DIRTY 0
250 #define BTRFS_BLOCK_GROUP_AVAIL 1
251 #define BTRFS_BLOCK_GROUP_HINTS 8
252 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
253 struct btrfs_block_group_item {
255 } __attribute__ ((__packed__));
257 struct btrfs_block_group_cache {
258 struct btrfs_key key;
259 struct btrfs_block_group_item item;
260 struct radix_tree_root *radix;
270 struct btrfs_fs_info {
271 struct btrfs_root *extent_root;
272 struct btrfs_root *tree_root;
273 struct btrfs_root *dev_root;
274 struct radix_tree_root fs_roots_radix;
275 struct radix_tree_root pending_del_radix;
276 struct radix_tree_root pinned_radix;
277 struct radix_tree_root dev_radix;
278 struct radix_tree_root block_group_radix;
279 struct radix_tree_root block_group_data_radix;
280 struct radix_tree_root extent_map_radix;
282 u64 extent_tree_insert[BTRFS_MAX_LEVEL * 3];
283 int extent_tree_insert_nr;
284 u64 extent_tree_prealloc[BTRFS_MAX_LEVEL * 3];
285 int extent_tree_prealloc_nr;
288 struct btrfs_transaction *running_transaction;
289 struct btrfs_super_block *disk_super;
290 struct buffer_head *sb_buffer;
291 struct super_block *sb;
292 struct inode *btree_inode;
293 struct mutex trans_mutex;
294 struct mutex fs_mutex;
295 struct list_head trans_list;
296 struct crypto_hash *hash_tfm;
297 spinlock_t hash_lock;
303 * in ram representation of the tree. extent_root is used for all allocations
304 * and for the extent tree extent_root root.
307 struct buffer_head *node;
308 struct buffer_head *commit_root;
309 struct btrfs_root_item root_item;
310 struct btrfs_key root_key;
311 struct btrfs_fs_info *fs_info;
319 u64 last_inode_alloc;
322 /* the lower bits in the key flags defines the item type */
323 #define BTRFS_KEY_TYPE_MAX 256
324 #define BTRFS_KEY_TYPE_SHIFT 24
325 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
326 BTRFS_KEY_TYPE_SHIFT)
329 * inode items have the data typically returned from stat and store other
330 * info about object characteristics. There is one for every file and dir in
333 #define BTRFS_INODE_ITEM_KEY 1
335 /* reserve 2-15 close to the inode for later flexibility */
338 * dir items are the name -> inode pointers in a directory. There is one
339 * for every name in a directory.
341 #define BTRFS_DIR_ITEM_KEY 16
342 #define BTRFS_DIR_INDEX_KEY 17
344 * extent data is for file data
346 #define BTRFS_EXTENT_DATA_KEY 18
348 * csum items have the checksums for data in the extents
350 #define BTRFS_CSUM_ITEM_KEY 19
352 /* reserve 20-31 for other file stuff */
355 * root items point to tree roots. There are typically in the root
356 * tree used by the super block to find all the other trees
358 #define BTRFS_ROOT_ITEM_KEY 32
360 * extent items are in the extent map tree. These record which blocks
361 * are used, and how many references there are to each block
363 #define BTRFS_EXTENT_ITEM_KEY 33
366 * block groups give us hints into the extent allocation trees. Which
367 * blocks are free etc etc
369 #define BTRFS_BLOCK_GROUP_ITEM_KEY 34
372 * dev items list the devices that make up the FS
374 #define BTRFS_DEV_ITEM_KEY 35
377 * string items are for debugging. They just store a short string of
380 #define BTRFS_STRING_ITEM_KEY 253
383 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
385 return le64_to_cpu(bi->used);
388 static inline void btrfs_set_block_group_used(struct
389 btrfs_block_group_item *bi,
392 bi->used = cpu_to_le64(val);
395 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
397 return le64_to_cpu(i->generation);
400 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
403 i->generation = cpu_to_le64(val);
406 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
408 return le64_to_cpu(i->size);
411 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
413 i->size = cpu_to_le64(val);
416 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
418 return le64_to_cpu(i->nblocks);
421 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
423 i->nblocks = cpu_to_le64(val);
426 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
428 return le64_to_cpu(i->block_group);
431 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
434 i->block_group = cpu_to_le64(val);
437 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
439 return le32_to_cpu(i->nlink);
442 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
444 i->nlink = cpu_to_le32(val);
447 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
449 return le32_to_cpu(i->uid);
452 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
454 i->uid = cpu_to_le32(val);
457 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
459 return le32_to_cpu(i->gid);
462 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
464 i->gid = cpu_to_le32(val);
467 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
469 return le32_to_cpu(i->mode);
472 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
474 i->mode = cpu_to_le32(val);
477 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
479 return le32_to_cpu(i->rdev);
482 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
484 i->rdev = cpu_to_le32(val);
487 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
489 return le16_to_cpu(i->flags);
492 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
494 i->flags = cpu_to_le16(val);
497 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
499 return le16_to_cpu(i->compat_flags);
502 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
505 i->compat_flags = cpu_to_le16(val);
508 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
510 return le64_to_cpu(ts->sec);
513 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
516 ts->sec = cpu_to_le64(val);
519 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
521 return le32_to_cpu(ts->nsec);
524 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
527 ts->nsec = cpu_to_le32(val);
530 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
532 return le32_to_cpu(ei->refs);
535 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
537 ei->refs = cpu_to_le32(val);
540 static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
542 return le64_to_cpu(ei->owner);
545 static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val)
547 ei->owner = cpu_to_le64(val);
550 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
552 return le64_to_cpu(n->ptrs[nr].blockptr);
556 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
559 n->ptrs[nr].blockptr = cpu_to_le64(val);
562 static inline u32 btrfs_item_offset(struct btrfs_item *item)
564 return le32_to_cpu(item->offset);
567 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
569 item->offset = cpu_to_le32(val);
572 static inline u32 btrfs_item_end(struct btrfs_item *item)
574 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
577 static inline u16 btrfs_item_size(struct btrfs_item *item)
579 return le16_to_cpu(item->size);
582 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
584 item->size = cpu_to_le16(val);
587 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
589 return le16_to_cpu(d->flags);
592 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
594 d->flags = cpu_to_le16(val);
597 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
602 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
607 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
609 return le16_to_cpu(d->name_len);
612 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
614 d->name_len = cpu_to_le16(val);
617 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
618 struct btrfs_disk_key *disk)
620 cpu->offset = le64_to_cpu(disk->offset);
621 cpu->flags = le32_to_cpu(disk->flags);
622 cpu->objectid = le64_to_cpu(disk->objectid);
625 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
626 struct btrfs_key *cpu)
628 disk->offset = cpu_to_le64(cpu->offset);
629 disk->flags = cpu_to_le32(cpu->flags);
630 disk->objectid = cpu_to_le64(cpu->objectid);
633 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
635 return le64_to_cpu(disk->objectid);
638 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
641 disk->objectid = cpu_to_le64(val);
644 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
646 return le64_to_cpu(disk->offset);
649 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
652 disk->offset = cpu_to_le64(val);
655 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
657 return le32_to_cpu(disk->flags);
660 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
663 disk->flags = cpu_to_le32(val);
666 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
668 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
671 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
674 u32 flags = btrfs_disk_key_flags(key);
675 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
676 val = val << BTRFS_KEY_TYPE_SHIFT;
677 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
678 btrfs_set_disk_key_flags(key, flags);
681 static inline u32 btrfs_key_type(struct btrfs_key *key)
683 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
686 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
688 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
689 val = val << BTRFS_KEY_TYPE_SHIFT;
690 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
693 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
695 return le64_to_cpu(h->blocknr);
698 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
700 h->blocknr = cpu_to_le64(blocknr);
703 static inline u64 btrfs_header_generation(struct btrfs_header *h)
705 return le64_to_cpu(h->generation);
708 static inline void btrfs_set_header_generation(struct btrfs_header *h,
711 h->generation = cpu_to_le64(val);
714 static inline u64 btrfs_header_owner(struct btrfs_header *h)
716 return le64_to_cpu(h->owner);
719 static inline void btrfs_set_header_owner(struct btrfs_header *h,
722 h->owner = cpu_to_le64(val);
725 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
727 return le16_to_cpu(h->nritems);
730 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
732 h->nritems = cpu_to_le16(val);
735 static inline u16 btrfs_header_flags(struct btrfs_header *h)
737 return le16_to_cpu(h->flags);
740 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
742 h->flags = cpu_to_le16(val);
745 static inline int btrfs_header_level(struct btrfs_header *h)
750 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
752 BUG_ON(level > BTRFS_MAX_LEVEL);
756 static inline int btrfs_is_leaf(struct btrfs_node *n)
758 return (btrfs_header_level(&n->header) == 0);
761 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
763 return le64_to_cpu(item->blocknr);
766 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
768 item->blocknr = cpu_to_le64(val);
771 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
773 return le64_to_cpu(item->root_dirid);
776 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
778 item->root_dirid = cpu_to_le64(val);
781 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
783 return le32_to_cpu(item->refs);
786 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
788 item->refs = cpu_to_le32(val);
791 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
793 return le64_to_cpu(s->blocknr);
796 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
798 s->blocknr = cpu_to_le64(val);
801 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
803 return le64_to_cpu(s->generation);
806 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
809 s->generation = cpu_to_le64(val);
812 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
814 return le64_to_cpu(s->root);
817 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
819 s->root = cpu_to_le64(val);
822 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
824 return le64_to_cpu(s->total_blocks);
827 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
830 s->total_blocks = cpu_to_le64(val);
833 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
835 return le64_to_cpu(s->blocks_used);
838 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
841 s->blocks_used = cpu_to_le64(val);
844 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
846 return le32_to_cpu(s->blocksize);
849 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
852 s->blocksize = cpu_to_le32(val);
855 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
857 return le64_to_cpu(s->root_dir_objectid);
860 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
863 s->root_dir_objectid = cpu_to_le64(val);
866 static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
868 return le64_to_cpu(s->last_device_id);
871 static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
874 s->last_device_id = cpu_to_le64(val);
877 static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
879 return le64_to_cpu(s->device_id);
882 static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
885 s->device_id = cpu_to_le64(val);
888 static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
890 return le64_to_cpu(s->device_block_start);
893 static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
896 s->device_block_start = cpu_to_le64(val);
899 static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
901 return le64_to_cpu(s->device_num_blocks);
904 static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
907 s->device_num_blocks = cpu_to_le64(val);
910 static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
912 return le64_to_cpu(s->device_root);
915 static inline void btrfs_set_super_device_root(struct btrfs_super_block
918 s->device_root = cpu_to_le64(val);
922 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
924 return (u8 *)l->items;
927 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
931 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
937 static inline char *btrfs_file_extent_inline_start(struct
938 btrfs_file_extent_item *e)
940 return (char *)(&e->disk_blocknr);
943 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
945 return (unsigned long)(&((struct
946 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
949 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
951 struct btrfs_file_extent_item *fe = NULL;
952 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
955 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
958 return le64_to_cpu(e->disk_blocknr);
961 static inline void btrfs_set_file_extent_disk_blocknr(struct
962 btrfs_file_extent_item
965 e->disk_blocknr = cpu_to_le64(val);
968 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
970 return le64_to_cpu(e->generation);
973 static inline void btrfs_set_file_extent_generation(struct
974 btrfs_file_extent_item *e,
977 e->generation = cpu_to_le64(val);
980 static inline u64 btrfs_file_extent_disk_num_blocks(struct
981 btrfs_file_extent_item *e)
983 return le64_to_cpu(e->disk_num_blocks);
986 static inline void btrfs_set_file_extent_disk_num_blocks(struct
987 btrfs_file_extent_item
990 e->disk_num_blocks = cpu_to_le64(val);
993 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
995 return le64_to_cpu(e->offset);
998 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
1001 e->offset = cpu_to_le64(val);
1004 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
1007 return le64_to_cpu(e->num_blocks);
1010 static inline void btrfs_set_file_extent_num_blocks(struct
1011 btrfs_file_extent_item *e,
1014 e->num_blocks = cpu_to_le64(val);
1017 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
1019 return le16_to_cpu(d->pathlen);
1022 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
1025 d->pathlen = cpu_to_le16(val);
1028 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
1030 return le64_to_cpu(d->device_id);
1033 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
1036 d->device_id = cpu_to_le64(val);
1039 static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
1041 return sb->s_fs_info;
1044 static inline void btrfs_check_bounds(void *vptr, size_t len,
1045 void *vcontainer, size_t container_len)
1048 char *container = vcontainer;
1049 WARN_ON(ptr < container);
1050 WARN_ON(ptr + len > container + container_len);
1053 static inline void btrfs_memcpy(struct btrfs_root *root,
1055 void *dst, const void *src, size_t nr)
1057 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1058 memcpy(dst, src, nr);
1061 static inline void btrfs_memmove(struct btrfs_root *root,
1063 void *dst, void *src, size_t nr)
1065 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1066 memmove(dst, src, nr);
1069 static inline void btrfs_mark_buffer_dirty(struct buffer_head *bh)
1071 WARN_ON(!atomic_read(&bh->b_count));
1072 mark_buffer_dirty(bh);
1075 /* helper function to cast into the data area of the leaf. */
1076 #define btrfs_item_ptr(leaf, slot, type) \
1077 ((type *)(btrfs_leaf_data(leaf) + \
1078 btrfs_item_offset((leaf)->items + (slot))))
1081 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1082 struct btrfs_block_group_cache
1083 *hint, u64 search_start,
1085 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1086 struct btrfs_root *root);
1087 struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1088 struct btrfs_root *root, u64 hint);
1089 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1090 struct btrfs_root *root, u64 owner,
1091 u64 num_blocks, u64 search_start,
1092 u64 search_end, struct btrfs_key *ins, int data);
1093 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1094 struct buffer_head *buf);
1095 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1096 *root, u64 blocknr, u64 num_blocks, int pin);
1097 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1099 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1100 struct btrfs_root *root,
1101 u64 blocknr, u64 num_blocks);
1102 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1103 struct btrfs_root *root);
1104 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1105 int btrfs_read_block_groups(struct btrfs_root *root);
1107 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1108 *root, struct btrfs_path *path, u32 data_size);
1109 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1110 struct btrfs_root *root,
1111 struct btrfs_path *path,
1113 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1114 *root, struct btrfs_key *key, struct btrfs_path *p, int
1116 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1117 struct btrfs_path *btrfs_alloc_path(void);
1118 void btrfs_free_path(struct btrfs_path *p);
1119 void btrfs_init_path(struct btrfs_path *p);
1120 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1121 struct btrfs_path *path);
1122 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1123 *root, struct btrfs_key *key, void *data, u32 data_size);
1124 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1125 *root, struct btrfs_path *path, struct btrfs_key
1126 *cpu_key, u32 data_size);
1127 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1128 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1129 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1130 *root, struct buffer_head *snap);
1132 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1133 struct btrfs_key *key);
1134 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1135 *root, struct btrfs_key *key, struct btrfs_root_item
1137 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1138 *root, struct btrfs_key *key, struct btrfs_root_item
1140 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1141 btrfs_root_item *item, struct btrfs_key *key);
1143 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1144 *root, const char *name, int name_len, u64 dir,
1145 struct btrfs_key *location, u8 type);
1146 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1147 struct btrfs_root *root,
1148 struct btrfs_path *path, u64 dir,
1149 const char *name, int name_len,
1151 struct btrfs_dir_item *
1152 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1153 struct btrfs_root *root,
1154 struct btrfs_path *path, u64 dir,
1155 u64 objectid, const char *name, int name_len,
1157 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1158 struct btrfs_path *path,
1159 const char *name, int name_len);
1160 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1161 struct btrfs_root *root,
1162 struct btrfs_path *path,
1163 struct btrfs_dir_item *di);
1165 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1166 struct btrfs_root *fs_root,
1167 u64 dirid, u64 *objectid);
1168 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1171 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1172 *root, u64 objectid, struct btrfs_inode_item
1174 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1175 *root, struct btrfs_path *path,
1176 struct btrfs_key *location, int mod);
1179 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1180 struct btrfs_root *root,
1181 u64 objectid, u64 pos, u64 offset,
1183 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1184 struct btrfs_root *root,
1185 struct btrfs_path *path, u64 objectid,
1186 u64 blocknr, int mod);
1187 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1188 struct btrfs_root *root,
1189 u64 objectid, u64 offset,
1190 char *data, size_t len);
1191 int btrfs_csum_verify_file_block(struct btrfs_root *root,
1192 u64 objectid, u64 offset,
1193 char *data, size_t len);
1194 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1195 struct btrfs_root *root,
1196 struct btrfs_path *path,
1197 u64 objectid, u64 offset,
1200 extern struct subsystem btrfs_subsys;