阅读:3796回复:9
[死锁无奈]谁能共享一下清缓存代码?
rt,开源万岁!
|
|
沙发#
发布于:2007-04-28 09:31
先把你的源开出来
|
|
板凳#
发布于:2007-04-28 10:28
我碰到的问题是想让ntfs磁盘$mft文件中常驻内存部分刷新或者丢弃,然后重读磁盘 的问题,大家是什么问题?至于磁盘刷新清缓存,csdn上有个应用层的解决方法,我也不知道好不好用,大家侧着看
CString strTemp; HANDLE hFile = CreateFile("\\\\.\\E:", GENERIC_READ| GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); if (hFile == INVALID_HANDLE_VALUE || hFile == NULL) { strTemp.Format("无法打开磁盘: %lu", GetLastError()); MessageBox(strTemp); return; } if (!FlushFileBuffers(hFile)) { strTemp.Format("刷新磁盘缓冲失败:%lu", GetLastError()); MessageBox(strTemp); CloseHandle(hFile); return; } CloseHandle(hFile); 至于驱动层,需要调用cc函数,也贴一小段代码, case IRP_MJ_CLOSE: if (FileObject && FileObject->SectionObjectPointer) { CcFlushCache(FileObject->SectionObjectPointer, NULL,0, &IoStatus); if (IoStatus.Status == STATUS_SUCCESS) retval = CcPurgeCacheSection( FileObject->SectionObjectPointer, NULL, 0, TRUE ); } break; 这个只是在文件关闭的时候,将该文件的内存中相关内容刷新。我一直怀疑系统调用的是cccopywrite函数,也就是说虽然刷新到了磁盘,但内存中仍然有数据,导致下次访问该文件仍然不从硬盘上读,不知道这么想对不对,请大牛们指教 |
|
地板#
发布于:2007-04-28 13:06
那当然了,CcFlushCache只是把CACHE数据回写到磁盘上,并不清除CACHE数据。
|
|
|
地下室#
发布于:2007-04-28 13:53
有办法清除cache 中的内容么?比如像chkdsk那样,添加/f参数后就可以将磁盘卸载,检查$mft文件的一致性和正确性,编程实现的话不卸载磁盘有别的办法么??
|
|
5楼#
发布于:2007-04-28 14:07
我的源会蓝屏:
void ManageFileCache(PFILE_OBJECT pFileObject) { PFSRTL_COMMON_FCB_HEADER pFcb; LARGE_INTEGER liInterval; //BOOLEAN bNeedReleaseResource = FALSE; //BOOLEAN bNeedReleasePagingIoResource = FALSE; KIRQL irql; BOOLEAN bLockedResource=FALSE; BOOLEAN bLockedPagingIoResource=FALSE; pFcb = (PFSRTL_COMMON_FCB_HEADER)pFileObject->FsContext; if(pFcb == NULL) { return; } irql = KeGetCurrentIrql(); if (irql >= DISPATCH_LEVEL) { return; } liInterval.QuadPart = -1 * (LONGLONG)50; KeEnterCriticalRegion(); bLockedPagingIoResource = ExIsResourceAcquiredExclusiveLite(pFcb->PagingIoResource); bLockedResource=ExIsResourceAcquiredExclusiveLite(pFcb->Resource); while(!bLockedPagingIoResource || !bLockedResource) { if(!bLockedPagingIoResource) { if(ExAcquireResourceExclusiveLite(pFcb->PagingIoResource, FALSE)==TRUE) bLockedPagingIoResource=TRUE; else goto clear; } if(!bLockedResource) { if(ExAcquireResourceExclusiveLite(pFcb->Resource, FALSE)==TRUE) bLockedResource=TRUE; else goto clear; } if(bLockedPagingIoResource && bLockedResource) break; clear: if (bLockedPagingIoResource) { ExReleaseResourceLite(pFcb->PagingIoResource); bLockedPagingIoResource = FALSE; } if (bLockedResource) { ExReleaseResourceLite(pFcb->Resource); bLockedResource=FALSE; } if (irql == PASSIVE_LEVEL) { KeDelayExecutionThread(KernelMode, FALSE, &liInterval); } else { KEVENT waitEvent; KeInitializeEvent(&waitEvent, NotificationEvent, FALSE); KeWaitForSingleObject(&waitEvent, Executive, KernelMode, FALSE, &liInterval); } } //加锁完毕 if (pFileObject->SectionObjectPointer) { IO_STATUS_BLOCK ioStatus; CcFlushCache(pFileObject->SectionObjectPointer, NULL, 0, &ioStatus); if (pFileObject->SectionObjectPointer->ImageSectionObject) { MmFlushImageSection(pFileObject->SectionObjectPointer, MmFlushForWrite);//MmFlushForDelete } CcPurgeCacheSection(pFileObject->SectionObjectPointer, NULL, 0, FALSE); } if (bLockedPagingIoResource) { ExReleaseResourceLite(pFcb->PagingIoResource); bLockedPagingIoResource = FALSE; } if (bLockedResource) { ExReleaseResourceLite(pFcb->Resource); bLockedResource=FALSE; } KeLeaveCriticalRegion(); } |
|
6楼#
发布于:2009-02-05 11:15
引用第2楼xx_qiang于2007-04-28 10:28发表的 : 我也有同样的问题,你解决了么 |
|
7楼#
发布于:2009-02-11 14:21
void NewEmptyCache(PCFLT_RELATED_OBJECTS FltObjects)
{ PFSRTL_COMMON_FCB_HEADER FcbHeader; // DbgPrint (( " IRP_MJ_CLEANUP --> ENCFILE \n")); FcbHeader = (PFSRTL_COMMON_FCB_HEADER)FltObjects->FileObject->FsContext; if ( FcbHeader != NULL && FcbHeader->PagingIoResource != NULL) { ExAcquireResourceExclusive (FcbHeader->PagingIoResource, TRUE); // DbgPrint (( "ExAcquireResourceExclusive \n")); } if (FltObjects->FileObject->SectionObjectPointer != NULL) { CcFlushCache(FltObjects->FileObject->SectionObjectPointer,0,0, NULL); CcPurgeCacheSection(FltObjects->FileObject->SectionObjectPointer,0,0, FALSE); // DbgPrint (( "CcFlushCache & CcPurgeCacheSection \n")); } if(FltObjects->FileObject->PrivateCacheMap) { CcUninitializeCacheMap(FltObjects->FileObject, NULL, NULL);; } if ( FcbHeader != NULL && FcbHeader->PagingIoResource != NULL) { ExReleaseResource (FcbHeader->PagingIoResource); // DbgPrint (( "ExReleaseResource \n")); } } |
|
8楼#
发布于:2009-02-24 23:47
清了缓存,非加密进程不是跟加密进程一样,都看到明文或者都看到密文了?
方法不对,只有双FSB或者另外一种方法,才能解决同时打开文件的问题。至于另外一种方法是什么,我不说 |
|
9楼#
发布于:2011-02-13 17:00
|
|