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.
Upcoming OSR Seminars:

Developing File Systems for Windows, Boston, Waltham, MA 12-15 May, 2015
Windows Internals & Software Drivers Lab, Dulles/Sterling, VA, 18-22 May, 2015
Writing WDF Drivers: Core Concepts Lab, Boston/Waltham, MA 8-12 June, 2015
Writing WDF Drivers: Advanced Lab, Boston/Waltham, MA 15-18 June, 2015


Go Back   OSR Online Lists > ntfsd
Welcome, Guest
You must login to post to this list
  Message 1 of 6  
06 Dec 10 13:00
Russel McDonald
xxxxxx@swbell.net
Join Date: 30 Apr 2007
Posts To This List: 28
flush memory mapped file

Hi, I've been trying to find how to flush a memory mapped file created in my file system mini-filter driver for a few hours now and it does not seem obvious. I create it with ZwCreateSection and ZwMapViewOfSection using a file opened with ZwCreateFile. At certain critical points I need to be able to manually force all dirty pages to be flushed to disk synchronously. I see in use mode one can use FlushViewOfFile, but there seems to be no ZwFlushViewOfFile counter part. I also read about MmFlushImageSection and CcFlushCache but those require SECTION_OBJECT_POITNERS and seem to be for OS drivers. Is it possible to manually force a flush of all dirty pages as I want to do in my filter driver? Russel
  Message 2 of 6  
06 Dec 10 13:20
Alex Carp
xxxxxx@gmail.com
Join Date: 23 Feb 2010
Posts To This List: 950
flush memory mapped file

There is ZwFlushVirtualMemory, but I haven't ever used it... Though it seems to do what you need... Also, since you have a minifilter, you could use FltFlushBuffers. Thanks, Alex.
  Message 3 of 6  
06 Dec 10 13:25
Don Burn
xxxxxx@acm.org
Join Date:
Posts To This List: 941
flush memory mapped file

The kernel equivalent of FlushViewOfFile is ZwFlushVirtualMemory. Don Burn (MVP, Windows DKD) Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr "xxxxx@swbell.net" <xxxxx@swbell.net> wrote in message news:89418@ntfsd: > Hi, > I've been trying to find how to flush a memory mapped file created in my file system mini-filter driver for a few hours now and it does not seem obvious. I create it with ZwCreateSection and ZwMapViewOfSection using a file opened with ZwCreateFile. At certain critical points I need to be able to manually force all dirty pages to be flushed to disk synchronously. > I see in use mode one can use FlushViewOfFile, but there seems to be no ZwFlushViewOfFile counter part. I also read about MmFlushImageSection and CcFlushCache but those require SECTION_OBJECT_POITNERS and seem to be for OS drivers. > Is it possible to manually force a flush of all dirty pages as I want to do in my filter driver? > > Russel
  Message 4 of 6  
06 Dec 10 16:48
Pavel Lebedinsky
xxxxxx@microsoft.com
Join Date: 24 Feb 2009
Posts To This List: 43
flush memory mapped file

ZwFlushVirtualMemory is not synchronous. User mode docs for FlushViewOfFile say that you have to call FlushFileBuffers (which translates to ZwFlushBuffersFile/FltFlushBuffers in the kernel) after flushing the view in order to get synchronous behavior. -----Original Message----- From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Don Burn Sent: Monday, December 06, 2010 10:25 AM To: Windows File Systems Devs Interest List Subject: Re:[ntfsd] flush memory mapped file The kernel equivalent of FlushViewOfFile is ZwFlushVirtualMemory. Don Burn (MVP, Windows DKD) Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr "xxxxx@swbell.net" <xxxxx@swbell.net> wrote in message news:89418@ntfsd: > Hi, > I've been trying to find how to flush a memory mapped file created in my file system mini-filter driver for a few hours now and it does not seem obvious. I create it with ZwCreateSection and ZwMapViewOfSection using a file opened with ZwCreateFile. At certain critical points I need to be able to manually force all dirty pages to be flushed to disk synchronously. > I see in use mode one can use FlushViewOfFile, but there seems to be no ZwFlushViewOfFile counter part. I also read about MmFlushImageSection and CcFlushCache but those require SECTION_OBJECT_POITNERS and seem to be for OS drivers. > Is it possible to manually force a flush of all dirty pages as I want to do in my filter driver? > > Russel --- NTFSD is sponsored by OSR For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
  Message 5 of 6  
07 Dec 10 13:14
Russel McDonald
xxxxxx@swbell.net
Join Date: 30 Apr 2007
Posts To This List: 28
flush memory mapped file

You guys are the best! Thanks so much. I'll try the FlushFileBuffers as well for synchronous behavior. Will post back once I get it working in case anyone else needs this. I need the synchronous part since I'm filtering a SQL Server database and to maintain crash-scenario integrity I need our memory mapped file flushed to disk before completing a SQL Server file header page write (which has the log LSNs in it). Thanks again.
  Message 6 of 6  
08 Dec 10 10:46
Russel McDonald
xxxxxx@swbell.net
Join Date: 30 Apr 2007
Posts To This List: 28
flush memory mapped file

Yep that worked. Thanks! if (pFilterCtx->hBitMapFile) { NTSTATUS rcFlush = ZwFlushVirtualMemory(ZwCurrentProcess(), &pFlushBaseAddress, &iFlushLen, &iostat); DbgTrace(("ZwFlushVirtualMemory - rcFlush: %d iostat: %d\n",rcFlush, iostat.Status)); if (pFilterCtx->pBitMapFileObject) { NTSTATUS rcFlushBuffers = FltFlushBuffers(pCfltRelatedObjects->Instance, pFilterCtx->pBitMapFileObject); DbgTrace(("FltFlushBuffers - rc: %d\n",rcFlushBuffers)); } }
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 13:42.


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