From: mwilck@arcor.de
To: neilb@suse.de, linux-raid@vger.kernel.org
Cc: mwilck@arcor.de
Subject: [PATCH 1/6] DDF: add endian-safe typedefs
Date: Sun, 21 Jul 2013 19:28:19 +0200 [thread overview]
Message-ID: <1374427704-7903-2-git-send-email-mwilck@arcor.de> (raw)
In-Reply-To: <1374427704-7903-1-git-send-email-mwilck@arcor.de>
This adds typedefs for big-endian numbers. This will hopefully
reduce the number of endianness bugs I make.
---
super-ddf.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/super-ddf.c b/super-ddf.c
index d7da4c1..7f28d84 100644
--- a/super-ddf.c
+++ b/super-ddf.c
@@ -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
--
1.7.1
next prev parent reply other threads:[~2013-07-21 17:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-21 17:28 [RFC/PATCH 0/6] DDF: safe big-endian types mwilck
2013-07-21 17:28 ` mwilck [this message]
2013-07-21 17:28 ` [PATCH 2/6] DDF: convert big endian to be32 type mwilck
2013-07-21 17:28 ` [PATCH 3/6] DDF: convert big-endian __u64 to be64 type mwilck
2013-07-21 17:28 ` [PATCH 4/6] DDF: convert big-endian __u16 to be16 type mwilck
2013-07-21 17:28 ` [PATCH 5/6] DDF: add_other_bvd: fix endianness bug mwilck
2013-07-21 17:28 ` [PATCH 6/6] DDF: ddf_set_disk: fix minor " mwilck
2013-07-23 4:06 ` [RFC/PATCH 0/6] DDF: safe big-endian types NeilBrown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374427704-7903-2-git-send-email-mwilck@arcor.de \
--to=mwilck@arcor.de \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).