Windows: AFSLocateNameEntry Evaluate Symlink Target
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSNameSupport.cpp
index 8bb007b..1a0940e 100644 (file)
@@ -63,9 +63,11 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
     BOOLEAN           bAllocatedSymLinkBuffer = FALSE;
     UNICODE_STRING    uniRelativeName, uniNoOpName;
     AFSObjectInfoCB  *pCurrentObject = NULL;
+    AFSObjectInfoCB  *pParentObjectInfo = NULL;
     AFSVolumeCB      *pCurrentVolume = *VolumeCB;
     BOOLEAN           bReleaseCurrentVolume = TRUE;
     BOOLEAN           bSubstitutedName = FALSE;
+    LONG              lCount;
 
     __Enter
     {
@@ -119,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
             //
@@ -154,7 +158,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               pCurrentObject->FileId.Volume,
                               pCurrentObject->FileId.Vnode,
                               pCurrentObject->FileId.Unique,
-                              ntStatus);
+                              STATUS_FILE_DELETED);
 
                 try_return( ntStatus = STATUS_FILE_DELETED);
             }
@@ -171,7 +175,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               pCurrentObject->FileId.Volume,
                               pCurrentObject->FileId.Vnode,
                               pCurrentObject->FileId.Unique,
-                              ntStatus);
+                              STATUS_DELETE_PENDING);
 
                 try_return( ntStatus = STATUS_DELETE_PENDING);
             }
@@ -195,9 +199,18 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               pCurrentObject->FileId.Vnode,
                               pCurrentObject->FileId.Unique);
 
+                //
+                // Directory TreeLock should be exclusively held
+                //
+
+                AFSAcquireExcl( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
+                                TRUE);
+
                 ntStatus = AFSVerifyEntry( AuthGroup,
                                            pDirEntry);
 
+                AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
                 if( !NT_SUCCESS( ntStatus))
                 {
 
@@ -240,16 +253,55 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 if( !NT_SUCCESS( ntStatus))
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                                  AFS_TRACE_LEVEL_ERROR,
-                                  "AFSLocateNameEntry (FO: %08lX) Failed to evaluate parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
-                                  FileObject,
-                                  &pDirEntry->NameInformation.FileName,
-                                  pCurrentObject->FileId.Cell,
-                                  pCurrentObject->FileId.Volume,
-                                  pCurrentObject->FileId.Vnode,
-                                  pCurrentObject->FileId.Unique,
-                                  ntStatus);
+                    if ( ntStatus == STATUS_NOT_A_DIRECTORY)
+                    {
+
+                        if ( pCurrentObject->ParentObjectInformation == NULL)
+                        {
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                          AFS_TRACE_LEVEL_ERROR,
+                                          "AFSLocateNameEntry (FO: %08lX) Failed to evaluate object %wZ FID %08lX-%08lX-%08lX-%08lX PARENT NULL Status %08lX\n",
+                                          FileObject,
+                                          &pDirEntry->NameInformation.FileName,
+                                          pCurrentObject->FileId.Cell,
+                                          pCurrentObject->FileId.Volume,
+                                          pCurrentObject->FileId.Vnode,
+                                          pCurrentObject->FileId.Unique,
+                                          ntStatus);
+                        }
+                        else
+                        {
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                          AFS_TRACE_LEVEL_ERROR,
+                                          "AFSLocateNameEntry (FO: %08lX) Failed to evaluate object %wZ FID %08lX-%08lX-%08lX-%08lX PARENT %08lX-%08lX-%08lX-%08lX Status %08lX\n",
+                                          FileObject,
+                                          &pDirEntry->NameInformation.FileName,
+                                          pCurrentObject->FileId.Cell,
+                                          pCurrentObject->FileId.Volume,
+                                          pCurrentObject->FileId.Vnode,
+                                          pCurrentObject->FileId.Unique,
+                                          pCurrentObject->ParentObjectInformation->FileId.Cell,
+                                          pCurrentObject->ParentObjectInformation->FileId.Volume,
+                                          pCurrentObject->ParentObjectInformation->FileId.Vnode,
+                                          pCurrentObject->ParentObjectInformation->FileId.Unique,
+                                          ntStatus);
+                        }
+                    }
+                    else
+                    {
+                        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                      AFS_TRACE_LEVEL_ERROR,
+                                      "AFSLocateNameEntry (FO: %08lX) Failed to evaluate parent %wZ FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
+                                      FileObject,
+                                      &pDirEntry->NameInformation.FileName,
+                                      pCurrentObject->FileId.Cell,
+                                      pCurrentObject->FileId.Volume,
+                                      pCurrentObject->FileId.Vnode,
+                                      pCurrentObject->FileId.Unique,
+                                      ntStatus);
+                    }
 
                     try_return( ntStatus);
                 }
@@ -295,6 +347,9 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         try_return( ntStatus);
                     }
 
+                    AFSAcquireExcl( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
+                                    TRUE);
+
                     AFSAcquireExcl( &pDirEntry->NonPaged->Lock,
                                     TRUE);
 
@@ -319,9 +374,15 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       pCurrentObject->FileId.Vnode,
                                       pCurrentObject->FileId.Unique);
 
+                        //
+                        // Directory TreeLock should be exclusively held
+                        //
+
                         ntStatus = AFSVerifyEntry( AuthGroup,
                                                    pDirEntry);
 
+                        AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
                         if( !NT_SUCCESS( ntStatus))
                         {
 
@@ -353,6 +414,11 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                             continue;
                         }
                     }
+                    else
+                    {
+
+                        AFSReleaseResource( pCurrentObject->Specific.Directory.DirectoryNodeHdr.TreeLock);
+                    }
 
                     //
                     // If we were given a zero length target name then deny access to the entry
@@ -361,7 +427,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     if( pDirEntry->NameInformation.TargetName.Length == 0)
                     {
 
-                        ntStatus = STATUS_ACCESS_DENIED;
+                        ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                                       AFS_TRACE_LEVEL_ERROR,
@@ -488,7 +554,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         if( pTmpBuffer != NULL)
                         {
 
-                            AFSExFreePool( pTmpBuffer);
+                            AFSExFreePoolWithTag( pTmpBuffer, 0);
                         }
 
                         AFSReleaseResource( &pDirEntry->NonPaged->Lock);
@@ -497,7 +563,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Dereference the current entry ..
                         //
 
-                        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -505,7 +571,9 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
+
+                        ASSERT( lCount >= 0);
 
                         //
                         // OK, need to back up one entry for the correct parent since the current
@@ -518,7 +586,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Increment our reference on this dir entry
                         //
 
-                        InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -526,7 +594,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
 
                         if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_ROOT_VOLUME))
                         {
@@ -555,6 +623,26 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       pCurrentObject->FileId.Vnode,
                                       pCurrentObject->FileId.Unique);
 
+                        if ( !AFSIsAbsoluteAFSName( &pDirEntry->NameInformation.TargetName))
+                        {
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                          AFS_TRACE_LEVEL_ERROR,
+                                          "AFSLocateNameEntry Name %wZ contains invalid server name\n",
+                                          &pDirEntry->NameInformation.TargetName);
+
+                            //
+                            // The correct response would be STATUS_OBJECT_PATH_INVALID
+                            // but that prevents cmd.exe from performing a recursive
+                            // directory enumeration when opening a directory entry
+                            // that represents a symlink to an invalid path is discovered.
+                            //
+
+                            AFSReleaseResource( &pDirEntry->NonPaged->Lock);
+
+                            try_return( ntStatus = STATUS_OBJECT_PATH_NOT_FOUND);
+                        }
+
                         //
                         // We'll substitute this name into the current process name
                         // starting at where we sit in the path
