Isolates qcow probe as part of the modularization process. Signed-off-by: Colin Lord <cl...@redhat.com> --- block/Makefile.objs | 2 +- block/probe/qcow.c | 16 ++++++++++++++++ block/qcow.c | 31 ++----------------------------- include/block/driver/qcow.h | 21 +++++++++++++++++++++ include/block/probe.h | 1 + 5 files changed, 41 insertions(+), 30 deletions(-) create mode 100644 block/probe/qcow.c create mode 100644 include/block/driver/qcow.h
diff --git a/block/Makefile.objs b/block/Makefile.objs index 12607db..9458da8 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -25,7 +25,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += probe/bochs.o probe/cloop.o probe/luks.o probe/dmg.o -block-obj-y += probe/parallels.o +block-obj-y += probe/parallels.o probe/qcow.o common-obj-y += stream.o common-obj-y += commit.o diff --git a/block/probe/qcow.c b/block/probe/qcow.c new file mode 100644 index 0000000..6024d11 --- /dev/null +++ b/block/probe/qcow.c @@ -0,0 +1,16 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "block/driver/qcow.h" + +int qcow_probe(const uint8_t *buf, int buf_size, const char *filename) +{ + const QCowHeader *cow_header = (const void *)buf; + + if (buf_size >= sizeof(QCowHeader) && + be32_to_cpu(cow_header->magic) == QCOW_MAGIC && + be32_to_cpu(cow_header->version) == QCOW_VERSION) + return 100; + else + return 0; +} diff --git a/block/qcow.c b/block/qcow.c index 312af52..828749c 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -26,6 +26,8 @@ #include "qemu-common.h" #include "qemu/error-report.h" #include "block/block_int.h" +#include "block/probe.h" +#include "block/driver/qcow.h" #include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/bswap.h" @@ -37,28 +39,11 @@ /**************************************************************/ /* QEMU COW block driver with compression and encryption support */ -#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) -#define QCOW_VERSION 1 - #define QCOW_CRYPT_NONE 0 #define QCOW_CRYPT_AES 1 #define QCOW_OFLAG_COMPRESSED (1LL << 63) -typedef struct QCowHeader { - uint32_t magic; - uint32_t version; - uint64_t backing_file_offset; - uint32_t backing_file_size; - uint32_t mtime; - uint64_t size; /* in bytes */ - uint8_t cluster_bits; - uint8_t l2_bits; - uint16_t padding; - uint32_t crypt_method; - uint64_t l1_table_offset; -} QEMU_PACKED QCowHeader; - #define L2_CACHE_SIZE 16 typedef struct BDRVQcowState { @@ -85,18 +70,6 @@ typedef struct BDRVQcowState { static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset); -static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename) -{ - const QCowHeader *cow_header = (const void *)buf; - - if (buf_size >= sizeof(QCowHeader) && - be32_to_cpu(cow_header->magic) == QCOW_MAGIC && - be32_to_cpu(cow_header->version) == QCOW_VERSION) - return 100; - else - return 0; -} - static int qcow_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { diff --git a/include/block/driver/qcow.h b/include/block/driver/qcow.h new file mode 100644 index 0000000..c96ea24 --- /dev/null +++ b/include/block/driver/qcow.h @@ -0,0 +1,21 @@ +#ifndef QCOW_H +#define QCOW_H + +#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) +#define QCOW_VERSION 1 + +typedef struct QCowHeader { + uint32_t magic; + uint32_t version; + uint64_t backing_file_offset; + uint32_t backing_file_size; + uint32_t mtime; + uint64_t size; /* in bytes */ + uint8_t cluster_bits; + uint8_t l2_bits; + uint16_t padding; + uint32_t crypt_method; + uint64_t l1_table_offset; +} QEMU_PACKED QCowHeader; + +#endif diff --git a/include/block/probe.h b/include/block/probe.h index f8b0984..5230da4 100644 --- a/include/block/probe.h +++ b/include/block/probe.h @@ -7,5 +7,6 @@ int block_crypto_probe_luks(const uint8_t *buf, int buf_size, const char *filename); int dmg_probe(const uint8_t *buf, int buf_size, const char *filename); int parallels_probe(const uint8_t *buf, int buf_size, const char *filename); +int qcow_probe(const uint8_t *buf, int buf_size, const char *filename); #endif -- 2.5.5