public static MessageStatus OpenFileinitial()

in TestSuites/FileServer/src/FSAModel/Model/OpenFile/OpenFile.cs [37:532]


        public static MessageStatus OpenFileinitial(
            FileAccess desiredAccess,
            ShareAccess shareAccess,
            CreateOptions createOption,
            CreateDisposition createDisposition,
            FileAttribute fileAttribute,
            StreamFoundType streamFoundType,
            SymbolicLinkType symbolicLinkType,
            StreamTypeNameToOpen streamTypeNameToOPen,
            FileType openFileType,
            FileNameStatus fileNameStatus)
        {
            #region phase 1  Parameter Validation

            //If DesiredAccess is not a valid value as specified in MS-SMB2 section 2.2.13.1
            if (desiredAccess == FileAccess.None)
            {
                Helper.CaptureRequirement(366, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]If any of the bits in the mask 0x0CE0FE00 are set, 
                    the operation MUST be failed with STATUS_ACCESS_DENIED.");
                //If DesiredAccess is zero
                Helper.CaptureRequirement(377, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]If DesiredAccess is zero, the operation MUST be failed with STATUS_ACCESS_DENIED.");
                return MessageStatus.ACCESS_DENIED;
            }

            //If ShareAccess is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (shareAccess == ShareAccess.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(2370, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If ShareAccess are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (createOption == CreateOptions.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(2371, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateDisposition is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (createDisposition == CreateDisposition.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(2372, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateDisposition are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If FileAttributes is not valid values for a file object as specified in MS-SMB2 section 2.2.13
            if (fileAttribute == FileAttribute.NOT_VALID_VALUE)
            {
                Helper.CaptureRequirement(404, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If FileAttributes are not valid values for a file object as specified in [MS-SMB2] section 2.2.13.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE.
            //65 indicates CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE
            if (createOption == (CreateOptions.DIRECTORY_FILE | CreateOptions.NON_DIRECTORY_FILE))
            {
                Helper.CaptureRequirement(368, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && !DesiredAccess.SYNCHRONIZE.
            //updated by meying:desiredAccess == FileAccess.FILE_READ_DATA
            if (createOption == CreateOptions.SYNCHRONOUS_IO_ALERT
               && desiredAccess == FileAccess.FILE_READ_DATA)
            {
                Helper.CaptureRequirement(369, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && !DesiredAccess.SYNCHRONIZE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If Create.FILE_SYNCHRONOUS_IO_NONALERT && !DesiredAccess.SYNCHRONIZE.
            //updated by meying:desiredAccess == FileAccess.FILE_READ_DATA
            if (createOption == CreateOptions.SYNCHRONOUS_IO_NONALERT
               && desiredAccess == FileAccess.FILE_READ_DATA)
            {
                Helper.CaptureRequirement(2373, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If Create.FILE_SYNCHRONOUS_IO_NONALERT&& !DesiredAccess.SYNCHRONIZE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DELETE_ON_CLOSE && !DesiredAccess.DELETE.
            if (createOption == CreateOptions.DELETE_ON_CLOSE &&
                (desiredAccess == FileAccess.FILE_READ_DATA))
            {
                Helper.CaptureRequirement(371, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DELETE_ON_CLOSE && !DesiredAccess.DELETE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT
            //48 indicates CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT
            if (createOption == (CreateOptions.SYNCHRONOUS_IO_NONALERT | CreateOptions.SYNCHRONOUS_IO_ALERT))
            {
                Helper.CaptureRequirement(373, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_SYNCHRONOUS_IO_ALERT && Create.FILE_SYNCHRONOUS_IO_NONALERT.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE.
            if (createOption == CreateOptions.DIRECTORY_FILE &&
                createDisposition == CreateDisposition.OVERWRITE)
            {
                Helper.CaptureRequirement(2375, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == NONE .
            if (createOption == CreateOptions.DIRECTORY_FILE &&
                createDisposition == CreateDisposition.SUPERSEDE)
            {
                Helper.CaptureRequirement(2374, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == SUPERSEDE .");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE_IF.
            if (createOption == CreateOptions.DIRECTORY_FILE &&
                createDisposition == CreateDisposition.OVERWRITE_IF)
            {
                Helper.CaptureRequirement(2376, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_DIRECTORY_FILE && CreateDisposition == OVERWRITE_IF).");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER
            //if ((createOption & (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER)) != 0)
            //1048832 indicates CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER
            if (createOption == (CreateOptions.COMPLETE_IF_OPLOCKED | CreateOptions.RESERVE_OPFILTER))
            {
                Helper.CaptureRequirement(375, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.COMPLETE_IF_OPLOCKED && CreateOptions.FILE_RESERVE_OPFILTER.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING && DesiredAccess.FILE_APPEND_DATA.
            if (createOption == CreateOptions.NO_INTERMEDIATE_BUFFERING &&
                desiredAccess == FileAccess.FILE_APPEND_DATA)
            {
                Helper.CaptureRequirement(376, @"[In Application Requests an Open of a File ,Phase 1 - Parameter Validation:]
                    The operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:
                    If CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING && DesiredAccess.FILE_APPEND_DATA.");
                return MessageStatus.INVALID_PARAMETER;
            }

            //If PathName is not valid as specified in [MS-FSCC] section 2.1.5.
            if (fileNameStatus == FileNameStatus.NotPathNameValid)
            {
                Helper.CaptureRequirement(379, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions:
                    If PathName is not valid as specified in [MS-FSCC] section 2.1.5.");
                return MessageStatus.OBJECT_NAME_INVALID;
            }

            //If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is true
            if (fileNameStatus == FileNameStatus.BackslashName &&
                createOption == CreateOptions.NON_DIRECTORY_FILE && 
                desiredAccess == FileAccess.FILE_READ_DATA)
            {
                Helper.CaptureRequirement(380, @"[In Application Requests an Open of a File ,Pseudocode for the operation is as follows:
                    Phase 1 - Parameter Validation:]The operation MUST be failed with STATUS_OBJECT_NAME_INVALID under any of the following conditions:
                    If PathName contains a trailing backslash and CreateOptions.FILE_NON_DIRECTORY_FILE is TRUE.");
                return MessageStatus.OBJECT_NAME_INVALID;
            }

            #endregion

            #region phase 2  Volume State

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == FILE_CREATE) 
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.CREATE))
            {
                Helper.CaptureRequirement(2377, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly && CreateDisposition == FILE_CREATE,then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == FILE_SUPERSEDE) 
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.SUPERSEDE))
            {
                Helper.CaptureRequirement(2378, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly &&CreateDisposition == FILE_SUPERSEDE, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == OVERWRITE) 
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.OVERWRITE))
            {
                Helper.CaptureRequirement(2379, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly &&CreateDisposition == OVERWRITE, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            //If RootOpen.Volume.IsReadOnly && (CreateDisposition == OVERWRITE_IF) 
            //then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED
            if (isFileVolumeReadOnly && (createDisposition == CreateDisposition.OVERWRITE_IF))
            {
                Helper.CaptureRequirement(2380, @"[In Application Requests an Open of a File,Pseudocode for the operation is as follows: ]
                    If RootOpen.Volume.IsReadOnly &&CreateDisposition == OVERWRITE_IF, then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                return MessageStatus.MEDIA_WRITE_PROTECTED;
            }

            #endregion

            #region Phase 3  Initialization of Open Object

            gOpenRemainingDesiredAccess = desiredAccess;
            gOpenSharingMode = shareAccess;
            //4158 indicates (createOption & (CreateOptions.WRITE_THROUGH |
            //CreateOptions.SEQUENTIAL_ONLY | CreateOptions.NO_INTERMEDIATE_BUFFERING |
            //CreateOptions.SYNCHRONOUS_IO_ALERT | CreateOptions.SYNCHRONOUS_IO_NONALERT |
            //CreateOptions.DELETE_ON_CLOSE));

            gOpenMode = (CreateOptions.WRITE_THROUGH |
            CreateOptions.SEQUENTIAL_ONLY | CreateOptions.NO_INTERMEDIATE_BUFFERING |
            CreateOptions.SYNCHRONOUS_IO_ALERT | CreateOptions.SYNCHRONOUS_IO_NONALERT |
            CreateOptions.DELETE_ON_CLOSE);
            if (gSecurityContext.privilegeSet == PrivilegeSet.SeBackupPrivilege)
            {
                isOpenHasBackupAccess = true;
            }

            if (gSecurityContext.privilegeSet == PrivilegeSet.SeRestorePrivilege)
            {
                isOpenHasRestoreAccess = true;
            }

            if (gSecurityContext.privilegeSet == PrivilegeSet.SeCreateSymbolicLinkPrivilege)
            {
                isOpenHasCreateSymbolicLinkAccess = true;
            }

            if (gSecurityContext.privilegeSet == PrivilegeSet.SeManageVolumePrivilege)
            {
                isOpenHasManageVolumeAccess = true;
            }

            if (gSecurityContext.isSecurityContextSIDsContainWellKnown)
            {
                isOpenIsAdministrator = true;
            }

            #endregion

            #region phase 4  Check for backup/restore intent

            //If CreateOptions.FILE_OPEN_FOR_BACKUP_INTENT is set and (CreateDisposition == 
            //FILE_OPEN || CreateDisposition == FILE_OPEN_IF || CreateDisposition == 
            //FILE_OVERWRITE_IF) and Open.HasBackupAccess is true, then the object store 
            //SHOULD grant backup access as shown in the following pseudocode:
            if (createOption == CreateOptions.OPEN_FOR_BACKUP_INTENT &&
                (createDisposition == CreateDisposition.OPEN ||
                createDisposition == CreateDisposition.OPEN_IF ||
                createDisposition == CreateDisposition.OVERWRITE_IF) && isOpenHasBackupAccess)
            {
                //2164391968 indicates FileAccess.READ_CONTROL |
                //FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_READ |
                //FileAccess.FILE_TRAVERSE;
                FileAccess BackupAccess = FileAccess.READ_CONTROL |
                FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_READ |
                FileAccess.FILE_TRAVERSE;

                if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED)
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | BackupAccess;
                }
                else
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | (gOpenRemainingDesiredAccess & BackupAccess);
                }

                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess);
            }

            //If CreateOptions.FILE_OPEN_FOR_BACKUP_INTENT is set and Open.HasRestoreAccess is true, 
            //then the object store SHOULD grant restore access as shown in the following pseudocode:
            if (createOption == CreateOptions.OPEN_FOR_BACKUP_INTENT && isHasRestoreAccess)
            {
                //1091309574 indicates FileAccess.WRITE_DAC | FileAccess.WRITE_OWNER |
                //FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_WRITE |
                //FileAccess.FILE_ADD_FILE | FileAccess.FILE_ADD_SUBDIRECTORY |
                //FileAccess.DELETE
                FileAccess RestoreAccess = FileAccess.WRITE_DAC | FileAccess.WRITE_OWNER |
                FileAccess.ACCESS_SYSTEM_SECURITY | FileAccess.GENERIC_WRITE |
                FileAccess.FILE_ADD_FILE | FileAccess.FILE_ADD_SUBDIRECTORY |
                FileAccess.DELETE;

                if (gOpenRemainingDesiredAccess == FileAccess.MAXIMUM_ALLOWED)
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | RestoreAccess;
                }
                else
                {
                    gOpenGrantedAccess = gOpenGrantedAccess | (gOpenRemainingDesiredAccess & RestoreAccess);
                }

                gOpenRemainingDesiredAccess = gOpenRemainingDesiredAccess & (~gOpenGrantedAccess);
            }

            #endregion

            #region phase 5  Parse path name

            //If any StreamTypeNamei is "$INDEX_ALLOCATION" and the corresponding 
            //StreamNamei has a value other than an empty string or "$I30"
            if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION)
            {
                if (sutPlatForm != PlatformType.NoneWindows)
                {
                    Helper.CaptureRequirement(507, @"[In Application Requests an Open of a File ,Phase 5 -- Parse path name:]
                        If any StreamTypeNamei is \""$INDEX_ALLOCATION"" and the corresponding StreamNamei has a value other than an empty string 
                        or \""$I30"", the operation is failed with STATUS_INVALID_PARAMETER in Windows.");
                    return MessageStatus.INVALID_PARAMETER;
                }
                else if (isR507Implemented)
                {
                    Helper.CaptureRequirement(392, @"[In Application Requests an Open of a File ,Phase 5 -- Parse path name:]
                        If any StreamTypeNamei is \""$INDEX_ALLOCATION"" and the corresponding StreamNamei has a value other than an empty string 
                        or \""$I30\"", the operation SHOULD be failed with STATUS_INVALID_PARAMETER.");
                    return MessageStatus.INVALID_PARAMETER;
                }
            }

            #endregion

            #region phase 6  Location of file

            if (streamFoundType == StreamFoundType.StreamIsNotFound)
            {
                //If (CreateDisposition == FILE_OPEN )
                if (createDisposition == CreateDisposition.OPEN)
                {
                    Helper.CaptureRequirement(513, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Else:[If such a link is not found:]
                        If CreateDisposition == FILE_OPEN, the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND.");
                    return MessageStatus.OBJECT_NAME_NOT_FOUND;
                }

                //If (CreateDisposition == FILE_OVERWRITE)
                if (createDisposition == CreateDisposition.OVERWRITE)
                {
                    Helper.CaptureRequirement(2395, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Else:[If such a link is not found:]If CreateDisposition == FILE_OVERWRITE), 
                        the operation MUST be failed with STATUS_OBJECT_NAME_NOT_FOUND.");
                    return MessageStatus.OBJECT_NAME_NOT_FOUND;
                }

                //If RootOpen.Volume.IsReadOnly 
                if (isFileVolumeReadOnly)
                {
                    Helper.CaptureRequirement(514, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Else:[If such a link is not found:]If RootOpen.Volume.IsReadOnly 
                        then the operation MUST be failed with STATUS_MEDIA_WRITE_PROTECTED.");
                    return MessageStatus.MEDIA_WRITE_PROTECTED;
                }

                //Helper.CaptureRequirement(547, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:Phase 6 -- Location of file:] for this search is as follows:For i = 1 to n-1:Search ParentFile.DirectoryList for a Link where Link.Name or Link.ShortName matches FileNamei,If no such link is found, the operation MUST be failed with STATUS_OBJECT_PATH_NOT_FOUND.");
                //return MessageStatus.OBJECT_PATH_NOT_FOUND;
            }

            //If Open.GrantedAccess.FILE_TRAVERSE is not set and 
            //AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) 
            //returns FALSE,
            if ((gOpenGrantedAccess & FileAccess.FILE_TRAVERSE) == 0)
            {
                if (sutPlatForm != PlatformType.NoneWindows)
                {
                    Helper.CaptureRequirement(405, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 6 -- Location of file:] Pseudocode for this search:For i = 1 to n-1:
                        If Open.GrantedAccess.FILE_TRAVERSE is not set and AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) 
                        returns FALSE, the operation is not  failed with STATUS_ACCESS_DENIED in Windows.");
                }
                if (isR405Implemented)
                {
                    Helper.CaptureRequirement(397, @"[In Application Requests an Open of a File ,
                        Pseudocode for the operation is as follows:Phase 6 -- Location of file:] 
                        Pseudocode for this search:For i = 1 to n-1:If Open.GrantedAccess.FILE_TRAVERSE is not set 
                        and AccessCheck( SecurityContext, Link.File.SecurityDescriptor, FILE_TRAVERSE ) returns FALSE, the operation MAY be failed with STATUS_ACCESS_DENIED.");
                    return MessageStatus.ACCESS_DENIED;
                }
            }
            //If Link.File.IsSymbolicLink is true
            if (symbolicLinkType == SymbolicLinkType.IsSymbolicLink)
            {
                Helper.CaptureRequirement(399, @"[In Application Requests an Open of a File , 
                     Pseudocode for the operation is as follows:Phase 6 - Location of file:] 
                     Pseudocode for this search:For i = 1 to n-1:If Link.File.IsSymbolicLink is TRUE, 
                     the operation MUST be failed with Status set to STATUS_STOPPED_ON_SYMLINK .");
                return MessageStatus.STOPPED_ON_SYMLINK;
            }

            #endregion

            #region phase 7  Type of file to open

            //If CreateOptions.FILE_DIRECTORY_FILE is true
            if (createOption == CreateOptions.DIRECTORY_FILE)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //Else if CreateOptions.FILE_NON_DIRECTORY_FILE is true
            else if (createOption == CreateOptions.NON_DIRECTORY_FILE)
            {
                gfileTypeToOpen = FileType.DataFile;
            }
            //Else if StreamTypeNameToOpen is "$INDEX_ALLOCATION"
            else if (streamTypeNameToOPen == StreamTypeNameToOpen.INDEX_ALLOCATION)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //Else if StreamTypeNameToOpen is "$DATA"
            else if (streamTypeNameToOPen == StreamTypeNameToOpen.DATA)
            {
                gfileTypeToOpen = FileType.DataFile;
            }
            //Else if Open.File is not NULL and Open.File.FileType is DirectoryFile
            else if (fileNameStatus == FileNameStatus.OpenFileNotNull &&
                openFileType == FileType.DirectoryFile)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //Else if PathName contains a trailing backslash
            else if (fileNameStatus == FileNameStatus.PathNameTrailBack)
            {
                gfileTypeToOpen = FileType.DirectoryFile;
            }
            //else
            else
            {
                gfileTypeToOpen = FileType.DataFile;
            }

            //If FileTypeToOpen is DirectoryFile and Open.File is not NULL and 
            //Open.File.FileType is not DirectoryFile:
            if (gfileTypeToOpen == FileType.DirectoryFile &&
                fileNameStatus == FileNameStatus.OpenFileNotNull &&
                openFileType == FileType.DataFile)
            {
                //If CreateDisposition == FILE_CREATE
                if (createDisposition == CreateDisposition.CREATE)
                {
                    Helper.CaptureRequirement(414, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                        Phase 7 -- Type of file to open:]If FileTypeToOpen is DirectoryFile and Open.File is not NULL 
                        and Open.File.FileType is not DirectoryFile:If CreateDisposition == FILE_CREATE then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.");
                    return MessageStatus.OBJECT_NAME_COLLISION;
                }
                //else
                else
                {
                    Helper.CaptureRequirement(2396, @"[In Application Requests an Open of a File , Phase 7 -- Type of file to open:]
                        If FileTypeToOpen is DirectoryFile and Open.File is not NULL and Open.File.FileType is not DirectoryFile:
                        else[If CreateDisposition != FILE_CREATE] the operation MUST be failed with STATUS_NOT_A_DIRECTORY.");
                    return MessageStatus.NOT_A_DIRECTORY;
                }
            }

            //If FileTypeToOpen is DataFile and StreamNameToOpen is empty and Open.File 
            //is not NULL and Open.File.FileType is DirectoryFile
            if (gfileTypeToOpen == FileType.DataFile &&
                streamTypeNameToOPen == StreamTypeNameToOpen.NULL &&
                fileNameStatus == FileNameStatus.OpenFileNotNull &&
                openFileType == FileType.DirectoryFile)
            {
                Helper.CaptureRequirement(415, @"[In Application Requests an Open of a File , Pseudocode for the operation is as follows:
                    Phase 7 -- Type of file to open:]If FileTypeToOpen is DataFile and StreamNameToOpen is empty and Open.File is not NULL 
                    and Open.File.FileType is DirectoryFile, the operation MUST be failed with STATUS_FILE_IS_A_DIRECTORY.");
                return MessageStatus.FILE_IS_A_DIRECTORY;
            }

            #endregion

            return MessageStatus.SUCCESS;
        }