From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lu6KE-0005zi-1H for qemu-devel@nongnu.org; Wed, 15 Apr 2009 10:42:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lu6KD-0005zS-OI for qemu-devel@nongnu.org; Wed, 15 Apr 2009 10:42:53 -0400 Received: from [199.232.76.173] (port=50618 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lu6KD-0005zP-F5 for qemu-devel@nongnu.org; Wed, 15 Apr 2009 10:42:53 -0400 Received: from savannah.gnu.org ([199.232.41.3]:43283 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lu6KC-0002Rs-Lk for qemu-devel@nongnu.org; Wed, 15 Apr 2009 10:42:53 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Lu6K7-00081L-4S for qemu-devel@nongnu.org; Wed, 15 Apr 2009 14:42:47 +0000 Received: from aurel32 by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1Lu6K6-00081H-SI for qemu-devel@nongnu.org; Wed, 15 Apr 2009 14:42:47 +0000 MIME-Version: 1.0 Errors-To: aurel32 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurelien Jarno Message-Id: Date: Wed, 15 Apr 2009 14:42:46 +0000 Subject: [Qemu-devel] [7109] block-vpc: Don't silently create smaller image than requested Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7109 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7109 Author: aurel32 Date: 2009-04-15 14:42:46 +0000 (Wed, 15 Apr 2009) Log Message: ----------- 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 Signed-off-by: Aurelien Jarno Modified Paths: -------------- trunk/block-vpc.c trunk/qemu-img.c Modified: trunk/block-vpc.c =================================================================== --- trunk/block-vpc.c 2009-04-15 14:42:30 UTC (rev 7108) +++ trunk/block-vpc.c 2009-04-15 14:42:46 UTC (rev 7109) @@ -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: trunk/qemu-img.c =================================================================== --- trunk/qemu-img.c 2009-04-15 14:42:30 UTC (rev 7108) +++ trunk/qemu-img.c 2009-04-15 14:42:46 UTC (rev 7109) @@ -306,6 +306,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"); } @@ -494,6 +496,8 @@ 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); }