From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH] block-vpc: Don't silently create smaller image than requested
Date: Wed, 8 Apr 2009 16:49:05 +0200 [thread overview]
Message-ID: <1239202145-18271-1-git-send-email-kwolf@redhat.com> (raw)
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>
---
block-vpc.c | 9 ++++++---
qemu-img.c | 4 ++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/block-vpc.c b/block-vpc.c
index 7ae5202..d915d20 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;
@@ -493,7 +495,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 913ad34..ccf4a6f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -306,6 +306,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");
}
@@ -494,6 +496,8 @@ static int img_convert(int argc, char **argv)
if (ret < 0) {
if (ret == -ENOTSUP) {
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);
}
--
1.6.0.6
next reply other threads:[~2009-04-08 14:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-08 14:49 Kevin Wolf [this message]
2009-04-08 22:53 ` [Qemu-devel] [PATCH] block-vpc: Don't silently create smaller image than requested Aurelien Jarno
2009-04-09 7:43 ` [Qemu-devel] [PATCH v2] " Kevin Wolf
2009-04-15 14:45 ` Aurelien Jarno
2009-04-18 15:41 ` [Qemu-devel] [PATCH] " Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1239202145-18271-1-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).