qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [PATCH v5 1/9] util: Add UUID API


From: Richard Henderson
Subject: Re: [Qemu-block] [PATCH v5 1/9] util: Add UUID API
Date: Fri, 12 Aug 2016 07:24:54 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

On 08/12/2016 05:52 AM, Fam Zheng wrote:
+/* Version 4 UUID (pseudo random numbers), RFC4122 4.4. */
+
+typedef struct {
+    union {
+        unsigned char data[16];
+        struct {
+            /* Generated in BE endian, can be swapped with qemu_uuid_bswap. */

Nit: BE endian is redundant.  big-endian or just BE, please.

+            uint32_t time_low;
+            uint16_t time_mid;
+            uint16_t time_high_and_version;
+            uint8_t  clock_seq_and_reserved;
+            uint8_t  clock_seq_low;
+            uint8_t  node[6];
+        } fields;
+    };
+} QemuUUID;

Wait, didn't you just tell me that you *couldn't* add this union because of the packed usage within some file?

But of course if you're going to do this, you should actually use these fields,

+    /* Set the two most significant bits (bits 6 and 7) of the
+      clock_seq_hi_and_reserved to zero and one, respectively. */
+    uuid->data[8] = (uuid->data[8] & 0x3f) | 0x80;
+    /* Set the four most significant bits (bits 12 through 15) of the
+      time_hi_and_version field to the 4-bit version number.
+      */
+    uuid->data[6] = (uuid->data[6] & 0xf) | 0x40;

Here,

+void qemu_uuid_bswap(QemuUUID *uuid)
+{
+    assert(QEMU_IS_ALIGNED((uint64_t)uuid, sizeof(uint32_t)));
+    bswap32s(&uuid->fields.time_low);
+    bswap16s(&uuid->fields.time_mid);
+    bswap16s(&uuid->fields.time_high_and_version);

And then you don't need this assert.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]