From eb8a297ba0b189fd93eef19e21e3c275f756c0c9 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 14 Mar 2026 03:29:01 +0000 Subject: util/nvmutil: detect partial gbe rw we already covered this in prw() which is what ultimately gets called, but still. it's logically correct not to check it here. Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'util/nvmutil') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 0f3158e7..0292a4cb 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -1489,6 +1489,7 @@ static void rw_gbe_file_part(size_t p, int rw_type, const char *rw_type_str) { + ssize_t r; size_t gbe_rw_size = command[cmd_index].rw_size; u8 invert = command[cmd_index].invert; @@ -1509,11 +1510,17 @@ rw_gbe_file_part(size_t p, int rw_type, mem_offset = gbe_mem_offset(p ^ invert, rw_type_str); file_offset = (off_t)gbe_file_offset(p, rw_type_str); - if (rw_gbe_file_exact(gbe_fd, mem_offset, - gbe_rw_size, file_offset, rw_type) == -1) + r = rw_gbe_file_exact(gbe_fd, mem_offset, + gbe_rw_size, file_offset, rw_type); + + if (r == -1) err(errno, "%s: %s: part %lu", fname, rw_type_str, (ulong)p); + if ((size_t)r != gbe_rw_size) + err(EIO, "%s: partial %s: part %lu", + fname, rw_type_str, (ulong)p); + /* * Next, we read back what was written, * to ensure that it was done correctly. @@ -1531,12 +1538,18 @@ rw_gbe_file_part(size_t p, int rw_type, err(errno, "%s: fsync: part %lu (post-verification)", fname, (ulong)p); - if (rw_gbe_file_exact(gbe_fd, pad, - gbe_rw_size, file_offset, IO_PREAD) == -1) + r = rw_gbe_file_exact(gbe_fd, pad, + gbe_rw_size, file_offset, IO_PREAD); + + if (r == -1) err(errno, "%s: pread: part %lu (post-verification)", fname, (ulong)p); - if (memcmp(mem_offset, pad, gbe_rw_size)) + if ((size_t)r != gbe_rw_size) + err(EIO, "%s: partial pread: part %lu (post-verification)", + fname, (ulong)p); + + if (memcmp(mem_offset, pad, gbe_rw_size) != 0) err(errno, "%s: pwrite: corrupt write on part %lu", fname, (ulong)p); } -- cgit v1.2.1