From: Kevin Wolf <kwolf@suse.de>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@suse.de>
Subject: [Qemu-devel] [PATCH 1/7] block-vpc: Split up struct vpc_subheader
Date: Mon, 26 Jan 2009 17:59:22 +0100 [thread overview]
Message-ID: <1232989168-27759-2-git-send-email-kwolf@suse.de> (raw)
In-Reply-To: <1232989168-27759-1-git-send-email-kwolf@suse.de>
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 <kwolf@suse.de>
---
block-vpc.c | 85 ++++++++++++++++++++++++++++++-----------------------------
1 files changed, 43 insertions(+), 42 deletions(-)
diff --git a/block-vpc.c b/block-vpc.c
index f76c451..0b4666d 100644
--- a/block-vpc.c
+++ b/block-vpc.c
@@ -31,36 +31,31 @@
//#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 {
@@ -90,7 +85,9 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
{
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 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
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;
+
+ if (strncmp(dyndisk_header->magic, "cxsparse", 8))
+ goto fail;
- bs->total_sectors = ((uint64_t)be32_to_cpu(header.type.sparse.pagetable_entries) *
- be32_to_cpu(header.type.sparse.pageentry_size)) / 512;
+ bs->total_sectors = ((uint64_t)be32_to_cpu(dyndisk_header->pagetable_entries) *
+ be32_to_cpu(dyndisk_header->pageentry_size)) / 512;
- lseek(s->fd, be32_to_cpu(header.type.sparse.pagetable_offset), SEEK_SET);
+ lseek(s->fd, be32_to_cpu(dyndisk_header->pagetable_offset), SEEK_SET);
- s->pagetable_entries = be32_to_cpu(header.type.sparse.pagetable_entries);
+ 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 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
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)
--
1.6.0.2
next prev parent reply other threads:[~2009-01-26 17:12 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-26 16:59 [Qemu-devel] [PATCH 0/7] block-vpc: Improve support for VHD images Kevin Wolf
2009-01-26 16:59 ` Kevin Wolf [this message]
2009-01-26 20:27 ` [Qemu-devel] [PATCH 1/7] block-vpc: Split up struct vpc_subheader Anthony Liguori
2009-01-26 16:59 ` [Qemu-devel] [PATCH 2/7] block-vpc: Adapt header structures to official documentation Kevin Wolf
2009-01-26 16:59 ` [Qemu-devel] [PATCH 3/7] block-vpc: Fix disk size Kevin Wolf
2009-01-26 16:59 ` [Qemu-devel] [PATCH 4/7] block-vpc: Fix support for images > 4 GB Kevin Wolf
2009-01-27 11:03 ` Kevin Wolf
2009-01-27 14:30 ` Anthony Liguori
2009-01-27 14:29 ` Anthony Liguori
2009-01-26 16:59 ` [Qemu-devel] [PATCH 5/7] block-vpc: Use the qemu block layer Kevin Wolf
2009-01-26 16:59 ` [Qemu-devel] [PATCH 6/7] block-vpc: Write support Kevin Wolf
2009-01-26 16:59 ` [Qemu-devel] [PATCH 7/7] block-vpc: Create images Kevin Wolf
2009-01-26 21:52 ` [Qemu-devel] [PATCH 0/7] block-vpc: Improve support for VHD images Jamie Lokier
2009-01-27 9:20 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1232989168-27759-2-git-send-email-kwolf@suse.de \
--to=kwolf@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).