Windows: Performing async work after cache invalidation
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSGeneric.cpp
index f47bec2..ca071ed 100644 (file)
@@ -643,6 +643,7 @@ AFSInitializeGlobalDirectoryEntries()
     AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSObjectInfoCB *pObjectInfoCB = NULL;
     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -665,13 +666,13 @@ AFSInitializeGlobalDirectoryEntries()
             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
 
-        InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInitializeGlobalDirectoryEntries Increment count on object %08lX Cnt %d\n",
                       pObjectInfoCB,
-                      pObjectInfoCB->ObjectReferenceCount);
+                      lCount);
 
         ntStatus = STATUS_SUCCESS;
 
@@ -772,13 +773,13 @@ AFSInitializeGlobalDirectoryEntries()
             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
 
-        InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInitializeGlobalDirectoryEntries Increment count on object %08lX Cnt %d\n",
                       pObjectInfoCB,
-                      pObjectInfoCB->ObjectReferenceCount);
+                      lCount);
 
         ntStatus = STATUS_SUCCESS;
 
@@ -912,6 +913,7 @@ AFSInitDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
     BOOLEAN bAllocatedObjectCB = FALSE;
     ULONGLONG ullIndex = 0;
     AFSNonPagedDirectoryCB *pNonPagedDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -968,13 +970,13 @@ AFSInitDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
                           FileName);
         }
 
-        InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
+        lCount = InterlockedIncrement( &pObjectInfoCB->ObjectReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInitDirEntry Increment count on object %08lX Cnt %d\n",
                       pObjectInfoCB,
-                      pObjectInfoCB->ObjectReferenceCount);
+                      lCount);
 
         AFSReleaseResource( ParentObjectInfo->VolumeCB->ObjectInfoTree.TreeLock);
 
@@ -1194,13 +1196,13 @@ try_exit:
             if( pObjectInfoCB != NULL)
             {
 
-                InterlockedDecrement( &pObjectInfoCB->ObjectReferenceCount);
+                lCount = InterlockedDecrement( &pObjectInfoCB->ObjectReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSInitDirEntry Decrement count on object %08lX Cnt %d\n",
                               pObjectInfoCB,
-                              pObjectInfoCB->ObjectReferenceCount);
+                              lCount);
 
                 if( bAllocatedObjectCB)
                 {
@@ -1565,6 +1567,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
     AFSObjectInfoCB *pObjectInfo = NULL;
     IO_STATUS_BLOCK stIoStatus;
     ULONG ulFilter = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -1598,13 +1601,13 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
         if( pVolumeCB != NULL)
         {
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInvalidateCache Increment count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -1635,7 +1638,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
                                             FILE_NOTIFY_CHANGE_SIZE,
                                             FILE_ACTION_MODIFIED);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             try_return( ntStatus);
         }
@@ -1643,7 +1646,7 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
         AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                           TRUE);
 
-        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -1664,13 +1667,13 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
             // Reference the node so it won't be torn down
             //
 
-            InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInvalidateCache Increment count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
 
         AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -1796,7 +1799,9 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
                                   pObjectInfo->ParentObjectInformation->FileId.Unique);
 
                     SetFlag( pObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
+
                     pObjectInfo->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
+
                     pObjectInfo->ParentObjectInformation->Expiration.QuadPart = 0;
                 }
 
@@ -1814,19 +1819,10 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
                                                 ulFilter,
                                                 FILE_ACTION_REMOVED);
 
-                if( pObjectInfo->FileType == AFS_FILE_TYPE_FILE &&
-                    pObjectInfo->Fcb != NULL)
+                if( NT_SUCCESS( AFSQueueInvalidateObject( pObjectInfo,
+                                                          InvalidateCB->Reason)))
                 {
-
-
-                    //
-                    // Clear out the extents
-                    // And get rid of them (note this involves waiting
-                    // for any writes or reads to the cache to complete)
-                    //
-
-                    (VOID) AFSTearDownFcbExtents( pObjectInfo->Fcb,
-                                                  NULL);
+                    pObjectInfo = NULL; // We'll dec the count in the worker item
                 }
 
                 break;
@@ -1964,6 +1960,13 @@ AFSInvalidateCache( IN AFSInvalidateCacheCB *InvalidateCB)
 
                 SetFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
 
