private NTStatus OpenFileStream(out Stream stream, string path, FileAccess fileAccess, ShareAccess shareAccess, CreateOptions openOptions) { stream = null; FileShare fileShare = NTFileStoreHelper.ToFileShare(shareAccess); FileOptions fileOptions = ToFileOptions(openOptions); string fileShareString = fileShare.ToString().Replace(", ", "|"); string fileOptionsString = ToFileOptionsString(fileOptions); try { stream = m_fileSystem.OpenFile(path, FileMode.Open, fileAccess, fileShare, fileOptions); } catch (Exception ex) { if (ex is IOException || ex is UnauthorizedAccessException) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status); return(status); } else { throw; } } Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString); return(NTStatus.STATUS_SUCCESS); }
public bool PosTest1() { bool retVal = true; const string c_TEST_DESC = "PosTest1:check the FileShare.Write value is 2..."; const string c_TEST_ID = "P001"; FileShare FLAG_VALUE = (FileShare)2; TestLibrary.TestFramework.BeginScenario(c_TEST_DESC); try { if (FileShare.Write != FLAG_VALUE) { string errorDesc = "value is not " + FLAG_VALUE.ToString() + " as expected: Actual is " + FileShare.Write.ToString(); TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); TestLibrary.TestFramework.LogInformation(e.StackTrace); retVal = false; } return(retVal); }
private NTStatus OpenFileStream(out Stream stream, string path, FileAccess fileAccess, ShareAccess shareAccess, CreateOptions openOptions) { stream = null; // When FILE_OPEN_REPARSE_POINT is specified, the operation should continue normally if the file is not a reparse point. // FILE_OPEN_REPARSE_POINT is a hint that the caller does not intend to actually read the file, with the exception // of a file copy operation (where the caller will attempt to simply copy the reparse point). bool openReparsePoint = (openOptions & CreateOptions.FILE_OPEN_REPARSE_POINT) > 0; bool disableBuffering = (openOptions & CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING) > 0; bool buffered = (openOptions & CreateOptions.FILE_SEQUENTIAL_ONLY) > 0 && !disableBuffering && !openReparsePoint; FileShare fileShare = NTFileStoreHelper.ToFileShare(shareAccess); string fileShareString = fileShare.ToString().Replace(", ", "|"); try { stream = m_fileSystem.OpenFile(path, FileMode.Open, fileAccess, fileShare); } catch (Exception ex) { NTStatus status = ToNTStatus(ex); Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status); return(status); } Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, Buffered={3}", path, fileAccess, fileShareString, buffered); if (buffered) { stream = new PrefetchedStream(stream); } return(NTStatus.STATUS_SUCCESS); }