Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Lrge2-0007xM-DG for qemu-devel@nongnu.org; Wed, 08 Apr 2009 18:53:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Lrge1-0007x2-QY for qemu-devel@nongnu.org; Wed, 08 Apr 2009 18:53:22 -0400 Received: from [199.232.76.173] (port=53150 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lrge1-0007wx-Lq for qemu-devel@nongnu.org; Wed, 08 Apr 2009 18:53:21 -0400 Received: from hall.aurel32.net ([88.191.82.174]:55704) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Lrge1-0001qQ-6K for qemu-devel@nongnu.org; Wed, 08 Apr 2009 18:53:21 -0400 Date: Thu, 9 Apr 2009 00:53:16 +0200 From: Aurelien Jarno Subject: Re: [Qemu-devel] [PATCH] block-vpc: Don't silently create smaller image than requested Message-ID: <20090408225316.GA23493@volta.aurel32.net> References: <1239202145-18271-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1239202145-18271-1-git-send-email-kwolf@redhat.com> 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 Cc: Kevin Wolf On Wed, Apr 08, 2009 at 04:49:05PM +0200, Kevin Wolf wrote: > 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 > --- > 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 > */ Actually 0 is never returned, leading to a warning: CC block-vpc.o block-vpc.c: In function ‘calculate_geometry’: block-vpc.c:475: warning: control reaches end of non-void function > -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 > > > > -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net