@@ -600,10 +688,10 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         //
 
                         RtlCopyMemory( uniTempName.Buffer,
-                                       pDirEntry->NameInformation.TargetName.Buffer,
-                                       pDirEntry->NameInformation.TargetName.Length);
+                                       &pDirEntry->NameInformation.TargetName.Buffer[ AFSMountRootName.Length/sizeof( WCHAR)],
+                                       pDirEntry->NameInformation.TargetName.Length - AFSMountRootName.Length);
 
-                        uniTempName.Length = pDirEntry->NameInformation.TargetName.Length;
+                        uniTempName.Length = pDirEntry->NameInformation.TargetName.Length - AFSMountRootName.Length;
 
                         //
                         // And now any remaining portion of the name
@@ -633,7 +721,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         if( pTmpBuffer != NULL)
                         {
 
-                            AFSExFreePool( pTmpBuffer);
+                            AFSExFreePoolWithTag( pTmpBuffer, 0);
                         }
 
                         AFSReleaseResource( &pDirEntry->NonPaged->Lock);
@@ -655,35 +743,30 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                           pCurrentObject->FileId.Vnode,
                                           pCurrentObject->FileId.Unique);
 
-                            InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
+                            lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                           AFS_TRACE_LEVEL_VERBOSE,
                                           "AFSLocateNameEntry Decrement count on volume %08lX Cnt %d\n",
                                           pCurrentVolume,
-                                          pCurrentVolume->VolumeReferenceCount);
-
-                            AFSReleaseResource( pCurrentVolume->VolumeLock);
+                                          lCount);
 
                             pCurrentVolume = AFSGlobalRoot;
 
-                            AFSAcquireShared( pCurrentVolume->VolumeLock,
-                                              TRUE);
-
-                            InterlockedIncrement( &pCurrentVolume->VolumeReferenceCount);
+                            lCount = InterlockedIncrement( &pCurrentVolume->VolumeReferenceCount);
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                           AFS_TRACE_LEVEL_VERBOSE,
                                           "AFSLocateNameEntry Increment count on volume %08lX Cnt %d\n",
                                           pCurrentVolume,
-                                          pCurrentVolume->VolumeReferenceCount);
+                                          lCount);
                         }
 
                         //
                         // Dereference our current dir entry
                         //
 
-                        InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -691,7 +774,9 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
+
+                        ASSERT( lCount >= 0);
 
                         pDirEntry = pCurrentVolume->DirectoryCB;
 
@@ -699,7 +784,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // Reference the new dir entry
                         //
 
-                        InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                        lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                       AFS_TRACE_LEVEL_VERBOSE,
@@ -707,7 +792,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       &pDirEntry->NameInformation.FileName,
                                       pDirEntry,
                                       NULL,
-                                      pDirEntry->OpenReferenceCount);
+                                      lCount);
 
                         //
                         // Reset the name array
@@ -731,35 +816,6 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                         pNameArray->LinkCount = lLinkCount;
 
-                        //
-                        // Process over the \\<Global root> portion of the name
-                        //
-
-                        FsRtlDissectName( uniPathName,
-                                          &uniComponentName,
-                                          &uniRemainingPath);
-
-                        if( RtlCompareUnicodeString( &uniComponentName,
-                                                     &AFSServerName,
-                                                     TRUE) != 0)
-                        {
-
-                            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                                          AFS_TRACE_LEVEL_ERROR,
-                                          "AFSLocateNameEntry Name %wZ contains invalid server name\n",
-                                          &uniPathName);
-
-                            //
-                            // The correct response would be STATUS_OBJECT_PATH_INVALID
-                            // but that prevents cmd.exe from performing a recursive
-                            // directory enumeration when opening a directory entry
-                            // that represents a symlink to an invalid path is discovered.
-                            //
-                            try_return( ntStatus = STATUS_OBJECT_PATH_NOT_FOUND);
-                        }
-
-                        uniPathName = uniRemainingPath;
-
                         pParentDirEntry = NULL;
                     }
 
@@ -767,7 +823,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our link count
                     //
 
-                    InterlockedIncrement( &pNameArray->LinkCount);
+                    lCount = InterlockedIncrement( &pNameArray->LinkCount);
 
                     continue;
                 }
@@ -818,15 +874,13 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                     ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                    InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
+                    lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSLocateNameEntry Decrement2 count on volume %08lX Cnt %d\n",
                                   pCurrentVolume,
-                                  pCurrentVolume->VolumeReferenceCount);
-
-                    AFSReleaseResource( pCurrentVolume->VolumeLock);
+                                  lCount);
 
                     ntStatus = AFSBuildMountPointTarget( AuthGroup,
                                                          pDirEntry,
@@ -852,26 +906,17 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                         bReleaseCurrentVolume = FALSE;
 
-                        try_return( ntStatus = STATUS_ACCESS_DENIED);
+                        try_return( ntStatus);
                     }
 
                     ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                    ASSERT( ExIsResourceAcquiredLite( pCurrentVolume->VolumeLock));
-
-                    //
-                    // Replace the current name for the mp with the volume root of the target
-                    //
-
-                    AFSReplaceCurrentElement( pNameArray,
-                                              pCurrentVolume->DirectoryCB);
-
                     //
                     // We want to restart processing here on the new parent ...
                     // Deref and ref count the entries
                     //
 
-                    InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -879,11 +924,13 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   &pDirEntry->NameInformation.FileName,
                                   pDirEntry,
                                   NULL,
-                                  pDirEntry->OpenReferenceCount);
+                                  lCount);
+
+                    ASSERT( lCount >= 0);
 
                     pDirEntry = pCurrentVolume->DirectoryCB;
 
-                    InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -891,7 +938,15 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   &pDirEntry->NameInformation.FileName,
                                   pDirEntry,
                                   NULL,
-                                  pDirEntry->OpenReferenceCount);
+                                  lCount);
+
+                    //
+                    // The name array stores both the mount point and the target.
+                    // Insert the target.
+                    //
+
+                    AFSInsertNextElement( pNameArray,
+                                          pDirEntry);
 
                     pParentDirEntry = NULL;
 
@@ -899,7 +954,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our link count
                     //
 
-                    InterlockedIncrement( &pNameArray->LinkCount);
+                    lCount = InterlockedIncrement( &pNameArray->LinkCount);
 
                     continue;
                 }
@@ -1126,7 +1181,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 uniSearchName.Buffer != NULL)
             {
 
-                AFSExFreePool( uniSearchName.Buffer);
+                AFSExFreePoolWithTag( uniSearchName.Buffer, 0);
 
                 bSubstituteName = FALSE;
 
@@ -1178,8 +1233,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 //
                 // Need to back up one entry in the name array
                 //
-
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1187,7 +1241,9 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               &pDirEntry->NameInformation.FileName,
                               pDirEntry,
                               NULL,
-                              pDirEntry->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
 
                 pDirEntry = AFSBackupEntry( NameArray);
 
@@ -1201,7 +1257,15 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     try_return(ntStatus = STATUS_OBJECT_PATH_INVALID);
                 }
 
