diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index 816295636b2e..415d04bd0427 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -858,6 +858,12 @@ + + + + + + diff --git a/src/mscorlib/corefx/System/IO/FileStream.Linux.cs b/src/mscorlib/corefx/System/IO/FileStream.Linux.cs new file mode 100644 index 000000000000..873c4eb5599d --- /dev/null +++ b/src/mscorlib/corefx/System/IO/FileStream.Linux.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.Win32.SafeHandles; +using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; + +namespace System.IO +{ + public partial class FileStream : Stream + { + /// Prevents other processes from reading from or writing to the FileStream. + /// The beginning of the range to lock. + /// The range to be locked. + private void LockInternal(long position, long length) + { + CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_WRLCK)); + } + + /// Allows access by other processes to all or part of a file that was previously locked. + /// The beginning of the range to unlock. + /// The range to be unlocked. + private void UnlockInternal(long position, long length) + { + CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_UNLCK)); + } + } +} diff --git a/src/mscorlib/corefx/System/IO/FileStream.OSX.cs b/src/mscorlib/corefx/System/IO/FileStream.OSX.cs new file mode 100644 index 000000000000..a1167bfca01f --- /dev/null +++ b/src/mscorlib/corefx/System/IO/FileStream.OSX.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.IO +{ + public partial class FileStream : Stream + { + private void LockInternal(long position, long length) + { + throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_OSXFileLocking")); + } + + private void UnlockInternal(long position, long length) + { + throw new PlatformNotSupportedException(Environment.GetResourceString("PlatformNotSupported_OSXFileLocking")); + } + } +} diff --git a/src/mscorlib/corefx/System/IO/FileStream.Unix.cs b/src/mscorlib/corefx/System/IO/FileStream.Unix.cs index f83fc8425900..87bcc6c15ead 100644 --- a/src/mscorlib/corefx/System/IO/FileStream.Unix.cs +++ b/src/mscorlib/corefx/System/IO/FileStream.Unix.cs @@ -796,22 +796,6 @@ public override void WriteByte(byte value) // avoids an array allocation in the } } - /// Prevents other processes from reading from or writing to the FileStream. - /// The beginning of the range to lock. - /// The range to be locked. - private void LockInternal(long position, long length) - { - CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_WRLCK)); - } - - /// Allows access by other processes to all or part of a file that was previously locked. - /// The beginning of the range to unlock. - /// The range to be unlocked. - private void UnlockInternal(long position, long length) - { - CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_UNLCK)); - } - /// Sets the current position of this stream to the given value. /// The point relative to origin from which to begin seeking. /// diff --git a/src/mscorlib/src/System.Private.CoreLib.txt b/src/mscorlib/src/System.Private.CoreLib.txt index e45de2dbbef8..cb4a62c1c61c 100644 --- a/src/mscorlib/src/System.Private.CoreLib.txt +++ b/src/mscorlib/src/System.Private.CoreLib.txt @@ -1719,6 +1719,8 @@ event_Barrier_PhaseFinished=Barrier finishing phase {1}. ; Unix threading PlatformNotSupported_NamedSynchronizationPrimitives=The named version of this synchronization primitive is not supported on this platform. PlatformNotSupported_NamedSyncObjectWaitAnyWaitAll=Wait operations on multiple wait handles including a named synchronization primitive are not supported on this platform. +; OSX File locking +PlatformNotSupported_OSXFileLocking=Locking/unlocking file regions is not supported on this platform. Use FileShare on the entire file instead. #endif ;