Windows: use local var for interlocked result
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 4 Jan 2012 17:13:40 +0000 (12:13 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Wed, 11 Jan 2012 03:52:32 +0000 (19:52 -0800)
Save the result of the interlocked operations for use in
debug logging.  Do not reference the incremented or decremented
object in the log messages, it may have changed.

Local assignment is provided even in functions that are currently
not logging to assist with debugging and as a reminder to use
the result variable in future log messages.

Change-Id: Ia7ed8bf14b204b265e1db7713b96864634a731d7
Reviewed-on: http://gerrit.openafs.org/6508
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsrdr/kernel/lib/AFSCleanup.cpp
src/WINNT/afsrdr/kernel/lib/AFSCreate.cpp
src/WINNT/afsrdr/kernel/lib/AFSDirControl.cpp
src/WINNT/afsrdr/kernel/lib/AFSExtentsSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSFcbSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSFileInfo.cpp
src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp
src/WINNT/afsrdr/kernel/lib/AFSIoSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSNetworkProviderSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp

index fbb42a8..5f5be09 100644 (file)
@@ -69,6 +69,7 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
     AFSFileCleanupResultCB *pResultCB = NULL;
     ULONG ulResultLen = 0;
     ULONG   ulNotificationFlags = 0;
+    LONG    lCount;
 
     __try
     {
@@ -153,15 +154,15 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                 ASSERT( pFcb->OpenHandleCount != 0);
 
-                InterlockedDecrement( &pFcb->OpenHandleCount);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCleanup (RootAll) Decrement handle count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenHandleCount);
-
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                              lCount);
 
                 FsRtlNotifyCleanup( pControlDeviceExt->Specific.Control.NotifySync,
                                     &pControlDeviceExt->Specific.Control.DirNotifyList,
@@ -192,28 +193,24 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
                 {
 
-                    InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                    lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSCleanup (IOCtl) Decrement child open handle count on Parent object %08lX Cnt %d\n",
                                   pObjectInfo->ParentObjectInformation,
-                                  pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                                  lCount);
                 }
 
-                InterlockedDecrement( &pFcb->OpenHandleCount);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCleanup (IOCtl) Decrement handle count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenHandleCount);
-
-                //
-                // And finally, release the Fcb if we acquired it.
-                //
-
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                              lCount);
 
                 break;
             }
@@ -628,28 +625,24 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                     ASSERT( pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0);
 
-                    InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                    lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSCleanup (File) Decrement child open handle count on Parent object %08lX Cnt %d\n",
                                   pObjectInfo->ParentObjectInformation,
-                                  pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                                  lCount);
                 }
 
-                InterlockedDecrement( &pFcb->OpenHandleCount);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCleanup (File) Decrement handle count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenHandleCount);
-
-                //
-                // And finally, release the Fcb if we acquired it.
-                //
-
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                              lCount);
 
                 break;
             }
@@ -946,28 +939,24 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                     ASSERT( pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0);
 
-                    InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                    lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSCleanup (Dir) Decrement child open handle count on Parent object %08lX Cnt %d\n",
                                   pObjectInfo->ParentObjectInformation,
-                                  pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                                  lCount);
                 }
 
-                InterlockedDecrement( &pFcb->OpenHandleCount);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCleanup (Dir) Decrement handle count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenHandleCount);
-
-                //
-                // And finally, release the Fcb if we acquired it.
-                //
-
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                              lCount);
 
                 break;
             }
@@ -1241,28 +1230,24 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
 
                     ASSERT( pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0);
 
-                    InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                    lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSCleanup (MP/SL) Decrement child open handle count on Parent object %08lX Cnt %d\n",
                                   pObjectInfo->ParentObjectInformation,
-                                  pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                                  lCount);
                 }
 
-                InterlockedDecrement( &pFcb->OpenHandleCount);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCleanup (MP/SL) Decrement handle count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenHandleCount);
-
-                //
-                // And finally, release the Fcb if we acquired it.
-                //
-
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                              lCount);
 
                 break;
             }
@@ -1289,28 +1274,24 @@ AFSCleanup( IN PDEVICE_OBJECT LibDeviceObject,
                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount > 0)
                 {
 
-                    InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                    lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSCleanup (Share) Decrement child open handle count on Parent object %08lX Cnt %d\n",
                                   pObjectInfo->ParentObjectInformation,
-                                  pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                                  lCount);
                 }
 
-                InterlockedDecrement( &pFcb->OpenHandleCount);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
+                lCount = InterlockedDecrement( &pFcb->OpenHandleCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCleanup (Share) Decrement handle count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenHandleCount);
-
-                //
-                // And finally, release the Fcb if we acquired it.
-                //
-
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                              lCount);
 
                 break;
             }
index 9087e79..5698162 100644 (file)
@@ -146,6 +146,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
     GUID                stAuthGroup;
     ULONG               ulNameProcessingFlags = 0;
     BOOLEAN             bOpenedReparsePoint = FALSE;
+    LONG                lCount;
 
     __Enter
     {
@@ -364,15 +365,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               "AFSCommonCreate Failed to open root Status %08lX\n",
                               ntStatus);
 
-                InterlockedDecrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement1 count on &wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement1 count on &wZ DE %p Ccb %p Cnt %d\n",
                               &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                               AFSGlobalRoot->DirectoryCB,
                               NULL,
-                              AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                              lCount);
             }
 
             try_return( ntStatus);
@@ -568,15 +569,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 // Perform in this order to prevent thrashing
                 //
 
-                InterlockedIncrement( &pParentDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pParentDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Increment1 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pParentDirectoryCB->NameInformation.FileName,
                               pParentDirectoryCB,
                               NULL,
-                              pParentDirectoryCB->OpenReferenceCount);
+                              lCount);
 
                 //
                 // Do NOT decrement the reference count on the pDirectoryCB yet.
@@ -610,15 +611,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 //
                 // It is now safe to drop the Reference Count
                 //
-                InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pDirectoryCB->NameInformation.FileName,
                               pDirectoryCB,
                               NULL,
-                              pDirectoryCB->OpenReferenceCount);
+                              lCount);
             }
 
             if( !NT_SUCCESS( ntStatus))
@@ -634,15 +635,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 // Decrement the reference on the parent
                 //
 
-                InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pParentDirectoryCB->NameInformation.FileName,
                               pParentDirectoryCB,
                               NULL,
-                              pParentDirectoryCB->OpenReferenceCount);
+                              lCount);
             }
 
             try_return( ntStatus);
@@ -703,15 +704,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   &pDirectoryCB->NameInformation.FileName,
                                   ntStatus);
 
-                    InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSCreate Decrement4 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  "AFSCommonCreate Decrement4 count on %wZ DE %p Ccb %p Cnt %d\n",
                                   &pDirectoryCB->NameInformation.FileName,
                                   pDirectoryCB,
                                   NULL,
-                                  pDirectoryCB->OpenReferenceCount);
+                                  lCount);
                 }
                 else
                 {
@@ -725,7 +726,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSCreate Decrement5 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  "AFSCommonCreate Decrement5 count on %wZ DE %p Ccb %p Cnt %d\n",
                                   &pParentDirectoryCB->NameInformation.FileName,
                                   pParentDirectoryCB,
                                   NULL,
@@ -764,7 +765,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
             // Dereference the parent entry
             //
 
-            InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -772,7 +773,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                           &pParentDirectoryCB->NameInformation.FileName,
                           pParentDirectoryCB,
                           NULL,
-                          pParentDirectoryCB->OpenReferenceCount);
+                          lCount);
 
             try_return( ntStatus);
         }
@@ -831,28 +832,28 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 if( pDirectoryCB != NULL)
                 {
 
-                    InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSCreate Decrement7a count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  "AFSCommonCreate Decrement7a count on %wZ DE %p Ccb %p Cnt %d\n",
                                   &pDirectoryCB->NameInformation.FileName,
                                   pDirectoryCB,
                                   NULL,
-                                  pDirectoryCB->OpenReferenceCount);
+                                  lCount);
                 }
                 else
                 {
 
-                    InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSCreate Decrement7b count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  "AFSCommonCreate Decrement7b count on %wZ DE %p Ccb %p Cnt %d\n",
                                   &pParentDirectoryCB->NameInformation.FileName,
                                   pParentDirectoryCB,
                                   NULL,
-                                  pParentDirectoryCB->OpenReferenceCount);
+                                  lCount);
                 }
             }
 
@@ -878,15 +879,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               "AFSCommonCreate (%08lX) Attempt to open root as delete on close\n",
                               Irp);
 
-                InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement8 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement8 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pDirectoryCB->NameInformation.FileName,
                               pDirectoryCB,
                               NULL,
-                              pDirectoryCB->OpenReferenceCount);
+                              lCount);
 
                 try_return( ntStatus = STATUS_CANNOT_DELETE);
             }
@@ -903,15 +904,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               "AFSCommonCreate (%08lX) Attempt to open root as target directory\n",
                               Irp);
 
-                InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement9 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement9 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pDirectoryCB->NameInformation.FileName,
                               pDirectoryCB,
                               NULL,
-                              pDirectoryCB->OpenReferenceCount);
+                              lCount);
 
                 try_return( ntStatus = STATUS_INVALID_PARAMETER);
             }
@@ -936,15 +937,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               pVolumeCB->ObjectInformation.FileId.Volume,
                               ntStatus);
 
-                InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement10 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement10 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pDirectoryCB->NameInformation.FileName,
                               pDirectoryCB,
                               NULL,
-                              pDirectoryCB->OpenReferenceCount);
+                              lCount);
             }
 
             try_return( ntStatus);
@@ -992,15 +993,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               &pDirectoryCB->NameInformation.FileName,
                               ntStatus);
 
-                InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Decrement11 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Decrement11 count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pDirectoryCB->NameInformation.FileName,
                               pDirectoryCB,
                               NULL,
-                              pDirectoryCB->OpenReferenceCount);
+                              lCount);
             }
 
             try_return( ntStatus);
@@ -1027,15 +1028,15 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                           &pDirectoryCB->NameInformation.FileName,
                           ntStatus);
 
-            InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSCreate Decrement12 count on %wZ DE %p Ccb %p Cnt %d\n",
+                          "AFSCommonCreate Decrement12 count on %wZ DE %p Ccb %p Cnt %d\n",
                           &pDirectoryCB->NameInformation.FileName,
                           pDirectoryCB,
                           NULL,
-                          pDirectoryCB->OpenReferenceCount);
+                          lCount);
         }
 
 try_exit:
@@ -1085,7 +1086,7 @@ try_exit:
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSCreate Count on %wZ DE %p Ccb %p Cnt %d\n",
+                              "AFSCommonCreate Count on %wZ DE %p Ccb %p Cnt %d\n",
                               &pCcb->DirectoryCB->NameInformation.FileName,
                               pCcb->DirectoryCB,
                               pCcb,
