diff --git a/block/file-win32.c b/block/file-win32.c index 4a430d45f1..2e2f746bb1 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -553,10 +553,40 @@ static int64_t raw_get_allocated_file_size(BlockDriverState *bs) return st.st_size; } +static int raw_co_create(BlockdevCreateOptions *options, Error **errp) +{ + BlockdevCreateOptionsFile *file_opts; + int fd; + + assert(options->driver == BLOCKDEV_DRIVER_FILE); + file_opts = &options->u.file; + + if (file_opts->has_preallocation) { + error_setg(errp, "Preallocation is not supported on Windows"); + return -EINVAL; + } + if (file_opts->has_nocow) { + error_setg(errp, "nocow is not supported on Windows"); + return -EINVAL; + } + + fd = qemu_open(file_opts->filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + 0644); + if (fd < 0) { + error_setg_errno(errp, errno, "Could not create file"); + return -EIO; + } + set_sparse(fd); + ftruncate(fd, file_opts->size); + qemu_close(fd); + + return 0; +} + static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, Error **errp) { - int fd; + BlockdevCreateOptions options; int64_t total_size = 0; strstart(filename, "file:", &filename); @@ -565,19 +595,18 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts, total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); - fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - 0644); - if (fd < 0) { - error_setg_errno(errp, errno, "Could not create file"); - return -EIO; - } - set_sparse(fd); - ftruncate(fd, total_size); - qemu_close(fd); - return 0; + options = (BlockdevCreateOptions) { + .driver = BLOCKDEV_DRIVER_FILE, + .u.file = { + .filename = (char *) filename, + .size = total_size, + .has_preallocation = false, + .has_nocow = false, + }, + }; + return raw_co_create(&options, errp); } - static QemuOptsList raw_create_opts = { .name = "raw-create-opts", .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),