Windows: SetFileRenameInfo Improve Error Handling
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSFileInfo.cpp
index 87d21c8..25d4b79 100644 (file)
@@ -139,6 +139,15 @@ AFSQueryFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
             try_return( ntStatus);
         }
 
+        else if( pFcb->Header.NodeTypeCode == AFS_INVALID_FCB)
+        {
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSQueryFileInfo request against Invalid Fcb\n");
+
+            try_return( ntStatus = STATUS_ACCESS_DENIED);
+        }
+
         //
         // Process the request
         //
@@ -316,6 +325,7 @@ AFSQueryFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
                 break;
             }
 
+            case FileNormalizedNameInformation:
             case FileNameInformation:
             {
 
@@ -432,13 +442,15 @@ try_exit:
             }
         }
     }
-    __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
+    __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
     {
 
         AFSDbgLogMsg( 0,
                       0,
                       "EXCEPTION - AFSQueryFileInfo\n");
 
+        AFSDumpTraceFilesFnc();
+
         ntStatus = STATUS_UNSUCCESSFUL;
 
         if( bReleaseMain)
@@ -556,6 +568,16 @@ AFSSetFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
                           "AFSSetFileInfo Request failed due to read only volume\n",
                           Irp);
 
+            try_return( ntStatus = STATUS_MEDIA_WRITE_PROTECTED);
+        }
+
+        if( pFcb->Header.NodeTypeCode == AFS_INVALID_FCB &&
+            FileInformationClass != FileDispositionInformation)
+        {
+            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetFileInfo request against Invalid Fcb\n");
+
             try_return( ntStatus = STATUS_ACCESS_DENIED);
         }
 
@@ -672,7 +694,7 @@ try_exit:
 
             ntStatus = AFSUpdateFileInformation( &stParentFileId,
                                                  pFcb->ObjectInformation,
-                                                 &pFcb->AuthGroup);
+                                                 &pCcb->AuthGroup);
 
             if( !NT_SUCCESS( ntStatus))
             {
@@ -720,14 +742,22 @@ try_exit:
             }
         }
     }
-    __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
+    __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
     {
 
         AFSDbgLogMsg( 0,
                       0,
                       "EXCEPTION - AFSSetFileInfo\n");
 
+        AFSDumpTraceFilesFnc();
+
         ntStatus = STATUS_UNSUCCESSFUL;
+
+        if( bReleaseMain)
+        {
+
+            AFSReleaseResource( &pFcb->NPFcb->Resource);
+        }
     }
 
     AFSCompleteRequest( Irp,
@@ -795,18 +825,42 @@ AFSQueryBasicInfo( IN PIRP Irp,
             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
                                                        DirectoryCB,
                                                        &uniParentPath,
-                                                       NULL,
+                                                       pCcb->NameArray,
+                                                       &pCcb->AuthGroup,
                                                        &stFileInfo)))
             {
-                ulFileAttribs = stFileInfo.FileAttributes;
 
-                ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
+                {
+
+                    ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+                else
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+
+                if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
+                }
             }
 
             AFSAcquireShared( &pFcb->NPFcb->Resource,
                               TRUE);
         }
 
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE_2,
+                      "AFSQueryBasicInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
+                      &pCcb->DirectoryCB->NameInformation.FileName,
+                      pCcb->DirectoryCB->ObjectInformation->FileType,
+                      pCcb->DirectoryCB->ObjectInformation->FileAttributes,
+                      ulFileAttribs);
+
         Buffer->CreationTime = DirectoryCB->ObjectInformation->CreationTime;
         Buffer->LastAccessTime = DirectoryCB->ObjectInformation->LastAccessTime;
         Buffer->LastWriteTime = DirectoryCB->ObjectInformation->LastWriteTime;
@@ -892,16 +946,41 @@ AFSQueryStandardInfo( IN PIRP Irp,
             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
                                                        DirectoryCB,
                                                        &uniParentPath,
-                                                       NULL,
+                                                       pCcb->NameArray,
+                                                       &pCcb->AuthGroup,
                                                        &stFileInfo)))
             {
-                ulFileAttribs = stFileInfo.FileAttributes;
+
+                if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
+                {
+
+                    ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+                else
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+
+                if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
+                }
             }
 
             AFSAcquireShared( &pFcb->NPFcb->Resource,
                               TRUE);
         }
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE_2,
+                      "AFSQueryStandardInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
+                      &pCcb->DirectoryCB->NameInformation.FileName,
+                      pCcb->DirectoryCB->ObjectInformation->FileType,
+                      pCcb->DirectoryCB->ObjectInformation->FileAttributes,
+                      ulFileAttribs);
+
         Buffer->Directory = BooleanFlagOn( ulFileAttribs, FILE_ATTRIBUTE_DIRECTORY);
 
         *Length -= sizeof( FILE_STANDARD_INFORMATION);
