diff options
author | Leah Rowe <leah@libreboot.org> | 2025-01-27 04:55:05 +0000 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2025-01-27 04:55:05 +0000 |
commit | c72f699d368e88dcfc48316fae8b1f16393d3d9f (patch) | |
tree | fe0253072e5c586a881a0dfb86731a402fb43110 | |
parent | d666f67ebe5648ac72de698ff61d6593a8ea83ea (diff) |
util/nvmutil: err if fewer bytes written
it will probably never happen, and this is technically
not an error condition of pread/pwrite, but we need it
to read and write that exact number of bytes, as per nf
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r-- | util/nvmutil/nvmutil.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index a7aee76f..15090a5a 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -34,7 +34,8 @@ uint8_t hextonum(char chs), rhex(void); #define SIZE_128KB 0x20000 uint16_t mac[3] = {0, 0, 0}; -size_t partsize, nf, gbe[2]; +ssize_t nf; +size_t partsize, gbe[2]; uint8_t nvmPartChanged[2] = {0, 0}, do_read[2] = {1, 1}; int e = 1, flags, rfd, fd, part, gbeFileChanged = 0; @@ -420,15 +421,19 @@ writeGbe(void) if ((!gbeFileChanged) || (flags == O_RDONLY)) return; - size_t tbw = 0; /* total bytes written */ + ssize_t tbw = 0; /* total bytes written */ for (int p = 0; p < 2; p++) { if ((!nvmPartChanged[p])) continue; swap(p); /* swap bytes on big-endian host CPUs */ - err_if(pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize) - == -1); + ssize_t bw = pwrite(fd, (uint8_t *) gbe[p], nf, p * partsize); + err_if(bw == -1); + if (bw != nf) + err(errno == ECANCELED, + "%ld bytes written on '%s', expected %ld bytes\n", + bw, filename, nf); tbw += nf; } |