summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-12 12:29:44 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-12 12:29:44 -0400
commitce3b109650062fe94c900f4b153835f2f3b600cc (patch)
tree3cdf3d07507783d08726d73447bc726d7562e338
parent8e17fab249e8541a57558c30e3b6ed8dc3ce0738 (diff)
Add sparse endian annotations to struct header
rename struct header to btrfs_header
-rw-r--r--ctree.h65
-rw-r--r--kerncompat.h29
2 files changed, 61 insertions, 33 deletions
diff --git a/ctree.h b/ctree.h
index 60c21fe1..e1aaca66 100644
--- a/ctree.h
+++ b/ctree.h
@@ -24,19 +24,19 @@ struct key {
/*
* every tree block (leaf or node) starts with this header.
*/
-struct header {
- u64 fsid[2]; /* FS specific uuid */
- u64 blocknr; /* which block this node is supposed to live in */
- u64 parentid; /* objectid of the tree root */
- u32 csum;
- u32 ham;
- u16 nritems;
- u16 flags;
+struct btrfs_header {
+ __le64 fsid[2]; /* FS specific uuid */
+ __le64 blocknr; /* which block this node is supposed to live in */
+ __le64 parentid; /* objectid of the tree root */
+ __le32 csum;
+ __le32 ham;
+ __le16 nritems;
+ __le16 flags;
/* generation flags to be added */
} __attribute__ ((__packed__));
#define MAX_LEVEL 8
-#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct header)) / \
+#define NODEPTRS_PER_BLOCK ((CTREE_BLOCKSIZE - sizeof(struct btrfs_header)) / \
(sizeof(struct key) + sizeof(u64)))
struct tree_buffer;
@@ -100,12 +100,12 @@ struct item {
* The data is separate from the items to get the keys closer together
* during searches.
*/
-#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct header))
+#define LEAF_DATA_SIZE (CTREE_BLOCKSIZE - sizeof(struct btrfs_header))
struct leaf {
- struct header header;
+ struct btrfs_header header;
union {
struct item items[LEAF_DATA_SIZE/sizeof(struct item)];
- u8 data[CTREE_BLOCKSIZE-sizeof(struct header)];
+ u8 data[CTREE_BLOCKSIZE-sizeof(struct btrfs_header)];
};
} __attribute__ ((__packed__));
@@ -114,7 +114,7 @@ struct leaf {
* other blocks
*/
struct node {
- struct header header;
+ struct btrfs_header header;
struct key keys[NODEPTRS_PER_BLOCK];
u64 blockptrs[NODEPTRS_PER_BLOCK];
} __attribute__ ((__packed__));
@@ -141,54 +141,55 @@ struct ctree_path {
int slots[MAX_LEVEL];
};
-static inline u64 btrfs_header_blocknr(struct header *h)
+static inline u64 btrfs_header_blocknr(struct btrfs_header *h)
{
- return h->blocknr;
+ return le64_to_cpu(h->blocknr);
}
-static inline void btrfs_set_header_blocknr(struct header *h, u64 blocknr)
+static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
{
- h->blocknr = blocknr;
+ h->blocknr = cpu_to_le64(blocknr);
}
-static inline u64 btrfs_header_parentid(struct header *h)
+static inline u64 btrfs_header_parentid(struct btrfs_header *h)
{
- return h->parentid;
+ return le64_to_cpu(h->parentid);
}
-static inline void btrfs_set_header_parentid(struct header *h, u64 parentid)
+static inline void btrfs_set_header_parentid(struct btrfs_header *h,
+ u64 parentid)
{
- h->parentid = parentid;
+ h->parentid = cpu_to_le64(parentid);
}
-static inline u32 btrfs_header_nritems(struct header *h)
+static inline u16 btrfs_header_nritems(struct btrfs_header *h)
{
- return h->nritems;
+ return le16_to_cpu(h->nritems);
}
-static inline void btrfs_set_header_nritems(struct header *h, u32 val)
+static inline void btrfs_set_header_nritems(struct btrfs_header *h, u16 val)
{
- h->nritems = val;
+ h->nritems = cpu_to_le16(val);
}
-static inline u32 btrfs_header_flags(struct header *h)
+static inline u16 btrfs_header_flags(struct btrfs_header *h)
{
- return h->flags;
+ return le16_to_cpu(h->flags);
}
-static inline void btrfs_set_header_flags(struct header *h, u32 val)
+static inline void btrfs_set_header_flags(struct btrfs_header *h, u16 val)
{
- h->flags = val;
+ h->flags = cpu_to_le16(val);
}
-static inline int btrfs_header_level(struct header *h)
+static inline int btrfs_header_level(struct btrfs_header *h)
{
return btrfs_header_flags(h) & (MAX_LEVEL - 1);
}
-static inline void btrfs_set_header_level(struct header *h, int level)
+static inline void btrfs_set_header_level(struct btrfs_header *h, int level)
{
- u32 flags;
+ u16 flags;
BUG_ON(level > MAX_LEVEL);
flags = btrfs_header_flags(h) & ~(MAX_LEVEL - 1);
btrfs_set_header_flags(h, flags | level);
diff --git a/kerncompat.h b/kerncompat.h
index f5efc5f0..54cf70ea 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -9,10 +9,16 @@
#define GFP_KERNEL 0
#define __read_mostly
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define __force
#define PAGE_SHIFT 12
#define ULONG_MAX (~0UL)
#define BUG() abort()
+#ifdef __CHECKER__
+#define __force __attribute__((force))
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __force
+#define __bitwise__
+#endif
typedef unsigned int u32;
typedef unsigned long long u64;
@@ -67,3 +73,24 @@ static inline void __clear_bit(int bit, unsigned long *map) {
#define ENOMEM 5
#define EEXIST 6
+
+#define __CHECK_ENDIAN__
+#ifdef __CHECK_ENDIAN__
+#define __bitwise __bitwise__
+#else
+#define __bitwise
+#endif
+
+typedef u16 __bitwise __le16;
+typedef u16 __bitwise __be16;
+typedef u32 __bitwise __le32;
+typedef u32 __bitwise __be32;
+typedef u64 __bitwise __le64;
+typedef u64 __bitwise __be64;
+
+#define cpu_to_le64(x) ((__force __le64)(u64)(x))
+#define le64_to_cpu(x) ((__force u64)(__le64)(x))
+#define cpu_to_le32(x) ((__force __le32)(u32)(x))
+#define le32_to_cpu(x) ((__force u32)(__le32)(x))
+#define cpu_to_le16(x) ((__force __le16)(u16)(x))
+#define le16_to_cpu(x) ((__force u16)(__le16)(x))