@@ -1366,18 +1445,41 @@ AFSQueryNetworkInfo( IN PIRP Irp,
             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
                                                        DirectoryCB,
                                                        &uniParentPath,
-                                                       NULL,
+                                                       pCcb->NameArray,
+                                                       &pCcb->AuthGroup,
                                                        &stFileInfo)))
             {
-                ulFileAttribs = stFileInfo.FileAttributes;
 
-                ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
+                {
+
+                    ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+                else
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+
+                if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
+                }
             }
 
             AFSAcquireShared( &pFcb->NPFcb->Resource,
                               TRUE);
         }
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE_2,
+                      "AFSQueryNetworkInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
+                      &pCcb->DirectoryCB->NameInformation.FileName,
+                      pCcb->DirectoryCB->ObjectInformation->FileType,
+                      pCcb->DirectoryCB->ObjectInformation->FileAttributes,
+                      ulFileAttribs);
+
         Buffer->CreationTime.QuadPart = DirectoryCB->ObjectInformation->CreationTime.QuadPart;
         Buffer->LastAccessTime.QuadPart = DirectoryCB->ObjectInformation->LastAccessTime.QuadPart;
         Buffer->LastWriteTime.QuadPart = DirectoryCB->ObjectInformation->LastWriteTime.QuadPart;
@@ -1534,18 +1636,41 @@ AFSQueryAttribTagInfo( IN PIRP Irp,
             if( NT_SUCCESS( AFSRetrieveFileAttributes( pParentDirectoryCB,
                                                        DirectoryCB,
                                                        &uniParentPath,
-                                                       NULL,
+                                                       pCcb->NameArray,
+                                                       &pCcb->AuthGroup,
                                                        &stFileInfo)))
             {
-                ulFileAttribs = stFileInfo.FileAttributes;
 
-                ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                if ( ulFileAttribs == FILE_ATTRIBUTE_NORMAL)
+                {
+
+                    ulFileAttribs = FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+                else
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_REPARSE_POINT;
+                }
+
+                if ( stFileInfo.FileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+                {
+
+                    ulFileAttribs |= FILE_ATTRIBUTE_DIRECTORY;
+                }
             }
 
             AFSAcquireShared( &pFcb->NPFcb->Resource,
                               TRUE);
         }
 
+        AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE_2,
+                      "AFSAttribTagInfo %wZ Type 0x%x Attrib 0x%x -> 0x%x\n",
+                      &pCcb->DirectoryCB->NameInformation.FileName,
+                      pCcb->DirectoryCB->ObjectInformation->FileType,
+                      pCcb->DirectoryCB->ObjectInformation->FileAttributes,
+                      ulFileAttribs);
+
         Buffer->FileAttributes = ulFileAttribs;
 
         if( DirectoryCB->NameInformation.FileName.Buffer[ 0] == L'.' &&
@@ -1566,7 +1691,7 @@ AFSQueryAttribTagInfo( IN PIRP Irp,
 
         if( BooleanFlagOn( DirectoryCB->ObjectInformation->FileAttributes, FILE_ATTRIBUTE_REPARSE_POINT))
         {
-            Buffer->ReparseTag = IO_REPARSE_TAG_OPENAFS_DFS;
+            Buffer->ReparseTag = IO_REPARSE_TAG_SURROGATE|IO_REPARSE_TAG_OPENAFS_DFS;
         }
 
         *Length -= sizeof( FILE_ATTRIBUTE_TAG_INFORMATION);
@@ -1894,6 +2019,7 @@ AFSSetDispositionInfo( IN PIRP Irp,
             //
 
             ntStatus = AFSNotifyDelete( DirectoryCB,
+                                        &pCcb->AuthGroup,
                                         TRUE);
 
             if( !NT_SUCCESS( ntStatus))
@@ -1937,8 +2063,16 @@ AFSSetDispositionInfo( IN PIRP Irp,
 
                     try_return( ntStatus = STATUS_DIRECTORY_NOT_EMPTY);
                 }
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSSetDispositionInfo Setting PENDING_DELETE on DirEntry  %p Name %wZ\n",
+                              DirectoryCB,
+                              &DirectoryCB->NameInformation.FileName);
+
+                SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
             }
-            else
+            else if( pFcb->Header.NodeTypeCode == AFS_FILE_FCB)
             {
 
                 //
@@ -1958,26 +2092,36 @@ AFSSetDispositionInfo( IN PIRP Irp,
                 }
 
                 //
+                // Set PENDING_DELETE before CcPurgeCacheSection to avoid a
+                // deadlock with Trend Micro's Enterprise anti-virus product
+                // which attempts to open the file which is being deleted.
+                //
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSSetDispositionInfo Setting PENDING_DELETE on DirEntry %p Name %wZ\n",
+                              DirectoryCB,
+                              &DirectoryCB->NameInformation.FileName);
+
+                SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
+
+                //
                 // Purge the cache as well
                 //
 
                 if( pFcb->NPFcb->SectionObjectPointers.DataSectionObject != NULL)
                 {
 
-                    CcPurgeCacheSection( &pFcb->NPFcb->SectionObjectPointers,
-                                         NULL,
-                                         0,
-                                         TRUE);
+                    if ( !CcPurgeCacheSection( &pFcb->NPFcb->SectionObjectPointers,
+                                               NULL,
+                                               0,
+                                               TRUE))
+                    {
+
+                        SetFlag( pFcb->Flags, AFS_FCB_FLAG_PURGE_ON_CLOSE);
+                    }
                 }
             }
