Windows: RefCounts, Asserts, and Trace Logging
authorJeffrey Altman <jaltman@your-file-system.com>
Mon, 26 Nov 2012 16:25:43 +0000 (11:25 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 29 Nov 2012 23:57:37 +0000 (15:57 -0800)
Rename DirectoryCB.OpenReferenceCount to DirOpenReferenceCount
to distinguish it from the FCB.OpenReferenceCount.  This makes
it easier to search for instances within an editor or debugger.

Ensure that all InterlockedIncrement and InterlockedDecrement
calls on a reference count field assign their value to a local
'lCount' variable.  Ensure that 'lCount' is used within any
trace log messages and conditionals.

Add ASSERT( lCount >= 0) after all reference count decrements
in order to catch underflows.

Change conditionals from (RefCount == 0) to (RefCount <= 0) so
that object destruction can occur when there has been an underflow.
This is important in release builds for which ASSERT() is a no-op.

Change-Id: I1d10076464c68745ede117eef2f728f70a0003c1
Reviewed-on: http://gerrit.openafs.org/8522
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

12 files changed:
src/WINNT/afsrdr/kernel/lib/AFSClose.cpp
src/WINNT/afsrdr/kernel/lib/AFSCommSupport.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/AFSNameSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSNetworkProviderSupport.cpp
src/WINNT/afsrdr/kernel/lib/AFSWorker.cpp
src/WINNT/afsrdr/kernel/lib/Include/AFSStructs.h

index 983e6d3..07d578a 100644 (file)
@@ -63,6 +63,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
     AFSCcb *pCcb = NULL;
     AFSObjectInfoCB *pObjectInfo = NULL;
     AFSDirectoryCB *pDirCB = NULL;
+    LONG lCount;
 
     __try
     {
@@ -167,9 +168,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                     ntStatus = STATUS_SUCCESS;
                 }
 
-                ASSERT( pDirCB->OpenReferenceCount > 0);
-
-                InterlockedDecrement( &pDirCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -177,7 +176,9 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                               &pDirCB->NameInformation.FileName,
                               pDirCB,
                               pCcb,
-                              pDirCB->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 //
                 // If this is not the root then decrement the open child reference count
@@ -198,15 +199,15 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 AFSReleaseResource( &pFcb->NPFcb->Resource);
 
-                ASSERT( pFcb->OpenReferenceCount != 0);
-
-                InterlockedDecrement( &pFcb->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSClose (IOCtl) Decrement count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 break;
             }
@@ -248,9 +249,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                     ntStatus = STATUS_SUCCESS;
                 }
 
-                ASSERT( pDirCB->OpenReferenceCount > 0);
-
-                InterlockedDecrement( &pDirCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -258,19 +257,21 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                               &pDirCB->NameInformation.FileName,
                               pDirCB,
                               pCcb,
-                              pDirCB->OpenReferenceCount);
+                              lCount);
 
-                AFSReleaseResource( &pFcb->NPFcb->Resource);
+                ASSERT( lCount >= 0);
 
-                ASSERT( pFcb->OpenReferenceCount > 0);
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
 
-                InterlockedDecrement( &pFcb->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSClose (RootAll) Decrement count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 break;
             }
@@ -426,19 +427,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                     AFSAcquireExcl( pObjectInfo->VolumeCB->ObjectInfoTree.TreeLock,
                                     TRUE);
 
-                    if ( pDirCB->OpenReferenceCount == 0)
-                    {
-                        AFSDbgLogMsg( 0,
-                                      0,
-                                      "AFSClose (Other) OpenReferenceCount is Zero on DE %08lX Ccb %08lX FileName %wZ\n",
-                                      pDirCB,
-                                      pCcb,
-                                      &pDirCB->NameInformation.FileName);
-                    }
-
-                    ASSERT( pDirCB->OpenReferenceCount > 0);
-
-                    InterlockedDecrement( &pDirCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -446,9 +435,11 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                                   &pDirCB->NameInformation.FileName,
                                   pDirCB,
                                   pCcb,
-                                  pDirCB->OpenReferenceCount);
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
 
-                    if( pDirCB->OpenReferenceCount == 0)
+                    if( lCount == 0)
                     {
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
@@ -500,9 +491,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 else
                 {
 
-                    ASSERT( pDirCB->OpenReferenceCount > 0);
-
-                    InterlockedDecrement( &pDirCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -510,7 +499,9 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                                   &pDirCB->NameInformation.FileName,
                                   pDirCB,
                                   pCcb,
-                                  pDirCB->OpenReferenceCount);
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
                 }
 
                 //
@@ -535,15 +526,15 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 // Decrement the reference count on the Fcb. this is protecting it from teardown.
                 //
 
-                ASSERT( pFcb->OpenReferenceCount != 0);
-
-                InterlockedDecrement( &pFcb->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSClose Decrement count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 break;
             }
@@ -553,6 +544,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
 
                 AFSPipeOpenCloseRequestCB stPipeClose;
 
+                pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
+
                 AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSClose Acquiring Special Share lock %08lX EXCL %08lX\n",
@@ -562,10 +555,6 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                 AFSAcquireExcl( &pFcb->NPFcb->Resource,
                                 TRUE);
 
-                pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
-
-                pDirCB = pCcb->DirectoryCB;
-
                 RtlZeroMemory( &stPipeClose,
                                sizeof( AFSPipeOpenCloseRequestCB));
 
@@ -589,6 +578,8 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                                    NULL);
                 */
 
+                pDirCB = pCcb->DirectoryCB;
+
                 //
                 // Remove the Ccb and de-allocate it
                 //
@@ -610,9 +601,7 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                     ntStatus = STATUS_SUCCESS;
                 }
 
