bring back the inode number directory index
[btrfs-progs-unstable.git] / ctree.h
bloba258b18a137d237ecb7ebaddd5adae6e8918f350
1 #ifndef __BTRFS__
2 #define __BTRFS__
4 #include "list.h"
5 #include "kerncompat.h"
7 struct btrfs_trans_handle;
9 #define BTRFS_MAGIC "_BtRfS_M"
11 #define BTRFS_ROOT_TREE_OBJECTID 1ULL
12 #define BTRFS_DEV_TREE_OBJECTID 2ULL
13 #define BTRFS_EXTENT_TREE_OBJECTID 3ULL
14 #define BTRFS_FS_TREE_OBJECTID 4ULL
15 #define BTRFS_ROOT_TREE_DIR_OBJECTID 5ULL
16 #define BTRFS_FIRST_FREE_OBJECTID 6ULL
19 * we can actually store much bigger names, but lets not confuse the rest
20 * of linux
22 #define BTRFS_NAME_LEN 255
24 /* 32 bytes in various csum fields */
25 #define BTRFS_CSUM_SIZE 32
28 * the key defines the order in the tree, and so it also defines (optimal)
29 * block layout. objectid corresonds to the inode number. The flags
30 * tells us things about the object, and is a kind of stream selector.
31 * so for a given inode, keys with flags of 1 might refer to the inode
32 * data, flags of 2 may point to file data in the btree and flags == 3
33 * may point to extents.
35 * offset is the starting byte offset for this key in the stream.
37 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
38 * in cpu native order. Otherwise they are identical and their sizes
39 * should be the same (ie both packed)
41 struct btrfs_disk_key {
42 __le64 objectid;
43 __le32 flags;
44 __le64 offset;
45 } __attribute__ ((__packed__));
47 struct btrfs_key {
48 u64 objectid;
49 u32 flags;
50 u64 offset;
51 } __attribute__ ((__packed__));
54 * every tree block (leaf or node) starts with this header.
56 struct btrfs_header {
57 u8 csum[BTRFS_CSUM_SIZE];
58 u8 fsid[16]; /* FS specific uuid */
59 __le64 blocknr; /* which block this node is supposed to live in */
60 __le64 generation;
61 __le16 nritems;
62 __le16 flags;
63 u8 level;
64 } __attribute__ ((__packed__));
66 #define BTRFS_MAX_LEVEL 8
67 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \
68 sizeof(struct btrfs_header)) / \
69 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
70 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
71 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize))
73 struct btrfs_buffer;
75 * the super block basically lists the main trees of the FS
76 * it currently lacks any block count etc etc
78 struct btrfs_super_block {
79 u8 csum[BTRFS_CSUM_SIZE];
80 /* the first 3 fields must match struct btrfs_header */
81 u8 fsid[16]; /* FS specific uuid */
82 __le64 blocknr; /* this block number */
83 __le64 magic;
84 __le32 blocksize;
85 __le64 generation;
86 __le64 root;
87 __le64 total_blocks;
88 __le64 blocks_used;
89 __le64 root_dir_objectid;
90 __le64 last_device_id;
91 /* fields below here vary with the underlying disk */
92 __le64 device_block_start;
93 __le64 device_num_blocks;
94 __le64 device_root;
95 __le64 device_id;
96 } __attribute__ ((__packed__));
99 * A leaf is full of items. offset and size tell us where to find
100 * the item in the leaf (relative to the start of the data area)
102 struct btrfs_item {
103 struct btrfs_disk_key key;
104 __le32 offset;
105 __le16 size;
106 } __attribute__ ((__packed__));
109 * leaves have an item area and a data area:
110 * [item0, item1....itemN] [free space] [dataN...data1, data0]
112 * The data is separate from the items to get the keys closer together
113 * during searches.
115 struct btrfs_leaf {
116 struct btrfs_header header;
117 struct btrfs_item items[];
118 } __attribute__ ((__packed__));
121 * all non-leaf blocks are nodes, they hold only keys and pointers to
122 * other blocks
124 struct btrfs_key_ptr {
125 struct btrfs_disk_key key;
126 __le64 blockptr;
127 } __attribute__ ((__packed__));
129 struct btrfs_node {
130 struct btrfs_header header;
131 struct btrfs_key_ptr ptrs[];
132 } __attribute__ ((__packed__));
135 * btrfs_paths remember the path taken from the root down to the leaf.
136 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
137 * to any other levels that are present.
139 * The slots array records the index of the item or block pointer
140 * used while walking the tree.
142 struct btrfs_path {
143 struct btrfs_buffer *nodes[BTRFS_MAX_LEVEL];
144 int slots[BTRFS_MAX_LEVEL];
148 * items in the extent btree are used to record the objectid of the
149 * owner of the block and the number of references
151 struct btrfs_extent_item {
152 __le32 refs;
153 } __attribute__ ((__packed__));
155 struct btrfs_inode_timespec {
156 __le64 sec;
157 __le32 nsec;
158 } __attribute__ ((__packed__));
161 * there is no padding here on purpose. If you want to extent the inode,
162 * make a new item type
164 struct btrfs_inode_item {
165 __le64 generation;
166 __le64 size;
167 __le64 nblocks;
168 __le32 nlink;
169 __le32 uid;
170 __le32 gid;
171 __le32 mode;
172 __le32 rdev;
173 __le16 flags;
174 __le16 compat_flags;
175 struct btrfs_inode_timespec atime;
176 struct btrfs_inode_timespec ctime;
177 struct btrfs_inode_timespec mtime;
178 struct btrfs_inode_timespec otime;
179 } __attribute__ ((__packed__));
181 /* inline data is just a blob of bytes */
182 struct btrfs_inline_data_item {
183 u8 data;
184 } __attribute__ ((__packed__));
186 struct btrfs_dir_item {
187 struct btrfs_disk_key location;
188 __le16 flags;
189 __le16 name_len;
190 u8 type;
191 } __attribute__ ((__packed__));
193 struct btrfs_root_item {
194 struct btrfs_inode_item inode;
195 __le64 root_dirid;
196 __le64 blocknr;
197 __le32 flags;
198 __le64 block_limit;
199 __le64 blocks_used;
200 __le32 refs;
201 } __attribute__ ((__packed__));
203 #define BTRFS_FILE_EXTENT_REG 0
204 #define BTRFS_FILE_EXTENT_INLINE 1
206 struct btrfs_file_extent_item {
207 __le64 generation;
208 u8 type;
210 * disk space consumed by the extent, checksum blocks are included
211 * in these numbers
213 __le64 disk_blocknr;
214 __le64 disk_num_blocks;
216 * the logical offset in file blocks (no csums)
217 * this extent record is for. This allows a file extent to point
218 * into the middle of an existing extent on disk, sharing it
219 * between two snapshots (useful if some bytes in the middle of the
220 * extent have changed
222 __le64 offset;
224 * the logical number of file blocks (no csums included)
226 __le64 num_blocks;
227 } __attribute__ ((__packed__));
229 struct btrfs_csum_item {
230 u8 csum[BTRFS_CSUM_SIZE];
231 } __attribute__ ((__packed__));
233 struct btrfs_device_item {
234 __le16 pathlen;
235 __le64 device_id;
236 } __attribute__ ((__packed__));
238 struct btrfs_fs_info {
239 struct btrfs_root *fs_root;
240 struct btrfs_root *extent_root;
241 struct btrfs_root *tree_root;
242 struct btrfs_root *dev_root;
243 struct btrfs_key current_insert;
244 struct btrfs_key last_insert;
245 struct radix_tree_root cache_radix;
246 struct radix_tree_root pinned_radix;
247 struct radix_tree_root dev_radix;
248 struct list_head trans;
249 struct list_head cache;
250 u64 last_inode_alloc;
251 u64 last_inode_alloc_dirid;
252 u64 generation;
253 int cache_size;
254 int fp;
255 struct btrfs_trans_handle *running_transaction;
256 struct btrfs_super_block *disk_super;
260 * in ram representation of the tree. extent_root is used for all allocations
261 * and for the extent tree extent_root root. current_insert is used
262 * only for the extent tree.
264 struct btrfs_root {
265 struct btrfs_buffer *node;
266 struct btrfs_buffer *commit_root;
267 struct btrfs_root_item root_item;
268 struct btrfs_key root_key;
269 struct btrfs_fs_info *fs_info;
270 u32 blocksize;
271 int ref_cows;
272 u32 type;
275 /* the lower bits in the key flags defines the item type */
276 #define BTRFS_KEY_TYPE_MAX 256
277 #define BTRFS_KEY_TYPE_SHIFT 24
278 #define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
279 BTRFS_KEY_TYPE_SHIFT)
282 * inode items have the data typically returned from stat and store other
283 * info about object characteristics. There is one for every file and dir in
284 * the FS
286 #define BTRFS_INODE_ITEM_KEY 1
289 * dir items are the name -> inode pointers in a directory. There is one
290 * for every name in a directory.
292 #define BTRFS_DIR_ITEM_KEY 2
293 #define BTRFS_DIR_INDEX_KEY 3
295 * inline data is file data that fits in the btree.
297 #define BTRFS_INLINE_DATA_KEY 4
299 * extent data is for data that can't fit in the btree. It points to
300 * a (hopefully) huge chunk of disk
302 #define BTRFS_EXTENT_DATA_KEY 5
304 * csum items have the checksums for data in the extents
306 #define BTRFS_CSUM_ITEM_KEY 6
309 * root items point to tree roots. There are typically in the root
310 * tree used by the super block to find all the other trees
312 #define BTRFS_ROOT_ITEM_KEY 7
314 * extent items are in the extent map tree. These record which blocks
315 * are used, and how many references there are to each block
317 #define BTRFS_EXTENT_ITEM_KEY 8
320 * dev items list the devices that make up the FS
322 #define BTRFS_DEV_ITEM_KEY 9
325 * string items are for debugging. They just store a short string of
326 * data in the FS
328 #define BTRFS_STRING_ITEM_KEY 10
330 static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
332 return le64_to_cpu(i->generation);
335 static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
336 u64 val)
338 i->generation = cpu_to_le64(val);
341 static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
343 return le64_to_cpu(i->size);
346 static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
348 i->size = cpu_to_le64(val);
351 static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
353 return le64_to_cpu(i->nblocks);
356 static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
358 i->nblocks = cpu_to_le64(val);
361 static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
363 return le32_to_cpu(i->nlink);
366 static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
368 i->nlink = cpu_to_le32(val);
371 static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
373 return le32_to_cpu(i->uid);
376 static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
378 i->uid = cpu_to_le32(val);
381 static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
383 return le32_to_cpu(i->gid);
386 static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
388 i->gid = cpu_to_le32(val);
391 static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
393 return le32_to_cpu(i->mode);
396 static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
398 i->mode = cpu_to_le32(val);
401 static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i)
403 return le32_to_cpu(i->rdev);
406 static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val)
408 i->rdev = cpu_to_le32(val);
411 static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i)
413 return le16_to_cpu(i->flags);
416 static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val)
418 i->flags = cpu_to_le16(val);
421 static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i)
423 return le16_to_cpu(i->compat_flags);
426 static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
427 u16 val)
429 i->compat_flags = cpu_to_le16(val);
432 static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
434 return le64_to_cpu(ts->sec);
437 static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
438 u64 val)
440 ts->sec = cpu_to_le64(val);
443 static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
445 return le32_to_cpu(ts->nsec);
448 static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
449 u32 val)
451 ts->nsec = cpu_to_le32(val);
454 static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei)
456 return le32_to_cpu(ei->refs);
459 static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val)
461 ei->refs = cpu_to_le32(val);
464 static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr)
466 return le64_to_cpu(n->ptrs[nr].blockptr);
469 static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr,
470 u64 val)
472 n->ptrs[nr].blockptr = cpu_to_le64(val);
475 static inline u32 btrfs_item_offset(struct btrfs_item *item)
477 return le32_to_cpu(item->offset);
480 static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val)
482 item->offset = cpu_to_le32(val);
485 static inline u32 btrfs_item_end(struct btrfs_item *item)
487 return le32_to_cpu(item->offset) + le16_to_cpu(item->size);
490 static inline u16 btrfs_item_size(struct btrfs_item *item)
492 return le16_to_cpu(item->size);
495 static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val)
497 item->size = cpu_to_le16(val);
500 static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
502 return le16_to_cpu(d->flags);
505 static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
507 d->flags = cpu_to_le16(val);
510 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
512 return d->type;
515 static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val)
517 d->type = val;
520 static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d)
522 return le16_to_cpu(d->name_len);
525 static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
527 d->name_len = cpu_to_le16(val);
530 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
531 struct btrfs_disk_key *disk)
533 cpu->offset = le64_to_cpu(disk->offset);
534 cpu->flags = le32_to_cpu(disk->flags);
535 cpu->objectid = le64_to_cpu(disk->objectid);
538 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
539 struct btrfs_key *cpu)
541 disk->offset = cpu_to_le64(cpu->offset);
542 disk->flags = cpu_to_le32(cpu->flags);
543 disk->objectid = cpu_to_le64(cpu->objectid);
546 static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk)
548 return le64_to_cpu(disk->objectid);
551 static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
552 u64 val)
554 disk->objectid = cpu_to_le64(val);
557 static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
559 return le64_to_cpu(disk->offset);
562 static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
563 u64 val)
565 disk->offset = cpu_to_le64(val);
568 static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
570 return le32_to_cpu(disk->flags);
573 static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
574 u32 val)
576 disk->flags = cpu_to_le32(val);
579 static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
581 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
584 static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
585 u32 val)
587 u32 flags = btrfs_disk_key_flags(key);
588 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
589 val = val << BTRFS_KEY_TYPE_SHIFT;
590 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
591 btrfs_set_disk_key_flags(key, flags);
594 static inline u32 btrfs_key_type(struct btrfs_key *key)
596 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
599 static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
601 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
602 val = val << BTRFS_KEY_TYPE_SHIFT;
603 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
606 static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
608 return le64_to_cpu(h->blocknr);
611 static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
613 h->blocknr = cpu_to_le64(blocknr);
616 static inline u64 btrfs_header_generation(struct btrfs_header *h)
618 return le64_to_cpu(h->generation);
621 static inline void btrfs_set_header_generation(struct btrfs_header *h,
622 u64 val)
624 h->generation = cpu_to_le64(val);
627 static inline u16 btrfs_header_nritems(struct btrfs_header *h)
629 return le16_to_cpu(h->nritems);
632 static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
634 h->nritems = cpu_to_le16(val);
637 static inline u16 btrfs_header_flags(struct btrfs_header *h)
639 return le16_to_cpu(h->flags);
642 static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
644 h->flags = cpu_to_le16(val);
647 static inline int btrfs_header_level(struct btrfs_header *h)
649 return h->level;
652 static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
654 BUG_ON(level > BTRFS_MAX_LEVEL);
655 h->level = level;
658 static inline int btrfs_is_leaf(struct btrfs_node *n)
660 return (btrfs_header_level(&n->header) == 0);
663 static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
665 return le64_to_cpu(item->blocknr);
668 static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
670 item->blocknr = cpu_to_le64(val);
673 static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
675 return le64_to_cpu(item->root_dirid);
678 static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
680 item->root_dirid = cpu_to_le64(val);
683 static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
685 return le32_to_cpu(item->refs);
688 static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
690 item->refs = cpu_to_le32(val);
693 static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
695 return le64_to_cpu(s->blocknr);
698 static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
700 s->blocknr = cpu_to_le64(val);
703 static inline u64 btrfs_super_generation(struct btrfs_super_block *s)
705 return le64_to_cpu(s->generation);
708 static inline void btrfs_set_super_generation(struct btrfs_super_block *s,
709 u64 val)
711 s->generation = cpu_to_le64(val);
714 static inline u64 btrfs_super_root(struct btrfs_super_block *s)
716 return le64_to_cpu(s->root);
719 static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
721 s->root = cpu_to_le64(val);
724 static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
726 return le64_to_cpu(s->total_blocks);
729 static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
730 u64 val)
732 s->total_blocks = cpu_to_le64(val);
735 static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
737 return le64_to_cpu(s->blocks_used);
740 static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
741 u64 val)
743 s->blocks_used = cpu_to_le64(val);
746 static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s)
748 return le32_to_cpu(s->blocksize);
751 static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
752 u32 val)
754 s->blocksize = cpu_to_le32(val);
757 static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s)
759 return le64_to_cpu(s->root_dir_objectid);
762 static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64
763 val)
765 s->root_dir_objectid = cpu_to_le64(val);
768 static inline u64 btrfs_super_last_device_id(struct btrfs_super_block *s)
770 return le64_to_cpu(s->last_device_id);
773 static inline void btrfs_set_super_last_device_id(struct btrfs_super_block *s,
774 u64 val)
776 s->last_device_id = cpu_to_le64(val);
779 static inline u64 btrfs_super_device_id(struct btrfs_super_block *s)
781 return le64_to_cpu(s->device_id);
784 static inline void btrfs_set_super_device_id(struct btrfs_super_block *s,
785 u64 val)
787 s->device_id = cpu_to_le64(val);
790 static inline u64 btrfs_super_device_block_start(struct btrfs_super_block *s)
792 return le64_to_cpu(s->device_block_start);
795 static inline void btrfs_set_super_device_block_start(struct btrfs_super_block
796 *s, u64 val)
798 s->device_block_start = cpu_to_le64(val);
801 static inline u64 btrfs_super_device_num_blocks(struct btrfs_super_block *s)
803 return le64_to_cpu(s->device_num_blocks);
806 static inline void btrfs_set_super_device_num_blocks(struct btrfs_super_block
807 *s, u64 val)
809 s->device_num_blocks = cpu_to_le64(val);
812 static inline u64 btrfs_super_device_root(struct btrfs_super_block *s)
814 return le64_to_cpu(s->device_root);
817 static inline void btrfs_set_super_device_root(struct btrfs_super_block
818 *s, u64 val)
820 s->device_root = cpu_to_le64(val);
823 static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l)
825 return (u8 *)l->items;
828 static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e)
830 return e->type;
832 static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
833 u8 val)
835 e->type = val;
838 static inline char *btrfs_file_extent_inline_start(struct
839 btrfs_file_extent_item *e)
841 return (char *)(&e->disk_blocknr);
844 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
846 return (unsigned long)(&((struct
847 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
850 static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
852 struct btrfs_file_extent_item *fe = NULL;
853 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
856 static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
859 return le64_to_cpu(e->disk_blocknr);
862 static inline void btrfs_set_file_extent_disk_blocknr(struct
863 btrfs_file_extent_item
864 *e, u64 val)
866 e->disk_blocknr = cpu_to_le64(val);
869 static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e)
871 return le64_to_cpu(e->generation);
874 static inline void btrfs_set_file_extent_generation(struct
875 btrfs_file_extent_item *e,
876 u64 val)
878 e->generation = cpu_to_le64(val);
881 static inline u64 btrfs_file_extent_disk_num_blocks(struct
882 btrfs_file_extent_item *e)
884 return le64_to_cpu(e->disk_num_blocks);
887 static inline void btrfs_set_file_extent_disk_num_blocks(struct
888 btrfs_file_extent_item
889 *e, u64 val)
891 e->disk_num_blocks = cpu_to_le64(val);
894 static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
896 return le64_to_cpu(e->offset);
899 static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
900 *e, u64 val)
902 e->offset = cpu_to_le64(val);
905 static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
908 return le64_to_cpu(e->num_blocks);
911 static inline void btrfs_set_file_extent_num_blocks(struct
912 btrfs_file_extent_item *e,
913 u64 val)
915 e->num_blocks = cpu_to_le64(val);
918 static inline u16 btrfs_device_pathlen(struct btrfs_device_item *d)
920 return le16_to_cpu(d->pathlen);
923 static inline void btrfs_set_device_pathlen(struct btrfs_device_item *d,
924 u16 val)
926 d->pathlen = cpu_to_le16(val);
929 static inline u64 btrfs_device_id(struct btrfs_device_item *d)
931 return le64_to_cpu(d->device_id);
934 static inline void btrfs_set_device_id(struct btrfs_device_item *d,
935 u64 val)
937 d->device_id = cpu_to_le64(val);
940 /* helper function to cast into the data area of the leaf. */
941 #define btrfs_item_ptr(leaf, slot, type) \
942 ((type *)(btrfs_leaf_data(leaf) + \
943 btrfs_item_offset((leaf)->items + (slot))))
945 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
946 *root, struct btrfs_path *path, u32 data_size);
947 struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
948 struct btrfs_root *root);
949 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
950 struct btrfs_buffer *buf);
951 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
952 *root, u64 blocknr, u64 num_blocks, int pin);
953 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
954 *root, struct btrfs_key *key, struct btrfs_path *p, int
955 ins_len, int cow);
956 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
957 void btrfs_init_path(struct btrfs_path *p);
958 int btrfs_del_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
959 struct btrfs_path *path);
960 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
961 *root, struct btrfs_key *key, void *data, u32 data_size);
962 int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
963 *root, struct btrfs_path *path, struct btrfs_key
964 *cpu_key, u32 data_size);
965 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
966 int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf);
967 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
968 *root, struct btrfs_buffer *snap);
969 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct
970 btrfs_root *root);
971 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
972 struct btrfs_key *key);
973 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
974 *root, struct btrfs_key *key, struct btrfs_root_item
975 *item);
976 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
977 *root, struct btrfs_key *key, struct btrfs_root_item
978 *item);
979 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
980 btrfs_root_item *item, struct btrfs_key *key);
981 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
982 *root, char *name, int name_len, u64 dir,
983 struct btrfs_key *location, u8 type);
984 int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
985 *root, struct btrfs_path *path, u64 dir, char *name,
986 int name_len, int mod);
987 int btrfs_match_dir_item_name(struct btrfs_root *root, struct btrfs_path *path,
988 char *name, int name_len);
989 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
990 struct btrfs_root *fs_root,
991 u64 dirid, u64 *objectid);
992 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
993 *root, u64 objectid, struct btrfs_inode_item
994 *inode_item);
995 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
996 *root, struct btrfs_path *path, u64 objectid, int mod);
997 #endif