Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results
The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.
Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/
Upcoming OSR Seminars | ||
---|---|---|
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead! | ||
Writing WDF Drivers | 7 Dec 2020 | LIVE ONLINE |
Internals & Software Drivers | 25 Jan 2021 | LIVE ONLINE |
Developing Minifilters | 8 March 2021 | LIVE ONLINE |
Comments
will do the trick.
As far as I remember, if that flag is set FSD will purge the file cache as
part of the create request handling.
Vladimir
-----Original Message-----
From: Mark Twain [mailto:[email protected]]
Sent: Tuesday, April 04, 2000 11:10 AM
To: File Systems Developers
Subject: [ntfsd] File Cache Purge
Hello,
Do you know how can I purge the cache for a given file and re-read this file
from the disk?
Best:
Mark
> -----Original Message-----
> From: Mark Twain
> Sent: martes 4 de abril de 2000 18:10
> To: File Systems Developers
> Subject: [ntfsd] File Cache Purge
>
> Hello,
> Do you know how can I purge the cache for a given file and re-read this
> file from the disk?
>
> Best:
> Mark
mapping.
In other case, CcPurgeCacheSection helps.
Max
----- Original Message -----
From: Mark Twain
To: File Systems Developers
Sent: Tuesday, April 04, 2000 8:09 PM
Subject: [ntfsd] File Cache Purge
Hello,
Do you know how can I purge the cache for a given file and re-read this file
from the disk?
Best:
Mark
I was thinking the same but the next function doesn't work. Can somebody
explains me why after everything is successfull? It seems that the purge is
OK but the file is not re-read from the disk. It's obtained again from the
cache.
BOOLEAN
PurgeFile (
)
{
WCHAR filename[] = L"\\??\\E:\\diddid.txt";
UNICODE_STRING fileNameUnicodeString;
OBJECT_ATTRIBUTES objectAttributes;
PFILE_OBJECT fileObject;
HANDLE ntFileHandle;
PFSRTL_COMMON_FCB_HEADER Fcb;
BOOLEAN result = TRUE, IoPagingRelease = FALSE,
MainResRelease = FALSE;
NTSTATUS status;
IO_STATUS_BLOCK ioStatus;
//Open file
RtlInitUnicodeString( &fileNameUnicodeString, filename );
InitializeObjectAttributes( &objectAttributes,
&fileNameUnicodeString,
OBJ_CASE_INSENSITIVE, NULL, NULL);
status = ZwCreateFile( &ntFileHandle, SYNCHRONIZE|FILE_ANY_ACCESS,
&objectAttributes, &ioStatus, NULL,0,0,
FILE_OPEN,
FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE,
NULL, 0 );
if( !NT_SUCCESS( status ) ) return FALSE;
// Find file-object it refers to
status = ObReferenceObjectByHandle( ntFileHandle, FILE_READ_DATA,
NULL, KernelMode,
(PVOID*)&fileObject, NULL );
if( !NT_SUCCESS( status )) {
ZwClose( ntFileHandle );
return FALSE;
}
Fcb = (PFSRTL_COMMON_FCB_HEADER)(fileObject->FsContext);
if (Fcb==NULL) return FALSE;
if (!ExAcquireResourceExclusive(Fcb->Resource, TRUE ))
result = FALSE;
else MainResRelease = TRUE;
if (!ExAcquireResourceExclusive( Fcb->PagingIoResource , TRUE ))
result = FALSE ;
else IoPagingRelease = TRUE;
if (result &&
(fileObject->SectionObjectPointer->ImageSectionObject != NULL))
if (!MmFlushImageSection(fileObject->SectionObjectPointer,
MmFlushForWrite )) result =
FALSE;
if (result &&
(fileObject->SectionObjectPointer->DataSectionObject != NULL))
if (!CcPurgeCacheSection( fileObject->SectionObjectPointer,
NULL, 0, FALSE )) result = FALSE;
if (IoPagingRelease) ExReleaseResource(Fcb->PagingIoResource);
if (MainResRelease) ExReleaseResource(Fcb->Resource);
if (fileObject != NULL) {
if (result && (fileObject->PrivateCacheMap != NULL)) {
CcUninitializeCacheMap( fileObject, NULL, NULL );
}
ObDereferenceObject( fileObject );
}
ZwClose( ntFileHandle );
return result;
}
>From: "Maxim S. Shatskih" <[email protected]>
>Reply-To: "File Systems Developers" <[email protected]>
>To: "File Systems Developers" <[email protected]>
>Subject: [ntfsd] Re: File Cache Purge
>Date: Wed, 5 Apr 2000 23:42:29 +0400
>
>It's impossible if the file is also mapped in the user space by file
>mapping.
>In other case, CcPurgeCacheSection helps.
>
> Max
>
>----- Original Message -----
>From: Mark Twain
>To: File Systems Developers
>Sent: Tuesday, April 04, 2000 8:09 PM
>Subject: [ntfsd] File Cache Purge
>
>
>Hello,
>Do you know how can I purge the cache for a given file and re-read this
>file
>from the disk?
>
>Best:
>Mark
>
>
>---
>You are currently subscribed to ntfsd as: [email protected]
>To unsubscribe send a blank email to $subst('Email.Unsub')
>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
I figure out that CcUninitializeCacheMap will do the same but...
Inaki.
> -----Original Message-----
> From: Jack Brown
> Sent: jueves 6 de abril de 2000 19:34
> To: File Systems Developers
> Subject: [ntfsd] Re: File Cache Purge
>
> Max,
> I was thinking the same but the next function doesn't work. Can somebody
> explains me why after everything is successfull? It seems that the purge
> is
> OK but the file is not re-read from the disk. It's obtained again from the
>
> cache.
>
> BOOLEAN
> PurgeFile (
> )
> {
> WCHAR filename[] = L"\\??\\E:\\diddid.txt";
> UNICODE_STRING fileNameUnicodeString;
> OBJECT_ATTRIBUTES objectAttributes;
> PFILE_OBJECT fileObject;
> HANDLE ntFileHandle;
> PFSRTL_COMMON_FCB_HEADER Fcb;
> BOOLEAN result = TRUE, IoPagingRelease = FALSE,
>
> MainResRelease = FALSE;
> NTSTATUS status;
> IO_STATUS_BLOCK ioStatus;
>
>
> //Open file
> RtlInitUnicodeString( &fileNameUnicodeString, filename );
> InitializeObjectAttributes( &objectAttributes,
>
>
>
> &fileNameUnicodeString,
> OBJ_CASE_INSENSITIVE, NULL, NULL);
>
> status = ZwCreateFile( &ntFileHandle, SYNCHRONIZE|FILE_ANY_ACCESS,
> &objectAttributes, &ioStatus, NULL,0,0,
> FILE_OPEN,
>
>
> FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE,
> NULL, 0 );
>
> if( !NT_SUCCESS( status ) ) return FALSE;
>
> // Find file-object it refers to
> status = ObReferenceObjectByHandle( ntFileHandle, FILE_READ_DATA,
> NULL, KernelMode,
>
>
>
>
> (PVOID*)&fileObject, NULL );
> if( !NT_SUCCESS( status )) {
> ZwClose( ntFileHandle );
> return FALSE;
> }
>
> Fcb = (PFSRTL_COMMON_FCB_HEADER)(fileObject->FsContext);
> if (Fcb==NULL) return FALSE;
>
> if (!ExAcquireResourceExclusive(Fcb->Resource, TRUE ))
> result = FALSE;
> else MainResRelease = TRUE;
>
> if (!ExAcquireResourceExclusive( Fcb->PagingIoResource , TRUE ))
>
> result = FALSE ;
> else IoPagingRelease = TRUE;
>
> if (result &&
> (fileObject->SectionObjectPointer->ImageSectionObject != NULL))
> if (!MmFlushImageSection(fileObject->SectionObjectPointer,
>
>
>
> MmFlushForWrite )) result =
> FALSE;
>
> if (result &&
> (fileObject->SectionObjectPointer->DataSectionObject != NULL))
> if (!CcPurgeCacheSection( fileObject->SectionObjectPointer,
> NULL, 0, FALSE )) result = FALSE;
>
> if (IoPagingRelease) ExReleaseResource(Fcb->PagingIoResource);
> if (MainResRelease) ExReleaseResource(Fcb->Resource);
>
> if (fileObject != NULL) {
>
> if (result && (fileObject->PrivateCacheMap != NULL)) {
>
> CcUninitializeCacheMap( fileObject, NULL, NULL );
> }
>
> ObDereferenceObject( fileObject );
> }
> ZwClose( ntFileHandle );
> return result;
> }
>
> >From: "Maxim S. Shatskih" <[email protected]>
> >Reply-To: "File Systems Developers" <[email protected]>
> >To: "File Systems Developers" <[email protected]>
> >Subject: [ntfsd] Re: File Cache Purge
> >Date: Wed, 5 Apr 2000 23:42:29 +0400
> >
> >It's impossible if the file is also mapped in the user space by file
> >mapping.
> >In other case, CcPurgeCacheSection helps.
> >
> > Max
> >
> >----- Original Message -----
> >From: Mark Twain
> >To: File Systems Developers
> >Sent: Tuesday, April 04, 2000 8:09 PM
> >Subject: [ntfsd] File Cache Purge
> >
> >
> >Hello,
> >Do you know how can I purge the cache for a given file and re-read this
> >file
> >from the disk?
> >
> >Best:
> >Mark
> >
> >
> >---
> >You are currently subscribed to ntfsd as: [email protected]
> >To unsubscribe send a blank email to $subst('Email.Unsub')
> >
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
>
> ---
> You are currently subscribed to ntfsd as: [email protected]
> To unsubscribe send a blank email to $subst('Email.Unsub')
>From: Iñaki Castillo <[email protected]>
>Reply-To: "File Systems Developers" <[email protected]>
>To: "File Systems Developers" <[email protected]>
>Subject: [ntfsd] Re: File Cache Purge
>Date: Thu, 6 Apr 2000 20:02:09 +0200
>
>Have tried to set CcPurgeCacheSection last parameter to TRUE ?
>I figure out that CcUninitializeCacheMap will do the same but...
>
>Inaki.
>
> > -----Original Message-----
> > From: Jack Brown
> > Sent: jueves 6 de abril de 2000 19:34
> > To: File Systems Developers
> > Subject: [ntfsd] Re: File Cache Purge
> >
> > Max,
> > I was thinking the same but the next function doesn't work. Can somebody
> > explains me why after everything is successfull? It seems that the purge
> > is
> > OK but the file is not re-read from the disk. It's obtained again from
>the
> >
> > cache.
> >
> > BOOLEAN
> > PurgeFile (
> > )
> > {
> > WCHAR filename[] = L"\\??\\E:\\diddid.txt";
> > UNICODE_STRING fileNameUnicodeString;
> > OBJECT_ATTRIBUTES objectAttributes;
> > PFILE_OBJECT fileObject;
> > HANDLE ntFileHandle;
> > PFSRTL_COMMON_FCB_HEADER Fcb;
> > BOOLEAN result = TRUE, IoPagingRelease = FALSE,
> >
> > MainResRelease = FALSE;
> > NTSTATUS status;
> > IO_STATUS_BLOCK ioStatus;
> >
> >
> > //Open file
> > RtlInitUnicodeString( &fileNameUnicodeString, filename );
> > InitializeObjectAttributes( &objectAttributes,
> >
> >
> >
> > &fileNameUnicodeString,
> > OBJ_CASE_INSENSITIVE, NULL, NULL);
> >
> > status = ZwCreateFile( &ntFileHandle, SYNCHRONIZE|FILE_ANY_ACCESS,
> > &objectAttributes, &ioStatus, NULL,0,0,
> > FILE_OPEN,
> >
> >
> > FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE,
> > NULL, 0 );
> >
> > if( !NT_SUCCESS( status ) ) return FALSE;
> >
> > // Find file-object it refers to
> > status = ObReferenceObjectByHandle( ntFileHandle, FILE_READ_DATA,
> > NULL, KernelMode,
> >
> >
> >
> >
> > (PVOID*)&fileObject, NULL );
> > if( !NT_SUCCESS( status )) {
> > ZwClose( ntFileHandle );
> > return FALSE;
> > }
> >
> > Fcb = (PFSRTL_COMMON_FCB_HEADER)(fileObject->FsContext);
> > if (Fcb==NULL) return FALSE;
> >
> > if (!ExAcquireResourceExclusive(Fcb->Resource, TRUE ))
> > result = FALSE;
> > else MainResRelease = TRUE;
> >
> > if (!ExAcquireResourceExclusive( Fcb->PagingIoResource , TRUE ))
> >
> > result = FALSE ;
> > else IoPagingRelease = TRUE;
> >
> > if (result &&
> > (fileObject->SectionObjectPointer->ImageSectionObject != NULL))
> > if (!MmFlushImageSection(fileObject->SectionObjectPointer,
> >
> >
> >
> > MmFlushForWrite )) result =
> > FALSE;
> >
> > if (result &&
> > (fileObject->SectionObjectPointer->DataSectionObject != NULL))
> > if (!CcPurgeCacheSection( fileObject->SectionObjectPointer,
> > NULL, 0, FALSE )) result = FALSE;
> >
> > if (IoPagingRelease) ExReleaseResource(Fcb->PagingIoResource);
> > if (MainResRelease) ExReleaseResource(Fcb->Resource);
> >
> > if (fileObject != NULL) {
> >
> > if (result && (fileObject->PrivateCacheMap != NULL)) {
> >
> > CcUninitializeCacheMap( fileObject, NULL, NULL );
> > }
> >
> > ObDereferenceObject( fileObject );
> > }
> > ZwClose( ntFileHandle );
> > return result;
> > }
> >
> > >From: "Maxim S. Shatskih" <[email protected]>
> > >Reply-To: "File Systems Developers" <[email protected]>
> > >To: "File Systems Developers" <[email protected]>
> > >Subject: [ntfsd] Re: File Cache Purge
> > >Date: Wed, 5 Apr 2000 23:42:29 +0400
> > >
> > >It's impossible if the file is also mapped in the user space by file
> > >mapping.
> > >In other case, CcPurgeCacheSection helps.
> > >
> > > Max
> > >
> > >----- Original Message -----
> > >From: Mark Twain
> > >To: File Systems Developers
> > >Sent: Tuesday, April 04, 2000 8:09 PM
> > >Subject: [ntfsd] File Cache Purge
> > >
> > >
> > >Hello,
> > >Do you know how can I purge the cache for a given file and re-read this
> > >file
> > >from the disk?
> > >
> > >Best:
> > >Mark
> > >
> > >
> > >---
> > >You are currently subscribed to ntfsd as: [email protected]
> > >To unsubscribe send a blank email to $subst('Email.Unsub')
> > >
> >
> > ______________________________________________________
> > Get Your Private, Free Email at http://www.hotmail.com
> >
> >
> > ---
> > You are currently subscribed to ntfsd as: [email protected]
> > To unsubscribe send a blank email to $subst('Email.Unsub')
>
>---
>You are currently subscribed to ntfsd as: [email protected]
>To unsubscribe send a blank email to $subst('Email.Unsub')
>
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com