From 233c58ca964e15e6ce1e756940ec59819d797edf Mon Sep 17 00:00:00 2001 From: Ian Hays Date: Thu, 17 Nov 2016 15:36:31 -0800 Subject: [PATCH] Add Unix FileStream Lock/Unlock Implements FileStream Lock/Unlock by calling the SystemNative functions for fcntl F_SETLK --- .../corefx/Interop/Unix/System.Native/Interop.Fcntl.cs | 18 ++++++++++++++++++ src/mscorlib/corefx/System/IO/FileStream.Unix.cs | 6 ++---- src/mscorlib/mscorlib.shared.sources.props | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs diff --git a/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs new file mode 100644 index 0000000..1dc003b --- /dev/null +++ b/src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs @@ -0,0 +1,18 @@ +// 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 System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Sys + { + [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LockFileRegion", SetLastError=true)] + internal static extern int LockFileRegion(SafeHandle fd, long offset, long length); + + [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_UnlockFileRegion", SetLastError=true)] + internal static extern int UnlockFileRegion(SafeHandle fd, long offset, long length); + } +} diff --git a/src/mscorlib/corefx/System/IO/FileStream.Unix.cs b/src/mscorlib/corefx/System/IO/FileStream.Unix.cs index ece1923..f11f97c 100644 --- a/src/mscorlib/corefx/System/IO/FileStream.Unix.cs +++ b/src/mscorlib/corefx/System/IO/FileStream.Unix.cs @@ -801,8 +801,7 @@ namespace System.IO /// The range to be locked. private void LockInternal(long position, long length) { - // TODO #5964: Implement this with fcntl and F_SETLK in System.Native - throw new PlatformNotSupportedException(); + CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length)); } /// Allows access by other processes to all or part of a file that was previously locked. @@ -810,8 +809,7 @@ namespace System.IO /// The range to be unlocked. private void UnlockInternal(long position, long length) { - // TODO #5964: Implement this with fcntl and F_SETLK in System.Native - throw new PlatformNotSupportedException(); + CheckFileCall(Interop.Sys.UnlockFileRegion(_fileHandle, position, length)); } /// Sets the current position of this stream to the given value. diff --git a/src/mscorlib/mscorlib.shared.sources.props b/src/mscorlib/mscorlib.shared.sources.props index 2fdfa01..98fee90 100644 --- a/src/mscorlib/mscorlib.shared.sources.props +++ b/src/mscorlib/mscorlib.shared.sources.props @@ -1250,6 +1250,7 @@ + -- 2.7.4