@@ -1239,13 +1240,13 @@ try_exit:
         if( bReleaseVolume)
         {
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCommonCreate Decrement count on Volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         //
@@ -1265,6 +1266,7 @@ AFSOpenRedirector( IN PIRP Irp,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    LONG lCount;
 
     __Enter
     {
@@ -1296,25 +1298,25 @@ AFSOpenRedirector( IN PIRP Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &AFSRedirectorRoot->RootFcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &AFSRedirectorRoot->RootFcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenRedirector Increment count on Fcb %08lX Cnt %d\n",
                       AFSRedirectorRoot->RootFcb,
-                      AFSRedirectorRoot->RootFcb->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &AFSRedirectorRoot->RootFcb->OpenHandleCount);
+        lCount = InterlockedIncrement( &AFSRedirectorRoot->RootFcb->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenRedirector Increment handle count on Fcb %08lX Cnt %d\n",
                       AFSRedirectorRoot->RootFcb,
-                      AFSRedirectorRoot->RootFcb->OpenHandleCount);
+                      lCount);
 
         *Fcb = AFSRedirectorRoot->RootFcb;
 
-        InterlockedIncrement( &(*Ccb)->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedIncrement( &(*Ccb)->DirectoryCB->OpenReferenceCount);
 
         //
         // Return the open result for this file
@@ -1337,6 +1339,7 @@ AFSOpenAFSRoot( IN PIRP Irp,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    LONG lCount;
 
     __Enter
     {
@@ -1368,21 +1371,21 @@ AFSOpenAFSRoot( IN PIRP Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &AFSGlobalRoot->RootFcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &AFSGlobalRoot->RootFcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenAFSRoot Increment count on Fcb %08lX Cnt %d\n",
                       AFSGlobalRoot->RootFcb,
-                      AFSGlobalRoot->RootFcb->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &AFSGlobalRoot->RootFcb->OpenHandleCount);
+        lCount = InterlockedIncrement( &AFSGlobalRoot->RootFcb->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenAFSRoot Increment handle count on Fcb %08lX Cnt %d\n",
                       AFSGlobalRoot->RootFcb,
-                      AFSGlobalRoot->RootFcb->OpenHandleCount);
+                      lCount);
 
         *Fcb = AFSGlobalRoot->RootFcb;
 
@@ -1418,6 +1421,7 @@ AFSOpenRoot( IN PIRP Irp,
     AFSFileOpenCB   stOpenCB;
     AFSFileOpenResultCB stOpenResultCB;
     ULONG       ulResultLen = 0;
+    LONG        lCount;
 
     __Enter
     {
@@ -1649,21 +1653,21 @@ AFSOpenRoot( IN PIRP Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &VolumeCB->RootFcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &VolumeCB->RootFcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenRoot Increment count on Fcb %08lX Cnt %d\n",
                       VolumeCB->RootFcb,
-                      VolumeCB->RootFcb->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &VolumeCB->RootFcb->OpenHandleCount);
+        lCount = InterlockedIncrement( &VolumeCB->RootFcb->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenRoot Increment handle count on Fcb %08lX Cnt %d\n",
                       VolumeCB->RootFcb,
-                      VolumeCB->RootFcb->OpenHandleCount);
+                      lCount);
 
         //
         // Indicate the object is held
@@ -1733,6 +1737,7 @@ AFSProcessCreate( IN PIRP               Irp,
     AFSDirectoryCB *pDirEntry = NULL;
     AFSObjectInfoCB *pParentObjectInfo = NULL;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -2010,41 +2015,41 @@ AFSProcessCreate( IN PIRP               Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &(*Fcb)->OpenReferenceCount);
+        lCount = InterlockedIncrement( &(*Fcb)->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessCreate Increment count on Fcb %08lX Cnt %d\n",
                       *Fcb,
-                      (*Fcb)->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &(*Fcb)->OpenHandleCount);
+        lCount = InterlockedIncrement( &(*Fcb)->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessCreate Increment handle count on Fcb %08lX Cnt %d\n",
                       (*Fcb),
-                      (*Fcb)->OpenHandleCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the parent node
         //
 
-        InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+        lCount = InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessCreate Increment child open handle count on Parent object %08lX Cnt %d\n",
                       pObjectInfo->ParentObjectInformation,
-                      pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                      lCount);
 
-        InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessCreate Increment child open ref count on Parent object %08lX Cnt %d\n",
                       pObjectInfo->ParentObjectInformation,
-                      pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+                      lCount);
 
         if( ulOptions & FILE_DELETE_ON_CLOSE)
         {
@@ -2113,14 +2118,14 @@ try_exit:
                 // Decrement the reference added during initialization of the DE
                 //
 
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSProcessCreate Decrement count on %wZ DE %p Cnt %d\n",
                               &pDirEntry->NameInformation.FileName,
                               pDirEntry,
-                              pDirEntry->OpenReferenceCount);
+                              lCount);
 
                 //
                 // Pull the directory entry from the parent
@@ -2188,6 +2193,7 @@ AFSOpenTargetDirectory( IN PIRP Irp,
     BOOLEAN bReleaseFcb = FALSE, bAllocatedFcb = FALSE;
     AFSObjectInfoCB *pParentObject = NULL, *pTargetObject = NULL;
     UNICODE_STRING uniTargetName;
+    LONG lCount;
 
     __Enter
     {
@@ -2363,21 +2369,21 @@ AFSOpenTargetDirectory( IN PIRP Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &pParentObject->Fcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentObject->Fcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenTargetDirectory Increment count on Fcb %08lX Cnt %d\n",
                       pParentObject->Fcb,
-                      pParentObject->Fcb->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentObject->Fcb->OpenHandleCount);
+        lCount = InterlockedIncrement( &pParentObject->Fcb->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenTargetDirectory Increment handle count on Fcb %08lX Cnt %d\n",
                       pParentObject->Fcb,
-                      pParentObject->Fcb->OpenHandleCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the parent node
@@ -2386,21 +2392,21 @@ AFSOpenTargetDirectory( IN PIRP Irp,
         if( pParentObject->ParentObjectInformation != NULL)
         {
 
-            InterlockedIncrement( &pParentObject->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+            lCount = InterlockedIncrement( &pParentObject->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSOpenTargetDirectory Increment child open handle count on Parent object %08lX Cnt %d\n",
                           pParentObject->ParentObjectInformation,
-                          pParentObject->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                          lCount);
 
-            InterlockedIncrement( &pParentObject->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+            lCount = InterlockedIncrement( &pParentObject->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSOpenTargetDirectory Increment child open ref count on Parent object %08lX Cnt %d\n",
                           pParentObject->ParentObjectInformation,
-                          pParentObject->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+                          lCount);
         }
 
 try_exit:
@@ -2462,6 +2468,7 @@ AFSProcessOpen( IN PIRP Irp,
     AFSObjectInfoCB *pObjectInfo = NULL;
     ULONG       ulFileAccess = 0;
     AFSFileAccessReleaseCB stReleaseFileAccess;
+    LONG lCount;
 
     __Enter
     {
@@ -2587,13 +2594,13 @@ AFSProcessOpen( IN PIRP Irp,
         // Reference the Fcb so it won't go away while we call into the service for processing
         //
 
-        InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOpen Increment count on Fcb %08lX Cnt %d\n",
                       pObjectInfo->Fcb,
-                      pObjectInfo->Fcb->OpenReferenceCount);
+                      lCount);
 
         //
         // Check access on the entry
@@ -2828,41 +2835,41 @@ AFSProcessOpen( IN PIRP Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOpen Increment2 count on Fcb %08lX Cnt %d\n",
                       pObjectInfo->Fcb,
-                      pObjectInfo->Fcb->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pObjectInfo->Fcb->OpenHandleCount);
+        lCount = InterlockedIncrement( &pObjectInfo->Fcb->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOpen Increment handle count on Fcb %08lX Cnt %d\n",
                       pObjectInfo->Fcb,
-                      pObjectInfo->Fcb->OpenHandleCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the parent node
         //
 
-        InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+        lCount = InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOpen Increment child open handle count on Parent object %08lX Cnt %d\n",
                       pObjectInfo->ParentObjectInformation,
-                      pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                      lCount);
 
-        InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOpen Increment child open ref count on Parent object %08lX Cnt %d\n",
                       pObjectInfo->ParentObjectInformation,
-                      pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+                      lCount);
 
         if( BooleanFlagOn( ulOptions, FILE_DELETE_ON_CLOSE))
         {
@@ -2904,13 +2911,13 @@ try_exit:
             // Remove the reference we added initially
             //
 
-            InterlockedDecrement( &pObjectInfo->Fcb->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->Fcb->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSProcessOpen Decrement count on Fcb %08lX Cnt %d\n",
                           pObjectInfo->Fcb,
-                          pObjectInfo->Fcb->OpenReferenceCount);
+                          lCount);
 
             AFSReleaseResource( pObjectInfo->Fcb->Header.Resource);
         }
@@ -2986,6 +2993,7 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
     USHORT usShareAccess;
     AFSObjectInfoCB *pParentObjectInfo = NULL;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -3075,13 +3083,13 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
         // Reference the Fcb so it won't go away while processing the request
         //
 
-        InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOverwriteSupersede Increment count on Fcb %08lX Cnt %d\n",
                       pObjectInfo->Fcb,
-                      pObjectInfo->Fcb->OpenReferenceCount);
+                      lCount);
 
         //
         // Check access on the entry
@@ -3294,41 +3302,41 @@ AFSProcessOverwriteSupersede( IN PDEVICE_OBJECT DeviceObject,
         // Increment the open count on this Fcb.
         //
 
-        InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->Fcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOverwriteSupersede Increment2 count on Fcb %08lX Cnt %d\n",
                       pObjectInfo->Fcb,
-                      pObjectInfo->Fcb->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pObjectInfo->Fcb->OpenHandleCount);
+        lCount = InterlockedIncrement( &pObjectInfo->Fcb->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOverwriteSupersede Increment handle count on Fcb %08lX Cnt %d\n",
                       pObjectInfo->Fcb,
-                      pObjectInfo->Fcb->OpenHandleCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the parent node
         //
 
-        InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+        lCount = InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOverwriteSupersede Increment child open handle count on Parent object %08lX Cnt %d\n",
                       pObjectInfo->ParentObjectInformation,
-                      pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+                      lCount);
 
-        InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessOverwriteSupersede Increment child open ref count on Parent object %08lX Cnt %d\n",
                       pObjectInfo->ParentObjectInformation,
-                      pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+                      lCount);
 
         *Fcb = pObjectInfo->Fcb;
 
@@ -3347,13 +3355,13 @@ try_exit:
             // Remove the reference we added above to prevent tear down
             //
 
-            InterlockedDecrement( &pObjectInfo->Fcb->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->Fcb->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSProcessOverwriteSupersede Decrement count on Fcb %08lX Cnt %d\n",
                           pObjectInfo->Fcb,
-                          pObjectInfo->Fcb->OpenReferenceCount);
+                          lCount);
 
             AFSReleaseResource( pObjectInfo->Fcb->Header.Resource);
         }
@@ -3420,6 +3428,7 @@ AFSOpenIOCtlFcb( IN PIRP Irp,
     AFSPIOCtlOpenCloseRequestCB stPIOCtlOpen;
     AFSFileID stFileID;
     AFSObjectInfoCB *pParentObjectInfo = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -3557,7 +3566,7 @@ AFSOpenIOCtlFcb( IN PIRP Irp,
         // Reference the directory entry
         //
 
-        InterlockedIncrement( &((*Ccb)->DirectoryCB->OpenReferenceCount));
+        lCount = InterlockedIncrement( &((*Ccb)->DirectoryCB->OpenReferenceCount));
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -3565,47 +3574,47 @@ AFSOpenIOCtlFcb( IN PIRP Irp,
                       &(*Ccb)->DirectoryCB->NameInformation.FileName,
                       (*Ccb)->DirectoryCB,
                       (*Ccb),
-                      (*Ccb)->DirectoryCB->OpenReferenceCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the node
         //
 
-        InterlockedIncrement( &(*Fcb)->OpenReferenceCount);
+        lCount = InterlockedIncrement( &(*Fcb)->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenIOCtlFcb Increment count on Fcb %08lX Cnt %d\n",
                       (*Fcb),
-                      (*Fcb)->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &(*Fcb)->OpenHandleCount);
+        lCount = InterlockedIncrement( &(*Fcb)->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenIOCtlFcb Increment handle count on Fcb %08lX Cnt %d\n",
                       (*Fcb),
-                      (*Fcb)->OpenHandleCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the parent node
         //
 
-        InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenHandleCount);
+        lCount = InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenIOCtlFcb Increment child open handle count on Parent object %08lX Cnt %d\n",
                       pParentObjectInfo,
-                      pParentObjectInfo->Specific.Directory.ChildOpenHandleCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenIOCtlFcb Increment child open ref count on Parent object %08lX Cnt %d\n",
                       pParentObjectInfo,
-                      pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount);
+                      lCount);
 
         //
         // Return the open result for this file
@@ -3620,7 +3629,7 @@ try_exit:
         // is already referenced
         //
 
-        InterlockedDecrement( &ParentDirCB->OpenReferenceCount);
+        lCount = InterlockedDecrement( &ParentDirCB->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -3628,7 +3637,7 @@ try_exit:
                       &ParentDirCB->NameInformation.FileName,
                       ParentDirCB,
                       NULL,
-                      ParentDirCB->OpenReferenceCount);
+                      lCount);
 
         //
         // If we created the Fcb we need to release the resources
@@ -3687,6 +3696,7 @@ AFSOpenSpecialShareFcb( IN PIRP Irp,
     BOOLEAN bReleaseFcb = FALSE, bAllocatedCcb = FALSE, bAllocateFcb = FALSE;
     AFSObjectInfoCB *pParentObjectInfo = NULL;
     AFSPipeOpenCloseRequestCB stPipeOpen;
+    LONG lCount;
 
     __Enter
     {
@@ -3805,41 +3815,41 @@ AFSOpenSpecialShareFcb( IN PIRP Irp,
         // Increment the open count on this Fcb
         //
 
-        InterlockedIncrement( &(*Fcb)->OpenReferenceCount);
+        lCount = InterlockedIncrement( &(*Fcb)->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenSpecialShareFcb Increment count on Fcb %08lX Cnt %d\n",
                       (*Fcb),
-                      (*Fcb)->OpenReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &(*Fcb)->OpenHandleCount);
+        lCount = InterlockedIncrement( &(*Fcb)->OpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenSpecialShareFcb Increment handle count on Fcb %08lX Cnt %d\n",
                       (*Fcb),
-                      (*Fcb)->OpenHandleCount);
+                      lCount);
 
         //
         // Increment the open reference and handle on the parent node
         //
 
-        InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenHandleCount);
+        lCount = InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenHandleCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenSpecialShareFcb Increment child open handle count on Parent object %08lX Cnt %d\n",
                       pParentObjectInfo,
-                      pParentObjectInfo->Specific.Directory.ChildOpenHandleCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSOpenSpecialShareFcb Increment child open ref count on Parent object %08lX Cnt %d\n",
                       pParentObjectInfo,
-                      pParentObjectInfo->Specific.Directory.ChildOpenReferenceCount);
+                      lCount);
 
         //
         // Return the open result for this file
index b62a0bd..82139d1 100644 (file)
@@ -147,6 +147,7 @@ AFSQueryDirectory( IN PIRP Irp)
     BOOLEAN         bUseFileInfo = TRUE;
     AFSObjectInfoCB *pObjectInfo = NULL;
     ULONG ulAdditionalAttributes = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -640,7 +641,7 @@ AFSQueryDirectory( IN PIRP Irp)
                      BooleanFlagOn( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED))
             {
 
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                 continue;
             }
@@ -664,7 +665,7 @@ AFSQueryDirectory( IN PIRP Irp)
                     if( !FlagOn( pObjectInfo->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
                     {
 
-                        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                         continue;
                     }
@@ -685,7 +686,7 @@ AFSQueryDirectory( IN PIRP Irp)
                                                       NULL))
                         {
 
-                            InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                            lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                             continue;
                         }
@@ -707,7 +708,7 @@ AFSQueryDirectory( IN PIRP Irp)
                                                          TRUE))
                             {
 
-                                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                                 continue;
                             }
