Why existing APIs for file creation suck
Published on 2007/07/21 by Igor Levicki
I was thinking about modern filesystems and related operating system file access APIs and I come to a shocking realization. They suck.
You see, it is not just filesystems themselves which do not prevent fragmentation. In my opinion, badly thought out file creation APIs in all "modern" operating systems (including Linux) bear much more guilt for your system slowing down due to excessive disk fragmentation.
At the moment of this writing, when an application creates a file, there is no way to pass the hint about the final file size to the operating system.
Isn't that a gaping hole in the API design? Sure. Why it hasn't been fixed yet? Of course it is not possible to patch existing applications, but why there is no CreateFileEx() which accepts final file size as one of its parameters, and why application developers are not encouraged to use it?
Think about it, if filesystem knows the file size of the newly created file, it will be able to place it so as to avoid the fragmentation. I know that not all files have their size known in advance but even an educated guess would be better than no such information at all.