mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-19 19:23:24 +02:00
util/nvmutil: portable pread/pwrite
not thread-safe lucky we're single-threaded! Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+20
-6
@@ -216,6 +216,7 @@ 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);
|
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,
|
static ssize_t prw(int fd, void *mem, size_t count,
|
||||||
off_t offset, int rw_type, const char *path);
|
off_t offset, int rw_type, const char *path);
|
||||||
|
static off_t lseek_eintr(int fd, off_t offset, int whence);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Error handling and cleanup
|
* Error handling and cleanup
|
||||||
@@ -1397,14 +1398,13 @@ static ssize_t
|
|||||||
prw(int fd, void *mem, size_t count,
|
prw(int fd, void *mem, size_t count,
|
||||||
off_t offset, int rw_type, const char *path)
|
off_t offset, int rw_type, const char *path)
|
||||||
{
|
{
|
||||||
|
off_t rs;
|
||||||
off_t old;
|
off_t old;
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
old = lseek(fd, 0, SEEK_CUR);
|
if ((old = lseek_eintr(fd, (off_t)0, SEEK_CUR)) == (off_t)-1)
|
||||||
if (old == (off_t)-1)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
if ((r = lseek_eintr(fd, offset, SEEK_SET)) == (off_t)-1)
|
||||||
if (lseek(fd, offset, SEEK_SET) == (off_t)-1)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -1416,12 +1416,26 @@ prw(int fd, void *mem, size_t count,
|
|||||||
err(EIO, "%s: Invalid rw_type", path);
|
err(EIO, "%s: Invalid rw_type", path);
|
||||||
} while (r < 0 && errno == EINTR);
|
} while (r < 0 && errno == EINTR);
|
||||||
|
|
||||||
if (lseek(fd, old, SEEK_SET) == (off_t)-1 && r >= 0)
|
if (r >= 0) {
|
||||||
errno = EIO;
|
if ((rs = lseek_eintr(fd, old, SEEK_SET)) == (off_t)-1)
|
||||||
|
errno = EIO;
|
||||||
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static off_t
|
||||||
|
lseek_eintr(int fd, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
off_t old;
|
||||||
|
|
||||||
|
do {
|
||||||
|
old = lseek(fd, offset, whence);
|
||||||
|
} while (old == (off_t)-1 && errno == EINTR);
|
||||||
|
|
||||||
|
return old;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
err(int nvm_errval, const char *msg, ...)
|
err(int nvm_errval, const char *msg, ...)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user