Isolate parallels probe as part of the modularization process. Signed-off-by: Colin Lord <cl...@redhat.com> --- block/Makefile.objs | 1 + block/parallels.c | 43 ++-------------------------------------- block/probe/parallels.c | 22 ++++++++++++++++++++ include/block/driver/parallels.h | 26 ++++++++++++++++++++++++ include/block/probe.h | 1 + 5 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 block/probe/parallels.c create mode 100644 include/block/driver/parallels.h
diff --git a/block/Makefile.objs b/block/Makefile.objs index 1d744eb..12607db 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 += probe/bochs.o probe/cloop.o probe/luks.o probe/dmg.o +block-obj-y += probe/parallels.o common-obj-y += stream.o common-obj-y += commit.o diff --git a/block/parallels.c b/block/parallels.c index d6a1a61..547373e 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 "block/driver/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/probe/parallels.c b/block/probe/parallels.c new file mode 100644 index 0000000..66cddea --- /dev/null +++ b/block/probe/parallels.c @@ -0,0 +1,22 @@ +#include "qemu/osdep.h" +#include "block/block_int.h" +#include "block/probe.h" +#include "block/driver/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/include/block/driver/parallels.h b/include/block/driver/parallels.h new file mode 100644 index 0000000..512ef5f --- /dev/null +++ b/include/block/driver/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