-                ASSERT( pDirCB->OpenReferenceCount > 0);
-
-                InterlockedDecrement( &pDirCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -620,7 +609,9 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                               &pDirCB->NameInformation.FileName,
                               pDirCB,
                               pCcb,
-                              pDirCB->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 //
                 // If this is not the root then decrement the open child reference count
@@ -630,26 +621,26 @@ AFSClose( IN PDEVICE_OBJECT LibDeviceObject,
                     pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount > 0)
                 {
 
-                    InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+                    lCount = InterlockedDecrement( &pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSClose (Share) Decrement child open ref count on Parent object %08lX Cnt %d\n",
                                   pObjectInfo->ParentObjectInformation,
-                                  pObjectInfo->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+                                  lCount);
                 }
 
                 AFSReleaseResource( &pFcb->NPFcb->Resource);
 
-                ASSERT( pFcb->OpenReferenceCount != 0);
-
-                InterlockedDecrement( &pFcb->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pFcb->OpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FCB_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSClose (Share) Decrement count on Fcb %08lX Cnt %d\n",
                               pFcb,
-                              pFcb->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 break;
             }
index 90f9444..356a379 100644 (file)
@@ -332,7 +332,7 @@ AFSEnumerateDirectory( IN GUID *AuthGroup,
                         // Need to tear down this entry and rebuild it below
                         //
 
-                        if( pDirNode->OpenReferenceCount == 0)
+                        if( pDirNode->DirOpenReferenceCount <= 0)
                         {
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1145,7 +1145,7 @@ AFSVerifyDirectoryContent( IN AFSObjectInfoCB *ObjectInfoCB,
                     // Need to tear down this entry and rebuild it below
                     //
 
-                    if( pDirNode->OpenReferenceCount == 0)
+                    if( pDirNode->DirOpenReferenceCount <= 0)
                     {
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1523,6 +1523,7 @@ AFSNotifyFileCreate( IN GUID            *AuthGroup,
     UNICODE_STRING uniTargetName;
     AFSDirectoryCB *pDirNode = NULL;
     ULONG     ulCRC = 0;
+    LONG       lCount;
     LARGE_INTEGER liOldDataVersion;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
 
@@ -1641,14 +1642,16 @@ AFSNotifyFileCreate( IN GUID            *AuthGroup,
                                     &pResultCB->DirEnum.FileId))
                 {
 
-                    InterlockedIncrement( &pDirNode->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSNotifyFileCreate Increment count on %wZ DE %p Cnt %d\n",
                                   &pDirNode->NameInformation.FileName,
                                   pDirNode,
-                                  pDirNode->OpenReferenceCount);
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
 
                     *DirNode = pDirNode;
 
@@ -1678,7 +1681,7 @@ AFSNotifyFileCreate( IN GUID            *AuthGroup,
                                   pResultCB->DirEnum.FileId.Vnode,
                                   pResultCB->DirEnum.FileId.Unique);
 
-                    if( pDirNode->OpenReferenceCount == 0)
+                    if( pDirNode->DirOpenReferenceCount <= 0)
                     {
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -2086,6 +2089,7 @@ AFSNotifyHardLink( IN AFSObjectInfoCB *ObjectInfo,
     ULONG     ulCRC = 0;
     BOOLEAN bReleaseParentLock = FALSE, bReleaseTargetParentLock = FALSE;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -2228,14 +2232,16 @@ AFSNotifyHardLink( IN AFSObjectInfoCB *ObjectInfo,
                                     &pResultCB->DirEnum.FileId))
                 {
 
-                    InterlockedIncrement( &pDirNode->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSNotifyHardLink Increment count on %wZ DE %p Cnt %d\n",
                                   &pDirNode->NameInformation.FileName,
                                   pDirNode,
-                                  pDirNode->OpenReferenceCount);
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
 
                     AFSReleaseResource( TargetParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
 
@@ -2263,7 +2269,7 @@ AFSNotifyHardLink( IN AFSObjectInfoCB *ObjectInfo,
                                   pResultCB->DirEnum.FileId.Vnode,
                                   pResultCB->DirEnum.FileId.Unique);
 
-                    if( pDirNode->OpenReferenceCount == 0)
+                    if( pDirNode->DirOpenReferenceCount <= 0)
                     {
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
index 2a42f18..0fbf686 100644 (file)
@@ -367,7 +367,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               "AFSCommonCreate Failed to open root Status %08lX\n",
                               ntStatus);
 
-                lCount = InterlockedDecrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -376,6 +376,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               AFSGlobalRoot->DirectoryCB,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             try_return( ntStatus);
@@ -571,7 +573,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 // Perform in this order to prevent thrashing
                 //
 
-                lCount = InterlockedIncrement( &pParentDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pParentDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -613,7 +615,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 //
                 // It is now safe to drop the Reference Count
                 //
-                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -622,6 +624,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               pDirectoryCB,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             if( !NT_SUCCESS( ntStatus))
@@ -637,7 +641,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 // Decrement the reference on the parent
                 //
 
-                lCount = InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -646,6 +650,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               pParentDirectoryCB,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             try_return( ntStatus);
@@ -706,7 +712,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   &pDirectoryCB->NameInformation.FileName,
                                   ntStatus);
 
-                    lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -715,6 +721,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   pDirectoryCB,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
                 else
                 {
@@ -724,7 +732,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   "AFSCommonCreate Object name collision on create Status %08lX\n",
                                   ntStatus);
 
-                    InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -732,7 +740,9 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   &pParentDirectoryCB->NameInformation.FileName,
                                   pParentDirectoryCB,
                                   NULL,
-                                  pParentDirectoryCB->OpenReferenceCount);
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
                 }
 
                 try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
@@ -767,7 +777,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
             // Dereference the parent entry
             //
 
-            lCount = InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -777,6 +787,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                           NULL,
                           lCount);
 
+            ASSERT( lCount >= 0);
+
             try_return( ntStatus);
         }
 
@@ -834,7 +846,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                 if( pDirectoryCB != NULL)
                 {
 
-                    lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -843,11 +855,13 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   pDirectoryCB,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
                 else
                 {
 
-                    lCount = InterlockedDecrement( &pParentDirectoryCB->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirectoryCB->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -856,6 +870,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                                   pParentDirectoryCB,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
             }
 
@@ -881,7 +897,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               "AFSCommonCreate (%08lX) Attempt to open root as delete on close\n",
                               Irp);
 
-                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -891,6 +907,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               NULL,
                               lCount);
 
+                ASSERT( lCount >= 0);
+
                 try_return( ntStatus = STATUS_CANNOT_DELETE);
             }
 
@@ -906,7 +924,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               "AFSCommonCreate (%08lX) Attempt to open root as target directory\n",
                               Irp);
 
-                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -916,6 +934,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               NULL,
                               lCount);
 
+                ASSERT( lCount >= 0);
+
                 try_return( ntStatus = STATUS_INVALID_PARAMETER);
             }
 
@@ -939,7 +959,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               pVolumeCB->ObjectInformation.FileId.Volume,
                               ntStatus);
 
