Paul Eggert <egg...@cs.ucla.edu> writes:

> 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.

Oops, you are right. POSIX says it needs one of O_EXEC, O_RDONLY,
O_RDWR, O_SEARCH, or O_WRONLY.

> 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.

Ah, I see. I thought fdatasync didn't exist on AIX for some reason. It
doesn't have a man page but is declared in unistd.h where it is
standardized.

> 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.

I thought it might have been worth doing something for AIX like (not
tested):

    int
    fsync (int fd)
    #undef fsync
    {
      int saved_errno _GL_UNUSED = errno;
      int result = fsync (fd);
    #if defined _AIX
      if (result < 0)
        {
          struct stat st;
          if (errno == EBADF && fstat (fd, &st) == 0 && S_ISDIR (&st))
            {
              errno = saved_errno;
              return 0;
            }
    #endif
        }
      return result;
    }

But I don't like the situtation where fsync reports success and the file
is not flushed to the disc. And as you mention, it is not used much so
is probably not worth doing.

Collin

Reply via email to