To flush cache, should a Windows file system filter driver use CcFlushCache() directly or create/send a FSD request with major function IRP_MJ_FLUSH_BUFFERS? After searching online, we got two completely opposite answers:
"The first thing to note is that CcFlushCache and CcPurgeCache are not
for use by filters. They are there for Filesystems to take advantage of.
This doesn’t stop people from using them and it “mostly” works, but callers
of these functions should be aware that Cc Expects you to hold “the right
locks” when they are called and you will eventually deadlock or crash
otherwise.
?
Subject to certain restrictions that the FSD may impose, yes. Remember
however you have no guarantee that when this returns someone won’t have
written to a mapped file and dirtied it again. Filters would be better
sending an IRP_MJ_FLUSH IRP"
“The IRP_MJ_FLUSH_BUFFERS request is sent by the I/O Manager and other operating system components, as well as other kernel-mode drivers, when buffered data needs to be flushed to disk. It can be sent, for example, when a user-mode application has called a Microsoft Win32 function such as FlushFileBuffers. (For file system drivers and file system filter drivers, calling CcFlushCache is usually preferable to sending an IRP.)”
I would appreciate your opinion or suggestions.