-                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -948,6 +968,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               pDirectoryCB,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             try_return( ntStatus);
@@ -995,7 +1017,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               &pDirectoryCB->NameInformation.FileName,
                               ntStatus);
 
-                lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1004,6 +1026,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                               pDirectoryCB,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             try_return( ntStatus);
@@ -1030,7 +1054,7 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                           &pDirectoryCB->NameInformation.FileName,
                           ntStatus);
 
-            lCount = InterlockedDecrement( &pDirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -1039,6 +1063,8 @@ AFSCommonCreate( IN PDEVICE_OBJECT DeviceObject,
                           pDirectoryCB,
                           NULL,
                           lCount);
+
+            ASSERT( lCount >= 0);
         }
 
 try_exit:
@@ -1095,9 +1121,9 @@ try_exit:
                               &pCcb->DirectoryCB->NameInformation.FileName,
                               pCcb->DirectoryCB,
                               pCcb,
-                              pCcb->DirectoryCB->OpenReferenceCount);
+                              lCount = pCcb->DirectoryCB->DirOpenReferenceCount);
 
-                ASSERT( pCcb->DirectoryCB->OpenReferenceCount > 0);
+                ASSERT( lCount >= 0);
 
                 pCcb->CurrentDirIndex = 0;
 
@@ -2141,7 +2167,7 @@ try_exit:
                 // Decrement the reference added during initialization of the DE
                 //
 
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -2150,6 +2176,8 @@ try_exit:
                               pDirEntry,
                               lCount);
 
+                ASSERT( lCount >= 0);
+
                 //
                 // Pull the directory entry from the parent
                 //
@@ -3552,7 +3580,7 @@ AFSOpenIOCtlFcb( IN PIRP Irp,
         // Reference the directory entry
         //
 
-        lCount = InterlockedIncrement( &((*Ccb)->DirectoryCB->OpenReferenceCount));
+        lCount = InterlockedIncrement( &((*Ccb)->DirectoryCB->DirOpenReferenceCount));
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -3607,7 +3635,7 @@ try_exit:
         // is already referenced
         //
 
-        lCount = InterlockedDecrement( &ParentDirCB->OpenReferenceCount);
+        lCount = InterlockedDecrement( &ParentDirCB->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -3617,6 +3645,8 @@ try_exit:
                       NULL,
                       lCount);
 
+        ASSERT( lCount >= 0);
+
         //
         // If we created the Fcb we need to release the resources
         //
index 88b25f4..2ac140e 100644 (file)
@@ -661,7 +661,17 @@ AFSQueryDirectory( IN PIRP Irp)
                      BooleanFlagOn( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED))
             {
 
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSQueryDirectory Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              pCcb,
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 continue;
             }
@@ -685,7 +695,17 @@ AFSQueryDirectory( IN PIRP Irp)
                     if( !FlagOn( pObjectInfo->FileAttributes, FILE_ATTRIBUTE_DIRECTORY))
                     {
 
-                        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                      AFS_TRACE_LEVEL_VERBOSE,
+                                      "AFSQueryDirectory Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                      &pDirEntry->NameInformation.FileName,
+                                      pDirEntry,
+                                      pCcb,
+                                      lCount);
+
+                        ASSERT( lCount >= 0);
 
                         continue;
                     }
@@ -706,7 +726,17 @@ AFSQueryDirectory( IN PIRP Irp)
                                                       NULL))
                         {
 
-                            lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                            lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSQueryDirectory Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                          &pDirEntry->NameInformation.FileName,
+                                          pDirEntry,
+                                          pCcb,
+                                          lCount);
+
+                            ASSERT( lCount >= 0);
 
                             continue;
                         }
@@ -728,7 +758,17 @@ AFSQueryDirectory( IN PIRP Irp)
                                                          TRUE))
                             {
 
-                                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                              AFS_TRACE_LEVEL_VERBOSE,
+                                              "AFSQueryDirectory Decrement4 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                              &pDirEntry->NameInformation.FileName,
+                                              pDirEntry,
+                                              pCcb,
+                                              lCount);
+
+                                ASSERT( lCount >= 0);
 
                                 continue;
                             }
@@ -776,7 +816,17 @@ AFSQueryDirectory( IN PIRP Irp)
 
                 pCcb->CurrentDirIndex--;
 
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSQueryDirectory Decrement5 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              pCcb,
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 try_return( ntStatus = STATUS_SUCCESS);
             }
@@ -952,7 +1002,17 @@ AFSQueryDirectory( IN PIRP Irp)
                                   Irp,
                                   FileInformationClass);
 
-                    lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSQueryDirectory Decrement6 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  &pDirEntry->NameInformation.FileName,
+                                  pDirEntry,
+                                  pCcb,
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
 
                     try_return( ntStatus = STATUS_INVALID_INFO_CLASS);
 
@@ -980,12 +1040,32 @@ AFSQueryDirectory( IN PIRP Irp)
             if( ulBytesConverted < pDirEntry->NameInformation.FileName.Length)
             {
 
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSQueryDirectory Decrement7 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              pCcb,
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 try_return( ntStatus = STATUS_BUFFER_OVERFLOW);
             }
 
-            lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSQueryDirectory Decrement8 count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pDirEntry->NameInformation.FileName,
+                          pDirEntry,
+                          pCcb,
+                          lCount);
+
+            ASSERT( lCount >= 0);
 
             dStatus = STATUS_SUCCESS;
 
@@ -1157,7 +1237,17 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
                 if( pDirEntry != NULL)
                 {
 
-                    lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSLocateNextDirEntry Increment count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  &pDirEntry->NameInformation.FileName,
+                                  pDirEntry,
+                                  Ccb,
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
                 }
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1189,7 +1279,17 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
             if( pDirEntry != NULL)
             {
 
-                lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLocateNextDirEntry Increment2 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              Ccb,
+                              lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1213,7 +1313,17 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
             if( pDirEntry != NULL)
             {
 
-                lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLocateNextDirEntry Increment3 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              Ccb,
+                              lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -1287,7 +1397,17 @@ AFSLocateNextDirEntry( IN AFSObjectInfoCB *ObjectInfo,
                                       ObjectInfo->FileId.Vnode,
                                       ObjectInfo->FileId.Unique);
 
-                        lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                      AFS_TRACE_LEVEL_VERBOSE,
+                                      "AFSLocateNextDirEntry Increment4 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                      &pDirEntry->NameInformation.FileName,
+                                      pDirEntry,
+                                      Ccb,
+                                      lCount);
+
+                        ASSERT( lCount >= 0);
                     }
                     else
                     {
index 3862c61..74b328f 100644 (file)
@@ -1324,6 +1324,12 @@ AFSProcessSetFileExtents( IN AFSSetFileExtentsCB *SetExtents )
                           PsGetCurrentThread());
 
             lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSProcessSetFileExtents Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
         }
 
         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -1349,6 +1355,12 @@ AFSProcessSetFileExtents( IN AFSSetFileExtentsCB *SetExtents )
 
         lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSProcessSetFileExtents Decrement count on volume %08lX Cnt %d\n",