+                if( InvalidateCB->Reason == AFS_INVALIDATE_DATA_VERSION &&
+                    NT_SUCCESS( AFSQueueInvalidateObject( pObjectInfo,
+                                                          InvalidateCB->Reason)))
+                {
+                    pObjectInfo = NULL; // We'll dec the count in the worker item
+                }
+
                 break;
             }
         }
@@ -1973,13 +1976,13 @@ try_exit:
         if( pObjectInfo != NULL)
         {
 
-            InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInvalidateCache Decrement count on object %08lX Cnt %d\n",
                           pObjectInfo,
-                          pObjectInfo->ObjectReferenceCount);
+                          lCount);
         }
     }
 
@@ -3042,6 +3045,7 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
     AFSVolumeCB *pVolumeCB = NULL;
     AFSFcb *pFcb = NULL;
     AFSObjectInfoCB *pCurrentObject = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -3078,7 +3082,7 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
         if( pVolumeCB != NULL)
         {
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
 
@@ -3174,7 +3178,7 @@ AFSSetVolumeState( IN AFSVolumeStatusCB *VolumeStatus)
 
             AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
         }
         else
         {
@@ -4837,6 +4841,7 @@ AFSInitNameArray( IN AFSDirectoryCB *DirectoryCB,
 
     AFSNameArrayHdr *pNameArray = NULL;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -4873,16 +4878,16 @@ AFSInitNameArray( IN AFSDirectoryCB *DirectoryCB,
 
             pNameArray->CurrentEntry = &pNameArray->ElementArray[ 0];
 
-            InterlockedIncrement( &pNameArray->Count);
+            lCount = InterlockedIncrement( &pNameArray->Count);
 
-            InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInitNameArray Increment count on %wZ DE %p Cnt %d\n",
                           &DirectoryCB->NameInformation.FileName,
                           DirectoryCB,
-                          DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             pNameArray->CurrentEntry->DirectoryCB = DirectoryCB;
 
@@ -4912,6 +4917,7 @@ AFSPopulateNameArray( IN AFSNameArrayHdr *NameArray,
     ULONG  ulTotalCount = 0;
     ULONG ulIndex = 0;
     USHORT usLength = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -4930,14 +4936,14 @@ AFSPopulateNameArray( IN AFSNameArrayHdr *NameArray,
 
         pCurrentElement->DirectoryCB = DirectoryCB->ObjectInformation->VolumeCB->DirectoryCB;
 
-        InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSPopulateNameArray Increment count on volume %wZ DE %p Cnt %d\n",
                       &pCurrentElement->DirectoryCB->NameInformation.FileName,
                       pCurrentElement->DirectoryCB,
-                      pCurrentElement->DirectoryCB->OpenReferenceCount);
+                      lCount);
 
         pCurrentElement->Component = DirectoryCB->ObjectInformation->VolumeCB->DirectoryCB->NameInformation.FileName;
 
@@ -4977,6 +4983,7 @@ AFSPopulateNameArrayFromRelatedArray( IN AFSNameArrayHdr *NameArray,
     ULONG  ulTotalCount = 0;
     ULONG ulIndex = 0;
     USHORT usLength = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -5006,16 +5013,16 @@ AFSPopulateNameArrayFromRelatedArray( IN AFSNameArrayHdr *NameArray,
 
             pCurrentElement->FileId    = pCurrentElement->DirectoryCB->ObjectInformation->FileId;
 
-            InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSPopulateNameArrayFromRelatedArray Increment count on %wZ DE %p Cnt %d\n",
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
-                          pCurrentElement->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
-            InterlockedIncrement( &NameArray->Count);
+            lCount = InterlockedIncrement( &NameArray->Count);
 
             if( pCurrentElement->DirectoryCB == DirectoryCB ||
                 NameArray->Count == RelatedNameArray->Count)
@@ -5048,6 +5055,7 @@ AFSFreeNameArray( IN AFSNameArrayHdr *NameArray)
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSNameArrayCB *pCurrentElement = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -5063,14 +5071,14 @@ AFSFreeNameArray( IN AFSNameArrayHdr *NameArray)
                 break;
             }
 
-            InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSFreeNameArray Decrement count on %wZ DE %p Cnt %d\n",
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
-                          pCurrentElement->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             pCurrentElement++;
         }
@@ -5088,6 +5096,7 @@ AFSInsertNextElement( IN AFSNameArrayHdr *NameArray,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -5115,16 +5124,16 @@ AFSInsertNextElement( IN AFSNameArrayHdr *NameArray,
             NameArray->CurrentEntry = &NameArray->ElementArray[ 0];
         }
 
-        InterlockedIncrement( &NameArray->Count);
+        lCount = InterlockedIncrement( &NameArray->Count);
 
-        InterlockedIncrement( &DirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &DirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSInsertNextElement Increment count on %wZ DE %p Cnt %d\n",
                       &DirEntry->NameInformation.FileName,
                       DirEntry,
-                      DirEntry->OpenReferenceCount);
+                      lCount);
 
         NameArray->CurrentEntry->DirectoryCB = DirEntry;
 
@@ -5144,26 +5153,27 @@ void
 AFSReplaceCurrentElement( IN AFSNameArrayHdr *NameArray,
                           IN AFSDirectoryCB *DirectoryCB)
 {
+    LONG lCount;
 
     ASSERT( NameArray->CurrentEntry != NULL);
 
-    InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+    lCount = InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSReplaceCurrentElement Decrement count on %wZ DE %p Cnt %d\n",
                   &NameArray->CurrentEntry->DirectoryCB->NameInformation.FileName,
                   NameArray->CurrentEntry->DirectoryCB,
-                  NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+                  lCount);
 
-    InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
+    lCount = InterlockedIncrement( &DirectoryCB->OpenReferenceCount);
 
     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                   AFS_TRACE_LEVEL_VERBOSE,
                   "AFSReplaceCurrentElement Increment count on %wZ DE %p Cnt %d\n",
                   &DirectoryCB->NameInformation.FileName,
                   DirectoryCB,
-                  DirectoryCB->OpenReferenceCount);
+                  lCount);
 
     NameArray->CurrentEntry->DirectoryCB = DirectoryCB;
 
@@ -5185,6 +5195,7 @@ AFSBackupEntry( IN AFSNameArrayHdr *NameArray)
 {
 
     AFSDirectoryCB *pCurrentDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -5194,18 +5205,20 @@ AFSBackupEntry( IN AFSNameArrayHdr *NameArray)
             try_return( pCurrentDirEntry);
         }
 
-        InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+        lCount = InterlockedDecrement( &NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSBackupEntry Decrement count on %wZ DE %p Cnt %d\n",
                       &NameArray->CurrentEntry->DirectoryCB->NameInformation.FileName,
                       NameArray->CurrentEntry->DirectoryCB,
-                      NameArray->CurrentEntry->DirectoryCB->OpenReferenceCount);
+                      lCount);
 
         NameArray->CurrentEntry->DirectoryCB = NULL;
 