-                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))
                 {
@@ -1216,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;
@@ -1374,7 +1430,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                         // a lookup in the short name tree
                         //
 
-                        if( RtlIsNameLegalDOS8Dot3( &uniSearchName,
+                        if( !BooleanFlagOn( pDevExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
+                            RtlIsNameLegalDOS8Dot3( &uniSearchName,
                                                     NULL,
                                                     NULL))
                         {
@@ -1390,6 +1447,26 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                                         &pDirEntry);
                         }
 
+                        if ( pDirEntry == NULL &&
+                             pParentDirEntry->ObjectInformation->VolumeCB == AFSGlobalRoot)
+                        {
+
+                            //
+                            // Check with the service to see if this is a valid cell name
+                            // that can be automatically resolved.  Drop the shared TreeLock
+                            // since AFSCheckCellName must acquire it exclusively.
+                            //
+
+                            AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
+                            ntStatus = AFSCheckCellName( AuthGroup,
+                                                         &uniSearchName,
+                                                         &pDirEntry);
+
+                            AFSAcquireShared( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
+                                              TRUE);
+                        }
+
                         if( pDirEntry == NULL)
                         {
 
@@ -1400,7 +1477,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                             if( bSubstituteName)
                             {
 
-                                AFSExFreePool( uniSearchName.Buffer);
+                                AFSExFreePoolWithTag( uniSearchName.Buffer, 0);
 
                                 uniSearchName = uniComponentName;
 
@@ -1471,6 +1548,20 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                             pDirEntry->CaseInsensitiveList.fLink != NULL)
                         {
 
+                            //
+                            // Increment our dir entry ref count since we will decrement it on exit
+                            //
+
+                            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
+
+                            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                                          AFS_TRACE_LEVEL_VERBOSE,
+                                          "AFSLocateNameEntry Increment5 count on %wZ DE %p Ccb %p Cnt %d\n",
+                                          &pDirEntry->NameInformation.FileName,
+                                          pDirEntry,
+                                          NULL,
+                                          lCount);
+
                             AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
 
                             try_return(ntStatus = STATUS_OBJECT_NAME_COLLISION);
@@ -1502,9 +1593,18 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                       pParentDirEntry->ObjectInformation->FileId.Vnode,
                                       pParentDirEntry->ObjectInformation->FileId.Unique);
 
+                        //
+                        // Directory TreeLock should be exclusively held
+                        //
+
+                        AFSAcquireExcl( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
+                                        TRUE);
+
                         ntStatus = AFSVerifyEntry( AuthGroup,
                                                    pParentDirEntry);
 
+                        AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
                         if( !NT_SUCCESS( ntStatus))
                         {
 
@@ -1539,7 +1639,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Increment our dir entry ref count
                     //
 
-                    InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+                    lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
                     AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                                   AFS_TRACE_LEVEL_VERBOSE,
@@ -1547,7 +1647,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   &pDirEntry->NameInformation.FileName,
                                   pDirEntry,
                                   NULL,
-                                  pDirEntry->OpenReferenceCount);
+                                  lCount);
                 }
 
                 AFSReleaseResource( pParentDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
@@ -1566,7 +1666,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                               AFS_TRACE_LEVEL_ERROR,
-                              "AFSLocateNameEntry (FO: %08lX) Deleted parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                              "AFSLocateNameEntry (FO: %08lX) Deleted entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
                               FileObject,
                               &pDirEntry->NameInformation.FileName,
                               pCurrentObject->FileId.Cell,
@@ -1579,18 +1679,32 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 // on the entry
                 //
 
-                ASSERT( pCurrentObject->ParentObjectInformation != NULL);
+                pParentObjectInfo = pCurrentObject->ParentObjectInformation;
+
+                ASSERT( pParentObjectInfo != NULL);
 
-                AFSAcquireExcl( pCurrentObject->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
+                AFSAcquireExcl( pParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock,
                                 TRUE);
 
                 AFSAcquireExcl( pCurrentObject->VolumeCB->ObjectInfoTree.TreeLock,
                                 TRUE);
 
-                if( InterlockedDecrement( &pDirEntry->OpenReferenceCount) == 0)
+                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)
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING|AFS_SUBSYSTEM_CLEANUP_PROCESSING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSLocateNameEntry Deleting dir entry %08lX (%08lX) for %wZ\n",
                                   pDirEntry,
@@ -1601,10 +1715,13 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     // Remove and delete the directory entry from the parent list
                     //
 
-                    AFSDeleteDirEntry( pCurrentObject->ParentObjectInformation,
+                    AFSDeleteDirEntry( pParentObjectInfo,
                                        pDirEntry);
 
-                    if( pCurrentObject->ObjectReferenceCount == 0)
+                    AFSAcquireShared( &pCurrentObject->NonPagedInfo->ObjectInfoLock,
+                                      TRUE);
+
+                    if( pCurrentObject->ObjectReferenceCount <= 0)
                     {
 
                         if( BooleanFlagOn( pCurrentObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE))
@@ -1621,6 +1738,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                             ClearFlag( pCurrentObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE);
                         }
                     }
+
+                    AFSReleaseResource( &pCurrentObject->NonPagedInfo->ObjectInfoLock);
                 }
                 else
                 {
@@ -1633,11 +1752,11 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                     SetFlag( pDirEntry->Flags, AFS_DIR_ENTRY_DELETED);
 
-                    AFSRemoveNameEntry( pCurrentObject->ParentObjectInformation,
+                    AFSRemoveNameEntry( pParentObjectInfo,
                                         pDirEntry);
                 }
 
-                AFSReleaseResource( pCurrentObject->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
+                AFSReleaseResource( pParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
 
                 AFSReleaseResource( pCurrentObject->VolumeCB->ObjectInfoTree.TreeLock);
 
@@ -1695,7 +1814,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
             // Decrement the previous parent
             //
 
-            InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -1703,7 +1822,9 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                           &pParentDirEntry->NameInformation.FileName,
                           pParentDirEntry,
                           NULL,
-                          pParentDirEntry->OpenReferenceCount);
+                          lCount);
+
+            ASSERT( lCount >= 0);
 
             //
             // If we ended up substituting a name in the component then update
@@ -1779,9 +1900,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
             //
 
             if( pCurrentObject->FileType == AFS_FILE_TYPE_SYMLINK &&
-                pCurrentObject->TargetFileId.Vnode == 0 &&
-                pCurrentObject->TargetFileId.Unique == 0 &&
-                pDirEntry->NameInformation.TargetName.Length == 0)
+                ( pCurrentObject->TargetFileId.Vnode == 0 ||
+                  pDirEntry->NameInformation.TargetName.Length == 0))
             {
 
                 ntStatus = AFSValidateSymLink( AuthGroup,
@@ -1846,7 +1966,7 @@ try_exit:
             if( pDirEntry != NULL)
             {
 
-                InterlockedDecrement( &pDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1854,12 +1974,14 @@ try_exit:
                               &pDirEntry->NameInformation.FileName,
                               pDirEntry,
                               NULL,
-                              pDirEntry->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
             }
             else if( pParentDirEntry != NULL)
             {
 
-                InterlockedDecrement( &pParentDirEntry->OpenReferenceCount);
+                lCount = InterlockedDecrement( &pParentDirEntry->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -1867,7 +1989,9 @@ try_exit:
                               &pParentDirEntry->NameInformation.FileName,
                               pParentDirEntry,
                               NULL,
-                              pParentDirEntry->OpenReferenceCount);
+                              lCount);
+
+                ASSERT( lCount >= 0);
             }
 
             if( bReleaseCurrentVolume)
@@ -1875,23 +1999,19 @@ try_exit:
 
                 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                ASSERT( ExIsResourceAcquiredLite( pCurrentVolume->VolumeLock));
-
-                InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
+                lCount = InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
                               "AFSLocateNameEntry Decrement3 count on volume %08lX Cnt %d\n",
                               pCurrentVolume,
-                              pCurrentVolume->VolumeReferenceCount);
-
-                AFSReleaseResource( pCurrentVolume->VolumeLock);
+                              lCount);
             }
 
             if( RootPathName->Buffer != uniFullPathName.Buffer)
             {
 
-                AFSExFreePool( uniFullPathName.Buffer);
+                AFSExFreePoolWithTag( uniFullPathName.Buffer, 0);
             }
         }
         else
