Reputation: 4604
Is it valid to call CreateFile with the FILE_FLAG_NO_BUFFERING
flag but without the FILE_FLAG_WRITE_THROUGH
flag? In what situations will this usage be considered useful?
FILE_FLAG_NO_BUFFERING
indicates the OS shouldn't buffer the data, but the absence of FILE_FLAG_WRITE_THROUGH
indicates the OS shouldn't write through to the disk. These seem like conflicting requirements, how can the OS not buffer and not write-through?
Upvotes: 1
Views: 3674
Reputation: 185
According to a recent Microsoft blog post, the FILE_FLAG_WRITE_THROUGH
flag "[tells] the disk controller to flush the data out of its internal cache."
The table at the bottom of that post further clarifies that there is "no hardware flush" when FILE_FLAG_NO_BUFFERING
is set without FILE_FLAG_WRITE_THROUGH
.
Also, as Eryk Sun previously noted in a comment, FILE_FLAG_NO_BUFFERING
is not documented to immediately write file metadata to disk, whereas FILE_FLAG_WRITE_THROUGH
is documented to immediately write file metadata to disk. This makes sense because the focus of FILE_FLAG_NO_BUFFERING
is to avoid copying of file data into OS-owned buffers, which seems an unreasonable goal for file system metadata since that would necessitate restricting file systems to one specific, publicly defined on-disk layout of file metadata.
Upvotes: 1