alternative to FltFlushBuffers2() in OS version prior to 19041

Sagi Zar 6 Reputation points
2020-12-24T14:38:21.67+00:00

Hi,

I'm implementing a minifilter driver and I need to flush and purge the cache of files that I monitor.
This is for flush and purge the cache after write and read requests that were initiated by user-mode applications.
I saw that recently Microsoft added a new API FltFlushBuffers2() that does flush and can also purge the cache.
In the past I used the cache manager API's to do that, but they are not safe to use and cause my driver to hang from time to time.
FltFlushBuffers2() seems to be supported only from Windows build version 19041 which still can't be installed on all computers.
What alternatives I have if I need to flush and purge files that I monitor from within my minifilter?

Thanks,
Sagi

Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,625 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Neal Christiansen 1 Reputation point Microsoft Employee
    2021-01-06T07:06:32.937+00:00

    The underlying functionality made available via FltFlushBuffers2 API has been in the system since at least Windows 7.

    Your minifilter can generate its own CallbackData structure and issue its own FLUSH api. It would like something like this:

    status = FltAllocateCallbackData( YourInstance, FileObjectToFlush, &cbd);
    cbd->Iopb->MajorFunction = IRP_MJ_FLUSH_BUFFERS;
    cbd->Iopb->MinorFUnction = IRP_MN_FLUSH_AND_PURGE;
    cbd->Iopb->IrpFlags = IRP_SYNCHRONOUS_API;
    
    FltPerformSynchronousIO(cbd);
    

    I have not tried executing this code but this should work.

    If you already have a handle created via FltCreateFile (or one of its variants), if you call ZwFlushBuffersFileEx using that handle, the flush request will be properly targeted to filters below you and wi

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.