[Toybox] cp --sparse=
enh
enh at google.com
Wed Feb 4 15:21:07 PST 2026
we had some recent issues where folks were copying large sparse files
not realizing that cp does not preserve sparseness. i was looking at
implementing --sparse= in toybox cp, but i was a bit confused that i
couldn't actually make coreutils' "auto" heuristic fire. if you use
--sparse=auto it does the lseek() you'd expect (like the existing
toybox tar.c code), and --sparse=never is obviously the current
behavior, but i'm not sure about "auto" based on observed
behavior/strace.
i also don't really understand why coreutils is trying to be clever
here? why not just do the lseek()?
i also kind of assume this would make your refactoring finger itch and
want to share the sendfile_sparse() code from tar.c rather than have a
duplicate implementation in cp.c or changing the lib xsendfile() stuff
to take a "sparse mode" argument. and i _also_ haven't thought hard
enough about why tar.c's sparse file handling is a two-pass algorithm,
and whether that's meaningful for cp too.
(but i've been idly thinking about this for weeks without making any
forward progress, so it's time to just send a braindump :-) )
More information about the Toybox
mailing list