@@ -1906,7 +2026,7 @@ try_exit:
                               &(*ParentDirectoryCB)->NameInformation.FileName,
                               *ParentDirectoryCB,
                               NULL,
-                              (*ParentDirectoryCB)->OpenReferenceCount);
+                              (*ParentDirectoryCB)->DirOpenReferenceCount);
             }
 
             if( *DirectoryCB != NULL)
@@ -1918,7 +2038,7 @@ try_exit:
                               &(*DirectoryCB)->NameInformation.FileName,
                               *DirectoryCB,
                               NULL,
-                              (*DirectoryCB)->OpenReferenceCount);
+                              (*DirectoryCB)->DirOpenReferenceCount);
             }
         }
 
@@ -1926,7 +2046,7 @@ try_exit:
             uniSearchName.Buffer != NULL)
         {
 
-            AFSExFreePool( uniSearchName.Buffer);
+            AFSExFreePoolWithTag( uniSearchName.Buffer, 0);
         }
     }
 
@@ -1947,6 +2067,7 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
     AFSDirectoryCB *pDirNode = NULL, *pExistingDirNode = NULL;
     UNICODE_STRING uniShortName;
     LARGE_INTEGER liFileSize = {0,0};
+    LONG lCount;
 
     __Enter
     {
@@ -2057,24 +2178,79 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
 
         if( pExistingDirNode != NULL)
         {
+            if (AFSIsEqualFID( &pDirNode->ObjectInformation->FileId,
+                               &pExistingDirNode->ObjectInformation->FileId))
+            {
 
-            AFSDeleteDirEntry( ParentObjectInfo,
-                               pDirNode);
+                AFSDeleteDirEntry( ParentObjectInfo,
+                                   pDirNode);
 
-            InterlockedIncrement( &pExistingDirNode->OpenReferenceCount);
+                lCount = InterlockedIncrement( &pExistingDirNode->DirOpenReferenceCount);
 
-            AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
-                          AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
-                          &pExistingDirNode->NameInformation.FileName,
-                          pExistingDirNode,
-                          pExistingDirNode->OpenReferenceCount);
+                AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSCreateDirEntry Increment count on %wZ DE %p Cnt %d\n",
+                              &pExistingDirNode->NameInformation.FileName,
+                              pExistingDirNode,
+                              lCount);
 
-            *DirEntry = pExistingDirNode;
+                *DirEntry = pExistingDirNode;
 
-            AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
+                AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
 
-            try_return( ntStatus = STATUS_SUCCESS);
+                try_return( ntStatus = STATUS_SUCCESS);
+            }
+            else
+            {
+
+                //
+                // Need to tear down this entry and rebuild it below
+                //
+
+                if( pExistingDirNode->DirOpenReferenceCount <= 0)
+                {
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCreateDirEntry Different FIDs - Deleting DE %p for %wZ Old FID %08lX-%08lX-%08lX-%08lX New FID %08lX-%08lX-%08lX-%08lX\n",
+                                  pExistingDirNode,
+                                  &pExistingDirNode->NameInformation.FileName,
+                                  pExistingDirNode->ObjectInformation->FileId.Cell,
+                                  pExistingDirNode->ObjectInformation->FileId.Volume,
+                                  pExistingDirNode->ObjectInformation->FileId.Vnode,
+                                  pExistingDirNode->ObjectInformation->FileId.Unique,
+                                  pDirNode->ObjectInformation->FileId.Cell,
+                                  pDirNode->ObjectInformation->FileId.Volume,
+                                  pDirNode->ObjectInformation->FileId.Vnode,
+                                  pDirNode->ObjectInformation->FileId.Unique);
+
+                    AFSDeleteDirEntry( ParentObjectInfo,
+                                       pExistingDirNode);
+                }
+                else
+                {
+
+                    SetFlag( pExistingDirNode->Flags, AFS_DIR_ENTRY_DELETED);
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                  AFS_TRACE_LEVEL_VERBOSE,
+                                  "AFSCreateDirEntry Different FIDs - Removing DE %p for %wZ Old FID %08lX-%08lX-%08lX-%08lX New FID %08lX-%08lX-%08lX-%08lX\n",
+                                  pExistingDirNode,
+                                  &pExistingDirNode->NameInformation.FileName,
+                                  pExistingDirNode->ObjectInformation->FileId.Cell,
+                                  pExistingDirNode->ObjectInformation->FileId.Volume,
+                                  pExistingDirNode->ObjectInformation->FileId.Vnode,
+                                  pExistingDirNode->ObjectInformation->FileId.Unique,
+                                  pDirNode->ObjectInformation->FileId.Cell,
+                                  pDirNode->ObjectInformation->FileId.Volume,
+                                  pDirNode->ObjectInformation->FileId.Vnode,
+                                  pDirNode->ObjectInformation->FileId.Unique);
+
+                    AFSRemoveNameEntry( ParentObjectInfo,
+                                        pExistingDirNode);
+                }
+
+            }
         }
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -2095,14 +2271,14 @@ AFSCreateDirEntry( IN GUID            *AuthGroup,
                                 pDirNode,
                                 TRUE);
 
-        InterlockedIncrement( &pDirNode->OpenReferenceCount);
+        lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSCreateDirEntry Increment2 count on %wZ DE %p Cnt %d\n",
                       &pDirNode->NameInformation.FileName,
                       pDirNode,
-                      pDirNode->OpenReferenceCount);
+                      lCount);
 
         //
         // Pass back the dir entry
@@ -2126,6 +2302,8 @@ AFSInsertDirectoryNode( IN AFSObjectInfoCB *ParentObjectInfo,
                         IN BOOLEAN InsertInEnumList)
 {
 
+    LONG lCount;
+
     __Enter
     {
 
@@ -2247,7 +2425,7 @@ AFSInsertDirectoryNode( IN AFSObjectInfoCB *ParentObjectInfo,
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSInsertDirectoryNode Inserting entry %08lX %wZ FID %08lX-%08lX-%08lX-%08lXStatus %08lX\n",
+                          "AFSInsertDirectoryNode Inserting entry %08lX %wZ FID %08lX-%08lX-%08lX-%08lX\n",
                           DirEntry,
                           &DirEntry->NameInformation.FileName,
                           DirEntry->ObjectInformation->FileId.Cell,
@@ -2272,17 +2450,17 @@ AFSInsertDirectoryNode( IN AFSObjectInfoCB *ParentObjectInfo,
 
             SetFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
 
-            InterlockedIncrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
+            lCount = InterlockedIncrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSInsertDirectoryNode Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
-                              &DirEntry->NameInformation.FileName,
-                              ParentObjectInfo->Specific.Directory.DirectoryNodeCount,
-                              ParentObjectInfo->FileId.Cell,
-                              ParentObjectInfo->FileId.Volume,
-                              ParentObjectInfo->FileId.Vnode,
-                              ParentObjectInfo->FileId.Unique);
+                          &DirEntry->NameInformation.FileName,
+                          lCount,
+                          ParentObjectInfo->FileId.Cell,
+                          ParentObjectInfo->FileId.Volume,
+                          ParentObjectInfo->FileId.Vnode,
+                          ParentObjectInfo->FileId.Unique);
         }
     }
 
