There IS a solution, and it’s heinous. This has been discussed here previously. You can call MmCanFileBeTruncated from IRP_MJ_CLEANUP to determine whether or not there are any user mapped views of the file. If not, flush the modified data. If it is user mapped, you will have to wait for the IRP_MJ_CLOSE.
-----Original Message-----
From: Robin [mailto:xxxxx@xpsonline.com]
Sent: Wednesday, February 20, 2002 3:19 AM
To: File Systems Developers
Subject: [ntfsd] RE: How to check if there is dirty data in the cache
after IRP_MJ_CLEANUP
Hello,
Thanks for the reply. I considered flushing the modified pages in the
cache, but it appears to me that it may not be the proper solution in my
case. Here is the explanation:
My driver is just passively watching the file write (and other
modification) operation for replication purpose. It is not modifying the
file data in the cache. I would also prefer not to alter the system
behavior by flushing the modified pages earlier.
But calling CcFlushCache may not ensure that all modified pages will be
written to storage device as I understand it does not flush the buffer
currently pinned in the memory. Users may also close the handle of a memory
mapped file but continue to modify it through its mapped view. I think in
that case the driver will receive the IRP_MJ_CLEANUP when the file handle
is closed. But the system will continue to flush modified pages through
paging I/O as user modifies them in the cache.
So, some way to check if there is still modified page(s) in the cache for a
FileObject in IRP_MJ_WRITE, and IRP_MJ_CLEANUP completion handler, and wait
till the system flushes all modified pages, would be my preferred solution.
Any alternative idea on how to do that?
In another related problem, if my driver opens a file (from a system worker
thread) for writing with FILE_SHARE_READ sharing mode, Windows does not
even allow to open that file in read-only mode by another process. For
example, “Notepad” displays an error message “The process cannot access the
file because it is being used by another process”.
Any idea on why this is happening and if there is some way to allow user to
open a file (for reading only) that is being used by the device diver?
Thanks in advance for any reply.
Regards,
Robin
At 12:42 AM 2/20/02, you wrote:
Well, it’s certainly impossible to PURGE memory-mapped cache pages, but
there is no restriction against forcing a modified memory map to flush
to disk. The poster may run into problems if he is doing something like
in-place encryption of data in the cache while it’s still memory-mapped,
so if he is doing something that may conflict with a user simultaneously
writing to the mapped cache pages, he should check for the
FSRTL_FLAG_USER_MAPPED_FILE flag and not perform the post-processing.I shouldn’t have even mentioned the CcPurgeCacheSection call below, it’s
not necessary if all you want to do is flush dirty data (as opposed to
blowing away the entire cache).
- Nicholas Ryan
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> xxxxx@lists.osr.com] On Behalf Of Fuller, Rob
> Sent: Tuesday, February 19, 2002 10:36 AM
> To: File Systems Developers
> Subject: [ntfsd] RE: How check if there is dirty data in the cache
after
> IRP_MJ_CLEANUP
>
> If I understand the memory manager correctly, this guarantee breaks if
the
> file is memory mapped.
>
> -----Original Message-----
> From: Nicholas Ryan [mailto:xxxxx@secretseal.com]
> Sent: Tuesday, February 19, 2002 1:13 PM
> To: File Systems Developers
> Subject: [ntfsd] RE: How check if there is dirty data in the cache
after
> IRP_MJ_CLEANUP
>
>
> Well what you can do is ENSURE there is no dirty data for a file in
your
> cleanup handler, and then do whatever post-processing is necessary. To
> do this, take both FCB resources exclusive and then flush the NT cache
> for the file using
CcFlushCache/MmFlushImageSection/CcPurgeCacheSection.
> Now it’s been guaranteed that all modified pages have been flushed to
> disk. Then perform your post-processing before releasing the FCB
> resources.
>
> - Nicholas Ryan
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> > xxxxx@lists.osr.com] On Behalf Of Robin
> > Sent: Tuesday, February 19, 2002 4:00 AM
> > To: File Systems Developers
> > Subject: [ntfsd] How check if there is dirty data in the cache after
> > IRP_MJ_CLEANUP
> >
> > Hello all,
> >
> > I am monitoring file modifications (specially IRP_MJ_WRITE) from a
> filter
> > driver and need to do something when all handles to a monitored file
> are
> > closed and there is no more dirty data in the cache for this file.
The
> > problem is how can I determine if there is still dirty data in the
> cache
> > for this file and when the last dirty page for this file is flushed
> out to
> > the disk using a paging IO through IRP_MJ_WRITE? I want to check
this
> in
> > the completion routine of both IRP_MJ_CLEANUP and IRP_MJ_WRITE (for
> paging
> > IO only).
> >
> > Is there something like “CcIsThereDirtyData” for the FileObject? I
> have
> > tried “CcGetLsnForFileObject”, but it is always returning zero.
> >
> > Any idea on how to solve this problem (on NT/2K/XP) will be highly
> > appreciated. Thanks in advance.
> >
> > Regards,
> > Robin
> >
> >
You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com