Received: from eggs.gnu.org ([208.118.235.92]:36364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQhvB-0004cS-0t for qemu-devel@nongnu.org; Fri, 12 Apr 2013 13:38:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQhv5-0007FX-2H for qemu-devel@nongnu.org; Fri, 12 Apr 2013 13:37:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQhv4-0007FO-Qy for qemu-devel@nongnu.org; Fri, 12 Apr 2013 13:37:50 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3CHboSs028124 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Apr 2013 13:37:50 -0400 From: Stefan Hajnoczi Date: Fri, 12 Apr 2013 19:37:48 +0200 Message-Id: <1365788268-24787-1-git-send-email-stefanha@redhat.com> Subject: [Qemu-devel] [PATCH] qemu-img: refuse to compress files with invalid size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf Image file compression works at cluster granularity. It is not possible to compress less than a cluster of data at a time. Print an error when attempting qemu-img convert -c with an input file that is not a multiple of the cluster size. I considered automatically adjusting the output file size but think it's better to be explicit. This avoids confusion when users notice that image file size changed after conversion. Signed-off-by: Stefan Hajnoczi --- qemu-img.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 31627b0..2273851 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1370,6 +1370,13 @@ static int img_convert(int argc, char **argv) goto out; } cluster_sectors = cluster_size >> 9; + if (total_sectors % cluster_sectors) { + error_report("compression requires that input file size is a " + "multiple of %d bytes", + cluster_size); + ret = -1; + goto out; + } sector_num = 0; nb_sectors = total_sectors; -- 1.8.1.4