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

next in thread | previous in thread | raw e-mail | index | archive | help
--------
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.

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

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



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