aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/btrfs/ctree.h65
-rw-r--r--fs/btrfs/kerncompat.h29
2 files changed, 61 insertions, 33 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 60c21fe1566a..e1aaca66d590 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -24,19 +24,19 @@ struct key {
24/* 24/*
25 * every tree block (leaf or node) starts with this header. 25 * every tree block (leaf or node) starts with this header.
26 */ 26 */
27struct header { 27struct btrfs_header {
28 u64 fsid[2]; /* FS specific uuid */ 28 __le64 fsid[2]; /* FS specific uuid */
29 u64 blocknr; /* which block this node is supposed to live in */ 29 __le64 blocknr; /* which block this node is supposed to live in */
30 u64 parentid; /* objectid of the tree root */ 30 __le64 parentid; /* objectid of the tree root */
31 u32 csum; 31 __le32 csum;
32 u32 ham; 32 __le32 ham;
33 u16 nritems; 33 __le16 nritems;
34 u16 flags; 34 __le16 flags;
35 /* generation flags to be added */ 35 /* generation flags to be added */
36} __attribute__ ((__packed__)); 36} __attribute__ ((__packed__));
37 37
38#define MAX_LEVEL 8 38#define MAX_LEVEL 8
39#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \ 39#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \
40 (sizeof(struct key) + sizeof(u64))) 40 (sizeof(struct key) + sizeof(u64)))
41 41
42struct tree_buffer; 42struct tree_buffer;
@@ -100,12 +100,12 @@ struct item {
100 * The data is separate from the items to get the keys closer together 100 * The data is separate from the items to get the keys closer together
101 * during searches. 101 * during searches.
102 */ 102 */
103#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header)) 103#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct btrfs_header))
104struct leaf { 104struct leaf {
105 struct header header; 105 struct btrfs_header header;
106 union { 106 union {
107 struct item items[LEAF_DATA_SIZE/sizeof(struct item)]; 107 struct item items[LEAF_DATA_SIZE/sizeof(struct item)];
108 u8 data[CTREE_BLOCKSIZE-sizeof(struct header)]; 108 u8 data[CTREE_BLOCKSIZE-sizeof(struct btrfs_header)];
109 }; 109 };
110} __attribute__ ((__packed__)); 110} __attribute__ ((__packed__));
111 111
@@ -114,7 +114,7 @@ struct leaf {
114 * other blocks 114 * other blocks
115 */ 115 */
116struct node { 116struct node {
117 struct header header; 117 struct btrfs_header header;
118 struct key keys[NODEPTRS_PER_BLOCK]; 118 struct key keys[NODEPTRS_PER_BLOCK];
119 u64 blockptrs[NODEPTRS_PER_BLOCK]; 119 u64 blockptrs[NODEPTRS_PER_BLOCK];
120} __attribute__ ((__packed__)); 120} __attribute__ ((__packed__));
@@ -141,54 +141,55 @@ struct ctree_path {
141 int slots[MAX_LEVEL]; 141 int slots[MAX_LEVEL];
142}; 142};
143 143
144static inline u64 btrfs_header_blocknr(struct header *h) 144static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
145{ 145{
146 return h->blocknr; 146 return le64_to_cpu(h->blocknr);
147} 147}
148 148
149static inline void btrfs_set_header_blocknr(struct header *h, u64 blocknr) 149static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
150{ 150{
151 h->blocknr = blocknr; 151 h->blocknr = cpu_to_le64(blocknr);
152} 152}
153 153
154static inline u64 btrfs_header_parentid(struct header *h) 154static inline u64 btrfs_header_parentid(struct btrfs_header *h)
155{ 155{
156 return h->parentid; 156 return le64_to_cpu(h->parentid);
157} 157}
158 158
159static inline void btrfs_set_header_parentid(struct header *h, u64 parentid) 159static inline void btrfs_set_header_parentid(struct btrfs_header *h,
160 u64 parentid)
160{ 161{
161 h->parentid = parentid; 162 h->parentid = cpu_to_le64(parentid);
162} 163}
163 164
164static inline u32 btrfs_header_nritems(struct header *h) 165static inline u16 btrfs_header_nritems(struct btrfs_header *h)
165{ 166{
166 return h->nritems; 167 return le16_to_cpu(h->nritems);
167} 168}
168 169
169static inline void btrfs_set_header_nritems(struct header *h, u32 val) 170static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
170{ 171{
171 h->nritems = val; 172 h->nritems = cpu_to_le16(val);
172} 173}
173 174
174static inline u32 btrfs_header_flags(struct header *h) 175static inline u16 btrfs_header_flags(struct btrfs_header *h)
175{ 176{
176 return h->flags; 177 return le16_to_cpu(h->flags);
177} 178}
178 179
179static inline void btrfs_set_header_flags(struct header *h, u32 val) 180static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
180{ 181{
181 h->flags = val; 182 h->flags = cpu_to_le16(val);
182} 183}
183 184
184static inline int btrfs_header_level(struct header *h) 185static inline int btrfs_header_level(struct btrfs_header *h)
185{ 186{
186 return btrfs_header_flags(h) & (MAX_LEVEL - 1); 187 return btrfs_header_flags(h) & (MAX_LEVEL - 1);
187} 188}
188 189
189static inline void btrfs_set_header_level(struct header *h, int level) 190static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
190{ 191{
191 u32 flags; 192 u16 flags;
192 BUG_ON(level > MAX_LEVEL); 193 BUG_ON(level > MAX_LEVEL);
193 flags = btrfs_header_flags(h) & ~(MAX_LEVEL - 1); 194 flags = btrfs_header_flags(h) & ~(MAX_LEVEL - 1);
194 btrfs_set_header_flags(h, flags | level); 195 btrfs_set_header_flags(h, flags | level);
diff --git a/fs/btrfs/kerncompat.h b/fs/btrfs/kerncompat.h
index f5efc5f0fff0..54cf70eaa01f 100644
--- a/fs/btrfs/kerncompat.h
+++ b/fs/btrfs/kerncompat.h
@@ -9,10 +9,16 @@
9#define GFP_KERNEL 0 9#define GFP_KERNEL 0
10#define __read_mostly 10#define __read_mostly
11#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 11#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
12#define __force
13#define PAGE_SHIFT 12 12#define PAGE_SHIFT 12
14#define ULONG_MAX (~0UL) 13#define ULONG_MAX (~0UL)
15#define BUG() abort() 14#define BUG() abort()
15#ifdef __CHECKER__
16#define __force __attribute__((force))
17#define __bitwise__ __attribute__((bitwise))
18#else
19#define __force
20#define __bitwise__
21#endif
16 22
17typedef unsigned int u32; 23typedef unsigned int u32;
18typedef unsigned long long u64; 24typedef unsigned long long u64;
@@ -67,3 +73,24 @@ static inline void __clear_bit(int bit, unsigned long *map) {
67 73
68#define ENOMEM 5 74#define ENOMEM 5
69#define EEXIST 6 75#define EEXIST 6
76
77#define __CHECK_ENDIAN__
78#ifdef __CHECK_ENDIAN__
79#define __bitwise __bitwise__
80#else
81#define __bitwise
82#endif
83
84typedef u16 __bitwise __le16;
85typedef u16 __bitwise __be16;
86typedef u32 __bitwise __le32;
87typedef u32 __bitwise __be32;
88typedef u64 __bitwise __le64;
89typedef u64 __bitwise __be64;
90
91#define cpu_to_le64(x) ((__force __le64)(u64)(x))
92#define le64_to_cpu(x) ((__force u64)(__le64)(x))
93#define cpu_to_le32(x) ((__force __le32)(u32)(x))
94#define le32_to_cpu(x) ((__force u32)(__le32)(x))
95#define cpu_to_le16(x) ((__force __le16)(u16)(x))
96#define le16_to_cpu(x) ((__force u16)(__le16)(x))