-
-            AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                          AFS_TRACE_LEVEL_VERBOSE,
-                          "AFSSetDispositionInfo Setting PENDING_DELETE on DirEntry  %p Name %wZ\n",
-                          DirectoryCB,
-                          &DirectoryCB->NameInformation.FileName);
-
-            SetFlag( pCcb->DirectoryCB->Flags, AFS_DIR_ENTRY_PENDING_DELETE);
         }
         else
         {
@@ -2004,14 +2148,16 @@ AFSSetRenameInfo( IN PIRP Irp)
 {
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
+    AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation( Irp);
     IO_STATUS_BLOCK stIoSb = {0,0};
     AFSFcb *pSrcFcb = NULL, *pTargetDcb = NULL, *pTargetFcb = NULL;
     AFSCcb *pSrcCcb = NULL, *pTargetDirCcb = NULL;
     PFILE_OBJECT pSrcFileObj = pIrpSp->FileObject;
     PFILE_OBJECT pTargetFileObj = pIrpSp->Parameters.SetFile.FileObject;
+    PFILE_OBJECT pTargetParentFileObj = NULL;
     PFILE_RENAME_INFORMATION pRenameInfo = NULL;
-    UNICODE_STRING uniTargetName, uniSourceName;
+    UNICODE_STRING uniTargetName, uniSourceName, uniTargetParentName;
     BOOLEAN bReplaceIfExists = FALSE;
     UNICODE_STRING uniShortName;
     AFSDirectoryCB *pTargetDirEntry = NULL;
@@ -2021,13 +2167,13 @@ AFSSetRenameInfo( IN PIRP Irp)
     AFSObjectInfoCB *pSrcParentObject = NULL, *pTargetParentObject = NULL;
     AFSFileID stNewFid, stTmpTargetFid;
     ULONG ulNotificationAction = 0, ulNotifyFilter = 0;
-    UNICODE_STRING uniFullTargetPath;
+    UNICODE_STRING uniFullTargetName;
     BOOLEAN bCommonParent = FALSE;
-    ULONG oldFileIndex;
-    BOOLEAN bReleaseVolumeLock = FALSE;
     BOOLEAN bReleaseTargetDirLock = FALSE;
     BOOLEAN bReleaseSourceDirLock = FALSE;
+    BOOLEAN bDereferenceTargetParentObject = FALSE;
     PERESOURCE  pSourceDirLock = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -2038,6 +2184,7 @@ AFSSetRenameInfo( IN PIRP Irp)
         pSrcCcb = (AFSCcb *)pSrcFileObj->FsContext2;
 
         pSrcObject = pSrcFcb->ObjectInformation;
+        pSrcParentObject = pSrcFcb->ObjectInformation->ParentObjectInformation;
 
         //
         // Perform some basic checks to ensure FS integrity
@@ -2075,20 +2222,15 @@ AFSSetRenameInfo( IN PIRP Irp)
                 try_return( ntStatus = STATUS_ACCESS_DENIED);
             }
         }
