internal static MessageStatus WorkaroundOpenExistingFile(ShareAccess shareAccess, FileAccess desiredAccess,
                                                          bool streamFound, bool isSymbolicLink, FileType openFileType, FileNameStatus fileNameStatus,
                                                          CreateOptions existingOpenModeCreateOption, ShareAccess existOpenShareModeShareAccess,
                                                          FileAccess existOpenDesiredAccess, CreateOptions createOption, CreateDisposition createDisposition,
                                                          StreamTypeNameToOpen streamTypeNameToOPen, FileAttribute fileAttribute,
                                                          FileAttribute desiredFileAttribute, MessageStatus returnedStatus, ITestSite site)
 {
     if (shareAccess == ShareAccess.FILE_SHARE_READ && desiredAccess == FileAccess.FILE_ADD_SUBDIRECTORY &&
         !streamFound && !isSymbolicLink && openFileType == FileType.DataFile && fileNameStatus == FileNameStatus.Normal &&
         existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE && existOpenShareModeShareAccess == ShareAccess.FILE_SHARE_READ &&
         existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY && createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING &&
         createDisposition == CreateDisposition.OPEN_IF && streamTypeNameToOPen == StreamTypeNameToOpen.NULL &&
         fileAttribute == FileAttribute.NORMAL && desiredFileAttribute == FileAttribute.NORMAL)
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(376, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT))
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(373, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT &&
              desiredAccess == FileAccess.FILE_READ_DATA)
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(369, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT &&
              desiredAccess == FileAccess.FILE_READ_DATA)
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(2373, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == CreateOptions.DELETE_ON_CLOSE &&
              (desiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY))
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(371, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER))
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.INVALID_PARAMETER, returnedStatus, site);
     }
     else if (streamFound && !isSymbolicLink && openFileType == FileType.DataFile &&
              existingOpenModeCreateOption == CreateOptions.DIRECTORY_FILE &&
              existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY &&
              createOption == CreateOptions.DIRECTORY_FILE)
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.ACCESS_VIOLATION, returnedStatus, site);
     }
     else if (!streamFound && !isSymbolicLink && openFileType == FileType.DataFile &&
              existingOpenModeCreateOption == CreateOptions.NON_DIRECTORY_FILE &&
              existOpenDesiredAccess == FileAccess.FILE_LIST_DIRECTORY &&
              createOption == CreateOptions.NON_DIRECTORY_FILE &&
              fileAttribute == FileAttribute.READONLY)
     {
         returnedStatus = FsaUtility.TransferExpectedResult <MessageStatus>(375, MessageStatus.ACCESS_DENIED, returnedStatus, site);
     }
     return(returnedStatus);
 }
        public static MessageStatus CreateFile(
            FileAttribute desiredFileAttribute,
            CreateOptions createOption,
            StreamTypeNameToOpen streamTypeNameToOPen,
            FileAccess desiredAccess,
            ShareAccess shareAccess,
            CreateDisposition createDisposition,
            StreamFoundType streamFoundType,
            SymbolicLinkType symbolicLinkType,
            FileType openFileType,
            FileNameStatus fileNameStatus
            )
        {
            MessageStatus status = OpenFileinitial(
                desiredAccess,
                shareAccess,
                createOption,
                createDisposition,
                desiredFileAttribute,
                streamFoundType,
                symbolicLinkType,
                streamTypeNameToOPen,
                openFileType,
                fileNameStatus);

            if (status != MessageStatus.SUCCESS)
            {
                return(status);
            }

            #region Pseudocode for the operation

            //If FileTypeToOpen is DirectoryFile and DesiredFileAttributes.FILE_ATTRIBUTE_TEMPORARY is set
            if (gfileTypeToOpen == FileType.DirectoryFile &&
                desiredFileAttribute == FileAttribute.TEMPORARY)
            {
                Helper.CaptureRequirement(418, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If FileTypeToOpen is DirectoryFile and DesiredFileAttributes.FILE_ATTRIBUTE_TEMPORARY is set, the operation MUST be failed with STATUS_INVALID_PARAMETER.");
                return(MessageStatus.INVALID_PARAMETER);
            }

            //If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE
            //are both set
            if (desiredFileAttribute == FileAttribute.READONLY &&
                createOption == CreateOptions.DELETE_ON_CLOSE)
            {
                Helper.CaptureRequirement(419, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE are both set, the operation MUST be failed with STATUS_CANNOT_DELETE.");
                return(MessageStatus.CANNOT_DELETE);
            }

            //If StreamTypeNameToOpen is non-empty and has a value other than "$DATA" or
            //"$INDEX_ALLOCATION", the operation MUST be failed with STATUS_ACCESS_DENIED.
            if (streamTypeNameToOPen == StreamTypeNameToOpen.Other)
            {
                Helper.CaptureRequirement(420, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If StreamTypeNameToOpen is non-empty and has a value other than \""$DATA"",the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return(MessageStatus.OBJECT_NAME_INVALID);
            }

            //If Open.RemainingDesiredAccess.ACCESS_SYSTEM_SECURITY is set and
            //Open.GrantedAccess.ACCESS_SYSTEM_SECURITY is not set and
            //SecurityContext.PrivilegeSet does not contain "SeSecurityPrivilege"
            //3 indicate SeBackupPrivilege and SeRestorePrivilege
            if (gOpenRemainingDesiredAccess == FileAccess.ACCESS_SYSTEM_SECURITY &&
                gOpenGrantedAccess == FileAccess.FILE_APPEND_DATA &&
                gSecurityContext.privilegeSet == (PrivilegeSet.SeBackupPrivilege | PrivilegeSet.SeRestorePrivilege))
            {
                Helper.CaptureRequirement(422, @"[In Creation of a New File,Pseudocode for the operation is as follows:]If Open.RemainingDesiredAccess.ACCESS_SYSTEM_SECURITY is set and Open.GrantedAccess.ACCESS_SYSTEM_SECURITY is not set and SecurityContext.PrivilegeSet does not contain \""SeSecurityPrivilege"", the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return(MessageStatus.ACCESS_DENIED);
            }

            //If FileTypeToOpen is DataFile and Open.GrantedAccess.FILE_ADD_FILE is not set
            //and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor,
            //FILE_ADD_FILE ) returns FALSE and Open.HasRestoreAccess is FALSE

            if (gfileTypeToOpen == FileType.DataFile &&
                gOpenGrantedAccess == FileAccess.FILE_ADD_SUBDIRECTORY &&
                !isOpenHasRestoreAccess)
            {
                Helper.CaptureRequirement(423, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                    If FileTypeToOpen is DataFile and Open.GrantedAccess.FILE_ADD_FILE is not set and 
                    AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_ADD_FILE ) 
                    returns FALSE and Open.HasRestoreAccess is FALSE, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return(MessageStatus.ACCESS_DENIED);
            }

            //If FileTypeToOpen is DirectoryFile and Open.GrantedAccess.FILE_ADD_SUBDIRECTORY
            //is not set and AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor,
            //FILE_ADD_SUBDIRECTORY ) returns FALSE and Open.HasRestoreAccess is FALSE

            if (gfileTypeToOpen == FileType.DirectoryFile &&
                gOpenGrantedAccess == FileAccess.FILE_ADD_FILE &&
                !isOpenHasRestoreAccess)
            {
                Helper.CaptureRequirement(424, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                   If FileTypeToOpen is DirectoryFile and Open.GrantedAccess.FILE_ADD_SUBDIRECTORY is not set and 
                   AccessCheck( SecurityContext, Open.Link.ParentFile.SecurityDescriptor, FILE_ADD_SUBDIRECTORY ) 
                   returns FALSE and Open.HasRestoreAccess is FALSE, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return(MessageStatus.ACCESS_DENIED);
            }

            if (streamTypeNameToOPen == StreamTypeNameToOpen.DATA ||
                streamTypeNameToOPen == StreamTypeNameToOpen.NULL)
            {
                gStreamType = StreamType.DataStream;
            }
            else
            {
                gStreamType = StreamType.DirectoryStream;
            }

            gFileAttribute = desiredFileAttribute;
            Helper.CaptureRequirement(475, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                The object store MUST return:CreateAction set to FILE_CREATED.");
            gCreateAction = CreateAction.CREATED;

            #endregion

            Helper.CaptureRequirement(474, @"[In Creation of a New File,Pseudocode for the operation is as follows:]
                The object store MUST return :Status set to STATUS_SUCCESS.");
            return(MessageStatus.SUCCESS);
        }