Received: from eggs.gnu.org ([2001:4830:134:3::10]:40953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bY5ty-0001q4-5G for qemu-devel@nongnu.org; Fri, 12 Aug 2016 02:25:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bY5tw-0005sQ-Id for qemu-devel@nongnu.org; Fri, 12 Aug 2016 02:25:05 -0400 Sender: Richard Henderson References: <1470977536-18209-1-git-send-email-famz@redhat.com> <1470977536-18209-2-git-send-email-famz@redhat.com> From: Richard Henderson Message-ID: <8dff3fef-5d8b-27e2-bfd7-7cc7bc92cd9c@twiddle.net> Date: Fri, 12 Aug 2016 07:24:54 +0100 MIME-Version: 1.0 In-Reply-To: <1470977536-18209-2-git-send-email-famz@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 1/9] util: Add UUID API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-block@nongnu.org, sw@weilnetz.de, jcody@redhat.com, mdroth@linux.vnet.ibm.com, armbru@redhat.com, pbonzini@redhat.com, mreitz@redhat.com 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~