the following code will deadlock on my fat32 disk, how can i edit the
function so it does not deadlock
void PurgeCache(PFILE_OBJECT lpFileObject)
{
IO_STATUS_BLOCK IoStatus;
PFSRTL_COMMON_FCB_HEADER lpFcb;
BOOLEAN test;
BOOLEAN loop = TRUE;
DbgPrint( “Flushing” );
lpFcb = (PFSRTL_COMMON_FCB_HEADER)lpFileObject->FsContext;
KeEnterCriticalRegion();
do
{
loop = FALSE;
test = ExAcquireResourceExclusiveLite(lpFcb->Resource, TRUE);
if ( !ExAcquireResourceExclusiveLite(lpFcb->PagingIoResource, TRUE) )
{
ExReleaseResourceLite(lpFcb->Resource);
DbgPrint( “pausing” );
//pause 50ms
loop = TRUE;
}
}while(loop == TRUE);
if(lpFileObject->SectionObjectPointer)
{
try
{
CcFlushCache(lpFileObject->SectionObjectPointer,
NULL,
0,
&IoStatus);
if(lpFileObject->SectionObjectPointer->ImageSectionObject)
{
MmFlushImageSection(lpFileObject->SectionObjectPointer,
MmFlushForWrite);
}
if(lpFileObject->SectionObjectPointer->DataSectionObject)
{
CcPurgeCacheSection(lpFileObject->SectionObjectPointer,
NULL,
0,
FALSE);
}
}
except(EXCEPTION_EXECUTE_HANDLER)
{
// Do nothing
}
}
if(lpFcb->PagingIoResource)
{
ExReleaseResourceLite(lpFcb->PagingIoResource);
}
if(lpFcb->Resource)
{
ExReleaseResourceLite(lpFcb->Resource);
}
KeLeaveCriticalRegion();
}