All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-img: refuse to compress files with invalid size
@ 2013-04-12 17:37 Stefan Hajnoczi
  2013-04-12 19:55 ` Benoît Canet
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Hajnoczi @ 2013-04-12 17:37 UTC (permalink / raw)
  To: qemu-devel; +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 <stefanha@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-15  6:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-12 17:37 [Qemu-devel] [PATCH] qemu-img: refuse to compress files with invalid size Stefan Hajnoczi
2013-04-12 19:55 ` Benoît Canet
2013-04-12 20:04   ` Eric Blake
2013-04-15  6:53     ` Stefan Hajnoczi

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.