diff options
-rw-r--r-- | fs/btrfs/ctree.h | 65 | ||||
-rw-r--r-- | fs/btrfs/kerncompat.h | 29 |
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 | */ |
27 | struct header { | 27 | struct 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 | ||
42 | struct tree_buffer; | 42 | struct 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)) |
104 | struct leaf { | 104 | struct 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 | */ |
116 | struct node { | 116 | struct 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 | ||
144 | static inline u64 btrfs_header_blocknr(struct header *h) | 144 | static 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 | ||
149 | static inline void btrfs_set_header_blocknr(struct header *h, u64 blocknr) | 149 | static 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 | ||
154 | static inline u64 btrfs_header_parentid(struct header *h) | 154 | static 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 | ||
159 | static inline void btrfs_set_header_parentid(struct header *h, u64 parentid) | 159 | static 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 | ||
164 | static inline u32 btrfs_header_nritems(struct header *h) | 165 | static 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 | ||
169 | static inline void btrfs_set_header_nritems(struct header *h, u32 val) | 170 | static 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 | ||
174 | static inline u32 btrfs_header_flags(struct header *h) | 175 | static 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 | ||
179 | static inline void btrfs_set_header_flags(struct header *h, u32 val) | 180 | static 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 | ||
184 | static inline int btrfs_header_level(struct header *h) | 185 | static 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 | ||
189 | static inline void btrfs_set_header_level(struct header *h, int level) | 190 | static 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 | ||
17 | typedef unsigned int u32; | 23 | typedef unsigned int u32; |
18 | typedef unsigned long long u64; | 24 | typedef 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 | |||
84 | typedef u16 __bitwise __le16; | ||
85 | typedef u16 __bitwise __be16; | ||
86 | typedef u32 __bitwise __le32; | ||
87 | typedef u32 __bitwise __be32; | ||
88 | typedef u64 __bitwise __le64; | ||
89 | typedef 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)) | ||