Re: SEEK_HOLE at EOF
- Reply: Poul-Henning Kamp: "Re: SEEK_HOLE at EOF"
- In reply to: Poul-Henning Kamp: "Re: SEEK_HOLE at EOF"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 05 Apr 2024 13:41:31 UTC
On Thu, Apr 4, 2024 at 11:43 PM 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 incompetence.