string pipePath = Path.GetFullPath($@"\\.\pipe\{pipeName}");
var server = new NamedPipeServerStream(pipeName, PipeDirection.In);
- var clienStream = new FileStream(File.OpenHandle(pipePath, FileMode.Open, FileAccess.Write, FileShare.None), FileAccess.Write);
+ var clienStream = new FileStream(pipePath, FileMode.Open, FileAccess.Write, FileShare.None);
await server.WaitForConnectionAsync();
<data name="NotSupported_DynamicModule" xml:space="preserve">
<value>The invoked member is not supported in a dynamic module.</value>
</data>
- <data name="NotSupported_FileStreamOnNonFiles" xml:space="preserve">
- <value>FileStream was asked to open a device that was not a file. For support for devices like 'com1:' or 'lpt1:', call CreateFile, then use the FileStream constructors that take an OS handle as an IntPtr.</value>
- </data>
<data name="NotSupported_FixedSizeCollection" xml:space="preserve">
<value>Collection was of a fixed size.</value>
</data>
return result;
}
- internal static void ValidateFileTypeForNonExtendedPaths(SafeFileHandle handle, string originalPath) { /* nop */ }
-
internal static long Seek(SafeFileHandle handle, long offset, SeekOrigin origin, bool closeInvalidHandle = false) =>
CheckFileCall(Interop.Sys.LSeek(handle, offset, (Interop.Sys.SeekWhence)(int)origin), handle.Path); // SeekOrigin values are the same as Interop.libc.SeekWhence values
}
}
- internal static void ValidateFileTypeForNonExtendedPaths(SafeFileHandle handle, string originalPath)
- {
- if (!PathInternal.IsExtended(originalPath))
- {
- // To help avoid stumbling into opening COM/LPT ports by accident, we will block on non file handles unless
- // we were explicitly passed a path that has \\?\. GetFullPath() will turn paths like C:\foo\con.txt into
- // \\.\CON, so we'll only allow the \\?\ syntax.
-
- int fileType = handle.GetFileType();
- if (fileType != Interop.Kernel32.FileTypes.FILE_TYPE_DISK)
- {
- int errorCode = fileType == Interop.Kernel32.FileTypes.FILE_TYPE_UNKNOWN
- ? Marshal.GetLastPInvokeError()
- : Interop.Errors.ERROR_SUCCESS;
-
- handle.Dispose();
-
- if (errorCode != Interop.Errors.ERROR_SUCCESS)
- {
- throw Win32Marshal.GetExceptionForWin32Error(errorCode);
- }
- throw new NotSupportedException(SR.NotSupported_FileStreamOnNonFiles);
- }
- }
- }
-
internal static unsafe void SetFileLength(SafeFileHandle handle, long length)
{
var eofInfo = new Interop.Kernel32.FILE_END_OF_FILE_INFO
}
}
-
internal static unsafe int ReadFileNative(SafeFileHandle handle, Span<byte> bytes, NativeOverlapped* overlapped, out int errorCode)
{
Debug.Assert(handle != null, "handle != null");
int r;
int numBytesRead = 0;
-
fixed (byte* p = &MemoryMarshal.GetReference(bytes))
{
r = overlapped == null
private void Init(FileMode mode, string originalPath, FileOptions options)
{
- FileStreamHelpers.ValidateFileTypeForNonExtendedPaths(_fileHandle, originalPath);
-
Debug.Assert(!_useAsyncIO || _fileHandle.ThreadPoolBinding != null);
// For Append mode...
try
{
- FileStreamHelpers.ValidateFileTypeForNonExtendedPaths(_fileHandle, path);
-
if (mode == FileMode.Append && CanSeek)
{
_appendStart = _filePosition = Length;