-        else
-        {
 
-            if( pSrcFcb->OpenHandleCount > 1)
-            {
+        //
+        // Extract off the final component name from the Fcb
+        //
 
-                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                              AFS_TRACE_LEVEL_ERROR,
-                              "AFSSetRenameInfo Attempt to rename directory with open references %wZ\n",
-                              &pSrcCcb->DirectoryCB->NameInformation.FileName);
+        uniSourceName.Length = (USHORT)pSrcCcb->DirectoryCB->NameInformation.FileName.Length;
+        uniSourceName.MaximumLength = uniSourceName.Length;
 
-                try_return( ntStatus = STATUS_ACCESS_DENIED);
-            }
-        }
+        uniSourceName.Buffer = pSrcCcb->DirectoryCB->NameInformation.FileName.Buffer;
 
         //
         // Resolve the target fileobject
@@ -2097,19 +2239,58 @@ AFSSetRenameInfo( IN PIRP Irp)
         if( pTargetFileObj == NULL)
         {
 
-            //
-            // This is a simple rename. Here the target directory is the same as the source parent directory
-            // and the name is retrieved from the system buffer information
-            //
-
             pRenameInfo = (PFILE_RENAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
 
-            pTargetParentObject = pSrcFcb->ObjectInformation->ParentObjectInformation;
+            if ( pRenameInfo->RootDirectory)
+            {
 
-            pTargetDcb = pTargetParentObject->Fcb;
+                AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                              AFS_TRACE_LEVEL_ERROR,
+                              "AFSSetRenameInfo Handle provided but no FileObject ntStatus INVALID_PARAMETER\n");
+
+                try_return( ntStatus = STATUS_INVALID_PARAMETER);
+            }
+            else
+            {
 
-            uniTargetName.Length = (USHORT)pRenameInfo->FileNameLength;
-            uniTargetName.Buffer = (PWSTR)&pRenameInfo->FileName;
+                uniFullTargetName.Length = (USHORT)pRenameInfo->FileNameLength;
+
+                uniFullTargetName.Buffer = (PWSTR)&pRenameInfo->FileName;
+
+                AFSRetrieveFinalComponent( &uniFullTargetName,
+                                           &uniTargetName);
+
+                AFSRetrieveParentPath( &uniFullTargetName,
+                                       &uniTargetParentName);
+
+                if ( uniTargetParentName.Length == 0)
+                {
+
+                    //
+                    // This is a simple rename. Here the target directory is the same as the source parent directory
+                    // and the name is retrieved from the system buffer information
+                    //
+
+                    pTargetParentObject = pSrcParentObject;
+                }
+                else
+                {
+                    //
+                    // uniTargetParentName contains the directory the renamed object
+                    // will be moved to.  Must obtain the TargetParentObject.
+                    //
+
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
+                                  AFS_TRACE_LEVEL_ERROR,
+                                  "AFSSetRenameInfo Attempt to move %wZ to %wZ -- not yet supported (NOT_SAME_DEVICE)\n",
+                                  &pSrcCcb->DirectoryCB->NameInformation.FileName,
+                                  &uniFullTargetName);
+
+                    try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
+                }
+            }
+
+            pTargetDcb = pTargetParentObject->Fcb;
         }
         else
         {
@@ -2133,6 +2314,31 @@ AFSSetRenameInfo( IN PIRP Irp)
         }
 
         //
+        // The quick check to see if they are not really performing a rename
+        // Do the names match? Only do this where the parent directories are
+        // the same
+        //
+
+        if( pTargetParentObject == pSrcParentObject)
+        {
+
+            if( FsRtlAreNamesEqual( &uniTargetName,
+                                    &uniSourceName,
+                                    FALSE,
+                                    NULL))
+            {
+                try_return( ntStatus = STATUS_SUCCESS);
+            }
+
+            bCommonParent = TRUE;
+        }
+        else
+        {
+
+            bCommonParent = FALSE;
+        }
+
+        //
         // We do not allow cross-volume renames to occur
         //
 
@@ -2147,11 +2353,6 @@ AFSSetRenameInfo( IN PIRP Irp)
             try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
         }
 
