qemu-img.c (0bfcd599e3f5c5679cc7d0165a0a1822e2f60de2) qemu-img.c (b50cbabc1bc12e6b0082089c70015c1b97db86a1)
1/*
2 * QEMU disk image utility
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 238 unchanged lines hidden (view full) ---

247
248static int img_create(int argc, char **argv)
249{
250 int c, ret, flags;
251 const char *fmt = "raw";
252 const char *base_fmt = NULL;
253 const char *filename;
254 const char *base_filename = NULL;
1/*
2 * QEMU disk image utility
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights

--- 238 unchanged lines hidden (view full) ---

247
248static int img_create(int argc, char **argv)
249{
250 int c, ret, flags;
251 const char *fmt = "raw";
252 const char *base_fmt = NULL;
253 const char *filename;
254 const char *base_filename = NULL;
255 BlockDriver *drv;
256 QEMUOptionParameter *param = NULL;
255 BlockDriver *drv, *proto_drv;
256 QEMUOptionParameter *param = NULL, *create_options = NULL;
257 char *options = NULL;
258
259 flags = 0;
260 for(;;) {
261 c = getopt(argc, argv, "F:b:f:he6o:");
262 if (c == -1)
263 break;
264 switch(c) {

--- 16 unchanged lines hidden (view full) ---

281 flags |= BLOCK_FLAG_COMPAT6;
282 break;
283 case 'o':
284 options = optarg;
285 break;
286 }
287 }
288
257 char *options = NULL;
258
259 flags = 0;
260 for(;;) {
261 c = getopt(argc, argv, "F:b:f:he6o:");
262 if (c == -1)
263 break;
264 switch(c) {

--- 16 unchanged lines hidden (view full) ---

281 flags |= BLOCK_FLAG_COMPAT6;
282 break;
283 case 'o':
284 options = optarg;
285 break;
286 }
287 }
288
289 /* Get the filename */
290 if (optind >= argc)
291 help();
292 filename = argv[optind++];
293
289 /* Find driver and parse its options */
290 drv = bdrv_find_format(fmt);
291 if (!drv)
292 error("Unknown file format '%s'", fmt);
293
294 /* Find driver and parse its options */
295 drv = bdrv_find_format(fmt);
296 if (!drv)
297 error("Unknown file format '%s'", fmt);
298
299 proto_drv = bdrv_find_protocol(filename);
300 if (!proto_drv)
301 error("Unknown protocol '%s'", filename);
302
303 create_options = append_option_parameters(create_options,
304 drv->create_options);
305 create_options = append_option_parameters(create_options,
306 proto_drv->create_options);
307
294 if (options && !strcmp(options, "?")) {
308 if (options && !strcmp(options, "?")) {
295 print_option_help(drv->create_options);
309 print_option_help(create_options);
296 return 0;
297 }
298
299 /* Create parameter list with default values */
310 return 0;
311 }
312
313 /* Create parameter list with default values */
300 param = parse_option_parameters("", drv->create_options, param);
314 param = parse_option_parameters("", create_options, param);
301 set_option_parameter_int(param, BLOCK_OPT_SIZE, -1);
302
303 /* Parse -o options */
304 if (options) {
315 set_option_parameter_int(param, BLOCK_OPT_SIZE, -1);
316
317 /* Parse -o options */
318 if (options) {
305 param = parse_option_parameters(options, drv->create_options, param);
319 param = parse_option_parameters(options, create_options, param);
306 if (param == NULL) {
307 error("Invalid options for file format '%s'.", fmt);
308 }
309 }
310
320 if (param == NULL) {
321 error("Invalid options for file format '%s'.", fmt);
322 }
323 }
324
311 /* Get the filename */
312 if (optind >= argc)
313 help();
314 filename = argv[optind++];
315
316 /* Add size to parameters */
317 if (optind < argc) {
318 set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]);
319 }
320
321 /* Add old-style options to parameters */
322 add_old_style_options(fmt, param, flags, base_filename, base_fmt);
323

--- 33 unchanged lines hidden (view full) ---

357 }
358 }
359
360 printf("Formatting '%s', fmt=%s ", filename, fmt);
361 print_option_parameters(param);
362 puts("");
363
364 ret = bdrv_create(drv, filename, param);
325 /* Add size to parameters */
326 if (optind < argc) {
327 set_option_parameter(param, BLOCK_OPT_SIZE, argv[optind++]);
328 }
329
330 /* Add old-style options to parameters */
331 add_old_style_options(fmt, param, flags, base_filename, base_fmt);
332

--- 33 unchanged lines hidden (view full) ---

