How to create holes in files ?

Ben RUBSON ben.rubson at gmail.com
Fri Sep 29 07:32:02 UTC 2017


> On 29 Sep 2017, at 09:08, Bob Eager <rde at tavi.co.uk> wrote:
> 
> On Fri, 29 Sep 2017 08:26:13 +0200
> Ben RUBSON <ben.rubson at gmail.com> wrote:
> 
>> Unfortunately here storage blocks will be set/written to 0,
>> they will not be freed/recovered, a file hole will not be created.
> 
> You need to add:  conv=sparse    to the dd command to turn zero blocks
> into unallocated blocks.

You're right Bob it works :

# dd if=/dev/random of=f bs=1M count=4
4+0 records out

# zfs userspace home
POSIX User  root  4.04M   none

# dd if=/dev/zero of=f bs=1M count=2 seek=2 conv=sparse
2+0 records out


# zfs userspace home
POSIX User  root  2.04M   none

# ls -lh f
-rw-------  1 root  wheel   4.0M 29 Sep 09:25 f


Unfortunately, using "conv=notrunc,sparse" to make a hole in the middle
of a file does not seem to work, file is truncated :

# rm f

# dd if=/dev/random of=f bs=1M count=4
4+0 records out

# dd if=/dev/zero of=f bs=1M count=1 seek=2 conv=notrunc,sparse
1+0 records out

# ls -lh f
-rw-------  1 root  wheel   3.0M 29 Sep 09:26 f

# zfs userspace home
POSIX User  root  3.04M   none


Anyway thank you for this tip, this is something to analyse !

Ben



More information about the freebsd-fs mailing list