Driver Problems? Questions? Issues?
Put OSR's experience to work for you! Contact us for assistance with:
  • Creating the right design for your requirements
  • Reviewing your existing driver code
  • Analyzing driver reliability/performance issues
  • Custom training mixed with consulting and focused directly on your specific areas of interest/concern.
Check us out. OSR, the Windows driver experts.

On-Access, Transparent, Per-File Data Encryption:

OSR's File Encryption Solution Framework (FESF) provides all the infrastructure you need to build a transparent file encryption product REALLY FAST.

Super flexible policy determination and customization, all done in user-mode. Extensive starter/sample code provided.

Proven, robust, flexible. In use in multiple commercial products.

Currently available on Windows. FESF for Linux will ship in 2018.

For more info: https://www.osr.com/fesf

Go Back   OSR Online Lists > ntfsd
Welcome, Guest
You must login to post to this list
  Message 1 of 3  
20 Mar 17 15:39
Peter Scott
xxxxxx@kerneldrivers.com
Join Date: 17 Feb 2012
Posts To This List: 669
Re[2]: How to flush memory mapped files?

In addition to these comments, check out the FAT source code to see how=20 it attempts to maintain data sync for the various write pathways. It=20 performs, or attempts to perform a flush, for example in the non-cached=20 (non-paging) path prior to allowing the IO through if there is a backing= =20 section to the file. Pete -- Kernel Drivers Windows File System and Device Driver Consulting www.KernelDrivers.com 866.263.9295 ------ Original Message ------ From: xxxxx@hotmail.com To: "Windows File Systems Devs Interest List" <xxxxx@lists.osr.com> Sent: 3/20/2017 1:08:55 PM Subject: RE:[ntfsd] How to flush memory mapped files? >If your driver maintains( i.e. initializes ) file objects then=20 >CcFlushCache is your friend as it calls MmFlushSection even for=20 >non-cached files ( i.e. mapped but not cached ), if the file is mapped=20 >and cached then the cache is supported by the same pages as the mapped=20 >virtual address range. Do not forget about proper synchronization=20 >before calling CcFlushCache. > >If your driver doesn't maintain file objects and uses file objects=20 >initialized by FSD(file system driver) it is attached to then there is=20 >no common way to do this. You can play with IRP_MJ_FLUSH_BUFFERS or you= =20 >can use CcFlushCache, in the latter with a risk of going into conflict=20 >with FSD and MM( Memory Manager ) as you will be unable to properly=20 >synchronize with FSD before calling CcFlushCache. > >--- >NTFSD is sponsored by OSR > > >MONTHLY seminars on crash dump analysis, WDF, Windows internals and=20 >software drivers! <...excess quoted lines suppressed...>
  Message 2 of 3  
21 Mar 17 03:44
Hunter Wang
xxxxxx@serpurity.com
Join Date: 20 Mar 2017
Posts To This List: 2
Re[2]: How to flush memory mapped files?

Yes, my filter maintains( i.e. initializes ) file objects, so in this situation CcFlushCache could flush memory mapped content into the file? Are you sure about that?
  Message 3 of 3  
21 Mar 17 07:59
Slava Imameev
xxxxxx@hotmail.com
Join Date: 13 Sep 2013
Posts To This List: 253
Re[2]: How to flush memory mapped files?

Yes I am sure. I can't point you to the source code. It is shame that Microsoft still thinks that preventing access to the source code does any good for Windows development and OS future. The sequence of calls will be CcFlushCache ->MmFlushSection->IoAsynchronousPageWrite->IoCallDriver( paging IRP_MJ_WRITE ) IoCallDriver recursively calls your filter with paging write request so you have dirty pages in hand. Here you need to decide how you are going to synchronize with a file on a disk/storage. Actually in most cases you need synchronize file caches/memory mapped data but not write data directly to the disk as changing data on the disk without changing the cached/mapped data will not provide you with a desired effect as user applications fetch data from the cache/mapped file. This might result in data inconsistencies when the system will synchronize the cache/mapped data with the data on storage/disk. I do not know your architecture. If you need to synchronize with files opened by user applications then you can copy data in a buffer ( I do not recommend to play with MDL here ), complete the paging write request as successful and issue a cached write to a file with which you want to synchronize data from a special worker thread used for data synchronization. In that case you know that when you are in this thread context you need either pass through the request to a lower FSD( if you are synchronizing with file objects initialized by a lower FSD ) or just call CcCopyWrite for file object your filter initialized ( if you are synchronizing with file objects initialized by your filter ). This will synchronize the cache and memory mapped file data and the data on the disk when the system will flush dirty pages. You can take a more risky approach and issue requests directly on paging write path. This is prone to deadlocks in the Memory Manager and FSD. As Done told you can't say with certainty that you flushed data for a file object on a lower FSD. Actually you don't need this as you need to synchronize cached/mapped data and let the system to do the rest.
Posting Rules  
You may not post new threads
You may not post replies
You may not post attachments
You must login to OSR Online AND be a member of the ntfsd list to be able to post.

All times are GMT -5. The time now is 07:21.


Copyright ©2015, OSR Open Systems Resources, Inc.
Based on vBulletin Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Modified under license