@@ -785,7 +786,7 @@ AFSQueryDirectory( IN PIRP Irp)
 
                 pCcb->CurrentDirIndex--;
 
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                 try_return( ntStatus = STATUS_SUCCESS);
             }
@@ -909,7 +910,7 @@ AFSQueryDirectory( IN PIRP Irp)
                                   Irp,
                                   FileInformationClass);
 
-                    InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                     try_return( ntStatus = STATUS_INVALID_INFO_CLASS);
 
@@ -937,12 +938,12 @@ AFSQueryDirectory( IN PIRP Irp)
             if( ulBytesConverted < pDirEntry->NameInformation.FileName.Length)
             {
 
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                 try_return( ntStatus = STATUS_BUFFER_OVERFLOW);
             }
 
-            InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
             dStatus = STATUS_SUCCESS;
 
@@ -1087,6 +1088,7 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
     AFSSnapshotHdr *pSnapshotHdr = NULL;
     AFSSnapshotEntry *pSnapshotEntry = NULL;
     ULONG ulCount = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -1106,7 +1108,8 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
 
                 if( pDirEntry != NULL)
                 {
-                    InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+
+                    lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
                 }
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1137,7 +1140,8 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
 
             if( pDirEntry != NULL)
             {
-                InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+
+                lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
             }
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1160,7 +1164,8 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
 
             if( pDirEntry != NULL)
             {
-                InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+
+                lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
             }
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1237,7 +1242,7 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
                                       ObjectInfo->FileId.Vnode,
                                       ObjectInfo->FileId.Unique);
 
-                        InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
                     }
                     else
                     {
index 13c0d83..14251e3 100644 (file)
@@ -121,6 +121,7 @@ AFSTearDownFcbExtents( IN AFSFcb *Fcb,
     AFSDeviceExt        *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
     GUID                *pAuthGroup = AuthGroup;
     GUID                 stAuthGroup;
+    LONG                 lCount;
 
     __Enter
     {
@@ -279,9 +280,11 @@ AFSTearDownFcbExtents( IN AFSFcb *Fcb,
                 le = le->Flink;
                 AFSExFreePool( pEntry);
 
-                InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+                lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
 
-                if( InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount) == 0)
+                lCount = InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount);
+
+                if( lCount == 0)
                 {
 
                     KeSetEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent,
@@ -860,6 +863,7 @@ AFSProcessExtentsResult( IN AFSFcb *Fcb,
     BOOLEAN           bFoundExtent = FALSE;
     LIST_ENTRY       *pSkipEntries[AFS_NUM_EXTENT_LISTS] = { 0 };
     AFSDeviceExt     *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
+    LONG              lCount;
 
     //
     // Grab the extents exclusive for the duration
@@ -1037,9 +1041,11 @@ AFSProcessExtentsResult( IN AFSFcb *Fcb,
 
                 InterlockedExchangeAdd( &Fcb->Specific.File.ExtentLength, (LONG)(pExtent->Size/1024));
 
-                InterlockedIncrement( &Fcb->Specific.File.ExtentCount);
+                lCount = InterlockedIncrement( &Fcb->Specific.File.ExtentCount);
+
+                lCount = InterlockedIncrement( &pControlDevExt->Specific.Control.ExtentCount);
 
-                if( InterlockedIncrement( &pControlDevExt->Specific.Control.ExtentCount) == 1)
+                if( lCount == 1)
                 {
 
                     KeClearEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent);
@@ -1247,6 +1253,7 @@ AFSProcessSetFileExtents( IN AFSSetFileExtentsCB *SetExtents )
     AFSDeviceExt *pDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     ULONGLONG     ullIndex = 0;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    LONG          lCount;
 
     __Enter
     {
@@ -1286,7 +1293,7 @@ AFSProcessSetFileExtents( IN AFSSetFileExtentsCB *SetExtents )
                           pVolumeCB->ObjectInfoTree.TreeLock,
                           PsGetCurrentThread());
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
         }
 
         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -1310,7 +1317,7 @@ AFSProcessSetFileExtents( IN AFSSetFileExtentsCB *SetExtents )
         AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                           TRUE);
 
-        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
         //
         // Now locate the Object in this volume
@@ -1329,13 +1336,13 @@ AFSProcessSetFileExtents( IN AFSSetFileExtentsCB *SetExtents )
             // Reference the node so it won't be torn down
             //
 
-            InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSProcessSetFileExtents Increment count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
 
         AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -1410,13 +1417,13 @@ try_exit:
         if( pObjectInfo != NULL)
         {
 
-            InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSProcessSetFileExtents Decrement count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
     }
 
@@ -1441,6 +1448,7 @@ AFSReleaseSpecifiedExtents( IN  AFSReleaseFileExtentsCB *Extents,
     NTSTATUS             ntStatus = STATUS_SUCCESS;
     BOOLEAN              bReleaseAll = FALSE;
     AFSDeviceExt        *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
+    LONG                 lCount;
 
     __Enter
     {
@@ -1618,7 +1626,7 @@ AFSReleaseSpecifiedExtents( IN  AFSReleaseFileExtentsCB *Extents,
 
                     FileExtents[*ExtentCount].Flags |= AFS_EXTENT_FLAG_DIRTY;
 
-                    InterlockedDecrement( &Fcb->Specific.File.ExtentsDirtyCount);
+                    lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentsDirtyCount);
 
                     *DirtyExtents = TRUE;
                 }
@@ -1653,9 +1661,11 @@ AFSReleaseSpecifiedExtents( IN  AFSReleaseFileExtentsCB *Extents,
             //
             AFSExFreePool( pExtent);
 
-            InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+            lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
 
-            if( InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount) == 0)
+            lCount = InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount);
+
+            if( lCount == 0)
             {
 
                 KeSetEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent,
@@ -1683,6 +1693,7 @@ AFSFindFcbToClean(ULONG IgnoreTime, AFSFcb *LastFcb, BOOLEAN Block)
     BOOLEAN bLocatedEntry = FALSE;
     AFSObjectInfoCB *pCurrentObject = NULL;
     BOOLEAN bReleaseVolumeListLock = FALSE;
+    LONG lCount;
 
     pRDRDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     pControlDeviceExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
@@ -1713,7 +1724,7 @@ AFSFindFcbToClean(ULONG IgnoreTime, AFSFcb *LastFcb, BOOLEAN Block)
                       pVolumeCB->ObjectInfoTree.TreeLock,
                       PsGetCurrentThread());
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSReleaseResource( &pRDRDeviceExt->Specific.RDR.VolumeListLock);
 
@@ -1722,7 +1733,7 @@ AFSFindFcbToClean(ULONG IgnoreTime, AFSFcb *LastFcb, BOOLEAN Block)
         AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                           TRUE);
 
-        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
         if( NULL == LastFcb)
         {
@@ -1840,13 +1851,13 @@ AFSFindFcbToClean(ULONG IgnoreTime, AFSFcb *LastFcb, BOOLEAN Block)
                 // A hit a very palpable hit.  Pin it
                 //
 
-                InterlockedIncrement( &pCurrentObject->ObjectReferenceCount);
+                lCount = InterlockedIncrement( &pCurrentObject->ObjectReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSFindFcbToClean Increment count on Fcb %08lX Cnt %d\n",
                               pCurrentObject,
-                              pCurrentObject->ObjectReferenceCount);
+                              lCount);
 
                 bLocatedEntry = TRUE;
 
@@ -1892,6 +1903,7 @@ AFSProcessExtentFailure( PIRP Irp)
     AFSVolumeCB                       *pVolumeCB = NULL;
     ULONGLONG                          ullIndex = 0;
     AFSObjectInfoCB                   *pObjectInfo = NULL;
+    LONG                               lCount;
 
     __Enter
     {
@@ -1937,7 +1949,7 @@ AFSProcessExtentFailure( PIRP Irp)
                           pVolumeCB->ObjectInfoTree.TreeLock,
                           PsGetCurrentThread());
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
         }
 
         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -1957,7 +1969,7 @@ AFSProcessExtentFailure( PIRP Irp)
         AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                           TRUE);
 
-        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
         //
         // Now locate the Object in this volume
@@ -1977,13 +1989,13 @@ AFSProcessExtentFailure( PIRP Irp)
             // Reference the node so it won't be torn down
             //
 
-            InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSProcessExtentFailure Increment count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
 
         AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -2038,13 +2050,13 @@ AFSProcessExtentFailure( PIRP Irp)
 
         AFSReleaseResource( &pObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource);
 
-        InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+        lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSProcessExtentFailure Decrement count on object %08lX Cnt %d\n",
                       pObjectInfo,
-                      pObjectInfo->ObjectReferenceCount);
+                      lCount);
 
 try_exit:
 
