Re: cat: adjust the maximum data copied by copy_file_range
From:
Matteo Croce
Subject:
Re: cat: adjust the maximum data copied by copy_file_range
Date:
Sat, 20 Dec 2025 17:51:54 +0900
Il giorno mer 17 dic 2025 alle ore 09:07 Paul Eggert
<eggert@cs.ucla.edu> ha scritto:
>
> On 2025-12-14 18:18, Matteo Croce wrote:
> > Il giorno dom 14 dic 2025 alle ore 01:44 Paul Eggert
> > <eggert@cs.ucla.edu> ha scritto:
> >> On 2025-12-13 08:09, Matteo Croce wrote:
> >>> That was the purpose of the patch, even if maybe I should calculate it
> >>> by using sysconf(_SC_PAGESIZE).
> >> OK, but I'm not seeing why the patch would be a good idea for the
> >> coreutils master branch. Without the patch, doesn't 'cat' work well on
> >> all porting targets? Why add an unnecessary syscall?
> > Which syscall? sysconf doesn't ask the kernel for page size.
>
> Fair enough. But why add an unnecessary call? How would it improve cat's
> behavior, from the user's viewpoint?
I'm investigating a kernel bug[1] where it seems that if (file offset
+ read size > LONG_MAX), then all I/O fails with EINVAL.
This can be triggered with a huge file:
$ truncate -s $((2**63 - 1)) file1
$ ( dd bs=1M skip=$((2**43 - 2)) count=0 && cat ) < file1
0+0 records in
0+0 records out
0 bytes copied, 2,825e-05 s, 0,0 kB/s
cat: -: Invalid argument
$ dd if=file1 bs=1M skip=$((2**43 - 2))
dd: error reading 'file1': Invalid argument
1+0 records in
1+0 records out
1048576 bytes (1,0 MB, 1,0 MiB) copied, 0,103536 s, 10,1 MB/s
or with a small file and a huge read, e.g. as in the attached file.
[1]
https://lore.kernel.org/linux-fsdevel/20251219125250.65245-1-teknoraver@meta.com/T/
--
Matteo Croce
perl -e 'for($t=0;;$t++){print chr($t*($t>>8|$t>>13)&255)}' |aplay