@@ -2295,20 +2473,24 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    LONG lCount;
 
     __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,
@@ -2321,13 +2503,13 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
         if( BooleanFlagOn( DirEntry->Flags, AFS_DIR_RELEASE_NAME_BUFFER))
         {
 
-            AFSExFreePool( DirEntry->NameInformation.FileName.Buffer);
+            AFSExFreePoolWithTag( DirEntry->NameInformation.FileName.Buffer, 0);
         }
 
         if( BooleanFlagOn( DirEntry->Flags, AFS_DIR_RELEASE_TARGET_NAME_BUFFER))
         {
 
-            AFSExFreePool( DirEntry->NameInformation.TargetName.Buffer);
+            AFSExFreePoolWithTag( DirEntry->NameInformation.TargetName.Buffer, 0);
         }
 
         //
@@ -2336,26 +2518,30 @@ AFSDeleteDirEntry( IN AFSObjectInfoCB *ParentObjectInfo,
 
         ASSERT( DirEntry->ObjectInformation->ObjectReferenceCount > 0);
 
-        if( InterlockedDecrement( &DirEntry->ObjectInformation->ObjectReferenceCount) == 0)
-        {
-            SetFlag( DirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED);
-        }
+        lCount = AFSObjectInfoDecrement( DirEntry->ObjectInformation);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_OBJECT_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSDeleteDirEntry Decrement count on object %08lX Cnt %d\n",
                       DirEntry->ObjectInformation,
-                      DirEntry->ObjectInformation->ObjectReferenceCount);
+                      lCount);
+
+        if( BooleanFlagOn( DirEntry->Flags, AFS_DIR_ENTRY_DELETED) &&
+            DirEntry->ObjectInformation->Links == 0)
+        {
+
+            SetFlag( DirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_DELETED);
+        }
 
         ExDeleteResourceLite( &DirEntry->NonPaged->Lock);
 
-        AFSExFreePool( DirEntry->NonPaged);
+        AFSExFreePoolWithTag( DirEntry->NonPaged, AFS_DIR_ENTRY_NP_TAG);
 
         //
         // Free up the dir entry
         //
 
-        AFSExFreePool( DirEntry);
+        AFSExFreePoolWithTag( DirEntry, AFS_DIR_ENTRY_TAG);
     }
 
     return ntStatus;
@@ -2368,6 +2554,7 @@ AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    LONG lCount;
 
     __Enter
     {
@@ -2441,7 +2628,7 @@ AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
 
             ASSERT( ParentObjectInfo->Specific.Directory.DirectoryNodeCount > 0);
 
-            InterlockedDecrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
+            lCount = InterlockedDecrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeCount);
 
             ClearFlag( DirEntry->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
 
@@ -2449,7 +2636,7 @@ AFSRemoveDirNodeFromParent( IN AFSObjectInfoCB *ParentObjectInfo,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSRemoveDirNodeFromParent Removing entry %wZ Dec Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
                           &DirEntry->NameInformation.FileName,
-                          ParentObjectInfo->Specific.Directory.DirectoryNodeCount,
+                          lCount,
                           ParentObjectInfo->FileId.Cell,
                           ParentObjectInfo->FileId.Volume,
                           ParentObjectInfo->FileId.Vnode,
@@ -2568,6 +2755,7 @@ AFSParseName( IN PIRP Irp,
     AFSFcb             *pRelatedFcb = NULL;
     BOOLEAN             bReleaseTreeLock = FALSE;
     BOOLEAN             bIsAllShare = FALSE;
+    LONG                lCount;
 
     __Enter
     {
@@ -2625,11 +2813,11 @@ AFSParseName( IN PIRP Irp,
             *FileName = pIrpSp->FileObject->FileName;
 
             //
-            // Grab the root node exclusive before returning
+            // Grab the root node while checking state
             //
 
-            AFSAcquireExcl( pVolumeCB->VolumeLock,
-                            TRUE);
+            AFSAcquireShared( pVolumeCB->VolumeLock,
+                              TRUE);
 
             if( BooleanFlagOn( pVolumeCB->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID) ||
                 BooleanFlagOn( pVolumeCB->Flags, AFS_VOLUME_FLAGS_OFFLINE))
@@ -2679,7 +2867,7 @@ AFSParseName( IN PIRP Irp,
                 }
             }
 
-            AFSConvertToShared( pVolumeCB->VolumeLock);
+            AFSReleaseResource( pVolumeCB->VolumeLock);
 
             if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY))
             {
@@ -2694,9 +2882,18 @@ AFSParseName( IN PIRP Irp,
                               pDirEntry->ObjectInformation->FileId.Vnode,
                               pDirEntry->ObjectInformation->FileId.Unique);
 
+                //
+                // Directory TreeLock should be exclusively held
+                //
+
+                AFSAcquireExcl( pDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
+                                TRUE);
+
                 ntStatus = AFSVerifyEntry( AuthGroup,
                                            pDirEntry);
 
+                AFSReleaseResource( pDirEntry->ObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock);
+
                 if( !NT_SUCCESS( ntStatus))
                 {
 
@@ -2711,8 +2908,6 @@ AFSParseName( IN PIRP Irp,
                                   pDirEntry->ObjectInformation->FileId.Unique,
                                   ntStatus);
 
-                    AFSReleaseResource( pVolumeCB->VolumeLock);
-
                     try_return( ntStatus);
                 }
             }
@@ -2740,8 +2935,6 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Failed to allocate full name buffer\n",
                               Irp);
 
-                AFSReleaseResource( pVolumeCB->VolumeLock);
-
                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
             }
 
@@ -2805,9 +2998,7 @@ AFSParseName( IN PIRP Irp,
                                   "AFSParseName (%08lX) Failed to initialize name array\n",
                                   Irp);
 
-                    AFSExFreePool( uniFullName.Buffer);
-
-                    AFSReleaseResource( pVolumeCB->VolumeLock);
+                    AFSExFreePoolWithTag( uniFullName.Buffer, 0);
 
                     try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
                 }
@@ -2834,9 +3025,7 @@ AFSParseName( IN PIRP Irp,
                                   "AFSParseName (%08lX) Failed to initialize name array\n",
                                   Irp);
 
-                    AFSExFreePool( uniFullName.Buffer);
-
-                    AFSReleaseResource( pVolumeCB->VolumeLock);
+                    AFSExFreePoolWithTag( uniFullName.Buffer, 0);
 
                     try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
                 }
@@ -2854,9 +3043,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Failed to populate name array\n",
                               Irp);
 
-                AFSExFreePool( uniFullName.Buffer);
-
-                AFSReleaseResource( pVolumeCB->VolumeLock);
+                AFSExFreePoolWithTag( uniFullName.Buffer, 0);
 
                 try_return( ntStatus);
             }
@@ -2880,17 +3067,17 @@ AFSParseName( IN PIRP Irp,
             // Increment our volume reference count
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSParseName Increment count on volume %08lX Cnt %d\n",
                           pVolumeCB,
-                          pVolumeCB->VolumeReferenceCount);
+                          lCount);
 
             *ParentDirectoryCB = pDirEntry;
 
-            InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -2898,7 +3085,7 @@ AFSParseName( IN PIRP Irp,
                           &pDirEntry->NameInformation.FileName,
                           pDirEntry,
                           NULL,
-                          pDirEntry->OpenReferenceCount);
+                          lCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE_2,
@@ -3019,6 +3206,18 @@ AFSParseName( IN PIRP Irp,
             }
         }
 
