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>
This commit is contained in:
Jeff Mahoney committed 2013-09-17 13:28:53 -04:00
1 parent 19566d0878
commit 57eac8416c
3 files changed
+55 -32

No files matched your search

+47 -26
View File
@@ -9,36 +9,43 @@
#include <endian.h> #include <endian.h>
#include <linux/types.h> #include <linux/types.h>
#define __swab16(x) \ #define __constant_swab16(x) ((__u16)( \
({ \ (((__u16)(x) & (__u16)0x00ffU) << 8) | \
__u16 __x = (x); \ (((__u16)(x) & (__u16)0xff00U) >> 8) ))
((__u16)( \
(((__u16)(__x) & (__u16)0x00ffU) << 8) | \ #define __swab16(x) \
(((__u16)(__x) & (__u16)0xff00U) >> 8) )); \ ({ \
__u16 __x = (x); \
__constant_swab16(__x); \
}) })
#define __swab32(x) \ #define __constant_swab32(x) ((__u32)( \
({ \ (((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
__u32 __x = (x); \ (((__u32)(x) & (__u32)0x0000ff00UL) << 8) | \
((__u32)( \ (((__u32)(x) & (__u32)0x00ff0000UL) >> 8) | \
(((__u32)(__x) & (__u32)0x000000ffUL) << 24) | \ (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
(((__u32)(__x) & (__u32)0x0000ff00UL) << 8) | \
(((__u32)(__x) & (__u32)0x00ff0000UL) >> 8) | \ #define __swab32(x) \
(((__u32)(__x) & (__u32)0xff000000UL) >> 24) )); \ ({ \
__u32 __x = (x); \
__constant_swab32(__x); \
}) })
#define __swab64(x) \ #define __constant_swab64(x) ((__u64)( \
({ \ (((__u64)(x) & (__u64)0x00000000000000ffULL) << 56) | \
__u64 __x = (x); \ (((__u64)(x) & (__u64)0x000000000000ff00ULL) << 40) | \
((__u64)( \ (((__u64)(x) & (__u64)0x0000000000ff0000ULL) << 24) | \
(__u64)(((__u64)(__x) & (__u64)0x00000000000000ffULL) << 56) | \ (((__u64)(x) & (__u64)0x00000000ff000000ULL) << 8) | \
(__u64)(((__u64)(__x) & (__u64)0x000000000000ff00ULL) << 40) | \ (((__u64)(x) & (__u64)0x000000ff00000000ULL) >> 8) | \
(__u64)(((__u64)(__x) & (__u64)0x0000000000ff0000ULL) << 24) | \ (((__u64)(x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
(__u64)(((__u64)(__x) & (__u64)0x00000000ff000000ULL) << 8) | \ (((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \
(__u64)(((__u64)(__x) & (__u64)0x000000ff00000000ULL) >> 8) | \ (((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56)))
(__u64)(((__u64)(__x) & (__u64)0x0000ff0000000000ULL) >> 24) | \
(__u64)(((__u64)(__x) & (__u64)0x00ff000000000000ULL) >> 40) | \
(__u64)(((__u64)(__x) & (__u64)0xff00000000000000ULL) >> 56) )); \ #define __swab64(x) \
({ \
__u64 __x = (x); \
__constant_swab64(__x); \
}) })
#ifndef le32_to_cpu #ifndef le32_to_cpu
@@ -56,6 +63,13 @@
#define cpu_to_le16(x) ((__force __le16)(__u16)(x)) #define cpu_to_le16(x) ((__force __le16)(__u16)(x))
#define le16_to_cpu(x) ((__force __u16)(__le16)(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 #elif __BYTE_ORDER == __BIG_ENDIAN
#define cpu_to_le64(x) ((__force __le64)__swab64((x))) #define cpu_to_le64(x) ((__force __le64)__swab64((x)))
#define le64_to_cpu(x) __swab64((__force __u64)(__le64)(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 cpu_to_le16(x) ((__force __le16)__swab16((x)))
#define le16_to_cpu(x) __swab16((__force __u16)(__le16)(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 #else
# error "nuxi/pdp-endian archs are not supported" # error "nuxi/pdp-endian archs are not supported"
#endif #endif
+3 -2
View File
@@ -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 parent_root_dir_key = { 0, 0, {{0, 0},} };
struct reiserfs_key lost_found_dir_key = { 0, 0, {{0, 0},} }; struct reiserfs_key lost_found_dir_key = { 0, 0, {{0, 0},} };
static struct reiserfs_key badblock_key = static struct reiserfs_key badblock_key =
{ cpu_to_le32(BADBLOCK_DIRID), cpu_to_le32(BADBLOCK_OBJID), { constant_cpu_to_le32(BADBLOCK_DIRID),
{{cpu_to_le32(0), cpu_to_le32(0)},} }; constant_cpu_to_le32(BADBLOCK_OBJID),
{{constant_cpu_to_le32(0), constant_cpu_to_le32(0)},} };
__u16 root_dir_format = 0; __u16 root_dir_format = 0;
__u16 lost_found_dir_format = 0; __u16 lost_found_dir_format = 0;
+5 -4
View File
@@ -174,13 +174,14 @@ int bin_search(void *p_v_key, /* Key to search for. */
/* Minimal possible key. It is never in the tree. */ /* Minimal possible key. It is never in the tree. */
const struct reiserfs_key MIN_KEY = const struct reiserfs_key MIN_KEY =
{ cpu_to_le32(0), cpu_to_le32(0), { constant_cpu_to_le32(0), constant_cpu_to_le32(0),
{{cpu_to_le32(0), cpu_to_le32(0)},} }; {{constant_cpu_to_le32(0), constant_cpu_to_le32(0)},} };
/* Maximal possible key. It is never in the tree. */ /* Maximal possible key. It is never in the tree. */
const struct reiserfs_key MAX_KEY = const struct reiserfs_key MAX_KEY =
{ cpu_to_le32(0xffffffff), cpu_to_le32(0xffffffff), { constant_cpu_to_le32(0xffffffff), constant_cpu_to_le32(0xffffffff),
{{cpu_to_le32(0xffffffff), 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 /* 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 path, starting from the bottom of the path, and going upwards. We must