-        if( InterlockedDecrement( &NameArray->Count) == 0)
+        lCount = InterlockedDecrement( &NameArray->Count);
+
+        if( lCount == 0)
         {
             NameArray->CurrentEntry = NULL;
         }
@@ -5259,6 +5272,7 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
 
     AFSNameArrayCB *pCurrentElement = NULL;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *) AFSRDRDeviceObject->DeviceExtension;
+    LONG lCount;
 
     __Enter
     {
@@ -5274,14 +5288,14 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
                 break;
             }
 
-            InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pCurrentElement->DirectoryCB->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSResetNameArray Decrement count on %wZ DE %p Cnt %d\n",
                           &pCurrentElement->DirectoryCB->NameInformation.FileName,
                           pCurrentElement->DirectoryCB,
-                          pCurrentElement->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             pCurrentElement++;
         }
@@ -5297,16 +5311,16 @@ AFSResetNameArray( IN AFSNameArrayHdr *NameArray,
 
             NameArray->CurrentEntry = &NameArray->ElementArray[ 0];
 
-            InterlockedIncrement( &NameArray->Count);
+            lCount = InterlockedIncrement( &NameArray->Count);
 
-            InterlockedIncrement( &DirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &DirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSResetNameArray Increment count on %wZ DE %p Cnt %d\n",
                           &DirEntry->NameInformation.FileName,
                           DirEntry,
-                          DirEntry->OpenReferenceCount);
+                          lCount);
 
             NameArray->CurrentEntry->DirectoryCB = DirEntry;
 