-        AFSAcquireExcl( pTargetParentObject->VolumeCB->VolumeLock,
-                        TRUE);
-
-        bReleaseVolumeLock = TRUE;
-
         ulTargetCRC = AFSGenerateCRC( &uniTargetName,
                                       FALSE);
 
@@ -2160,14 +2361,14 @@ AFSSetRenameInfo( IN PIRP Irp)
 
         bReleaseTargetDirLock = TRUE;
 
-        if( pTargetParentObject != pSrcFcb->ObjectInformation->ParentObjectInformation)
+        if( pTargetParentObject != pSrcParentObject)
         {
-            AFSAcquireExcl( pSrcFcb->ObjectInformation->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock,
+            AFSAcquireExcl( pSrcParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock,
                             TRUE);
 
             bReleaseSourceDirLock = TRUE;
 
-            pSourceDirLock = pSrcFcb->ObjectInformation->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.TreeLock;
+            pSourceDirLock = pSrcParentObject->Specific.Directory.DirectoryNodeHdr.TreeLock;
         }
 
         AFSLocateCaseSensitiveDirEntry( pTargetParentObject->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
@@ -2189,7 +2390,8 @@ AFSSetRenameInfo( IN PIRP Irp)
                                               &pTargetDirEntry);
         }
 
