Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-10 08:44:56 +00:00
parent edb1508a59
commit 5ae5d53751
+35 -2
View File
@@ -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, ...)
{