366 }
367 }
368
369 printf("Formatting '%s', fmt=%s ", filename, fmt);
370 print_option_parameters(param);
371 puts("");
372
373 ret = bdrv_create(drv, filename, param);
374 free_option_parameters(create_options);
365 free_option_parameters(param);
366
367 if (ret < 0) {
368 if (ret == -ENOTSUP) {
369 error("Formatting or formatting option not supported for file format '%s'", fmt);
370 } else if (ret == -EFBIG) {
371 error("The image size is too large for file format '%s'", fmt);
372 } else {

--- 165 unchanged lines hidden (view full) ---

538}
539
540#define IO_BUF_SIZE (2 * 1024 * 1024)
541
542static int img_convert(int argc, char **argv)
543{
544 int c, ret, n, n1, bs_n, bs_i, flags, cluster_size, cluster_sectors;
545 const char *fmt, *out_fmt, *out_baseimg, *out_filename;
375 free_option_parameters(param);
376
377 if (ret < 0) {
378 if (ret == -ENOTSUP) {
379 error("Formatting or formatting option not supported for file format '%s'", fmt);
380 } else if (ret == -EFBIG) {
381 error("The image size is too large for file format '%s'", fmt);
382 } else {

--- 165 unchanged lines hidden (view full) ---

548}
549
550#define IO_BUF_SIZE (2 * 1024 * 1024)
551
552static int img_convert(int argc, char **argv)
553{
554 int c, ret, n, n1, bs_n, bs_i, flags, cluster_size, cluster_sectors;
555 const char *fmt, *out_fmt, *out_baseimg, *out_filename;
546 BlockDriver *drv;
556 BlockDriver *drv, *proto_drv;
547 BlockDriverState **bs, *out_bs;
548 int64_t total_sectors, nb_sectors, sector_num, bs_offset;
549 uint64_t bs_sectors;
550 uint8_t * buf;
551 const uint8_t *buf1;
552 BlockDriverInfo bdi;
557 BlockDriverState **bs, *out_bs;
558 int64_t total_sectors, nb_sectors, sector_num, bs_offset;
559 uint64_t bs_sectors;
560 uint8_t * buf;
561 const uint8_t *buf1;
562 BlockDriverInfo bdi;
553 QEMUOptionParameter *param = NULL;
563 QEMUOptionParameter *param = NULL, *create_options = NULL;
554 char *options = NULL;
555
556 fmt = NULL;
557 out_fmt = "raw";
558 out_baseimg = NULL;
559 flags = 0;
560 for(;;) {
561 c = getopt(argc, argv, "f:O:B:hce6o:");

--- 48 unchanged lines hidden (view full) ---

610 total_sectors += bs_sectors;
611 }
612
613 /* Find driver and parse its options */
614 drv = bdrv_find_format(out_fmt);
615 if (!drv)
616 error("Unknown file format '%s'", out_fmt);
617
564 char *options = NULL;
565
566 fmt = NULL;
567 out_fmt = "raw";
568 out_baseimg = NULL;
569 flags = 0;
570 for(;;) {
571 c = getopt(argc, argv, "f:O:B:hce6o:");

--- 48 unchanged lines hidden (view full) ---

620 total_sectors += bs_sectors;
621 }
622
623 /* Find driver and parse its options */
624 drv = bdrv_find_format(out_fmt);
625 if (!drv)
626 error("Unknown file format '%s'", out_fmt);
627
628 proto_drv = bdrv_find_protocol(out_filename);
629 if (!proto_drv)
630 error("Unknown protocol '%s'", out_filename);
631
632 create_options = append_option_parameters(create_options,
633 drv->create_options);
634 create_options = append_option_parameters(create_options,
635 proto_drv->create_options);
618 if (options && !strcmp(options, "?")) {
636 if (options && !strcmp(options, "?")) {
619 print_option_help(drv->create_options);
637 print_option_help(create_options);
620 free(bs);
621 return 0;
622 }
623
624 if (options) {
638 free(bs);
639 return 0;
640 }
641
642 if (options) {
625 param = parse_option_parameters(options, drv->create_options, param);
643 param = parse_option_parameters(options, create_options, param);
626 if (param == NULL) {
627 error("Invalid options for file format '%s'.", out_fmt);
628 }
629 } else {
644 if (param == NULL) {
645 error("Invalid options for file format '%s'.", out_fmt);
646 }
647 } else {
630 param = parse_option_parameters("", drv->create_options, param);
648 param = parse_option_parameters("", create_options, param);
631 }
632
633 set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
634 add_old_style_options(out_fmt, param, flags, out_baseimg, NULL);
635
636 /* Check if compression is supported */
637 if (flags & BLOCK_FLAG_COMPRESS) {
638 QEMUOptionParameter *encryption =

--- 5 unchanged lines hidden (view full) ---

644
645 if (encryption && encryption->value.n) {
646 error("Compression and encryption not supported at the same time");
647 }
648 }
649
650 /* Create the new image */
651 ret = bdrv_create(drv, out_filename, param);
649 }
650
651 set_option_parameter_int(param, BLOCK_OPT_SIZE, total_sectors * 512);
652 add_old_style_options(out_fmt, param, flags, out_baseimg, NULL);
653
654 /* Check if compression is supported */
655 if (flags & BLOCK_FLAG_COMPRESS) {
656 QEMUOptionParameter *encryption =

--- 5 unchanged lines hidden (view full) ---

662
663 if (encryption && encryption->value.n) {
664 error("Compression and encryption not supported at the same time");
665 }
666 }
667
668 /* Create the new image */
669 ret = bdrv_create(drv, out_filename, param);
670 free_option_parameters(create_options);
652 free_option_parameters(param);
653
654 if (ret < 0) {
655 if (ret == -ENOTSUP) {
656 error("Formatting not supported for file format '%s'", out_fmt);
657 } else if (ret == -EFBIG) {
658 error("The image size is too large for file format '%s'", out_fmt);
659 } else {

--- 691 unchanged lines hidden ---
671 free_option_parameters(param);
672
673 if (ret < 0) {
674 if (ret == -ENOTSUP) {
675 error("Formatting not supported for file format '%s'", out_fmt);
676 } else if (ret == -EFBIG) {
677 error("The image size is too large for file format '%s'", out_fmt);
678 } else {

--- 691 unchanged lines hidden ---