+        if( FsRtlDoesNameContainWildCards( &uniFullName))
+        {
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                          AFS_TRACE_LEVEL_ERROR,
+                          "AFSParseName (%08lX) Component %wZ contains wild cards\n",
+                          Irp,
+                          &uniFullName);
+
+            try_return( ntStatus = STATUS_OBJECT_NAME_INVALID);
+        }
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
                       "AFSParseName (%08lX) Processing full name %wZ\n",
@@ -3036,8 +3235,8 @@ AFSParseName( IN PIRP Irp,
         // Be sure we are online and ready to go
         //
 
-        AFSAcquireExcl( AFSGlobalRoot->VolumeLock,
-                        TRUE);
+        AFSAcquireShared( AFSGlobalRoot->VolumeLock,
+                          TRUE);
 
         if( BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID) ||
             BooleanFlagOn( AFSGlobalRoot->Flags, AFS_VOLUME_FLAGS_OFFLINE))
@@ -3087,6 +3286,8 @@ AFSParseName( IN PIRP Irp,
             }
         }
 
+        AFSReleaseResource( AFSGlobalRoot->VolumeLock);
+
         if( !BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_DIRECTORY_ENUMERATED))
         {
 
@@ -3108,8 +3309,6 @@ AFSParseName( IN PIRP Irp,
                               Irp,
                               ntStatus);
 
-                AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
                 try_return( ntStatus);
             }
         }
@@ -3128,7 +3327,7 @@ AFSParseName( IN PIRP Irp,
                           "AFSParseName (%08lX) Returning global root access\n",
                           Irp);
 
-            InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3136,9 +3335,7 @@ AFSParseName( IN PIRP Irp,
                           &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                           AFSGlobalRoot->DirectoryCB,
                           NULL,
-                          AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
-
-            AFSReleaseResource( AFSGlobalRoot->VolumeLock);
+                          lCount);
 
             *VolumeCB = NULL;
 
@@ -3170,11 +3367,24 @@ AFSParseName( IN PIRP Irp,
                           &uniComponentName,
                           &uniRemainingPath);
 
+        if( FsRtlDoesNameContainWildCards( &uniFullName))
+        {
+
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                          AFS_TRACE_LEVEL_ERROR,
+                          "AFSParseName (%08lX) Component %wZ contains wild cards\n",
+                          Irp,
+                          &uniComponentName);
+
+            try_return( ntStatus = STATUS_OBJECT_NAME_INVALID);
+        }
+
         //
         // If this is the ALL access then perform some additional processing
         //
 
