*/
#include "qemu/osdep.h"
-#include "hw/hw.h"
#include "hw/block/fdc.h"
#include "qapi/error.h"
#include "qemu/error-report.h"
#include "qemu/timer.h"
+#include "hw/irq.h"
#include "hw/isa/isa.h"
+#include "hw/qdev-properties.h"
#include "hw/sysbus.h"
+#include "migration/vmstate.h"
#include "hw/block/block.h"
#include "sysemu/block-backend.h"
#include "sysemu/blockdev.h"
#include "sysemu/sysemu.h"
#include "qemu/log.h"
+#include "qemu/main-loop.h"
+#include "qemu/module.h"
#include "trace.h"
/********************************************************/
FloppyDrive *dev = FLOPPY_DRIVE(qdev);
FloppyBus *bus = FLOPPY_BUS(qdev->parent_bus);
FDrive *drive;
+ bool read_only;
int ret;
if (dev->unit == -1) {
if (!dev->conf.blk) {
/* Anonymous BlockBackend for an empty drive */
- dev->conf.blk = blk_new(0, BLK_PERM_ALL);
+ dev->conf.blk = blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL);
ret = blk_attach_dev(dev->conf.blk, qdev);
assert(ret == 0);
+
+ /* Don't take write permissions on an empty drive to allow attaching a
+ * read-only node later */
+ read_only = true;
+ } else {
+ read_only = !blk_bs(dev->conf.blk) || blk_is_read_only(dev->conf.blk);
}
blkconf_blocksizes(&dev->conf);
dev->conf.rerror = BLOCKDEV_ON_ERROR_AUTO;
dev->conf.werror = BLOCKDEV_ON_ERROR_AUTO;
- if (!blkconf_apply_backend_options(&dev->conf,
- blk_is_read_only(dev->conf.blk),
- false, errp)) {
+ if (!blkconf_apply_backend_options(&dev->conf, read_only, false, errp)) {
return;
}
k->realize = floppy_drive_realize;
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
k->bus_type = TYPE_FLOPPY_BUS;
- k->props = floppy_drive_properties;
+ device_class_set_props(k, floppy_drive_properties);
k->desc = "virtual floppy drive";
}
FLOPPY_DPRINTF("init controller\n");
fdctrl->fifo = qemu_memalign(512, FD_SECTOR_LEN);
+ memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
fdctrl->fifo_size = 512;
fdctrl->result_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
fdctrl_result_timer, fdctrl);
dc->fw_name = "fdc";
dc->reset = fdctrl_external_reset_isa;
dc->vmsd = &vmstate_isa_fdc;
- dc->props = isa_fdc_properties;
+ device_class_set_props(dc, isa_fdc_properties);
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
}
{
DeviceClass *dc = DEVICE_CLASS(klass);
- dc->props = sysbus_fdc_properties;
+ device_class_set_props(dc, sysbus_fdc_properties);
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
}
{
DeviceClass *dc = DEVICE_CLASS(klass);
- dc->props = sun4m_fdc_properties;
+ device_class_set_props(dc, sun4m_fdc_properties);
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
}