diff options
author | aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-15 14:42:46 +0000 |
---|---|---|
committer | aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162> | 2009-04-15 14:42:46 +0000 |
commit | 6e9ea0c0629fe25723494a19498bedf4b781cbfa (patch) | |
tree | c0427853275f28ccbe5d1dd6fc4d8fee6c360675 /block-vpc.c | |
parent | 29463b24a8f427b7ff779b30fe52f1f00ad9b98c (diff) |
block-vpc: Don't silently create smaller image than requested
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: Aurelien Jarno <aurelien@aurel32.net>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7109 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block-vpc.c')
-rw-r--r-- | block-vpc.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/block-vpc.c b/block-vpc.c index 7ae520235f..71a171d0eb 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 |