diff --git a/dump_inode.c b/dump_inode.c index 24d0ff2..652976e 100644 --- a/dump_inode.c +++ b/dump_inode.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -430,31 +431,45 @@ void *xmalloc(size_t size) { } void xpread(int fd, void *buf, size_t nbytes, off_t offset) { - ssize_t n = pread(fd, buf, nbytes, offset); - if (n == -1) { - err(1, "pread() failed"); - } - if (n != nbytes) { - errx(1, "Incomplete read"); + while (nbytes) { + ssize_t n = pread(fd, buf, nbytes, offset); + if (n == -1) { + if (errno == EINTR) { + continue; + } + err(1, "pread() failed"); + } + buf = (char *)buf + n; + nbytes -= n; + offset += n; } } void xwrite(int fd, void *buf, size_t nbytes) { - ssize_t n = write(fd, buf, nbytes); - if (n == -1) { - err(1, "write() failed"); - } - if (n != nbytes) { - errx(1, "Incomplete write"); + while (nbytes) { + ssize_t n = write(fd, buf, nbytes); + if (n == -1) { + if (errno == EINTR || errno == EAGAIN) { + continue; + } + err(1, "write() failed"); + } + buf = (char *)buf + n; + nbytes -= n; } } void xpwrite(int fd, void *buf, size_t nbytes, off_t offset) { - ssize_t n = pwrite(fd, buf, nbytes, offset); - if (n == -1) { - err(1, "pwrite() failed"); - } - if (n != nbytes) { - errx(1, "Incomplete write"); + while (nbytes) { + ssize_t n = pwrite(fd, buf, nbytes, offset); + if (n == -1) { + if (errno == EINTR) { + continue; + } + err(1, "pwrite() failed"); + } + buf = (char *)buf + n; + nbytes -= n; + offset += n; } }