qemu-img.c (adfe078e4b658c5406be089980c5b9034bae42a4) | qemu-img.c (f2feebbd93c251ec0098a9ccf808f7cb1da7f67c) |
---|---|
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 --- 718 unchanged lines hidden (view full) --- 727 error("error while compressing sector %" PRId64, 728 sector_num); 729 } 730 sector_num += n; 731 } 732 /* signal EOF to align */ 733 bdrv_write_compressed(out_bs, 0, NULL, 0); 734 } else { | 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 --- 718 unchanged lines hidden (view full) --- 727 error("error while compressing sector %" PRId64, 728 sector_num); 729 } 730 sector_num += n; 731 } 732 /* signal EOF to align */ 733 bdrv_write_compressed(out_bs, 0, NULL, 0); 734 } else { |
735 int has_zero_init = bdrv_has_zero_init(out_bs); 736 |
|
735 sector_num = 0; // total number of sectors converted so far 736 for(;;) { 737 nb_sectors = total_sectors - sector_num; 738 if (nb_sectors <= 0) 739 break; 740 if (nb_sectors >= (IO_BUF_SIZE / 512)) 741 n = (IO_BUF_SIZE / 512); 742 else --- 7 unchanged lines hidden (view full) --- 750 /* printf("changing part: sector_num=%lld, bs_i=%d, " 751 "bs_offset=%lld, bs_sectors=%lld\n", 752 sector_num, bs_i, bs_offset, bs_sectors); */ 753 } 754 755 if (n > bs_offset + bs_sectors - sector_num) 756 n = bs_offset + bs_sectors - sector_num; 757 | 737 sector_num = 0; // total number of sectors converted so far 738 for(;;) { 739 nb_sectors = total_sectors - sector_num; 740 if (nb_sectors <= 0) 741 break; 742 if (nb_sectors >= (IO_BUF_SIZE / 512)) 743 n = (IO_BUF_SIZE / 512); 744 else --- 7 unchanged lines hidden (view full) --- 752 /* printf("changing part: sector_num=%lld, bs_i=%d, " 753 "bs_offset=%lld, bs_sectors=%lld\n", 754 sector_num, bs_i, bs_offset, bs_sectors); */ 755 } 756 757 if (n > bs_offset + bs_sectors - sector_num) 758 n = bs_offset + bs_sectors - sector_num; 759 |
758 if (!drv->no_zero_init) { | 760 if (has_zero_init) { |
759 /* If the output image is being created as a copy on write image, 760 assume that sectors which are unallocated in the input image 761 are present in both the output's and input's base images (no 762 need to copy them). */ 763 if (out_baseimg) { 764 if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, 765 n, &n1)) { 766 sector_num += n1; --- 16 unchanged lines hidden (view full) --- 783 while (n > 0) { 784 /* If the output image is being created as a copy on write image, 785 copy all sectors even the ones containing only NUL bytes, 786 because they may differ from the sectors in the base image. 787 788 If the output is to a host device, we also write out 789 sectors that are entirely 0, since whatever data was 790 already there is garbage, not 0s. */ | 761 /* If the output image is being created as a copy on write image, 762 assume that sectors which are unallocated in the input image 763 are present in both the output's and input's base images (no 764 need to copy them). */ 765 if (out_baseimg) { 766 if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, 767 n, &n1)) { 768 sector_num += n1; --- 16 unchanged lines hidden (view full) --- 785 while (n > 0) { 786 /* If the output image is being created as a copy on write image, 787 copy all sectors even the ones containing only NUL bytes, 788 because they may differ from the sectors in the base image. 789 790 If the output is to a host device, we also write out 791 sectors that are entirely 0, since whatever data was 792 already there is garbage, not 0s. */ |
791 if (drv->no_zero_init || out_baseimg || | 793 if (!has_zero_init || out_baseimg || |
792 is_allocated_sectors(buf1, n, &n1)) { 793 if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) 794 error("error while writing"); 795 } 796 sector_num += n1; 797 n -= n1; 798 buf1 += n1 * 512; 799 } --- 457 unchanged lines hidden --- | 794 is_allocated_sectors(buf1, n, &n1)) { 795 if (bdrv_write(out_bs, sector_num, buf1, n1) < 0) 796 error("error while writing"); 797 } 798 sector_num += n1; 799 n -= n1; 800 buf1 += n1 * 512; 801 } --- 457 unchanged lines hidden --- |