summaryrefslogtreecommitdiffstats
path: root/lib/ext2fs/qcow2.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 04:59:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 04:59:34 +0000
commit6187d406bede6461086d6e5263f42ae4826675c4 (patch)
tree32a35120c4385929cfd5a7b9c584b9dd8396b108 /lib/ext2fs/qcow2.c
parentReleasing progress-linux version 1.47.0-2.4~progress7.99u1. (diff)
downloade2fsprogs-6187d406bede6461086d6e5263f42ae4826675c4.tar.xz
e2fsprogs-6187d406bede6461086d6e5263f42ae4826675c4.zip
Merging upstream version 1.47.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ext2fs/qcow2.c')
-rw-r--r--lib/ext2fs/qcow2.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/ext2fs/qcow2.c b/lib/ext2fs/qcow2.c
index 2082417..8f96eee 100644
--- a/lib/ext2fs/qcow2.c
+++ b/lib/ext2fs/qcow2.c
@@ -134,7 +134,9 @@ static int qcow2_read_l2_table(struct ext2_qcow2_image *img,
static int qcow2_copy_data(int fdin, int fdout, __u64 off_in,
__u64 off_out, void *buf, size_t count)
{
- size_t size;
+ ssize_t c1, c2, c;
+ void *ptr;
+ int retries = 10;
assert(buf);
@@ -144,14 +146,24 @@ static int qcow2_copy_data(int fdin, int fdout, __u64 off_in,
if (ext2fs_llseek(fdin, off_in, SEEK_SET) < 0)
return errno;
- size = read(fdin, buf, count);
- if (size != count)
- return errno;
-
- size = write(fdout, buf, count);
- if (size != count)
- return errno;
-
+ while (count > 0) {
+ errno = 0;
+ c1 = read(fdin, buf, count);
+ if (c1 < 0 || ((c1 == 0) && errno))
+ return errno;
+ if (c1 == 0)
+ break; /* EOF */
+
+ for (ptr = buf, c = c1; c > 0; ptr += c2, c -= c2) {
+ errno = 0;
+ c2 = write(fdout, ptr, c1);
+ if (c2 < 0 || ((c2 == 0) && errno))
+ return errno;
+ if (c2 == 0 && --retries <= 0)
+ break; /* This should never happen... */
+ }
+ count -= c1;
+ }
return 0;
}