[Mono-dev] Sparse files

Robert Jordan robertj at gmx.net
Sun Mar 25 16:29:00 EDT 2007


David Brown wrote:
> Alan McGovern wrote:
> 
>> Not quite, a sparse file is different to a normal file in how
>> allocations happen. For example if i wanted to write 1 megabyte at
>> an index of 100 megabytes, a seek + write would result in a 101
>> megabyte file on the disk.
> 
>> With a sparse file, there'd actually be 1 megabyte physically taken
>> up on disk but any program that tries to read that file would see
>> that 1 megabyte existing at an offset of 100 megabytes. (At least
>> that's my understanding of it).
> 
> The is no Unix API for creating sparse files.  Unix only allocates
> space on write.  If you seek 100 MB into a file and write 1MB, you'll
> only write 1MB of data.  Depending on the filesystem overhead, there
> will be some space taken to manage the gap, but much less then 100MB.
> 
> Standard Unix doesn't provide any API to detect the sparse data, it
> just reads back as zero.

It does. Use stat(2) and check the st_blocks member.

Robert




More information about the Mono-devel-list mailing list