diff mbox

[v5,03/10] public: xen.h: add definitions for UUID handling

Message ID 1504210172-27234-4-git-send-email-volodymyr_babchuk@epam.com (mailing list archive)
State New, archived
Headers show

Commit Message

Volodymyr Babchuk Aug. 31, 2017, 8:09 p.m. UTC
Added type xen_uuid_t. This type represents UUID as an array of 16
bytes in big endian format.

Added macro XEN_DEFINE_UUID that constructs UUID in the usual way:

 XEN_DEFINE_UUID(00112233, 4455, 6677, 8899, aabbccddeeff)

will construct UUID 00112233-4455-6677-8899-aabbccddeeff presented as
 {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
  0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}

NB: This is compatible with Linux kernel and with libuuid, but it is not
compatible with Microsoft, as they use mixed-endian encoding (some
components are little-endian, some are big-endian).

Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
---

 * Array was wrapped into a structure

---
xen/include/public/xen.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Ian Jackson Sept. 1, 2017, 9:42 a.m. UTC | #1
Volodymyr Babchuk writes ("[PATCH v5 03/10] public: xen.h: add definitions for UUID handling"):
> Added type xen_uuid_t. This type represents UUID as an array of 16
> bytes in big endian format.
> 
> Added macro XEN_DEFINE_UUID that constructs UUID in the usual way:
> 
>  XEN_DEFINE_UUID(00112233, 4455, 6677, 8899, aabbccddeeff)

The commit message implies the uuid value is supplied in hex.
But:

> +#define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6)             \
> +    {{((a) >> 24) & 0xFF, ((a) >> 16) & 0xFF,                           \
> +      ((a) >>  8) & 0xFF, ((a) >>  0) & 0xFF,                           \
> +      ((b) >>  8) & 0xFF, ((b) >>  0) & 0xFF,                           \
> +      ((c) >>  8) & 0xFF, ((c) >>  0) & 0xFF,                           \
> +      ((d) >>  8) & 0xFF, ((d) >>  0) & 0xFF,                           \
> +                e1, e2, e3, e4, e5, e6}}

Nothing pastes 0x onto the front of these constants.

Ian.
diff mbox

Patch

diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 2ac6b1e..3dc81e3 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -930,6 +930,19 @@  __DEFINE_XEN_GUEST_HANDLE(uint16, uint16_t);
 __DEFINE_XEN_GUEST_HANDLE(uint32, uint32_t);
 __DEFINE_XEN_GUEST_HANDLE(uint64, uint64_t);
 
+typedef struct
+{
+    uint8_t a[16];
+} xen_uuid_t;
+
+#define XEN_DEFINE_UUID(a, b, c, d, e1, e2, e3, e4, e5, e6)             \
+    {{((a) >> 24) & 0xFF, ((a) >> 16) & 0xFF,                           \
+      ((a) >>  8) & 0xFF, ((a) >>  0) & 0xFF,                           \
+      ((b) >>  8) & 0xFF, ((b) >>  0) & 0xFF,                           \
+      ((c) >>  8) & 0xFF, ((c) >>  0) & 0xFF,                           \
+      ((d) >>  8) & 0xFF, ((d) >>  0) & 0xFF,                           \
+                e1, e2, e3, e4, e5, e6}}
+
 #endif /* !__ASSEMBLY__ */
 
 /* Default definitions for macros used by domctl/sysctl. */