aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-12 16:22:34 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-12 16:22:34 -0400
commite2fa7227cdf132d72e7410dd0679dc573a1c2618 (patch)
tree2f739ce2f7f7735c81a86c209290c050efa85ade /fs/btrfs/ctree.h
parentbb492bb0a5453222109a72859353728959c2539d (diff)
Btrfs: struct key endian fixes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h78
1 files changed, 70 insertions, 8 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index e1aaca66d590..58e03e90f23a 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2,6 +2,7 @@
2#define __CTREE__ 2#define __CTREE__
3 3
4#include "list.h" 4#include "list.h"
5#include "kerncompat.h"
5 6
6#define CTREE_BLOCKSIZE 1024 7#define CTREE_BLOCKSIZE 1024
7 8
@@ -14,8 +15,18 @@
14 * may point to extents. 15 * may point to extents.
15 * 16 *
16 * offset is the starting byte offset for this key in the stream. 17 * offset is the starting byte offset for this key in the stream.
18 *
19 * btrfs_disk_key is in disk byte order. struct btrfs_key is always
20 * in cpu native order. Otherwise they are identical and their sizes
21 * should be the same (ie both packed)
17 */ 22 */
18struct key { 23struct btrfs_disk_key {
24 __le64 objectid;
25 __le32 flags;
26 __le64 offset;
27} __attribute__ ((__packed__));
28
29struct btrfs_key {
19 u64 objectid; 30 u64 objectid;
20 u32 flags; 31 u32 flags;
21 u64 offset; 32 u64 offset;
@@ -37,7 +48,7 @@ struct btrfs_header {
37 48
38#define MAX_LEVEL 8 49#define MAX_LEVEL 8
39#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \ 50#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \
40 (sizeof(struct key) + sizeof(u64))) 51 (sizeof(struct btrfs_disk_key) + sizeof(u64)))
41 52
42struct tree_buffer; 53struct tree_buffer;
43 54
@@ -50,8 +61,8 @@ struct ctree_root {
50 struct tree_buffer *node; 61 struct tree_buffer *node;
51 struct tree_buffer *commit_root; 62 struct tree_buffer *commit_root;
52 struct ctree_root *extent_root; 63 struct ctree_root *extent_root;
53 struct key current_insert; 64 struct btrfs_key current_insert;
54 struct key last_insert; 65 struct btrfs_key last_insert;
55 int fp; 66 int fp;
56 struct radix_tree_root cache_radix; 67 struct radix_tree_root cache_radix;
57 struct radix_tree_root pinned_radix; 68 struct radix_tree_root pinned_radix;
@@ -88,7 +99,7 @@ struct ctree_super_block {
88 * the item in the leaf (relative to the start of the data area) 99 * the item in the leaf (relative to the start of the data area)
89 */ 100 */
90struct item { 101struct item {
91 struct key key; 102 struct btrfs_disk_key key;
92 u16 offset; 103 u16 offset;
93 u16 size; 104 u16 size;
94} __attribute__ ((__packed__)); 105} __attribute__ ((__packed__));
@@ -115,7 +126,7 @@ struct leaf {
115 */ 126 */
116struct node { 127struct node {
117 struct btrfs_header header; 128 struct btrfs_header header;
118 struct key keys[NODEPTRS_PER_BLOCK]; 129 struct btrfs_disk_key keys[NODEPTRS_PER_BLOCK];
119 u64 blockptrs[NODEPTRS_PER_BLOCK]; 130 u64 blockptrs[NODEPTRS_PER_BLOCK];
120} __attribute__ ((__packed__)); 131} __attribute__ ((__packed__));
121 132
@@ -141,6 +152,55 @@ struct ctree_path {
141 int slots[MAX_LEVEL]; 152 int slots[MAX_LEVEL];
142}; 153};
143 154
155static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
156 struct btrfs_disk_key *disk)
157{
158 cpu->offset = le64_to_cpu(disk->offset);
159 cpu->flags = le32_to_cpu(disk->flags);
160 cpu->objectid = le64_to_cpu(disk->objectid);
161}
162
163static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
164 struct btrfs_key *cpu)
165{
166 disk->offset = cpu_to_le64(cpu->offset);
167 disk->flags = cpu_to_le32(cpu->flags);
168 disk->objectid = cpu_to_le64(cpu->objectid);
169}
170
171static inline u64 btrfs_key_objectid(struct btrfs_disk_key *disk)
172{
173 return le64_to_cpu(disk->objectid);
174}
175
176static inline void btrfs_set_key_objectid(struct btrfs_disk_key *disk,
177 u64 val)
178{
179 disk->objectid = cpu_to_le64(val);
180}
181
182static inline u64 btrfs_key_offset(struct btrfs_disk_key *disk)
183{
184 return le64_to_cpu(disk->offset);
185}
186
187static inline void btrfs_set_key_offset(struct btrfs_disk_key *disk,
188 u64 val)
189{
190 disk->offset = cpu_to_le64(val);
191}
192
193static inline u32 btrfs_key_flags(struct btrfs_disk_key *disk)
194{
195 return le32_to_cpu(disk->flags);
196}
197
198static inline void btrfs_set_key_flags(struct btrfs_disk_key *disk,
199 u32 val)
200{
201 disk->flags = cpu_to_le32(val);
202}
203
144static inline u64 btrfs_header_blocknr(struct btrfs_header *h) 204static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
145{ 205{
146 return le64_to_cpu(h->blocknr); 206 return le64_to_cpu(h->blocknr);
@@ -203,11 +263,13 @@ static inline int btrfs_is_leaf(struct node *n)
203struct tree_buffer *alloc_free_block(struct ctree_root *root); 263struct tree_buffer *alloc_free_block(struct ctree_root *root);
204int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf); 264int btrfs_inc_ref(struct ctree_root *root, struct tree_buffer *buf);
205int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks); 265int free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks);
206int search_slot(struct ctree_root *root, struct key *key, struct ctree_path *p, int ins_len, int cow); 266int search_slot(struct ctree_root *root, struct btrfs_key *key,
267 struct ctree_path *p, int ins_len, int cow);
207void release_path(struct ctree_root *root, struct ctree_path *p); 268void release_path(struct ctree_root *root, struct ctree_path *p);
208void init_path(struct ctree_path *p); 269void init_path(struct ctree_path *p);
209int del_item(struct ctree_root *root, struct ctree_path *path); 270int del_item(struct ctree_root *root, struct ctree_path *path);
210int insert_item(struct ctree_root *root, struct key *key, void *data, int data_size); 271int insert_item(struct ctree_root *root, struct btrfs_key *key,
272 void *data, int data_size);
211int next_leaf(struct ctree_root *root, struct ctree_path *path); 273int next_leaf(struct ctree_root *root, struct ctree_path *path);
212int leaf_free_space(struct leaf *leaf); 274int leaf_free_space(struct leaf *leaf);
213int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap); 275int btrfs_drop_snapshot(struct ctree_root *root, struct tree_buffer *snap);