public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* readdir and ENOENT error or EOF?
@ 2021-06-16 20:49 Mark Olesen
  2021-06-17  7:07 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Olesen @ 2021-06-16 20:49 UTC (permalink / raw)
  To: libc-alpha

There appears to be ambiguity in user documentation for readdir when
it returns NULL and errno is set to ENOENT.

Is this an EOF condition or an actual error that should be handled?

...
/* On some systems getdents fails with ENOENT when the
open directory has been rmdir'd already. POSIX.1
requires that we treat this condition like normal EOF. */
if (bytes < 0 && errno == ENOENT)
bytes = 0;
...
https://code.woboq.org/userspace/glibc/sysdeps/posix/readdir.c.htmlin

Thanks in advance for your time and help on this matter.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: readdir and ENOENT error or EOF?
  2021-06-16 20:49 readdir and ENOENT error or EOF? Mark Olesen
@ 2021-06-17  7:07 ` Florian Weimer
  2021-06-18 18:02   ` Mark Olesen
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2021-06-17  7:07 UTC (permalink / raw)
  To: Mark Olesen via Libc-alpha; +Cc: Mark Olesen

* Mark Olesen via Libc-alpha:

> There appears to be ambiguity in user documentation for readdir when
> it returns NULL and errno is set to ENOENT.
>
> Is this an EOF condition or an actual error that should be handled?
>
> ...
> /* On some systems getdents fails with ENOENT when the
> open directory has been rmdir'd already. POSIX.1
> requires that we treat this condition like normal EOF. */
> if (bytes < 0 && errno == ENOENT)
> bytes = 0;
> ...
> https://code.woboq.org/userspace/glibc/sysdeps/posix/readdir.c.htmlin

Note that the Linux implementation is in
sysdeps/unix/sysv/linux/readdir.c, but it has this quirk as well.

I believe this has been copied over from historic times.  In general,
Linux handles this corner case differently.  However, the Linux VFS
layer will pass through ENOENT from file system implementations, so if a
file system implementation generates ENOENT in its readdir
implementation, we might still see ENOENT in userspace.  That's why it's
difficult to remove the check from glibc's readdir implementation.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: readdir and ENOENT error or EOF?
  2021-06-17  7:07 ` Florian Weimer
@ 2021-06-18 18:02   ` Mark Olesen
  2021-06-22  7:53     ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Olesen @ 2021-06-18 18:02 UTC (permalink / raw)
  To: Florian Weimer; +Cc: Mark Olesen via Libc-alpha

I apologize for what I posted in libc-alpha. I did not realize the
post actually made it on the list. I reposted it in libc-help.
However, thanks for your answer.

Should ENOENT be handled as an error or is it indeed an EOF condition?



On Thu, Jun 17, 2021 at 1:07 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Mark Olesen via Libc-alpha:
>
> > There appears to be ambiguity in user documentation for readdir when
> > it returns NULL and errno is set to ENOENT.
> >
> > Is this an EOF condition or an actual error that should be handled?
> >
> > ...
> > /* On some systems getdents fails with ENOENT when the
> > open directory has been rmdir'd already. POSIX.1
> > requires that we treat this condition like normal EOF. */
> > if (bytes < 0 && errno == ENOENT)
> > bytes = 0;
> > ...
> > https://code.woboq.org/userspace/glibc/sysdeps/posix/readdir.c.htmlin
>
> Note that the Linux implementation is in
> sysdeps/unix/sysv/linux/readdir.c, but it has this quirk as well.
>
> I believe this has been copied over from historic times.  In general,
> Linux handles this corner case differently.  However, the Linux VFS
> layer will pass through ENOENT from file system implementations, so if a
> file system implementation generates ENOENT in its readdir
> implementation, we might still see ENOENT in userspace.  That's why it's
> difficult to remove the check from glibc's readdir implementation.
>
> Thanks,
> Florian
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: readdir and ENOENT error or EOF?
  2021-06-18 18:02   ` Mark Olesen
@ 2021-06-22  7:53     ` Florian Weimer
  2021-06-22  8:18       ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2021-06-22  7:53 UTC (permalink / raw)
  To: Mark Olesen; +Cc: Mark Olesen via Libc-alpha

* Mark Olesen:

> Should ENOENT be handled as an error or is it indeed an EOF condition?

I don't know.  It's really hard to make such changes because there are
so many Linux file system implementations.  So we kind of default to
make not making changes. 8-/

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: readdir and ENOENT error or EOF?
  2021-06-22  7:53     ` Florian Weimer
@ 2021-06-22  8:18       ` Andreas Schwab
  0 siblings, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2021-06-22  8:18 UTC (permalink / raw)
  To: Florian Weimer via Libc-alpha; +Cc: Mark Olesen, Florian Weimer

On Jun 22 2021, Florian Weimer via Libc-alpha wrote:

> * Mark Olesen:
>
>> Should ENOENT be handled as an error or is it indeed an EOF condition?
>
> I don't know.  It's really hard to make such changes because there are
> so many Linux file system implementations.  So we kind of default to
> make not making changes. 8-/

POSIX makes it clear that when an EOF condition occurs, errno must be
left unchanged.  AFAICS, our readdir implementation conforms to that.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-06-22  8:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 20:49 readdir and ENOENT error or EOF? Mark Olesen
2021-06-17  7:07 ` Florian Weimer
2021-06-18 18:02   ` Mark Olesen
2021-06-22  7:53     ` Florian Weimer
2021-06-22  8:18       ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).