Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LRY2i-0007Oi-Mj for qemu-devel@nongnu.org; Mon, 26 Jan 2009 15:26:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LRY2h-0007OB-SC for qemu-devel@nongnu.org; Mon, 26 Jan 2009 15:26:48 -0500 Received: from [199.232.76.173] (port=52235 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LRY2h-0007O8-P0 for qemu-devel@nongnu.org; Mon, 26 Jan 2009 15:26:47 -0500 Received: from savannah.gnu.org ([199.232.41.3]:35028 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LRY2h-00072C-EP for qemu-devel@nongnu.org; Mon, 26 Jan 2009 15:26:47 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LRY2g-0002wo-RC for qemu-devel@nongnu.org; Mon, 26 Jan 2009 20:26:46 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LRY2g-0002wk-KH for qemu-devel@nongnu.org; Mon, 26 Jan 2009 20:26:46 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Mon, 26 Jan 2009 20:26:46 +0000 Subject: [Qemu-devel] [6454] block-vpc: Split up struct vpc_subheader (Kevin Wolf) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6454 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6454 Author: aliguori Date: 2009-01-26 20:26:46 +0000 (Mon, 26 Jan 2009) Log Message: ----------- block-vpc: Split up struct vpc_subheader (Kevin Wolf) struct vpc_subheader currently is a union of two completely different data structures (the Hard Disk Footer and the Dynamic Disk Header). That doesn't make too much sense, so split them up. Signed-off-by: Kevin Wolf Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/block-vpc.c Modified: trunk/block-vpc.c =================================================================== --- trunk/block-vpc.c 2009-01-26 19:54:36 UTC (rev 6453) +++ trunk/block-vpc.c 2009-01-26 20:26:46 UTC (rev 6454) @@ -31,38 +31,33 @@ //#define CACHE // always big-endian -struct vpc_subheader { - char magic[8]; // "conectix" / "cxsparse" - union { - struct { - uint32_t unk1[2]; - uint32_t unk2; // always zero? - uint32_t subheader_offset; - uint32_t unk3; // some size? - char creator[4]; // "vpc " - uint16_t major; - uint16_t minor; - char guest[4]; // "Wi2k" - uint32_t unk4[7]; - uint8_t vnet_id[16]; // virtual network id, purpose unknown - // next 16 longs are used, but dunno the purpose - // next 6 longs unknown, following 7 long maybe a serial - char padding[HEADER_SIZE - 84]; - } main; - struct { - uint32_t unk1[2]; // all bits set - uint32_t unk2; // always zero? - uint32_t pagetable_offset; - uint32_t unk3; - uint32_t pagetable_entries; // 32bit/entry - uint32_t pageentry_size; // 512*8*512 - uint32_t nb_sectors; - char padding[HEADER_SIZE - 40]; - } sparse; - char padding[HEADER_SIZE - 8]; - } type; +struct vhd_footer { + char creator[8]; // "conectix + uint32_t unk1[2]; + uint32_t unk2; // always zero? + uint32_t subheader_offset; + uint32_t unk3; // some size? + char creator_app[4]; // "vpc " + uint16_t major; + uint16_t minor; + char guest[4]; // "Wi2k" + uint32_t unk4[7]; + uint8_t vnet_id[16]; // virtual network id, purpose unknown + // next 16 longs are used, but dunno the purpose + // next 6 longs unknown, following 7 long maybe a serial }; +struct vhd_dyndisk_header { + char magic[8]; // "cxsparse" + uint32_t unk1[2]; // all bits set + uint32_t unk2; // always zero? + uint32_t pagetable_offset; + uint32_t unk3; + uint32_t pagetable_entries; // 32bit/entry + uint32_t pageentry_size; // 512*8*512 + uint32_t nb_sectors; +}; + typedef struct BDRVVPCState { int fd; @@ -90,7 +85,9 @@ { BDRVVPCState *s = bs->opaque; int fd, i; - struct vpc_subheader header; + struct vhd_footer* footer; + struct vhd_dyndisk_header* dyndisk_header; + uint8_t buf[HEADER_SIZE]; fd = open(filename, O_RDONLY | O_BINARY); if (fd < 0) @@ -100,25 +97,29 @@ s->fd = fd; - if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE) + if (read(fd, buf, HEADER_SIZE) != HEADER_SIZE) goto fail; - if (strncmp(header.magic, "conectix", 8)) + footer = (struct vhd_footer*) buf; + if (strncmp(footer->creator, "conectix", 8)) goto fail; - lseek(s->fd, be32_to_cpu(header.type.main.subheader_offset), SEEK_SET); - if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE) + lseek(s->fd, be32_to_cpu(footer->subheader_offset), SEEK_SET); + if (read(fd, buf, HEADER_SIZE) != HEADER_SIZE) goto fail; - if (strncmp(header.magic, "cxsparse", 8)) - goto fail; + footer = NULL; + dyndisk_header = (struct vhd_dyndisk_header*) buf; - bs->total_sectors = ((uint64_t)be32_to_cpu(header.type.sparse.pagetable_entries) * - be32_to_cpu(header.type.sparse.pageentry_size)) / 512; + if (strncmp(dyndisk_header->magic, "cxsparse", 8)) + goto fail; - lseek(s->fd, be32_to_cpu(header.type.sparse.pagetable_offset), SEEK_SET); + bs->total_sectors = ((uint64_t)be32_to_cpu(dyndisk_header->pagetable_entries) * + be32_to_cpu(dyndisk_header->pageentry_size)) / 512; - s->pagetable_entries = be32_to_cpu(header.type.sparse.pagetable_entries); + lseek(s->fd, be32_to_cpu(dyndisk_header->pagetable_offset), SEEK_SET); + + s->pagetable_entries = be32_to_cpu(dyndisk_header->pagetable_entries); s->pagetable = qemu_malloc(s->pagetable_entries * 4); if (!s->pagetable) goto fail; @@ -128,7 +129,7 @@ for (i = 0; i < s->pagetable_entries; i++) be32_to_cpus(&s->pagetable[i]); - s->pageentry_size = be32_to_cpu(header.type.sparse.pageentry_size); + s->pageentry_size = be32_to_cpu(dyndisk_header->pageentry_size); #ifdef CACHE s->pageentry_u8 = qemu_malloc(512); if (!s->pageentry_u8)