aboutsummaryrefslogtreecommitdiffstats
path: root/src/copy-file-data.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-11-04maint: adjust lseek_copy to handle non zero offsetsPádraig Brady1-2/+2
* src/copy-file-data.c (lseek_copy): hole_start is initialized only when ext_start == ipos. (infer_scantype): Update the hole_start initialization to the more logically correct POS, even though that init is only needed to suppress a -Wmaybe-uninitialized warning. Note gcc 15.2 at least doesn't seem to need that suppression.
2025-11-03doc: squashfs issue to be squashed in Linux 6.18Paul Eggert1-2/+3
2025-11-01copy: be more defensive/restrictive with posix_fadvisePádraig Brady1-8/+9
* src/copy-file-data.c (copy_file_data): Only give the POSIX_FADV_SEQUENTIAL hint when we _know_ we'll definitely use a read/write loop to copy the data. Also only apply the hint to the whole file, as we've seen OpenZFS at least special case that. (sparse_copy): Update stale comment.
2025-11-01copy: don't avoid copy-offload upon SEEK_HOLE indicating non-sparsePádraig Brady1-2/+9
* src/copy-file-data.c (infer_scantype): Fall back to a plain copy if SEEK_HOLE indicates non-sparse, as zero copy avoids copy offload. This was seen with transparently compressed files on OpenZFS. * tests/cp/sparse-perf.sh: Add a test case even though it might only trigger on compressed file systems that don't support reflink. * NEWS: Mention the bug fix. Addresses https://github.com/coreutils/coreutils/issues/122
2025-11-01copy: avoid posix_fadvise bypassing copy offload behaviorPádraig Brady1-2/+5
* src/copy-file-data.c (): pass 0 to posix_fadvise to indicate to EOF. coreutils 9.8 used OFF_T_MAX instead, which triggered OpenZFS 2.2.2 at least to synchronously (decompress and) populate the page cache. Addresses https://github.com/coreutils/coreutils/issues/122
2025-09-19copy: pacify older clangPaul Eggert1-9/+10
* src/copy-file-data.c (copy_file_data): Redo conditionals for clarity. This pacifies the clang in FreeBSD 11 and OpenBSD 7.6. Problem reported by Bruno Haible in: https://lists.gnu.org/r/coreutils/2025-09/msg00104.html
2025-09-16maint: avoid syntax-check failures from recent commitsPádraig Brady1-2/+3
* cfg.mk: Avoid spellcheck failures. * src/copy-file-data.c: Avoid sc_tight_scope and long_lines failure. * src/copy.h: Avoid indentation issues.
2025-09-15cp: create_hole now returns off_tPaul Eggert1-8/+10
* src/copy-file-data.c (create_hole): Refactor by returning resulting offset, not bool. All callers changed.
2025-09-15cp: prefer signed types in copy-file-data.cPaul Eggert1-11/+13
* src/copy-file-data.c (sparse_copy, lseek_copy) (copy_file_data): Prefer idx_t to size_t. (copy_file_data): Defend against st_size < 0, which can happen on ancient buggy platforms. Check for overflow; the old code was wrong on theoretical-but-valid hosts where SIZE_MAX <= INT_MAX.
2025-09-15cp: don’t allocate a separate zero bufferPaul Eggert1-21/+11
* src/copy-file-data.c (write_zeros): New args abuf, buf_size. Use the lazily-allocated buffer, which most likely already exists, rather than allocating a separate buffer just for zeros. This makes the code more reentrant as there is no longer a need for static storage here. Although there is some CPU overhead due to the need to zero out the buffer for each file, the overhead is relatively small as the buffer is smallish and should be cached. All callers changed.
2025-09-15cp: refactor copying to return bytes copiedPaul Eggert1-52/+56
This doesn’t change behavior; it simplifies future changes. * src/copy-file-data.c (sparse_copy, lseek_copy, copy_file_data): Return the number of bytes copied, or -1 on failure, instead of merely returning a success indication. All callers changed.
2025-09-15cp: copy_file_data now supports ibytesPaul Eggert1-11/+29
This does not affect current coreutils behavior; it is merely to help make copy_file_data more useful in the future. * src/copy-file-data.c (lseek_copy): New arg ibytes. Caller changed. (copy_file_data): Implement the ibytes arg; formerly it was always treated as COUNT_MAX, though all callers currently pass COUNT_MAX so there was no problem in practice.
2025-09-15cp: prefer signed type for file byte countPaul Eggert1-4/+4
* src/copy-file-data.c (sparse_copy): max_n_read arg is now of type count_t, not uintmax_t. This is better for debugging with -fsanitize=undefined.
2025-09-15cp: port better to old limited hostsPaul Eggert1-3/+7
Port better ancient platforms where OFF_T_MAX is only 2**31 - 1, but some devices have more than that many bytes. * src/copy-file-data.c (copy_file_data): Byte count is now count_t, not off_t. All callers changed. Since we need to check for overflow anyway, also check for too-small calls to fadvise.
2025-09-15cp: refactor out data copyingPaul Eggert1-0/+593
* po/POTFILES.in, src/local.mk (copy_sources): Add the new file. * src/copy.c: Move the #includes of alignalloc.h, buffer-lcm.h, fadvise.h, full-write.h, ioblksize.h to copy-file-data.c. (enum copy_debug_val, struct copy_debug): Move these decls to copy.h. (punch_hole, create_hole, is_CLONENOTSUP, sparse_copy) (write_zeros, lseek_copy, HAVE_STRUCT_STAT_ST_BLOCKS) (enum scantype, struct scan_inference, infer_scantype): Move to copy-file-data.c. (copy_reg): Move the data-copying part of this function to the new function copy_file_data in copy-file-data.c. * src/copy-file-data.c: New file, taken from part of copy.c.