Page MenuHomeFreeBSD

cp: fall back to read/write if copy_file_range fails
ClosedPublic

Authored by asomers on Sep 10 2020, 6:11 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 11 2024, 5:04 PM
Unknown Object (File)
Mar 11 2024, 5:03 PM
Unknown Object (File)
Mar 8 2024, 2:34 AM
Unknown Object (File)
Mar 8 2024, 2:22 AM
Unknown Object (File)
Jan 23 2024, 8:37 PM
Unknown Object (File)
Dec 20 2023, 6:08 AM
Unknown Object (File)
Sep 26 2023, 11:07 AM
Unknown Object (File)
Sep 19 2023, 4:00 AM

Details

Summary

cp: fall back to read/write if copy_file_range fails

Even though copy_file_range has a file-system agnostic version, it still
fails on devfs (perhaps because the file descriptor is non-seekable?) In
that case, fallback to old-fashioned read/write. Fixes
"cp /dev/null /tmp/null"

Reported-by: Michael Butler

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 33496
Build 30769: arc lint + arc unit

Event Timeline

Minor nit, which could report a bad write total in some rare circumstances is the only issue I see.

bin/cp/utils.c
249

if rcount < 0, then this code will execute where before it would not.

bin/cp/utils.c
249

Yeah, I'm aware of that. But I didn't think inaccurate SIGINFO output in the event of an error was a problem. Do you want me to fix it?

mjg added a subscriber: mjg.

This is a serious regression, just please get this in. The SIGINFO nit can be sorted out later.

This revision is now accepted and ready to land.Sep 11 2020, 8:27 PM

I think it fails because vn_copy_file_range checks for v_type == VREG while /dev/null is VCHR. There may be other problems.

Might I suggest that you enable NetBSD's cp tests, and add necessary tests to prevent this breakage again?

allanjude added inline comments.
head/bin/cp/utils.c
245 ↗(On Diff #76932)

Is there a reason this isn't juse an else?

head/bin/cp/utils.c
245 ↗(On Diff #76932)

Think first time through