internal static MessageStatus WorkaroundSetFileRenameInfo(InputBufferFileNameLength inputBufferFileNameLength, MessageStatus returnedStatus, ITestSite site)
 {
     if (inputBufferFileNameLength == InputBufferFileNameLength.Greater)
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(3025, MessageStatus.MEDIA_WRITE_PROTECTED, returnedStatus, site);
     }
     return(returnedStatus);
 }
 internal static MessageStatus WorkaroundSetFileRenameInfo(InputBufferFileNameLength inputBufferFileNameLength, MessageStatus returnedStatus, ITestSite site)
 {
     if (inputBufferFileNameLength == InputBufferFileNameLength.Greater)
     {
         returnedStatus = FsaUtility.TransferExpectedResult<MessageStatus>(3025, MessageStatus.MEDIA_WRITE_PROTECTED, returnedStatus, site);
     }
     return returnedStatus;
 }
        public static MessageStatus SetFileRenameInfo(
            InputBufferFileNameLength inputBufferFileNameLength,
            InputBufferFileName inputBufferFileName,
            DirectoryVolumeType directoryVolumeType,
            DestinationDirectoryType destinationDirectoryType,
            NewLinkNameFormatType newLinkNameFormatType,
            NewLinkNameMatchType newLinkNameMatchType,
            ReplacementType replacementType,
            TargetLinkDeleteType targetLinkDeleteType,
            OplockBreakStatusType oplockBreakStatusType,
            TargetLinkFileOpenListType targetLinkFileOpenListType
            )
        {
            bool RemoveTargetLink = false;
            bool TargetExistsSameFile = false;

            //Boolean values (initialized to true): ActivelyRemoveSourceLink, RemoveSourceLink, AddTargetLink
            bool AddTargetLink = true;
            //If InputBuffer.FileNameLength is equal to zero.
            if (inputBufferFileNameLength == InputBufferFileNameLength.EqualTo_Zero)
            {
                Helper.CaptureRequirement(3023, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                    The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If InputBuffer.FileNameLength is equal to zero.");
                return MessageStatus.INVALID_PARAMETER;
            }

            // inputNameLengthValidate == 1:If InputBuffer.FileNameLength is an odd number
            if (inputBufferFileNameLength == InputBufferFileNameLength.OddNumber)
            {
                Helper.CaptureRequirement(3024, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                    The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If InputBuffer.FileNameLength is an odd number.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If InputBuffer.FileNameLength is greater than
            //InputBufferLength minus the byte offset into the FILE_RENAME_INFORMATION InputBuffer
            //of the InputBuffer.FileName field (that is, the total length of InputBuffer as given
            //in InputBufferLength is insufficient to contain the fixed-size fields of InputBuffer
            //plus the length of InputBuffer.FileName)
            if (inputBufferFileNameLength == InputBufferFileNameLength.Greater)
            {
                Helper.CaptureRequirement(3025, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                    The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If InputBuffer.FileNameLength is greater than InputBufferLength minus the byte offset into the FILE_RENAME_INFORMATION InputBuffer
                    of the InputBuffer.FileName field (that is, the total length of InputBuffer as given in InputBufferLength
            is insufficient to contain the fixed-size fields of InputBuffer plus the length of InputBuffer.FileName).");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If Open.GrantedAccess does not contain DELETE, as defined in [MS-SMB2] section 2.2.13.1
            if ((gOpenGrantedAccess != FileAccess.None) && (gOpenGrantedAccess & FileAccess.DELETE) == 0)
            {
                Helper.CaptureRequirement(3026, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                    If Open.GrantedAccess does not contain DELETE, as defined in [MS-SMB2] section 2.2.13.1,
                    the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            // If the first character of InputBuffer.FileName is '\'
            if (inputBufferFileName == InputBufferFileName.StartWithBackSlash)
            {

                //if DestinationDirectory.Volume is not equal to Open.File.Volume
                if (directoryVolumeType == DirectoryVolumeType.DestDirVolumeNotEqualToOpenFileVolume)
                {
                    Helper.CaptureRequirement(3034, @"[In FileRenameInformation,Pseudocode for the operation is as follows:
                        If the first character of InputBuffer.FileName is '\']Else if DestinationDirectory.Volume is not equal
                        to Open.File.Volume:The operation MUST be failed with STATUS_NOT_SAME_DEVICE.");
                    return MessageStatus.NOT_SAME_DEVICE;
                }
            }

            // If the first character of InputBuffer.FileName is ':'
            if (inputBufferFileName == InputBufferFileName.StartWithColon)
            {
                Helper.CaptureRequirement(3042, @"[In FileRenameInformation,Pseudocode for the operation is as follows:
                    If the first character of InputBuffer.FileName is ':']The operation immediately returns STATUS_SUCCESS.");
                return MessageStatus.SUCCESS;
            }

            //If Open.File contains open files, the operation MUST be failed with STATUS_ACCESS_DENIED
            //if (isOpenFileContain)
            if (gIsOpenListContains)
            {
                Helper.CaptureRequirement(3044, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                    If Open.File contains open files, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If InputBuffer.FileName is not valid as specified in [MS-FSCC] section 2.1.5
            if (inputBufferFileName == InputBufferFileName.NotValid)
            {
                Helper.CaptureRequirement(3045, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                    If InputBuffer.FileName is not valid as specified in [MS-FSCC] section 2.1.5,
                    the operation MUST be failed with STATUS_OBJECT_NAME_INVALID.");
                return MessageStatus.OBJECT_NAME_INVALID;
            }

            //If DestinationDirectory is the same as Open.Link.ParentFile:
            if (destinationDirectoryType == DestinationDirectoryType.DestDirIsSameAsOpenLinkParentFile)
            {
                //If NewLinkName is a case-sensitive exact match with Open.Link.Name
                if (newLinkNameFormatType == NewLinkNameFormatType.NewLinkNameIsCaseSensitive)
                {
                    Helper.CaptureRequirement(3046, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                        If DestinationDirectory is the same as Open.Link.ParentFile:If NewLinkName is a case-sensitive exact match with Open.Link.Name,
                        the operation MUST immediately return STATUS_SUCCESS.");
                    return MessageStatus.SUCCESS;
                }
            }

            //If NewLinkName matches the Name or ShortName of any Link in DestinationDirectory.
            //DirectoryList using case-sensitivity according to Open.IsCaseInsensitive:
            if (newLinkNameMatchType == NewLinkNameMatchType.NewLinkNameMatchTargetLinkShortName)
            {
                //Set FoundLink to true.
                //Set TargetLink to the existing Link found in DestinationDirectory.DirectoryList. Because the name may have been found using a case-insensitive search (if Open.IsCaseInsensitive is true), this preserves the case of the found name.
                //If NewLinkName matched TargetLink.ShortName, set MatchedShortName to true.
                //Set RemoveTargetLink to true.
                RemoveTargetLink = true;
                //If TargetLink.File.FileID equals Open.File.FileID, set TargetExistsSameFile to true. This detects a rename to another existing link to the same file.

                //If (TargetLink.Name is a case-sensitive exact match with NewLinkName) or MatchedShortName is true and TargetLink.ShortName is a case-sensitive exact match with NewLinkName):
                //Set ExactCaseMatch to true.

                //If RemoveTargetLink is true:
                if (RemoveTargetLink)
                {
                    //If TargetExistsSameFile is FALSE and InputBuffer.ReplaceIfExists is FALSE
                    if (!TargetExistsSameFile && replacementType == ReplacementType.NotReplaceIfExists)
                    {
                        Helper.CaptureRequirement(3067, @"[In FileRenameInformation,Pseudocode for the operation is as follows:]
                            If RemoveTargetLink is TRUE:If TargetExistsSameFile is FALSE and InputBuffer.ReplaceIfExists is FALSE,
                            the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.");
                        return MessageStatus.OBJECT_NAME_COLLISION;
                    }

                    //If TargetExistsSameFile is FALSE
                    if (!TargetExistsSameFile)
                    {
                        if (gfileTypeToOpen == FileType.DirectoryFile)
                        {
                            Helper.CaptureRequirement(3069, @"[In FileRenameInformation,Pseudocode for the operation is as follows:
                                If RemoveTargetLink is TRUE:] If TargetExistsSameFile is FALSE:The operation MUST be failed with TATUS_ACCESS_DENIED
                                under any of the following conditions: If TargetLink.File.FileType is DirectoryFile.");
                            return MessageStatus.ACCESS_DENIED;
                        }

                        if ((gFileAttribute & FileAttribute.READONLY) != 0)
                        {
                            Helper.CaptureRequirement(3071, @"[In FileRenameInformation,Pseudocode for the operation is as follows:
                                If RemoveTargetLink is TRUE: If TargetExistsSameFile is FALSE:The operation MUST be failed with TATUS_ACCESS_DENIED
                                under any of the following conditions:]If TargetLink.File.FileAttributes.FILE_ATTRIBUTE_READONLY is TRUE.");
                            return MessageStatus.ACCESS_DENIED;
                        }

                        //If TargetLink.IsDeleted is true
                        if (targetLinkDeleteType == TargetLinkDeleteType.TargetLinkIsDeleted)
                        {
                            Helper.CaptureRequirement(3072, @"[In FileRenameInformation,Pseudocode for the operation is as follows:If RemoveTargetLink is TRUE:
                                If TargetExistsSameFile is FALSE: ]If TargetLink.IsDeleted is TRUE, the operation MUST be failed with STATUS_DELETE_PENDING.");
                            return MessageStatus.DELETE_PENDING;
                        }

                        //If the caller does not have DELETE access to TargetLink.File
                        if ((gOpenGrantedAccess != FileAccess.None) && (gOpenGrantedAccess & FileAccess.DELETE) == 0)
                        {
                            //If the caller does not have FILE_DELETE_CHILD access to DestinationDirectory
                            if ((gOpenGrantedAccess != FileAccess.None) && (gOpenGrantedAccess & FileAccess.FILE_DELETE_CHILD) == 0)
                            {
                                Helper.CaptureRequirement(3073, @"[In FileRenameInformation,Pseudocode for the operation is as follows:
                                    If RemoveTargetLink is TRUE: If TargetExistsSameFile is FALSE:] If the caller does not have DELETE access to
                                    TargetLink.File:If the caller does not have FILE_DELETE_CHILD access to DestinationDirectory:
                                    The operation MUST be failed with STATUS_ACCESS_DENIED.");
                                return MessageStatus.ACCESS_DENIED;
                            }
                        }

                        //If there was not an oplock to be broken and TargetLink.File.OpenList contains
                        //an Open with a Stream matching the current Stream
                        if (oplockBreakStatusType == OplockBreakStatusType.HasNoOplockBreak &&
                            targetLinkFileOpenListType == TargetLinkFileOpenListType.TargetLinkFileOpenListContainMatchedOpen)
                        {
                            Helper.CaptureRequirement(3075, @"[In FileRenameInformation,Pseudocode for the operation is as follows:
                                If RemoveTargetLink is TRUE: If TargetExistsSameFile is FALSE: For each Stream on TargetLink.File ]
                                If there was not an oplock to be broken and TargetLink.File.OpenList contains an Open with a Stream matching the current Stream,
                                the operation MUST be failed with STATUS_ACCESS_DENIED.");
                            return MessageStatus.ACCESS_DENIED;
                        }
                    }
                }
            }

            //If AddTargetLink is true:
            if (AddTargetLink)
            {
                //The operation must be failed with STATUS_ACCESS_DENIED
                //if either of the following conditions are true: Open.File.FileType is DirectoryFile
                //and the caller does not have FILE_ADD_SUBDIRECTORY access on DestinationDirectory.
                if ((gfileTypeToOpen == FileType.DirectoryFile) && ((gOpenGrantedAccess != FileAccess.None) && (gOpenGrantedAccess & FileAccess.FILE_ADD_SUBDIRECTORY) == 0))
                {
                    Helper.CaptureRequirement(3086, @"[In FileRenameInformation,Pseudocode for the operation is as follows:] If AddTargetLink is TRUE:
                        The operation must be failed with STATUS_ACCESS_DENIED if either of the following conditions are true:
                        Open.File.FileType is DirectoryFile and the caller does not have FILE_ADD_SUBDIRECTORY access on DestinationDirectory.");
                    return MessageStatus.ACCESS_DENIED;
                }

                //The operation MUST be failed with STATUS_ACCESS_DENIED if either of the following conditions are true: ]
                //Open.File.FileType is DataFile and the caller does not have FILE_ADD_FILE access on DestinationDirectory.
                if (gfileTypeToOpen == FileType.DataFile && ((gOpenGrantedAccess & FileAccess.FILE_ADD_FILE) == 0))
                {
                    Helper.CaptureRequirement(3087, @"[In FileRenameInformation,Pseudocode for the operation is as follows: If AddTargetLink is TRUE:
                        The operation MUST be failed with STATUS_ACCESS_DENIED if either of the following conditions are true: ]Open.File.FileType is DataFile
                        and the caller does not have FILE_ADD_FILE access on DestinationDirectory.");
                    return MessageStatus.ACCESS_DENIED;
                }
            }
            Helper.CaptureRequirement(3126, @"[In FileRenameInformation,Pseudocode for the operation is as follows:] The operation returns STATUS_SUCCESS.");
            return MessageStatus.SUCCESS;
        }