mirror of https://github.com/xemu-project/xemu.git
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 <kwolf@suse.de> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6454 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
f55761a0c4
commit
b9fa33a6e4
89
block-vpc.c
89
block-vpc.c
|
@ -31,36 +31,31 @@
|
||||||
//#define CACHE
|
//#define CACHE
|
||||||
|
|
||||||
// always big-endian
|
// always big-endian
|
||||||
struct vpc_subheader {
|
struct vhd_footer {
|
||||||
char magic[8]; // "conectix" / "cxsparse"
|
char creator[8]; // "conectix
|
||||||
union {
|
uint32_t unk1[2];
|
||||||
struct {
|
uint32_t unk2; // always zero?
|
||||||
uint32_t unk1[2];
|
uint32_t subheader_offset;
|
||||||
uint32_t unk2; // always zero?
|
uint32_t unk3; // some size?
|
||||||
uint32_t subheader_offset;
|
char creator_app[4]; // "vpc "
|
||||||
uint32_t unk3; // some size?
|
uint16_t major;
|
||||||
char creator[4]; // "vpc "
|
uint16_t minor;
|
||||||
uint16_t major;
|
char guest[4]; // "Wi2k"
|
||||||
uint16_t minor;
|
uint32_t unk4[7];
|
||||||
char guest[4]; // "Wi2k"
|
uint8_t vnet_id[16]; // virtual network id, purpose unknown
|
||||||
uint32_t unk4[7];
|
// next 16 longs are used, but dunno the purpose
|
||||||
uint8_t vnet_id[16]; // virtual network id, purpose unknown
|
// next 6 longs unknown, following 7 long maybe a serial
|
||||||
// next 16 longs are used, but dunno the purpose
|
};
|
||||||
// next 6 longs unknown, following 7 long maybe a serial
|
|
||||||
char padding[HEADER_SIZE - 84];
|
struct vhd_dyndisk_header {
|
||||||
} main;
|
char magic[8]; // "cxsparse"
|
||||||
struct {
|
uint32_t unk1[2]; // all bits set
|
||||||
uint32_t unk1[2]; // all bits set
|
uint32_t unk2; // always zero?
|
||||||
uint32_t unk2; // always zero?
|
uint32_t pagetable_offset;
|
||||||
uint32_t pagetable_offset;
|
uint32_t unk3;
|
||||||
uint32_t unk3;
|
uint32_t pagetable_entries; // 32bit/entry
|
||||||
uint32_t pagetable_entries; // 32bit/entry
|
uint32_t pageentry_size; // 512*8*512
|
||||||
uint32_t pageentry_size; // 512*8*512
|
uint32_t nb_sectors;
|
||||||
uint32_t nb_sectors;
|
|
||||||
char padding[HEADER_SIZE - 40];
|
|
||||||
} sparse;
|
|
||||||
char padding[HEADER_SIZE - 8];
|
|
||||||
} type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct BDRVVPCState {
|
typedef struct BDRVVPCState {
|
||||||
|
@ -90,7 +85,9 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
{
|
{
|
||||||
BDRVVPCState *s = bs->opaque;
|
BDRVVPCState *s = bs->opaque;
|
||||||
int fd, i;
|
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);
|
fd = open(filename, O_RDONLY | O_BINARY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -100,25 +97,29 @@ static int vpc_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
|
|
||||||
s->fd = fd;
|
s->fd = fd;
|
||||||
|
|
||||||
if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE)
|
if (read(fd, buf, HEADER_SIZE) != HEADER_SIZE)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (strncmp(header.magic, "conectix", 8))
|
footer = (struct vhd_footer*) buf;
|
||||||
goto fail;
|
if (strncmp(footer->creator, "conectix", 8))
|
||||||
lseek(s->fd, be32_to_cpu(header.type.main.subheader_offset), SEEK_SET);
|
|
||||||
|
|
||||||
if (read(fd, &header, HEADER_SIZE) != HEADER_SIZE)
|
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (strncmp(header.magic, "cxsparse", 8))
|
lseek(s->fd, be32_to_cpu(footer->subheader_offset), SEEK_SET);
|
||||||
goto fail;
|
if (read(fd, buf, HEADER_SIZE) != HEADER_SIZE)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
bs->total_sectors = ((uint64_t)be32_to_cpu(header.type.sparse.pagetable_entries) *
|
footer = NULL;
|
||||||
be32_to_cpu(header.type.sparse.pageentry_size)) / 512;
|
dyndisk_header = (struct vhd_dyndisk_header*) buf;
|
||||||
|
|
||||||
lseek(s->fd, be32_to_cpu(header.type.sparse.pagetable_offset), SEEK_SET);
|
if (strncmp(dyndisk_header->magic, "cxsparse", 8))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
s->pagetable_entries = be32_to_cpu(header.type.sparse.pagetable_entries);
|
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(dyndisk_header->pagetable_offset), SEEK_SET);
|
||||||
|
|
||||||
|
s->pagetable_entries = be32_to_cpu(dyndisk_header->pagetable_entries);
|
||||||
s->pagetable = qemu_malloc(s->pagetable_entries * 4);
|
s->pagetable = qemu_malloc(s->pagetable_entries * 4);
|
||||||
if (!s->pagetable)
|
if (!s->pagetable)
|
||||||
goto fail;
|
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++)
|
for (i = 0; i < s->pagetable_entries; i++)
|
||||||
be32_to_cpus(&s->pagetable[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
|
#ifdef CACHE
|
||||||
s->pageentry_u8 = qemu_malloc(512);
|
s->pageentry_u8 = qemu_malloc(512);
|
||||||
if (!s->pageentry_u8)
|
if (!s->pageentry_u8)
|
||||||
|
|
Loading…
Reference in New Issue