@@ -5350,6 +5364,7 @@ AFSDumpNameArray( IN AFSNameArrayHdr *NameArray)
 void
 AFSSetEnumerationEvent( IN AFSFcb *Fcb)
 {
+    LONG lCount;
 
     //
     // Depending on the type of node, set the event
@@ -5365,7 +5380,7 @@ AFSSetEnumerationEvent( IN AFSFcb *Fcb)
                         0,
                         FALSE);
 
-            InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+            lCount = InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
 
             break;
         }
@@ -5378,7 +5393,7 @@ AFSSetEnumerationEvent( IN AFSFcb *Fcb)
                         0,
                         FALSE);
 
-            InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+            lCount = InterlockedIncrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
 
             break;
         }
@@ -5391,6 +5406,8 @@ void
 AFSClearEnumerationEvent( IN AFSFcb *Fcb)
 {
 
+    LONG lCount;
+
     //
     // Depending on the type of node, set the event
     //
@@ -5403,7 +5420,9 @@ AFSClearEnumerationEvent( IN AFSFcb *Fcb)
 
             ASSERT( Fcb->NPFcb->Specific.Directory.DirectoryEnumCount > 0);
 
-            if( InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount) == 0)
+            lCount = InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+
+            if( lCount == 0)
             {
 
                 KeClearEvent( &Fcb->NPFcb->Specific.Directory.DirectoryEnumEvent);
@@ -5418,7 +5437,9 @@ AFSClearEnumerationEvent( IN AFSFcb *Fcb)
 
             ASSERT( Fcb->NPFcb->Specific.Directory.DirectoryEnumCount > 0);
 
-            if( InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount) == 0)
+            lCount = InterlockedDecrement( &Fcb->NPFcb->Specific.Directory.DirectoryEnumCount);
+
+            if( lCount == 0)
             {
 
                 KeClearEvent( &Fcb->NPFcb->Specific.Directory.DirectoryEnumEvent);
@@ -5630,6 +5651,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
     WCHAR *pwchBuffer = NULL;
     UNICODE_STRING uniComponentName, uniRemainingPath, uniParsedName;
     ULONG ulNameDifference = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -5658,7 +5680,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                 if( pDirEntry != NULL)
                 {
 
-                    ntStatus = STATUS_ACCESS_DENIED;
+                    ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
                 }
 
                 try_return( ntStatus);
@@ -5877,15 +5899,15 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
         // Increment the ref count on the volume and dir entry for correct processing below
         //
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSRetrieveFileAttributes Increment count on volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -5893,7 +5915,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                       &pParentDirEntry->NameInformation.FileName,
                       pParentDirEntry,
                       NULL,
-                      pParentDirEntry->OpenReferenceCount);
+                      lCount);
 
         ntStatus = AFSLocateNameEntry( NULL,
                                        NULL,
@@ -5920,19 +5942,19 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                 if( pVolumeCB != NULL)
                 {
 
-                    InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                    lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSRetrieveFileAttributes Decrement count on volume %08lX Cnt %d\n",
                                   pVolumeCB,
-                                  pVolumeCB->VolumeReferenceCount);
+                                  lCount);
                 }
 
                 if( pDirectoryEntry != NULL)
                 {
 
-                    InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -5940,12 +5962,12 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                                   &pDirectoryEntry->NameInformation.FileName,
                                   pDirectoryEntry,
                                   NULL,
-                                  pDirectoryEntry->OpenReferenceCount);
+                                  lCount);
                 }
                 else
                 {
 
-                    InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -5953,7 +5975,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                                   &pParentDirEntry->NameInformation.FileName,
                                   pParentDirEntry,
                                   NULL,
-                                  pParentDirEntry->OpenReferenceCount);
+                                  lCount);
                 }
             }
 
@@ -6009,7 +6031,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
         // Remove the reference made above
         //
 
-        InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6017,7 +6039,7 @@ AFSRetrieveFileAttributes( IN AFSDirectoryCB *ParentDirectoryCB,
                       &pDirectoryEntry->NameInformation.FileName,
                       pDirectoryEntry,
                       NULL,
-                      pDirectoryEntry->OpenReferenceCount);
+                      lCount);
 
 try_exit:
 
