Revision efa84d43
b/qemu-img.c | ||
---|---|---|
215 | 215 |
return bs; |
216 | 216 |
} |
217 | 217 |
|
218 |
static void add_old_style_options(const char *fmt, QEMUOptionParameter *list, |
|
219 |
int flags, const char *base_filename, const char *base_fmt) |
|
220 |
{ |
|
221 |
if (flags & BLOCK_FLAG_ENCRYPT) { |
|
222 |
if (set_option_parameter(list, BLOCK_OPT_ENCRYPT, "on")) { |
|
223 |
error("Encryption not supported for file format '%s'", fmt); |
|
224 |
} |
|
225 |
} |
|
226 |
if (flags & BLOCK_FLAG_COMPAT6) { |
|
227 |
if (set_option_parameter(list, BLOCK_OPT_COMPAT6, "on")) { |
|
228 |
error("VMDK version 6 not supported for file format '%s'", fmt); |
|
229 |
} |
|
230 |
} |
|
231 |
|
|
232 |
if (base_filename) { |
|
233 |
if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) { |
|
234 |
error("Backing file not supported for file format '%s'", fmt); |
|
235 |
} |
|
236 |
} |
|
237 |
if (base_fmt) { |
|
238 |
if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) { |
|
239 |
error("Backing file format not supported for file format '%s'", fmt); |
|
240 |
} |
|
241 |
} |
|
242 |
} |
|
243 |
|
|
218 | 244 |
static int img_create(int argc, char **argv) |
219 | 245 |
{ |
220 | 246 |
int c, ret, flags; |
... | ... | |
279 | 305 |
} |
280 | 306 |
|
281 | 307 |
/* Add old-style options to parameters */ |
282 |
if (flags & BLOCK_FLAG_ENCRYPT) { |
|
283 |
if (set_option_parameter(param, BLOCK_OPT_ENCRYPT, "on")) { |
|
284 |
error("Encryption not supported for file format '%s'", fmt); |
|
285 |
} |
|
286 |
} |
|
287 |
if (flags & BLOCK_FLAG_COMPAT6) { |
|
288 |
if (set_option_parameter(param, BLOCK_OPT_COMPAT6, "on")) { |
|
289 |
error("VMDK version 6 not supported for file format '%s'", fmt); |
|
290 |
} |
|
291 |
} |
|
292 |
|
|
293 |
if (base_filename) { |
|
294 |
if (set_option_parameter(param, BLOCK_OPT_BACKING_FILE, base_filename)) { |
|
295 |
error("Backing file not supported for file format '%s'", fmt); |
|
296 |
} |
|
297 |
} |
|
298 |
if (base_fmt) { |
|
299 |
if (set_option_parameter(param, BLOCK_OPT_BACKING_FMT, base_fmt)) { |
|
300 |
error("Backing file format not supported for file format '%s'", fmt); |
|
301 |
} |
|
302 |
} |
|
308 |
add_old_style_options(fmt, param, flags, base_filename, base_fmt); |
|
303 | 309 |
|
304 | 310 |
// The size for the image must always be specified, with one exception: |
305 | 311 |
// If we are using a backing file, we can obtain the size from there |
... | ... | |
525 | 531 |
uint8_t buf[IO_BUF_SIZE]; |
526 | 532 |
const uint8_t *buf1; |
527 | 533 |
BlockDriverInfo bdi; |
534 |
QEMUOptionParameter *param = NULL; |
|
535 |
char *options = NULL; |
|
528 | 536 |
|
529 | 537 |
fmt = NULL; |
530 | 538 |
out_fmt = "raw"; |
531 | 539 |
out_baseimg = NULL; |
532 | 540 |
flags = 0; |
533 | 541 |
for(;;) { |
534 |
c = getopt(argc, argv, "f:O:B:hce6"); |
|
542 |
c = getopt(argc, argv, "f:O:B:hce6o:");
|
|
535 | 543 |
if (c == -1) |
536 | 544 |
break; |
537 | 545 |
switch(c) { |
... | ... | |
556 | 564 |
case '6': |
557 | 565 |
flags |= BLOCK_FLAG_COMPAT6; |
558 | 566 |
break; |
567 |
case 'o': |
|
568 |
options = optarg; |
|
569 |
break; |
|
559 | 570 |
} |
560 | 571 |
} |
561 | 572 |
|
... | ... | |
580 | 591 |
total_sectors += bs_sectors; |
581 | 592 |
} |
582 | 593 |
|
594 |
/* Find driver and parse its options */ |
|
583 | 595 |
drv = bdrv_find_format(out_fmt); |
584 | 596 |
if (!drv) |
585 | 597 |
error("Unknown file format '%s'", out_fmt); |
586 |
if (flags & BLOCK_FLAG_COMPRESS && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2")) |
|
587 |
error("Compression not supported for this file format"); |
|
588 |
if (flags & BLOCK_FLAG_ENCRYPT && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2")) |
|
589 |
error("Encryption not supported for this file format"); |
|
590 |
if (flags & BLOCK_FLAG_COMPAT6 && strcmp(drv->format_name, "vmdk")) |
|
591 |
error("Alternative compatibility level not supported for this file format"); |
|
592 |
if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) |
|
593 |
error("Compression and encryption not supported at the same time"); |
|
594 |
|
|
595 |
ret = bdrv_create2(drv, out_filename, total_sectors, out_baseimg, NULL, flags); |
|
598 |
|
|
599 |
if (options) { |
|
600 |
param = parse_option_parameters(options, drv->create_options, param); |
|
601 |
if (param == NULL) { |
|
602 |
error("Invalid options for file format '%s'.", out_fmt); |
|
603 |
} |
|
604 |
} else { |
|
605 |
param = parse_option_parameters("", drv->create_options, param); |
|
606 |
} |
|
607 |
|
|
608 |
set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512); |
|
609 |
add_old_style_options(out_fmt, param, flags, out_baseimg, NULL); |
|
610 |
|
|
611 |
/* Check if compression is supported */ |
|
612 |
if (flags & BLOCK_FLAG_COMPRESS) { |
|
613 |
QEMUOptionParameter *encryption = |
|
614 |
get_option_parameter(param, BLOCK_OPT_ENCRYPT); |
|
615 |
|
|
616 |
if (!drv->bdrv_write_compressed) { |
|
617 |
error("Compression not supported for this file format"); |
|
618 |
} |
|
619 |
|
|
620 |
if (encryption && encryption->value.n) { |
|
621 |
error("Compression and encryption not supported at the same time"); |
|
622 |
} |
|
623 |
} |
|
624 |
|
|
625 |
/* Create the new image */ |
|
626 |
ret = bdrv_create(drv, out_filename, param); |
|
627 |
free_option_parameters(param); |
|
628 |
|
|
596 | 629 |
if (ret < 0) { |
597 | 630 |
if (ret == -ENOTSUP) { |
598 | 631 |
error("Formatting not supported for file format '%s'", out_fmt); |
Also available in: Unified diff