[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~
- [Qemu-block] [PATCH v5 0/9] UUID clean ups for 2.8, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 1/9] util: Add UUID API, Fam Zheng, 2016/08/12
- Re: [Qemu-block] [PATCH v5 1/9] util: Add UUID API,
Richard Henderson <=
- [Qemu-block] [PATCH v5 2/9] vhdx: Use QEMU UUID API, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 3/9] vdi: Use QEMU UUID API, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 4/9] vpc: Use QEMU UUID API, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 5/9] crypto: Switch to QEMU UUID API, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 6/9] tests: No longer dependent on CONFIG_UUID, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 7/9] configure: Remove detection code for UUID, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 9/9] tests: Add uuid tests, Fam Zheng, 2016/08/12
- [Qemu-block] [PATCH v5 8/9] vl: Switch qemu_uuid to QemuUUID, Fam Zheng, 2016/08/12
- Re: [Qemu-block] [Qemu-devel] [PATCH v5 0/9] UUID clean ups for 2.8, no-reply, 2016/08/12