HomeFreeBSD

vfs_syscalls.c: Fix handling of offset args for copy_file_range

Description

vfs_syscalls.c: Fix handling of offset args for copy_file_range

Commit 197997a broke handling of the offset
arguments to copy_file_range() when specified non-NULL.
The code fails to update the offsets and, as such, a loop like:

do {

len = copy_file_range(infd, &inpos, outfd, &outpos,
   SSIZE_MAX, 0);

} while (len > 0);

becomes an infinite loop, just doing the same copy over and
over again.

This patch fixes it.

The clause "(foffsets_locked || foffsets_set)" in the if is not
actually needed for correctness, but I thought it made the code
a little more readable and might avoid some static
analyzer from throwing a "used before being set" for
the savinoff and savoutoff variables.

Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D51845
MFC after: 2 weeks
Fixes: 197997a4c36d ("file: Fix offset handling in kern_copy_file_range()")

Details

Provenance
rmacklemAuthored on Aug 9 2025, 9:15 PM
Reviewer
markj
Differential Revision
D51845: vfs_syscalls.c: Fix handling of offset arguments for copy_file_range
Parents
rG7a9834041c91: vfs: Put the definition of COPY_FILE_RANGE_CLONE in unistd.h
Branches
Unknown
Tags
Unknown