diff options
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r-- | fs/btrfs/ctree.h | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 05c7707263f5..c61ad0f69be9 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -5,7 +5,6 @@ | |||
5 | #include "kerncompat.h" | 5 | #include "kerncompat.h" |
6 | 6 | ||
7 | #define BTRFS_MAGIC "_BtRfS_M" | 7 | #define BTRFS_MAGIC "_BtRfS_M" |
8 | #define BTRFS_BLOCKSIZE 1024 | ||
9 | 8 | ||
10 | #define BTRFS_ROOT_TREE_OBJECTID 1 | 9 | #define BTRFS_ROOT_TREE_OBJECTID 1 |
11 | #define BTRFS_EXTENT_TREE_OBJECTID 2 | 10 | #define BTRFS_EXTENT_TREE_OBJECTID 2 |
@@ -52,8 +51,11 @@ struct btrfs_header { | |||
52 | } __attribute__ ((__packed__)); | 51 | } __attribute__ ((__packed__)); |
53 | 52 | ||
54 | #define BTRFS_MAX_LEVEL 8 | 53 | #define BTRFS_MAX_LEVEL 8 |
55 | #define NODEPTRS_PER_BLOCK ((BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)) / \ | 54 | #define BTRFS_NODEPTRS_PER_BLOCK(r) (((r)->blocksize - \ |
56 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) | 55 | sizeof(struct btrfs_header)) / \ |
56 | (sizeof(struct btrfs_disk_key) + sizeof(u64))) | ||
57 | #define __BTRFS_LEAF_DATA_SIZE(bs) ((bs) - sizeof(struct btrfs_header)) | ||
58 | #define BTRFS_LEAF_DATA_SIZE(r) (__BTRFS_LEAF_DATA_SIZE(r->blocksize)) | ||
57 | 59 | ||
58 | struct btrfs_buffer; | 60 | struct btrfs_buffer; |
59 | 61 | ||
@@ -86,6 +88,7 @@ struct btrfs_root { | |||
86 | int ref_cows; | 88 | int ref_cows; |
87 | struct btrfs_root_item root_item; | 89 | struct btrfs_root_item root_item; |
88 | struct btrfs_key root_key; | 90 | struct btrfs_key root_key; |
91 | u32 blocksize; | ||
89 | }; | 92 | }; |
90 | 93 | ||
91 | /* | 94 | /* |
@@ -97,7 +100,7 @@ struct btrfs_super_block { | |||
97 | __le64 blocknr; /* this block number */ | 100 | __le64 blocknr; /* this block number */ |
98 | __le32 csum; | 101 | __le32 csum; |
99 | __le64 magic; | 102 | __le64 magic; |
100 | __le16 blocksize; | 103 | __le32 blocksize; |
101 | __le64 generation; | 104 | __le64 generation; |
102 | __le64 root; | 105 | __le64 root; |
103 | __le64 total_blocks; | 106 | __le64 total_blocks; |
@@ -111,7 +114,7 @@ struct btrfs_super_block { | |||
111 | */ | 114 | */ |
112 | struct btrfs_item { | 115 | struct btrfs_item { |
113 | struct btrfs_disk_key key; | 116 | struct btrfs_disk_key key; |
114 | __le16 offset; | 117 | __le32 offset; |
115 | __le16 size; | 118 | __le16 size; |
116 | } __attribute__ ((__packed__)); | 119 | } __attribute__ ((__packed__)); |
117 | 120 | ||
@@ -122,24 +125,23 @@ struct btrfs_item { | |||
122 | * The data is separate from the items to get the keys closer together | 125 | * The data is separate from the items to get the keys closer together |
123 | * during searches. | 126 | * during searches. |
124 | */ | 127 | */ |
125 | #define LEAF_DATA_SIZE (BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)) | ||
126 | struct btrfs_leaf { | 128 | struct btrfs_leaf { |
127 | struct btrfs_header header; | 129 | struct btrfs_header header; |
128 | union { | 130 | struct btrfs_item items[]; |
129 | struct btrfs_item items[LEAF_DATA_SIZE/ | ||
130 | sizeof(struct btrfs_item)]; | ||
131 | u8 data[BTRFS_BLOCKSIZE - sizeof(struct btrfs_header)]; | ||
132 | }; | ||
133 | } __attribute__ ((__packed__)); | 131 | } __attribute__ ((__packed__)); |
134 | 132 | ||
135 | /* | 133 | /* |
136 | * all non-leaf blocks are nodes, they hold only keys and pointers to | 134 | * all non-leaf blocks are nodes, they hold only keys and pointers to |
137 | * other blocks | 135 | * other blocks |
138 | */ | 136 | */ |
137 | struct btrfs_key_ptr { | ||
138 | struct btrfs_disk_key key; | ||
139 | __le64 blockptr; | ||
140 | } __attribute__ ((__packed__)); | ||
141 | |||
139 | struct btrfs_node { | 142 | struct btrfs_node { |
140 | struct btrfs_header header; | 143 | struct btrfs_header header; |
141 | struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK]; | 144 | struct btrfs_key_ptr ptrs[]; |
142 | __le64 blockptrs[NODEPTRS_PER_BLOCK]; | ||
143 | } __attribute__ ((__packed__)); | 145 | } __attribute__ ((__packed__)); |
144 | 146 | ||
145 | /* | 147 | /* |
@@ -186,28 +188,28 @@ static inline void btrfs_set_extent_refs(struct btrfs_extent_item *ei, u32 val) | |||
186 | 188 | ||
187 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) | 189 | static inline u64 btrfs_node_blockptr(struct btrfs_node *n, int nr) |
188 | { | 190 | { |
189 | return le64_to_cpu(n->blockptrs[nr]); | 191 | return le64_to_cpu(n->ptrs[nr].blockptr); |
190 | } | 192 | } |
191 | 193 | ||
192 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, | 194 | static inline void btrfs_set_node_blockptr(struct btrfs_node *n, int nr, |
193 | u64 val) | 195 | u64 val) |
194 | { | 196 | { |
195 | n->blockptrs[nr] = cpu_to_le64(val); | 197 | n->ptrs[nr].blockptr = cpu_to_le64(val); |
196 | } | 198 | } |
197 | 199 | ||
198 | static inline u16 btrfs_item_offset(struct btrfs_item *item) | 200 | static inline u32 btrfs_item_offset(struct btrfs_item *item) |
199 | { | 201 | { |
200 | return le16_to_cpu(item->offset); | 202 | return le32_to_cpu(item->offset); |
201 | } | 203 | } |
202 | 204 | ||
203 | static inline void btrfs_set_item_offset(struct btrfs_item *item, u16 val) | 205 | static inline void btrfs_set_item_offset(struct btrfs_item *item, u32 val) |
204 | { | 206 | { |
205 | item->offset = cpu_to_le16(val); | 207 | item->offset = cpu_to_le32(val); |
206 | } | 208 | } |
207 | 209 | ||
208 | static inline u16 btrfs_item_end(struct btrfs_item *item) | 210 | static inline u32 btrfs_item_end(struct btrfs_item *item) |
209 | { | 211 | { |
210 | return le16_to_cpu(item->offset) + le16_to_cpu(item->size); | 212 | return le32_to_cpu(item->offset) + le16_to_cpu(item->size); |
211 | } | 213 | } |
212 | 214 | ||
213 | static inline u16 btrfs_item_size(struct btrfs_item *item) | 215 | static inline u16 btrfs_item_size(struct btrfs_item *item) |
@@ -390,20 +392,26 @@ static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s, | |||
390 | s->blocks_used = cpu_to_le64(val); | 392 | s->blocks_used = cpu_to_le64(val); |
391 | } | 393 | } |
392 | 394 | ||
393 | static inline u16 btrfs_super_blocksize(struct btrfs_super_block *s) | 395 | static inline u32 btrfs_super_blocksize(struct btrfs_super_block *s) |
394 | { | 396 | { |
395 | return le16_to_cpu(s->blocksize); | 397 | return le32_to_cpu(s->blocksize); |
396 | } | 398 | } |
397 | 399 | ||
398 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, | 400 | static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s, |
399 | u16 val) | 401 | u32 val) |
402 | { | ||
403 | s->blocksize = cpu_to_le32(val); | ||
404 | } | ||
405 | |||
406 | static inline u8 *btrfs_leaf_data(struct btrfs_leaf *l) | ||
400 | { | 407 | { |
401 | s->blocksize = cpu_to_le16(val); | 408 | return (u8 *)l->items; |
402 | } | 409 | } |
403 | 410 | ||
404 | /* helper function to cast into the data area of the leaf. */ | 411 | /* helper function to cast into the data area of the leaf. */ |
405 | #define btrfs_item_ptr(leaf, slot, type) \ | 412 | #define btrfs_item_ptr(leaf, slot, type) \ |
406 | ((type *)((leaf)->data + btrfs_item_offset((leaf)->items + (slot)))) | 413 | ((type *)(btrfs_leaf_data(leaf) + \ |
414 | btrfs_item_offset((leaf)->items + (slot)))) | ||
407 | 415 | ||
408 | struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root); | 416 | struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root); |
409 | int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf); | 417 | int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf); |
@@ -416,7 +424,7 @@ int btrfs_del_item(struct btrfs_root *root, struct btrfs_path *path); | |||
416 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key, | 424 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *key, |
417 | void *data, int data_size); | 425 | void *data, int data_size); |
418 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); | 426 | int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path); |
419 | int btrfs_leaf_free_space(struct btrfs_leaf *leaf); | 427 | int btrfs_leaf_free_space(struct btrfs_root *root, struct btrfs_leaf *leaf); |
420 | int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); | 428 | int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); |
421 | int btrfs_finish_extent_commit(struct btrfs_root *root); | 429 | int btrfs_finish_extent_commit(struct btrfs_root *root); |
422 | int btrfs_del_root(struct btrfs_root *root, struct btrfs_key *key); | 430 | int btrfs_del_root(struct btrfs_root *root, struct btrfs_key *key); |