diff options
author | Jeff Mahoney <jeffm@suse.com> | 2013-09-17 13:28:53 -0400 |
---|---|---|
committer | Jeff Mahoney <jeffm@suse.com> | 2013-09-17 13:28:53 -0400 |
commit | 57eac8416ca75d459a606856a6e3e06d222e04f4 (patch) | |
tree | 238253bb2280243efc64854d815ae4b516806273 | |
parent | 19566d08786018414e789d24c5352e6e1e5e4067 (diff) | |
download | reiserfsprogs-57eac8416ca75d459a606856a6e3e06d222e04f4.tar.gz |
reiserfsprogs: add helpers for constant endian routines
Initializing structures with little endian values requires a const
value. This means that the endian routines that are macro blocks
cause build failures.
This patch introduces constant_ macros that don't involve an
assignment. These can only be used with constant values or
unexpected results may occur.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
-rw-r--r-- | include/swab.h | 73 | ||||
-rw-r--r-- | reiserfscore/reiserfslib.c | 5 | ||||
-rw-r--r-- | reiserfscore/stree.c | 9 |
3 files changed, 55 insertions, 32 deletions
diff --git a/include/swab.h b/include/swab.h index 58efa0d..fef3c55 100644 --- a/include/swab.h +++ b/include/swab.h @@ -9,36 +9,43 @@ #include <endian.h> #include <linux/types.h> -#define __swab16(x) \ -({ \ - __u16 __x = (x); \ - ((__u16)( \ - (((__u16)(__x) & (__u16)0x00ffU) << 8) | \ - (((__u16)(__x) & (__u16)0xff00U) >> 8) )); \ +#define __constant_swab16(x) ((__u16)( \ + (((__u16)(x) & (__u16)0x00ffU) << 8) | \ + (((__u16)(x) & (__u16)0xff00U) >> 8) )) + +#define __swab16(x) \ +({ \ + __u16 __x = (x); \ + __constant_swab16(__x); \ }) -#define __swab32(x) \ -({ \ - __u32 __x = (x); \ - ((__u32)( \ - (((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \ - (((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \ - (((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \ - (((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \ +#define __constant_swab32(x) ((__u32)( \ + (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \ + (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \ + (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \ + (((__u32)(x) & (__u32)0xff000000UL) >> 24))) + +#define __swab32(x) \ +({ \ + __u32 __x = (x); \ + __constant_swab32(__x); \ }) -#define __swab64(x) \ -({ \ - __u64 __x = (x); \ - ((__u64)( \ - (__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \ - (__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \ - (__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \ - (__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \ - (__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \ - (__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \ - (__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \ - (__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \ +#define __constant_swab64(x) ((__u64)( \ + (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \ + (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \ + (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \ + (((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \ + (((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \ + (((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \ + (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \ + (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56))) + + +#define __swab64(x) \ +({ \ + __u64 __x = (x); \ + __constant_swab64(__x); \ }) #ifndef le32_to_cpu @@ -56,6 +63,13 @@ #define cpu_to_le16(x) ((__force __le16)(__u16)(x)) #define le16_to_cpu(x) ((__force __u16)(__le16)(x)) +#define constant_cpu_to_le64(x) ((__force __le64)(__u64)(x)) +#define constant_le64_to_cpu(x) ((__force __u64)(__le64)(x)) +#define constant_cpu_to_le32(x) ((__force __le32)(__u32)(x)) +#define constant_le32_to_cpu(x) ((__force __u32)(__le32)(x)) +#define constant_cpu_to_le16(x) ((__force __le16)(__u16)(x)) +#define constant_le16_to_cpu(x) ((__force __u16)(__le16)(x)) + #elif __BYTE_ORDER == __BIG_ENDIAN #define cpu_to_le64(x) ((__force __le64)__swab64((x))) #define le64_to_cpu(x) __swab64((__force __u64)(__le64)(x)) @@ -64,6 +78,13 @@ #define cpu_to_le16(x) ((__force __le16)__swab16((x))) #define le16_to_cpu(x) __swab16((__force __u16)(__le16)(x)) +#define constant_cpu_to_le64(x) ((__force __le64)__constant_swab64((x))) +#define constant_le64_to_cpu(x) __constant_swab64((__force __u64)(__le64)(x)) +#define constant_cpu_to_le32(x) ((__force __le32)__constant_swab32((x))) +#define constant_le32_to_cpu(x) __constant_swab32((__force __u32)(__le32)(x)) +#define constant_cpu_to_le16(x) ((__force __le16)__constant_swab16((x))) +#define constant_le16_to_cpu(x) __constant_swab16((__force __u16)(__le16)(x)) + #else # error "nuxi/pdp-endian archs are not supported" #endif diff --git a/reiserfscore/reiserfslib.c b/reiserfscore/reiserfslib.c index 5381001..e8041f7 100644 --- a/reiserfscore/reiserfslib.c +++ b/reiserfscore/reiserfslib.c @@ -13,8 +13,9 @@ struct reiserfs_key root_dir_key = { 0, 0, {{0, 0},} }; struct reiserfs_key parent_root_dir_key = { 0, 0, {{0, 0},} }; struct reiserfs_key lost_found_dir_key = { 0, 0, {{0, 0},} }; static struct reiserfs_key badblock_key = - { cpu_to_le32(BADBLOCK_DIRID), cpu_to_le32(BADBLOCK_OBJID), - {{cpu_to_le32(0), cpu_to_le32(0)},} }; + { constant_cpu_to_le32(BADBLOCK_DIRID), + constant_cpu_to_le32(BADBLOCK_OBJID), + {{constant_cpu_to_le32(0), constant_cpu_to_le32(0)},} }; __u16 root_dir_format = 0; __u16 lost_found_dir_format = 0; diff --git a/reiserfscore/stree.c b/reiserfscore/stree.c index 5ea0079..29a69ad 100644 --- a/reiserfscore/stree.c +++ b/reiserfscore/stree.c @@ -174,13 +174,14 @@ int bin_search(void *p_v_key, /* Key to search for. */ /* Minimal possible key. It is never in the tree. */ const struct reiserfs_key MIN_KEY = - { cpu_to_le32(0), cpu_to_le32(0), - {{cpu_to_le32(0), cpu_to_le32(0)},} }; + { constant_cpu_to_le32(0), constant_cpu_to_le32(0), + {{constant_cpu_to_le32(0), constant_cpu_to_le32(0)},} }; /* Maximal possible key. It is never in the tree. */ const struct reiserfs_key MAX_KEY = - { cpu_to_le32(0xffffffff), cpu_to_le32(0xffffffff), - {{cpu_to_le32(0xffffffff), cpu_to_le32(0xffffffff)},} }; + { constant_cpu_to_le32(0xffffffff), constant_cpu_to_le32(0xffffffff), + {{constant_cpu_to_le32(0xffffffff), + constant_cpu_to_le32(0xffffffff)},} }; /* Get delimiting key of the buffer by looking for it in the buffers in the path, starting from the bottom of the path, and going upwards. We must |