[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/7] block/vpc: Replace HEADER_SIZE by FOOTER_SIZE
From: |
Stefan Weil |
Subject: |
[Qemu-devel] [PATCH 3/7] block/vpc: Replace HEADER_SIZE by FOOTER_SIZE |
Date: |
Fri, 1 Feb 2013 22:51:30 +0100 |
HEADER_SIZE is the size of the footer (the last sector of the VHD image),
so its correct name is FOOTER_SIZE.
For the same reason, we have a footer checksum instead of a header checksum.
Signed-off-by: Stefan Weil <address@hidden>
---
block/vpc.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 4565723..bcc2ace 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -35,7 +35,7 @@
/**************************************************************/
-#define HEADER_SIZE 512
+#define FOOTER_SIZE 512
//#define CACHE
@@ -118,7 +118,7 @@ struct vhd_dyndisk_header {
typedef struct BDRVVPCState {
CoMutex lock;
- uint8_t footer_buf[HEADER_SIZE];
+ uint8_t footer_buf[FOOTER_SIZE];
uint64_t free_data_block_offset;
int max_table_entries;
uint32_t *pagetable;
@@ -166,24 +166,24 @@ static int vpc_open(BlockDriverState *bs, int flags)
int i;
struct vhd_footer *footer;
struct vhd_dyndisk_header *dyndisk_header;
- uint8_t buf[HEADER_SIZE];
+ uint8_t buf[FOOTER_SIZE];
uint32_t checksum;
int err = -1;
int disk_type = VHD_DYNAMIC;
- if (bdrv_pread(bs->file, 0, s->footer_buf, HEADER_SIZE) != HEADER_SIZE) {
+ if (bdrv_pread(bs->file, 0, s->footer_buf, FOOTER_SIZE) != FOOTER_SIZE) {
goto fail;
}
footer = (struct vhd_footer *)s->footer_buf;
if (strncmp(footer->creator, "conectix", 8)) {
int64_t offset = bdrv_getlength(bs->file);
- if (offset < HEADER_SIZE) {
+ if (offset < FOOTER_SIZE) {
goto fail;
}
/* If a fixed disk, the footer is found only at the end of the file */
- if (bdrv_pread(bs->file, offset-HEADER_SIZE, s->footer_buf,
HEADER_SIZE)
- != HEADER_SIZE) {
+ if (bdrv_pread(bs->file, offset-FOOTER_SIZE, s->footer_buf,
FOOTER_SIZE)
+ != FOOTER_SIZE) {
goto fail;
}
if (strncmp(footer->creator, "conectix", 8)) {
@@ -194,8 +194,8 @@ static int vpc_open(BlockDriverState *bs, int flags)
checksum = be32_to_cpu(footer->checksum);
footer->checksum = 0;
- if (vpc_checksum(s->footer_buf, HEADER_SIZE) != checksum) {
- fprintf(stderr, "block-vpc: The header checksum of '%s' is "
+ if (vpc_checksum(s->footer_buf, FOOTER_SIZE) != checksum) {
+ fprintf(stderr, "block-vpc: The footer checksum of '%s' is "
"incorrect.\n", bs->filename);
}
@@ -216,7 +216,7 @@ static int vpc_open(BlockDriverState *bs, int flags)
if (disk_type == VHD_DYNAMIC) {
if (bdrv_pread(bs->file, be64_to_cpu(footer->data_offset), buf,
- HEADER_SIZE) != HEADER_SIZE) {
+ FOOTER_SIZE) != FOOTER_SIZE) {
goto fail;
}
@@ -366,7 +366,7 @@ static int rewrite_footer(BlockDriverState *bs)
BDRVVPCState *s = bs->opaque;
int64_t offset = s->free_data_block_offset;
- ret = bdrv_pwrite_sync(bs->file, offset, s->footer_buf, HEADER_SIZE);
+ ret = bdrv_pwrite_sync(bs->file, offset, s->footer_buf, FOOTER_SIZE);
if (ret < 0) {
return ret;
}
@@ -602,14 +602,14 @@ static int create_dynamic_disk(int fd, uint8_t *buf,
int64_t total_sectors)
block_size = 0x200000;
num_bat_entries = (total_sectors + block_size / 512) / (block_size / 512);
- if (write(fd, buf, HEADER_SIZE) != HEADER_SIZE) {
+ if (write(fd, buf, FOOTER_SIZE) != FOOTER_SIZE) {
goto fail;
}
if (lseek(fd, 1536 + ((num_bat_entries * 4 + 511) & ~511), SEEK_SET) < 0) {
goto fail;
}
- if (write(fd, buf, HEADER_SIZE) != HEADER_SIZE) {
+ if (write(fd, buf, FOOTER_SIZE) != FOOTER_SIZE) {
goto fail;
}
@@ -669,7 +669,7 @@ static int create_fixed_disk(int fd, uint8_t *buf, int64_t
total_size)
if (lseek(fd, -512, SEEK_END) < 0) {
goto fail;
}
- if (write(fd, buf, HEADER_SIZE) != HEADER_SIZE) {
+ if (write(fd, buf, FOOTER_SIZE) != FOOTER_SIZE) {
goto fail;
}
@@ -742,7 +742,7 @@ static int vpc_create(const char *filename,
QEMUOptionParameter *options)
footer->features = be32_to_cpu(0x02);
footer->version = be32_to_cpu(0x00010000);
if (disk_type == VHD_DYNAMIC) {
- footer->data_offset = be64_to_cpu(HEADER_SIZE);
+ footer->data_offset = be64_to_cpu(FOOTER_SIZE);
} else {
footer->data_offset = be64_to_cpu(0xFFFFFFFFFFFFFFFFULL);
}
@@ -768,7 +768,7 @@ static int vpc_create(const char *filename,
QEMUOptionParameter *options)
uuid_generate(footer->uuid);
#endif
- footer->checksum = be32_to_cpu(vpc_checksum(buf, HEADER_SIZE));
+ footer->checksum = be32_to_cpu(vpc_checksum(buf, FOOTER_SIZE));
if (disk_type == VHD_DYNAMIC) {
ret = create_dynamic_disk(fd, buf, total_sectors);
--
1.7.10.4
- Re: [Qemu-devel] [PATCH 2/7] block/vpc: Add link to available VHD documentation, (continued)
[Qemu-devel] [PATCH 3/7] block/vpc: Replace HEADER_SIZE by FOOTER_SIZE,
Stefan Weil <=
[Qemu-devel] [PATCH 6/7] block/vpc: Remove workaround for geometry calculation, Stefan Weil, 2013/02/01