Re: SEEK_HOLE at EOF

From: Poul-Henning Kamp <phk_at_phk.freebsd.dk>
Date: Fri, 05 Apr 2024 05:43:13 UTC
--------
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.