]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
DDF: add endian-safe typedefs
authormwilck@arcor.de <mwilck@arcor.de>
Sun, 21 Jul 2013 17:28:19 +0000 (19:28 +0200)
committerNeilBrown <neilb@suse.de>
Tue, 23 Jul 2013 03:49:11 +0000 (13:49 +1000)
This adds typedefs for big-endian numbers. This will hopefully
reduce the number of endianness bugs I make.

Signed-off-by: NeilBrown <neilb@suse.de>
super-ddf.c

index d7da4c192284126940a360a8372cf24780ab98b8..7f28d8447433f1f8a63df7caeb3189601867547b 100644 (file)
@@ -58,6 +58,42 @@ unsigned long crc32(
  *
  */
 
+typedef struct __be16 {
+       __u16 _v16;
+} be16;
+#define be16_eq(x, y) ((x)._v16 == (y)._v16)
+
+typedef struct __be32 {
+       __u32 _v32;
+} be32;
+#define be32_eq(x, y) ((x)._v32 == (y)._v32)
+
+typedef struct __be64 {
+       __u64 _v64;
+} be64;
+#define be64_eq(x, y) ((x)._v64 == (y)._v64)
+
+#define be16_to_cpu(be) __be16_to_cpu((be)._v16)
+static inline be16 cpu_to_be16(__u16 x)
+{
+       be16 be = { ._v16 = __cpu_to_be16(x) };
+       return be;
+}
+
+#define be32_to_cpu(be) __be32_to_cpu((be)._v32)
+static inline be32 cpu_to_be32(__u32 x)
+{
+       be32 be = { ._v32 = __cpu_to_be32(x) };
+       return be;
+}
+
+#define be64_to_cpu(be) __be64_to_cpu((be)._v64)
+static inline be64 cpu_to_be64(__u64 x)
+{
+       be64 be = { ._v64 = __cpu_to_be64(x) };
+       return be;
+}
+
 /* Primary Raid Level (PRL) */
 #define        DDF_RAID0       0x00
 #define        DDF_RAID1       0x01