mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-06 05:31:50 +00:00
kvm: Fail if user specifies a QCOW disk image
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
committed by
Will Deacon
parent
e907b83f28
commit
5646450daa
@@ -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>
|
||||
@@ -14,6 +15,19 @@
|
||||
#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:
|
||||
|
||||
Reference in New Issue
Block a user