+                      pVolumeCB,
+                      lCount);
+
         //
         // Now locate the Object in this volume
         //
@@ -1727,6 +1739,12 @@ AFSFindFcbToClean(ULONG IgnoreTime, AFSFcb *LastFcb, BOOLEAN Block)
 
         lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSFindFcbToClean Increment count on volume %08lX Cnt %d\n",
+                      pVolumeCB,
+                      lCount);
+
         AFSReleaseResource( &pRDRDeviceExt->Specific.RDR.VolumeListLock);
 
         bReleaseVolumeListLock = FALSE;
@@ -1736,6 +1754,12 @@ AFSFindFcbToClean(ULONG IgnoreTime, AFSFcb *LastFcb, BOOLEAN Block)
 
         lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSFindFcbToClean Decrement count on volume %08lX Cnt %d\n",
+                      pVolumeCB,
+                      lCount);
+
         if( NULL == LastFcb)
         {
 
@@ -1951,6 +1975,12 @@ AFSProcessExtentFailure( PIRP Irp)
                           PsGetCurrentThread());
 
             lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSProcessExtentFailure Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
         }
 
         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -1972,6 +2002,11 @@ AFSProcessExtentFailure( PIRP Irp)
 
         lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSProcessExtentFailure Decrement count on volume %08lX Cnt %d\n",
+                      pVolumeCB,
+                      lCount);
         //
         // Now locate the Object in this volume
         //
@@ -2190,6 +2225,12 @@ AFSProcessReleaseFileExtents( IN PIRP Irp)
                               PsGetCurrentThread());
 
                 lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessReleaseFileExtents Increment count on volume %08lX Cnt %d\n",
+                              pVolumeCB,
+                              lCount);
             }
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -2211,6 +2252,12 @@ AFSProcessReleaseFileExtents( IN PIRP Irp)
 
             lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSProcessReleaseFileExtents Decrement count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
+
             //
             // Now locate the Object in this volume
             //
index b3dee29..8389376 100644 (file)
@@ -437,6 +437,12 @@ AFSInitVolume( IN GUID *AuthGroup,
 
                 lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSInitVolume Increment count on volume %08lX Cnt %d\n",
+                              pVolumeCB,
+                              lCount);
+
                 AFSReleaseResource( pDeviceExt->Specific.RDR.VolumeTree.TreeLock);
 
                 AFSReleaseResource( &pDeviceExt->Specific.RDR.VolumeListLock);
index ab13757..6ee14cd 100644 (file)
@@ -2391,7 +2391,17 @@ AFSSetFileLinkInfo( IN PIRP Irp)
 
             ASSERT( pTargetParentObject == pTargetDirEntry->ObjectInformation->ParentObjectInformation);
 
-            lCount = InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetDirEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetFileLinkInfo Increment count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pTargetDirEntry->NameInformation.FileName,
+                          pTargetDirEntry,
+                          pSrcCcb,
+                          lCount);
+
+            ASSERT( lCount >= 0);
 
             if( !pFileLinkInfo->ReplaceIfExists)
             {
@@ -2405,12 +2415,12 @@ AFSSetFileLinkInfo( IN PIRP Irp)
                 try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
             }
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_ERROR,
                           "AFSSetFileLinkInfo Target %wZ exists DE %p Count %08lX, performing delete of target\n",
                           &pTargetDirEntry->NameInformation.FileName,
                           pTargetDirEntry,
-                          pTargetDirEntry->OpenReferenceCount);
+                          pTargetDirEntry->DirOpenReferenceCount);
 
             //
             // Pull the directory entry from the parent
@@ -2497,7 +2507,17 @@ AFSSetFileLinkInfo( IN PIRP Irp)
         if( pTargetDirEntry != NULL)
         {
 
-            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetFileLinkInfo Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pTargetDirEntry->NameInformation.FileName,
+                          pTargetDirEntry,
+                          pSrcCcb,
+                          lCount);
+
+            ASSERT( lCount >= 0);
         }
 
         if( bReleaseTargetDirLock)
@@ -2780,7 +2800,18 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( pTargetParentObject == pTargetDirEntry->ObjectInformation->ParentObjectInformation);
 
-            lCount = InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetDirEntry->DirOpenReferenceCount);
+
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetRenameInfo Increment count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pTargetDirEntry->NameInformation.FileName,
+                          pTargetDirEntry,
+                          pSrcCcb,
+                          lCount);
+
+            ASSERT( lCount >= 0);
 
             if( !bReplaceIfExists)
             {
@@ -2794,12 +2825,12 @@ AFSSetRenameInfo( IN PIRP Irp)
                 try_return( ntStatus = STATUS_OBJECT_NAME_COLLISION);
             }
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_ERROR,
                           "AFSSetRenameInfo Target %wZ exists DE %p Count %08lX, performing delete of target\n",
                           &pTargetDirEntry->NameInformation.FileName,
                           pTargetDirEntry,
-                          pTargetDirEntry->OpenReferenceCount);
+                          pTargetDirEntry->DirOpenReferenceCount);
 
             //
             // Pull the directory entry from the parent
@@ -3084,7 +3115,7 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             if( pTargetDirEntry->ObjectInformation->FileType == AFS_FILE_TYPE_FILE &&
                 pTargetDirEntry->ObjectInformation->Fcb != NULL &&
-                pTargetDirEntry->OpenReferenceCount > 1)
+                pTargetDirEntry->DirOpenReferenceCount > 1)
             {
 
                 pTargetFcb = pTargetDirEntry->ObjectInformation->Fcb;
@@ -3109,9 +3140,19 @@ AFSSetRenameInfo( IN PIRP Irp)
                 AFSReleaseResource( &pTargetFcb->NPFcb->Resource);
             }
 
