Purging file cache in IRP_MJ_CREATE

I need to purge the data in the cache during an IRP_MJ_CREATE call.
How do I do that? Calling CcFlushCache or CcPurgeCacheSection causes
a bug check, saying 0xD5 (“memory used after being freed”).
Any clues? The IRP_MJ_CREATE handler does nothing special, it only
gets the file name, and tried to purge the cache section.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


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

This works for me:

a. Lock the FCB Resource exclusive (after checking for non-NULL).
a. Lock the FCB PagingIoResource exclusive (after checking for non-NULL
and in a polling loop to prevent deadlocks, since different filesystems
will apparently acquire these two locks in different orders).
a. If fobj->SectionObjectPointer is non-NULL then:

  • do a CcFlushCache for the entire file

  • do a MmFlushImageSection for write if
    fobj->SectionObjectPointer->ImageSectionObject is
    non-NULL

  • do a CcPurgeCacheSection (last param FALSE) if
    fobj->SectionObjectPointer->DataSectionObject is
    non-NULL
    a. Unlock the FCB PagingIoResource if you locked it.
    a. Unlock the FCB Resource if you locked it.

  • Nicholas Ryan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Friday, January 18, 2002 4:53 PM
To: File Systems Developers
Subject: [ntfsd] Purging file cache in IRP_MJ_CREATE

I need to purge the data in the cache during an IRP_MJ_CREATE
call.
How do I do that? Calling CcFlushCache or CcPurgeCacheSection
causes
a bug check, saying 0xD5 (“memory used after being freed”).
Any clues? The IRP_MJ_CREATE handler does nothing special, it only
gets the file name, and tried to purge the cache section.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: xxxxx@secretseal.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

OK the previous message got completely garbled, let’s have another go at
it:

This works for me:

  1. Lock the FCB Resource exclusive (after checking for non-NULL).
  2. Lock the FCB PagingIoResource exclusive (after checking for non-NULL
    and in a polling loop to prevent deadlocks, since different filesystems
    will apparently acquire these two locks in different orders).
  3. If fobj->SectionObjectPointer is non-NULL then:
    3a. do a CcFlushCache for the entire file
    3b. do a MmFlushImageSection for write if
    fobj->SectionObjectPointer->ImageSectionObject is
    non-NULL
    3c. do a CcPurgeCacheSection (last param FALSE) if
    fobj->SectionObjectPointer->DataSectionObject is
    non-NULL
  4. Unlock the FCB PagingIoResource if you locked it.
  5. Unlock the FCB Resource if you locked it.
  • Nicholas Ryan

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Friday, January 18, 2002 4:53 PM
To: File Systems Developers
Subject: [ntfsd] Purging file cache in IRP_MJ_CREATE

I need to purge the data in the cache during an IRP_MJ_CREATE
call.
How do I do that? Calling CcFlushCache or CcPurgeCacheSection
causes
a bug check, saying 0xD5 (“memory used after being freed”).
Any clues? The IRP_MJ_CREATE handler does nothing special, it only
gets the file name, and tried to purge the cache section.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32
developers.
Alfa Registry Protector - Registry protection library for Win32
developers.


You are currently subscribed to ntfsd as: xxxxx@secretseal.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

Thanks, I’ll try that!

Nicholas Ryan wrote:

OK the previous message got completely garbled, let’s have another go at
it:

This works for me:

  1. Lock the FCB Resource exclusive (after checking for non-NULL).
  2. Lock the FCB PagingIoResource exclusive (after checking for non-NULL
    and in a polling loop to prevent deadlocks, since different filesystems
    will apparently acquire these two locks in different orders).
  3. If fobj->SectionObjectPointer is non-NULL then:
    3a. do a CcFlushCache for the entire file
    3b. do a MmFlushImageSection for write if
    fobj->SectionObjectPointer->ImageSectionObject is
    non-NULL
    3c. do a CcPurgeCacheSection (last param FALSE) if
    fobj->SectionObjectPointer->DataSectionObject is
    non-NULL
  4. Unlock the FCB PagingIoResource if you locked it.
  5. Unlock the FCB Resource if you locked it.
  • Nicholas Ryan

> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
> xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
> Sent: Friday, January 18, 2002 4:53 PM
> To: File Systems Developers
> Subject: [ntfsd] Purging file cache in IRP_MJ_CREATE
>
>
> I need to purge the data in the cache during an IRP_MJ_CREATE
call.
> How do I do that? Calling CcFlushCache or CcPurgeCacheSection
causes
> a bug check, saying 0xD5 (“memory used after being freed”).
> Any clues? The IRP_MJ_CREATE handler does nothing special, it only
> gets the file name, and tried to purge the cache section.
>
> –
> Kind regards, Dejan M. www.alfasp.com
> E-mail: xxxxx@alfasp.com ICQ#: 56570367
> Alfa File Monitor - File monitoring library for Win32 developers.
> Alfa File Protector - File protection and hiding library for Win32
> developers.
> Alfa Registry Monitor - Registry monitoring library for Win32
> developers.
> Alfa Registry Protector - Registry protection library for Win32
> developers.
>
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@secretseal.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@alfasp.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


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

Yap, it works.
I had a problem in another place:-)
Now, another question: does the below code purge the read cache, too?
I need for the file system to return the non cached data, again.
I’m trying to create an encryption driver, and it is required that read
buffers are emptied if any application has read the data before, as the real
data now would need to be decrypted.

Regards, Dejan.

Nicholas Ryan wrote:

OK the previous message got completely garbled, let’s have another go at
it:

This works for me:

  1. Lock the FCB Resource exclusive (after checking for non-NULL).
  2. Lock the FCB PagingIoResource exclusive (after checking for non-NULL
    and in a polling loop to prevent deadlocks, since different filesystems
    will apparently acquire these two locks in different orders).
  3. If fobj->SectionObjectPointer is non-NULL then:
    3a. do a CcFlushCache for the entire file
    3b. do a MmFlushImageSection for write if
    fobj->SectionObjectPointer->ImageSectionObject is
    non-NULL
    3c. do a CcPurgeCacheSection (last param FALSE) if
    fobj->SectionObjectPointer->DataSectionObject is
    non-NULL
  4. Unlock the FCB PagingIoResource if you locked it.
  5. Unlock the FCB Resource if you locked it.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


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

> -----Original Message-----

From: xxxxx@lists.osr.com [mailto:bounce-ntfsd-
xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Friday, January 18, 2002 7:40 PM
To: File Systems Developers
Subject: [ntfsd] RE: Purging file cache in IRP_MJ_CREATE

Yap, it works.
I had a problem in another place:-)
Now, another question: does the below code purge the read cache,
too?
I need for the file system to return the non cached data, again.

Yes. It will of course fail if there is a user-mode mapping open for the
file. Memory-mapping under NT is a total pain in the ass for filter
driver developers, I tell you…

  • Nicholas Ryan

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

> Yes. It will of course fail if there is a user-mode mapping open for the

file. Memory-mapping under NT is a total pain in the ass for filter
driver developers, I tell you…

This shouldn’t be a problem, as at IRP_MJ_CREATE time mappings should
not be present.
But, the user won’t care for “shoulds” of course:-)


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


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

Surely, if the cache map was not initialized for a file - you can have this effect.

Max

----- Original Message -----
From: “Dejan Maksimovic”
To: “File Systems Developers”
Sent: Saturday, January 19, 2002 3:52 AM
Subject: [ntfsd] Purging file cache in IRP_MJ_CREATE

>
> I need to purge the data in the cache during an IRP_MJ_CREATE call.
> How do I do that? Calling CcFlushCache or CcPurgeCacheSection causes
> a bug check, saying 0xD5 (“memory used after being freed”).
> Any clues? The IRP_MJ_CREATE handler does nothing special, it only
> gets the file name, and tried to purge the cache section.
>
> –
> Kind regards, Dejan M. www.alfasp.com
> E-mail: xxxxx@alfasp.com ICQ#: 56570367
> Alfa File Monitor - File monitoring library for Win32 developers.
> Alfa File Protector - File protection and hiding library for Win32
> developers.
> Alfa Registry Monitor - Registry monitoring library for Win32
> developers.
> Alfa Registry Protector - Registry protection library for Win32
> developers.
>
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.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

> Surely, if the cache map was not initialized for a file - you can have this effect.

I knew I should’ve mentioned that I check if it’s cached, as someone would say
this:-))
It was a different issue.


Kind regards, Dejan M. www.alfasp.com
E-mail: xxxxx@alfasp.com ICQ#: 56570367
Alfa File Monitor - File monitoring library for Win32 developers.
Alfa File Protector - File protection and hiding library for Win32 developers.
Alfa Registry Monitor - Registry monitoring library for Win32 developers.
Alfa Registry Protector - Registry protection library for Win32 developers.


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