On 14/04/2025 23:18, Philip Rowlands wrote:
$ ( dd if=/dev/zero count=100; dd if=/dev/urandom count=100; dd if=/dev/zero
count=100 ) > unsparse
$ cp --sparse=always unsparse sparse
$ ls -ls *
52 -rw-r--r--. 1 root root 153600 Apr 14 22:55 sparse
152 -rw-r--r--. 1 root root 153600 Apr 14 22:54 unsparse
Great, the file was sparse-ified. On tmpfs.
## now on XFS with reflink support
$ cp --debug --sparse=always unsparse sparse
'unsparse' -> 'sparse'
copy offload: unknown, reflink: yes, sparse detection: unknown
$ ls -ls *
152 -rw-r--r--. 1 root root 153600 Apr 14 22:58 sparse
152 -rw-r--r--. 1 root root 153600 Apr 14 22:54 unsparse
The implicit --reflink=auto has won out over the explicit --sparse=always, but
at some point prior to coreutils 7.5, --sparse=always would have worked.
NEWS for 9.4 included
'cp --sparse=never' will avoid copy-on-write (reflinking) and copy
offloading,
to ensure no holes present in the destination copy.
[bug introduced in coreutils-9.0]
but we lack the opposite. I couldn't spot the discussion, if any, around the
patch
https://lists.gnu.org/archive/html/coreutils/2023-08/msg00052.html
I'm using coreutils 9.5 on Fedora 41.
Right. Users would use --sparse in an attempt to be space efficient,
but in this case the reflink is more space efficient and so takes precedence.
This is documented in the info docs as:
For example, with the following alias, ‘cp’ will use the minimum amount of
space supported by the file system. (Older versions of
‘cp’ can also benefit from ‘--reflink=auto’ here.)
alias cp='cp --sparse=always'
If you really want to focus on the file rather than the file system,
you can `cp --reflink=never --sparse=always`.
cheers,
Pádraig