-            ASSERT( pTargetDirEntry->OpenReferenceCount > 0);
+            ASSERT( pTargetDirEntry->DirOpenReferenceCount > 0);
+
+            lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount); // The count we added above
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetRenameInfo Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pTargetDirEntry->NameInformation.FileName,
+                          pTargetDirEntry,
+                          pSrcCcb,
+                          lCount);
 
-            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount); // The count we added above
+            ASSERT( lCount >= 0);
 
             if( lCount == 0)
             {
@@ -3145,7 +3186,17 @@ try_exit:
         if( pTargetDirEntry != NULL)
         {
 
-            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetRenameInfo Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pTargetDirEntry->NameInformation.FileName,
+                          pTargetDirEntry,
+                          pSrcCcb,
+                          lCount);
+
+            ASSERT( lCount >= 0);
         }
 
         if( bReleaseTargetDirLock)
index 26670a7..a3556c4 100644 (file)
@@ -2649,6 +2649,12 @@ AFSInvalidateAllVolumes( VOID)
                       PsGetCurrentThread());
 
         lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSInvalidateAllVolumes Increment count on volume %08lX Cnt %d\n",
+                      pVolumeCB,
+                      lCount);
     }
 
     while( pVolumeCB != NULL)
@@ -2660,6 +2666,12 @@ AFSInvalidateAllVolumes( VOID)
         {
 
             lCount = InterlockedIncrement( &pNextVolumeCB->VolumeReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSInvalidateAllVolumes Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
         }
 
         AFSReleaseResource( &pRDRDeviceExt->Specific.RDR.VolumeListLock);
@@ -2673,6 +2685,12 @@ AFSInvalidateAllVolumes( VOID)
 
         lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSInvalidateAllVolumes Decrement count on volume %08lX Cnt %d\n",
+                      pVolumeCB,
+                      lCount);
+
         pVolumeCB = pNextVolumeCB;
     }
 
@@ -3219,6 +3237,12 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
 
             lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetVolumeState Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
+
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
 
             //
@@ -3314,6 +3338,12 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
             AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
 
             lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetVolumeState Decrement count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
         }
         else
         {
@@ -3442,7 +3472,7 @@ AFSValidateDirectoryCache( IN AFSObjectInfoCB *ObjectInfo,
                 //
 
                 if( BooleanFlagOn( pCurrentDirEntry->Flags, AFS_DIR_ENTRY_DELETED) &&
-                    pCurrentDirEntry->OpenReferenceCount == 0)
+                    pCurrentDirEntry->DirOpenReferenceCount <= 0)
                 {
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -3463,7 +3493,7 @@ AFSValidateDirectoryCache( IN AFSObjectInfoCB *ObjectInfo,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSValidateDirectoryCache Clear VALID flag on DE %p Reference count %08lX\n",
                                   pCurrentDirEntry,
-                                  pCurrentDirEntry->OpenReferenceCount);
+                                  pCurrentDirEntry->DirOpenReferenceCount);
 
                     //
                     // We pull the short name from the parent tree since it could change below
@@ -3569,9 +3599,9 @@ AFSValidateDirectoryCache( IN AFSObjectInfoCB *ObjectInfo,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSValidateDirectoryCache Processing INVALID DE %p Reference count %08lX\n",
                           pCurrentDirEntry,
-                          pCurrentDirEntry->OpenReferenceCount);
+                          pCurrentDirEntry->DirOpenReferenceCount);
 
-            if( pCurrentDirEntry->OpenReferenceCount == 0)
+            if( pCurrentDirEntry->DirOpenReferenceCount <= 0)
             {
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -4636,7 +4666,7 @@ AFSResetDirectoryContent( IN AFSObjectInfoCB *ObjectInfoCB)
 
             pNextDirEntry = (AFSDirectoryCB *)pCurrentDirEntry->ListEntry.fLink;
 
-            if( pCurrentDirEntry->OpenReferenceCount == 0)
+            if( pCurrentDirEntry->DirOpenReferenceCount <= 0)
             {
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
@@ -5009,7 +5039,7 @@ AFSInitNameArray( IN AFSDirectoryCB *DirectoryCB,
 
             pNameArray->LinkCount = 0;
 
-            lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -5096,7 +5126,7 @@ AFSPopulateNameArray( IN AFSNameArrayHdr *NameArray,
 
         pCurrentElement->DirectoryCB = DirectoryCB->ObjectInformation->VolumeCB->DirectoryCB;
 
-        lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -5214,7 +5244,7 @@ AFSPopulateNameArrayFromRelatedArray( IN AFSNameArrayHdr *NameArray,
                 SetFlag( pCurrentElement->Flags, AFS_NAME_ARRAY_FLAG_ROOT_ELEMENT);
             }
 
-            lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -5281,7 +5311,7 @@ AFSFreeNameArray( IN AFSNameArrayHdr *NameArray)
 
             pCurrentElement = &NameArray->ElementArray[ lElement];
 
-            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -5289,6 +5319,8 @@ AFSFreeNameArray( IN AFSNameArrayHdr *NameArray)
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
                           lCount);
+
+            ASSERT( lCount >= 0);
         }
 
         AFSExFreePoolWithTag( NameArray, AFS_NAME_ARRAY_TAG);
@@ -5364,7 +5396,7 @@ AFSInsertNextElement( IN AFSNameArrayHdr *NameArray,
 
         lCount = InterlockedIncrement( &NameArray->Count);
 
-        lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedIncrement( &DirectoryCB->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -5373,6 +5405,8 @@ AFSInsertNextElement( IN AFSNameArrayHdr *NameArray,
                       DirectoryCB,
                       lCount);
 
+        ASSERT( lCount >= 2);
+
         pCurrentElement->DirectoryCB = DirectoryCB;
 
         pCurrentElement->Component = DirectoryCB->NameInformation.FileName;
@@ -5436,7 +5470,7 @@ AFSBackupEntry( IN AFSNameArrayHdr *NameArray)
             try_return( pCurrentElement);
         }
 
-        lCount = InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -5445,6 +5479,8 @@ AFSBackupEntry( IN AFSNameArrayHdr *NameArray)
                       NameArray->CurrentEntry->DirectoryCB,
                       lCount);
 
+        ASSERT( lCount >= 0);
+
         NameArray->CurrentEntry->DirectoryCB = NULL;
 
         lCount = InterlockedDecrement( &NameArray->Count);
@@ -5592,7 +5628,7 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
 
             pCurrentElement = &NameArray->ElementArray[ lElement];
 
-            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -5600,6 +5636,8 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
                           lCount);
+
+            ASSERT( lCount >= 0);
         }
 
         RtlZeroMemory( NameArray,
@@ -5619,7 +5657,7 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
 
             NameArray->LinkCount = 0;
 
-            lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -6213,7 +6251,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                       pVolumeCB,
                       lCount);
 