@@ -6030,13 +6052,13 @@ try_exit:
         if( pVolumeCB != NULL)
         {
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSRetrieveFileAttributes Decrement2 count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         if( pNameArray != NULL)
@@ -6077,6 +6099,7 @@ AFSAllocateObjectInfo( IN AFSObjectInfoCB *ParentObjectInfo,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSObjectInfoCB *pObjectInfo = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -6116,7 +6139,7 @@ AFSAllocateObjectInfo( IN AFSObjectInfoCB *ParentObjectInfo,
 
         if( ParentObjectInfo != NULL)
         {
-            InterlockedIncrement( &ParentObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &ParentObjectInfo->ObjectReferenceCount);
         }
 
         //
@@ -6187,6 +6210,7 @@ AFSDeleteObjectInfo( IN AFSObjectInfoCB *ObjectInfo)
 {
 
     BOOLEAN bAcquiredTreeLock = FALSE;
+    LONG lCount;
 
     if( !ExIsResourceAcquiredExclusiveLite( ObjectInfo->VolumeCB->ObjectInfoTree.TreeLock))
     {
@@ -6250,7 +6274,8 @@ AFSDeleteObjectInfo( IN AFSObjectInfoCB *ObjectInfo)
 
     if( ObjectInfo->ParentObjectInformation != NULL)
     {
-        InterlockedDecrement( &ObjectInfo->ParentObjectInformation->ObjectReferenceCount);
+
+        lCount = InterlockedDecrement( &ObjectInfo->ParentObjectInformation->ObjectReferenceCount);
     }
 
     if( bAcquiredTreeLock)
@@ -6293,6 +6318,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
     UNICODE_STRING uniComponentName, uniRemainingPath, uniParsedName;
     ULONG ulNameDifference = 0;
     GUID    stAuthGroup;
+    LONG lCount;
 
     __Enter
     {
@@ -6331,7 +6357,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                 if( pDirEntry != NULL)
                 {
 
-                    ntStatus = STATUS_ACCESS_DENIED;
+                    ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
                 }
 
                 try_return( ntStatus);
@@ -6446,15 +6472,15 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
 
         pParentDirEntry = AFSGlobalRoot->DirectoryCB;
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSEvaluateRootEntry Increment count on volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
-        InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
@@ -6462,7 +6488,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                       &pParentDirEntry->NameInformation.FileName,
                       pParentDirEntry,
                       NULL,
-                      pParentDirEntry->OpenReferenceCount);
+                      lCount);
 
         ntStatus = AFSLocateNameEntry( NULL,
                                        NULL,
@@ -6489,19 +6515,19 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                 if( pVolumeCB != NULL)
                 {
 
-                    InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                    lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSEvaluateRootEntry Decrement count on volume %08lX Cnt %d\n",
                                   pVolumeCB,
-                                  pVolumeCB->VolumeReferenceCount);
+                                  lCount);
                 }
 
                 if( pDirectoryEntry != NULL)
                 {
 
-                    InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6509,12 +6535,12 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                                   &pDirectoryEntry->NameInformation.FileName,
                                   pDirectoryEntry,
                                   NULL,
-                                  pDirectoryEntry->OpenReferenceCount);
+                                  lCount);
                 }
                 else
                 {
 
-                    InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -6522,7 +6548,7 @@ AFSEvaluateRootEntry( IN AFSDirectoryCB *DirectoryCB,
                                   &pParentDirEntry->NameInformation.FileName,
                                   pParentDirEntry,
                                   NULL,
-                                  pParentDirEntry->OpenReferenceCount);
+                                  lCount);
                 }
             }
 
@@ -6548,13 +6574,13 @@ try_exit:
         if( pVolumeCB != NULL)
         {
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSEvaluateRootEntry2 Decrement count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
         }
 
         if( pNameArray != NULL)
@@ -7404,10 +7430,9 @@ AFSInitializeLibrary( IN AFSLibraryInitCB *LibraryInit)
         ulTimeIncrement = KeQueryTimeIncrement();
 
         pControlDevExt->Specific.Control.ObjectLifeTimeCount.QuadPart = (ULONGLONG)((ULONGLONG)AFS_OBJECT_LIFETIME / (ULONGLONG)ulTimeIncrement);
-        pControlDevExt->Specific.Control.FcbPurgeTimeCount.QuadPart = AFS_ONE_SECOND;
-        pControlDevExt->Specific.Control.FcbPurgeTimeCount.QuadPart *= AFS_SERVER_PURGE_DELAY;
+        pControlDevExt->Specific.Control.FcbPurgeTimeCount.QuadPart = AFS_SERVER_PURGE_DELAY;
         pControlDevExt->Specific.Control.FcbPurgeTimeCount.QuadPart /= ulTimeIncrement;
