All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [7183] block-vpc: Don't silently create smaller image than requested ( Kevin Wolf)
@ 2009-04-18 15:39 Anthony Liguori
  0 siblings, 0 replies; only message in thread
From: Anthony Liguori @ 2009-04-18 15:39 UTC (permalink / raw)
  To: qemu-devel

Revision: 7183
          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7183
Author:   aliguori
Date:     2009-04-18 15:39:10 +0000 (Sat, 18 Apr 2009)
Log Message:
-----------
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>

Modified Paths:
--------------
    branches/stable_0_10/block-vpc.c
    branches/stable_0_10/qemu-img.c

Modified: branches/stable_0_10/block-vpc.c
===================================================================
--- branches/stable_0_10/block-vpc.c	2009-04-18 15:36:23 UTC (rev 7182)
+++ branches/stable_0_10/block-vpc.c	2009-04-18 15:39:10 UTC (rev 7183)
@@ -433,14 +433,16 @@
  *
  * 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 @@
     // 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 @@
         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

Modified: branches/stable_0_10/qemu-img.c
===================================================================
--- branches/stable_0_10/qemu-img.c	2009-04-18 15:36:23 UTC (rev 7182)
+++ branches/stable_0_10/qemu-img.c	2009-04-18 15:39:10 UTC (rev 7183)
@@ -290,6 +290,8 @@
     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 @@
     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);
         }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-04-18 15:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-18 15:39 [Qemu-devel] [7183] block-vpc: Don't silently create smaller image than requested ( Kevin Wolf) Anthony Liguori

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.