-        if( RtlCompareUnicodeString( &uniComponentName,
+        if( uniComponentName.Length == 0 ||
+            RtlCompareUnicodeString( &uniComponentName,
                                      &AFSGlobalRootName,
                                      TRUE) == 0)
         {
@@ -3196,7 +3406,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Returning global root access\n",
                               Irp);
 
-                InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -3204,9 +3414,7 @@ AFSParseName( IN PIRP Irp,
                               &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                               AFSGlobalRoot->DirectoryCB,
                               NULL,
-                              AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
-
-                AFSReleaseResource( AFSGlobalRoot->VolumeLock);
+                              lCount);
 
                 *VolumeCB = NULL;
 
@@ -3241,7 +3449,7 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Returning root PIOCtl access\n",
                               Irp);
 
-                InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
+                lCount = InterlockedIncrement( &AFSGlobalRoot->DirectoryCB->DirOpenReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                               AFS_TRACE_LEVEL_VERBOSE,
@@ -3249,9 +3457,7 @@ AFSParseName( IN PIRP Irp,
                               &AFSGlobalRoot->DirectoryCB->NameInformation.FileName,
                               AFSGlobalRoot->DirectoryCB,
                               NULL,
-                              AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
-
-                AFSReleaseResource( AFSGlobalRoot->VolumeLock);
+                              lCount);
 
                 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
 
@@ -3272,8 +3478,6 @@ AFSParseName( IN PIRP Irp,
                           Irp,
                           &uniComponentName);
 
-            AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
             //
             // Add in the full share name to pass back
             //
@@ -3308,7 +3512,7 @@ AFSParseName( IN PIRP Irp,
 
             ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
 
-            InterlockedIncrement( &pDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirEntry->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3316,7 +3520,7 @@ AFSParseName( IN PIRP Irp,
                           &pDirEntry->NameInformation.FileName,
                           pDirEntry,
                           NULL,
-                          pDirEntry->OpenReferenceCount);
+                          lCount);
 
             try_return( ntStatus = STATUS_SUCCESS);
         }
@@ -3355,7 +3559,8 @@ AFSParseName( IN PIRP Irp,
                 // a lookup in the short name tree
                 //
 
-                if( RtlIsNameLegalDOS8Dot3( &uniComponentName,
+                if( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
+                    RtlIsNameLegalDOS8Dot3( &uniComponentName,
                                             NULL,
                                             NULL))
                 {
@@ -3382,7 +3587,6 @@ AFSParseName( IN PIRP Irp,
 
                     if( !NT_SUCCESS( ntStatus))
                     {
-                        AFSReleaseResource( AFSGlobalRoot->VolumeLock);
 
                         if ( bIsAllShare &&
                              uniRemainingPath.Length == 0 &&
@@ -3403,6 +3607,7 @@ AFSParseName( IN PIRP Irp,
             AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
         }
 
+
         //
         // Be sure we are starting from the correct volume
         //
@@ -3418,6 +3623,38 @@ AFSParseName( IN PIRP Irp,
             pVolumeCB = pDirEntry->ObjectInformation->VolumeCB;
 
             //
+            // Init our name array
+            //
+
+            pNameArray = AFSInitNameArray( AFSGlobalRoot->DirectoryCB,
+                                           0);
+
+            if( pNameArray == NULL)
+            {
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSParseName (%08lX) Failed to initialize name array\n",
+                              Irp);
+
+                try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
+            }
+
+            ntStatus = AFSInsertNextElement( pNameArray,
+                                             pVolumeCB->DirectoryCB);
+
+            if ( ntStatus)
+            {
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSParseName (%08lX) Failed to insert name array element\n",
+                              Irp);
+
+                try_return( ntStatus);
+            }
+
+            //
             // In this case don't add back in the 'share' name since that is where we are
             // starting. Just put the leading slash back in
             //
@@ -3467,6 +3704,23 @@ AFSParseName( IN PIRP Irp,
             pVolumeCB = AFSGlobalRoot;
 
             //
+            // Init our name array
+            //
+
+            pNameArray = AFSInitNameArray( AFSGlobalRoot->DirectoryCB,
+                                           0);
+            if( pNameArray == NULL)
+            {
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSParseName (%08lX) Failed to initialize name array\n",
+                              Irp);
+
+                try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
+            }
+
+            //
             // Add back in the 'share' portion of the name since we will parse it out on return
             //
 
@@ -3509,7 +3763,7 @@ AFSParseName( IN PIRP Irp,
             uniRemainingPath.Length += sizeof( WCHAR);
             uniRemainingPath.MaximumLength += sizeof( WCHAR);
 
-            InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3517,39 +3771,14 @@ AFSParseName( IN PIRP Irp,
                           &pVolumeCB->DirectoryCB->NameInformation.FileName,
                           pVolumeCB->DirectoryCB,
                           NULL,
-                          pVolumeCB->DirectoryCB->OpenReferenceCount);
+                          lCount);
 
             //
             // Pass back the parent being the volume root
             //
 
             *ParentDirectoryCB = pVolumeCB->DirectoryCB;
-        }
-
-        //
-        // We only need the volume shared at this point
-        //
-
-        AFSConvertToShared( pVolumeCB->VolumeLock);
-
-        //
-        // Init our name array
-        //
-
-        pNameArray = AFSInitNameArray( pVolumeCB->DirectoryCB,
-                                       0);
 
-        if( pNameArray == NULL)
-        {
-
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                          AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSParseName (%08lX) Failed to initialize name array\n",
-                          Irp);
-
-            AFSReleaseResource( pVolumeCB->VolumeLock);
-
-            try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
 
         //
@@ -3568,13 +3797,13 @@ AFSParseName( IN PIRP Irp,
         // Increment our reference on the volume
         //
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+        lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSParseName Increment2 count on global volume %08lX Cnt %d\n",
                       pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
+                      lCount);
 
 try_exit:
 
@@ -3590,13 +3819,12 @@ try_exit:
                               &(*ParentDirectoryCB)->NameInformation.FileName,
                               *ParentDirectoryCB,
                               NULL,
-                              (*ParentDirectoryCB)->OpenReferenceCount);
+                              (*ParentDirectoryCB)->DirOpenReferenceCount);
             }
         }
 
         if( *VolumeCB != NULL)
         {
-
             ASSERT( (*VolumeCB)->VolumeReferenceCount > 1);
         }
 
@@ -3622,13 +3850,13 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     UNICODE_STRING uniName;
-    AFSFileID stFileID;
     AFSDirEnumEntry *pDirEnumEntry = NULL;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSDirHdr *pDirHdr = &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr;
     AFSDirectoryCB *pDirNode = NULL;
     UNICODE_STRING uniDirName, uniTargetName;
     AFSVolumeCB *pVolumeCB = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -3685,16 +3913,24 @@ AFSCheckCellName( IN GUID *AuthGroup,
         // OK, ask the CM about this component name
         //
 
-        stFileID = AFSGlobalRoot->ObjectInformation.FileId;
-
         ntStatus = AFSEvaluateTargetByName( AuthGroup,
-                                            &stFileID,
+                                            &AFSGlobalRoot->ObjectInformation,
                                             CellName,
                                             &pDirEnumEntry);
 
         if( !NT_SUCCESS( ntStatus))
         {
 
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                          AFS_TRACE_LEVEL_WARNING,
+                          "AFSCheckCellName entry %wZ does not exist parent FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
+                          CellName,
+                          AFSGlobalRoot->ObjectInformation.FileId.Cell,
+                          AFSGlobalRoot->ObjectInformation.FileId.Volume,
+                          AFSGlobalRoot->ObjectInformation.FileId.Vnode,
+                          AFSGlobalRoot->ObjectInformation.FileId.Unique,
+                          ntStatus);
+
             try_return( ntStatus);
         }
 
@@ -3717,12 +3953,6 @@ AFSCheckCellName( IN GUID *AuthGroup,
         {
 
             //
-            // We have the global root on entry so drop it now
-            //
-
-            AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
-            //
             // Build the root volume entry
             //
 
@@ -3732,20 +3962,12 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
             if( !NT_SUCCESS( ntStatus))
             {
-
-                //
-                // On failure this routine is expecting to hold the global root
-                //
-
-                AFSAcquireShared( AFSGlobalRoot->VolumeLock,
-                                  TRUE);
-
                 try_return( ntStatus);
             }
 
             *ShareDirEntry = pVolumeCB->DirectoryCB;
 
-            InterlockedIncrement( &pVolumeCB->DirectoryCB->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->DirectoryCB->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3753,18 +3975,26 @@ AFSCheckCellName( IN GUID *AuthGroup,
                           &pVolumeCB->DirectoryCB->NameInformation.FileName,
                           pVolumeCB->DirectoryCB,
                           NULL,
-                          pVolumeCB->DirectoryCB->OpenReferenceCount);
+                          lCount);
+
+            lCount = InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
 
-            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
         {
 
+            lCount = InterlockedIncrement( &pDirHdr->ContentIndex);
+
             pDirNode = AFSInitDirEntry( &AFSGlobalRoot->ObjectInformation,
                                         &uniDirName,
                                         &uniTargetName,
                                         pDirEnumEntry,
-                                        (ULONG)InterlockedIncrement( &pDirHdr->ContentIndex));
+                                        (ULONG)lCount);
 
             if( pDirNode == NULL)
             {
@@ -3849,19 +4079,19 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
             SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
 
-            InterlockedIncrement( &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount);
+            lCount = InterlockedIncrement( &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSCheckCellName Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
-                              &pDirNode->NameInformation.FileName,
-                              AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeCount,
-                              AFSGlobalRoot->ObjectInformation.FileId.Cell,
-                              AFSGlobalRoot->ObjectInformation.FileId.Volume,
-                              AFSGlobalRoot->ObjectInformation.FileId.Vnode,
-                              AFSGlobalRoot->ObjectInformation.FileId.Unique);
+                          &pDirNode->NameInformation.FileName,
+                          lCount,
+                          AFSGlobalRoot->ObjectInformation.FileId.Cell,
+                          AFSGlobalRoot->ObjectInformation.FileId.Volume,
+                          AFSGlobalRoot->ObjectInformation.FileId.Vnode,
+                          AFSGlobalRoot->ObjectInformation.FileId.Unique);
 
-            InterlockedIncrement( &pDirNode->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pDirNode->DirOpenReferenceCount);
 
             AFSDbgLogMsg( AFS_SUBSYSTEM_DIRENTRY_REF_COUNTING,
                           AFS_TRACE_LEVEL_VERBOSE,
@@ -3869,7 +4099,7 @@ AFSCheckCellName( IN GUID *AuthGroup,
                           &pDirNode->NameInformation.FileName,
                           pDirNode,
                           NULL,
-                          pDirNode->OpenReferenceCount);
+                          lCount);
 
             AFSReleaseResource( AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr.TreeLock);
 
@@ -3885,7 +4115,7 @@ try_exit:
         if( pDirEnumEntry != NULL)
         {
 
-            AFSExFreePool( pDirEnumEntry);
+            AFSExFreePoolWithTag( pDirEnumEntry, AFS_GENERIC_MEMORY_31_TAG);
         }
     }
 
@@ -3906,6 +4136,8 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
     ULONGLONG       ullIndex = 0;
     AFSVolumeCB *pVolumeCB = NULL;
     AFSFileID stTargetFileID;
+    LONG lCount;
+    BOOLEAN bReleaseVolumeLock = FALSE;
 
     __Enter
     {
@@ -3973,7 +4205,7 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
                               DirectoryCB->ObjectInformation->FileId.Vnode,
                               DirectoryCB->ObjectInformation->FileId.Unique);
 
-                try_return( ntStatus = STATUS_ACCESS_DENIED);
+                try_return( ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED);
             }
 
             AFSAcquireExcl( &DirectoryCB->NonPaged->Lock,
@@ -4060,40 +4292,46 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
 
                 try_return( ntStatus);
             }
-        }
-        else
-        {
 
             //
-            // Check if this volume has been deleted or taken offline
+            // pVolumeCB->VolumeLock held exclusive and
+            // pVolumeCB->VolumeReferenceCount has been incremented
+            // pVolumeCB->RootFcb == NULL
             //
 
-            if( BooleanFlagOn( pVolumeCB->Flags, AFS_VOLUME_FLAGS_OFFLINE))
-            {
-
-                AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
-
-                try_return( ntStatus = STATUS_FILE_IS_OFFLINE);
-            }
+            bReleaseVolumeLock = TRUE;
+        }
+        else
+        {
 
             //
-            // Just to ensure that things don't get torn down AND we don't create a
-            // deadlock with invalidation
+            // AFSInitVolume returns with a VolumeReferenceCount
+            // obtain one to match
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
-
-            AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
-            AFSAcquireExcl( pVolumeCB->VolumeLock,
-                            TRUE);
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSBuildMountPointTarget Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
         }
 
         if( pVolumeCB->RootFcb == NULL)
         {
 
+            if ( bReleaseVolumeLock == FALSE)
+            {
+
+                AFSAcquireExcl( pVolumeCB->VolumeLock,
+                                TRUE);
+
+                bReleaseVolumeLock = TRUE;
+            }
+
             //
             // Initialize the root fcb for this volume
             //
@@ -4104,6 +4342,14 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
             if( !NT_SUCCESS( ntStatus))
             {
 
+                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);
@@ -4116,7 +4362,11 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
             AFSReleaseResource( &pVolumeCB->RootFcb->NPFcb->Resource);
         }
 
-        AFSConvertToShared( pVolumeCB->VolumeLock);
+        if ( bReleaseVolumeLock == TRUE)
+        {
+
+            AFSReleaseResource( pVolumeCB->VolumeLock);
+        }
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
@@ -4127,14 +4377,6 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
                       pVolumeCB->ObjectInformation.FileId.Vnode,
                       pVolumeCB->ObjectInformation.FileId.Unique);
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
-
-        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
-                      AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSBuildMountPointTarget Increment count on volume %08lX Cnt %d\n",
-                      pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
-
         *TargetVolumeCB = pVolumeCB;
 
 try_exit:
@@ -4142,7 +4384,7 @@ try_exit:
         if( pDirEntry)
         {
 
-            AFSExFreePool( pDirEntry);
+            AFSExFreePoolWithTag( pDirEntry, AFS_GENERIC_MEMORY_2_TAG);
         }
     }
 
