cp: use SEEK_DATA/SEEK_HOLE if available
commita6eaee501f6ec0c152abe88640203a64c390993e
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 25 Jun 2020 23:31:44 +0000 (25 16:31 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 26 Jun 2020 01:53:43 +0000 (25 18:53 -0700)
tree759d9d1b4d0fd5e770f196010d699c05a77b2926
parent2fcd0f3328f5181a2986905fa5469a0152c67279
cp: use SEEK_DATA/SEEK_HOLE if available

If it works, prefer lseek with SEEK_DATA and SEEK_HOLE to FIEMAP,
as lseek is simpler and more portable (will be in next POSIX).
Problem reported in 2011 by Jeff Liu (Bug#8061).
* NEWS: Mention this.
* src/copy.c (lseek_copy) [SEEK_HOLE]: New function.
(enum scantype): New constants ERROR_SCANTYPE, LSEEK_SCANTYPE.
(union scan_inference): New type.
(infer_scantype): Last arg is now union scan_inference *,
not struct extent_scan *.  All callers changed.
Prefer SEEK_HOLE to FIEMAP if both work, since
SEEK_HOLE is simpler and more portable.
(copy_reg): Do the fdadvise after initial scan, in case the scan
fails.  Report an error if the initial scan fails.
(copy_reg) [SEEK_HOLE]: Use lseek_copy if scantype says so.
NEWS
src/copy.c