coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFC: posix_fadvise( "to end of file" ) semantics


From: Collin Funk
Subject: Re: RFC: posix_fadvise( "to end of file" ) semantics
Date: Wed, 29 Oct 2025 19:18:01 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

PƔdraig Brady <P@draigBrady.com> writes:

> I was debugging a change in coreutils 9.8 and noticed that fadvise was
> being passed OFF_T_MAX to indicate to apply advice to end of file.
>
> This struck me as a bit unusual and coreutils <= 9.7 used 0 to do the same 
> thing.
> It seems to me like 0 may be treated specially or more efficiently in more 
> cases?
>
> How about the following to go back to 0 meaning, to end of file?
>
> cheers,
> Padraig
>
> diff --git a/src/copy-file-data.c b/src/copy-file-data.c
> index 1eefd3071..c3abe41e2 100644
> --- a/src/copy-file-data.c
> +++ b/src/copy-file-data.c
> @@ -538,7 +538,7 @@ copy_file_data (int ifd, struct stat const *ist, off_t 
> ipos, char const *iname,
>     /* Don't bother calling fadvise for small copies, as it is not
>        likely to help performance and might even hurt it.  */
>     if (IO_BUFSIZE < ibytes)
> -    fdadvise (ifd, ipos, ibytes <= OFF_T_MAX - ipos ? ibytes : 0,
> +    fdadvise (ifd, ipos, ibytes < OFF_T_MAX - ipos ? ibytes : 0,
>                 FADVISE_SEQUENTIAL);
>
>     /* If not making a sparse file, try to use a more-efficient

Your change seems to match the expectations of POSIX [1]:

    If len is zero, all data from offset to the largest possible value
    of the file offset for that file shall be specified.

And the Linux man pages [2]:

    or until the end of the file if size is 0

Whether or not it causes issues, I am not sure.

Collin

[1] 
https://pubs.opengroup.org/onlinepubs/9799919799/functions/posix_fadvise.html
[2] https://www.man7.org/linux/man-pages/man2/posix_fadvise.2.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]