]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: Fail if user specifies a QCOW disk image
authorPekka Enberg <penberg@kernel.org>
Fri, 7 Jan 2011 19:25:24 +0000 (21:25 +0200)
committerPekka Enberg <penberg@kernel.org>
Fri, 7 Jan 2011 19:25:24 +0000 (21:25 +0200)
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/disk-image.c

index 9b301c6e9974067331e065849f1c792d869b5879..a6d1e964810a5cb0d9b5c4fb565929b3b526f543 100644 (file)
@@ -6,6 +6,7 @@
 #include <inttypes.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <unistd.h>
 #define SECTOR_SHIFT           9
 #define SECTOR_SIZE            (1UL << SECTOR_SHIFT)
 
+static const char QCOW_MAGIC[] = { 'Q', 'F', 'I', 0xfb };
+
+struct qcow_header {
+       uint8_t                 magic[5];
+};
+
+static bool disk_image__is_qcow(struct disk_image *self)
+{
+       struct qcow_header *header = self->mmap;
+
+       return !memcmp(header->magic, QCOW_MAGIC, ARRAY_SIZE(QCOW_MAGIC));
+}
+
 struct disk_image *disk_image__open(const char *filename)
 {
        struct disk_image *self;
@@ -36,6 +50,9 @@ struct disk_image *disk_image__open(const char *filename)
        if (self->mmap == MAP_FAILED)
                goto failed_close_fd;
 
+       if (disk_image__is_qcow(self))
+               die("QCOW disk image format is not supported.");
+
        return self;
 
 failed_close_fd: