"\n"
"Command parameters:\n"
" 'filename' is a disk image filename\n"
- " 'base_image' is the read-only disk image which is used as base for a copy on\n"
- " write image; the copy on write image only stores the modified data\n"
- " 'output_base_image' forces the output image to be created as a copy on write\n"
- " image of the specified base image; 'output_base_image' should have the same\n"
- " content as the input's base image, however the path, image format, etc may\n"
- " differ\n"
" 'fmt' is the disk image format. It is guessed automatically in most cases\n"
- " 'size' is the disk image size in kilobytes. Optional suffixes\n"
- " 'M' (megabyte, 1024 * 1024) and 'G' (gigabyte, 1024 * 1024 * 1024) are\n"
- " supported any 'k' or 'K' is ignored\n"
+ " 'size' is the disk image size in bytes. Optional suffixes\n"
+ " 'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' (gigabyte, 1024M)\n"
+ " and T (terabyte, 1024G) are supported. 'b' is ignored.\n"
" 'output_filename' is the destination disk image filename\n"
" 'output_fmt' is the destination format\n"
" 'options' is a comma separated list of format specific options in a\n"
return 0;
}
+ /* Create parameter list with default values */
+ param = parse_option_parameters("", drv->create_options, param);
+ set_option_parameter_int(param, BLOCK_OPT_SIZE, -1);
+
+ /* Parse -o options */
if (options) {
param = parse_option_parameters(options, drv->create_options, param);
if (param == NULL) {
error("Invalid options for file format '%s'.", fmt);
}
- } else {
- param = parse_option_parameters("", drv->create_options, param);
}
/* Get the filename */
// The size for the image must always be specified, with one exception:
// If we are using a backing file, we can obtain the size from there
- if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == 0) {
+ if (get_option_parameter(param, BLOCK_OPT_SIZE)->value.n == -1) {
QEMUOptionParameter *backing_file =
get_option_parameter(param, BLOCK_OPT_BACKING_FILE);
return v;
}
-#define IO_BUF_SIZE 65536
+#define IO_BUF_SIZE (2 * 1024 * 1024)
static int img_convert(int argc, char **argv)
{
if (options && !strcmp(options, "?")) {
print_option_help(drv->create_options);
+ free(bs);
return 0;
}
if (n > bs_offset + bs_sectors - sector_num)
n = bs_offset + bs_sectors - sector_num;
- if (strcmp(drv->format_name, "host_device")) {
- if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
- n, &n1)) {
- sector_num += n1;
- continue;
+ if (!drv->no_zero_init) {
+ /* If the output image is being created as a copy on write image,
+ assume that sectors which are unallocated in the input image
+ are present in both the output's and input's base images (no
+ need to copy them). */
+ if (out_baseimg) {
+ if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
+ n, &n1)) {
+ sector_num += n1;
+ continue;
+ }
+ /* The next 'n1' sectors are allocated in the input image. Copy
+ only those as they may be followed by unallocated sectors. */
+ n = n1;
}
- /* The next 'n1' sectors are allocated in the input image. Copy
- only those as they may be followed by unallocated sectors. */
- n = n1;
} else {
n1 = n;
}
If the output is to a host device, we also write out
sectors that are entirely 0, since whatever data was
already there is garbage, not 0s. */
- if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg ||
+ if (drv->no_zero_init || out_baseimg ||
is_allocated_sectors(buf1, n, &n1)) {
if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
error("error while writing");