From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDc9v-0005JG-1K for qemu-devel@nongnu.org; Thu, 07 Mar 2013 09:51:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UDc9r-0002YG-LA for qemu-devel@nongnu.org; Thu, 07 Mar 2013 09:51:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UDc9r-0002Y3-DW for qemu-devel@nongnu.org; Thu, 07 Mar 2013 09:50:59 -0500 Date: Thu, 7 Mar 2013 15:50:56 +0100 From: Stefan Hajnoczi Message-ID: <20130307145056.GD27175@stefanha-thinkpad.redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH 6/7] block: add header update capability for VHDX images. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jeff Cody Cc: kwolf@redhat.com, sw@weilnetz.de, qemu-devel@nongnu.org On Wed, Mar 06, 2013 at 09:48:33AM -0500, Jeff Cody wrote: > This adds the ability to update the headers in a VHDX image, including > generating a new MS-compatible GUID, and checksum. > > Signed-off-by: Jeff Cody > --- > block/vhdx.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 163 insertions(+), 2 deletions(-) > > diff --git a/block/vhdx.c b/block/vhdx.c > index 97775d2..13d1e7f 100644 > --- a/block/vhdx.c > +++ b/block/vhdx.c > @@ -27,6 +27,11 @@ > le16_to_cpus(&(guid)->data2); \ > le16_to_cpus(&(guid)->data3); } while (0) > > +#define cpu_to_leguids(guid) do { \ > + cpu_to_le32s(&(guid)->data1); \ > + cpu_to_le16s(&(guid)->data2); \ > + cpu_to_le16s(&(guid)->data3); } while (0) > + Please use a function instead of a macro. > +/* Calculates new checksum. > + * > + * Zero is substituted during crc calculation for the original crc field > + * crc_offset: byte offset in buf of the buffer crc > + * buf: buffer pointer > + * size: size of buffer (must be > crc_offset+4) > + */ > +static uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset) > +{ > + uint32_t crc; > + > + assert(buf != NULL); > + assert(size > (crc_offset+4)); > + > + memset(buf+crc_offset, 0, sizeof(crc)); > + crc = crc32c(0xffffffff, buf, size); > + memcpy(buf+crc_offset, &crc, sizeof(crc)); Worth a comment that the checksum is in CPU endianness. Must use vhdx_header_le_export() before writing to file. That implies the buffer must also be in CPU endianness otherwise vhdx_header_le_export() will byteswap unwanted fields. > + > + return crc; > +} > + > /* Validates the checksum of the buffer, with an in-place CRC. > * > * Zero is substituted during crc calculation for the original crc field, > @@ -198,6 +227,33 @@ static bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset) > } > > /* > + * This generates a UUID that is compliant with the MS GUIDs used > + * in the VHDX spec (and elsewhere). > + * > + * We can do this with uuid_generate if uuid.h is present, > + * however not all systems have uuid and the generation is Do you mean libuuid is not available on all host platforms supported by QEMU, or just that you wanted to avoid the dependency? Since other parts of QEMU already use libuuid I'd rather see it used than reimplemented in VHDX.