Fix the pretty print code for num_bytes == 0
[btrfs-progs-unstable.git] / ctree.h
bloba5a284c6b1078aaa6e1e357a8d5288cbad825bf4
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
62 #define BTRFS_FIRST_CHUNK_TREE_OBJECTID 256ULL
66 * the device items go into the chunk tree. The key is in the form
67 * [ 1 BTRFS_DEV_ITEM_KEY device_id ]
69 #define BTRFS_DEV_ITEMS_OBJECTID 1ULL
72 * we can actually store much bigger names, but lets not confuse the rest
73 * of linux
75 #define BTRFS_NAME_LEN 255
77 /* 32 bytes in various csum fields */
78 #define BTRFS_CSUM_SIZE 32
79 /* four bytes for CRC32 */
80 #define BTRFS_CRC32_SIZE 4
81 #define BTRFS_EMPTY_DIR_SIZE 0
83 #define BTRFS_FT_UNKNOWN 0
84 #define BTRFS_FT_REG_FILE 1
85 #define BTRFS_FT_DIR 2
86 #define BTRFS_FT_CHRDEV 3
87 #define BTRFS_FT_BLKDEV 4
88 #define BTRFS_FT_FIFO 5
89 #define BTRFS_FT_SOCK 6
90 #define BTRFS_FT_SYMLINK 7
91 #define BTRFS_FT_XATTR 8
92 #define BTRFS_FT_MAX 9
95 * the key defines the order in the tree, and so it also defines (optimal)
96 * block layout. objectid corresonds to the inode number. The flags
97 * tells us things about the object, and is a kind of stream selector.
98 * so for a given inode, keys with flags of 1 might refer to the inode
99 * data, flags of 2 may point to file data in the btree and flags == 3
100 * may point to extents.
102 * offset is the starting byte offset for this key in the stream.
104 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
105 * in cpu native order. Otherwise they are identical and their sizes
106 * should be the same (ie both packed)
108 struct btrfs_disk_key {
109 __le64 objectid;
110 u8 type;
111 __le64 offset;
112 } __attribute__ ((__packed__));
114 struct btrfs_key {
115 u64 objectid;
116 u8 type;
117 u64 offset;
118 } __attribute__ ((__packed__));
120 struct btrfs_mapping_tree {
121 struct cache_tree cache_tree;
124 #define BTRFS_UUID_SIZE 16
125 struct btrfs_dev_item {
126 /* the internal btrfs device id */
127 __le64 devid;
129 /* size of the device */
130 __le64 total_bytes;
132 /* bytes used */
133 __le64 bytes_used;
135 /* optimal io alignment for this device */
136 __le32 io_align;
138 /* optimal io width for this device */
139 __le32 io_width;
141 /* minimal io size for this device */
142 __le32 sector_size;
144 /* type and info about this device */
145 __le64 type;
147 /* grouping information for allocation decisions */
148 __le32 dev_group;
150 /* seek speed 0-100 where 100 is fastest */
151 u8 seek_speed;
153 /* bandwidth 0-100 where 100 is fastest */
154 u8 bandwidth;
156 /* btrfs generated uuid for this device */
157 u8 uuid[BTRFS_UUID_SIZE];
158 } __attribute__ ((__packed__));
160 struct btrfs_stripe {
161 __le64 devid;
162 __le64 offset;
163 u8 dev_uuid[BTRFS_UUID_SIZE];
164 } __attribute__ ((__packed__));
166 struct btrfs_chunk {
167 /* size of this chunk in bytes */
168 __le64 length;
170 /* objectid of the root referencing this chunk */
171 __le64 owner;
173 __le64 stripe_len;
174 __le64 type;
176 /* optimal io alignment for this chunk */
177 __le32 io_align;
179 /* optimal io width for this chunk */
180 __le32 io_width;
182 /* minimal io size for this chunk */
183 __le32 sector_size;
185 /* 2^16 stripes is quite a lot, a second limit is the size of a single
186 * item in the btree
188 __le16 num_stripes;
190 /* sub stripes only matter for raid10 */
191 __le16 sub_stripes;
192 struct btrfs_stripe stripe;
193 /* additional stripes go here */
194 } __attribute__ ((__packed__));
196 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
198 BUG_ON(num_stripes == 0);
199 return sizeof(struct btrfs_chunk) +
200 sizeof(struct btrfs_stripe) * (num_stripes - 1);
203 #define BTRFS_FSID_SIZE 16
204 #define BTRFS_HEADER_FLAG_WRITTEN (1 << 0)
207 * every tree block (leaf or node) starts with this header.
209 struct btrfs_header {
210 /* these first four must match the super block */
211 u8 csum[BTRFS_CSUM_SIZE];
212 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
213 __le64 bytenr; /* which block this node is supposed to live in */
214 __le64 flags;
216 /* allowed to be different from the super from here on down */
217 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
218 __le64 generation;
219 __le64 owner;
220 __le32 nritems;
221 u8 level;
222 } __attribute__ ((__packed__));
224 #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
225 sizeof(struct btrfs_header)) / \
226 sizeof(struct btrfs_key_ptr))
227 #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
228 #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
229 #define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
230 sizeof(struct btrfs_item) - \
231 sizeof(struct btrfs_file_extent_item))
234 * this is a very generous portion of the super block, giving us
235 * room to translate 14 chunks with 3 stripes each.
237 #define BTRFS_SYSTEM_CHUNK_ARRAY_SIZE 2048
238 #define BTRFS_LABEL_SIZE 256
241 * the super block basically lists the main trees of the FS
242 * it currently lacks any block count etc etc
244 struct btrfs_super_block {
245 u8 csum[BTRFS_CSUM_SIZE];
246 /* the first 3 fields must match struct btrfs_header */
247 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
248 __le64 bytenr; /* this block number */
249 __le64 flags;
251 /* allowed to be different from the btrfs_header from here own down */
252 __le64 magic;
253 __le64 generation;
254 __le64 root;
255 __le64 chunk_root;
256 __le64 total_bytes;
257 __le64 bytes_used;
258 __le64 root_dir_objectid;
259 __le64 num_devices;
260 __le32 sectorsize;
261 __le32 nodesize;
262 __le32 leafsize;
263 __le32 stripesize;
264 __le32 sys_chunk_array_size;
265 u8 root_level;
266 u8 chunk_root_level;
267 struct btrfs_dev_item dev_item;
268 char label[BTRFS_LABEL_SIZE];
269 u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
270 } __attribute__ ((__packed__));
273 * A leaf is full of items. offset and size tell us where to find
274 * the item in the leaf (relative to the start of the data area)
276 struct btrfs_item {
277 struct btrfs_disk_key key;
278 __le32 offset;
279 __le32 size;
280 } __attribute__ ((__packed__));
283 * leaves have an item area and a data area:
284 * [item0, item1....itemN] [free space] [dataN...data1, data0]
286 * The data is separate from the items to get the keys closer together
287 * during searches.
289 struct btrfs_leaf {
290 struct btrfs_header header;
291 struct btrfs_item items[];
292 } __attribute__ ((__packed__));
295 * all non-leaf blocks are nodes, they hold only keys and pointers to
296 * other blocks
298 struct btrfs_key_ptr {
299 struct btrfs_disk_key key;
300 __le64 blockptr;
301 __le64 generation;
302 } __attribute__ ((__packed__));
304 struct btrfs_node {
305 struct btrfs_header header;
306 struct btrfs_key_ptr ptrs[];
307 } __attribute__ ((__packed__));
310 * btrfs_paths remember the path taken from the root down to the leaf.
311 * level 0 is always the leaf, and nodes[1...BTRFS_MAX_LEVEL] will point
312 * to any other levels that are present.
314 * The slots array records the index of the item or block pointer
315 * used while walking the tree.
317 struct btrfs_path {
318 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
319 int slots[BTRFS_MAX_LEVEL];
320 int reada;
321 int lowest_level;
325 * items in the extent btree are used to record the objectid of the
326 * owner of the block and the number of references
328 struct btrfs_extent_item {
329 __le32 refs;
330 } __attribute__ ((__packed__));
332 struct btrfs_extent_ref {
333 __le64 root;
334 __le64 generation;
335 __le64 objectid;
336 __le64 offset;
337 } __attribute__ ((__packed__));
339 /* dev extents record free space on individual devices. The owner
340 * field points back to the chunk allocation mapping tree that allocated
341 * the extent. The chunk tree uuid field is a way to double check the owner
343 struct btrfs_dev_extent {
344 __le64 chunk_tree;
345 __le64 chunk_objectid;
346 __le64 chunk_offset;
347 __le64 length;
348 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
349 } __attribute__ ((__packed__));
351 struct btrfs_inode_ref {
352 __le16 name_len;
353 /* name goes here */
354 } __attribute__ ((__packed__));
356 struct btrfs_timespec {
357 __le64 sec;
358 __le32 nsec;
359 } __attribute__ ((__packed__));
362 * there is no padding here on purpose. If you want to extent the inode,
363 * make a new item type
365 struct btrfs_inode_item {
366 __le64 generation;
367 __le64 size;
368 __le64 nblocks;
369 __le64 block_group;
370 __le32 nlink;
371 __le32 uid;
372 __le32 gid;
373 __le32 mode;
374 __le64 rdev;
375 __le16 flags;
376 __le16 compat_flags;
377 struct btrfs_timespec atime;
378 struct btrfs_timespec ctime;
379 struct btrfs_timespec mtime;
380 struct btrfs_timespec otime;
381 } __attribute__ ((__packed__));
383 struct btrfs_dir_item {
384 struct btrfs_disk_key location;
385 __le16 data_len;
386 __le16 name_len;
387 u8 type;
388 } __attribute__ ((__packed__));
390 struct btrfs_root_item {
391 struct btrfs_inode_item inode;
392 __le64 root_dirid;
393 __le64 bytenr;
394 __le64 byte_limit;
395 __le64 bytes_used;
396 __le32 flags;
397 __le32 refs;
398 struct btrfs_disk_key drop_progress;
399 u8 drop_level;
400 u8 level;
401 } __attribute__ ((__packed__));
403 #define BTRFS_FILE_EXTENT_REG 0
404 #define BTRFS_FILE_EXTENT_INLINE 1
406 struct btrfs_file_extent_item {
407 __le64 generation;
408 u8 type;
410 * disk space consumed by the extent, checksum blocks are included
411 * in these numbers
413 __le64 disk_bytenr;
414 __le64 disk_num_bytes;
416 * the logical offset in file blocks (no csums)
417 * this extent record is for. This allows a file extent to point
418 * into the middle of an existing extent on disk, sharing it
419 * between two snapshots (useful if some bytes in the middle of the
420 * extent have changed
422 __le64 offset;
424 * the logical number of file blocks (no csums included)
426 __le64 num_bytes;
427 } __attribute__ ((__packed__));
429 struct btrfs_csum_item {
430 u8 csum;
431 } __attribute__ ((__packed__));
433 /* tag for the radix tree of block groups in ram */
434 #define BTRFS_BLOCK_GROUP_DATA (1 << 0)
435 #define BTRFS_BLOCK_GROUP_SYSTEM (1 << 1)
436 #define BTRFS_BLOCK_GROUP_METADATA (1 << 2)
437 #define BTRFS_BLOCK_GROUP_RAID0 (1 << 3)
438 #define BTRFS_BLOCK_GROUP_RAID1 (1 << 4)
439 #define BTRFS_BLOCK_GROUP_DUP (1 << 5)
440 #define BTRFS_BLOCK_GROUP_RAID10 (1 << 6)
442 struct btrfs_block_group_item {
443 __le64 used;
444 __le64 chunk_objectid;
445 __le64 flags;
446 } __attribute__ ((__packed__));
448 struct btrfs_space_info {
449 u64 flags;
450 u64 total_bytes;
451 u64 bytes_used;
452 u64 bytes_pinned;
453 int full;
454 struct list_head list;
457 struct btrfs_block_group_cache {
458 struct cache_extent cache;
459 struct btrfs_key key;
460 struct btrfs_block_group_item item;
461 struct btrfs_space_info *space_info;
462 u64 pinned;
463 u64 flags;
464 int cached;
467 struct btrfs_extent_ops {
468 int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
469 u64 hint_byte, struct btrfs_key *ins);
470 int (*free_extent)(struct btrfs_root *root, u64 bytenr,
471 u64 num_bytes);
474 struct btrfs_device;
475 struct btrfs_fs_devices;
476 struct btrfs_fs_info {
477 u8 fsid[BTRFS_FSID_SIZE];
478 u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
479 struct btrfs_root *fs_root;
480 struct btrfs_root *extent_root;
481 struct btrfs_root *tree_root;
482 struct btrfs_root *chunk_root;
483 struct btrfs_root *dev_root;
485 struct extent_io_tree extent_cache;
486 struct extent_io_tree free_space_cache;
487 struct extent_io_tree block_group_cache;
488 struct extent_io_tree pinned_extents;
489 struct extent_io_tree pending_del;
490 struct extent_io_tree extent_ins;
492 /* logical->physical extent mapping */
493 struct btrfs_mapping_tree mapping_tree;
495 u64 generation;
496 u64 last_trans_committed;
498 u64 avail_data_alloc_bits;
499 u64 avail_metadata_alloc_bits;
500 u64 avail_system_alloc_bits;
501 u64 data_alloc_profile;
502 u64 metadata_alloc_profile;
503 u64 system_alloc_profile;
504 u64 alloc_start;
506 struct btrfs_trans_handle *running_transaction;
507 struct btrfs_super_block super_copy;
508 struct extent_buffer *sb_buffer;
509 struct mutex fs_mutex;
510 u64 total_pinned;
512 struct btrfs_extent_ops *extent_ops;
513 struct list_head dirty_cowonly_roots;
515 struct btrfs_fs_devices *fs_devices;
516 struct list_head space_info;
517 int system_allocs;
518 int readonly;
522 * in ram representation of the tree. extent_root is used for all allocations
523 * and for the extent tree extent_root root.
525 struct btrfs_root {
526 struct extent_buffer *node;
527 struct extent_buffer *commit_root;
528 struct btrfs_root_item root_item;
529 struct btrfs_key root_key;
530 struct btrfs_fs_info *fs_info;
531 u64 objectid;
532 u64 last_trans;
534 /* data allocations are done in sectorsize units */
535 u32 sectorsize;
537 /* node allocations are done in nodesize units */
538 u32 nodesize;
540 /* leaf allocations are done in leafsize units */
541 u32 leafsize;
543 /* leaf allocations are done in leafsize units */
544 u32 stripesize;
546 int ref_cows;
547 int track_dirty;
550 u32 type;
551 u64 highest_inode;
552 u64 last_inode_alloc;
554 /* the dirty list is only used by non-reference counted roots */
555 struct list_head dirty_list;
559 * inode items have the data typically returned from stat and store other
560 * info about object characteristics. There is one for every file and dir in
561 * the FS
563 #define BTRFS_INODE_ITEM_KEY 1
564 #define BTRFS_INODE_REF_KEY 2
565 #define BTRFS_XATTR_ITEM_KEY 8
567 /* reserve 3-15 close to the inode for later flexibility */
570 * dir items are the name -> inode pointers in a directory. There is one
571 * for every name in a directory.
573 #define BTRFS_DIR_ITEM_KEY 16
574 #define BTRFS_DIR_INDEX_KEY 17
576 * extent data is for file data
578 #define BTRFS_EXTENT_DATA_KEY 18
580 * csum items have the checksums for data in the extents
582 #define BTRFS_CSUM_ITEM_KEY 19
584 /* reserve 20-31 for other file stuff */
587 * root items point to tree roots. There are typically in the root
588 * tree used by the super block to find all the other trees
590 #define BTRFS_ROOT_ITEM_KEY 32
592 * extent items are in the extent map tree. These record which blocks
593 * are used, and how many references there are to each block
595 #define BTRFS_EXTENT_ITEM_KEY 33
596 #define BTRFS_EXTENT_REF_KEY 34
599 * block groups give us hints into the extent allocation trees. Which
600 * blocks are free etc etc
602 #define BTRFS_BLOCK_GROUP_ITEM_KEY 50
604 #define BTRFS_DEV_EXTENT_KEY 75
605 #define BTRFS_DEV_ITEM_KEY 76
606 #define BTRFS_CHUNK_ITEM_KEY 77
609 * string items are for debugging. They just store a short string of
610 * data in the FS
612 #define BTRFS_STRING_ITEM_KEY 253
614 * Inode flags
616 #define BTRFS_INODE_NODATASUM (1 << 0)
617 #define BTRFS_INODE_NODATACOW (1 << 1)
618 #define BTRFS_INODE_READONLY (1 << 2)
620 #define read_eb_member(eb, ptr, type, member, result) ( \
621 read_extent_buffer(eb, (char *)(result), \
622 ((unsigned long)(ptr)) + \
623 offsetof(type, member), \
624 sizeof(((type *)0)->member)))
626 #define write_eb_member(eb, ptr, type, member, result) ( \
627 write_extent_buffer(eb, (char *)(result), \
628 ((unsigned long)(ptr)) + \
629 offsetof(type, member), \
630 sizeof(((type *)0)->member)))
632 #define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
633 static inline u##bits btrfs_##name(struct extent_buffer *eb) \
635 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
636 return le##bits##_to_cpu(h->member); \
638 static inline void btrfs_set_##name(struct extent_buffer *eb, \
639 u##bits val) \
641 struct btrfs_header *h = (struct btrfs_header *)eb->data; \
642 h->member = cpu_to_le##bits(val); \
645 #define BTRFS_SETGET_FUNCS(name, type, member, bits) \
646 static inline u##bits btrfs_##name(struct extent_buffer *eb, \
647 type *s) \
649 unsigned long offset = (unsigned long)s; \
650 type *p = (type *) (eb->data + offset); \
651 return le##bits##_to_cpu(p->member); \
653 static inline void btrfs_set_##name(struct extent_buffer *eb, \
654 type *s, u##bits val) \
656 unsigned long offset = (unsigned long)s; \
657 type *p = (type *) (eb->data + offset); \
658 p->member = cpu_to_le##bits(val); \
661 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
662 static inline u##bits btrfs_##name(type *s) \
664 return le##bits##_to_cpu(s->member); \
666 static inline void btrfs_set_##name(type *s, u##bits val) \
668 s->member = cpu_to_le##bits(val); \
671 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
672 BTRFS_SETGET_FUNCS(device_total_bytes, struct btrfs_dev_item, total_bytes, 64);
673 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
674 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
675 BTRFS_SETGET_FUNCS(device_io_width, struct btrfs_dev_item, io_width, 32);
676 BTRFS_SETGET_FUNCS(device_sector_size, struct btrfs_dev_item, sector_size, 32);
677 BTRFS_SETGET_FUNCS(device_id, struct btrfs_dev_item, devid, 64);
678 BTRFS_SETGET_FUNCS(device_group, struct btrfs_dev_item, dev_group, 32);
679 BTRFS_SETGET_FUNCS(device_seek_speed, struct btrfs_dev_item, seek_speed, 8);
680 BTRFS_SETGET_FUNCS(device_bandwidth, struct btrfs_dev_item, bandwidth, 8);
682 BTRFS_SETGET_STACK_FUNCS(stack_device_type, struct btrfs_dev_item, type, 64);
683 BTRFS_SETGET_STACK_FUNCS(stack_device_total_bytes, struct btrfs_dev_item,
684 total_bytes, 64);
685 BTRFS_SETGET_STACK_FUNCS(stack_device_bytes_used, struct btrfs_dev_item,
686 bytes_used, 64);
687 BTRFS_SETGET_STACK_FUNCS(stack_device_io_align, struct btrfs_dev_item,
688 io_align, 32);
689 BTRFS_SETGET_STACK_FUNCS(stack_device_io_width, struct btrfs_dev_item,
690 io_width, 32);
691 BTRFS_SETGET_STACK_FUNCS(stack_device_sector_size, struct btrfs_dev_item,
692 sector_size, 32);
693 BTRFS_SETGET_STACK_FUNCS(stack_device_id, struct btrfs_dev_item, devid, 64);
694 BTRFS_SETGET_STACK_FUNCS(stack_device_group, struct btrfs_dev_item,
695 dev_group, 32);
696 BTRFS_SETGET_STACK_FUNCS(stack_device_seek_speed, struct btrfs_dev_item,
697 seek_speed, 8);
698 BTRFS_SETGET_STACK_FUNCS(stack_device_bandwidth, struct btrfs_dev_item,
699 bandwidth, 8);
701 static inline char *btrfs_device_uuid(struct btrfs_dev_item *d)
703 return (char *)d + offsetof(struct btrfs_dev_item, uuid);
706 BTRFS_SETGET_FUNCS(chunk_length, struct btrfs_chunk, length, 64);
707 BTRFS_SETGET_FUNCS(chunk_owner, struct btrfs_chunk, owner, 64);
708 BTRFS_SETGET_FUNCS(chunk_stripe_len, struct btrfs_chunk, stripe_len, 64);
709 BTRFS_SETGET_FUNCS(chunk_io_align, struct btrfs_chunk, io_align, 32);
710 BTRFS_SETGET_FUNCS(chunk_io_width, struct btrfs_chunk, io_width, 32);
711 BTRFS_SETGET_FUNCS(chunk_sector_size, struct btrfs_chunk, sector_size, 32);
712 BTRFS_SETGET_FUNCS(chunk_type, struct btrfs_chunk, type, 64);
713 BTRFS_SETGET_FUNCS(chunk_num_stripes, struct btrfs_chunk, num_stripes, 16);
714 BTRFS_SETGET_FUNCS(chunk_sub_stripes, struct btrfs_chunk, sub_stripes, 16);
715 BTRFS_SETGET_FUNCS(stripe_devid, struct btrfs_stripe, devid, 64);
716 BTRFS_SETGET_FUNCS(stripe_offset, struct btrfs_stripe, offset, 64);
718 static inline char *btrfs_stripe_dev_uuid(struct btrfs_stripe *s)
720 return (char *)s + offsetof(struct btrfs_stripe, dev_uuid);
723 BTRFS_SETGET_STACK_FUNCS(stack_chunk_length, struct btrfs_chunk, length, 64);
724 BTRFS_SETGET_STACK_FUNCS(stack_chunk_owner, struct btrfs_chunk, owner, 64);
725 BTRFS_SETGET_STACK_FUNCS(stack_chunk_stripe_len, struct btrfs_chunk,
726 stripe_len, 64);
727 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_align, struct btrfs_chunk,
728 io_align, 32);
729 BTRFS_SETGET_STACK_FUNCS(stack_chunk_io_width, struct btrfs_chunk,
730 io_width, 32);
731 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sector_size, struct btrfs_chunk,
732 sector_size, 32);
733 BTRFS_SETGET_STACK_FUNCS(stack_chunk_type, struct btrfs_chunk, type, 64);
734 BTRFS_SETGET_STACK_FUNCS(stack_chunk_num_stripes, struct btrfs_chunk,
735 num_stripes, 16);
736 BTRFS_SETGET_STACK_FUNCS(stack_chunk_sub_stripes, struct btrfs_chunk,
737 sub_stripes, 16);
738 BTRFS_SETGET_STACK_FUNCS(stack_stripe_devid, struct btrfs_stripe, devid, 64);
739 BTRFS_SETGET_STACK_FUNCS(stack_stripe_offset, struct btrfs_stripe, offset, 64);
741 static inline struct btrfs_stripe *btrfs_stripe_nr(struct btrfs_chunk *c,
742 int nr)
744 unsigned long offset = (unsigned long)c;
745 offset += offsetof(struct btrfs_chunk, stripe);
746 offset += nr * sizeof(struct btrfs_stripe);
747 return (struct btrfs_stripe *)offset;
750 static inline char *btrfs_stripe_dev_uuid_nr(struct btrfs_chunk *c, int nr)
752 return btrfs_stripe_dev_uuid(btrfs_stripe_nr(c, nr));
755 static inline u64 btrfs_stripe_offset_nr(struct extent_buffer *eb,
756 struct btrfs_chunk *c, int nr)
758 return btrfs_stripe_offset(eb, btrfs_stripe_nr(c, nr));
761 static inline void btrfs_set_stripe_offset_nr(struct extent_buffer *eb,
762 struct btrfs_chunk *c, int nr,
763 u64 val)
765 btrfs_set_stripe_offset(eb, btrfs_stripe_nr(c, nr), val);
768 static inline u64 btrfs_stripe_devid_nr(struct extent_buffer *eb,
769 struct btrfs_chunk *c, int nr)
771 return btrfs_stripe_devid(eb, btrfs_stripe_nr(c, nr));
774 static inline void btrfs_set_stripe_devid_nr(struct extent_buffer *eb,
775 struct btrfs_chunk *c, int nr,
776 u64 val)
778 btrfs_set_stripe_devid(eb, btrfs_stripe_nr(c, nr), val);
781 /* struct btrfs_block_group_item */
782 BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
783 used, 64);
784 BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
785 used, 64);
786 BTRFS_SETGET_STACK_FUNCS(block_group_chunk_objectid,
787 struct btrfs_block_group_item, chunk_objectid, 64);
789 BTRFS_SETGET_FUNCS(disk_block_group_chunk_objectid,
790 struct btrfs_block_group_item, chunk_objectid, 64);
791 BTRFS_SETGET_FUNCS(disk_block_group_flags,
792 struct btrfs_block_group_item, flags, 64);
793 BTRFS_SETGET_STACK_FUNCS(block_group_flags,
794 struct btrfs_block_group_item, flags, 64);
796 /* struct btrfs_inode_ref */
797 BTRFS_SETGET_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, name_len, 16);
799 /* struct btrfs_inode_item */
800 BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
801 BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
802 BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
803 BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
804 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
805 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
806 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
807 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
808 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
809 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
810 BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
811 compat_flags, 16);
813 BTRFS_SETGET_STACK_FUNCS(stack_inode_generation,
814 struct btrfs_inode_item, generation, 64);
815 BTRFS_SETGET_STACK_FUNCS(stack_inode_size,
816 struct btrfs_inode_item, size, 64);
817 BTRFS_SETGET_STACK_FUNCS(stack_inode_nblocks,
818 struct btrfs_inode_item, nblocks, 64);
819 BTRFS_SETGET_STACK_FUNCS(stack_inode_block_group,
820 struct btrfs_inode_item, block_group, 64);
821 BTRFS_SETGET_STACK_FUNCS(stack_inode_nlink,
822 struct btrfs_inode_item, nlink, 32);
823 BTRFS_SETGET_STACK_FUNCS(stack_inode_uid,
824 struct btrfs_inode_item, uid, 32);
825 BTRFS_SETGET_STACK_FUNCS(stack_inode_gid,
826 struct btrfs_inode_item, gid, 32);
827 BTRFS_SETGET_STACK_FUNCS(stack_inode_mode,
828 struct btrfs_inode_item, mode, 32);
829 BTRFS_SETGET_STACK_FUNCS(stack_inode_rdev,
830 struct btrfs_inode_item, rdev, 64);
831 BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
832 struct btrfs_inode_item, flags, 16);
833 BTRFS_SETGET_STACK_FUNCS(stack_inode_compat_flags,
834 struct btrfs_inode_item, compat_flags, 16);
836 static inline struct btrfs_timespec *
837 btrfs_inode_atime(struct btrfs_inode_item *inode_item)
839 unsigned long ptr = (unsigned long)inode_item;
840 ptr += offsetof(struct btrfs_inode_item, atime);
841 return (struct btrfs_timespec *)ptr;
844 static inline struct btrfs_timespec *
845 btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
847 unsigned long ptr = (unsigned long)inode_item;
848 ptr += offsetof(struct btrfs_inode_item, mtime);
849 return (struct btrfs_timespec *)ptr;
852 static inline struct btrfs_timespec *
853 btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
855 unsigned long ptr = (unsigned long)inode_item;
856 ptr += offsetof(struct btrfs_inode_item, ctime);
857 return (struct btrfs_timespec *)ptr;
860 static inline struct btrfs_timespec *
861 btrfs_inode_otime(struct btrfs_inode_item *inode_item)
863 unsigned long ptr = (unsigned long)inode_item;
864 ptr += offsetof(struct btrfs_inode_item, otime);
865 return (struct btrfs_timespec *)ptr;
868 BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_timespec, sec, 64);
869 BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_timespec, nsec, 32);
870 BTRFS_SETGET_STACK_FUNCS(stack_timespec_sec, struct btrfs_timespec,
871 sec, 64);
872 BTRFS_SETGET_STACK_FUNCS(stack_timespec_nsec, struct btrfs_timespec,
873 nsec, 32);
875 /* struct btrfs_dev_extent */
876 BTRFS_SETGET_FUNCS(dev_extent_chunk_tree, struct btrfs_dev_extent,
877 chunk_tree, 64);
878 BTRFS_SETGET_FUNCS(dev_extent_chunk_objectid, struct btrfs_dev_extent,
879 chunk_objectid, 64);
880 BTRFS_SETGET_FUNCS(dev_extent_chunk_offset, struct btrfs_dev_extent,
881 chunk_offset, 64);
882 BTRFS_SETGET_FUNCS(dev_extent_length, struct btrfs_dev_extent, length, 64);
884 static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
886 unsigned long ptr = offsetof(struct btrfs_dev_extent, chunk_tree_uuid);
887 return (u8 *)((unsigned long)dev + ptr);
890 /* struct btrfs_extent_item */
891 BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
893 /* struct btrfs_extent_ref */
894 BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64);
895 BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64);
896 BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64);
897 BTRFS_SETGET_FUNCS(ref_offset, struct btrfs_extent_ref, offset, 64);
899 BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
900 BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref,
901 generation, 64);
902 BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref,
903 objectid, 64);
904 BTRFS_SETGET_STACK_FUNCS(stack_ref_offset, struct btrfs_extent_ref, offset, 64);
906 BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
907 refs, 32);
909 /* struct btrfs_node */
910 BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
911 BTRFS_SETGET_FUNCS(key_generation, struct btrfs_key_ptr, generation, 64);
913 static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
915 unsigned long ptr;
916 ptr = offsetof(struct btrfs_node, ptrs) +
917 sizeof(struct btrfs_key_ptr) * nr;
918 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
921 static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
922 int nr, u64 val)
924 unsigned long ptr;
925 ptr = offsetof(struct btrfs_node, ptrs) +
926 sizeof(struct btrfs_key_ptr) * nr;
927 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
930 static inline u64 btrfs_node_ptr_generation(struct extent_buffer *eb, int nr)
932 unsigned long ptr;
933 ptr = offsetof(struct btrfs_node, ptrs) +
934 sizeof(struct btrfs_key_ptr) * nr;
935 return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
938 static inline void btrfs_set_node_ptr_generation(struct extent_buffer *eb,
939 int nr, u64 val)
941 unsigned long ptr;
942 ptr = offsetof(struct btrfs_node, ptrs) +
943 sizeof(struct btrfs_key_ptr) * nr;
944 btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
947 static inline unsigned long btrfs_node_key_ptr_offset(int nr)
949 return offsetof(struct btrfs_node, ptrs) +
950 sizeof(struct btrfs_key_ptr) * nr;
953 static inline void btrfs_node_key(struct extent_buffer *eb,
954 struct btrfs_disk_key *disk_key, int nr)
956 unsigned long ptr;
957 ptr = btrfs_node_key_ptr_offset(nr);
958 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
959 struct btrfs_key_ptr, key, disk_key);
962 static inline void btrfs_set_node_key(struct extent_buffer *eb,
963 struct btrfs_disk_key *disk_key, int nr)
965 unsigned long ptr;
966 ptr = btrfs_node_key_ptr_offset(nr);
967 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
968 struct btrfs_key_ptr, key, disk_key);
971 /* struct btrfs_item */
972 BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
973 BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
975 static inline unsigned long btrfs_item_nr_offset(int nr)
977 return offsetof(struct btrfs_leaf, items) +
978 sizeof(struct btrfs_item) * nr;
981 static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
982 int nr)
984 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
987 static inline u32 btrfs_item_end(struct extent_buffer *eb,
988 struct btrfs_item *item)
990 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
993 static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
995 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
998 static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
1000 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
1003 static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
1005 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
1008 static inline void btrfs_item_key(struct extent_buffer *eb,
1009 struct btrfs_disk_key *disk_key, int nr)
1011 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1012 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
1015 static inline void btrfs_set_item_key(struct extent_buffer *eb,
1016 struct btrfs_disk_key *disk_key, int nr)
1018 struct btrfs_item *item = btrfs_item_nr(eb, nr);
1019 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
1022 /* struct btrfs_dir_item */
1023 BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
1024 BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
1025 BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1027 static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1028 struct btrfs_dir_item *item,
1029 struct btrfs_disk_key *key)
1031 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
1034 static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
1035 struct btrfs_dir_item *item,
1036 struct btrfs_disk_key *key)
1038 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
1041 /* struct btrfs_disk_key */
1042 BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
1043 objectid, 64);
1044 BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
1045 BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
1047 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
1048 struct btrfs_disk_key *disk)
1050 cpu->offset = le64_to_cpu(disk->offset);
1051 cpu->type = disk->type;
1052 cpu->objectid = le64_to_cpu(disk->objectid);
1055 static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
1056 struct btrfs_key *cpu)
1058 disk->offset = cpu_to_le64(cpu->offset);
1059 disk->type = cpu->type;
1060 disk->objectid = cpu_to_le64(cpu->objectid);
1063 static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
1064 struct btrfs_key *key, int nr)
1066 struct btrfs_disk_key disk_key;
1067 btrfs_node_key(eb, &disk_key, nr);
1068 btrfs_disk_key_to_cpu(key, &disk_key);
1071 static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
1072 struct btrfs_key *key, int nr)
1074 struct btrfs_disk_key disk_key;
1075 btrfs_item_key(eb, &disk_key, nr);
1076 btrfs_disk_key_to_cpu(key, &disk_key);
1079 static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
1080 struct btrfs_dir_item *item,
1081 struct btrfs_key *key)
1083 struct btrfs_disk_key disk_key;
1084 btrfs_dir_item_key(eb, item, &disk_key);
1085 btrfs_disk_key_to_cpu(key, &disk_key);
1089 static inline u8 btrfs_key_type(struct btrfs_key *key)
1091 return key->type;
1094 static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
1096 key->type = val;
1099 /* struct btrfs_header */
1100 BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
1101 BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
1102 generation, 64);
1103 BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
1104 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
1105 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
1106 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
1108 static inline int btrfs_header_flag(struct extent_buffer *eb, u64 flag)
1110 return (btrfs_header_flags(eb) & flag) == flag;
1113 static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
1115 u64 flags = btrfs_header_flags(eb);
1116 btrfs_set_header_flags(eb, flags | flag);
1117 return (flags & flag) == flag;
1120 static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
1122 u64 flags = btrfs_header_flags(eb);
1123 btrfs_set_header_flags(eb, flags & ~flag);
1124 return (flags & flag) == flag;
1127 static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
1129 unsigned long ptr = offsetof(struct btrfs_header, fsid);
1130 return (u8 *)ptr;
1133 static inline u8 *btrfs_header_chunk_tree_uuid(struct extent_buffer *eb)
1135 unsigned long ptr = offsetof(struct btrfs_header, chunk_tree_uuid);
1136 return (u8 *)ptr;
1139 static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
1141 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
1142 return (u8 *)ptr;
1145 static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
1147 unsigned long ptr = offsetof(struct btrfs_header, csum);
1148 return (u8 *)ptr;
1151 static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
1153 return NULL;
1156 static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
1158 return NULL;
1161 static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
1163 return NULL;
1166 static inline int btrfs_is_leaf(struct extent_buffer *eb)
1168 return (btrfs_header_level(eb) == 0);
1171 /* struct btrfs_root_item */
1172 BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
1173 BTRFS_SETGET_FUNCS(disk_root_bytenr, struct btrfs_root_item, bytenr, 64);
1174 BTRFS_SETGET_FUNCS(disk_root_level, struct btrfs_root_item, level, 8);
1176 BTRFS_SETGET_STACK_FUNCS(root_bytenr, struct btrfs_root_item, bytenr, 64);
1177 BTRFS_SETGET_STACK_FUNCS(root_level, struct btrfs_root_item, level, 8);
1178 BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
1179 BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
1180 BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
1181 BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64);
1182 BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64);
1184 /* struct btrfs_super_block */
1185 BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
1186 BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
1187 generation, 64);
1188 BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
1189 BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
1190 struct btrfs_super_block, sys_chunk_array_size, 32);
1191 BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
1192 root_level, 8);
1193 BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
1194 chunk_root, 64);
1195 BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
1196 chunk_root_level, 64);
1197 BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
1198 total_bytes, 64);
1199 BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
1200 bytes_used, 64);
1201 BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
1202 sectorsize, 32);
1203 BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
1204 nodesize, 32);
1205 BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
1206 leafsize, 32);
1207 BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
1208 stripesize, 32);
1209 BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
1210 root_dir_objectid, 64);
1211 BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
1212 num_devices, 64);
1214 static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
1216 return offsetof(struct btrfs_leaf, items);
1219 /* struct btrfs_file_extent_item */
1220 BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
1222 static inline unsigned long btrfs_file_extent_inline_start(struct
1223 btrfs_file_extent_item *e)
1225 unsigned long offset = (unsigned long)e;
1226 offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
1227 return offset;
1230 static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
1232 return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
1235 static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
1236 struct btrfs_item *e)
1238 unsigned long offset;
1239 offset = offsetof(struct btrfs_file_extent_item, disk_bytenr);
1240 return btrfs_item_size(eb, e) - offset;
1243 BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item,
1244 disk_bytenr, 64);
1245 BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
1246 generation, 64);
1247 BTRFS_SETGET_FUNCS(file_extent_disk_num_bytes, struct btrfs_file_extent_item,
1248 disk_num_bytes, 64);
1249 BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
1250 offset, 64);
1251 BTRFS_SETGET_FUNCS(file_extent_num_bytes, struct btrfs_file_extent_item,
1252 num_bytes, 64);
1254 static inline u32 btrfs_level_size(struct btrfs_root *root, int level) {
1255 if (level == 0)
1256 return root->leafsize;
1257 return root->nodesize;
1260 /* helper function to cast into the data area of the leaf. */
1261 #define btrfs_item_ptr(leaf, slot, type) \
1262 ((type *)(btrfs_leaf_data(leaf) + \
1263 btrfs_item_offset_nr(leaf, slot)))
1265 #define btrfs_item_ptr_offset(leaf, slot) \
1266 ((unsigned long)(btrfs_leaf_data(leaf) + \
1267 btrfs_item_offset_nr(leaf, slot)))
1269 /* extent-tree.c */
1270 u32 btrfs_count_snapshots_in_path(struct btrfs_root *root,
1271 struct btrfs_path *count_path,
1272 u64 first_extent);
1273 int btrfs_extent_post_op(struct btrfs_trans_handle *trans,
1274 struct btrfs_root *root);
1275 int btrfs_copy_pinned(struct btrfs_root *root, struct extent_io_tree *copy);
1276 struct btrfs_block_group_cache *btrfs_lookup_block_group(struct
1277 btrfs_fs_info *info,
1278 u64 bytenr);
1279 struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1280 struct btrfs_block_group_cache
1281 *hint, u64 search_start,
1282 int data, int owner);
1283 int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1284 struct btrfs_root *root, u64 owner_objectid);
1285 struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1286 struct btrfs_root *root, u32 size,
1287 u64 root_objectid,
1288 u64 hint, u64 empty_size);
1289 struct extent_buffer *__btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1290 struct btrfs_root *root,
1291 u32 blocksize,
1292 u64 root_objectid,
1293 u64 ref_generation,
1294 u64 first_objectid,
1295 int level,
1296 u64 hint,
1297 u64 empty_size);
1298 int btrfs_grow_extent_tree(struct btrfs_trans_handle *trans,
1299 struct btrfs_root *root, u64 new_size);
1300 int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
1301 int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1302 struct btrfs_root *root,
1303 struct btrfs_path *path, u64 bytenr,
1304 u64 root_objectid, u64 ref_generation,
1305 u64 owner, u64 owner_offset);
1306 int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1307 struct btrfs_root *root,
1308 u64 num_bytes, u64 root_objectid, u64 ref_generation,
1309 u64 owner, u64 owner_offset,
1310 u64 empty_size, u64 hint_byte,
1311 u64 search_end, struct btrfs_key *ins, int data);
1312 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1313 struct extent_buffer *buf);
1314 int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1315 *root, u64 bytenr, u64 num_bytes,
1316 u64 root_objectid, u64 ref_generation,
1317 u64 owner_objectid, u64 owner_offset, int pin);
1318 int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
1319 struct btrfs_root *root,
1320 struct extent_io_tree *unpin);
1321 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
1322 struct btrfs_root *root,
1323 u64 bytenr, u64 num_bytes,
1324 u64 root_objectid, u64 ref_generation,
1325 u64 owner, u64 owner_offset);
1326 int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1327 struct btrfs_root *root);
1328 int btrfs_free_block_groups(struct btrfs_fs_info *info);
1329 int btrfs_read_block_groups(struct btrfs_root *root);
1330 int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1331 struct btrfs_root *root, u64 bytes_used,
1332 u64 type, u64 chunk_objectid, u64 chunk_offset,
1333 u64 size);
1334 int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
1335 struct btrfs_root *root);
1336 u64 btrfs_hash_extent_ref(u64 root_objectid, u64 ref_generation,
1337 u64 owner, u64 owner_offset);
1338 int btrfs_update_block_group(struct btrfs_trans_handle *trans,
1339 struct btrfs_root *root, u64 bytenr, u64 num,
1340 int alloc, int mark_free);
1341 /* ctree.c */
1342 int btrfs_previous_item(struct btrfs_root *root,
1343 struct btrfs_path *path, u64 min_objectid,
1344 int type);
1345 int btrfs_comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2);
1346 int btrfs_cow_block(struct btrfs_trans_handle *trans,
1347 struct btrfs_root *root, struct extent_buffer *buf,
1348 struct extent_buffer *parent, int parent_slot,
1349 struct extent_buffer **cow_ret);
1350 int __btrfs_cow_block(struct btrfs_trans_handle *trans,
1351 struct btrfs_root *root,
1352 struct extent_buffer *buf,
1353 struct extent_buffer *parent, int parent_slot,
1354 struct extent_buffer **cow_ret,
1355 u64 search_start, u64 empty_size);
1356 int btrfs_copy_root(struct btrfs_trans_handle *trans,
1357 struct btrfs_root *root,
1358 struct extent_buffer *buf,
1359 struct extent_buffer **cow_ret, u64 new_root_objectid);
1360 int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1361 *root, struct btrfs_path *path, u32 data_size);
1362 int btrfs_truncate_item(struct btrfs_trans_handle *trans,
1363 struct btrfs_root *root,
1364 struct btrfs_path *path,
1365 u32 new_size, int from_end);
1366 int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1367 *root, struct btrfs_key *key, struct btrfs_path *p, int
1368 ins_len, int cow);
1369 int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1370 struct btrfs_root *root, struct extent_buffer *parent,
1371 int start_slot, int cache_only, u64 *last_ret,
1372 struct btrfs_key *progress);
1373 void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1374 struct btrfs_path *btrfs_alloc_path(void);
1375 void btrfs_free_path(struct btrfs_path *p);
1376 void btrfs_init_path(struct btrfs_path *p);
1377 int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1378 struct btrfs_path *path, int slot, int nr);
1380 static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
1381 struct btrfs_root *root,
1382 struct btrfs_path *path)
1384 return btrfs_del_items(trans, root, path, path->slots[0], 1);
1387 int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root
1388 *root, struct btrfs_key *key, void *data, u32 data_size);
1389 int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
1390 struct btrfs_root *root,
1391 struct btrfs_path *path,
1392 struct btrfs_key *cpu_key, u32 *data_size, int nr);
1394 static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
1395 struct btrfs_root *root,
1396 struct btrfs_path *path,
1397 struct btrfs_key *key,
1398 u32 data_size)
1400 return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
1403 int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1404 int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);
1405 int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1406 int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1407 *root);
1410 /* root-item.c */
1411 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1412 struct btrfs_key *key);
1413 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
1414 *root, struct btrfs_key *key, struct btrfs_root_item
1415 *item);
1416 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
1417 *root, struct btrfs_key *key, struct btrfs_root_item
1418 *item);
1419 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, struct
1420 btrfs_root_item *item, struct btrfs_key *key);
1421 int btrfs_find_dead_roots(struct btrfs_root *root, u64 objectid,
1422 struct btrfs_root *latest_root);
1423 /* dir-item.c */
1424 int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
1425 *root, const char *name, int name_len, u64 dir,
1426 struct btrfs_key *location, u8 type);
1427 struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
1428 struct btrfs_root *root,
1429 struct btrfs_path *path, u64 dir,
1430 const char *name, int name_len,
1431 int mod);
1432 struct btrfs_dir_item *
1433 btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
1434 struct btrfs_root *root,
1435 struct btrfs_path *path, u64 dir,
1436 u64 objectid, const char *name, int name_len,
1437 int mod);
1438 struct btrfs_dir_item *btrfs_match_dir_item_name(struct btrfs_root *root,
1439 struct btrfs_path *path,
1440 const char *name, int name_len);
1441 int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
1442 struct btrfs_root *root,
1443 struct btrfs_path *path,
1444 struct btrfs_dir_item *di);
1445 int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
1446 struct btrfs_root *root, const char *name,
1447 u16 name_len, const void *data, u16 data_len,
1448 u64 dir);
1449 struct btrfs_dir_item *btrfs_lookup_xattr(struct btrfs_trans_handle *trans,
1450 struct btrfs_root *root,
1451 struct btrfs_path *path, u64 dir,
1452 const char *name, u16 name_len,
1453 int mod);
1454 /* inode-map.c */
1455 int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1456 struct btrfs_root *fs_root,
1457 u64 dirid, u64 *objectid);
1458 int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1460 /* inode-item.c */
1461 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
1462 struct btrfs_root *root,
1463 const char *name, int name_len,
1464 u64 inode_objectid, u64 ref_objectid);
1465 int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
1466 struct btrfs_root *root,
1467 const char *name, int name_len,
1468 u64 inode_objectid, u64 ref_objectid);
1469 int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1470 struct btrfs_root *root,
1471 struct btrfs_path *path, u64 objectid);
1472 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1473 *root, u64 objectid, struct btrfs_inode_item
1474 *inode_item);
1475 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1476 *root, struct btrfs_path *path,
1477 struct btrfs_key *location, int mod);
1479 /* file-item.c */
1480 int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
1481 struct btrfs_root *root,
1482 u64 objectid, u64 pos, u64 offset,
1483 u64 disk_num_bytes,
1484 u64 num_bytes);
1485 int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
1486 struct btrfs_root *root, u64 objectid,
1487 u64 offset, char *buffer, size_t size);
1488 int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
1489 struct btrfs_root *root,
1490 struct btrfs_path *path, u64 objectid,
1491 u64 bytenr, int mod);
1492 int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
1493 struct btrfs_root *root,
1494 struct btrfs_inode_item *inode,
1495 u64 objectid, u64 offset,
1496 char *data, size_t len);
1497 struct btrfs_csum_item *btrfs_lookup_csum(struct btrfs_trans_handle *trans,
1498 struct btrfs_root *root,
1499 struct btrfs_path *path,
1500 u64 objectid, u64 offset,
1501 int cow);
1502 int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
1503 struct btrfs_root *root, struct btrfs_path *path,
1504 u64 isize);
1505 #endif