-        lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentDirEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6260,7 +6298,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                 if( pDirectoryEntry != NULL)
                 {
 
-                    lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6269,11 +6307,13 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                                   pDirectoryEntry,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
                 else
                 {
 
-                    lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6282,6 +6322,8 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                                   pParentDirEntry,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
             }
 
@@ -6337,7 +6379,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
         // Remove the reference made above
         //
 
-        lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pDirectoryEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6347,6 +6389,8 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                       NULL,
                       lCount);
 
+        ASSERT( lCount >= 0);
+
 try_exit:
 
         if( pDirEntry != NULL)
@@ -6871,7 +6915,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                       pVolumeCB,
                       lCount);
 
-        lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentDirEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6918,7 +6962,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                 if( pDirectoryEntry != NULL)
                 {
 
-                    lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6927,19 +6971,23 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                                   pDirectoryEntry,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
                 else
                 {
 
-                    lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
-                                  "AFSEvaluateRootEntry Decrement1 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                  "AFSEvaluateRootEntry Decrement2 count on %wZ DE %p Ccb %p Cnt %d\n",
                                   &pParentDirEntry->NameInformation.FileName,
                                   pParentDirEntry,
                                   NULL,
                                   lCount);
+
+                    ASSERT( lCount >= 0);
                 }
             }
 
@@ -6969,7 +7017,7 @@ try_exit:
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSEvaluateRootEntry2 Decrement count on volume %08lX Cnt %d\n",
+                          "AFSEvaluateRootEntry Decrement2 count on volume %08lX Cnt %d\n",
                           pVolumeCB,
                           lCount);
         }
@@ -7919,6 +7967,12 @@ AFSInitializeLibrary( IN AFSLibraryInitCB *LibraryInit)
 
             lCount = InterlockedDecrement( &AFSGlobalRoot->VolumeReferenceCount);
 
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSInitializeLibrary Increment count on volume %08lX Cnt %d\n",
+                          AFSGlobalRoot,
+                          lCount);
+
             AFSReleaseResource( AFSGlobalRoot->VolumeLock);
 
             try_return( ntStatus);
@@ -7947,6 +8001,12 @@ AFSInitializeLibrary( IN AFSLibraryInitCB *LibraryInit)
 
         lCount = InterlockedDecrement( &AFSGlobalRoot->VolumeReferenceCount);
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSInitializeLibrary Decrement count on volume %08lX Cnt %d\n",
+                      AFSGlobalRoot,
+                      lCount);
+
         AFSReleaseResource( AFSGlobalRoot->VolumeLock);
 
         AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Fcb->Header.Resource);
@@ -8129,6 +8189,12 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                 lCount = AFSObjectInfoIncrement( pObjectInfo);
 
                 lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
+                              pVolumeCB,
+                              lCount);
             }
             else
             {
@@ -8140,7 +8206,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
+                              "AFSGetObjectStatus Decrement2 count on volume %08lX Cnt %d\n",
                               pVolumeCB,
                               lCount);
 
@@ -8237,11 +8303,11 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSGetObjectStatus Increment count on volume %08lX Cnt %d\n",
+                          "AFSGetObjectStatus Increment2 count on volume %08lX Cnt %d\n",
                           pVolumeCB,
                           lCount);
 
-            lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pParentDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -8281,7 +8347,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
-                                      "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
+                                      "AFSGetObjectStatus Decrement3 count on volume %08lX Cnt %d\n",
                                       pVolumeCB,
                                       lCount);
                     }
@@ -8289,7 +8355,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                     if( pDirectoryEntry != NULL)
                     {
 
-                        lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirectoryEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -8298,11 +8364,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                                       pDirectoryEntry,
                                       NULL,
                                       lCount);
+
+                        ASSERT( lCount >= 0);
                     }
                     else
                     {
 
-                        lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -8311,6 +8379,8 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                                       pParentDirEntry,
                                       NULL,
                                       lCount);
+
+                        ASSERT( lCount >= 0);
                     }
                 }
 
@@ -8323,7 +8393,17 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             // Remove the reference made above
             //
 
-            lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirectoryEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSGetObjectStatus Decrement3 count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pDirectoryEntry->NameInformation.FileName,
+                          pDirectoryEntry,
+                          NULL,
+                          lCount);
+
+            ASSERT( lCount >= 0);
 
             pObjectInfo = pDirectoryEntry->ObjectInformation;
 
@@ -8336,9 +8416,9 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSRetrieveFileAttributes Decrement2 count on volume %08lX Cnt %d\n",
+                              "AFSGetObjectStatus Decrement4 count on volume %08lX Cnt %d\n",
                               pVolumeCB,
-                              pVolumeCB->VolumeReferenceCount);
+                              lCount);
             }
         }
 
@@ -8480,7 +8560,17 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
 
         if( pDirEntry != NULL)
         {
-            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSCheckSymlinkAccess Increment count on %wZ DE %p Ccb %p Cnt %d\n",
+                          &pDirEntry->NameInformation.FileName,
+                          pDirEntry,
+                          NULL,
+                          lCount);
+
+            ASSERT( lCount >= 0);
         }
 
         AFSReleaseResource( ParentDirectoryCB->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -8508,7 +8598,17 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
 
         ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
 
-        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSCheckSymlinkAccess Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                      &pDirEntry->NameInformation.FileName,
+                      pDirEntry,
+                      NULL,
+                      lCount);
+
+        ASSERT( lCount >= 0);
 
 try_exit:
 
index 0f22bba..f924c5a 100644 (file)
@@ -121,11 +121,13 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
         uniSearchName.Length = uniSearchName.MaximumLength = 0;
         uniSearchName.Buffer = NULL;
 
-        ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
-
         while( TRUE)
         {
 
+            ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
+
+            ASSERT( pDirEntry->DirOpenReferenceCount > 0);
+
             //
             // Check our total link count for this name array
             //
@@ -561,7 +563,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Dereference the current entry ..
                         //
 
-                        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -571,6 +573,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       NULL,
                                       lCount);
 
+                        ASSERT( lCount >= 0);
+
                         //
                         // OK, need to back up one entry for the correct parent since the current
                         // entry we are on is the symlink itself
