handle partial reads/writes
This commit is contained in:
parent
fc2b116dc2
commit
9281b75737
51
dump_inode.c
51
dump_inode.c
|
@ -25,6 +25,7 @@
|
||||||
#include <ufs/ufs/dir.h>
|
#include <ufs/ufs/dir.h>
|
||||||
|
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -430,31 +431,45 @@ void *xmalloc(size_t size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void xpread(int fd, void *buf, size_t nbytes, off_t offset) {
|
void xpread(int fd, void *buf, size_t nbytes, off_t offset) {
|
||||||
ssize_t n = pread(fd, buf, nbytes, offset);
|
while (nbytes) {
|
||||||
if (n == -1) {
|
ssize_t n = pread(fd, buf, nbytes, offset);
|
||||||
err(1, "pread() failed");
|
if (n == -1) {
|
||||||
}
|
if (errno == EINTR) {
|
||||||
if (n != nbytes) {
|
continue;
|
||||||
errx(1, "Incomplete read");
|
}
|
||||||
|
err(1, "pread() failed");
|
||||||
|
}
|
||||||
|
buf = (char *)buf + n;
|
||||||
|
nbytes -= n;
|
||||||
|
offset += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void xwrite(int fd, void *buf, size_t nbytes) {
|
void xwrite(int fd, void *buf, size_t nbytes) {
|
||||||
ssize_t n = write(fd, buf, nbytes);
|
while (nbytes) {
|
||||||
if (n == -1) {
|
ssize_t n = write(fd, buf, nbytes);
|
||||||
err(1, "write() failed");
|
if (n == -1) {
|
||||||
}
|
if (errno == EINTR || errno == EAGAIN) {
|
||||||
if (n != nbytes) {
|
continue;
|
||||||
errx(1, "Incomplete write");
|
}
|
||||||
|
err(1, "write() failed");
|
||||||
|
}
|
||||||
|
buf = (char *)buf + n;
|
||||||
|
nbytes -= n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void xpwrite(int fd, void *buf, size_t nbytes, off_t offset) {
|
void xpwrite(int fd, void *buf, size_t nbytes, off_t offset) {
|
||||||
ssize_t n = pwrite(fd, buf, nbytes, offset);
|
while (nbytes) {
|
||||||
if (n == -1) {
|
ssize_t n = pwrite(fd, buf, nbytes, offset);
|
||||||
err(1, "pwrite() failed");
|
if (n == -1) {
|
||||||
}
|
if (errno == EINTR) {
|
||||||
if (n != nbytes) {
|
continue;
|
||||||
errx(1, "Incomplete write");
|
}
|
||||||
|
err(1, "pwrite() failed");
|
||||||
|
}
|
||||||
|
buf = (char *)buf + n;
|
||||||
|
nbytes -= n;
|
||||||
|
offset += n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue