阅读:1468回复:4
有无办法清除Cache中所有文件块
看了下以前兄弟们写的清除Cache数据的东西
发现这个函数依赖于FileObject,但是FileObjet是在Create时才会产生 1.我想一次性清掉Cache中所有文件块 2.有办法比较Cache中的数据块和Disk上的数据是否一致的办法么? |
|
沙发#
发布于:2007-03-29 09:20
Q40 How do I force files to be closed from my file system/filter driver?
A common problem for file system and file system filter driver writers is that they observe files are "never" closed. They often assume this is some bug in their filter or file system but in fact this is normal system behavior because of the way the OS caches files in the virtual memory system. A file may be accessed using either the "normal" read/write API or via the alternative memory mapped file API. Typically, user access to a file, even when performed via the read/write API, is actually satisfied using the memory mapping mechanism. |
|
|
板凳#
发布于:2007-04-08 13:35
1.我也有个问题,清除内存映射的缓存好像很难成功,即便我在调用CcPurgeCacheSection前调用了MmFlushImageSection也会有失败的情况. 谁能指点一下?
|
|
地板#
发布于:2007-04-08 17:42
是呀,我要遇到这样的问题。
我用 fsContext 做索引 但是总是 误被 判断成别的文件哦。 这是我 Copy 论坛 的一位 仁兄 清除 Cache 的代码。放上去 死机 。 /*KeEnterCriticalRegion(); if(ExAcquireResourceExclusiveLite( ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->Resource, FALSE)) { if(ExAcquireResourceExclusiveLite( ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->PagingIoResource, FALSE)) { if(FileObject->SectionObjectPointer) { IoSetTopLevelIrp( (PIRP)FSRTL_FSP_TOP_LEVEL_IRP ); CcFlushCache( FileObject->SectionObjectPointer, NULL, 0, NULL ); if(FileObject->SectionObjectPointer->ImageSectionObject) { MmFlushImageSection( FileObject->SectionObjectPointer, MmFlushForWrite//MmFlushForDelete// ) ; } if(FileObject->SectionObjectPointer->DataSectionObject) { CcPurgeCacheSection( FileObject->SectionObjectPointer, NULL, 0, FALSE ); //为TRUE,会强迫所有的FileObject重新初始化Cache } if(FileObject->PrivateCacheMap) { CcUninitializeCacheMap(FileObject, NULL, NULL);; } if(FileObject->SectionObjectPointer->DataSectionObject) { //Interval.QuadPart = DELAY_ONE_MILLISECOND * 500;//500ms //KeDelayExecutionThread(KernelMode, FALSE, &Interval); MmForceSectionClosed( FileObject->SectionObjectPointer, TRUE//改为TRUE,彻底刷新缓存!!! ); } IoSetTopLevelIrp(NULL); } ExReleaseResourceLite( ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->PagingIoResource ); } ExReleaseResourceLite( ((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->Resource ); } KeLeaveCriticalRegion();*/ 怎么搞得 。 |
|
|
地下室#
发布于:2007-04-09 08:56
我想知道 内存的里的缓存。如果清除了 。
缓存写回 时也会 通过 fsContext 结构信息 回写到硬盘上 是吗? 而后 fsContext 指针 会 分配给别人。这时候,可以 确认 这个指针 完全 被前面的文件 废弃掉了吗? |
|
|