NTFS does support sparse files, but I want to make sure the files I have to write to (which might have been created, set as sparse, and partially filled by another application) are fully allocated, so that I won't get an error due to lack of space when writing to the middle of such file at a later time (i.e. if they are to happen, out of space errors should happen now).
Is there a WinAPI function to ensure a sparse file is fully allocated (preferably atomically), like we have posix_fallocate()
in POSIX systems? If not, how do I preallocate it?
I don't think these are duplicates:
- How do you pre-allocate space for a file in C/C++ on Windows? - the question is about files in general, which in Windows are non-sparse by default, so the answers don't address how to do it with sparse files.
- How to create a file of a particular size on windows without io? - this question specifically asks about
posix_fallocate()
, but proceeds to ask a question that almost the opposite, i.e. how to create a large file quickly on Windows (for which one commenter suggested NTFS sparse files).