Add back pointers from extents to the file or btree referencing them
[btrfs-progs-unstable/devel.git] / ctree.h
blob174fb239c4f7fa51e2cfcd918ecd543cc7fd7c72
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 struct btrfs_root;
27 struct btrfs_trans_handle;
28 #define BTRFS_MAGIC "_B2RfS_M"
30 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
31 #define BTRFS_EXTENT_TREE_OBJECTID 2ULL
32 #define BTRFS_FS_TREE_OBJECTID 3ULL
33 #define BTRFS_ROOT_TREE_DIR_OBJECTID 4ULL
34 #define BTRFS_FIRST_FREE_OBJECTID 5ULL
37 * we can actually store much bigger names, but lets not confuse the rest
38 * of linux
40 #define BTRFS_NAME_LEN 255
42 /* 32 bytes in various csum fields */
43 #define BTRFS_CSUM_SIZE 32
44 /* four bytes for CRC32 */
45 #define BTRFS_CRC32_SIZE 4
47 #define BTRFS_FT_UNKNOWN 0
48 #define BTRFS_FT_REG_FILE 1
49 #define BTRFS_FT_DIR 2
50 #define BTRFS_FT_CHRDEV 3
51 #define BTRFS_FT_BLKDEV 4
52 #define BTRFS_FT_FIFO 5
53 #define BTRFS_FT_SOCK 6
54 #define BTRFS_FT_SYMLINK 7
55 #define BTRFS_FT_XATTR 8
56 #define BTRFS_FT_MAX 9
59 * the key defines the order in the tree, and so it also defines (optimal)
60 * block layout. objectid corresonds to the inode number. The flags
61 * tells us things about the object, and is a kind of stream selector.
62 * so for a given inode, keys with flags of 1 might refer to the inode
63 * data, flags of 2 may point to file data in the btree and flags == 3
64 * may point to extents.
66 * offset is the starting byte offset for this key in the stream.
68 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
69 * in cpu native order. Otherwise they are identical and their sizes
70 * should be the same (ie both packed)
72 struct btrfs_disk_key {
73 __le64 objectid;
74 u8 type;
75 __le64 offset;
76 } __attribute__ ((__packed__));
78 struct btrfs_key {
79 u64 objectid;
80 u8 type;
81 u64 offset;
82 } __attribute__ ((__packed__));
85 * every tree block (leaf or node) starts with this header.
87 struct btrfs_header {
88 u8 csum[BTRFS_CSUM_SIZE];
89 u8 fsid[16]; /* FS specific uuid */
90 __le64 bytenr; /* which block this node is supposed to live in */
91 __le64 generation;
92 __le64 owner;
93 __le32 nritems;
94 __le16 flags;
95 u8 level;
96 } __attribute__ ((__packed__));
98 #define BTRFS_MAX_LEVEL 8
99 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
100 sizeof(struct btrfs_header)) / \
101 sizeof(struct btrfs_key_ptr))
102 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
103 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
104 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
105 sizeof(struct btrfs_item) - \
106 sizeof(struct btrfs_file_extent_item))
107 struct btrfs_buffer;
109 * the super block basically lists the main trees of the FS
110 * it currently lacks any block count etc etc
112 struct btrfs_super_block {
113 u8 csum[BTRFS_CSUM_SIZE];
114 /* the first 3 fields must match struct btrfs_header */
115 u8 fsid[16]; /* FS specific uuid */
116 __le64 bytenr; /* this block number */
117 __le64 magic;
118 __le64 generation;
119 __le64 root;
120 __le64 total_bytes;
121 __le64 bytes_used;
122 __le64 root_dir_objectid;
123 __le32 sectorsize;
124 __le32 nodesize;
125 __le32 leafsize;
126 __le32 stripesize;
127 u8 root_level;
128 } __attribute__ ((__packed__));
131 * A leaf is full of items. offset and size tell us where to find
132 * the item in the leaf (relative to the start of the data area)
134 struct btrfs_item {
135 struct btrfs_disk_key key;
136 __le32 offset;
137 __le32 size;
138 } __attribute__ ((__packed__));
141 * leaves have an item area and a data area:
142 * [item0, item1....itemN] [free space] [dataN...data1, data0]
144 * The data is separate from the items to get the keys closer together
145 * during searches.
147 struct btrfs_leaf {
148 struct btrfs_header header;
149 struct btrfs_item items[];
150 } __attribute__ ((__packed__));
153 * all non-leaf blocks are nodes, they hold only keys and pointers to
154 * other blocks
156 struct btrfs_key_ptr {
157 struct btrfs_disk_key key;
158 __le64 blockptr;
159 __le64 generation;
160 } __attribute__ ((__packed__));
162 struct btrfs_node {
163 struct btrfs_header header;
164 struct btrfs_key_ptr ptrs[];
165 } __attribute__ ((__packed__));
168 * btrfs_paths remember the path taken from the root down to the leaf.
169 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
170 * to any other levels that are present.
172 * The slots array records the index of the item or block pointer
173 * used while walking the tree.
175 struct btrfs_path {
176 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
177 int slots[BTRFS_MAX_LEVEL];
181 * items in the extent btree are used to record the objectid of the
182 * owner of the block and the number of references
184 struct btrfs_extent_item {
185 __le32 refs;
186 } __attribute__ ((__packed__));
188 struct btrfs_extent_ref {
189 __le64 root;
190 __le64 generation;
191 __le64 objectid;
192 __le64 offset;
193 } __attribute__ ((__packed__));
195 struct btrfs_inode_timespec {
196 __le64 sec;
197 __le32 nsec;
198 } __attribute__ ((__packed__));
201 * there is no padding here on purpose. If you want to extent the inode,
202 * make a new item type
204 struct btrfs_inode_item {
205 __le64 generation;
206 __le64 size;
207 __le64 nblocks;
208 __le64 block_group;
209 __le32 nlink;
210 __le32 uid;
211 __le32 gid;
212 __le32 mode;
213 __le32 rdev;
214 __le16 flags;
215 __le16 compat_flags;
216 struct btrfs_inode_timespec atime;
217 struct btrfs_inode_timespec ctime;
218 struct btrfs_inode_timespec mtime;
219 struct btrfs_inode_timespec otime;
220 } __attribute__ ((__packed__));
222 /* inline data is just a blob of bytes */
223 struct btrfs_inline_data_item {
224 u8 data;
225 } __attribute__ ((__packed__));
227 struct btrfs_dir_item {
228 struct btrfs_disk_key location;
229 __le16 data_len;
230 __le16 name_len;
231 u8 type;
232 } __attribute__ ((__packed__));
234 struct btrfs_root_item {
235 struct btrfs_inode_item inode;
236 __le64 root_dirid;
237 __le64 bytenr;
238 __le64 byte_limit;
239 __le64 bytes_used;
240 __le32 flags;
241 __le32 refs;
242 struct btrfs_disk_key drop_progress;
243 u8 drop_level;
244 u8 level;
245 } __attribute__ ((__packed__));
247 #define BTRFS_FILE_EXTENT_REG 0
248 #define BTRFS_FILE_EXTENT_INLINE 1
250 struct btrfs_file_extent_item {
251 __le64 generation;
252 u8 type;
254 * disk space consumed by the extent, checksum blocks are included
255 * in these numbers
257 __le64 disk_bytenr;
258 __le64 disk_num_bytes;
260 * the logical offset in file blocks (no csums)
261 * this extent record is for. This allows a file extent to point
262 * into the middle of an existing extent on disk, sharing it
263 * between two snapshots (useful if some bytes in the middle of the
264 * extent have changed
266 __le64 offset;
268 * the logical number of file blocks (no csums included)
270 __le64 num_bytes;
271 } __attribute__ ((__packed__));
273 struct btrfs_csum_item {
274 u8 csum[BTRFS_CSUM_SIZE];
275 } __attribute__ ((__packed__));
277 /* tag for the radix tree of block groups in ram */
278 #define BTRFS_BLOCK_GROUP_DIRTY 0
279 #define BTRFS_BLOCK_GROUP_SIZE (256 * 1024 * 1024)
282 #define BTRFS_BLOCK_GROUP_DATA 1
283 struct btrfs_block_group_item {
284 __le64 used;
285 u8 flags;
286 } __attribute__ ((__packed__));
288 struct btrfs_block_group_cache {
289 struct cache_extent cache;
290 struct btrfs_key key;
291 struct btrfs_block_group_item item;
292 int dirty;
295 struct btrfs_fs_info {
296 struct btrfs_root *fs_root;
297 struct btrfs_root *extent_root;
298 struct btrfs_root *tree_root;
299 struct btrfs_key last_insert;
300 struct cache_tree extent_cache;
301 struct cache_tree block_group_cache;
302 struct cache_tree pending_tree;
303 struct cache_tree pinned_tree;
304 struct cache_tree del_pending;
305 struct list_head trans;
306 struct list_head cache;
307 u64 last_inode_alloc;
308 u64 last_inode_alloc_dirid;
309 u64 generation;
310 int cache_size;
311 int fp;
312 struct btrfs_trans_handle *running_transaction;
313 struct btrfs_super_block *disk_super;
317 * in ram representation of the tree. extent_root is used for all allocations
318 * and for the extent tree extent_root root.
320 struct btrfs_root {
321 struct btrfs_buffer *node;
322 struct btrfs_buffer *commit_root;
323 struct btrfs_root_item root_item;
324 struct btrfs_key root_key;
325 struct btrfs_fs_info *fs_info;
327 /* data allocations are done in sectorsize units */
328 u32 sectorsize;
330 /* node allocations are done in nodesize units */
331 u32 nodesize;
333 /* leaf allocations are done in leafsize units */
334 u32 leafsize;
336 /* leaf allocations are done in leafsize units */
337 u32 stripesize;
339 int ref_cows;
340 u32 type;
343 /* the lower bits in the key flags defines the item type */
344 #define BTRFS_KEY_TYPE_MAX 256
345 #define BTRFS_KEY_TYPE_SHIFT 24
346 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
347 BTRFS_KEY_TYPE_SHIFT)
350 * inode items have the data typically returned from stat and store other
351 * info about object characteristics. There is one for every file and dir in
352 * the FS
354 #define BTRFS_INODE_ITEM_KEY 1
355 #define BTRFS_XATTR_ITEM_KEY 2
357 /* reserve 3-15 close to the inode for later flexibility */
360 * dir items are the name -> inode pointers in a directory. There is one
361 * for every name in a directory.
363 #define BTRFS_DIR_ITEM_KEY 16
364 #define BTRFS_DIR_INDEX_KEY 17
366 * extent data is for file data
368 #define BTRFS_EXTENT_DATA_KEY 18
370 * csum items have the checksums for data in the extents
372 #define BTRFS_CSUM_ITEM_KEY 19
374 /* reserve 20-31 for other file stuff */
377 * root items point to tree roots. There are typically in the root
378 * tree used by the super block to find all the other trees
380 #define BTRFS_ROOT_ITEM_KEY 32
382 * extent items are in the extent map tree. These record which blocks
383 * are used, and how many references there are to each block
385 #define BTRFS_EXTENT_ITEM_KEY 33
386 #define BTRFS_EXTENT_REF_KEY 34
389 * block groups give us hints into the extent allocation trees. Which
390 * blocks are free etc etc
392 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
395 * string items are for debugging. They just store a short string of
396 * data in the FS
398 #define BTRFS_STRING_ITEM_KEY 253
400 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
401 static inline u##bits btrfs_##name(type *s) \
403 return le##bits##_to_cpu(s->member); \
405 static inline void btrfs_set_##name(type *s, u##bits val) \
407 s->member = cpu_to_le##bits(val); \
410 static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi)
412 return le64_to_cpu(bi->used);
415 static inline void btrfs_set_block_group_used(struct
416 btrfs_block_group_item *bi,
417 u64 val)
419 bi->used = cpu_to_le64(val);
422 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
424 return le64_to_cpu(i->generation);
427 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
428 u64 val)
430 i->generation = cpu_to_le64(val);
433 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
435 return le64_to_cpu(i->size);
438 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
440 i->size = cpu_to_le64(val);
443 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
445 return le64_to_cpu(i->nblocks);
448 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
450 i->nblocks = cpu_to_le64(val);
453 static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
455 return le64_to_cpu(i->block_group);
458 static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
459 u64 val)
461 i->block_group = cpu_to_le64(val);
464 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
466 return le32_to_cpu(i->nlink);
469 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
471 i->nlink = cpu_to_le32(val);
474 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
476 return le32_to_cpu(i->uid);
479 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
481 i->uid = cpu_to_le32(val);
484 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
486 return le32_to_cpu(i->gid);
489 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
491 i->gid = cpu_to_le32(val);
494 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
496 return le32_to_cpu(i->mode);
499 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
501 i->mode = cpu_to_le32(val);
504 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
506 return le32_to_cpu(i->rdev);
509 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
511 i->rdev = cpu_to_le32(val);
514 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
516 return le16_to_cpu(i->flags);
519 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
521 i->flags = cpu_to_le16(val);
524 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
526 return le16_to_cpu(i->compat_flags);
529 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
530 u16 val)
532 i->compat_flags = cpu_to_le16(val);
535 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
537 return le64_to_cpu(ts->sec);
540 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
541 u64 val)
543 ts->sec = cpu_to_le64(val);
546 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
548 return le32_to_cpu(ts->nsec);
551 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
552 u32 val)
554 ts->nsec = cpu_to_le32(val);
557 BTRFS_SETGET_STACK_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
559 BTRFS_SETGET_STACK_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
560 BTRFS_SETGET_STACK_FUNCS(ref_generation, struct btrfs_extent_ref,
561 generation, 64);
562 BTRFS_SETGET_STACK_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
563 BTRFS_SETGET_STACK_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
565 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
567 return le64_to_cpu(n->ptrs[nr].blockptr);
570 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
571 u64 val)
573 n->ptrs[nr].blockptr = cpu_to_le64(val);
576 static inline u64 btrfs_node_ptr_generation(struct btrfs_node *n, int nr)
578 return le64_to_cpu(n->ptrs[nr].generation);
581 static inline void btrfs_set_node_ptr_generation(struct btrfs_node *n, int nr,
582 u64 val)
584 n->ptrs[nr].generation = cpu_to_le64(val);
587 static inline u32 btrfs_item_offset(struct btrfs_item *item)
589 return le32_to_cpu(item->offset);
592 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
594 item->offset = cpu_to_le32(val);
597 static inline u32 btrfs_item_end(struct btrfs_item *item)
599 return le32_to_cpu(item->offset) + le32_to_cpu(item->size);
602 static inline u32 btrfs_item_size(struct btrfs_item *item)
604 return le32_to_cpu(item->size);
607 static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
609 item->size = cpu_to_le32(val);
612 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
614 return d->type;
617 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
619 d->type = val;
622 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
624 return le16_to_cpu(d->name_len);
627 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
629 d->name_len = cpu_to_le16(val);
632 static inline u16 btrfs_dir_data_len(struct btrfs_dir_item *d)
634 return le16_to_cpu(d->data_len);
637 static inline void btrfs_set_dir_data_len(struct btrfs_dir_item *d, u16 val)
639 d->data_len = cpu_to_le16(val);
642 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
643 struct btrfs_disk_key *disk)
645 cpu->offset = le64_to_cpu(disk->offset);
646 cpu->type = le32_to_cpu(disk->type);
647 cpu->objectid = le64_to_cpu(disk->objectid);
650 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
651 struct btrfs_key *cpu)
653 disk->offset = cpu_to_le64(cpu->offset);
654 disk->type = cpu_to_le32(cpu->type);
655 disk->objectid = cpu_to_le64(cpu->objectid);
658 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
660 return le64_to_cpu(disk->objectid);
663 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
664 u64 val)
666 disk->objectid = cpu_to_le64(val);
669 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
671 return le64_to_cpu(disk->offset);
674 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
675 u64 val)
677 disk->offset = cpu_to_le64(val);
680 static inline u8 btrfs_disk_key_type(struct btrfs_disk_key *key)
682 return key->type;
685 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key, u8 val)
687 key->type = val;
690 static inline u32 btrfs_key_type(struct btrfs_key *key)
692 return key->type;
695 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
697 key->type = val;
700 static inline u64 btrfs_header_bytenr(struct btrfs_header *h)
702 return le64_to_cpu(h->bytenr);
705 static inline void btrfs_set_header_bytenr(struct btrfs_header *h, u64 bytenr)
707 h->bytenr = cpu_to_le64(bytenr);
710 static inline u64 btrfs_header_generation(struct btrfs_header *h)
712 return le64_to_cpu(h->generation);
715 static inline void btrfs_set_header_generation(struct btrfs_header *h,
716 u64 val)
718 h->generation = cpu_to_le64(val);
721 static inline u64 btrfs_header_owner(struct btrfs_header *h)
723 return le64_to_cpu(h->owner);
726 static inline void btrfs_set_header_owner(struct btrfs_header *h,
727 u64 val)
729 h->owner = cpu_to_le64(val);
732 static inline u32 btrfs_header_nritems(struct btrfs_header *h)
734 return le32_to_cpu(h->nritems);
737 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u32 val)
739 h->nritems = cpu_to_le32(val);
742 static inline u16 btrfs_header_flags(struct btrfs_header *h)
744 return le16_to_cpu(h->flags);
747 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
749 h->flags = cpu_to_le16(val);
752 static inline int btrfs_header_level(struct btrfs_header *h)
754 return h->level;
757 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
759 BUG_ON(level > BTRFS_MAX_LEVEL);
760 h->level = level;
763 static inline int btrfs_is_leaf(struct btrfs_node *n)
765 return (btrfs_header_level(&n->header) == 0);
768 static inline u64 btrfs_root_bytenr(struct btrfs_root_item *item)
770 return le64_to_cpu(item->bytenr);
773 static inline void btrfs_set_root_bytenr(struct btrfs_root_item *item, u64 val)
775 item->bytenr = cpu_to_le64(val);
778 static inline u64 btrfs_root_byte_limit(struct btrfs_root_item *item)
780 return le64_to_cpu(item->byte_limit);
783 static inline void btrfs_set_root_byte_limit(struct btrfs_root_item *item,
784 u64 val)
786 item->byte_limit = cpu_to_le64(val);
789 static inline u8 btrfs_root_level(struct btrfs_root_item *item)
791 return item->level;
794 static inline void btrfs_set_root_level(struct btrfs_root_item *item, u8 val)
796 item->level = val;
799 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
801 return le64_to_cpu(item->root_dirid);
804 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
806 item->root_dirid = cpu_to_le64(val);
809 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
811 return le32_to_cpu(item->refs);
814 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
816 item->refs = cpu_to_le32(val);
819 static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
821 return le32_to_cpu(item->flags);
824 static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
826 item->flags = cpu_to_le32(val);
829 static inline void btrfs_set_root_bytes_used(struct btrfs_root_item *item,
830 u64 val)
832 item->bytes_used = cpu_to_le64(val);
835 static inline u64 btrfs_root_bytes_used(struct btrfs_root_item *item)
837 return le64_to_cpu(item->bytes_used);
840 static inline u64 btrfs_super_bytenr(struct btrfs_super_block *s)
842 return le64_to_cpu(s->bytenr);
845 static inline void btrfs_set_super_bytenr(struct btrfs_super_block *s, u64 val)
847 s->bytenr = cpu_to_le64(val);
850 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
852 return le64_to_cpu(s->generation);
855 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
856 u64 val)
858 s->generation = cpu_to_le64(val);
861 static inline u8 btrfs_super_root_level(struct btrfs_super_block *s)
863 return s->root_level;
866 static inline void btrfs_set_super_root_level(struct btrfs_super_block *s,
867 u8 val)
869 s->root_level = val;
872 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
874 return le64_to_cpu(s->root);
877 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
879 s->root = cpu_to_le64(val);
882 static inline u64 btrfs_super_total_bytes(struct btrfs_super_block *s)
884 return le64_to_cpu(s->total_bytes);
887 static inline void btrfs_set_super_total_bytes(struct btrfs_super_block *s,
888 u64 val)
890 s->total_bytes = cpu_to_le64(val);
893 static inline u64 btrfs_super_bytes_used(struct btrfs_super_block *s)
895 return le64_to_cpu(s->bytes_used);
898 static inline void btrfs_set_super_bytes_used(struct btrfs_super_block *s,
899 u64 val)
901 s->bytes_used = cpu_to_le64(val);
904 static inline u32 btrfs_super_sectorsize(struct btrfs_super_block *s)
906 return le32_to_cpu(s->sectorsize);
909 static inline void btrfs_set_super_sectorsize(struct btrfs_super_block *s,
910 u32 val)
912 s->sectorsize = cpu_to_le32(val);
915 static inline u32 btrfs_super_nodesize(struct btrfs_super_block *s)
917 return le32_to_cpu(s->nodesize);
920 static inline void btrfs_set_super_nodesize(struct btrfs_super_block *s,
921 u32 val)
923 s->nodesize = cpu_to_le32(val);
926 static inline u32 btrfs_super_leafsize(struct btrfs_super_block *s)
928 return le32_to_cpu(s->leafsize);
931 static inline void btrfs_set_super_leafsize(struct btrfs_super_block *s,
932 u32 val)
934 s->leafsize = cpu_to_le32(val);
937 static inline u32 btrfs_super_stripesize(struct btrfs_super_block *s)
939 return le32_to_cpu(s->stripesize);
942 static inline void btrfs_set_super_stripesize(struct btrfs_super_block *s,
943 u32 val)
945 s->stripesize = cpu_to_le32(val);
948 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
950 return le64_to_cpu(s->root_dir_objectid);
953 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
954 val)
956 s->root_dir_objectid = cpu_to_le64(val);
959 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
961 return (u8 *)l->items;
964 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
966 return e->type;
968 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
969 u8 val)
971 e->type = val;
974 static inline char *btrfs_file_extent_inline_start(struct
975 btrfs_file_extent_item *e)
977 return (char *)(&e->disk_bytenr);
980 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
982 return (unsigned long)(&((struct
983 btrfs_file_extent_item *)NULL)->disk_bytenr) + datasize;
986 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
988 struct btrfs_file_extent_item *fe = NULL;
989 return btrfs_item_size(e) - (unsigned long)(&fe->disk_bytenr);
992 static inline u64 btrfs_file_extent_disk_bytenr(struct btrfs_file_extent_item
995 return le64_to_cpu(e->disk_bytenr);
998 static inline void btrfs_set_file_extent_disk_bytenr(struct
999 btrfs_file_extent_item
1000 *e, u64 val)
1002 e->disk_bytenr = cpu_to_le64(val);
1005 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
1007 return le64_to_cpu(e->generation);
1010 static inline void btrfs_set_file_extent_generation(struct
1011 btrfs_file_extent_item *e,
1012 u64 val)
1014 e->generation = cpu_to_le64(val);
1017 static inline u64 btrfs_file_extent_disk_num_bytes(struct
1018 btrfs_file_extent_item *e)
1020 return le64_to_cpu(e->disk_num_bytes);
1023 static inline void btrfs_set_file_extent_disk_num_bytes(struct
1024 btrfs_file_extent_item
1025 *e, u64 val)
1027 e->disk_num_bytes = cpu_to_le64(val);
1030 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
1032 return le64_to_cpu(e->offset);
1035 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
1036 *e, u64 val)
1038 e->offset = cpu_to_le64(val);
1041 static inline u64 btrfs_file_extent_num_bytes(struct btrfs_file_extent_item
1044 return le64_to_cpu(e->num_bytes);
1047 static inline void btrfs_set_file_extent_num_bytes(struct
1048 btrfs_file_extent_item *e,
1049 u64 val)
1051 e->num_bytes = cpu_to_le64(val);
1054 /* helper function to cast into the data area of the leaf. */
1055 #define btrfs_item_ptr(leaf, slot, type) \
1056 ((type *)(btrfs_leaf_data(leaf) + \
1057 btrfs_item_offset((leaf)->items + (slot))))
1058 #define btrfs_item_ptr_offset(leaf, slot) \
1059 ((unsigned long)(btrfs_leaf_data(leaf) + \
1060 btrfs_item_offset_nr(leaf, slot)))
1062 static inline u32 btrfs_level_size(struct btrfs_root *root, int level)
1064 if (level == 0)
1065 return root->leafsize;
1066 return root->nodesize;
1068 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1069 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1070 struct btrfs_root *root,
1071 u32 blocksize);
1072 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1073 struct btrfs_buffer *buf);
1074 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1075 struct btrfs_root *root, u64 owner_objectid);
1076 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1077 *root, u64 bytenr, u64 num_bytes,
1078 u64 root_objectid, u64 root_generation,
1079 u64 owner, u64 owner_offset, int pin);
1080 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1081 struct btrfs_root *root, struct btrfs_buffer *buf,
1082 struct btrfs_buffer *parent, int parent_slot,
1083 struct btrfs_buffer **cow_ret);
1084 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1085 *root, struct btrfs_path *path, u32 data_size);
1086 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1087 struct btrfs_root *root,
1088 struct btrfs_path *path,
1089 u32 new_size, int from_end);
1090 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1091 *root, struct btrfs_key *key, struct btrfs_path *p, int
1092 ins_len, int cow);
1093 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1094 void btrfs_init_path(struct btrfs_path *p);
1095 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1096 struct btrfs_path *path);
1097 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1098 *root, struct btrfs_key *key, void *data, u32 data_size);
1099 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1100 *root, struct btrfs_path *path, struct btrfs_key
1101 *cpu_key, u32 data_size);
1102 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1103 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
1104 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1105 *root, struct btrfs_buffer *snap);
1106 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
1107 btrfs_root *root);
1108 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1109 struct btrfs_key *key);
1110 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1111 *root, struct btrfs_key *key, struct btrfs_root_item
1112 *item);
1113 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1114 *root, struct btrfs_key *key, struct btrfs_root_item
1115 *item);
1116 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1117 btrfs_root_item *item, struct btrfs_key *key);
1118 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1119 *root, char *name, int name_len, u64 dir,
1120 struct btrfs_key *location, u8 type);
1121 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1122 struct btrfs_root *root, struct btrfs_path *path,
1123 u64 dir, char *name, int name_len, int mod);
1124 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1125 struct btrfs_path *path,
1126 const char *name, int name_len);
1127 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1128 struct btrfs_root *root,
1129 struct btrfs_path *path,
1130 struct btrfs_dir_item *di);
1131 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1132 struct btrfs_root *fs_root,
1133 u64 dirid, u64 *objectid);
1134 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1135 *root, u64 objectid, struct btrfs_inode_item
1136 *inode_item);
1137 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1138 *root, struct btrfs_path *path, u64 objectid, int mod);
1139 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1140 struct btrfs_root *root);
1141 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1142 int btrfs_read_block_groups(struct btrfs_root *root);
1143 int btrfs_insert_block_group(struct btrfs_trans_handle *trans,
1144 struct btrfs_root *root,
1145 struct btrfs_key *key,
1146 struct btrfs_block_group_item *bi);
1147 /* file-item.c */
1148 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1149 struct btrfs_root *root,
1150 u64 objectid, u64 pos, u64 offset,
1151 u64 disk_num_bytes, u64 num_bytes);
1152 int btrfs_insert_inline_file_extent(struct btrfs_trans_handle *trans,
1153 struct btrfs_root *root, u64 objectid,
1154 u64 offset, char *buffer, size_t size);
1155 int btrfs_lookup_csum(struct btrfs_trans_handle *trans, struct btrfs_root
1156 *root, struct btrfs_path *path, u64 objectid,
1157 u64 offset, int cow, struct btrfs_csum_item **item_ret);
1158 int btrfs_csum_file_block(struct btrfs_trans_handle *trans, struct btrfs_root
1159 *root, struct btrfs_inode_item *inode,
1160 u64 objectid, u64 offset, char *data, size_t len);
1161 #endif