Jump-start your project by learning from devs who
write Windows drivers and file systems every day.
Take an OSR seminar!

OSR is Hiring! Click here to find out more.

Upcoming OSR Seminars:
Kernel Debugging & Crash Analysis Lab, Dulles/Sterling, VA 24-28 March, 2014
Writing WDF Drivers for Windows Lab, Palo Alto, CA 28 April-2 May, 2014
Advanced WDF Driver Lab, Palo Alto, CA 5-8 May, 2014
Developing File Systems for Windows, Boston/Waltham, MA 13-16 May, 2014
Windows Internals & Software Drivers Lab, Dulles/Sterling, VA, CA 23-27 June, 2014


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: 22
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: 898
RE: 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
Re: 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: 41
RE: Re: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: 22
RE: 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: 22
RE: 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 17:46.


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