-        pControlDevExt->Specific.Control.FcbFlushTimeCount.QuadPart = (ULONGLONG)((ULONGLONG)(AFS_ONE_SECOND * AFS_SERVER_FLUSH_DELAY) / (ULONGLONG)ulTimeIncrement);
+        pControlDevExt->Specific.Control.FcbFlushTimeCount.QuadPart = (ULONGLONG)((ULONGLONG)AFS_SERVER_FLUSH_DELAY / (ULONGLONG)ulTimeIncrement);
         pControlDevExt->Specific.Control.ExtentRequestTimeCount.QuadPart = (ULONGLONG)((ULONGLONG)AFS_EXTENT_REQUEST_TIME/(ULONGLONG)ulTimeIncrement);
 
         //
@@ -7585,6 +7610,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
     UNICODE_STRING uniFullPathName, uniRemainingPath, uniComponentName, uniParsedName;
     AFSNameArrayHdr *pNameArray = NULL;
     AFSDirectoryCB *pDirectoryEntry = NULL, *pParentDirEntry = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -7615,13 +7641,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             if( pVolumeCB != NULL)
             {
 
-                InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetObjectStatus Increment count on volume %08lX Cnt %d\n",
                               pVolumeCB,
-                              pVolumeCB->VolumeReferenceCount);
+                              lCount);
             }
 
             AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
@@ -7637,9 +7663,9 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
 
                 pObjectInfo = &pVolumeCB->ObjectInformation;
 
-                InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+                lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
             }
             else
             {
@@ -7647,13 +7673,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                 AFSAcquireShared( pVolumeCB->ObjectInfoTree.TreeLock,
                                   TRUE);
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
                               pVolumeCB,
-                              pVolumeCB->VolumeReferenceCount);
+                              lCount);
 
                 ullIndex = AFSCreateLowIndex( &GetStatusInfo->FileID);
 
@@ -7668,13 +7694,13 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                     // Reference the node so it won't be torn down
                     //
 
-                    InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+                    lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSGetObjectStatus Increment count on object %08lX Cnt %d\n",
                                   pObjectInfo,
-                                  pObjectInfo->ObjectReferenceCount);
+                                  lCount);
                 }
 
                 AFSReleaseResource( pVolumeCB->ObjectInfoTree.TreeLock);
@@ -7744,15 +7770,15 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             // Increment the ref count on the volume and dir entry for correct processing below
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSGetObjectStatus Increment count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
 
-            InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pParentDirEntry->OpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -7760,7 +7786,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                           &pParentDirEntry->NameInformation.FileName,
                           pParentDirEntry,
                           NULL,
-                          pParentDirEntry->OpenReferenceCount);
+                          lCount);
 
             ntStatus = AFSLocateNameEntry( NULL,
                                            NULL,
@@ -7788,19 +7814,19 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                     if( pVolumeCB != NULL)
                     {
 
-                        InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                        lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
                                       "AFSGetObjectStatus Decrement count on volume %08lX Cnt %d\n",
                                       pVolumeCB,
-                                      pVolumeCB->VolumeReferenceCount);
+                                      lCount);
                     }
 
                     if( pDirectoryEntry != NULL)
                     {
 
-                        InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -7808,12 +7834,12 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                                       &pDirectoryEntry->NameInformation.FileName,
                                       pDirectoryEntry,
                                       NULL,
-                                      pDirectoryEntry->OpenReferenceCount);
+                                      lCount);
                     }
                     else
                     {
 
-                        InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -7821,7 +7847,7 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
                                       &pParentDirEntry->NameInformation.FileName,
                                       pParentDirEntry,
                                       NULL,
-                                      pParentDirEntry->OpenReferenceCount);
+                                      lCount);
                     }
                 }
 
@@ -7834,16 +7860,16 @@ AFSGetObjectStatus( IN AFSGetStatusInfoCB *GetStatusInfo,
             // Remove the reference made above
             //
 
-            InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pDirectoryEntry->OpenReferenceCount);
 
             pObjectInfo = pDirectoryEntry->ObjectInformation;
 
-            InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedIncrement( &pObjectInfo->ObjectReferenceCount);
 
             if( pVolumeCB != NULL)
             {
 
-                InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -7898,7 +7924,7 @@ try_exit:
         if( pObjectInfo != NULL)
         {
 
-            InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
+            lCount = InterlockedDecrement( &pObjectInfo->ObjectReferenceCount);
         }
 
         if( pNameArray != NULL)
@@ -7919,6 +7945,7 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
     NTSTATUS ntStatus = STATUS_SUCCESS;
     AFSDirectoryCB *pDirEntry = NULL;
     ULONG ulCRC = 0;
+    LONG lCount;
 
     __Enter
     {
@@ -7988,7 +8015,7 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
 
         if( pDirEntry != NULL)
         {
-            InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->OpenReferenceCount);
         }
 
         AFSReleaseResource( ParentDirectoryCB->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -8016,7 +8043,7 @@ AFSCheckSymlinkAccess( IN AFSDirectoryCB *ParentDirectoryCB,
 
         ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
 
-        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+        lCount = InterlockedDecrement( &pDirEntry->OpenReferenceCount);
 
 try_exit:
 
@@ -8495,3 +8522,112 @@ try_exit:
 
     return ntStatus;
 }
+
+NTSTATUS
+AFSPerformObjectInvalidate( IN AFSObjectInfoCB *ObjectInfo,
+                            IN ULONG InvalidateReason)
+{
+
+    NTSTATUS            ntStatus = STATUS_SUCCESS;
+    IO_STATUS_BLOCK     stIoStatus;
+    LIST_ENTRY         *le;
+    AFSExtent          *pEntry;
+    ULONG               ulProcessCount = 0;
+    ULONG               ulCount = 0;
+
+    __Enter
+    {
+
+        switch( InvalidateReason)
+        {
+
+            case AFS_INVALIDATE_DELETED:
+            {
+
+                if( ObjectInfo->FileType == AFS_FILE_TYPE_FILE &&
+                    ObjectInfo->Fcb != NULL)
+                {
+
+
+                    //
+                    // Clear out the extents
+                    // And get rid of them (note this involves waiting
+                    // for any writes or reads to the cache to complete)
+                    //
+
+                    (VOID) AFSTearDownFcbExtents( ObjectInfo->Fcb,
+                                                  NULL);
+                }
+
+                break;
+            }
+
+            case AFS_INVALIDATE_DATA_VERSION:
+            {
+
+                if( ObjectInfo->FileType == AFS_FILE_TYPE_FILE &&
+                    ObjectInfo->Fcb != NULL)
+                {
+
+                    AFSAcquireExcl( &ObjectInfo->Fcb->NPFcb->Resource,
+                                    TRUE);
+
+                    AFSLockForExtentsTrim( ObjectInfo->Fcb);
+
+                    __try
+                    {
+
+                        le = ObjectInfo->Fcb->Specific.File.ExtentsLists[AFS_EXTENTS_LIST].Flink;
+
+                        ulProcessCount = 0;
+
+                        ulCount = (ULONG)ObjectInfo->Fcb->Specific.File.ExtentCount;
+
+                        while( ulProcessCount < ulCount)
+                        {
+                            pEntry = ExtentFor( le, AFS_EXTENTS_LIST );
+
+                            if( !BooleanFlagOn( pEntry->Flags, AFS_EXTENT_DIRTY))
+                            {
+                                CcPurgeCacheSection( &ObjectInfo->Fcb->NPFcb->SectionObjectPointers,
+                                                     &pEntry->FileOffset,
+                                                     pEntry->Size,
+                                                     FALSE);
+                            }
+
+                            ulProcessCount++;
+                            le = le->Flink;
+                        }
+                    }
+                    __except( EXCEPTION_EXECUTE_HANDLER)
+                    {
+
+                        ntStatus = GetExceptionCode();
+                    }
+
+                    AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Specific.File.ExtentsResource );
+
+                    AFSReleaseResource( &ObjectInfo->Fcb->NPFcb->Resource);
+
+                    AFSReleaseCleanExtents( ObjectInfo->Fcb,
+                                            NULL);
+                }
+
+                break;
+            }
+
+            default:
+            {
+
+                break;
+            }
+        }
+
+        if( ObjectInfo != NULL)
+        {
+            InterlockedDecrement( &ObjectInfo->ObjectReferenceCount);
+        }
+    }
+
+    return ntStatus;
+}