Signed-off-by: Dong Xu Wang <wdon...@linux.vnet.ibm.com>
---
 block/raw-win32.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/block/raw-win32.c b/block/raw-win32.c
index 9b5b2af..78efc63 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -452,6 +452,40 @@ static QEMUOptionParameter raw_create_options[] = {
     { NULL }
 };
 
+
+static int raw_create_new(const char *filename, QemuOpts *opts)
+{
+    int fd;
+    int64_t total_size = 0;
+
+    /* Read out options */
+
+    total_size =
+        qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / 512;
+
+    fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
+                   0644);
+    if (fd < 0)
+        return -EIO;
+    set_sparse(fd);
+    ftruncate(fd, total_size * 512);
+    qemu_close(fd);
+    return 0;
+}
+
+static QemuOptsList raw_create_opts = {
+    .name = "raw-create-opts",
+    .head = QTAILQ_HEAD_INITIALIZER(raw_create_opts.head),
+    .desc = {
+        {
+            .name = BLOCK_OPT_SIZE,
+            .type = QEMU_OPT_SIZE,
+            .help = "Virtual disk size"
+        },
+        { /* end of list */ }
+    }
+};
+
 static BlockDriver bdrv_file = {
     .format_name       = "file",
     .protocol_name     = "file",
@@ -459,6 +493,7 @@ static BlockDriver bdrv_file = {
     .bdrv_file_open    = raw_open,
     .bdrv_close                = raw_close,
     .bdrv_create       = raw_create,
+    .bdrv_create_new = raw_create_new,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
 
     .bdrv_aio_readv     = raw_aio_readv,
@@ -471,6 +506,7 @@ static BlockDriver bdrv_file = {
                         = raw_get_allocated_file_size,
 
     .create_options = raw_create_options,
+    .bdrv_create_opts   = &raw_create_opts,
 };
 
 /***********************************************/
-- 
1.7.11.7


Reply via email to