Revision 91a073a9

b/block.c
184 184
    return NULL;
185 185
}
186 186

  
187
int bdrv_create2(BlockDriver *drv,
188
                const char *filename, int64_t size_in_sectors,
189
                const char *backing_file, const char *backing_format,
190
                int flags)
191
{
192
    QEMUOptionParameter *options;
193

  
194
    options = parse_option_parameters("", drv->create_options, NULL);
195

  
196
    // Process flags
197
    if (flags & ~(BLOCK_FLAG_ENCRYPT | BLOCK_FLAG_COMPAT6 | BLOCK_FLAG_COMPRESS)) {
198
        return -ENOTSUP;
199
    }
200

  
201
    if (flags & BLOCK_FLAG_ENCRYPT) {
202
        set_option_parameter_int(options, BLOCK_OPT_ENCRYPT, 1);
203
    }
204
    if (flags & BLOCK_FLAG_COMPAT6) {
205
        set_option_parameter_int(options, BLOCK_OPT_COMPAT6, 1);
206
    }
207

  
208
    // Add size to options
209
    set_option_parameter_int(options, BLOCK_OPT_SIZE, size_in_sectors * 512);
210

  
211
    // Backing files
212
    if ((backing_file != NULL && set_option_parameter(options,
213
            BLOCK_OPT_BACKING_FILE, backing_file))
214
        || (backing_format != NULL && set_option_parameter(options,
215
            BLOCK_OPT_BACKING_FMT, backing_format)))
216
    {
217
        return -ENOTSUP;
218
    }
219

  
220
    return bdrv_create(drv, filename, options);
221
}
222

  
223 187
int bdrv_create(BlockDriver *drv, const char* filename,
224 188
    QEMUOptionParameter *options)
225 189
{
......
392 356
        BlockDriverState *bs1;
393 357
        int64_t total_size;
394 358
        int is_protocol = 0;
359
        BlockDriver *bdrv_qcow2;
360
        QEMUOptionParameter *options;
395 361

  
396 362
        /* if snapshot, we create a temporary backing file and open it
397 363
           instead of opening 'filename' directly */
......
419 385
        else
420 386
            realpath(filename, backing_filename);
421 387

  
422
        ret = bdrv_create2(bdrv_find_format("qcow2"), tmp_filename,
423
                           total_size, backing_filename, 
424
                           (drv ? drv->format_name : NULL), 0);
388
        bdrv_qcow2 = bdrv_find_format("qcow2");
389
        options = parse_option_parameters("", bdrv_qcow2->create_options, NULL);
390

  
391
        set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size * 512);
392
        set_option_parameter(options, BLOCK_OPT_BACKING_FILE, backing_filename);
393
        if (drv) {
394
            set_option_parameter(options, BLOCK_OPT_BACKING_FMT,
395
                drv->format_name);
396
        }
397

  
398
        ret = bdrv_create(bdrv_qcow2, tmp_filename, options);
425 399
        if (ret < 0) {
426 400
            return ret;
427 401
        }
402

  
428 403
        filename = tmp_filename;
429
        drv = bdrv_find_format("qcow2");
404
        drv = bdrv_qcow2;
430 405
        bs->is_temporary = 1;
431 406
    }
432 407

  
b/block/vvfat.c
2770 2770

  
2771 2771
static int enable_write_target(BDRVVVFATState *s)
2772 2772
{
2773
    BlockDriver *bdrv_qcow;
2774
    QEMUOptionParameter *options;
2773 2775
    int size = sector2cluster(s, s->sector_count);
2774 2776
    s->used_clusters = calloc(size, 1);
2775 2777

  
......
2777 2779

  
2778 2780
    s->qcow_filename = qemu_malloc(1024);
2779 2781
    get_tmp_filename(s->qcow_filename, 1024);
2780
    if (bdrv_create2(bdrv_find_format("qcow"),
2781
		s->qcow_filename, s->sector_count, "fat:", NULL, 0) < 0)
2782

  
2783
    bdrv_qcow = bdrv_find_format("qcow");
2784
    options = parse_option_parameters("", bdrv_qcow->create_options, NULL);
2785
    set_option_parameter_int(options, BLOCK_OPT_SIZE, s->sector_count * 512);
2786
    set_option_parameter(options, BLOCK_OPT_BACKING_FILE, "fat:");
2787

  
2788
    if (bdrv_create(bdrv_qcow, s->qcow_filename, options) < 0)
2782 2789
	return -1;
2783 2790
    s->qcow = bdrv_new("");
2784 2791
    if (s->qcow == NULL || bdrv_open(s->qcow, s->qcow_filename, 0) < 0)

Also available in: Unified diff