Revision 93c65b47 qemu-img.c

b/qemu-img.c
493 493
    ret = bdrv_create(drv, out_filename, total_sectors, out_baseimg, flags);
494 494
    if (ret < 0) {
495 495
        if (ret == -ENOTSUP) {
496
            error("Formatting not supported for file format '%s'", fmt);
496
            error("Formatting not supported for file format '%s'", out_fmt);
497 497
        } else {
498 498
            error("Error while formatting '%s'", out_filename);
499 499
        }
......
592 592
            if (n > bs_offset + bs_sectors - sector_num)
593 593
                n = bs_offset + bs_sectors - sector_num;
594 594

  
595
            /* If the output image is being created as a copy on write image,
596
               assume that sectors which are unallocated in the input image
597
               are present in both the output's and input's base images (no
598
               need to copy them). */
599
            if (out_baseimg) {
600
               if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, n, &n1)) {
601
                  sector_num += n1;
602
                  continue;
603
               }
604
               /* The next 'n1' sectors are allocated in the input image. Copy
605
                  only those as they may be followed by unallocated sectors. */
606
               n = n1;
595
            if (drv != &bdrv_host_device) {
596
                if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
597
                                       n, &n1)) {
598
                    sector_num += n1;
599
                    continue;
600
                }
601
                /* The next 'n1' sectors are allocated in the input image. Copy
602
                   only those as they may be followed by unallocated sectors. */
603
                n = n1;
604
            } else {
605
                n1 = n;
607 606
            }
608 607

  
609 608
            if (bdrv_read(bs[bs_i], sector_num - bs_offset, buf, n) < 0) 
......
615 614
            while (n > 0) {
616 615
                /* If the output image is being created as a copy on write image,
617 616
                   copy all sectors even the ones containing only NUL bytes,
618
                   because they may differ from the sectors in the base image. */
619
                if (out_baseimg || is_allocated_sectors(buf1, n, &n1)) {
617
                   because they may differ from the sectors in the base image.
618

  
619
                   If the output is to a host device, we also write out
620
                   sectors that are entirely 0, since whatever data was
621
                   already there is garbage, not 0s. */
622
                if (drv == &bdrv_host_device || out_baseimg ||
623
                    is_allocated_sectors(buf1, n, &n1)) {
620 624
                    if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
621 625
                        error("error while writing");
622 626
                }

Also available in: Unified diff