luckyshow00
驱动牛犊
驱动牛犊
  • 注册日期2007-03-12
  • 最后登录2008-11-24
  • 粉丝0
  • 关注0
  • 积分2分
  • 威望36点
  • 贡献值0点
  • 好评度34点
  • 原创分0分
  • 专家分0分
阅读:1468回复:4

有无办法清除Cache中所有文件块

楼主#
更多 发布于:2007-03-28 16:30
  看了下以前兄弟们写的清除Cache数据的东西
发现这个函数依赖于FileObject,但是FileObjet是在Create时才会产生
1.我想一次性清掉Cache中所有文件块
2.有办法比较Cache中的数据块和Disk上的数据是否一致的办法么?
devia
论坛版主
论坛版主
  • 注册日期2005-05-14
  • 最后登录2016-04-05
  • 粉丝3
  • 关注0
  • 积分1029分
  • 威望712点
  • 贡献值1点
  • 好评度555点
  • 原创分8分
  • 专家分4分
沙发#
发布于: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.
人总在矛盾中徘徊。。。
silent_tiger
驱动牛犊
驱动牛犊
  • 注册日期2006-09-04
  • 最后登录2013-02-01
  • 粉丝0
  • 关注0
  • 积分30分
  • 威望4点
  • 贡献值0点
  • 好评度3点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2007-04-08 13:35
1.我也有个问题,清除内存映射的缓存好像很难成功,即便我在调用CcPurgeCacheSection前调用了MmFlushImageSection也会有失败的情况. 谁能指点一下?
magichere
驱动小牛
驱动小牛
  • 注册日期2007-01-24
  • 最后登录2008-05-07
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望137点
  • 贡献值0点
  • 好评度136点
  • 原创分0分
  • 专家分0分
地板#
发布于: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();*/

怎么搞得 。
创造美好的未来生活!!!
magichere
驱动小牛
驱动小牛
  • 注册日期2007-01-24
  • 最后登录2008-05-07
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望137点
  • 贡献值0点
  • 好评度136点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2007-04-09 08:56
我想知道 内存的里的缓存。如果清除了 。
缓存写回 时也会 通过 fsContext 结构信息 回写到硬盘上 是吗?
而后  fsContext 指针 会 分配给别人。这时候,可以 确认 这个指针 完全 被前面的文件 废弃掉了吗?
创造美好的未来生活!!!
游客

返回顶部