deadlock

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();

}

First, try to declare variable loop volatile: volatile BOOLEAN loop =
TRUE (RTFM) :slight_smile:
Second, you should not try to acquire FCB resources directly. This issue
has been discussed in this list multiple times. Look in archives for the
solution.

Vladimir Chtchetkine

Principal Engineer

Borland Software is the global leader in platform independent solutions
for Software Delivery Optimization, helping customers address the
constraints of modern day software development to maximize the business
value of their software.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of bob smith
Sent: Monday, October 03, 2005 9:52 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] deadlock

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();

}

— Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17 You are currently subscribed
to ntfsd as: unknown lmsubst tag argument: ‘’ To unsubscribe send a
blank email to xxxxx@lists.osr.com