@@ -2072,6 +2084,7 @@ AFSProcessReleaseFileExtents( IN PIRP Irp)
     BOOLEAN                            bLocked = FALSE;
     BOOLEAN                            bDirtyExtents = FALSE;
     GUID                               stAuthGroup;
+    LONG                               lCount;
 
     __Enter
     {
@@ -2175,7 +2188,7 @@ AFSProcessReleaseFileExtents( IN PIRP Irp)
                               pVolumeCB->ObjectInfoTree.TreeLock,
                               PsGetCurrentThread());
 
-                InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
             }
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -2195,7 +2208,7 @@ AFSProcessReleaseFileExtents( IN PIRP Irp)
             AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                               TRUE);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             //
             // Now locate the Object in this volume
@@ -2214,13 +2227,13 @@ AFSProcessReleaseFileExtents( IN PIRP Irp)
                 // Reference the node so it won't be torn down
                 //
 
-                InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+                lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSProcessReleaseFileExtents Increment count on object %08lX Cnt %d\n",
                               pObjectInfo,
-                              pObjectInfo->ObjectReferenceCount);
+                              lCount);
             }
 
             AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -2439,13 +2452,13 @@ try_exit:
         if( pObjectInfo != NULL)
         {
 
-            InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSProcessReleaseFileExtents Decrement count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
     }
 
