summaryrefslogtreecommitdiff
path: root/src/mscorlib
diff options
context:
space:
mode:
authorIan Hays <ianha@microsoft.com>2016-11-17 15:36:31 -0800
committerIan Hays <ianha@microsoft.com>2016-11-17 15:36:31 -0800
commit233c58ca964e15e6ce1e756940ec59819d797edf (patch)
treed5ea08be8742d748ed7ef02d75dcf0b40e61f883 /src/mscorlib
parent204f6e8859e3676114c85f49b8d2c311458ac715 (diff)
downloadcoreclr-233c58ca964e15e6ce1e756940ec59819d797edf.tar.gz
coreclr-233c58ca964e15e6ce1e756940ec59819d797edf.tar.bz2
coreclr-233c58ca964e15e6ce1e756940ec59819d797edf.zip
Add Unix FileStream Lock/Unlock
Implements FileStream Lock/Unlock by calling the SystemNative functions for fcntl F_SETLK
Diffstat (limited to 'src/mscorlib')
-rw-r--r--src/mscorlib/corefx/Interop/Unix/System.Native/Interop.Fcntl.cs18
-rw-r--r--src/mscorlib/corefx/System/IO/FileStream.Unix.cs6
-rw-r--r--src/mscorlib/mscorlib.shared.sources.props1
3 files changed, 21 insertions, 4 deletions
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 0000000000..1dc003b28a
--- /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 ece19235d7..f11f97c795 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
/// <param name="length">The range to be locked.</param>
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));
}
/// <summary>Allows access by other processes to all or part of a file that was previously locked.</summary>
@@ -810,8 +809,7 @@ namespace System.IO
/// <param name="length">The range to be unlocked.</param>
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));
}
/// <summary>Sets the current position of this stream to the given value.</summary>
diff --git a/src/mscorlib/mscorlib.shared.sources.props b/src/mscorlib/mscorlib.shared.sources.props
index 2fdfa01cb5..98fee905b2 100644
--- a/src/mscorlib/mscorlib.shared.sources.props
+++ b/src/mscorlib/mscorlib.shared.sources.props
@@ -1250,6 +1250,7 @@
<UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.Close.cs" />
<UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.GetCwd.cs" />
<UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.GetUnixName.cs" />
+ <UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.Fcntl.cs" />
<UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.FLock.cs" />
<UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.FSync.cs" />
<UnixInteropSources Include="$(CoreFxSourcesRoot)\Interop\Unix\System.Native\Interop.FTruncate.cs" />