| James T. Dennis 2005-10-08, 8:48 pm |
| In comp.unix.admin Stephane CHAZELAS <this.address@is.invalid> wrote:
> 2004-10-16, 02:05(+00), Ivan Rayner:
> [...]
[vbcol=seagreen]
> Using which API?
Some systems provide ioctl()s for this.
> [...]
> That would be very surprising given that GNU cp (at least from
> coreutils 5.2.1) has no code for that. All it does is create as
> many holes as possible in the destination file if it's a regular
> file.
Yes. As for as I know the best strategy for generating a sparse
file is to translate any streams of ASCII NUL characters into
seek() (lseek()) calls. The underlying filesystem will then refrain
from allocating any unnecessary blocks. (So there will be a number
of NULs written to the nearest block boundary, then zero or more blocks
my be left unallocated, and then some NULs may be written into the next
non-empty block --- as a result of the next write.
When I teach classes in Linux/UNIX fundamentals I teach that sparse
files are really a side effect of the filesystem block allocation
strategy. That the system can treat "holes" as blocks of contiguous
steams of NULs (for reads) and that the result naturally from seek()s
past the end of the file.
--
Jim Dennis,
Starshine: Signed, Sealed, Delivered
|