Lothar
Lothar

Reputation: 13092

Operating system API for accessing sparse files?

I need at least to test if a byte range in a file does really exist or is void.

It needs to work on the major Operating Systems: Unix (Linux/MacOSX/FreeBSD) and Windows.

I guess there is still no way to shoot holes into files or are there some file system specific API's and proposals? This would also be so great for log files.

Upvotes: 1

Views: 279

Answers (2)

wnoise
wnoise

Reputation: 9942

I know of no portable way to test for sparsity. To create a file with holes, you have to seek() over the holes of zeroes, rather than writing them. This obviously only works when creating new files or extending old ones. Using seek() on preexisting zeroes will do nothing.

Upvotes: 0

Maxim Razin
Maxim Razin

Reputation: 9466

On Windows, you can use FSCTL_GET_RETRIEVAL_POINTERS to find the mapping between file clusters and disk.

The corresponding Linux (and probably some other posixes) IOCTL is FIBMAP

Upvotes: 2

Related Questions