-        if( pTargetDirEntry == NULL && RtlIsNameLegalDOS8Dot3( &uniTargetName,
+        if ( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
+             pTargetDirEntry == NULL && RtlIsNameLegalDOS8Dot3( &uniTargetName,
                                                                NULL,
                                                                NULL))
         {
@@ -2210,7 +2412,7 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( pTargetParentObject == pTargetDirEntry->ObjectInformation->ParentObjectInformation);
 
-            InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
 
             if( !bReplaceIfExists)
             {
@@ -2244,42 +2446,8 @@ AFSSetRenameInfo( IN PIRP Irp)
         else
         {
             AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
-                          AFS_TRACE_LEVEL_ERROR,
-                          "AFSSetRenameInfo Target Target does NOT exist, normal rename\n");
-        }
-
-        //
-        // Extract off the final component name from the Fcb
-        //
-
-        uniSourceName.Length = (USHORT)pSrcCcb->DirectoryCB->NameInformation.FileName.Length;
-        uniSourceName.MaximumLength = uniSourceName.Length;
-
-        uniSourceName.Buffer = pSrcCcb->DirectoryCB->NameInformation.FileName.Buffer;
-
-        //
-        // The quick check to see if they are not really performing a rename
-        // Do the names match? Only do this where the parent directories are
-        // the same
-        //
-
-        if( pTargetParentObject == pSrcFcb->ObjectInformation->ParentObjectInformation)
-        {
-
-            bCommonParent = TRUE;
-
-            if( FsRtlAreNamesEqual( &uniTargetName,
-                                    &uniSourceName,
-                                    FALSE,
-                                    NULL))
-            {
-                try_return( ntStatus = STATUS_SUCCESS);
-            }
-        }
-        else
-        {
-
-            bCommonParent = FALSE;
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetRenameInfo Target does NOT exist, normal rename\n");
         }
 
         //
@@ -2292,27 +2460,13 @@ AFSSetRenameInfo( IN PIRP Irp)
                                     pSrcCcb->DirectoryCB,
                                     !bCommonParent);
 
-        oldFileIndex = pSrcCcb->DirectoryCB->FileIndex;
-
-        if( !bCommonParent)
-        {
-
-            //
-            // We always need to update the FileIndex since this entry will be put at the 'end'
-            // of the enumeraiton list. If we don't it will cause recursion ... We do this
-            // here to cover any failures which might occur below
-            //
-
-            pSrcCcb->DirectoryCB->FileIndex =
-                            (ULONG)InterlockedIncrement( &pTargetDcb->ObjectInformation->ParentObjectInformation->Specific.Directory.DirectoryNodeHdr.ContentIndex);
-        }
-
         //
         // OK, this is a simple rename. Issue the rename
         // request to the service.
         //
 
         ntStatus = AFSNotifyRename( pSrcFcb->ObjectInformation,
+                                    &pSrcCcb->AuthGroup,
                                     pSrcFcb->ObjectInformation->ParentObjectInformation,
                                     pTargetDcb->ObjectInformation,
                                     pSrcCcb->DirectoryCB,
@@ -2326,7 +2480,6 @@ AFSSetRenameInfo( IN PIRP Irp)
             // Attempt to re-insert the directory entry
             //
 
-            pSrcCcb->DirectoryCB->FileIndex = oldFileIndex;
             AFSInsertDirectoryNode( pSrcFcb->ObjectInformation->ParentObjectInformation,
                                     pSrcCcb->DirectoryCB,
                                     !bCommonParent);
@@ -2387,7 +2540,6 @@ AFSSetRenameInfo( IN PIRP Irp)
             // Attempt to re-insert the directory entry
             //
 
-            pSrcCcb->DirectoryCB->FileIndex = oldFileIndex;
             AFSInsertDirectoryNode( pSrcFcb->ObjectInformation->ParentObjectInformation,
                                     pSrcCcb->DirectoryCB,
                                     !bCommonParent);
@@ -2410,6 +2562,9 @@ AFSSetRenameInfo( IN PIRP Irp)
                             &stNewFid))
         {
 
+            AFSAcquireExcl( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock,
+                            TRUE);
+
             //
             // Remove the old information entry
             //
@@ -2435,9 +2590,20 @@ AFSSetRenameInfo( IN PIRP Irp)
             else
             {
 
-                AFSInsertHashEntry( pSrcObject->VolumeCB->ObjectInfoTree.TreeHead,
-                                    &pSrcObject->TreeEntry);
+                if ( !NT_SUCCESS( AFSInsertHashEntry( pSrcObject->VolumeCB->ObjectInfoTree.TreeHead,
+                                                     &pSrcObject->TreeEntry)))
+                {
+
+                    //
+                    // Lost a race, an ObjectInfo object already exists for this FID.
+                    // Let this copy be garbage collected.
+                    //
+
+                    ClearFlag( pSrcObject->Flags, AFS_OBJECT_INSERTED_HASH_TREE);
+                }
             }
+
+            AFSReleaseResource( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock);
         }
 
         //
@@ -2450,7 +2616,8 @@ AFSSetRenameInfo( IN PIRP Irp)
         pSrcCcb->DirectoryCB->CaseInsensitiveTreeEntry.HashIndex = AFSGenerateCRC( &pSrcCcb->DirectoryCB->NameInformation.FileName,
                                                                                    TRUE);
 
-        if( pSrcCcb->DirectoryCB->NameInformation.ShortNameLength > 0 &&
+        if( !BooleanFlagOn( pDeviceExt->DeviceFlags, AFS_DEVICE_FLAG_DISABLE_SHORTNAMES) &&
+            pSrcCcb->DirectoryCB->NameInformation.ShortNameLength > 0 &&
             !RtlIsNameLegalDOS8Dot3( &pSrcCcb->DirectoryCB->NameInformation.FileName,
                                      NULL,
                                      NULL))
@@ -2500,13 +2667,13 @@ AFSSetRenameInfo( IN PIRP Irp)
         if( pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation != pTargetParentObject)
         {
 
-            InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
+            lCount = InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenHandleCount);
 
-            InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
+            lCount = InterlockedDecrement( &pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation->Specific.Directory.ChildOpenReferenceCount);
 
-            InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenHandleCount);
+            lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenHandleCount);
 
-            InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetParentObject->Specific.Directory.ChildOpenReferenceCount);
 
             pSrcCcb->DirectoryCB->ObjectInformation->ParentObjectInformation = pTargetParentObject;
 
@@ -2576,9 +2743,9 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( pTargetDirEntry->OpenReferenceCount > 0);
 
-            InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount); // The count we added above
+            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount); // The count we added above
 
-            if( pTargetDirEntry->OpenReferenceCount == 0)
+            if( lCount == 0)
             {
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
@@ -2611,12 +2778,7 @@ try_exit:
         if( pTargetDirEntry != NULL)
         {
 
-            InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
-        }
-
-        if( bReleaseVolumeLock)
-        {
-            AFSReleaseResource( pTargetParentObject->VolumeCB->VolumeLock);
+            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
         }
 
         if( bReleaseTargetDirLock)
@@ -2630,6 +2792,12 @@ try_exit:
         }
     }
 
+    if ( bDereferenceTargetParentObject)
+    {
+
+        ObDereferenceObject( pTargetParentFileObj);
+    }
+
     return ntStatus;
 }
 