@@ -2556,6 +2569,7 @@ AFSFlushExtents( IN AFSFcb *Fcb,
     AFSDeviceExt        *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
     GUID                *pAuthGroup = AuthGroup;
     GUID                 stAuthGroup;
+    LONG                 lCount;
 
     ASSERT( Fcb->Header.NodeTypeCode == AFS_FILE_FCB);
 
@@ -2601,7 +2615,7 @@ AFSFlushExtents( IN AFSFcb *Fcb,
 
         bExtentsLocked = TRUE;
 
-        InterlockedIncrement( &Fcb->Specific.File.QueuedFlushCount);
+        lCount = InterlockedIncrement( &Fcb->Specific.File.QueuedFlushCount);
 
         //
         // Clear our queued flush event
@@ -2678,7 +2692,7 @@ AFSFlushExtents( IN AFSFcb *Fcb,
                 pExtent->DirtyList.fLink = NULL;
                 pExtent->DirtyList.bLink = NULL;
 
-                InterlockedDecrement( &Fcb->Specific.File.ExtentsDirtyCount);
+                lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentsDirtyCount);
 
                 //
                 // Clear the flag in advance of the write. If we do
@@ -2736,9 +2750,11 @@ AFSFlushExtents( IN AFSFcb *Fcb,
 
                 AFSExFreePool( pExtent);
 
-                InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+                lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+
+                lCount = InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount);
 
-                if( InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount) == 0)
+                if( lCount == 0)
                 {
 
                     KeSetEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent,
@@ -2823,7 +2839,9 @@ AFSFlushExtents( IN AFSFcb *Fcb,
 
 try_exit:
 
-        if( InterlockedDecrement( &Fcb->Specific.File.QueuedFlushCount) == 0)
+        lCount = InterlockedDecrement( &Fcb->Specific.File.QueuedFlushCount);
+
+        if( lCount == 0)
         {
 
             KeSetEvent( &pNPFcb->Specific.File.QueuedFlushEvent,
@@ -2875,6 +2893,7 @@ AFSReleaseExtentsWithFlush( IN AFSFcb *Fcb,
     AFSDeviceExt        *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
     GUID                *pAuthGroup = AuthGroup;
     GUID                 stAuthGroup;
+    LONG                 lCount;
 
     ASSERT( Fcb->Header.NodeTypeCode == AFS_FILE_FCB);
 
@@ -3020,7 +3039,7 @@ AFSReleaseExtentsWithFlush( IN AFSFcb *Fcb,
 
                         pRelease->FileExtents[count].Flags |= AFS_EXTENT_FLAG_DIRTY;
 
-                        InterlockedDecrement( &Fcb->Specific.File.ExtentsDirtyCount);
+                        lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentsDirtyCount);
                     }
 
                     AFSReleaseResource( &pNPFcb->Specific.File.DirtyExtentsListLock);
@@ -3044,9 +3063,11 @@ AFSReleaseExtentsWithFlush( IN AFSFcb *Fcb,
 
                 AFSExFreePool( pExtent);
 
-                InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+                lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+
+                lCount = InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount);
 
-                if( InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount) == 0)
+                if( lCount == 0)
                 {
 
                     KeSetEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent,
@@ -3160,6 +3181,7 @@ AFSMarkDirty( IN AFSFcb *Fcb,
     AFSExtent     *pNextExtent, *pCurrentExtent = NULL;
     ULONG ulCount = 0;
     BOOLEAN bInsertTail = FALSE, bInsertHead = FALSE;
+    LONG lCount;
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
@@ -3283,7 +3305,7 @@ AFSMarkDirty( IN AFSFcb *Fcb,
             // Up the dirty count
             //
 
-            InterlockedIncrement( &Fcb->Specific.File.ExtentsDirtyCount);
+            lCount = InterlockedIncrement( &Fcb->Specific.File.ExtentsDirtyCount);
         }
         else
         {
@@ -3299,7 +3321,7 @@ AFSMarkDirty( IN AFSFcb *Fcb,
 
         ASSERT( pExtent->ActiveCount > 0);
 
-        InterlockedDecrement( &pExtent->ActiveCount);
+        lCount = InterlockedDecrement( &pExtent->ActiveCount);
 
         pExtent = pNextExtent;
 
@@ -3407,6 +3429,7 @@ AFSTrimExtents( IN AFSFcb *Fcb,
     LARGE_INTEGER        liAlignedOffset = {0,0};
     AFSDeviceExt        *pDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSDeviceExt        *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
+    LONG                 lCount;
 
     __Enter
     {
@@ -3546,9 +3569,11 @@ AFSTrimExtents( IN AFSFcb *Fcb,
                 //
                 AFSExFreePool( pExtent);
 
-                InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+                lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
 
-                if( InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount) == 0)
+                lCount = InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount);
+
+                if( lCount == 0)
                 {
 
                     KeSetEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent,
@@ -3595,6 +3620,7 @@ AFSTrimSpecifiedExtents( IN AFSFcb *Fcb,
     NTSTATUS             ntStatus = STATUS_SUCCESS;
     AFSDeviceExt        *pDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSDeviceExt        *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
+    LONG                 lCount;
 
     __Enter
     {
@@ -3670,9 +3696,11 @@ AFSTrimSpecifiedExtents( IN AFSFcb *Fcb,
                 //
                 AFSExFreePool( pExtent);
 
-                InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+                lCount = InterlockedDecrement( &Fcb->Specific.File.ExtentCount);
+
+                lCount = InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount);
 
-                if( InterlockedDecrement( &pControlDevExt->Specific.Control.ExtentCount) == 0)
+                if( lCount == 0)
                 {
 
                     KeSetEvent( &pControlDevExt->Specific.Control.ExtentsHeldEvent,
@@ -3708,19 +3736,20 @@ AFSReferenceActiveExtents( IN AFSExtent *StartExtent,
     AFSExtent     *pExtent = StartExtent;
     AFSExtent     *pNextExtent;
     ULONG          ulCount = 0;
+    LONG           lCount;
 
     while( ulCount < ExtentsCount)
     {
 
         pNextExtent = NextExtent( pExtent, AFS_EXTENTS_LIST);
 
-        InterlockedIncrement( &pExtent->ActiveCount);
+        lCount = InterlockedIncrement( &pExtent->ActiveCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_ACTIVE_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSReferenceActiveExtents Increment count on extent %08lX Cnt %d\n",
                       pExtent,
-                      pExtent->ActiveCount);
+                      lCount);
 
         pExtent = pNextExtent;
 
@@ -3738,21 +3767,22 @@ AFSDereferenceActiveExtents( IN AFSExtent *StartExtent,
     AFSExtent     *pExtent = StartExtent;
     AFSExtent     *pNextExtent;
     ULONG          ulCount = 0;
+    LONG            lCount;
 
     while( ulCount < ExtentsCount)
     {
 
         pNextExtent = NextExtent( pExtent, AFS_EXTENTS_LIST);
 
+        ASSERT( pExtent->ActiveCount > 0);
+
+        lCount = InterlockedDecrement( &pExtent->ActiveCount);
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_ACTIVE_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSDereferenceActiveExtents Decrement count on extent %08lX Cnt %d\n",
                       pExtent,
-                      pExtent->ActiveCount);
-
-        ASSERT( pExtent->ActiveCount > 0);
-
-        InterlockedDecrement( &pExtent->ActiveCount);
+                      lCount);
 
         pExtent = pNextExtent;
 
index 8fdc8b6..73b9702 100644 (file)
@@ -358,6 +358,7 @@ AFSInitVolume( IN GUID *AuthGroup,
     BOOLEAN bReleaseLocks = FALSE;
     AFSVolumeInfoCB stVolumeInformation;
     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -415,7 +416,7 @@ AFSInitVolume( IN GUID *AuthGroup,
                 // So we don't lock with an invalidation call ...
                 //
 
-                InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSReleaseResource( pDeviceExt->Specific.RDR.VolumeTree.TreeLock);
 
@@ -426,7 +427,7 @@ AFSInitVolume( IN GUID *AuthGroup,
                 AFSAcquireExcl( pVolumeCB->VolumeLock,
                                 TRUE);
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                 *VolumeCB = pVolumeCB;
 
index 1f29a9d..ba96adf 100644 (file)
@@ -2083,6 +2083,7 @@ AFSSetRenameInfo( IN PIRP Irp)
     BOOLEAN bReleaseTargetDirLock = FALSE;
     BOOLEAN bReleaseSourceDirLock = FALSE;
     PERESOURCE  pSourceDirLock = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -2246,7 +2247,7 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( pTargetParentObject == pTargetDirEntry->ObjectInformation->ParentObjectInformation);
 
-            InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
 
             if( !bReplaceIfExists)
             {
@@ -2534,13 +2535,13 @@ AFSSetRenameInfo( IN PIRP Irp)
         if( pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation != pTargetParentObject)
         {
 
-            InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+            lCount = InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
-            InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+            lCount = InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
-            InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenHandleCount);
+            lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenHandleCount);
 
-            InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
 
             pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation = pTargetParentObject;
 
@@ -2610,9 +2611,9 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( pTargetDirEntry->OpenReferenceCount > 0);
 
-            InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount); // The count we added above
+            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount); // The count we added above
 
-            if( pTargetDirEntry->OpenReferenceCount == 0)
+            if( lCount == 0)
             {
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -2645,7 +2646,7 @@ try_exit:
         if( pTargetDirEntry != NULL)
         {
 
-            InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
         }
 
         if( bReleaseTargetDirLock)
index 50a8e46..a3c23a8 100644 (file)
@@ -643,6 +643,7 @@ AFSInitializeGlobalDirectoryEntries()
     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSObjectInfoCB *pObjectInfoCB = NULL;
     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -665,13 +666,13 @@ AFSInitializeGlobalDirectoryEntries()
             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
 
-        InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInitializeGlobalDirectoryEntries Increment count on object %08lX Cnt %d\n",
                       pObjectInfoCB,
-                      pObjectInfoCB->ObjectReferenceCount);
+                      lCount);
 
         ntStatus = STATUS_SUCCESS;
 
@@ -772,13 +773,13 @@ AFSInitializeGlobalDirectoryEntries()
             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
 
-        InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInitializeGlobalDirectoryEntries Increment count on object %08lX Cnt %d\n",
                       pObjectInfoCB,
-                      pObjectInfoCB->ObjectReferenceCount);
+                      lCount);
 
         ntStatus = STATUS_SUCCESS;
 
@@ -912,6 +913,7 @@ AFSInitDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
     BOOLEAN bAllocatedObjectCB = FALSE;
     ULONGLONG ullIndex = 0;
     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -968,13 +970,13 @@ AFSInitDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
                           FileName);
         }
 
-        InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInitDirEntry Increment count on object %08lX Cnt %d\n",
                       pObjectInfoCB,
-                      pObjectInfoCB->ObjectReferenceCount);
+                      lCount);
 
         AFSReleaseResource( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
 
@@ -1194,13 +1196,13 @@ try_exit:
             if( pObjectInfoCB != NULL)
             {
 
-                InterlockedDecrement( &pObjectInfoCB->ObjectReferenceCount);
+                lCount = InterlockedDecrement( &pObjectInfoCB->ObjectReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSInitDirEntry Decrement count on object %08lX Cnt %d\n",
                               pObjectInfoCB,
-                              pObjectInfoCB->ObjectReferenceCount);
+                              lCount);
 
                 if( bAllocatedObjectCB)
                 {
@@ -1565,6 +1567,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
     AFSObjectInfoCB *pObjectInfo = NULL;
     IO_STATUS_BLOCK stIoStatus;
     ULONG ulFilter = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -1598,13 +1601,13 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
         if( pVolumeCB != NULL)
         {
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInvalidateCache Increment count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -1635,7 +1638,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
                                             FILE_NOTIFY_CHANGE_SIZE,
                                             FILE_ACTION_MODIFIED);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             try_return( ntStatus);
         }
@@ -1643,7 +1646,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
         AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                           TRUE);
 
-        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -1664,13 +1667,13 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
             // Reference the node so it won't be torn down
             //
 
-            InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInvalidateCache Increment count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
 
         AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -1975,13 +1978,13 @@ try_exit:
         if( pObjectInfo != NULL)
         {
 
-            InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInvalidateCache Decrement count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
     }
 
@@ -3044,6 +3047,7 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
     AFSVolumeCB *pVolumeCB = NULL;
     AFSFcb *pFcb = NULL;
     AFSObjectInfoCB *pCurrentObject = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -3080,7 +3084,7 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
         if( pVolumeCB != NULL)
         {
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
 
@@ -3176,7 +3180,7 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
 
             AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
         }
         else
         {
@@ -4839,6 +4843,7 @@ AFSInitNameArray( IN AFSDirectoryCB *DirectoryCB,
 
     AFSNameArrayHdr *pNameArray = NULL;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -4875,16 +4880,16 @@ AFSInitNameArray( IN AFSDirectoryCB *DirectoryCB,
 
             pNameArray->CurrentEntry = &pNameArray->ElementArray[ 0];
 
-            InterlockedIncrement( &pNameArray->Count);
+            lCount = InterlockedIncrement( &pNameArray->Count);
 
-            InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInitNameArray Increment count on %wZ DE %p Cnt %d\n",
                           &DirectoryCB->NameInformation.FileName,
                           DirectoryCB,
-                          DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             pNameArray->CurrentEntry->DirectoryCB = DirectoryCB;
 
@@ -4914,6 +4919,7 @@ AFSPopulateNameArray( IN AFSNameArrayHdr *NameArray,
     ULONG  ulTotalCount = 0;
     ULONG ulIndex = 0;
     USHORT usLength = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -4932,14 +4938,14 @@ AFSPopulateNameArray( IN AFSNameArrayHdr *NameArray,
 
         pCurrentElement->DirectoryCB = DirectoryCB->ObjectInformation->VolumeCB->DirectoryCB;
 
-        InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSPopulateNameArray Increment count on volume %wZ DE %p Cnt %d\n",
                       &pCurrentElement->DirectoryCB->NameInformation.FileName,
                       pCurrentElement->DirectoryCB,
-                      pCurrentElement->DirectoryCB->OpenReferenceCount);
+                      lCount);
 
         pCurrentElement->Component = DirectoryCB->ObjectInformation->VolumeCB->DirectoryCB->NameInformation.FileName;
 
@@ -4979,6 +4985,7 @@ AFSPopulateNameArrayFromRelatedArray( IN AFSNameArrayHdr *NameArray,
     ULONG  ulTotalCount = 0;
     ULONG ulIndex = 0;
     USHORT usLength = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -5008,16 +5015,16 @@ AFSPopulateNameArrayFromRelatedArray( IN AFSNameArrayHdr *NameArray,
 
             pCurrentElement->FileId    = pCurrentElement->DirectoryCB->ObjectInformation->FileId;
 
-            InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSPopulateNameArrayFromRelatedArray Increment count on %wZ DE %p Cnt %d\n",
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
-                          pCurrentElement->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
-            InterlockedIncrement( &NameArray->Count);
+            lCount = InterlockedIncrement( &NameArray->Count);
 
             if( pCurrentElement->DirectoryCB == DirectoryCB ||
                 NameArray->Count == RelatedNameArray->Count)
@@ -5050,6 +5057,7 @@ AFSFreeNameArray( IN AFSNameArrayHdr *NameArray)
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSNameArrayCB *pCurrentElement = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -5065,14 +5073,14 @@ AFSFreeNameArray( IN AFSNameArrayHdr *NameArray)
                 break;
             }
 
-            InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSFreeNameArray Decrement count on %wZ DE %p Cnt %d\n",
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
-                          pCurrentElement->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             pCurrentElement++;
         }
@@ -5090,6 +5098,7 @@ AFSInsertNextElement( IN AFSNameArrayHdr *NameArray,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -5117,16 +5126,16 @@ AFSInsertNextElement( IN AFSNameArrayHdr *NameArray,
             NameArray->CurrentEntry = &NameArray->ElementArray[ 0];
         }
 
-        InterlockedIncrement( &NameArray->Count);
+        lCount = InterlockedIncrement( &NameArray->Count);
 
-        InterlockedIncrement( &DirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &DirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInsertNextElement Increment count on %wZ DE %p Cnt %d\n",
                       &DirEntry->NameInformation.FileName,
                       DirEntry,
-                      DirEntry->OpenReferenceCount);
+                      lCount);
 
         NameArray->CurrentEntry->DirectoryCB = DirEntry;
 
@@ -5146,26 +5155,27 @@ void
 AFSReplaceCurrentElement( IN AFSNameArrayHdr *NameArray,
                           IN AFSDirectoryCB *DirectoryCB)
 {
+    LONG lCount;
 
     ASSERT( NameArray->CurrentEntry != NULL);
 
-    InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+    lCount = InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSReplaceCurrentElement Decrement count on %wZ DE %p Cnt %d\n",
                   &NameArray->CurrentEntry->DirectoryCB->NameInformation.FileName,
                   NameArray->CurrentEntry->DirectoryCB,
-                  NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+                  lCount);
 
-    InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+    lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSReplaceCurrentElement Increment count on %wZ DE %p Cnt %d\n",
                   &DirectoryCB->NameInformation.FileName,
                   DirectoryCB,
-                  DirectoryCB->OpenReferenceCount);
+                  lCount);
 
     NameArray->CurrentEntry->DirectoryCB = DirectoryCB;
 
@@ -5187,6 +5197,7 @@ AFSBackupEntry( IN AFSNameArrayHdr *NameArray)
 {
 
     AFSDirectoryCB *pCurrentDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -5196,18 +5207,20 @@ AFSBackupEntry( IN AFSNameArrayHdr *NameArray)
             try_return( pCurrentDirEntry);
         }
 
-        InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSBackupEntry Decrement count on %wZ DE %p Cnt %d\n",
                       &NameArray->CurrentEntry->DirectoryCB->NameInformation.FileName,
                       NameArray->CurrentEntry->DirectoryCB,
-                      NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+                      lCount);
 
         NameArray->CurrentEntry->DirectoryCB = NULL;
 
-        if( InterlockedDecrement( &NameArray->Count) == 0)
+        lCount = InterlockedDecrement( &NameArray->Count);
+
+        if( lCount == 0)
         {
             NameArray->CurrentEntry = NULL;
         }
@@ -5261,6 +5274,7 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
 
     AFSNameArrayCB *pCurrentElement = NULL;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -5276,14 +5290,14 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
                 break;
             }
 
-            InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSResetNameArray Decrement count on %wZ DE %p Cnt %d\n",
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
-                          pCurrentElement->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             pCurrentElement++;
         }
@@ -5299,16 +5313,16 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
 
             NameArray->CurrentEntry = &NameArray->ElementArray[ 0];
 
-            InterlockedIncrement( &NameArray->Count);
+            lCount = InterlockedIncrement( &NameArray->Count);
 
-            InterlockedIncrement( &DirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &DirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSResetNameArray Increment count on %wZ DE %p Cnt %d\n",
                           &DirEntry->NameInformation.FileName,
                           DirEntry,
-                          DirEntry->OpenReferenceCount);
+                          lCount);
 
             NameArray->CurrentEntry->DirectoryCB = DirEntry;
 
@@ -5352,6 +5366,7 @@ AFSDumpNameArray( IN AFSNameArrayHdr *NameArray)
 void
 AFSSetEnumerationEvent( IN AFSFcb *Fcb)
 {
+    LONG lCount;
 
     //
     // Depending on the type of node, set the event
@@ -5367,7 +5382,7 @@ AFSSetEnumerationEvent( IN AFSFcb *Fcb)
                         0,
                         FALSE);
 
-            InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+            lCount = InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
 
             break;
         }
@@ -5380,7 +5395,7 @@ AFSSetEnumerationEvent( IN AFSFcb *Fcb)
                         0,
                         FALSE);
 
-            InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+            lCount = InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
 
             break;
         }
@@ -5393,6 +5408,8 @@ void
 AFSClearEnumerationEvent( IN AFSFcb *Fcb)
 {
 
+    LONG lCount;
+
     //
     // Depending on the type of node, set the event
     //
@@ -5405,7 +5422,9 @@ AFSClearEnumerationEvent( IN AFSFcb *Fcb)
 
             ASSERT( Fcb->NPFcb->Specific.Directory.DirectoryEnumCount > 0);
 
-            if( InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount) == 0)
+            lCount = InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+
+            if( lCount == 0)
             {
 
                 KeClearEvent( &Fcb->NPFcb->Specific.Directory.DirectoryEnumEvent);
@@ -5420,7 +5439,9 @@ AFSClearEnumerationEvent( IN AFSFcb *Fcb)
 
             ASSERT( Fcb->NPFcb->Specific.Directory.DirectoryEnumCount > 0);
 
-            if( InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount) == 0)
+            lCount = InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+
+            if( lCount == 0)
             {
 
                 KeClearEvent( &Fcb->NPFcb->Specific.Directory.DirectoryEnumEvent);
@@ -5632,6 +5653,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
     WCHAR *pwchBuffer = NULL;
     UNICODE_STRING uniComponentName, uniRemainingPath, uniParsedName;
     ULONG ulNameDifference = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -5879,15 +5901,15 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
         // Increment the ref count on the volume and dir entry for correct processing below
         //
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSRetrieveFileAttributes Increment count on volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -5895,7 +5917,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                       &pParentDirEntry->NameInformation.FileName,
                       pParentDirEntry,
                       NULL,
-                      pParentDirEntry->OpenReferenceCount);
+                      lCount);
 
         ntStatus = AFSLocateNameEntry( NULL,
                                        NULL,
@@ -5922,19 +5944,19 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                 if( pVolumeCB != NULL)
                 {
 
-                    InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                    lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSRetrieveFileAttributes Decrement count on volume %08lX Cnt %d\n",
                                   pVolumeCB,
-                                  pVolumeCB->VolumeReferenceCount);
+                                  lCount);
                 }
 
                 if( pDirectoryEntry != NULL)
                 {
 
-                    InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -5942,12 +5964,12 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                                   &pDirectoryEntry->NameInformation.FileName,
                                   pDirectoryEntry,
                                   NULL,
-                                  pDirectoryEntry->OpenReferenceCount);
+                                  lCount);
                 }
                 else
                 {
 
-                    InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -5955,7 +5977,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                                   &pParentDirEntry->NameInformation.FileName,
                                   pParentDirEntry,
                                   NULL,
-                                  pParentDirEntry->OpenReferenceCount);
+                                  lCount);
                 }
             }
 
