[PATCH] adding two new options to 'cp'

Rick C. Petty rick-freebsd at kiwi-computer.com
Tue Aug 1 20:18:08 UTC 2006


On Wed, Aug 02, 2006 at 05:04:53AM +1000, Peter Jeremy wrote:
> On Tue, 2006-Aug-01 12:51:32 -0500, Eric Anderson wrote:
> >string of zeros larger than the block size, or it needs to 'do the right 
> >thing' and determine if it's sparse or not.
> 
> You can do this by comparing stat.st_size with stat.st_blocks - a
> sparse file will have fewer blocks than its size requires.  What you
> can't do is accurately determine where the holes are.
> 
> Note that st_blksize is not nessarily the allocation blocksize and
> therefore is unrelated to the size of holes in the filesystem.  Also,
> on FreeBSD, the designation of "optimal" is a misnomer and I/O
> operations should be much larger than this for optimal efficiency.

True, but I've not seen the case where the following is not true:
The filesystem's block size (i.e. 8x fragment size) in UFS an integer
multiple of st_blksize.  My previously-posted example would work just
fine.  I guess a better solution would be to check every 512-byte chunk
and seek if zero.  It's up to the underlying filesystem to implement
this as a sparse file, if that filesystem supports such a thing.

-- Rick C. Petty


More information about the freebsd-hackers mailing list