@@ -2700,6 +2868,7 @@ AFSSetAllocationInfo( IN PIRP Irp,
             //
             // If this is a truncation we need to grab the paging IO resource.
             //
+
             AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
                           AFS_TRACE_LEVEL_VERBOSE,
                           "AFSSetAllocationInfo Acquiring Fcb PagingIo lock %08lX EXCL %08lX\n",
@@ -2711,6 +2880,13 @@ AFSSetAllocationInfo( IN PIRP Irp,
 
             bReleasePaging = TRUE;
 
+            //
+            // Must drop the Fcb Resource.  When changing the file size
+            // a deadlock can occur with Trend Micro's filter if the file
+            // size is set to zero.
+            //
+
+            AFSReleaseResource( &pFcb->NPFcb->Resource);
 
             pFcb->Header.AllocationSize = pBuffer->AllocationSize;
 
@@ -2741,6 +2917,26 @@ AFSSetAllocationInfo( IN PIRP Irp,
         //
         // Tell Cc if allocation is increased.
         //
+
+        AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                      AFS_TRACE_LEVEL_VERBOSE,
+                      "AFSSetAllocationInfo Acquiring Fcb PagingIo lock %08lX EXCL %08lX\n",
+                      &pFcb->NPFcb->PagingResource,
+                      PsGetCurrentThread());
+
+        AFSAcquireExcl( &pFcb->NPFcb->PagingResource,
+                        TRUE);
+
+        bReleasePaging = TRUE;
+
+        //
+        // Must drop the Fcb Resource.  When changing the file size
+        // a deadlock can occur with Trend Micro's filter if the file
+        // size is set to zero.
+        //
+
+        AFSReleaseResource( &pFcb->NPFcb->Resource);
+
         bTellCc = pBuffer->AllocationSize.QuadPart > pFcb->Header.AllocationSize.QuadPart;
 
         pFcb->Header.AllocationSize = pBuffer->AllocationSize;
@@ -2755,7 +2951,7 @@ AFSSetAllocationInfo( IN PIRP Irp,
     {
         ntStatus = AFSUpdateFileInformation( &pFcb->ObjectInformation->ParentObjectInformation->FileId,
                                              pFcb->ObjectInformation,
-                                             &pFcb->AuthGroup);
+                                             &pCcb->AuthGroup);
     }
 
     if (NT_SUCCESS(ntStatus))
@@ -2797,6 +2993,9 @@ AFSSetAllocationInfo( IN PIRP Irp,
     {
 
         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+
+        AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                        TRUE);
     }
 
     return ntStatus;
@@ -2845,6 +3044,7 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
             }
             else
             {
+
                 //
                 // If this is a truncation we need to grab the paging
                 // IO resource.
@@ -2860,6 +3060,14 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
 
                 bReleasePaging = TRUE;
 
+                //
+                // Must drop the Fcb Resource.  When changing the file size
+                // a deadlock can occur with Trend Micro's filter if the file
+                // size is set to zero.
+                //
+
+                AFSReleaseResource( &pFcb->NPFcb->Resource);
+
                 pFcb->Header.AllocationSize = pBuffer->EndOfFile;
 
                 pFcb->Header.FileSize = pBuffer->EndOfFile;
@@ -2881,10 +3089,34 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
         }
         else
         {
+
             //
             // extending the file, move EOF
             //
 
+            //
+            // If this is a truncation we need to grab the paging
+            // IO resource.
+            //
+            AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+                          AFS_TRACE_LEVEL_VERBOSE,
+                          "AFSSetAllocationInfo Acquiring Fcb PagingIo lock %08lX EXCL %08lX\n",
+                          &pFcb->NPFcb->PagingResource,
+                          PsGetCurrentThread());
+
+            AFSAcquireExcl( &pFcb->NPFcb->PagingResource,
+                            TRUE);
+
+            bReleasePaging = TRUE;
+
+            //
+            // Must drop the Fcb Resource.  When changing the file size
+            // a deadlock can occur with Trend Micro's filter if the file
+            // size is set to zero.
+            //
+
+            AFSReleaseResource( &pFcb->NPFcb->Resource);
+
             pFcb->Header.FileSize = pBuffer->EndOfFile;
 
             pFcb->ObjectInformation->EndOfFile = pBuffer->EndOfFile;
@@ -2916,7 +3148,7 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
 
         ntStatus = AFSUpdateFileInformation( &pFcb->ObjectInformation->ParentObjectInformation->FileId,
                                              pFcb->ObjectInformation,
-                                             &pFcb->AuthGroup);
+                                             &pCcb->AuthGroup);
 
         if( NT_SUCCESS(ntStatus))
         {
@@ -2950,6 +3182,9 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
     {
 
         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+
+        AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                        TRUE);
     }
 
     return ntStatus;