@@ -6011,7 +6033,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
         // Remove the reference made above
         //
 
-        InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6019,7 +6041,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                       &pDirectoryEntry->NameInformation.FileName,
                       pDirectoryEntry,
                       NULL,
-                      pDirectoryEntry->OpenReferenceCount);
+                      lCount);
 
 try_exit:
 
@@ -6032,13 +6054,13 @@ try_exit:
         if( pVolumeCB != NULL)
         {
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSRetrieveFileAttributes Decrement2 count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         if( pNameArray != NULL)
@@ -6079,6 +6101,7 @@ AFSAllocateObjectInfo( IN AFSObjectInfoCB *ParentObjectInfo,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -6118,7 +6141,7 @@ AFSAllocateObjectInfo( IN AFSObjectInfoCB *ParentObjectInfo,
 
         if( ParentObjectInfo != NULL)
         {
-            InterlockedIncrement( &ParentObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &ParentObjectInfo->ObjectReferenceCount);
         }
 
         //
@@ -6189,6 +6212,7 @@ AFSDeleteObjectInfo( IN AFSObjectInfoCB *ObjectInfo)
 {
 
     BOOLEAN bAcquiredTreeLock = FALSE;
+    LONG lCount;
 
     if( !ExIsResourceAcquiredExclusiveLite( ObjectInfo->VolumeCB->ObjectInfoTree.TreeLock))
     {
@@ -6252,7 +6276,8 @@ AFSDeleteObjectInfo( IN AFSObjectInfoCB *ObjectInfo)
 
     if( ObjectInfo->ParentObjectInformation != NULL)
     {
-        InterlockedDecrement( &ObjectInfo->ParentObjectInformation->ObjectReferenceCount);
+
+        lCount = InterlockedDecrement( &ObjectInfo->ParentObjectInformation->ObjectReferenceCount);
     }
 
     if( bAcquiredTreeLock)
@@ -6295,6 +6320,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
     UNICODE_STRING uniComponentName, uniRemainingPath, uniParsedName;
     ULONG ulNameDifference = 0;
     GUID    stAuthGroup;
+    LONG lCount;
 
     __Enter
     {
@@ -6448,15 +6474,15 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
 
         pParentDirEntry = AFSGlobalRoot->DirectoryCB;
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSEvaluateRootEntry Increment count on volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6464,7 +6490,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                       &pParentDirEntry->NameInformation.FileName,
                       pParentDirEntry,
                       NULL,
-                      pParentDirEntry->OpenReferenceCount);
+                      lCount);
 
         ntStatus = AFSLocateNameEntry( NULL,
                                        NULL,
@@ -6491,19 +6517,19 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                 if( pVolumeCB != NULL)
                 {
 
-                    InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                    lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSEvaluateRootEntry Decrement count on volume %08lX Cnt %d\n",
                                   pVolumeCB,
-                                  pVolumeCB->VolumeReferenceCount);
+                                  lCount);
                 }
 
                 if( pDirectoryEntry != NULL)
                 {
 
-                    InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6511,12 +6537,12 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                                   &pDirectoryEntry->NameInformation.FileName,
                                   pDirectoryEntry,
                                   NULL,
-                                  pDirectoryEntry->OpenReferenceCount);
+                                  lCount);
                 }
                 else
                 {
 
-                    InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6524,7 +6550,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                                   &pParentDirEntry->NameInformation.FileName,
                                   pParentDirEntry,
                                   NULL,
-                                  pParentDirEntry->OpenReferenceCount);
+                                  lCount);
                 }
             }
 
@@ -6550,13 +6576,13 @@ try_exit:
         if( pVolumeCB != NULL)
         {
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSEvaluateRootEntry2 Decrement count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         if( pNameArray != NULL)
@@ -7587,6 +7613,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
     UNICODE_STRING uniFullPathName, uniRemainingPath, uniComponentName, uniParsedName;
     AFSNameArrayHdr *pNameArray = NULL;
     AFSDirectoryCB *pDirectoryEntry = NULL, *pParentDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -7617,13 +7644,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             if( pVolumeCB != NULL)
             {
 
-                InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetObjectStatus Increment count on volume %08lX Cnt %d\n",
                               pVolumeCB,
-                              pVolumeCB->VolumeReferenceCount);
+                              lCount);
             }
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -7639,9 +7666,9 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
                 pObjectInfo = &pVolumeCB->ObjectInformation;
 
-                InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+                lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
             }
             else
             {
@@ -7649,13 +7676,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                 AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                                   TRUE);
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
                               pVolumeCB,
-                              pVolumeCB->VolumeReferenceCount);
+                              lCount);
 
                 ullIndex = AFSCreateLowIndex( &GetStatusInfo->FileID);
 
@@ -7670,13 +7697,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                     // Reference the node so it won't be torn down
                     //
 
-                    InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+                    lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSGetObjectStatus Increment count on object %08lX Cnt %d\n",
                                   pObjectInfo,
-                                  pObjectInfo->ObjectReferenceCount);
+                                  lCount);
                 }
 
                 AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -7746,15 +7773,15 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             // Increment the ref count on the volume and dir entry for correct processing below
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetObjectStatus Increment count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
 
-            InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -7762,7 +7789,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                           &pParentDirEntry->NameInformation.FileName,
                           pParentDirEntry,
                           NULL,
-                          pParentDirEntry->OpenReferenceCount);
+                          lCount);
 
             ntStatus = AFSLocateNameEntry( NULL,
                                            NULL,
@@ -7790,19 +7817,19 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                     if( pVolumeCB != NULL)
                     {
 
-                        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
                                       "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
                                       pVolumeCB,
-                                      pVolumeCB->VolumeReferenceCount);
+                                      lCount);
                     }
 
                     if( pDirectoryEntry != NULL)
                     {
 
-                        InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -7810,12 +7837,12 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                                       &pDirectoryEntry->NameInformation.FileName,
                                       pDirectoryEntry,
                                       NULL,
-                                      pDirectoryEntry->OpenReferenceCount);
+                                      lCount);
                     }
                     else
                     {
 
-                        InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -7823,7 +7850,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                                       &pParentDirEntry->NameInformation.FileName,
                                       pParentDirEntry,
                                       NULL,
-                                      pParentDirEntry->OpenReferenceCount);
+                                      lCount);
                     }
                 }
 
@@ -7836,16 +7863,16 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             // Remove the reference made above
             //
 
-            InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
             pObjectInfo = pDirectoryEntry->ObjectInformation;
 
-            InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
             if( pVolumeCB != NULL)
             {
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -7900,7 +7927,7 @@ try_exit:
         if( pObjectInfo != NULL)
         {
 
-            InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
         }
 
         if( pNameArray != NULL)
@@ -7921,6 +7948,7 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDirectoryCB *pDirEntry = NULL;
     ULONG ulCRC = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -7990,7 +8018,7 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
 
         if( pDirEntry != NULL)
         {
-            InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
         }
 
         AFSReleaseResource( ParentDirectoryCB->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -8018,7 +8046,7 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
 
         ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
 
-        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
 try_exit:
 
index d3d907a..fb23f0c 100644 (file)
@@ -280,6 +280,7 @@ AFSStartIos( IN PFILE_OBJECT     CacheFileObject,
     PIRP                pIrp;
     NTSTATUS            ntStatus = STATUS_SUCCESS;
     PDEVICE_OBJECT      pDeviceObject = NULL;
+    LONG                lCount;
 
     __Enter
     {
@@ -304,7 +305,7 @@ AFSStartIos( IN PFILE_OBJECT     CacheFileObject,
             // Bump the count *before* we start the IO, that way if it
             // completes real fast it will still not set the event
             //
-            InterlockedIncrement(&Gather->Count);
+            lCount = InterlockedIncrement(&Gather->Count);
 
             //
             // Set the completion routine.
@@ -338,12 +339,16 @@ VOID
 AFSCompleteIo( IN AFSGatherIo *Gather,
                IN NTSTATUS Status)
 {
+    LONG lCount;
+
     if (!NT_SUCCESS(Status)) {
 
         Gather->Status = Status;
     }
 
-    if (0 == InterlockedDecrement( &Gather->Count )) {
+    lCount = InterlockedDecrement( &Gather->Count );
+
+    if (0 == lCount) {
         //
         // Last outstanding IO.  Complete the parent and
         // do whatever it takes to clean up
index d894d43..2adf59e 100644 (file)
@@ -66,6 +66,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
     AFSVolumeCB      *pCurrentVolume = *VolumeCB;
     BOOLEAN           bReleaseCurrentVolume = TRUE;
     BOOLEAN           bSubstitutedName = FALSE;
+    LONG              lCount;
 
     __Enter
     {
@@ -515,7 +516,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Dereference the current entry ..
                         //
 
-                        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -523,7 +524,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
 
                         //
                         // OK, need to back up one entry for the correct parent since the current
@@ -536,7 +537,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Increment our reference on this dir entry
                         //
 
-                        InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -544,7 +545,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
 
                         if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_ROOT_VOLUME))
                         {
@@ -673,30 +674,30 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                           pCurrentObject->FileId.Vnode,
                                           pCurrentObject->FileId.Unique);
 
-                            InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
+                            lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                           AFS_TRACE_LEVEL_VERBOSE,
                                           "AFSLocateNameEntry Decrement count on volume %08lX Cnt %d\n",
                                           pCurrentVolume,
-                                          pCurrentVolume->VolumeReferenceCount);
+                                          lCount);
 
                             pCurrentVolume = AFSGlobalRoot;
 
-                            InterlockedIncrement( &pCurrentVolume->VolumeReferenceCount);
+                            lCount = InterlockedIncrement( &pCurrentVolume->VolumeReferenceCount);
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                           AFS_TRACE_LEVEL_VERBOSE,
                                           "AFSLocateNameEntry Increment count on volume %08lX Cnt %d\n",
                                           pCurrentVolume,
-                                          pCurrentVolume->VolumeReferenceCount);
+                                          lCount);
                         }
 
                         //
                         // Dereference our current dir entry
                         //
 
-                        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -704,7 +705,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
 
                         pDirEntry = pCurrentVolume->DirectoryCB;
 
@@ -712,7 +713,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Reference the new dir entry
                         //
 
-                        InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -720,7 +721,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
 
                         //
                         // Reset the name array
@@ -780,7 +781,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our link count
                     //
 
-                    InterlockedIncrement( &pNameArray->LinkCount);
+                    lCount = InterlockedIncrement( &pNameArray->LinkCount);
 
                     continue;
                 }
@@ -831,7 +832,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                     ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                    InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
+                    lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -880,7 +881,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Deref and ref count the entries
                     //
 
-                    InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -888,11 +889,11 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   &pDirEntry->NameInformation.FileName,
                                   pDirEntry,
                                   NULL,
-                                  pDirEntry->OpenReferenceCount);
+                                  lCount);
 
                     pDirEntry = pCurrentVolume->DirectoryCB;
 
-                    InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -900,7 +901,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   &pDirEntry->NameInformation.FileName,
                                   pDirEntry,
                                   NULL,
-                                  pDirEntry->OpenReferenceCount);
+                                  lCount);
 
                     pParentDirEntry = NULL;
 
@@ -908,7 +909,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our link count
                     //
 
-                    InterlockedIncrement( &pNameArray->LinkCount);
+                    lCount = InterlockedIncrement( &pNameArray->LinkCount);
 
                     continue;
                 }
@@ -1187,8 +1188,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 //
                 // Need to back up one entry in the name array
                 //
-
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1196,7 +1196,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               &pDirEntry->NameInformation.FileName,
                               pDirEntry,
                               NULL,
-                              pDirEntry->OpenReferenceCount);
+                              lCount);
 
                 pDirEntry = AFSBackupEntry( NameArray);
 
@@ -1210,7 +1210,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     try_return(ntStatus = STATUS_OBJECT_PATH_INVALID);
                 }
 
