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.

OSR Seminars

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
Join Date: 17 Feb 2012
Posts To This List: 684
Re[2]: How to flush memory mapped files?

In addition to these comments, check out the FAT source code to see how it attempts to maintain data sync for the various write pathways. It performs, or attempts to perform a flush, for example in the non-cached (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 866.263.9295 ------ Original Message ------ From: To: "Windows File Systems Devs Interest List" <> 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 >CcFlushCache is your friend as it calls MmFlushSection even for >non-cached files ( i.e. mapped but not cached ), if the file is mapped >and cached then the cache is supported by the same pages as the mapped >virtual address range. Do not forget about proper synchronization >before calling CcFlushCache. > >If your driver doesn't maintain file objects and uses file objects >initialized by FSD(file system driver) it is attached to then there is >no common way to do this. You can play with IRP_MJ_FLUSH_BUFFERS or you=20 <...excess quoted lines suppressed...>
  Message 2 of 3  
21 Mar 17 03:44
Hunter Wang
Join Date: 20 Mar 2017
Posts To This List: 9
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
Join Date: 13 Sep 2013
Posts To This List: 264
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 14:45.

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