[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Sparse File Creation



Steven Chervets wrote:
> I need to create an 8 GB sized sparse file which will do an actual  
> block allocation.  In other words, I want to allocate the blocks in  
> the directory structure, but not fill them with zeroes until they are  
> actually used.  Since this will be implemented in a closed appliance  
> I'm not concerned about security and can execute any command as root.
> 
> I have tried the dd seek command.  And while it creates a sparse file,  
> it doesn't reserve the blocks.
> 
> Thank you for your help.
> 
> Steve

Hi Steve -

On ext3 your only option to allocate a block is to write something into it.

On ext4, xfs, and similar extent-based filesystems, blocks are tracked
with more metadata (the extent structures) so they can be allocated
quickly and flagged as unwritten so that they will be read back as
zeros.  You can get to this through the fallocate syscall, glibc's
posix_fallocate(3) (which falls back to 0-writing if the fs doesn't
support sys_fallocate), and in bleeding-edge glibc, the fallocate(2) call.

Since you say you don't care about security, ext3 could probably be
hacked to skip the actual block initialization part and expose garbage,
but this is generally something filesystem try *very* hard to avoid, and
I don't think there'll be any way to do it with the stock code.

-Eric


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]