Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Apr 2024 07:41:31 -0600
From:      Alan Somers <asomers@freebsd.org>
To:        Poul-Henning Kamp <phk@phk.freebsd.dk>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: SEEK_HOLE at EOF
Message-ID:  <CAOtMX2hfxQNrk1iPtq6snYnt0EzK_ffXm5b1TnkTLCYKgW6j3A@mail.gmail.com>
In-Reply-To: <202404050543.4355hDcS009860@critter.freebsd.dk>
References:  <CAOtMX2gaHkH7gRT1OWTNpZEcr13%2BiozicmUDZ1hEapT6oiXiuQ@mail.gmail.com> <202404050543.4355hDcS009860@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Apr 4, 2024 at 11:43=E2=80=AFPM Poul-Henning Kamp <phk@phk.freebsd.=
dk> wrote:
>
> --------
> Alan Somers writes:
>
> > Linux's man page is clear: "whence is SEEK_DATA or SEEK_HOLE, and
> > offset is beyond the end of the file".
> >[...]
> > Contrary to its man page, Linux behaves mostly like FreeBSD. SEEK_HOLE
> > returns ENXIO at EOF on most file systems.
>
> Just two minor quibbles:
>
> If the file position is EOF, then you /are/ "beyond the end of the file"
> because a read(2) would not be able to return any data.

Do you distinguish between "at EOF" and "beyond EOF"?  And does it not
trouble you that calling SEEK_HOLE from the beginning of the "virtual
hole at EOF" will return ENXIO, even though calling SEEK_HOLE from the
beginning of any real hole will return the current offset?

>
> And returning ENXIO is more informative than returning the size of the
> file, since it atomically tells you that there are no more holes.

Ahh, that's a good point.  It's the first point I've heard in favor of
this option.  Are you aware of any applications that need to know
that?

>
> If it returned the size of the file, you would have to make another
> syscall (opening a race) to check if what you got was EOF or a hole.
>
> --
> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
> phk@FreeBSD.ORG         | TCP/IP since RFC 956
> FreeBSD committer       | BSD since 4.3-tahoe
> Never attribute to malice what can adequately be explained by incompetenc=
e.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2hfxQNrk1iPtq6snYnt0EzK_ffXm5b1TnkTLCYKgW6j3A>