From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33150) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKSDW-00064w-RO for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:24:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKSDU-00005a-Bl for qemu-devel@nongnu.org; Tue, 05 Jul 2016 11:24:53 -0400 From: Colin Lord Date: Tue, 5 Jul 2016 11:24:14 -0400 Message-Id: <1467732272-23368-15-git-send-email-clord@redhat.com> In-Reply-To: <1467732272-23368-1-git-send-email-clord@redhat.com> References: <1467732272-23368-1-git-send-email-clord@redhat.com> Subject: [Qemu-devel] [PATCH v3 14/32] blockdev: Move vhdx probe to its own file List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com, Colin Lord Isolates vhdx probe as part of the modularization process. Signed-off-by: Colin Lord --- block/Makefile.objs | 2 +- block/probe/vhdx.c | 21 +++++++++++++++++++++ block/vhdx.c | 20 +------------------- include/block/probe.h | 1 + 4 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 block/probe/vhdx.c diff --git a/block/Makefile.objs b/block/Makefile.objs index 4a5bd88..89e0da4 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -26,7 +26,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 probe/qcow.o probe/qcow2.o probe/qed.o -block-obj-y += probe/raw.o probe/vdi.o +block-obj-y += probe/raw.o probe/vdi.o probe/vhdx.o common-obj-y += stream.o common-obj-y += commit.o diff --git a/block/probe/vhdx.c b/block/probe/vhdx.c new file mode 100644 index 0000000..6c38aac --- /dev/null +++ b/block/probe/vhdx.c @@ -0,0 +1,21 @@ +#include "qemu/osdep.h" +#include "block/probe.h" + +/* + * Per the MS VHDX Specification, for every VHDX file: + * - The header section is fixed size - 1 MB + * - The header section is always the first "object" + * - The first 64KB of the header is the File Identifier + * - The first uint64 (8 bytes) is the VHDX Signature ("vhdxfile") + * - The following 512 bytes constitute a UTF-16 string identifiying the + * software that created the file, and is optional and diagnostic only. + * + * Therefore, we probe by looking for the vhdxfile signature "vhdxfile" + */ +int vhdx_probe(const uint8_t *buf, int buf_size, const char *filename) +{ + if (buf_size >= 8 && !memcmp(buf, "vhdxfile", 8)) { + return 100; + } + return 0; +} diff --git a/block/vhdx.c b/block/vhdx.c index f5605a2..ba8adfe 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -19,6 +19,7 @@ #include "qapi/error.h" #include "qemu-common.h" #include "block/block_int.h" +#include "block/probe.h" #include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/crc32c.h" @@ -273,25 +274,6 @@ static void vhdx_set_shift_bits(BDRVVHDXState *s) } /* - * Per the MS VHDX Specification, for every VHDX file: - * - The header section is fixed size - 1 MB - * - The header section is always the first "object" - * - The first 64KB of the header is the File Identifier - * - The first uint64 (8 bytes) is the VHDX Signature ("vhdxfile") - * - The following 512 bytes constitute a UTF-16 string identifiying the - * software that created the file, and is optional and diagnostic only. - * - * Therefore, we probe by looking for the vhdxfile signature "vhdxfile" - */ -static int vhdx_probe(const uint8_t *buf, int buf_size, const char *filename) -{ - if (buf_size >= 8 && !memcmp(buf, "vhdxfile", 8)) { - return 100; - } - return 0; -} - -/* * Writes the header to the specified offset. * * This will optionally read in buffer data from disk (otherwise zero-fill), diff --git a/include/block/probe.h b/include/block/probe.h index f85c178..e901d8f 100644 --- a/include/block/probe.h +++ b/include/block/probe.h @@ -12,5 +12,6 @@ int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename); int bdrv_qed_probe(const uint8_t *buf, int buf_size, const char *filename); int raw_probe(const uint8_t *buf, int buf_size, const char *filename); int vdi_probe(const uint8_t *buf, int buf_size, const char *filename); +int vhdx_probe(const uint8_t *buf, int buf_size, const char *filename); #endif -- 2.5.5