diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-10 08:44:56 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-10 08:44:56 +0000 |
| commit | 5ae5d537511c5bea40346bd47d33c885dabc00d0 (patch) | |
| tree | f7e35288b9f8b24cc67726d3b50a681e3e7de6ce /util | |
| parent | edb1508a5913d4d7c359da5b0408f5c5de6895d4 (diff) | |
wip
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index d1786571..4ab6018a 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -214,6 +214,8 @@ static off_t gbe_x_offset(size_t part, const char *f_op, const char *d_type, off_t nsize, off_t ncmp); static void rw_file_exact(int fd, uint8_t *mem, size_t len, off_t off, int rw_type, const char *path, const char *rw_type_str); +static ssize_t prw(int fd, void *mem, size_t count, + off_t offset, int rw_type, const char *path); /* * Error handling and cleanup @@ -1364,11 +1366,13 @@ rw_file_exact(int fd, uint8_t *mem, size_t len, for (rc = 0; rc != len; rc += rval) { if (rw_type == PSCHREIB) - rval = pwrite(fd, mem + rc, len - rc, off + rc); + rval = prw(fd, mem + rc, len - rc, + off + rc, rw_type, path); else if (rw_type == SCHREIB) rval = write(fd, mem + rc, len - rc); else if (rw_type == PLESEN) - rval = pread(fd, mem + rc, len - rc, off + rc); + rval = prw(fd, mem + rc, len - rc, + off + rc, rw_type, path); else if (rw_type == LESEN) rval = read(fd, mem + rc, len - rc); else @@ -1389,6 +1393,35 @@ rw_file_exact(int fd, uint8_t *mem, size_t len, } } +static ssize_t +prw(int fd, void *mem, size_t count, + off_t offset, int rw_type, const char *path) +{ + off_t old; + ssize_t r; + + old = lseek(fd, 0, SEEK_CUR); + if (old == (off_t)-1) + return -1; + + if (lseek(fd, offset, SEEK_SET) == (off_t)-1) + return -1; + + do { + if (rw_type == PLESEN) + r = read(fd, mem, count); + else if (rw_type == PSCHREIB) + r = write(fd, mem, count); + else + err(EIO, "%s: Invalid rw_type", path); + } while (r < 0 && errno == EINTR); + + if (lseek(fd, old, SEEK_SET) == (off_t)-1 && r >= 0) + errno = EIO; + + return r; +} + static void err(int nvm_errval, const char *msg, ...) { |
