Windows: SetFileRenameInfo Improve Error Handling
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSFileInfo.cpp
index 57c7909..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)
@@ -482,7 +494,6 @@ AFSSetFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
     PFILE_OBJECT pFileObject = NULL;
     BOOLEAN bReleaseMain = FALSE;
     BOOLEAN bUpdateFileInfo = FALSE;
-    BOOLEAN bReleaseVolumeLock = FALSE;
     AFSFileID stParentFileId;
 
     __try
@@ -507,15 +518,6 @@ AFSSetFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
         bCanQueueRequest = !(IoIsOperationSynchronous( Irp) | (KeGetCurrentIrql() != PASSIVE_LEVEL));
         FileInformationClass = pIrpSp->Parameters.SetFile.FileInformationClass;
 
-        if( FileInformationClass == FileRenameInformation)
-        {
-
-            AFSAcquireExcl( pFcb->ObjectInformation->VolumeCB->VolumeLock,
-                            TRUE);
-
-            bReleaseVolumeLock = TRUE;
-        }
-
         //
         // Grab the Fcb EXCL
         //
@@ -566,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);
         }
 
@@ -676,11 +688,6 @@ try_exit:
             AFSReleaseResource( &pFcb->NPFcb->Resource);
         }
 
-        if( bReleaseVolumeLock)
-        {
-            AFSReleaseResource( pFcb->ObjectInformation->VolumeCB->VolumeLock);
-        }
-
         if( NT_SUCCESS( ntStatus) &&
             bUpdateFileInfo)
         {
@@ -735,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,
@@ -810,13 +825,27 @@ 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,
@@ -917,11 +946,27 @@ 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,
@@ -1400,13 +1445,27 @@ 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,
@@ -1577,13 +1636,27 @@ 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,
@@ -1618,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);
@@ -1990,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)
             {
 
                 //
@@ -2011,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
         {
@@ -2057,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;
@@ -2074,11 +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;
     BOOLEAN bReleaseTargetDirLock = FALSE;
     BOOLEAN bReleaseSourceDirLock = FALSE;
+    BOOLEAN bDereferenceTargetParentObject = FALSE;
     PERESOURCE  pSourceDirLock = NULL;
+    LONG lCount;
 
     __Enter
     {
@@ -2089,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
@@ -2126,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
@@ -2148,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
+            {
+
+                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);
 
-            uniTargetName.Length = (USHORT)pRenameInfo->FileNameLength;
-            uniTargetName.Buffer = (PWSTR)&pRenameInfo->FileName;
+                    try_return( ntStatus = STATUS_NOT_SAME_DEVICE);
+                }
+            }
+
+            pTargetDcb = pTargetParentObject->Fcb;
         }
         else
         {
@@ -2184,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
         //
 
@@ -2206,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,
@@ -2235,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))
         {
@@ -2256,7 +2412,7 @@ AFSSetRenameInfo( IN PIRP Irp)
 
             ASSERT( pTargetParentObject == pTargetDirEntry->ObjectInformation->ParentObjectInformation);
 
-            InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedIncrement( &pTargetDirEntry->OpenReferenceCount);
 
             if( !bReplaceIfExists)
             {
@@ -2295,40 +2451,6 @@ AFSSetRenameInfo( IN PIRP Irp)
         }
 
         //
-        // 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;
-        }
-
-        //
         // We need to remove the DirEntry from the parent node, update the index
         // and reinsert it into the parent tree. Note that for entries with the
         // same parent we do not pull the node from the enumeration list
@@ -2440,6 +2562,9 @@ AFSSetRenameInfo( IN PIRP Irp)
                             &stNewFid))
         {
 
+            AFSAcquireExcl( pSrcObject->VolumeCB->ObjectInfoTree.TreeLock,
+                            TRUE);
+
             //
             // Remove the old information entry
             //
@@ -2465,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);
         }
 
         //
@@ -2480,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))
@@ -2530,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;
 
@@ -2606,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,
@@ -2641,7 +2778,7 @@ try_exit:
         if( pTargetDirEntry != NULL)
         {
 
-            InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
+            lCount = InterlockedDecrement( &pTargetDirEntry->OpenReferenceCount);
         }
 
         if( bReleaseTargetDirLock)
@@ -2655,6 +2792,12 @@ try_exit:
         }
     }
 
+    if ( bDereferenceTargetParentObject)
+    {
+
+        ObDereferenceObject( pTargetParentFileObj);
+    }
+
     return ntStatus;
 }
 
@@ -2725,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",
@@ -2736,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;
 
@@ -2766,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;
@@ -2822,6 +2993,9 @@ AFSSetAllocationInfo( IN PIRP Irp,
     {
 
         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+
+        AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                        TRUE);
     }
 
     return ntStatus;
@@ -2870,6 +3044,7 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
             }
             else
             {
+
                 //
                 // If this is a truncation we need to grab the paging
                 // IO resource.
@@ -2885,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;
@@ -2906,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;
@@ -2975,6 +3182,9 @@ AFSSetEndOfFileInfo( IN PIRP Irp,
     {
 
         AFSReleaseResource( &pFcb->NPFcb->PagingResource);
+
+        AFSAcquireExcl( &pFcb->NPFcb->Resource,
+                        TRUE);
     }
 
     return ntStatus;
@@ -3158,7 +3368,7 @@ 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);
                 }
@@ -3197,6 +3407,7 @@ AFSProcessPIOCtlQueryInfo( IN IRP *Irp,
                 break;
             }
 
+            case FileNormalizedNameInformation:
             case FileNameInformation:
             {