@@ -4161,6 +4403,8 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
     UNICODE_STRING uniDirName, uniTargetName;
     ULONGLONG       ullIndex = 0;
     AFSVolumeCB *pVolumeCB = NULL;
+    LONG lCount;
+    BOOLEAN bReleaseVolumeLock = FALSE;
 
     __Enter
     {
@@ -4212,7 +4456,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,
@@ -4228,29 +4472,47 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
 
                 try_return( ntStatus);
             }
+
+            //
+            // pVolumeCB->VolumeLock is held exclusive
+            // pVolumeCB->VolumeReferenceCount has been incremented
+            // pVolumeCB->RootFcb == NULL
+            //
+
+            bReleaseVolumeLock = TRUE;
         }
         else
         {
 
             //
-            // Just to ensure that things don't get torn down AND we don't create a
-            // deadlock with invalidation
+            // AFSInitVolume returns with a VolumeReferenceCount
+            // obtain one to match
             //
 
-            InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
+            lCount = InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
-            AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
-
-            AFSAcquireExcl( pVolumeCB->VolumeLock,
-                            TRUE);
+            AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSBuildRootVolume Increment count on volume %08lX Cnt %d\n",
+                          pVolumeCB,
+                          lCount);
 
-            InterlockedDecrement( &pVolumeCB->VolumeReferenceCount);
+            AFSReleaseResource( &pDevExt->Specific.RDR.VolumeTreeLock);
         }
 
 
         if( pVolumeCB->RootFcb == NULL)
         {
 
+            if ( bReleaseVolumeLock == FALSE)
+            {
+
+                AFSAcquireExcl( pVolumeCB->VolumeLock,
+                                TRUE);
+
+                bReleaseVolumeLock = TRUE;
+            }
+
             //
             // Initialize the root fcb for this volume
             //
@@ -4261,6 +4523,14 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
             if( !NT_SUCCESS( ntStatus))
             {
 
+                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);
@@ -4273,7 +4543,11 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
             AFSReleaseResource( &pVolumeCB->RootFcb->NPFcb->Resource);
         }
 
-        AFSConvertToShared( pVolumeCB->VolumeLock);
+        if ( bReleaseVolumeLock == TRUE)
+        {
+
+            AFSReleaseResource( pVolumeCB->VolumeLock);
+        }
 
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
@@ -4284,14 +4558,6 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
                       pVolumeCB->ObjectInformation.FileId.Vnode,
                       pVolumeCB->ObjectInformation.FileId.Unique);
 
-        InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
-
-        AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
-                      AFS_TRACE_LEVEL_VERBOSE,
-                      "AFSBuildRootVolume Increment count on volume %08lX Cnt %d\n",
-                      pVolumeCB,
-                      pVolumeCB->VolumeReferenceCount);
-
         *TargetVolumeCB = pVolumeCB;
 
 try_exit:
@@ -4312,6 +4578,7 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
     NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
     UNICODE_STRING uniReparseName;
     UNICODE_STRING uniMUPDeviceName;
+    UNICODE_STRING uniIOMgrDeviceName;
     AFSDirEnumEntry *pDirEntry = NULL;
 
     __Enter
@@ -4324,6 +4591,9 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
         RtlInitUnicodeString( &uniMUPDeviceName,
                               L"\\Device\\MUP");
 
+        RtlInitUnicodeString( &uniIOMgrDeviceName,
+                              L"\\??\\");
+
         uniReparseName.Length = 0;
         uniReparseName.Buffer = NULL;
 
@@ -4356,7 +4626,7 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
                 if( NT_SUCCESS( ntStatus))
                 {
 
-                    ntStatus = STATUS_ACCESS_DENIED;
+                    ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
                 }
 
                 try_return( ntStatus);
@@ -4442,18 +4712,32 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
         // Start building the name
         //
 
-        RtlCopyMemory( uniReparseName.Buffer,
-                       uniMUPDeviceName.Buffer,
-                       uniMUPDeviceName.Length);
+        if ( DirEntry->NameInformation.TargetName.Buffer[ 0] != L'\\' &&
+             DirEntry->NameInformation.TargetName.Buffer[ 1] == L':')
+        {
 
-        uniReparseName.Length = uniMUPDeviceName.Length;
+            RtlCopyMemory( uniReparseName.Buffer,
+                           uniIOMgrDeviceName.Buffer,
+                           uniIOMgrDeviceName.Length);
 
-        if( DirEntry->NameInformation.TargetName.Buffer[ 0] != L'\\')
+            uniReparseName.Length = uniIOMgrDeviceName.Length;
+        }
+        else
         {
 
-            uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)] = L'\\';
+            RtlCopyMemory( uniReparseName.Buffer,
+                           uniMUPDeviceName.Buffer,
+                           uniMUPDeviceName.Length);
+
+            uniReparseName.Length = uniMUPDeviceName.Length;
 
-            uniReparseName.Length += sizeof( WCHAR);
+            if( DirEntry->NameInformation.TargetName.Buffer[ 0] != L'\\')
+            {
+
+                uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)] = L'\\';
+
+                uniReparseName.Length += sizeof( WCHAR);
+            }
         }
 
         RtlCopyMemory( &uniReparseName.Buffer[ uniReparseName.Length/sizeof( WCHAR)],
@@ -4491,7 +4775,7 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
         if( FileObject->FileName.Buffer != NULL)
         {
 
-            AFSExFreePool( FileObject->FileName.Buffer);
+            AFSExFreePoolWithTag( FileObject->FileName.Buffer, 0);
         }
 
         FileObject->FileName = uniReparseName;
@@ -4517,7 +4801,7 @@ try_exit:
         if ( pDirEntry)
         {
 
-            AFSExFreePool( pDirEntry);
+            AFSExFreePoolWithTag( pDirEntry, AFS_GENERIC_MEMORY_2_TAG);
         }
     }