diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-13 22:45:28 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-13 22:45:28 +0000 |
| commit | e170ca00e63f2be0580074a502de012c959100e8 (patch) | |
| tree | 04eeedaaebacda24b193ebaca71c6862b8865322 /util/nvmutil | |
| parent | 5ff679e4db49da6b4a1edde3e2655e9b20597970 (diff) | |
util/nvmutil: move EINTR handle to prw()
this way, we now have a universal function
that is reusable elsewhere, with the same
redundancy. the rw_once and rw_exact functions
still get this redundancy, through prw
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index c92744ac..2485f7b8 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1618,9 +1618,6 @@ rw_file_once(int fd, u8 *mem, size_t nrw, read_again: rv = prw(fd, mem + rc, nrw - rc, off + rc, rw_type); - if (rv < 0 && errno == EINTR) - goto read_again; - if (rv < 0) return -1; @@ -1640,6 +1637,8 @@ err_rw_file_once: } /* + * prw() - portable read-write + * * This implements a portable analog of pwrite() * and pread() - note that this version is not * thread-safe (race conditions are possible on @@ -1660,15 +1659,27 @@ prw(int fd, void *mem, size_t nrw, ssize_t r; int saved_errno; int flags; + int positional_rw = 0; if (io_args(fd, mem, nrw, off, rw_type) == -1) goto err_prw; + r = -1; + +try_rw_again: + if (rw_type == IO_WRITE) - return write(fd, mem, nrw); + r = write(fd, mem, nrw); + else if (rw_type == IO_READ) + r = read(fd, mem, nrw); + else + positional_rw = 1; - if (rw_type == IO_READ) - return read(fd, mem, nrw); + if (!positional_rw) { + if (r == -1 && errno == EINTR) + goto try_rw_again; + return r; + } flags = fcntl(fd, F_GETFL); if (flags == -1) @@ -1700,7 +1711,6 @@ prw(int fd, void *mem, size_t nrw, if (lseek_eintr(fd, off_orig, SEEK_SET) == (off_t)-1) { if (r < 0) errno = saved_errno; - return -1; } errno = saved_errno; |