@@ -582,7 +586,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Increment our reference on this dir entry
                         //
 
-                        lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -762,7 +766,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Dereference our current dir entry
                         //
 
-                        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -772,13 +776,15 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       NULL,
                                       lCount);
 
+                        ASSERT( lCount >= 0);
+
                         pDirEntry = pCurrentVolume->DirectoryCB;
 
                         //
                         // Reference the new dir entry
                         //
 
-                        lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -874,7 +880,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSLocateNameEntry Decrement2 count on volume %08lX Cnt %d\n",
                                   pCurrentVolume,
-                                  pCurrentVolume->VolumeReferenceCount);
+                                  lCount);
 
                     ntStatus = AFSBuildMountPointTarget( AuthGroup,
                                                          pDirEntry,
@@ -910,7 +916,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Deref and ref count the entries
                     //
 
-                    lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -920,9 +926,11 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   NULL,
                                   lCount);
 
+                    ASSERT( lCount >= 0);
+
                     pDirEntry = pCurrentVolume->DirectoryCB;
 
-                    lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -1225,7 +1233,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 //
                 // Need to back up one entry in the name array
                 //
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1235,6 +1243,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               NULL,
                               lCount);
 
+                ASSERT( lCount >= 0);
+
                 pDirEntry = AFSBackupEntry( NameArray);
 
                 if( pDirEntry == NULL)
@@ -1247,7 +1257,15 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     try_return(ntStatus = STATUS_OBJECT_PATH_INVALID);
                 }
 
-                lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLocateNameEntry Increment4 count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              NULL,
+                              lCount);
 
                 if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_ROOT_VOLUME))
                 {
@@ -1262,14 +1280,6 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     ASSERT( pParentDirEntry != pDirEntry);
                 }
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
-                              AFS_TRACE_LEVEL_VERBOSE,
-                              "AFSLocateNameEntry Increment4 count on %wZ DE %p Ccb %p Cnt %d\n",
-                              &pDirEntry->NameInformation.FileName,
-                              pDirEntry,
-                              NULL,
-                              pDirEntry->OpenReferenceCount);
-
                 uniPathName = uniRemainingPath;
 
                 continue;
@@ -1522,7 +1532,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                             // Increment our dir entry ref count since we will decrement it on exit
                             //
 
-                            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                           AFS_TRACE_LEVEL_VERBOSE,
@@ -1609,7 +1619,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our dir entry ref count
                     //
 
-                    lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -1659,9 +1669,19 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 AFSAcquireExcl( pCurrentObject->VolumeCB->ObjectInfoTree.TreeLock,
                                 TRUE);
 
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSLocateNameEntry Decrement count on %wZ DE %p Ccb %p Cnt %d\n",
+                              &pDirEntry->NameInformation.FileName,
+                              pDirEntry,
+                              NULL,
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
-                if( lCount == 0)
+                if( lCount <= 0)
                 {
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING|AFS_SUBSYSTEM_CLEANUP_PROCESSING,
@@ -1774,7 +1794,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
             // Decrement the previous parent
             //
 
-            lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -1784,6 +1804,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                           NULL,
                           lCount);
 
+            ASSERT( lCount >= 0);
+
             //
             // If we ended up substituting a name in the component then update
             // the full path and update the pointers
@@ -1925,7 +1947,7 @@ try_exit:
             if( pDirEntry != NULL)
             {
 
-                lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1934,11 +1956,13 @@ try_exit:
                               pDirEntry,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
             else if( pParentDirEntry != NULL)
             {
 
-                lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1947,6 +1971,8 @@ try_exit:
                               pParentDirEntry,
                               NULL,
                               lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             if( bReleaseCurrentVolume)
@@ -1981,7 +2007,7 @@ try_exit:
                               &(*ParentDirectoryCB)->NameInformation.FileName,
                               *ParentDirectoryCB,
                               NULL,
-                              (*ParentDirectoryCB)->OpenReferenceCount);
+                              (*ParentDirectoryCB)->DirOpenReferenceCount);
             }
 
             if( *DirectoryCB != NULL)
@@ -1993,7 +2019,7 @@ try_exit:
                               &(*DirectoryCB)->NameInformation.FileName,
                               *DirectoryCB,
                               NULL,
-                              (*DirectoryCB)->OpenReferenceCount);
+                              (*DirectoryCB)->DirOpenReferenceCount);
             }
         }
 
@@ -2140,7 +2166,7 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                 AFSDeleteDirEntry( ParentObjectInfo,
                                    pDirNode);
 
-                lCount = InterlockedIncrement( &pExistingDirNode->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pExistingDirNode->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -2162,7 +2188,7 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                 // Need to tear down this entry and rebuild it below
                 //
 
-                if( pExistingDirNode->OpenReferenceCount == 0)
+                if( pExistingDirNode->DirOpenReferenceCount <= 0)
                 {
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -2226,7 +2252,7 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                                 pDirNode,
                                 TRUE);
 
-        lCount = InterlockedIncrement( &pDirNode->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -2433,16 +2459,19 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
     __Enter
     {
 
-        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSDeleteDirEntry Deleting dir entry in parent %08lX Entry %08lX %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                      "AFSDeleteDirEntry Deleting dir entry in parent %08lX Entry %08lX %wZ FID %08lX-%08lX-%08lX-%08lX RefCount %08lX\n",
                       ParentObjectInfo,
                       DirEntry,
                       &DirEntry->NameInformation.FileName,
                       DirEntry->ObjectInformation->FileId.Cell,
                       DirEntry->ObjectInformation->FileId.Volume,
                       DirEntry->ObjectInformation->FileId.Vnode,
-                      DirEntry->ObjectInformation->FileId.Unique);
+                      DirEntry->ObjectInformation->FileId.Unique,
+                      DirEntry->DirOpenReferenceCount);
+
+        ASSERT( DirEntry->DirOpenReferenceCount == 0);
 
         AFSRemoveDirNodeFromParent( ParentObjectInfo,
                                     DirEntry,
@@ -3029,7 +3058,7 @@ AFSParseName( IN PIRP Irp,
 
             *ParentDirectoryCB = pDirEntry;
 
-            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3279,7 +3308,7 @@ AFSParseName( IN PIRP Irp,
                           "AFSParseName (%08lX) Returning global root access\n",
                           Irp);
 
-            lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3358,7 +3387,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Returning global root access\n",
                               Irp);
 
-                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -3401,7 +3430,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Returning root PIOCtl access\n",
                               Irp);
 
-                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -3464,7 +3493,7 @@ AFSParseName( IN PIRP Irp,
 
             ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
 
-            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3715,7 +3744,7 @@ AFSParseName( IN PIRP Irp,
             uniRemainingPath.Length += sizeof( WCHAR);
             uniRemainingPath.MaximumLength += sizeof( WCHAR);
 
-            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3723,7 +3752,7 @@ AFSParseName( IN PIRP Irp,
                           &pVolumeCB->DirectoryCB->NameInformation.FileName,
                           pVolumeCB->DirectoryCB,
                           NULL,
-                          lCount = pVolumeCB->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             //
             // Pass back the parent being the volume root
@@ -3771,7 +3800,7 @@ try_exit:
                               &(*ParentDirectoryCB)->NameInformation.FileName,
                               *ParentDirectoryCB,
                               NULL,
-                              (*ParentDirectoryCB)->OpenReferenceCount);
+                              (*ParentDirectoryCB)->DirOpenReferenceCount);
             }
         }
 
