linux-user: fix ppc target_stat64 st_blocks layout
[qemu] / block / cow.c
index 94b3549..a70854e 100644 (file)
@@ -202,15 +202,23 @@ static void cow_close(BlockDriverState *bs)
     close(s->fd);
 }
 
-static int cow_create(const char *filename, int64_t image_sectors,
-                      const char *image_filename, int flags)
+static int cow_create(const char *filename, QEMUOptionParameter *options)
 {
     int fd, cow_fd;
     struct cow_header_v2 cow_header;
     struct stat st;
-
-    if (flags)
-        return -ENOTSUP;
+    int64_t image_sectors = 0;
+    const char *image_filename = NULL;
+
+    /* Read out options */
+    while (options && options->name) {
+        if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
+            image_sectors = options->value.n / 512;
+        } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
+            image_filename = options->value.s;
+        }
+        options++;
+    }
 
     cow_fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
               0644);
@@ -250,9 +258,23 @@ static int cow_create(const char *filename, int64_t image_sectors,
 static void cow_flush(BlockDriverState *bs)
 {
     BDRVCowState *s = bs->opaque;
-    fsync(s->fd);
+    qemu_fdatasync(s->fd);
 }
 
+static QEMUOptionParameter cow_create_options[] = {
+    {
+        .name = BLOCK_OPT_SIZE,
+        .type = OPT_SIZE,
+        .help = "Virtual disk size"
+    },
+    {
+        .name = BLOCK_OPT_BACKING_FILE,
+        .type = OPT_STRING,
+        .help = "File name of a base image"
+    },
+    { NULL }
+};
+
 static BlockDriver bdrv_cow = {
     .format_name       = "cow",
     .instance_size     = sizeof(BDRVCowState),
@@ -264,6 +286,8 @@ static BlockDriver bdrv_cow = {
     .bdrv_create       = cow_create,
     .bdrv_flush                = cow_flush,
     .bdrv_is_allocated = cow_is_allocated,
+
+    .create_options = cow_create_options,
 };
 
 static void bdrv_cow_init(void)