How to create holes in files ?

Fabian Keil freebsd-listen at fabiankeil.de
Thu Sep 28 15:36:35 UTC 2017


Ben RUBSON <ben.rubson at gmail.com> wrote:

> I'm trying to make holes in files in C.
> Goal is to deallocate huge files on ZFS while (randomly) reading them.

My interpretation of the above is that you want to create holes
without changing the file size and without affecting data that
is located before or after the holes that you want to create.

Otherwise you could simply "deallocate" the content with
truncate(1).

> The only thing I found is on Linux, fallocate(2) with
> FALLOC_FL_PUNCH_HOLE.
> 
> What about FreeBSD ?

I remember some discussions about adding something similar
for FreeBSD but I don't remember ever seeing any patches
(or commits) for it.

As a work around you can enable ZFS compression (if it isn't
enabled already) and "overwrite" data you don't need anymore
with zeros.

As an example see the delete_range() function in:
https://www.fabiankeil.de/sourcecode/electrobsd/ElectroBSD-r312620-6cfa243f1516/0033-ggate-cd-Add-BIO_DELETE-support.diff

Obviously this only works with ZFS, but you didn't mention
other file systems anyway.

Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20170928/3a7ffde2/attachment.sig>


More information about the freebsd-fs mailing list