Re: File Cache Purge

Try to call CcFlushCache(), just before your CcPurgeCacheSection() call.

Kristian

“Jack Brown” wrote in message news:xxxxx@ntfsd…
> 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
>
>
>