From 0e295fbdc4478f6e694f8c12f5cdaf507047534c Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Sat, 14 Mar 2026 16:13:48 +0000 Subject: util/nvmutil: don't check o_append in prw slow, per call. prw should be generic. do it just for gbe files, once Signed-off-by: Leah Rowe --- util/nvmutil/nvmutil.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'util') diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 9fc9adec..2f77d919 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -949,10 +949,24 @@ static void open_gbe_file(void) { struct stat gbe_st; + int flags; xopen(&gbe_fd, fname, command[cmd_index].flags | O_BINARY | O_NOFOLLOW, &gbe_st); + flags = fcntl(gbe_fd, F_GETFL); + if (flags == -1) + err(errno, "%s: fcntl(F_GETFL)", fname); + + /* + * O_APPEND must not be used, because this + * allows POSIX write() to ignore the + * current write offset and write at EOF, + * which would therefore break pread/pwrite + */ + if (flags & O_APPEND) + err(EIO, "%s: O_APPEND flag"); + gbe_file_size = gbe_st.st_size; switch (gbe_file_size) { @@ -1924,7 +1938,6 @@ prw(int fd, void *mem, size_t nrw, off_t off_orig; ssize_t r; int saved_errno; - int flags; int positional_rw; if (mem == NULL) @@ -1970,19 +1983,6 @@ real_pread_pwrite: return rw_over_nrw(r, nrw); } - flags = fcntl(fd, F_GETFL); - if (flags == -1) - return -1; - - /* - * O_APPEND must not be used, because this - * allows POSIX write() to ignore the - * current write offset and write at EOF, - * which would therefore break pread/pwrite - */ - if (flags & O_APPEND) - goto err_prw; - #if defined(HAVE_REAL_PREAD_PWRITE) && \ HAVE_REAL_PREAD_PWRITE > 0 goto real_pread_pwrite; -- cgit v1.2.1