@@ -3919,7 +3948,7 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
             *ShareDirEntry = pVolumeCB->DirectoryCB;
 
-            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3930,6 +3959,12 @@ AFSCheckCellName( IN GUID *AuthGroup,
                           lCount);
 
             lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSCheckCellName Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
         }
         else
         {
@@ -4037,7 +4072,7 @@ AFSCheckCellName( IN GUID *AuthGroup,
                           AFSGlobalRoot->ObjectInformation.FileId.Vnode,
                           AFSGlobalRoot->ObjectInformation.FileId.Unique);
 
-            lCount = InterlockedIncrement( &pDirNode->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -4290,6 +4325,12 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
 
                 lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSBuildMountPoint Decrement count on volume %08lX Cnt %d\n",
+                              pVolumeCB,
+                              lCount);
+
                 AFSReleaseResource( pVolumeCB->VolumeLock);
 
                 try_return( ntStatus);
@@ -4396,7 +4437,7 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
             //
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                          AFS_TRACE_LEVEL_VERBOSE_2,
+                         AFS_TRACE_LEVEL_VERBOSE_2,
                           "AFSBuildRootVolume Initializing root for FID %08lX-%08lX-%08lX-%08lX\n",
                           FileId->Cell,
                           FileId->Volume,
@@ -4465,6 +4506,12 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
 
                 lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSBuildRootVolume Decrement count on volume %08lX Cnt %d\n",
+                              pVolumeCB,
+                              lCount);
+
                 AFSReleaseResource( pVolumeCB->VolumeLock);
 
                 try_return( ntStatus);
index 1b27fc7..94126af 100644 (file)
@@ -1299,7 +1299,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             }
         }
 
-        lCount = InterlockedIncrement( &pShareDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pShareDirEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -1395,7 +1395,7 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
             pDirEntry = (AFSDirectoryCB *)pDirEntry->ListEntry.fLink;
         }
 
-        lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pTargetDirEntry->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -1405,6 +1405,8 @@ AFSEnumerateConnection( IN OUT AFSNetworkProviderConnectionCB *ConnectCB,
                       NULL,
                       lCount);
 
+        ASSERT( lCount >= 0);
+
         *CopiedLength = ulCopiedLength;
 
         AFSReleaseResource( pTargetDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -1413,7 +1415,7 @@ try_exit:
 
         if( pShareDirEntry != NULL)
         {
-            lCount = InterlockedDecrement( &pShareDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pShareDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -1422,6 +1424,8 @@ try_exit:
                           pShareDirEntry,
                           NULL,
                           lCount);
+
+            ASSERT( lCount >= 0);
         }
     }
 
index fa8d080..639da47 100644 (file)
@@ -1080,7 +1080,7 @@ AFSPrimaryVolumeWorkerThread( IN PVOID Context)
                                   TRUE);
 
                 if( pVolumeCB->ObjectInfoListHead == NULL &&
-                    pVolumeCB->DirectoryCB->OpenReferenceCount == 0 &&
+                    pVolumeCB->DirectoryCB->DirOpenReferenceCount <= 0 &&
                     pVolumeCB->VolumeReferenceCount == 1 &&
                     ( pVolumeCB->RootFcb == NULL ||
                       pVolumeCB->RootFcb->OpenReferenceCount == 0) &&
@@ -1275,7 +1275,7 @@ AFSPrimaryVolumeWorkerThread( IN PVOID Context)
                         while( pCurrentDirEntry != NULL)
                         {
 
-                            if( pCurrentDirEntry->OpenReferenceCount > 0 ||
+                            if( pCurrentDirEntry->DirOpenReferenceCount > 0 ||
                                 ( pCurrentDirEntry->ObjectInformation->Fcb != NULL &&
                                   pCurrentDirEntry->ObjectInformation->Fcb->OpenReferenceCount > 0) ||
                                 liCurrentTime.QuadPart <= pCurrentDirEntry->ObjectInformation->LastAccessCount.QuadPart ||
@@ -1340,7 +1340,7 @@ AFSPrimaryVolumeWorkerThread( IN PVOID Context)
                                 while( pCurrentDirEntry != NULL)
                                 {
 
-                                    if( pCurrentDirEntry->OpenReferenceCount > 0 ||
+                                    if( pCurrentDirEntry->DirOpenReferenceCount > 0 ||
                                         ( pCurrentDirEntry->ObjectInformation->Fcb != NULL &&
                                           pCurrentDirEntry->ObjectInformation->Fcb->OpenReferenceCount > 0) ||
                                         liCurrentTime.QuadPart <= pCurrentDirEntry->ObjectInformation->LastAccessCount.QuadPart ||
@@ -1383,7 +1383,7 @@ AFSPrimaryVolumeWorkerThread( IN PVOID Context)
 
                                     pFcb = NULL;
 
-                                    AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
+                                    AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING | AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                                   AFS_TRACE_LEVEL_VERBOSE,
                                                   "AFSPrimaryVolumeWorkerThread Deleting DE %wZ Object %08lX\n",
                                                   &pCurrentDirEntry->NameInformation.FileName,
index 8e98b31..4214208 100644 (file)
@@ -431,7 +431,7 @@ typedef struct _AFS_DIRECTORY_CB
     // for tear down
     //
 
-    LONG             OpenReferenceCount;
+    LONG             DirOpenReferenceCount;
 
     //
     // File index used in directory enumerations