summaryrefslogtreecommitdiffstats
path: root/block/vpc.c
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2010-05-17 13:17:34 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2010-05-17 13:17:34 -0500
commit129414184e79e887a4028f153f3b50b92354a6fc (patch)
treeed0c48e3df6d86f6cf750170daa4270d9305e5e8 /block/vpc.c
parentf7ce72878c05dacc5f52374b69e61d00556a185b (diff)
parent35ed5de6be186d46ff3e33554f32151fba0f401f (diff)
downloadhqemu-129414184e79e887a4028f153f3b50b92354a6fc.zip
hqemu-129414184e79e887a4028f153f3b50b92354a6fc.tar.gz
Merge remote branch 'kwolf/for-anthony' into staging
Diffstat (limited to 'block/vpc.c')
-rw-r--r--block/vpc.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/block/vpc.c b/block/vpc.c
index f94e469..214e9d1 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -463,9 +463,7 @@ static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,
}
}
- // Note: Rounding up deviates from the Virtual PC behaviour
- // However, we need this to avoid truncating images in qemu-img convert
- *cyls = (cyls_times_heads + *heads - 1) / *heads;
+ *cyls = cyls_times_heads / *heads;
return 0;
}
@@ -477,9 +475,9 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options)
struct vhd_dyndisk_header* dyndisk_header =
(struct vhd_dyndisk_header*) buf;
int fd, i;
- uint16_t cyls;
- uint8_t heads;
- uint8_t secs_per_cyl;
+ uint16_t cyls = 0;
+ uint8_t heads = 0;
+ uint8_t secs_per_cyl = 0;
size_t block_size, num_bat_entries;
int64_t total_sectors = 0;
@@ -496,9 +494,14 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options)
if (fd < 0)
return -EIO;
- // Calculate matching total_size and geometry
- if (calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl))
- return -EFBIG;
+ /* Calculate matching total_size and geometry. Increase the number of
+ sectors requested until we get enough (or fail). */
+ for (i = 0; total_sectors > (int64_t)cyls * heads * secs_per_cyl; i++) {
+ if (calculate_geometry(total_sectors + i,
+ &cyls, &heads, &secs_per_cyl)) {
+ return -EFBIG;
+ }
+ }
total_sectors = (int64_t) cyls * heads * secs_per_cyl;
// Prepare the Hard Disk Footer
OpenPOWER on IntegriCloud