-                InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
                 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_ROOT_VOLUME))
                 {
@@ -1557,7 +1557,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our dir entry ref count
                     //
 
-                    InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -1565,7 +1565,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   &pDirEntry->NameInformation.FileName,
                                   pDirEntry,
                                   NULL,
-                                  pDirEntry->OpenReferenceCount);
+                                  lCount);
                 }
 
                 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -1605,7 +1605,9 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 AFSAcquireExcl( pCurrentObject->VolumeCB->ObjectInfoTree.TreeLock,
                                 TRUE);
 
-                if( InterlockedDecrement( &pDirEntry->OpenReferenceCount) == 0)
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+
+                if( lCount == 0)
                 {
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING|AFS_SUBSYSTEM_CLEANUP_PROCESSING,
@@ -1713,7 +1715,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
             // Decrement the previous parent
             //
 
-            InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -1721,7 +1723,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                           &pParentDirEntry->NameInformation.FileName,
                           pParentDirEntry,
                           NULL,
-                          pParentDirEntry->OpenReferenceCount);
+                          lCount);
 
             //
             // If we ended up substituting a name in the component then update
@@ -1864,7 +1866,7 @@ try_exit:
             if( pDirEntry != NULL)
             {
 
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1872,12 +1874,12 @@ try_exit:
                               &pDirEntry->NameInformation.FileName,
                               pDirEntry,
                               NULL,
-                              pDirEntry->OpenReferenceCount);
+                              lCount);
             }
             else if( pParentDirEntry != NULL)
             {
 
-                InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1885,7 +1887,7 @@ try_exit:
                               &pParentDirEntry->NameInformation.FileName,
                               pParentDirEntry,
                               NULL,
-                              pParentDirEntry->OpenReferenceCount);
+                              lCount);
             }
 
             if( bReleaseCurrentVolume)
@@ -1893,13 +1895,13 @@ try_exit:
 
                 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSLocateNameEntry Decrement3 count on volume %08lX Cnt %d\n",
                               pCurrentVolume,
-                              pCurrentVolume->VolumeReferenceCount);
+                              lCount);
             }
 
             if( RootPathName->Buffer != uniFullPathName.Buffer)
@@ -1961,6 +1963,7 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
     AFSDirectoryCB *pDirNode = NULL, *pExistingDirNode = NULL;
     UNICODE_STRING uniShortName;
     LARGE_INTEGER liFileSize = {0,0};
+    LONG lCount;
 
     __Enter
     {
@@ -2078,14 +2081,14 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                 AFSDeleteDirEntry( ParentObjectInfo,
                                    pDirNode);
 
-                InterlockedIncrement( &pExistingDirNode->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pExistingDirNode->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
                               &pExistingDirNode->NameInformation.FileName,
                               pExistingDirNode,
-                              pExistingDirNode->OpenReferenceCount);
+                              lCount);
 
                 *DirEntry = pExistingDirNode;
 
@@ -2164,14 +2167,14 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                                 pDirNode,
                                 TRUE);
 
-        InterlockedIncrement( &pDirNode->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pDirNode->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSCreateDirEntry Increment2 count on %wZ DE %p Cnt %d\n",
                       &pDirNode->NameInformation.FileName,
                       pDirNode,
-                      pDirNode->OpenReferenceCount);
+                      lCount);
 
         //
         // Pass back the dir entry
@@ -2195,6 +2198,8 @@ AFSInsertDirectoryNode( IN AFSObjectInfoCB *ParentObjectInfo,
                         IN BOOLEAN InsertInEnumList)
 {
 
+    LONG lCount;
+
     __Enter
     {
 
@@ -2341,17 +2346,17 @@ AFSInsertDirectoryNode( IN AFSObjectInfoCB *ParentObjectInfo,
 
             SetFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
 
-            InterlockedIncrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
+            lCount = InterlockedIncrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInsertDirectoryNode Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
-                              &DirEntry->NameInformation.FileName,
-                              ParentObjectInfo->Specific.Directory.DirectoryNodeCount,
-                              ParentObjectInfo->FileId.Cell,
-                              ParentObjectInfo->FileId.Volume,
-                              ParentObjectInfo->FileId.Vnode,
-                              ParentObjectInfo->FileId.Unique);
+                          &DirEntry->NameInformation.FileName,
+                          lCount,
+                          ParentObjectInfo->FileId.Cell,
+                          ParentObjectInfo->FileId.Volume,
+                          ParentObjectInfo->FileId.Vnode,
+                          ParentObjectInfo->FileId.Unique);
         }
     }
 
@@ -2364,6 +2369,7 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    LONG lCount;
 
     __Enter
     {
@@ -2405,7 +2411,9 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
 
         ASSERT( DirEntry->ObjectInformation->ObjectReferenceCount > 0);
 
-        if( InterlockedDecrement( &DirEntry->ObjectInformation->ObjectReferenceCount) == 0)
+        lCount = InterlockedDecrement( &DirEntry->ObjectInformation->ObjectReferenceCount);
+
+        if( lCount == 0)
         {
             SetFlag( DirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED);
         }
@@ -2437,6 +2445,7 @@ AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    LONG lCount;
 
     __Enter
     {
@@ -2510,7 +2519,7 @@ AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
 
             ASSERT( ParentObjectInfo->Specific.Directory.DirectoryNodeCount > 0);
 
-            InterlockedDecrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
+            lCount = InterlockedDecrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
 
             ClearFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
 
@@ -2518,7 +2527,7 @@ AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSRemoveDirNodeFromParent Removing entry %wZ Dec Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
                           &DirEntry->NameInformation.FileName,
-                          ParentObjectInfo->Specific.Directory.DirectoryNodeCount,
+                          lCount,
                           ParentObjectInfo->FileId.Cell,
                           ParentObjectInfo->FileId.Volume,
                           ParentObjectInfo->FileId.Vnode,
@@ -2637,6 +2646,7 @@ AFSParseName( IN PIRP Irp,
     AFSFcb             *pRelatedFcb = NULL;
     BOOLEAN             bReleaseTreeLock = FALSE;
     BOOLEAN             bIsAllShare = FALSE;
+    LONG                lCount;
 
     __Enter
     {
@@ -2948,17 +2958,17 @@ AFSParseName( IN PIRP Irp,
             // Increment our volume reference count
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSParseName Increment count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
 
             *ParentDirectoryCB = pDirEntry;
 
-            InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -2966,7 +2976,7 @@ AFSParseName( IN PIRP Irp,
                           &pDirEntry->NameInformation.FileName,
                           pDirEntry,
                           NULL,
-                          pDirEntry->OpenReferenceCount);
+                          lCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE_2,
@@ -3196,7 +3206,7 @@ AFSParseName( IN PIRP Irp,
                           "AFSParseName (%08lX) Returning global root access\n",
                           Irp);
 
-            InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3204,7 +3214,7 @@ AFSParseName( IN PIRP Irp,
                           &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                           AFSGlobalRoot->DirectoryCB,
                           NULL,
-                          AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             *VolumeCB = NULL;
 
@@ -3262,7 +3272,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Returning global root access\n",
                               Irp);
 
-                InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -3270,7 +3280,7 @@ AFSParseName( IN PIRP Irp,
                               &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                               AFSGlobalRoot->DirectoryCB,
                               NULL,
-                              AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                              lCount);
 
                 *VolumeCB = NULL;
 
@@ -3305,7 +3315,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Returning root PIOCtl access\n",
                               Irp);
 
-                InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -3313,7 +3323,7 @@ AFSParseName( IN PIRP Irp,
                               &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                               AFSGlobalRoot->DirectoryCB,
                               NULL,
-                              AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                              lCount);
 
                 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
 
@@ -3368,7 +3378,7 @@ AFSParseName( IN PIRP Irp,
 
             ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
 
-            InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3376,7 +3386,7 @@ AFSParseName( IN PIRP Irp,
                           &pDirEntry->NameInformation.FileName,
                           pDirEntry,
                           NULL,
-                          pDirEntry->OpenReferenceCount);
+                          lCount);
 
             try_return( ntStatus = STATUS_SUCCESS);
         }
@@ -3568,7 +3578,7 @@ AFSParseName( IN PIRP Irp,
             uniRemainingPath.Length += sizeof( WCHAR);
             uniRemainingPath.MaximumLength += sizeof( WCHAR);
 
-            InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3576,7 +3586,7 @@ AFSParseName( IN PIRP Irp,
                           &pVolumeCB->DirectoryCB->NameInformation.FileName,
                           pVolumeCB->DirectoryCB,
                           NULL,
-                          pVolumeCB->DirectoryCB->OpenReferenceCount);
+                          lCount = pVolumeCB->DirectoryCB->OpenReferenceCount);
 
             //
             // Pass back the parent being the volume root
@@ -3619,13 +3629,13 @@ AFSParseName( IN PIRP Irp,
         // Increment our reference on the volume
         //
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSParseName Increment2 count on global volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
 try_exit:
 
@@ -3678,6 +3688,7 @@ AFSCheckCellName( IN GUID *AuthGroup,
     AFSDirectoryCB *pDirNode = NULL;
     UNICODE_STRING uniDirName, uniTargetName;
     AFSVolumeCB *pVolumeCB = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -3778,7 +3789,7 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
             *ShareDirEntry = pVolumeCB->DirectoryCB;
 
-            InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3786,18 +3797,20 @@ AFSCheckCellName( IN GUID *AuthGroup,
                           &pVolumeCB->DirectoryCB->NameInformation.FileName,
                           pVolumeCB->DirectoryCB,
                           NULL,
-                          pVolumeCB->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
         }
         else
         {
 
+            lCount = InterlockedIncrement( &pDirHdr->ContentIndex);
+
             pDirNode = AFSInitDirEntry( &AFSGlobalRoot->ObjectInformation,
                                         &uniDirName,
                                         &uniTargetName,
                                         pDirEnumEntry,
-                                        (ULONG)InterlockedIncrement( &pDirHdr->ContentIndex));
+                                        (ULONG)lCount);
 
             if( pDirNode == NULL)
             {
@@ -3882,19 +3895,19 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
             SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
 
-            InterlockedIncrement( &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount);
+            lCount = InterlockedIncrement( &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCheckCellName Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
-                              &pDirNode->NameInformation.FileName,
-                              AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount,
-                              AFSGlobalRoot->ObjectInformation.FileId.Cell,
-                              AFSGlobalRoot->ObjectInformation.FileId.Volume,
-                              AFSGlobalRoot->ObjectInformation.FileId.Vnode,
-                              AFSGlobalRoot->ObjectInformation.FileId.Unique);
+                          &pDirNode->NameInformation.FileName,
+                          lCount,
+                          AFSGlobalRoot->ObjectInformation.FileId.Cell,
+                          AFSGlobalRoot->ObjectInformation.FileId.Volume,
+                          AFSGlobalRoot->ObjectInformation.FileId.Vnode,
+                          AFSGlobalRoot->ObjectInformation.FileId.Unique);
 
-            InterlockedIncrement( &pDirNode->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirNode->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3902,7 +3915,7 @@ AFSCheckCellName( IN GUID *AuthGroup,
                           &pDirNode->NameInformation.FileName,
                           pDirNode,
                           NULL,
-                          pDirNode->OpenReferenceCount);
+                          lCount);
 
             AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
@@ -3939,6 +3952,7 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
     ULONGLONG       ullIndex = 0;
     AFSVolumeCB *pVolumeCB = NULL;
     AFSFileID stTargetFileID;
+    LONG lCount;
 
     __Enter
     {
@@ -4114,14 +4128,14 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
             // deadlock with invalidation
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
 
             AFSAcquireExcl( pVolumeCB->VolumeLock,
                             TRUE);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
         }
 
         if( pVolumeCB->RootFcb == NULL)
@@ -4158,7 +4172,7 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
                       pVolumeCB->ObjectInformation.FileId.Vnode,
                       pVolumeCB->ObjectInformation.FileId.Unique);
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSReleaseResource( pVolumeCB->VolumeLock);
 
@@ -4166,7 +4180,7 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSBuildMountPointTarget Increment count on volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
         *TargetVolumeCB = pVolumeCB;
 
@@ -4194,6 +4208,7 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
     UNICODE_STRING uniDirName, uniTargetName;
     ULONGLONG       ullIndex = 0;
     AFSVolumeCB *pVolumeCB = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -4270,14 +4285,14 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
             // deadlock with invalidation
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
 
             AFSAcquireExcl( pVolumeCB->VolumeLock,
                             TRUE);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
         }
 
 
@@ -4315,7 +4330,7 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
                       pVolumeCB->ObjectInformation.FileId.Vnode,
                       pVolumeCB->ObjectInformation.FileId.Unique);
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSReleaseResource( pVolumeCB->VolumeLock);
 
@@ -4323,7 +4338,7 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSBuildRootVolume Increment count on volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
         *TargetVolumeCB = pVolumeCB;
 
index 7cec196..449dc53 100644 (file)
@@ -1235,6 +1235,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
     ULONG ulIndex = 0;
     BOOLEAN bContinueProcessing = TRUE;
     AFSFileInfoCB stFileInformation;
+    LONG lCount;
 
     __Enter
     {
@@ -1298,7 +1299,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             }
         }
 
-        InterlockedIncrement( &pShareDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pShareDirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -1306,7 +1307,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
                       &pShareDirEntry->NameInformation.FileName,
                       pShareDirEntry,
                       NULL,
-                      pShareDirEntry->OpenReferenceCount);
+                      lCount);
 
         AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
