Isolate parallels probe as part of the modularization process. Signed-off-by: Colin Lord <cl...@redhat.com> Reviewed-by: Max Reitz <mre...@redhat.com> --- block/Makefile.objs | 1 + block/parallels-probe.c | 21 +++++++++++++++++++++ block/parallels.c | 43 ++----------------------------------------- block/parallels.h | 26 ++++++++++++++++++++++++++ include/block/probe.h | 1 + 5 files changed, 51 insertions(+), 41 deletions(-) create mode 100644 block/parallels-probe.c create mode 100644 block/parallels.h
diff --git a/block/Makefile.objs b/block/Makefile.objs index 09cc64c..43724ec 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -25,6 +25,7 @@ block-obj-y += write-threshold.o block-obj-y += crypto.o block-obj-y += bochs-probe.o cloop-probe.o crypto-probe.o dmg-probe.o +block-obj-y += parallels-probe.o common-obj-y += stream.o common-obj-y += backup.o diff --git a/block/parallels-probe.c b/block/parallels-probe.c new file mode 100644 index 0000000..ff2f6ba --- /dev/null +++ b/block/parallels-probe.c @@ -0,0 +1,21 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "parallels.h" + +int parallels_probe(const uint8_t *buf, int buf_size, const char *filename) +{ + const ParallelsHeader *ph = (const void *)buf; + + if (buf_size < sizeof(ParallelsHeader)) { + return 0; + } + + if ((!memcmp(ph->magic, HEADER_MAGIC, 16) || + !memcmp(ph->magic, HEADER_MAGIC2, 16)) && + (le32_to_cpu(ph->version) == HEADER_VERSION)) { + return 100; + } + + return 0; +} diff --git a/block/parallels.c b/block/parallels.c index 807a801..70e9439 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -31,6 +31,8 @@ #include "qapi/error.h" #include "qemu-common.h" #include "block/block_int.h" +#include "block/probe.h" +#include "parallels.h" #include "sysemu/block-backend.h" #include "qemu/module.h" #include "qemu/bswap.h" @@ -39,29 +41,6 @@ /**************************************************************/ -#define HEADER_MAGIC "WithoutFreeSpace" -#define HEADER_MAGIC2 "WithouFreSpacExt" -#define HEADER_VERSION 2 -#define HEADER_INUSE_MAGIC (0x746F6E59) - -#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ - - -// always little-endian -typedef struct ParallelsHeader { - char magic[16]; // "WithoutFreeSpace" - uint32_t version; - uint32_t heads; - uint32_t cylinders; - uint32_t tracks; - uint32_t bat_entries; - uint64_t nb_sectors; - uint32_t inuse; - uint32_t data_off; - char padding[12]; -} QEMU_PACKED ParallelsHeader; - - typedef enum ParallelsPreallocMode { PRL_PREALLOC_MODE_FALLOCATE = 0, PRL_PREALLOC_MODE_TRUNCATE = 1, @@ -536,24 +515,6 @@ exit: } -static int parallels_probe(const uint8_t *buf, int buf_size, - const char *filename) -{ - const ParallelsHeader *ph = (const void *)buf; - - if (buf_size < sizeof(ParallelsHeader)) { - return 0; - } - - if ((!memcmp(ph->magic, HEADER_MAGIC, 16) || - !memcmp(ph->magic, HEADER_MAGIC2, 16)) && - (le32_to_cpu(ph->version) == HEADER_VERSION)) { - return 100; - } - - return 0; -} - static int parallels_update_header(BlockDriverState *bs) { BDRVParallelsState *s = bs->opaque; diff --git a/block/parallels.h b/block/parallels.h new file mode 100644 index 0000000..512ef5f --- /dev/null +++ b/block/parallels.h @@ -0,0 +1,26 @@ +#ifndef PARALLELS_H +#define PARALLELS_H + +#define HEADER_MAGIC "WithoutFreeSpace" +#define HEADER_MAGIC2 "WithouFreSpacExt" +#define HEADER_VERSION 2 +#define HEADER_INUSE_MAGIC (0x746F6E59) + +#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ + + +// always little-endian +typedef struct ParallelsHeader { + char magic[16]; // "WithoutFreeSpace" + uint32_t version; + uint32_t heads; + uint32_t cylinders; + uint32_t tracks; + uint32_t bat_entries; + uint64_t nb_sectors; + uint32_t inuse; + uint32_t data_off; + char padding[12]; +} QEMU_PACKED ParallelsHeader; + +#endif diff --git a/include/block/probe.h b/include/block/probe.h index 267431d..f8b0984 100644 --- a/include/block/probe.h +++ b/include/block/probe.h @@ -6,5 +6,6 @@ int cloop_probe(const uint8_t *buf, int buf_size, const char *filename); 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); #endif -- 2.5.5