Files
reiserfsprogs/include/swab.h
T
Jeff Mahoney 81aeadf510 reiserfsprogs: annotate for endian safeness
By annotating structure members and other on-disk structures as little
endian, we can catch bugs more easily.

The code was already endian safe except for three minor spots:
1) The badblock list code was initializing its key in an endian-unsafe way.
2) Indirect block pointer sequence printing was treating cpu-order values
   as little endian.
3) reiserfsck was trying to do endian switching on the lost+found key,
   but it was before it was even initialized to anything, so we can
   just remove that completely.

These issues were fixed as part of this commit.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
2013-08-26 19:02:20 -04:00

73 lines
2.3 KiB
C

/*
* Copyright 2002-2004 by Hans Reiser, licensing governed by
* reiserfsprogs/README
*/
#ifndef REISERFSPROGS_SWAB_H
#define REISERFSPROGS_SWAB_H
#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 __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 __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) )); \
})
#ifndef le32_to_cpu
#ifdef __CHECKER__
#define __force __attribute__((force))
#else
#define __force
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
#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))
#elif __BYTE_ORDER == __BIG_ENDIAN
#define cpu_to_le64(x) ((__force __le64)__swab64((x)))
#define le64_to_cpu(x) __swab64((__force __u64)(__le64)(x))
#define cpu_to_le32(x) ((__force __le32)__swab32((x)))
#define le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
#define cpu_to_le16(x) ((__force __le16)__swab16((x)))
#define le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
#else
# error "nuxi/pdp-endian archs are not supported"
#endif
#endif
#endif /* REISERFS_SWAB_H */