@@ -3121,6 +3356,10 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
             case FileBasicInformation:
             {
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessPIOCtlQueryInfo (FileBasicInformation)\n");
+
                 if ( *Length >= sizeof( FILE_BASIC_INFORMATION))
                 {
                     PFILE_BASIC_INFORMATION pBasic = (PFILE_BASIC_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
@@ -3129,13 +3368,13 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
                     pBasic->LastAccessTime.QuadPart = 0;
                     pBasic->ChangeTime.QuadPart = 0;
                     pBasic->LastWriteTime.QuadPart = 0;
-                    pBasic->FileAttributes = FILE_ATTRIBUTE_SYSTEM;
+                    pBasic->FileAttributes = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
 
                     *Length -= sizeof( FILE_BASIC_INFORMATION);
                 }
                 else
                 {
-                    ntStatus = STATUS_BUFFER_OVERFLOW;
+                    ntStatus = STATUS_BUFFER_TOO_SMALL;
                 }
 
                 break;
@@ -3144,26 +3383,31 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
             case FileStandardInformation:
             {
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessPIOCtlQueryInfo (FileStandardInformation)\n");
+
                 if ( *Length >= sizeof( FILE_STANDARD_INFORMATION))
                 {
                     PFILE_STANDARD_INFORMATION pStandard = (PFILE_STANDARD_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
 
                     pStandard->NumberOfLinks = 1;
                     pStandard->DeletePending = 0;
-                    pStandard->AllocationSize.QuadPart = 4096;
-                    pStandard->EndOfFile.QuadPart = 4096;
+                    pStandard->AllocationSize.QuadPart = 0;
+                    pStandard->EndOfFile.QuadPart = 0;
                     pStandard->Directory = 0;
 
                     *Length -= sizeof( FILE_STANDARD_INFORMATION);
                 }
                 else
                 {
-                    ntStatus = STATUS_BUFFER_OVERFLOW;
+                    ntStatus = STATUS_BUFFER_TOO_SMALL;
                 }
 
                 break;
             }
 
+            case FileNormalizedNameInformation:
             case FileNameInformation:
             {
 
@@ -3174,6 +3418,10 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
                 PFILE_NAME_INFORMATION pNameInfo = (PFILE_NAME_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
                 UNICODE_STRING uniName;
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessPIOCtlQueryInfo (FileNameInformation)\n");
+
                 pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
                 pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
 
@@ -3265,6 +3513,10 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
 
                 PFILE_INTERNAL_INFORMATION pInternalInfo = (PFILE_INTERNAL_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
 
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_VERBOSE,
+                              "AFSProcessPIOCtlQueryInfo (FileInternalInformation)\n");
+
                 if( *Length >= sizeof( FILE_INTERNAL_INFORMATION))
                 {
 
@@ -3283,6 +3535,105 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
                 break;
             }
 
+            case FileAllInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileAllInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileEaInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileEaInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FilePositionInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FilePositionInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileAlternateNameInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileAlternateNameInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileNetworkOpenInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileNetworkOpenInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileStreamInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileStreamInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileAttributeTagInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileAttributeTagInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileRemoteProtocolInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileRemoteProtocolInformation) Not Implemented\n");
+
+                break;
+            }
+
+            case FileNetworkPhysicalNameInformation:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+
+                AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                              AFS_TRACE_LEVEL_WARNING,
+                              "AFSProcessPIOCtlQueryInfo (FileNetworkPhysicalNameInformation) Not Implemented\n");
+
+                break;
+            }
+
             default:
             {
                 ntStatus = STATUS_INVALID_PARAMETER;
@@ -3297,6 +3648,11 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
         }
     }
 
+    AFSDbgLogMsg( AFS_SUBSYSTEM_PIOCTL_PROCESSING,
+                  AFS_TRACE_LEVEL_VERBOSE,
+                  "AFSProcessPIOCtlQueryInfo ntStatus %08lX\n",
+                  ntStatus);
+
     return ntStatus;
 }