aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2009-06-03 11:11:50 +0100
committerKeir Fraser <keir.fraser@citrix.com>2009-06-03 11:11:50 +0100
commit4b48ffd60a4b9177e90b069024a26ec31f5e9e6b (patch)
treec2ddeacc7017b0bd35f107574e2461ba4044c6f7 /tools/blktap
parent2f78e9cccf5203964043e4b7656da663d9d8e30f (diff)
downloadxen-4b48ffd60a4b9177e90b069024a26ec31f5e9e6b.tar.gz
xen-4b48ffd60a4b9177e90b069024a26ec31f5e9e6b.tar.bz2
xen-4b48ffd60a4b9177e90b069024a26ec31f5e9e6b.zip
blktap: fix empty QCOW images (bug 1430 part 2)
Empty QCOW images consist of only the L1 table, this results in a file size which is not sector-aligned. Since blktap uses O_DIRECT, the block aligned read of the L1 table will go beyond the end of file and thus returns the actual file size and not the expected length. This patch checks whether at least the L1 table has been read. This should fix bug 1430. Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Diffstat (limited to 'tools/blktap')
-rw-r--r--tools/blktap/drivers/block-qcow.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/tools/blktap/drivers/block-qcow.c b/tools/blktap/drivers/block-qcow.c
index dd65cd01bb..8027fcaca2 100644
--- a/tools/blktap/drivers/block-qcow.c
+++ b/tools/blktap/drivers/block-qcow.c
@@ -824,7 +824,7 @@ static int tdqcow_open (struct disk_driver *dd, const char *name, td_flag_t flag
l1_table_block = ROUNDUP(l1_table_block, 512);
ret = posix_memalign((void **)&buf2, 4096, l1_table_block);
if (ret != 0) goto fail;
- if (read(fd, buf2, l1_table_block) != l1_table_block)
+ if (read(fd, buf2, l1_table_block) < l1_table_size + s->l1_table_offset)
goto fail;
memcpy(s->l1_table, buf2 + s->l1_table_offset, l1_table_size);
@@ -878,7 +878,8 @@ static int tdqcow_open (struct disk_driver *dd, const char *name, td_flag_t flag
memcpy(buf2 + s->l1_table_offset, s->l1_table, l1_table_size);
lseek(fd, 0, SEEK_SET);
- if (write(fd, buf2, l1_table_block) != l1_table_block) {
+ if (write(fd, buf2, l1_table_block) <
+ l1_table_size + s->l1_table_offset) {
DPRINTF("qcow: Failed to write new L1 table\n");
goto fail;
}