Hi,
Can anybody explain me, what exactly will not work (and why) when FileSystem driver will be implemented without CcInitializeCacheMap and related stuff.
I know all documentations says about problems with SECTION objects. But when I build my own FileSystem driver without using cache related functions, and test it from my own UserMode application for NtCreateSestion, NtMapViewOfSection, NtExtendSection and reading/writing mapped memory, every one operation was correctly translated to IRP for my FS driver…
So where is the problem ?
Thomas
To support mapping of the file into memory it is enough to set CurrentIrpSp->FileObject.FsContext+ SectionObjectPointer+PrivateCacheMap to correct values during IRP_MJ_CREATE. The FsContext must point to (nonpageble) FSRTL_COMMON_FCB_HEADER, which should be also correctly setup (Resource, PagingIoResource). The only functions from Cache Manager you should consider are: CcFlushCache() before you do non paged Read/Write or Cleanup, CcPurgeCacheSection() + MmFlushImageSection() in your cleanup to make Cache Manager + Memory Manager to release references to FILE_OBJECT, so IRP_MJ_CLOSE will be called. Note that it might not succeed.
You can use FSRTL_ADVANCED_FCB_HEADER instead of FSRTL_COMMON_FCB_HEADER to support context for minifilters. Consult documentation and WDK samples for using of FsRtlSetupAdvancedHeader() + FsRtlTeardownPerStreamContexts().
To briefly test that memory mapping works fine:
1)Execute .exe file from your FSD and check that you got IRP_MJ_CLOSE, when application exists
2) Use notepad to read + edit + save file and again check you get IRP_MJ_CLOSE when notepad is closed. Notepad uses memory mapped files.
It is not probably complete what you should do. Consider buying Rajeev Nagar’s book – Windows NT File System internals.
Hope it helps as a starting point.
-bg
The issue with cacheless FS driver is data inconsistency between file I/O view of file and MM view of file. Suppose, you MMapped file and read it through this mapping. After that all modifications to the file done via Write will not be visible through MM view. It’s already bad enough to question cacheless FS approach.
I am realizing that scenario described by Vladimir is not handled by approach described by me. By this approach you can keep consistency only in one direction, so we cannot call it by consistency :-). It should cover like 90-95% applications, but there are still holes.
-bg