@@ -1394,15 +1395,15 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
         }
 
-        InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSEnumerateConnection Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
-                                                    &pTargetDirEntry->NameInformation.FileName,
-                                                    pTargetDirEntry,
-                                                    NULL,
-                                                    pTargetDirEntry->OpenReferenceCount);
+                      &pTargetDirEntry->NameInformation.FileName,
+                      pTargetDirEntry,
+                      NULL,
+                      lCount);
 
         *CopiedLength = ulCopiedLength;
 
@@ -1412,7 +1413,15 @@ try_exit:
 
         if( pShareDirEntry != NULL)
         {
-            InterlockedDecrement( &pShareDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pShareDirEntry->OpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSEnumerateConnection1 Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pShareDirEntry->NameInformation.FileName,
+                          pShareDirEntry,
+                          NULL,
+                          lCount);
         }
     }
 
index 129b9ac..1074d2b 100644 (file)
@@ -338,6 +338,7 @@ AFSInitVolumeWorker( IN AFSVolumeCB *VolumeCB)
     HANDLE hThread;
     AFSDeviceExt *pControlDeviceExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
     PKSTART_ROUTINE pStartRoutine = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -395,7 +396,9 @@ AFSInitVolumeWorker( IN AFSVolumeCB *VolumeCB)
                                               FALSE,
                                               NULL);
 
-            if( InterlockedIncrement( &pControlDeviceExt->Specific.Control.VolumeWorkerThreadCount) > 0)
+            lCount = InterlockedIncrement( &pControlDeviceExt->Specific.Control.VolumeWorkerThreadCount);
+
+            if( lCount > 0)
             {
 
                 KeClearEvent( &pControlDeviceExt->Specific.Control.VolumeWorkerCloseEvent);
@@ -631,6 +634,7 @@ AFSWorkerThread( IN PVOID Context)
     BOOLEAN freeWorkItem = TRUE;
     BOOLEAN exitThread = FALSE;
     AFSDeviceExt *pLibraryDevExt = NULL;
+    LONG lCount;
 
     pLibraryDevExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
 
@@ -697,7 +701,7 @@ AFSWorkerThread( IN PVOID Context)
 
                         ASSERT( pWorkItem->Specific.Fcb.Fcb->OpenReferenceCount != 0);
 
-                        InterlockedDecrement( &pWorkItem->Specific.Fcb.Fcb->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pWorkItem->Specific.Fcb.Fcb->OpenReferenceCount);
 
                         break;
                     }
@@ -897,6 +901,7 @@ AFSPrimaryVolumeWorkerThread( IN PVOID Context)
     AFSVolumeCB *pVolumeCB = NULL, *pNextVolume = NULL;
     LARGE_INTEGER liCurrentTime;
     BOOLEAN bVolumeObject = FALSE;
+    LONG lCount;
 
     pControlDeviceExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
 
@@ -1547,7 +1552,9 @@ AFSPrimaryVolumeWorkerThread( IN PVOID Context)
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSPrimaryVolumeWorkerThread Exiting\n");
 
-    if( InterlockedDecrement( &pControlDeviceExt->Specific.Control.VolumeWorkerThreadCount) == 0)
+    lCount = InterlockedDecrement( &pControlDeviceExt->Specific.Control.VolumeWorkerThreadCount);
+
+    if( lCount == 0)
     {
 
         KeSetEvent( &pControlDeviceExt->Specific.Control.VolumeWorkerCloseEvent,
@@ -1573,6 +1580,7 @@ AFSVolumeWorkerThread( IN PVOID Context)
     LARGE_INTEGER DueTime;
     LONG TimeOut;
     KTIMER Timer;
+    LONG lCount;
 
     pControlDeviceExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
 
@@ -1641,7 +1649,9 @@ AFSVolumeWorkerThread( IN PVOID Context)
 
     KeCancelTimer( &Timer);
 
-    if( InterlockedDecrement( &pControlDeviceExt->Specific.Control.VolumeWorkerThreadCount) == 0)
+    lCount = InterlockedDecrement( &pControlDeviceExt->Specific.Control.VolumeWorkerThreadCount);
+
+    if( lCount == 0)
     {
 
         KeSetEvent( &pControlDeviceExt->Specific.Control.VolumeWorkerCloseEvent,
@@ -1660,6 +1670,7 @@ AFSInsertWorkitem( IN AFSWorkItem *WorkItem)
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDevExt = NULL;
+    LONG lCount;
 
     pDevExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
 
@@ -1672,11 +1683,13 @@ AFSInsertWorkitem( IN AFSWorkItem *WorkItem)
     AFSAcquireExcl( &pDevExt->Specific.Library.QueueLock,
                     TRUE);
 
+    lCount = InterlockedIncrement( &pDevExt->Specific.Library.QueueItemCount);
+
     AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSInsertWorkitem Inserting work item %08lX Count %08lX\n",
                   WorkItem,
-                  InterlockedIncrement( &pDevExt->Specific.Library.QueueItemCount));
+                  lCount);
 
     if( pDevExt->Specific.Library.QueueTail != NULL) // queue already has nodes
     {
@@ -1708,6 +1721,7 @@ AFSInsertIOWorkitem( IN AFSWorkItem *WorkItem)
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDevExt = NULL;
+    LONG lCount;
 
     pDevExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
 
@@ -1720,11 +1734,13 @@ AFSInsertIOWorkitem( IN AFSWorkItem *WorkItem)
     AFSAcquireExcl( &pDevExt->Specific.Library.IOQueueLock,
                     TRUE);
 
+    lCount = InterlockedIncrement( &pDevExt->Specific.Library.IOQueueItemCount);
+
     AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSInsertWorkitem Inserting IO work item %08lX Count %08lX\n",
                   WorkItem,
-                  InterlockedIncrement( &pDevExt->Specific.Library.IOQueueItemCount));
+                  lCount);
 
     if( pDevExt->Specific.Library.IOQueueTail != NULL) // queue already has nodes
     {
@@ -1756,6 +1772,7 @@ AFSInsertWorkitemAtHead( IN AFSWorkItem *WorkItem)
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDevExt = NULL;
+    LONG lCount;
 
     pDevExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
 
@@ -1772,11 +1789,13 @@ AFSInsertWorkitemAtHead( IN AFSWorkItem *WorkItem)
 
     pDevExt->Specific.Library.QueueHead = WorkItem;
 
+    lCount = InterlockedIncrement( &pDevExt->Specific.Library.QueueItemCount);
+
     AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSInsertWorkitemAtHead Inserting work item %08lX Count %08lX\n",
                   WorkItem,
-                  InterlockedIncrement( &pDevExt->Specific.Library.QueueItemCount));
+                  lCount);
 
     //
     // indicate that the queue has nodes
@@ -1798,6 +1817,7 @@ AFSRemoveWorkItem()
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSWorkItem        *pWorkItem = NULL;
     AFSDeviceExt *pDevExt = NULL;
+    LONG lCount;
 
     pDevExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
 
@@ -1815,11 +1835,13 @@ AFSRemoveWorkItem()
 
         pWorkItem = pDevExt->Specific.Library.QueueHead;
 
+        lCount = InterlockedDecrement( &pDevExt->Specific.Library.QueueItemCount);
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSRemoveWorkItem Removing work item %08lX Count %08lX Thread %08lX\n",
                       pWorkItem,
-                      InterlockedDecrement( &pDevExt->Specific.Library.QueueItemCount),
+                      lCount,
                       PsGetCurrentThreadId());
 
         pDevExt->Specific.Library.QueueHead = pDevExt->Specific.Library.QueueHead->next;
@@ -1849,6 +1871,7 @@ AFSRemoveIOWorkItem()
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSWorkItem        *pWorkItem = NULL;
     AFSDeviceExt *pDevExt = NULL;
+    LONG lCount;
 
     pDevExt = (AFSDeviceExt *)AFSLibraryDeviceObject->DeviceExtension;
 
@@ -1866,11 +1889,13 @@ AFSRemoveIOWorkItem()
 
         pWorkItem = pDevExt->Specific.Library.IOQueueHead;
 
+        lCount = InterlockedDecrement( &pDevExt->Specific.Library.IOQueueItemCount);
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSRemoveWorkItem Removing work item %08lX Count %08lX Thread %08lX\n",
                       pWorkItem,
-                      InterlockedDecrement( &pDevExt->Specific.Library.IOQueueItemCount),
+                      lCount,
                       PsGetCurrentThreadId());
 
         pDevExt->Specific.Library.IOQueueHead = pDevExt->Specific.Library.IOQueueHead->next;
@@ -1994,6 +2019,7 @@ AFSQueueFlushExtents( IN AFSFcb *Fcb,
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pRDRDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSWorkItem *pWorkItem = NULL;
+    LONG lCount;
 
     __try
     {
@@ -2011,7 +2037,9 @@ AFSQueueFlushExtents( IN AFSFcb *Fcb,
         // queue down. We'll decrement it just below.
         //
 
-        if( InterlockedIncrement( &Fcb->Specific.File.QueuedFlushCount) > 3)
+        lCount = InterlockedIncrement( &Fcb->Specific.File.QueuedFlushCount);
+
+        if( lCount > 3)
         {
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
@@ -2068,13 +2096,13 @@ AFSQueueFlushExtents( IN AFSFcb *Fcb,
 
         pWorkItem->Specific.Fcb.Fcb = Fcb;
 
-        InterlockedIncrement( &Fcb->OpenReferenceCount);
+        lCount = InterlockedIncrement( &Fcb->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSQueueFlushExtents Increment count on Fcb %08lX Cnt %d\n",
-                                                    Fcb,
-                                                    Fcb->OpenReferenceCount);
+                      Fcb,
+                      lCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_WORKER_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -2102,7 +2130,9 @@ try_exit:
         // Remove the count we added above
         //
 
-        if( InterlockedDecrement( &Fcb->Specific.File.QueuedFlushCount) == 0)
+        lCount = InterlockedDecrement( &Fcb->Specific.File.QueuedFlushCount);
+
+        if( lCount == 0)
         {
 
             KeSetEvent( &Fcb->NPFcb->Specific.File.QueuedFlushEvent,
@@ -2116,7 +2146,7 @@ try_exit:
             if( pWorkItem != NULL)
             {
 
-                InterlockedDecrement( &Fcb->OpenReferenceCount);
+                lCount = InterlockedDecrement( &Fcb->OpenReferenceCount);
 
                 ExFreePoolWithTag( pWorkItem, AFS_WORK_ITEM_TAG);
             }