How to generate a large file allocating space

Alex Bligh alex at
Sun Oct 31 10:12:41 UTC 2010

I want to generate or extend a large file in an ext4 filesystem allocating
space (i.e. not creating a sparse file) but not actually writing any data.
I realise that this will result in the file containing the contents of
whatever was there on the disk before, which is a possible security problem
in some circumstances, but it isn't a problem here.

Ideally what I'd like is a "make unsparse" bit of code. I'm happy for this
to use the libraries, and work on an unmounted fs (indeed that is probably

Supplementary question: can I assume that if a non-sparse file is on disk
and never opened, and never unlinked, then the sectors used to to store
that file's data will never change irrespective of other operations on the
ext4 filesystem? IE nothing is shuffling where ext4 files are stored.

Alex Bligh

More information about the Ext3-users mailing list