summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-04-18 15:39:10 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-04-18 15:39:10 +0000
commit530a491fc3a7469497d55b95259d97f8299b4dfa (patch)
treef14f3dc2109e5b4e63f41b274b2da2d3833cc527
parent2fcc1d5b6972cec2a313ec0ea7e9acc4a17e2f2a (diff)
downloadqemu-530a491fc3a7469497d55b95259d97f8299b4dfa.tar.gz
block-vpc: Don't silently create smaller image than requested (Kevin Wolf)
The algorithm from the VHD specification for CHS calculation silently limits images to 127 GB which may confuse a user who requested a larger image. Better output an error message and abort. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/branches/stable_0_10@7183 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--block-vpc.c11
-rw-r--r--qemu-img.c6
2 files changed, 13 insertions, 4 deletions
diff --git a/block-vpc.c b/block-vpc.c
index e353e31a8e..5ea390c702 100644
--- a/block-vpc.c
+++ b/block-vpc.c
@@ -433,14 +433,16 @@ static int vpc_write(BlockDriverState *bs, int64_t sector_num,
*
* Note that the geometry doesn't always exactly match total_sectors but
* may round it down.
+ *
+ * Returns 0 on success, -EFBIG if the size is larger than 127 GB
*/
-static void calculate_geometry(int64_t total_sectors, uint16_t* cyls,
+static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,
uint8_t* heads, uint8_t* secs_per_cyl)
{
uint32_t cyls_times_heads;
if (total_sectors > 65535 * 16 * 255)
- total_sectors = 65535 * 16 * 255;
+ return -EFBIG;
if (total_sectors > 65535 * 16 * 63) {
*secs_per_cyl = 255;
@@ -470,6 +472,8 @@ static void 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;
+
+ return 0;
}
static int vpc_create(const char *filename, int64_t total_sectors,
@@ -493,7 +497,8 @@ static int vpc_create(const char *filename, int64_t total_sectors,
return -EIO;
// Calculate matching total_size and geometry
- calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl);
+ if (calculate_geometry(total_sectors, &cyls, &heads, &secs_per_cyl))
+ return -EFBIG;
total_sectors = (int64_t) cyls * heads * secs_per_cyl;
// Prepare the Hard Disk Footer
diff --git a/qemu-img.c b/qemu-img.c
index efbb9b6be8..21c2ef5795 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -290,6 +290,8 @@ static int img_create(int argc, char **argv)
if (ret < 0) {
if (ret == -ENOTSUP) {
error("Formatting or formatting option not supported for file format '%s'", fmt);
+ } else if (ret == -EFBIG) {
+ error("The image size is too large for file format '%s'", fmt);
} else {
error("Error while formatting");
}
@@ -477,7 +479,9 @@ static int img_convert(int argc, char **argv)
ret = bdrv_create(drv, out_filename, total_sectors, out_baseimg, flags);
if (ret < 0) {
if (ret == -ENOTSUP) {
- error("Formatting not supported for file format '%s'", fmt);
+ error("Formatting not supported for file format '%s'", out_fmt);
+ } else if (ret == -EFBIG) {
+ error("The image size is too large for file format '%s'", out_fmt);
} else {
error("Error while formatting '%s'", out_filename);
}