Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override async Task<StreamPair> CreateConnectedStreamsAsync()
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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2845,9 +2845,6 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ internal static long CheckFileCall(long result, string? path, bool ignoreNotSupp
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,6 @@ internal static void Unlock(SafeFileHandle handle, long position, long length)
}
}

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
Expand All @@ -168,14 +142,12 @@ internal static unsafe void SetFileLength(SafeFileHandle handle, long length)
}
}


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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ internal sealed partial class Net5CompatFileStreamStrategy : FileStreamStrategy

private void Init(FileMode mode, string originalPath, FileOptions options)
{
FileStreamHelpers.ValidateFileTypeForNonExtendedPaths(_fileHandle, originalPath);

Debug.Assert(!_useAsyncIO || _fileHandle.ThreadPoolBinding != null);

// For Append mode...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ internal OSFileStreamStrategy(string path, FileMode mode, FileAccess access, Fil

try
{
FileStreamHelpers.ValidateFileTypeForNonExtendedPaths(_fileHandle, path);

if (mode == FileMode.Append && CanSeek)
{
_appendStart = _filePosition = Length;
Expand Down