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 believe, calling ZwCreateFile with FILE_NO_INTERMEDIATE_BUFFERING flag set
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:xxxxx@crosswinds.net]
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

CCFlushCache.

-----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

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

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”
>Reply-To: “File Systems Developers”
>To: “File Systems Developers”
>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: xxxxx@hotmail.com
>To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

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”
> >Reply-To: “File Systems Developers”
> >To: “File Systems Developers”
> >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: xxxxx@hotmail.com
> >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: xxxxx@pandasoftware.es
> To unsubscribe send a blank email to $subst(‘Email.Unsub’)

Thanks Inaki, but the result is the same !

From: Iñaki Castillo
>Reply-To: “File Systems Developers”
>To: “File Systems Developers”
>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”
> > >Reply-To: “File Systems Developers”
> > >To: “File Systems Developers”
> > >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: xxxxx@hotmail.com
> > >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: xxxxx@pandasoftware.es
> > To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>
>—
>You are currently subscribed to ntfsd as: xxxxx@hotmail.com
>To unsubscribe send a blank email to $subst(‘Email.Unsub’)
>


Get Your Private, Free Email at http://www.hotmail.com