223
static void add_old_style_options(const char *fmt, QEMUOptionParameter *list,
224
int flags, const char *base_filename, const char *base_fmt)
226
if (flags & BLOCK_FLAG_ENCRYPT) {
227
if (set_option_parameter(list, BLOCK_OPT_ENCRYPT, "on")) {
228
error("Encryption not supported for file format '%s'", fmt);
231
if (flags & BLOCK_FLAG_COMPAT6) {
232
if (set_option_parameter(list, BLOCK_OPT_COMPAT6, "on")) {
233
error("VMDK version 6 not supported for file format '%s'", fmt);
238
if (set_option_parameter(list, BLOCK_OPT_BACKING_FILE, base_filename)) {
239
error("Backing file not supported for file format '%s'", fmt);
243
if (set_option_parameter(list, BLOCK_OPT_BACKING_FMT, base_fmt)) {
244
error("Backing file format not supported for file format '%s'", fmt);
218
249
static int img_create(int argc, char **argv)
220
251
int c, ret, flags;
252
282
flags |= BLOCK_FLAG_COMPAT6;
258
filename = argv[optind++];
261
BlockDriverState *bs;
262
BlockDriver *base_drv = NULL;
265
base_drv = bdrv_find_format(base_fmt);
266
if (base_drv == NULL)
267
error("Unknown basefile format '%s'", base_fmt);
270
bs = bdrv_new_open(base_filename, base_fmt);
271
bdrv_get_geometry(bs, &size);
278
sizef = strtod(p, (char **)&p);
280
size = (uint64_t)(sizef * 1024 * 1024);
281
} else if (*p == 'G') {
282
size = (uint64_t)(sizef * 1024 * 1024 * 1024);
283
} else if (*p == 'k' || *p == 'K' || *p == '\0') {
284
size = (uint64_t)(sizef * 1024);
290
/* Find driver and parse its options */
289
291
drv = bdrv_find_format(fmt);
291
293
error("Unknown file format '%s'", fmt);
292
printf("Formatting '%s', fmt=%s",
294
if (flags & BLOCK_FLAG_ENCRYPT)
295
printf(", encrypted");
296
if (flags & BLOCK_FLAG_COMPAT6)
297
printf(", compatibility level=6");
299
printf(", backing_file=%s",
302
printf(", backing_fmt=%s",
305
printf(", size=%" PRIu64 " kB\n", size / 1024);
306
ret = bdrv_create2(drv, filename, size / 512, base_filename, base_fmt, flags);
295
if (options && !strcmp(options, "?")) {
296
print_option_help(drv->create_options);
301
param = parse_option_parameters(options, drv->create_options, param);
303
error("Invalid options for file format '%s'.", fmt);
306
param = parse_option_parameters("", drv->create_options, param);
309
/* Get the filename */
312
filename = argv[optind++];
314
/* Add size to parameters */
316
set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]);
319
/* Add old-style options to parameters */
320
add_old_style_options(fmt, param, flags, base_filename, base_fmt);
322
// The size for the image must always be specified, with one exception:
323
// If we are using a backing file, we can obtain the size from there
324
if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == 0) {
326
QEMUOptionParameter *backing_file =
327
get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
328
QEMUOptionParameter *backing_fmt =
329
get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
331
if (backing_file && backing_file->value.s) {
332
BlockDriverState *bs;
334
const char *fmt = NULL;
337
if (backing_fmt && backing_fmt->value.s) {
338
if (bdrv_find_format(backing_fmt->value.s)) {
339
fmt = backing_fmt->value.s;
341
error("Unknown backing file format '%s'",
342
backing_fmt->value.s);
346
bs = bdrv_new_open(backing_file->value.s, fmt);
347
bdrv_get_geometry(bs, &size);
351
snprintf(buf, sizeof(buf), "%" PRId64, size);
352
set_option_parameter(param, BLOCK_OPT_SIZE, buf);
354
error("Image creation needs a size parameter");
358
printf("Formatting '%s', fmt=%s ", filename, fmt);
359
print_option_parameters(param);
362
ret = bdrv_create(drv, filename, param);
363
free_option_parameters(param);
308
366
if (ret == -ENOTSUP) {
309
367
error("Formatting or formatting option not supported for file format '%s'", fmt);
540
603
total_sectors += bs_sectors;
606
/* Find driver and parse its options */
543
607
drv = bdrv_find_format(out_fmt);
545
609
error("Unknown file format '%s'", out_fmt);
546
if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2)
547
error("Compression not supported for this file format");
548
if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2)
549
error("Encryption not supported for this file format");
550
if (flags & BLOCK_FLAG_COMPAT6 && drv != &bdrv_vmdk)
551
error("Alternative compatibility level not supported for this file format");
552
if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS)
553
error("Compression and encryption not supported at the same time");
555
ret = bdrv_create(drv, out_filename, total_sectors, out_baseimg, flags);
611
if (options && !strcmp(options, "?")) {
612
print_option_help(drv->create_options);
617
param = parse_option_parameters(options, drv->create_options, param);
619
error("Invalid options for file format '%s'.", out_fmt);
622
param = parse_option_parameters("", drv->create_options, param);
625
set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
626
add_old_style_options(out_fmt, param, flags, out_baseimg, NULL);
628
/* Check if compression is supported */
629
if (flags & BLOCK_FLAG_COMPRESS) {
630
QEMUOptionParameter *encryption =
631
get_option_parameter(param, BLOCK_OPT_ENCRYPT);
633
if (!drv->bdrv_write_compressed) {
634
error("Compression not supported for this file format");
637
if (encryption && encryption->value.n) {
638
error("Compression and encryption not supported at the same time");
642
/* Create the new image */
643
ret = bdrv_create(drv, out_filename, param);
644
free_option_parameters(param);
557
647
if (ret == -ENOTSUP) {
558
648
error("Formatting not supported for file format '%s'", out_fmt);
937
1027
bdrv_delete(bs);
1032
static const img_cmd_t img_cmds[] = {
1033
#define DEF(option, callback, arg_string) \
1034
{ option, callback },
1035
#include "qemu-img-cmds.h"
940
1041
int main(int argc, char **argv)
1043
const img_cmd_t *cmd;
1044
const char *cmdname;
949
if (!strcmp(cmd, "create")) {
950
img_create(argc, argv);
951
} else if (!strcmp(cmd, "check")) {
952
img_check(argc, argv);
953
} else if (!strcmp(cmd, "commit")) {
954
img_commit(argc, argv);
955
} else if (!strcmp(cmd, "convert")) {
956
img_convert(argc, argv);
957
} else if (!strcmp(cmd, "info")) {
958
img_info(argc, argv);
959
} else if (!strcmp(cmd, "snapshot")) {
960
img_snapshot(argc, argv);
1052
/* find the command */
1053
for(cmd = img_cmds; cmd->name != NULL; cmd++) {
1054
if (!strcmp(cmdname, cmd->name)) {
1055
return cmd->handler(argc, argv);