I need a开发者_StackOverflow中文版t 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.
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
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.
精彩评论