aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-10-15 16:14:19 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:56 -0400
commit5f39d397dfbe140a14edecd4e73c34ce23c4f9ee (patch)
tree280561e4b68d573590557dd27df656869eed8023 /fs/btrfs/ctree.h
parent50b78c24d594e6985f36a9a8d8e2fb74e1664e90 (diff)
Btrfs: Create extent_buffer interface for large blocksizes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h849
1 files changed, 315 insertions, 534 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 800a3499cc3..c4b82980685 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -20,10 +20,10 @@
20#define __BTRFS__ 20#define __BTRFS__
21 21
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/buffer_head.h>
24#include <linux/workqueue.h> 23#include <linux/workqueue.h>
25#include <linux/completion.h> 24#include <linux/completion.h>
26#include "bit-radix.h" 25#include "bit-radix.h"
26#include "extent_map.h"
27 27
28struct btrfs_trans_handle; 28struct btrfs_trans_handle;
29struct btrfs_transaction; 29struct btrfs_transaction;
@@ -32,7 +32,7 @@ extern struct kmem_cache *btrfs_transaction_cachep;
32extern struct kmem_cache *btrfs_bit_radix_cachep; 32extern struct kmem_cache *btrfs_bit_radix_cachep;
33extern struct kmem_cache *btrfs_path_cachep; 33extern struct kmem_cache *btrfs_path_cachep;
34 34
35#define BTRFS_MAGIC "_BtRfS_M" 35#define BTRFS_MAGIC "_B2RfS_M"
36 36
37#define BTRFS_ROOT_TREE_OBJECTID 1ULL 37#define BTRFS_ROOT_TREE_OBJECTID 1ULL
38#define BTRFS_EXTENT_TREE_OBJECTID 2ULL 38#define BTRFS_EXTENT_TREE_OBJECTID 2ULL
@@ -78,41 +78,41 @@ extern struct kmem_cache *btrfs_path_cachep;
78 */ 78 */
79struct btrfs_disk_key { 79struct btrfs_disk_key {
80 __le64 objectid; 80 __le64 objectid;
81 __le32 flags; 81 u8 type;
82 __le64 offset; 82 __le64 offset;
83} __attribute__ ((__packed__)); 83} __attribute__ ((__packed__));
84 84
85struct btrfs_key { 85struct btrfs_key {
86 u64 objectid; 86 u64 objectid;
87 u32 flags; 87 u8 type;
88 u64 offset; 88 u64 offset;
89} __attribute__ ((__packed__)); 89} __attribute__ ((__packed__));
90 90
91#define BTRFS_FSID_SIZE 16
91/* 92/*
92 * every tree block (leaf or node) starts with this header. 93 * every tree block (leaf or node) starts with this header.
93 */ 94 */
94struct btrfs_header { 95struct btrfs_header {
95 u8 csum[BTRFS_CSUM_SIZE]; 96 u8 csum[BTRFS_CSUM_SIZE];
96 u8 fsid[16]; /* FS specific uuid */ 97 u8 fsid[BTRFS_FSID_SIZE]; /* FS specific uuid */
97 __le64 blocknr; /* which block this node is supposed to live in */ 98 __le64 blocknr; /* which block this node is supposed to live in */
98 __le64 generation; 99 __le64 generation;
99 __le64 owner; 100 __le64 owner;
100 __le16 nritems; 101 __le32 nritems;
101 __le16 flags; 102 __le16 flags;
102 u8 level; 103 u8 level;
103} __attribute__ ((__packed__)); 104} __attribute__ ((__packed__));
104 105
105#define BTRFS_MAX_LEVEL 8 106#define BTRFS_MAX_LEVEL 8
106#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ 107#define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->nodesize - \
107 sizeof(struct btrfs_header)) / \ 108 sizeof(struct btrfs_header)) / \
108 (sizeof(struct btrfs_disk_key) + sizeof(u64))) 109 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
109#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) 110#define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header))
110#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) 111#define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->leafsize))
111#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \ 112#define BTRFS_MAX_INLINE_DATA_SIZE(r) (BTRFS_LEAF_DATA_SIZE(r) - \
112 sizeof(struct btrfs_item) - \ 113 sizeof(struct btrfs_item) - \
113 sizeof(struct btrfs_file_extent_item)) 114 sizeof(struct btrfs_file_extent_item))
114 115
115struct buffer_head;
116/* 116/*
117 * the super block basically lists the main trees of the FS 117 * the super block basically lists the main trees of the FS
118 * it currently lacks any block count etc etc 118 * it currently lacks any block count etc etc
@@ -128,7 +128,9 @@ struct btrfs_super_block {
128 __le64 total_blocks; 128 __le64 total_blocks;
129 __le64 blocks_used; 129 __le64 blocks_used;
130 __le64 root_dir_objectid; 130 __le64 root_dir_objectid;
131 __le32 blocksize; 131 __le32 sectorsize;
132 __le32 nodesize;
133 __le32 leafsize;
132} __attribute__ ((__packed__)); 134} __attribute__ ((__packed__));
133 135
134/* 136/*
@@ -138,7 +140,7 @@ struct btrfs_super_block {
138struct btrfs_item { 140struct btrfs_item {
139 struct btrfs_disk_key key; 141 struct btrfs_disk_key key;
140 __le32 offset; 142 __le32 offset;
141 __le16 size; 143 __le32 size;
142} __attribute__ ((__packed__)); 144} __attribute__ ((__packed__));
143 145
144/* 146/*
@@ -176,7 +178,7 @@ struct btrfs_node {
176 * used while walking the tree. 178 * used while walking the tree.
177 */ 179 */
178struct btrfs_path { 180struct btrfs_path {
179 struct buffer_head *nodes[BTRFS_MAX_LEVEL]; 181 struct extent_buffer *nodes[BTRFS_MAX_LEVEL];
180 int slots[BTRFS_MAX_LEVEL]; 182 int slots[BTRFS_MAX_LEVEL];
181 int reada; 183 int reada;
182 int lowest_level; 184 int lowest_level;
@@ -292,6 +294,7 @@ struct btrfs_block_group_cache {
292}; 294};
293 295
294struct btrfs_fs_info { 296struct btrfs_fs_info {
297 u8 fsid[BTRFS_FSID_SIZE];
295 struct btrfs_root *extent_root; 298 struct btrfs_root *extent_root;
296 struct btrfs_root *tree_root; 299 struct btrfs_root *tree_root;
297 struct radix_tree_root fs_roots_radix; 300 struct radix_tree_root fs_roots_radix;
@@ -304,9 +307,8 @@ struct btrfs_fs_info {
304 u64 generation; 307 u64 generation;
305 u64 last_trans_committed; 308 u64 last_trans_committed;
306 struct btrfs_transaction *running_transaction; 309 struct btrfs_transaction *running_transaction;
307 struct btrfs_super_block *disk_super;
308 struct btrfs_super_block super_copy; 310 struct btrfs_super_block super_copy;
309 struct buffer_head *sb_buffer; 311 struct extent_buffer *sb_buffer;
310 struct super_block *sb; 312 struct super_block *sb;
311 struct inode *btree_inode; 313 struct inode *btree_inode;
312 struct mutex trans_mutex; 314 struct mutex trans_mutex;
@@ -325,8 +327,8 @@ struct btrfs_fs_info {
325 * and for the extent tree extent_root root. 327 * and for the extent tree extent_root root.
326 */ 328 */
327struct btrfs_root { 329struct btrfs_root {
328 struct buffer_head *node; 330 struct extent_buffer *node;
329 struct buffer_head *commit_root; 331 struct extent_buffer *commit_root;
330 struct btrfs_root_item root_item; 332 struct btrfs_root_item root_item;
331 struct btrfs_key root_key; 333 struct btrfs_key root_key;
332 struct btrfs_fs_info *fs_info; 334 struct btrfs_fs_info *fs_info;
@@ -336,7 +338,16 @@ struct btrfs_root {
336 struct rw_semaphore snap_sem; 338 struct rw_semaphore snap_sem;
337 u64 objectid; 339 u64 objectid;
338 u64 last_trans; 340 u64 last_trans;
339 u32 blocksize; 341
342 /* data allocations are done in sectorsize units */
343 u32 sectorsize;
344
345 /* node allocations are done in nodesize units */
346 u32 nodesize;
347
348 /* leaf allocations are done in leafsize units */
349 u32 leafsize;
350
340 u32 type; 351 u32 type;
341 u64 highest_inode; 352 u64 highest_inode;
342 u64 last_inode_alloc; 353 u64 last_inode_alloc;
@@ -347,12 +358,6 @@ struct btrfs_root {
347 char *name; 358 char *name;
348}; 359};
349 360
350/* the lower bits in the key flags defines the item type */
351#define BTRFS_KEY_TYPE_MAX 256
352#define BTRFS_KEY_TYPE_SHIFT 24
353#define BTRFS_KEY_TYPE_MASK (((u32)BTRFS_KEY_TYPE_MAX - 1) << \
354 BTRFS_KEY_TYPE_SHIFT)
355
356/* 361/*
357 * inode items have the data typically returned from stat and store other 362 * inode items have the data typically returned from stat and store other
358 * info about object characteristics. There is one for every file and dir in 363 * info about object characteristics. There is one for every file and dir in
@@ -402,246 +407,253 @@ struct btrfs_root {
402 */ 407 */
403#define BTRFS_STRING_ITEM_KEY 253 408#define BTRFS_STRING_ITEM_KEY 253
404 409
410/* some macros to generate set/get funcs for the struct fields. This
411 * assumes there is a lefoo_to_cpu for every type, so lets make a simple
412 * one for u8:
413 */
414#define le8_to_cpu(v) (v)
415#define cpu_to_le8(v) (v)
416#define __le8 u8
417
418#define read_eb_member(eb, ptr, type, member, result) ( \
419 read_extent_buffer(eb, (char *)(result), \
420 ((unsigned long)(ptr)) + \
421 offsetof(type, member), \
422 sizeof(((type *)0)->member)))
423
424#define write_eb_member(eb, ptr, type, member, result) ( \
425 write_extent_buffer(eb, (char *)(result), \
426 ((unsigned long)(ptr)) + \
427 offsetof(type, member), \
428 sizeof(((type *)0)->member)))
429
430#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
431static inline u##bits btrfs_##name(struct extent_buffer *eb, \
432 type *s) \
433{ \
434 __le##bits res; \
435 read_eb_member(eb, s, type, member, &res); \
436 return le##bits##_to_cpu(res); \
437} \
438static inline void btrfs_set_##name(struct extent_buffer *eb, \
439 type *s, u##bits val) \
440{ \
441 val = cpu_to_le##bits(val); \
442 write_eb_member(eb, s, type, member, &val); \
443}
444
445#define BTRFS_SETGET_HEADER_FUNCS(name, type, member, bits) \
446static inline u##bits btrfs_##name(struct extent_buffer *eb) \
447{ \
448 __le##bits res; \
449 read_eb_member(eb, NULL, type, member, &res); \
450 return le##bits##_to_cpu(res); \
451} \
452static inline void btrfs_set_##name(struct extent_buffer *eb, \
453 u##bits val) \
454{ \
455 val = cpu_to_le##bits(val); \
456 write_eb_member(eb, NULL, type, member, &val); \
457}
405 458
406static inline u64 btrfs_block_group_used(struct btrfs_block_group_item *bi) 459#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
407{ 460static inline u##bits btrfs_##name(type *s) \
408 return le64_to_cpu(bi->used); 461{ \
409} 462 return le##bits##_to_cpu(s->member); \
410 463} \
411static inline void btrfs_set_block_group_used(struct 464static inline void btrfs_set_##name(type *s, u##bits val) \
412 btrfs_block_group_item *bi, 465{ \
413 u64 val) 466 s->member = cpu_to_le##bits(val); \
414{
415 bi->used = cpu_to_le64(val);
416}
417
418static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
419{
420 return le64_to_cpu(i->generation);
421}
422
423static inline void btrfs_set_inode_generation(struct btrfs_inode_item *i,
424 u64 val)
425{
426 i->generation = cpu_to_le64(val);
427}
428
429static inline u64 btrfs_inode_size(struct btrfs_inode_item *i)
430{
431 return le64_to_cpu(i->size);
432}
433
434static inline void btrfs_set_inode_size(struct btrfs_inode_item *i, u64 val)
435{
436 i->size = cpu_to_le64(val);
437}
438
439static inline u64 btrfs_inode_nblocks(struct btrfs_inode_item *i)
440{
441 return le64_to_cpu(i->nblocks);
442}
443
444static inline void btrfs_set_inode_nblocks(struct btrfs_inode_item *i, u64 val)
445{
446 i->nblocks = cpu_to_le64(val);
447}
448
449static inline u64 btrfs_inode_block_group(struct btrfs_inode_item *i)
450{
451 return le64_to_cpu(i->block_group);
452}
453
454static inline void btrfs_set_inode_block_group(struct btrfs_inode_item *i,
455 u64 val)
456{
457 i->block_group = cpu_to_le64(val);
458}
459
460static inline u32 btrfs_inode_nlink(struct btrfs_inode_item *i)
461{
462 return le32_to_cpu(i->nlink);
463}
464
465static inline void btrfs_set_inode_nlink(struct btrfs_inode_item *i, u32 val)
466{
467 i->nlink = cpu_to_le32(val);
468}
469
470static inline u32 btrfs_inode_uid(struct btrfs_inode_item *i)
471{
472 return le32_to_cpu(i->uid);
473}
474
475static inline void btrfs_set_inode_uid(struct btrfs_inode_item *i, u32 val)
476{
477 i->uid = cpu_to_le32(val);
478}
479
480static inline u32 btrfs_inode_gid(struct btrfs_inode_item *i)
481{
482 return le32_to_cpu(i->gid);
483}
484
485static inline void btrfs_set_inode_gid(struct btrfs_inode_item *i, u32 val)
486{
487 i->gid = cpu_to_le32(val);
488}
489
490static inline u32 btrfs_inode_mode(struct btrfs_inode_item *i)
491{
492 return le32_to_cpu(i->mode);
493}
494
495static inline void btrfs_set_inode_mode(struct btrfs_inode_item *i, u32 val)
496{
497 i->mode = cpu_to_le32(val);
498} 467}
499 468
500static inline u32 btrfs_inode_rdev(struct btrfs_inode_item *i) 469/* struct btrfs_block_group_item */
501{ 470BTRFS_SETGET_STACK_FUNCS(block_group_used, struct btrfs_block_group_item,
502 return le32_to_cpu(i->rdev); 471 used, 64);
503} 472BTRFS_SETGET_FUNCS(disk_block_group_used, struct btrfs_block_group_item,
473 used, 64);
504 474
505static inline void btrfs_set_inode_rdev(struct btrfs_inode_item *i, u32 val) 475/* struct btrfs_inode_item */
506{ 476BTRFS_SETGET_FUNCS(inode_generation, struct btrfs_inode_item, generation, 64);
507 i->rdev = cpu_to_le32(val); 477BTRFS_SETGET_FUNCS(inode_size, struct btrfs_inode_item, size, 64);
508} 478BTRFS_SETGET_FUNCS(inode_nblocks, struct btrfs_inode_item, nblocks, 64);
479BTRFS_SETGET_FUNCS(inode_block_group, struct btrfs_inode_item, block_group, 64);
480BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
481BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
482BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
483BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
484BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 32);
485BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 16);
486BTRFS_SETGET_FUNCS(inode_compat_flags, struct btrfs_inode_item,
487 compat_flags, 16);
509 488
510static inline u16 btrfs_inode_flags(struct btrfs_inode_item *i) 489static inline struct btrfs_inode_timespec *
490btrfs_inode_atime(struct btrfs_inode_item *inode_item)
511{ 491{
512 return le16_to_cpu(i->flags); 492 unsigned long ptr = (unsigned long)inode_item;
493 ptr += offsetof(struct btrfs_inode_item, atime);
494 return (struct btrfs_inode_timespec *)ptr;
513} 495}
514 496
515static inline void btrfs_set_inode_flags(struct btrfs_inode_item *i, u16 val) 497static inline struct btrfs_inode_timespec *
498btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
516{ 499{
517 i->flags = cpu_to_le16(val); 500 unsigned long ptr = (unsigned long)inode_item;
501 ptr += offsetof(struct btrfs_inode_item, mtime);
502 return (struct btrfs_inode_timespec *)ptr;
518} 503}
519 504
520static inline u16 btrfs_inode_compat_flags(struct btrfs_inode_item *i) 505static inline struct btrfs_inode_timespec *
506btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
521{ 507{
522 return le16_to_cpu(i->compat_flags); 508 unsigned long ptr = (unsigned long)inode_item;
509 ptr += offsetof(struct btrfs_inode_item, ctime);
510 return (struct btrfs_inode_timespec *)ptr;
523} 511}
524 512
525static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i, 513static inline struct btrfs_inode_timespec *
526 u16 val) 514btrfs_inode_otime(struct btrfs_inode_item *inode_item)
527{ 515{
528 i->compat_flags = cpu_to_le16(val); 516 unsigned long ptr = (unsigned long)inode_item;
517 ptr += offsetof(struct btrfs_inode_item, otime);
518 return (struct btrfs_inode_timespec *)ptr;
529} 519}
530 520
531static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts) 521BTRFS_SETGET_FUNCS(timespec_sec, struct btrfs_inode_timespec, sec, 64);
532{ 522BTRFS_SETGET_FUNCS(timespec_nsec, struct btrfs_inode_timespec, nsec, 32);
533 return le64_to_cpu(ts->sec);
534}
535 523
536static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts, 524/* struct btrfs_extent_item */
537 u64 val) 525BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32);
538{ 526BTRFS_SETGET_FUNCS(extent_owner, struct btrfs_extent_item, owner, 32);
539 ts->sec = cpu_to_le64(val);
540}
541 527
542static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts) 528BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item,
543{ 529 refs, 32);
544 return le32_to_cpu(ts->nsec); 530BTRFS_SETGET_STACK_FUNCS(stack_extent_owner, struct btrfs_extent_item,
545} 531 owner, 32);
546 532
547static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts, 533/* struct btrfs_node */
548 u32 val) 534BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
549{
550 ts->nsec = cpu_to_le32(val);
551}
552 535
553static inline u32 btrfs_extent_refs(struct btrfs_extent_item *ei) 536static inline u64 btrfs_node_blockptr(struct extent_buffer *eb, int nr)
554{ 537{
555 return le32_to_cpu(ei->refs); 538 unsigned long ptr;
539 ptr = offsetof(struct btrfs_node, ptrs) +
540 sizeof(struct btrfs_key_ptr) * nr;
541 return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
556} 542}
557 543
558static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) 544static inline void btrfs_set_node_blockptr(struct extent_buffer *eb,
545 int nr, u64 val)
559{ 546{
560 ei->refs = cpu_to_le32(val); 547 unsigned long ptr;
548 ptr = offsetof(struct btrfs_node, ptrs) +
549 sizeof(struct btrfs_key_ptr) * nr;
550 btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
561} 551}
562 552
563static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) 553static unsigned long btrfs_node_key_ptr_offset(int nr)
564{ 554{
565 return le64_to_cpu(ei->owner); 555 return offsetof(struct btrfs_node, ptrs) +
556 sizeof(struct btrfs_key_ptr) * nr;
566} 557}
567 558
568static inline void btrfs_set_extent_owner(struct btrfs_extent_item *ei, u64 val) 559static void btrfs_node_key(struct extent_buffer *eb,
560 struct btrfs_disk_key *disk_key, int nr)
569{ 561{
570 ei->owner = cpu_to_le64(val); 562 unsigned long ptr;
563 ptr = btrfs_node_key_ptr_offset(nr);
564 read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
565 struct btrfs_key_ptr, key, disk_key);
571} 566}
572 567static inline void btrfs_set_node_key(struct extent_buffer *eb,
573static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) 568 struct btrfs_disk_key *disk_key, int nr)
574{ 569{
575 return le64_to_cpu(n->ptrs[nr].blockptr); 570 unsigned long ptr;
571 ptr = btrfs_node_key_ptr_offset(nr);
572 write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
573 struct btrfs_key_ptr, key, disk_key);
576} 574}
577 575
576/* struct btrfs_item */
577BTRFS_SETGET_FUNCS(item_offset, struct btrfs_item, offset, 32);
578BTRFS_SETGET_FUNCS(item_size, struct btrfs_item, size, 32);
578 579
579static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, 580static inline unsigned long btrfs_item_nr_offset(int nr)
580 u64 val)
581{ 581{
582 n->ptrs[nr].blockptr = cpu_to_le64(val); 582 return offsetof(struct btrfs_leaf, items) +
583 sizeof(struct btrfs_item) * nr;
583} 584}
584 585
585static inline u32 btrfs_item_offset(struct btrfs_item *item) 586static inline struct btrfs_item *btrfs_item_nr(struct extent_buffer *eb,
587 int nr)
586{ 588{
587 return le32_to_cpu(item->offset); 589 return (struct btrfs_item *)btrfs_item_nr_offset(nr);
588} 590}
589 591
590static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val) 592static inline u32 btrfs_item_end(struct extent_buffer *eb,
593 struct btrfs_item *item)
591{ 594{
592 item->offset = cpu_to_le32(val); 595 return btrfs_item_offset(eb, item) + btrfs_item_size(eb, item);
593} 596}
594 597
595static inline u32 btrfs_item_end(struct btrfs_item *item) 598static inline u32 btrfs_item_end_nr(struct extent_buffer *eb, int nr)
596{ 599{
597 return le32_to_cpu(item->offset) + le16_to_cpu(item->size); 600 return btrfs_item_end(eb, btrfs_item_nr(eb, nr));
598} 601}
599 602
600static inline u16 btrfs_item_size(struct btrfs_item *item) 603static inline u32 btrfs_item_offset_nr(struct extent_buffer *eb, int nr)
601{ 604{
602 return le16_to_cpu(item->size); 605 return btrfs_item_offset(eb, btrfs_item_nr(eb, nr));
603} 606}
604 607
605static inline void btrfs_set_item_size(struct btrfs_item *item, u16 val) 608static inline u32 btrfs_item_size_nr(struct extent_buffer *eb, int nr)
606{ 609{
607 item->size = cpu_to_le16(val); 610 return btrfs_item_size(eb, btrfs_item_nr(eb, nr));
608} 611}
609 612
610static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d) 613static inline void btrfs_item_key(struct extent_buffer *eb,
614 struct btrfs_disk_key *disk_key, int nr)
611{ 615{
612 return le16_to_cpu(d->flags); 616 struct btrfs_item *item = btrfs_item_nr(eb, nr);
617 read_eb_member(eb, item, struct btrfs_item, key, disk_key);
613} 618}
614 619
615static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val) 620static inline void btrfs_set_item_key(struct extent_buffer *eb,
621 struct btrfs_disk_key *disk_key, int nr)
616{ 622{
617 d->flags = cpu_to_le16(val); 623 struct btrfs_item *item = btrfs_item_nr(eb, nr);
624 write_eb_member(eb, item, struct btrfs_item, key, disk_key);
618} 625}
619 626
620static inline u8 btrfs_dir_type(struct btrfs_dir_item *d) 627/* struct btrfs_dir_item */
621{ 628BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, flags, 16);
622 return d->type; 629BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
623} 630BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
624 631
625static inline void btrfs_set_dir_type(struct btrfs_dir_item *d, u8 val) 632static inline void btrfs_dir_item_key(struct extent_buffer *eb,
633 struct btrfs_dir_item *item,
634 struct btrfs_disk_key *key)
626{ 635{
627 d->type = val; 636 read_eb_member(eb, item, struct btrfs_dir_item, location, key);
628} 637}
629 638
630static inline u16 btrfs_dir_name_len(struct btrfs_dir_item *d) 639static inline void btrfs_set_dir_item_key(struct extent_buffer *eb,
640 struct btrfs_dir_item *item,
641 struct btrfs_disk_key *key)
631{ 642{
632 return le16_to_cpu(d->name_len); 643 write_eb_member(eb, item, struct btrfs_dir_item, location, key);
633} 644}
634 645
635static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val) 646/* struct btrfs_disk_key */
636{ 647BTRFS_SETGET_STACK_FUNCS(disk_key_objectid, struct btrfs_disk_key,
637 d->name_len = cpu_to_le16(val); 648 objectid, 64);
638} 649BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
650BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
639 651
640static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, 652static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
641 struct btrfs_disk_key *disk) 653 struct btrfs_disk_key *disk)
642{ 654{
643 cpu->offset = le64_to_cpu(disk->offset); 655 cpu->offset = le64_to_cpu(disk->offset);
644 cpu->flags = le32_to_cpu(disk->flags); 656 cpu->type = disk->type;
645 cpu->objectid = le64_to_cpu(disk->objectid); 657 cpu->objectid = le64_to_cpu(disk->objectid);
646} 658}
647 659
@@ -649,400 +661,167 @@ static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
649 struct btrfs_key *cpu) 661 struct btrfs_key *cpu)
650{ 662{
651 disk->offset = cpu_to_le64(cpu->offset); 663 disk->offset = cpu_to_le64(cpu->offset);
652 disk->flags = cpu_to_le32(cpu->flags); 664 disk->type = cpu->type;
653 disk->objectid = cpu_to_le64(cpu->objectid); 665 disk->objectid = cpu_to_le64(cpu->objectid);
654} 666}
655 667
656static inline u64 btrfs_disk_key_objectid(struct btrfs_disk_key *disk) 668static inline void btrfs_node_key_to_cpu(struct extent_buffer *eb,
657{ 669 struct btrfs_key *key, int nr)
658 return le64_to_cpu(disk->objectid);
659}
660
661static inline void btrfs_set_disk_key_objectid(struct btrfs_disk_key *disk,
662 u64 val)
663{
664 disk->objectid = cpu_to_le64(val);
665}
666
667static inline u64 btrfs_disk_key_offset(struct btrfs_disk_key *disk)
668{
669 return le64_to_cpu(disk->offset);
670}
671
672static inline void btrfs_set_disk_key_offset(struct btrfs_disk_key *disk,
673 u64 val)
674{
675 disk->offset = cpu_to_le64(val);
676}
677
678static inline u32 btrfs_disk_key_flags(struct btrfs_disk_key *disk)
679{
680 return le32_to_cpu(disk->flags);
681}
682
683static inline void btrfs_set_disk_key_flags(struct btrfs_disk_key *disk,
684 u32 val)
685{
686 disk->flags = cpu_to_le32(val);
687}
688
689static inline u32 btrfs_disk_key_type(struct btrfs_disk_key *key)
690{
691 return le32_to_cpu(key->flags) >> BTRFS_KEY_TYPE_SHIFT;
692}
693
694static inline void btrfs_set_disk_key_type(struct btrfs_disk_key *key,
695 u32 val)
696{
697 u32 flags = btrfs_disk_key_flags(key);
698 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
699 val = val << BTRFS_KEY_TYPE_SHIFT;
700 flags = (flags & ~BTRFS_KEY_TYPE_MASK) | val;
701 btrfs_set_disk_key_flags(key, flags);
702}
703
704static inline u32 btrfs_key_type(struct btrfs_key *key)
705{
706 return key->flags >> BTRFS_KEY_TYPE_SHIFT;
707}
708
709static inline void btrfs_set_key_type(struct btrfs_key *key, u32 val)
710{
711 BUG_ON(val >= BTRFS_KEY_TYPE_MAX);
712 val = val << BTRFS_KEY_TYPE_SHIFT;
713 key->flags = (key->flags & ~(BTRFS_KEY_TYPE_MASK)) | val;
714}
715
716static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
717{
718 return le64_to_cpu(h->blocknr);
719}
720
721static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
722{
723 h->blocknr = cpu_to_le64(blocknr);
724}
725
726static inline u64 btrfs_header_generation(struct btrfs_header *h)
727{ 670{
728 return le64_to_cpu(h->generation); 671 struct btrfs_disk_key disk_key;
672 btrfs_node_key(eb, &disk_key, nr);
673 btrfs_disk_key_to_cpu(key, &disk_key);
729} 674}
730 675
731static inline void btrfs_set_header_generation(struct btrfs_header *h, 676static inline void btrfs_item_key_to_cpu(struct extent_buffer *eb,
732 u64 val) 677 struct btrfs_key *key, int nr)
733{ 678{
734 h->generation = cpu_to_le64(val); 679 struct btrfs_disk_key disk_key;
680 btrfs_item_key(eb, &disk_key, nr);
681 btrfs_disk_key_to_cpu(key, &disk_key);
735} 682}
736 683
737static inline u64 btrfs_header_owner(struct btrfs_header *h) 684static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
685 struct btrfs_dir_item *item,
686 struct btrfs_key *key)
738{ 687{
739 return le64_to_cpu(h->owner); 688 struct btrfs_disk_key disk_key;
689 btrfs_dir_item_key(eb, item, &disk_key);
690 btrfs_disk_key_to_cpu(key, &disk_key);
740} 691}
741 692
742static inline void btrfs_set_header_owner(struct btrfs_header *h,
743 u64 val)
744{
745 h->owner = cpu_to_le64(val);
746}
747
748static inline u16 btrfs_header_nritems(struct btrfs_header *h)
749{
750 return le16_to_cpu(h->nritems);
751}
752
753static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
754{
755 h->nritems = cpu_to_le16(val);
756}
757
758static inline u16 btrfs_header_flags(struct btrfs_header *h)
759{
760 return le16_to_cpu(h->flags);
761}
762
763static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
764{
765 h->flags = cpu_to_le16(val);
766}
767
768static inline int btrfs_header_level(struct btrfs_header *h)
769{
770 return h->level;
771}
772
773static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
774{
775 BUG_ON(level > BTRFS_MAX_LEVEL);
776 h->level = level;
777}
778
779static inline int btrfs_is_leaf(struct btrfs_node *n)
780{
781 return (btrfs_header_level(&n->header) == 0);
782}
783
784static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
785{
786 return le64_to_cpu(item->blocknr);
787}
788
789static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
790{
791 item->blocknr = cpu_to_le64(val);
792}
793
794static inline u64 btrfs_root_dirid(struct btrfs_root_item *item)
795{
796 return le64_to_cpu(item->root_dirid);
797}
798
799static inline void btrfs_set_root_dirid(struct btrfs_root_item *item, u64 val)
800{
801 item->root_dirid = cpu_to_le64(val);
802}
803
804static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
805{
806 return le32_to_cpu(item->refs);
807}
808
809static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
810{
811 item->refs = cpu_to_le32(val);
812}
813
814static inline u32 btrfs_root_flags(struct btrfs_root_item *item)
815{
816 return le32_to_cpu(item->flags);
817}
818
819static inline void btrfs_set_root_flags(struct btrfs_root_item *item, u32 val)
820{
821 item->flags = cpu_to_le32(val);
822}
823
824static inline void btrfs_set_root_blocks_used(struct btrfs_root_item *item,
825 u64 val)
826{
827 item->blocks_used = cpu_to_le64(val);
828}
829
830static inline u64 btrfs_root_blocks_used(struct btrfs_root_item *item)
831{
832 return le64_to_cpu(item->blocks_used);
833}
834
835static inline void btrfs_set_root_block_limit(struct btrfs_root_item *item,
836 u64 val)
837{
838 item->block_limit = cpu_to_le64(val);
839}
840
841static inline u64 btrfs_root_block_limit(struct btrfs_root_item *item)
842{
843 return le64_to_cpu(item->block_limit);
844}
845 693
846static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s) 694static inline u8 btrfs_key_type(struct btrfs_key *key)
847{ 695{
848 return le64_to_cpu(s->blocknr); 696 return key->type;
849} 697}
850 698
851static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val) 699static inline void btrfs_set_key_type(struct btrfs_key *key, u8 val)
852{ 700{
853 s->blocknr = cpu_to_le64(val); 701 key->type = val;
854} 702}
855 703
856static inline u64 btrfs_super_generation(struct btrfs_super_block *s) 704/* struct btrfs_header */
857{ 705BTRFS_SETGET_HEADER_FUNCS(header_blocknr, struct btrfs_header, blocknr, 64);
858 return le64_to_cpu(s->generation); 706BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
859} 707 generation, 64);
708BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
709BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
710BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 16);
711BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
860 712
861static inline void btrfs_set_super_generation(struct btrfs_super_block *s, 713static inline u8 *btrfs_header_fsid(struct extent_buffer *eb)
862 u64 val)
863{ 714{
864 s->generation = cpu_to_le64(val); 715 unsigned long ptr = offsetof(struct btrfs_header, fsid);
716 return (u8 *)ptr;
865} 717}
866 718
867static inline u64 btrfs_super_root(struct btrfs_super_block *s) 719static inline u8 *btrfs_super_fsid(struct extent_buffer *eb)
868{ 720{
869 return le64_to_cpu(s->root); 721 unsigned long ptr = offsetof(struct btrfs_super_block, fsid);
722 return (u8 *)ptr;
870} 723}
871 724
872static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val) 725static inline u8 *btrfs_header_csum(struct extent_buffer *eb)
873{ 726{
874 s->root = cpu_to_le64(val); 727 unsigned long ptr = offsetof(struct btrfs_header, csum);
728 return (u8 *)ptr;
875} 729}
876 730
877static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s) 731static inline struct btrfs_node *btrfs_buffer_node(struct extent_buffer *eb)
878{ 732{
879 return le64_to_cpu(s->total_blocks); 733 return NULL;
880} 734}
881 735
882static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s, 736static inline struct btrfs_leaf *btrfs_buffer_leaf(struct extent_buffer *eb)
883 u64 val)
884{ 737{
885 s->total_blocks = cpu_to_le64(val); 738 return NULL;
886} 739}
887 740
888static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s) 741static inline struct btrfs_header *btrfs_buffer_header(struct extent_buffer *eb)
889{ 742{
890 return le64_to_cpu(s->blocks_used); 743 return NULL;
891} 744}
892 745
893static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, 746static inline int btrfs_is_leaf(struct extent_buffer *eb)
894 u64 val)
895{ 747{
896 s->blocks_used = cpu_to_le64(val); 748 return (btrfs_header_level(eb) == 0);
897} 749}
898 750
899static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) 751/* struct btrfs_root_item */
900{ 752BTRFS_SETGET_FUNCS(disk_root_refs, struct btrfs_root_item, refs, 32);
901 return le32_to_cpu(s->blocksize); 753BTRFS_SETGET_FUNCS(disk_root_blocknr, struct btrfs_root_item, blocknr, 64);
902}
903 754
904static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, 755BTRFS_SETGET_STACK_FUNCS(root_blocknr, struct btrfs_root_item, blocknr, 64);
905 u32 val) 756BTRFS_SETGET_STACK_FUNCS(root_dirid, struct btrfs_root_item, root_dirid, 64);
906{ 757BTRFS_SETGET_STACK_FUNCS(root_refs, struct btrfs_root_item, refs, 32);
907 s->blocksize = cpu_to_le32(val); 758BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32);
908} 759BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, blocks_used, 64);
760BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, block_limit, 64);
909 761
910static inline u64 btrfs_super_root_dir(struct btrfs_super_block *s) 762/* struct btrfs_super_block */
911{ 763BTRFS_SETGET_STACK_FUNCS(super_blocknr, struct btrfs_super_block, blocknr, 64);
912 return le64_to_cpu(s->root_dir_objectid); 764BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
913} 765 generation, 64);
766BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
767BTRFS_SETGET_STACK_FUNCS(super_total_blocks, struct btrfs_super_block,
768 total_blocks, 64);
769BTRFS_SETGET_STACK_FUNCS(super_blocks_used, struct btrfs_super_block,
770 blocks_used, 64);
771BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
772 sectorsize, 32);
773BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
774 nodesize, 32);
775BTRFS_SETGET_STACK_FUNCS(super_leafsize, struct btrfs_super_block,
776 leafsize, 32);
777BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
778 root_dir_objectid, 64);
914 779
915static inline void btrfs_set_super_root_dir(struct btrfs_super_block *s, u64 780static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)
916 val)
917{ 781{
918 s->root_dir_objectid = cpu_to_le64(val); 782 return offsetof(struct btrfs_leaf, items);
919} 783}
920 784
921static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) 785/* struct btrfs_file_extent_item */
922{ 786BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8);
923 return (u8 *)l->items;
924}
925 787
926static inline int btrfs_file_extent_type(struct btrfs_file_extent_item *e) 788static inline unsigned long btrfs_file_extent_inline_start(struct
927{
928 return e->type;
929}
930static inline void btrfs_set_file_extent_type(struct btrfs_file_extent_item *e,
931 u8 val)
932{
933 e->type = val;
934}
935
936static inline char *btrfs_file_extent_inline_start(struct
937 btrfs_file_extent_item *e) 789 btrfs_file_extent_item *e)
938{ 790{
939 return (char *)(&e->disk_blocknr); 791 unsigned long offset = (unsigned long)e;
792 offset += offsetof(struct btrfs_file_extent_item, disk_blocknr);
793 return offset;
940} 794}
941 795
942static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize) 796static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
943{ 797{
944 return (unsigned long)(&((struct 798 return offsetof(struct btrfs_file_extent_item, disk_blocknr) + datasize;
945 btrfs_file_extent_item *)NULL)->disk_blocknr) + datasize;
946}
947
948static inline u32 btrfs_file_extent_inline_len(struct btrfs_item *e)
949{
950 struct btrfs_file_extent_item *fe = NULL;
951 return btrfs_item_size(e) - (unsigned long)(&fe->disk_blocknr);
952}
953
954static inline u64 btrfs_file_extent_disk_blocknr(struct btrfs_file_extent_item
955 *e)
956{
957 return le64_to_cpu(e->disk_blocknr);
958} 799}
959 800
960static inline void btrfs_set_file_extent_disk_blocknr(struct 801static inline u32 btrfs_file_extent_inline_len(struct extent_buffer *eb,
961 btrfs_file_extent_item 802 struct btrfs_item *e)
962 *e, u64 val)
963{ 803{
964 e->disk_blocknr = cpu_to_le64(val); 804 unsigned long offset;
805 offset = offsetof(struct btrfs_file_extent_item, disk_blocknr);
806 return btrfs_item_size(eb, e) - offset;
965} 807}
966 808
967static inline u64 btrfs_file_extent_generation(struct btrfs_file_extent_item *e) 809BTRFS_SETGET_FUNCS(file_extent_disk_blocknr, struct btrfs_file_extent_item,
968{ 810 disk_blocknr, 64);
969 return le64_to_cpu(e->generation); 811BTRFS_SETGET_FUNCS(file_extent_generation, struct btrfs_file_extent_item,
970} 812 generation, 64);
971 813BTRFS_SETGET_FUNCS(file_extent_disk_num_blocks, struct btrfs_file_extent_item,
972static inline void btrfs_set_file_extent_generation(struct 814 disk_num_blocks, 64);
973 btrfs_file_extent_item *e, 815BTRFS_SETGET_FUNCS(file_extent_offset, struct btrfs_file_extent_item,
974 u64 val) 816 offset, 64);
975{ 817BTRFS_SETGET_FUNCS(file_extent_num_blocks, struct btrfs_file_extent_item,
976 e->generation = cpu_to_le64(val); 818 num_blocks, 64);
977}
978
979static inline u64 btrfs_file_extent_disk_num_blocks(struct
980 btrfs_file_extent_item *e)
981{
982 return le64_to_cpu(e->disk_num_blocks);
983}
984
985static inline void btrfs_set_file_extent_disk_num_blocks(struct
986 btrfs_file_extent_item
987 *e, u64 val)
988{
989 e->disk_num_blocks = cpu_to_le64(val);
990}
991
992static inline u64 btrfs_file_extent_offset(struct btrfs_file_extent_item *e)
993{
994 return le64_to_cpu(e->offset);
995}
996
997static inline void btrfs_set_file_extent_offset(struct btrfs_file_extent_item
998 *e, u64 val)
999{
1000 e->offset = cpu_to_le64(val);
1001}
1002
1003static inline u64 btrfs_file_extent_num_blocks(struct btrfs_file_extent_item
1004 *e)
1005{
1006 return le64_to_cpu(e->num_blocks);
1007}
1008
1009static inline void btrfs_set_file_extent_num_blocks(struct
1010 btrfs_file_extent_item *e,
1011 u64 val)
1012{
1013 e->num_blocks = cpu_to_le64(val);
1014}
1015 819
1016static inline struct btrfs_root *btrfs_sb(struct super_block *sb) 820static inline struct btrfs_root *btrfs_sb(struct super_block *sb)
1017{ 821{
1018 return sb->s_fs_info; 822 return sb->s_fs_info;
1019} 823}
1020 824
1021static inline void btrfs_check_bounds(void *vptr, size_t len,
1022 void *vcontainer, size_t container_len)
1023{
1024 char *ptr = vptr;
1025 char *container = vcontainer;
1026 WARN_ON(ptr < container);
1027 WARN_ON(ptr + len > container + container_len);
1028}
1029
1030static inline void btrfs_memcpy(struct btrfs_root *root,
1031 void *dst_block,
1032 void *dst, const void *src, size_t nr)
1033{
1034 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1035 memcpy(dst, src, nr);
1036}
1037
1038static inline void btrfs_memmove(struct btrfs_root *root,
1039 void *dst_block,
1040 void *dst, void *src, size_t nr)
1041{
1042 btrfs_check_bounds(dst, nr, dst_block, root->fs_info->sb->s_blocksize);
1043 memmove(dst, src, nr);
1044}
1045
1046static inline int btrfs_set_root_name(struct btrfs_root *root, 825static inline int btrfs_set_root_name(struct btrfs_root *root,
1047 const char *name, int len) 826 const char *name, int len)
1048{ 827{
@@ -1063,7 +842,11 @@ static inline int btrfs_set_root_name(struct btrfs_root *root,
1063/* helper function to cast into the data area of the leaf. */ 842/* helper function to cast into the data area of the leaf. */
1064#define btrfs_item_ptr(leaf, slot, type) \ 843#define btrfs_item_ptr(leaf, slot, type) \
1065 ((type *)(btrfs_leaf_data(leaf) + \ 844 ((type *)(btrfs_leaf_data(leaf) + \
1066 btrfs_item_offset((leaf)->items + (slot)))) 845 btrfs_item_offset_nr(leaf, slot)))
846
847#define btrfs_item_ptr_offset(leaf, slot) \
848 ((unsigned long)(btrfs_leaf_data(leaf) + \
849 btrfs_item_offset_nr(leaf, slot)))
1067 850
1068/* mount option defines and helpers */ 851/* mount option defines and helpers */
1069#define BTRFS_MOUNT_SUBVOL 0x000001 852#define BTRFS_MOUNT_SUBVOL 0x000001
@@ -1084,7 +867,7 @@ struct btrfs_block_group_cache *btrfs_find_block_group(struct btrfs_root *root,
1084 int data, int owner); 867 int data, int owner);
1085int btrfs_inc_root_ref(struct btrfs_trans_handle *trans, 868int btrfs_inc_root_ref(struct btrfs_trans_handle *trans,
1086 struct btrfs_root *root); 869 struct btrfs_root *root);
1087struct buffer_head *btrfs_alloc_free_block(struct btrfs_trans_handle *trans, 870struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1088 struct btrfs_root *root, u64 hint, 871 struct btrfs_root *root, u64 hint,
1089 u64 empty_size); 872 u64 empty_size);
1090int btrfs_alloc_extent(struct btrfs_trans_handle *trans, 873int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
@@ -1092,7 +875,7 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1092 u64 num_blocks, u64 empty_size, u64 search_start, 875 u64 num_blocks, u64 empty_size, u64 search_start,
1093 u64 search_end, struct btrfs_key *ins, int data); 876 u64 search_end, struct btrfs_key *ins, int data);
1094int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, 877int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
1095 struct buffer_head *buf); 878 struct extent_buffer *buf);
1096int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root 879int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1097 *root, u64 blocknr, u64 num_blocks, int pin); 880 *root, u64 blocknr, u64 num_blocks, int pin);
1098int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, 881int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans,
@@ -1106,10 +889,10 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
1106int btrfs_free_block_groups(struct btrfs_fs_info *info); 889int btrfs_free_block_groups(struct btrfs_fs_info *info);
1107int btrfs_read_block_groups(struct btrfs_root *root); 890int btrfs_read_block_groups(struct btrfs_root *root);
1108/* ctree.c */ 891/* ctree.c */
1109int btrfs_cow_block(struct btrfs_trans_handle *trans, struct btrfs_root 892int btrfs_cow_block(struct btrfs_trans_handle *trans,
1110 *root, struct buffer_head *buf, struct buffer_head 893 struct btrfs_root *root, struct extent_buffer *buf,
1111 *parent, int parent_slot, struct buffer_head 894 struct extent_buffer *parent, int parent_slot,
1112 **cow_ret); 895 struct extent_buffer **cow_ret);
1113int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root 896int btrfs_extend_item(struct btrfs_trans_handle *trans, struct btrfs_root
1114 *root, struct btrfs_path *path, u32 data_size); 897 *root, struct btrfs_path *path, u32 data_size);
1115int btrfs_truncate_item(struct btrfs_trans_handle *trans, 898int btrfs_truncate_item(struct btrfs_trans_handle *trans,
@@ -1120,7 +903,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root
1120 *root, struct btrfs_key *key, struct btrfs_path *p, int 903 *root, struct btrfs_key *key, struct btrfs_path *p, int
1121 ins_len, int cow); 904 ins_len, int cow);
1122int btrfs_realloc_node(struct btrfs_trans_handle *trans, 905int btrfs_realloc_node(struct btrfs_trans_handle *trans,
1123 struct btrfs_root *root, struct buffer_head *parent, 906 struct btrfs_root *root, struct extent_buffer *parent,
1124 int cache_only, u64 *last_ret); 907 int cache_only, u64 *last_ret);
1125void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p); 908void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p);
1126struct btrfs_path *btrfs_alloc_path(void); 909struct btrfs_path *btrfs_alloc_path(void);
@@ -1134,7 +917,7 @@ int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, struct btrfs_root
1134 *root, struct btrfs_path *path, struct btrfs_key 917 *root, struct btrfs_path *path, struct btrfs_key
1135 *cpu_key, u32 data_size); 918 *cpu_key, u32 data_size);
1136int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); 919int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
1137int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); 920int btrfs_leaf_free_space(struct btrfs_root *root, struct extent_buffer *leaf);
1138int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root 921int btrfs_drop_snapshot(struct btrfs_trans_handle *trans, struct btrfs_root
1139 *root); 922 *root);
1140/* root-item.c */ 923/* root-item.c */
@@ -1179,9 +962,9 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
1179int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid); 962int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
1180 963
1181/* inode-item.c */ 964/* inode-item.c */
1182int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root 965int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
1183 *root, u64 objectid, struct btrfs_inode_item 966 struct btrfs_root *root,
1184 *inode_item); 967 struct btrfs_path *path, u64 objectid);
1185int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root 968int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
1186 *root, struct btrfs_path *path, 969 *root, struct btrfs_path *path,
1187 struct btrfs_key *location, int mod); 970 struct btrfs_key *location, int mod);
@@ -1224,8 +1007,6 @@ struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
1224 struct btrfs_root *root); 1007 struct btrfs_root *root);
1225int btrfs_commit_write(struct file *file, struct page *page, 1008int btrfs_commit_write(struct file *file, struct page *page,
1226 unsigned from, unsigned to); 1009 unsigned from, unsigned to);
1227int btrfs_get_block(struct inode *inode, sector_t iblock,
1228 struct buffer_head *result, int create);
1229struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, 1010struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
1230 size_t page_offset, u64 start, u64 end, 1011 size_t page_offset, u64 start, u64 end,
1231 int create); 1012 int create);