*/
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
/**************************************************************/
close(s->fd);
}
-BlockDriver bdrv_bochs = {
+static BlockDriver bdrv_bochs = {
.format_name = "bochs",
.instance_size = sizeof(BDRVBochsState),
.bdrv_probe = bochs_probe,
.bdrv_read = bochs_read,
.bdrv_close = bochs_close,
};
+
+static void bdrv_bochs_init(void)
+{
+ bdrv_register(&bdrv_bochs);
+}
+
+block_init(bdrv_bochs_init);
*/
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
#include <zlib.h>
typedef struct BDRVCloopState {
inflateEnd(&s->zstream);
}
-BlockDriver bdrv_cloop = {
+static BlockDriver bdrv_cloop = {
.format_name = "cloop",
.instance_size = sizeof(BDRVCloopState),
.bdrv_probe = cloop_probe,
.bdrv_read = cloop_read,
.bdrv_close = cloop_close,
};
+
+static void bdrv_cloop_init(void)
+{
+ bdrv_register(&bdrv_cloop);
+}
+
+block_init(bdrv_cloop_init);
#ifndef _WIN32
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
#include <sys/mman.h>
/**************************************************************/
fsync(s->fd);
}
-BlockDriver bdrv_cow = {
+static BlockDriver bdrv_cow = {
.format_name = "cow",
.instance_size = sizeof(BDRVCowState),
.bdrv_probe = cow_probe,
.bdrv_flush = cow_flush,
.bdrv_is_allocated = cow_is_allocated,
};
+
+static void bdrv_cow_init(void)
+{
+ bdrv_register(&bdrv_cow);
+}
+
+block_init(bdrv_cow_init);
#endif
#include "qemu-common.h"
#include "block_int.h"
#include "bswap.h"
+#include "module.h"
#include <zlib.h>
typedef struct BDRVDMGState {
dmg_close:
close(s->fd);
/* open raw instead */
- bs->drv=&bdrv_raw;
+ bs->drv=bdrv_find_format("raw");
return bs->drv->bdrv_open(bs, filename, flags);
}
info_begin=read_off(s->fd);
inflateEnd(&s->zstream);
}
-BlockDriver bdrv_dmg = {
+static BlockDriver bdrv_dmg = {
.format_name = "dmg",
.instance_size = sizeof(BDRVDMGState),
.bdrv_probe = dmg_probe,
.bdrv_read = dmg_read,
.bdrv_close = dmg_close,
};
+
+static void bdrv_dmg_init(void)
+{
+ bdrv_register(&bdrv_dmg);
+}
+
+block_init(bdrv_dmg_init);
#include "qemu-common.h"
#include "nbd.h"
+#include "module.h"
#include <sys/types.h>
#include <unistd.h>
return s->size;
}
-BlockDriver bdrv_nbd = {
+static BlockDriver bdrv_nbd = {
.format_name = "nbd",
.instance_size = sizeof(BDRVNBDState),
.bdrv_open = nbd_open,
.bdrv_getlength = nbd_getlength,
.protocol_name = "nbd",
};
+
+static void bdrv_nbd_init(void)
+{
+ bdrv_register(&bdrv_nbd);
+}
+
+block_init(bdrv_nbd_init);
*/
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
/**************************************************************/
close(s->fd);
}
-BlockDriver bdrv_parallels = {
+static BlockDriver bdrv_parallels = {
.format_name = "parallels",
.instance_size = sizeof(BDRVParallelsState),
.bdrv_probe = parallels_probe,
.bdrv_read = parallels_read,
.bdrv_close = parallels_close,
};
+
+static void bdrv_parallels_init(void)
+{
+ bdrv_register(&bdrv_parallels);
+}
+
+block_init(bdrv_parallels_init);
*/
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
#include <zlib.h>
#include "aes.h"
return 0;
}
-BlockDriver bdrv_qcow = {
+static BlockDriver bdrv_qcow = {
.format_name = "qcow",
.instance_size = sizeof(BDRVQcowState),
.bdrv_probe = qcow_probe,
.bdrv_write_compressed = qcow_write_compressed,
.bdrv_get_info = qcow_get_info,
};
+
+static void bdrv_qcow_init(void)
+{
+ bdrv_register(&bdrv_qcow);
+}
+
+block_init(bdrv_qcow_init);
*/
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
#include <zlib.h>
#include "aes.h"
return ret;
}
-BlockDriver bdrv_qcow2 = {
+static BlockDriver bdrv_qcow2 = {
.format_name = "qcow2",
.instance_size = sizeof(BDRVQcowState),
.bdrv_probe = qcow_probe,
.bdrv_create2 = qcow_create2,
.bdrv_check = qcow_check,
};
+
+static void bdrv_qcow2_init(void)
+{
+ bdrv_register(&bdrv_qcow2);
+}
+
+block_init(bdrv_qcow2_init);
#include "qemu-timer.h"
#include "qemu-char.h"
#include "block_int.h"
+#include "module.h"
#ifdef CONFIG_AIO
#include "posix-aio-compat.h"
#endif
fsync(s->fd);
}
-BlockDriver bdrv_raw = {
+static BlockDriver bdrv_raw = {
.format_name = "raw",
.instance_size = sizeof(BDRVRawState),
.bdrv_probe = NULL, /* no probe for protocols */
}
#endif
-BlockDriver bdrv_host_device = {
+static BlockDriver bdrv_host_device = {
.format_name = "host_device",
.instance_size = sizeof(BDRVRawState),
.bdrv_open = hdev_open,
.bdrv_aio_ioctl = raw_aio_ioctl,
#endif
};
+
+static void bdrv_raw_init(void)
+{
+ bdrv_register(&bdrv_raw);
+ bdrv_register(&bdrv_host_device);
+}
+
+block_init(bdrv_raw_init);
#include "qemu-common.h"
#include "qemu-timer.h"
#include "block_int.h"
+#include "module.h"
#include <windows.h>
#include <winioctl.h>
return 0;
}
-BlockDriver bdrv_raw = {
+static BlockDriver bdrv_raw = {
.format_name = "raw",
.instance_size = sizeof(BDRVRawState),
.bdrv_open = raw_open,
}
#endif
-BlockDriver bdrv_host_device = {
+static BlockDriver bdrv_host_device = {
.format_name = "host_device",
.instance_size = sizeof(BDRVRawState),
.bdrv_open = hdev_open,
.bdrv_write = raw_write,
.bdrv_getlength = raw_getlength,
};
+
+static void bdrv_raw_init(void)
+{
+ bdrv_register(&bdrv_raw);
+ bdrv_register(&bdrv_host_device);
+}
+
+block_init(bdrv_raw_init);
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
#define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
#define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
bdrv_flush(s->hd);
}
-BlockDriver bdrv_vmdk = {
+static BlockDriver bdrv_vmdk = {
.format_name = "vmdk",
.instance_size = sizeof(BDRVVmdkState),
.bdrv_probe = vmdk_probe,
.bdrv_flush = vmdk_flush,
.bdrv_is_allocated = vmdk_is_allocated,
};
+
+static void bdrv_vmdk_init(void)
+{
+ bdrv_register(&bdrv_vmdk);
+}
+
+block_init(bdrv_vmdk_init);
*/
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
/**************************************************************/
bdrv_delete(s->hd);
}
-BlockDriver bdrv_vpc = {
+static BlockDriver bdrv_vpc = {
.format_name = "vpc",
.instance_size = sizeof(BDRVVPCState),
.bdrv_probe = vpc_probe,
.bdrv_close = vpc_close,
.bdrv_create = vpc_create,
};
+
+static void bdrv_vpc_init(void)
+{
+ bdrv_register(&bdrv_vpc);
+}
+
+block_init(bdrv_vpc_init);
#include <dirent.h>
#include "qemu-common.h"
#include "block_int.h"
+#include "module.h"
#ifndef S_IWGRP
#define S_IWGRP 0
s->qcow_filename = qemu_malloc(1024);
get_tmp_filename(s->qcow_filename, 1024);
- if (bdrv_create(&bdrv_qcow,
+ if (bdrv_create(bdrv_find_format("qcow"),
s->qcow_filename, s->sector_count, "fat:", 0) < 0)
return -1;
s->qcow = bdrv_new("");
free(s->cluster_buffer);
}
-BlockDriver bdrv_vvfat = {
+static BlockDriver bdrv_vvfat = {
.format_name = "vvfat",
.instance_size = sizeof(BDRVVVFATState),
.bdrv_open = vvfat_open,
.protocol_name = "fat",
};
+static void bdrv_vvfat_init(void)
+{
+ bdrv_register(&bdrv_vvfat);
+}
+
+block_init(bdrv_vvfat_init);
+
#ifdef DEBUG
static void checkpoint(void) {
assert(((mapping_t*)array_get(&(vvv->mapping), 0))->end == 2);
#include "qemu-common.h"
#include "monitor.h"
#include "block_int.h"
+#include "module.h"
#ifdef HOST_BSD
#include <sys/types.h>
}
-static void bdrv_register(BlockDriver *bdrv)
+void bdrv_register(BlockDriver *bdrv)
{
if (!bdrv->bdrv_aio_readv) {
/* add AIO emulation layer */
#ifdef _WIN32
if (is_windows_drive(filename) ||
is_windows_drive_prefix(filename))
- return &bdrv_raw;
+ return bdrv_find_format("raw");
#endif
p = strchr(filename, ':');
if (!p)
- return &bdrv_raw;
+ return bdrv_find_format("raw");
len = p - filename;
if (len > sizeof(protocol) - 1)
len = sizeof(protocol) - 1;
/* detect host devices. By convention, /dev/cdrom[N] is always
recognized as a host CDROM */
if (strstart(filename, "/dev/cdrom", NULL))
- return &bdrv_host_device;
+ return bdrv_find_format("host_device");
#ifdef _WIN32
if (is_windows_drive(filename))
- return &bdrv_host_device;
+ return bdrv_find_format("host_device");
#else
{
struct stat st;
if (stat(filename, &st) >= 0 &&
(S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
- return &bdrv_host_device;
+ return bdrv_find_format("host_device");
}
}
#endif
drv = find_protocol(filename);
/* no need to test disk image formats for vvfat */
- if (drv == &bdrv_vvfat)
+ if (strcmp(drv->format_name, "vvfat") == 0)
return drv;
ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
else
realpath(filename, backing_filename);
- ret = bdrv_create2(&bdrv_qcow2, tmp_filename,
+ ret = bdrv_create2(bdrv_find_format("qcow2"), tmp_filename,
total_size, backing_filename,
(drv ? drv->format_name : NULL), 0);
if (ret < 0) {
return ret;
}
filename = tmp_filename;
- drv = &bdrv_qcow2;
+ drv = bdrv_find_format("qcow2");
bs->is_temporary = 1;
}
void bdrv_init(void)
{
- bdrv_register(&bdrv_raw);
- bdrv_register(&bdrv_host_device);
-#ifndef _WIN32
- bdrv_register(&bdrv_cow);
-#endif
- bdrv_register(&bdrv_qcow);
- bdrv_register(&bdrv_vmdk);
- bdrv_register(&bdrv_cloop);
- bdrv_register(&bdrv_dmg);
- bdrv_register(&bdrv_bochs);
- bdrv_register(&bdrv_vpc);
- bdrv_register(&bdrv_vvfat);
- bdrv_register(&bdrv_qcow2);
- bdrv_register(&bdrv_parallels);
- bdrv_register(&bdrv_nbd);
+ module_call_init(MODULE_INIT_BLOCK);
}
void aio_pool_init(AIOPool *pool, int aiocb_size,
/* block.c */
typedef struct BlockDriver BlockDriver;
-extern BlockDriver bdrv_raw;
-extern BlockDriver bdrv_host_device;
-extern BlockDriver bdrv_cow;
-extern BlockDriver bdrv_qcow;
-extern BlockDriver bdrv_vmdk;
-extern BlockDriver bdrv_cloop;
-extern BlockDriver bdrv_dmg;
-extern BlockDriver bdrv_bochs;
-extern BlockDriver bdrv_vpc;
-extern BlockDriver bdrv_vvfat;
-extern BlockDriver bdrv_qcow2;
-extern BlockDriver bdrv_parallels;
-extern BlockDriver bdrv_nbd;
-
typedef struct BlockDriverInfo {
/* in bytes, 0 if irrelevant */
int cluster_size;
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
int bdrv_commit(BlockDriverState *bs);
+void bdrv_register(BlockDriver *bdrv);
+
/* async block I/O */
typedef struct BlockDriverAIOCB BlockDriverAIOCB;
typedef void BlockDriverCompletionFunc(void *opaque, int ret);
drv = bdrv_find_format(out_fmt);
if (!drv)
error("Unknown file format '%s'", out_fmt);
- if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2)
+ if (flags & BLOCK_FLAG_COMPRESS && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2"))
error("Compression not supported for this file format");
- if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2)
+ if (flags & BLOCK_FLAG_ENCRYPT && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2"))
error("Encryption not supported for this file format");
- if (flags & BLOCK_FLAG_COMPAT6 && drv != &bdrv_vmdk)
+ if (flags & BLOCK_FLAG_COMPAT6 && strcmp(drv->format_name, "vmdk"))
error("Alternative compatibility level not supported for this file format");
if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS)
error("Compression and encryption not supported at the same time");
if (n > bs_offset + bs_sectors - sector_num)
n = bs_offset + bs_sectors - sector_num;
- if (drv != &bdrv_host_device) {
+ if (strcmp(drv->format_name, "host_device")) {
if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
n, &n1)) {
sector_num += n1;
If the output is to a host device, we also write out
sectors that are entirely 0, since whatever data was
already there is garbage, not 0s. */
- if (drv == &bdrv_host_device || out_baseimg ||
+ if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg ||
is_allocated_sectors(buf1, n, &n1)) {
if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
error("error while writing");