On 2025-07-22 14:47, Collin Funk wrote:
int fd = open (".", O_DIRECTORY);
I think one also needs O_RDONLY for that to conform to POSIX.More generally, fsync requires write access to the file, so it's not just directories. Also, fdatasync has the same issue. I installed the attached further patch to document these more general issues.
By the way, I see only two usages of fdatasync or fsync in Gnulib. One, in lib/utimens.c is never used (it's for obsolete Linux kernels and even way back when it was never used). The other, in lib/textstyle.in.h, seems to be a performance bug - at least, the description of FLUSH_ALL doesn't explain the sometimes-severe performance issues involved, which leads me to be puzzled about what's intended.
From 1f4148c1573f2019012f190b4760cd87dc0e0bd7 Mon Sep 17 00:00:00 2001 From: Paul Eggert <egg...@cs.ucla.edu> Date: Tue, 22 Jul 2025 15:37:22 -0700 Subject: [PATCH] fsync, fdatasync: generalize fsync write access doc --- ChangeLog | 7 +++++-- doc/posix-functions/fdatasync.texi | 5 +++++ doc/posix-functions/fsync.texi | 10 +++------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3cebc0d793..15c7c1a941 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,11 @@ 2025-07-22 Collin Funk <collin.fu...@gmail.com> + Paul Eggert <egg...@cs.ucla.edu> - doc: Document that fsync doesn't work on directories on AIX 7.3. - Reported by Lakshmi-Surekha <lakshmi.kovv...@ibm.com> in: + doc: Document that fsync and fdatasync require write access. + Reported for fsync on AIX by Lakshmi-Surekha + <lakshmi.kovv...@ibm.com> in: <https://github.com/tukaani-project/xz/issues/188>. + * doc/posix-functions/fdatasync.texi: * doc/posix-functions/fsync.texi: Document the behavior. 2025-07-22 Paul Eggert <egg...@cs.ucla.edu> diff --git a/doc/posix-functions/fdatasync.texi b/doc/posix-functions/fdatasync.texi index 646c5b9985..d2e7c6e964 100644 --- a/doc/posix-functions/fdatasync.texi +++ b/doc/posix-functions/fdatasync.texi @@ -19,4 +19,9 @@ Mac OS X 10.5, FreeBSD 11.0, OpenBSD 3.8, Minix 3.1.8, mingw, MSVC 14, Android 2 Portability problems not fixed by Gnulib: @itemize +@item +If the argument is a file descriptor that lacks write access, +such as a directory file descriptor, this function fails +with @code{EBADF} on some platforms: +AIX 7.3, Cygwin 3.6.x. @end itemize diff --git a/doc/posix-functions/fsync.texi b/doc/posix-functions/fsync.texi index 924546516b..48ff17bccf 100644 --- a/doc/posix-functions/fsync.texi +++ b/doc/posix-functions/fsync.texi @@ -17,12 +17,8 @@ mingw, MSVC 14. Portability problems not fixed by Gnulib: @itemize @item -If the argument is a read-only file descriptor, this function fails +If the argument is a file descriptor that lacks write access, +such as a directory file descriptor, this function fails with @code{EBADF} on some platforms: -AIX 7.2, Cygwin 2.9. - -@item -If the argument is a directory file descriptor, this function fails with -@code{EBADF} on some platforms: -AIX 7.3. +AIX 7.3, Cygwin 3.6.x. @end itemize -- 2.48.1