{
internal static partial class Sys
{
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LockFileRegion", SetLastError=true)]
- internal static extern int LockFileRegion(SafeHandle fd, long offset, long length);
+ internal enum LockType : short
+ {
+ F_UNLCK = 2, // unlock
+ F_WRLCK = 3 // exclusive or write lock
+ }
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_UnlockFileRegion", SetLastError=true)]
- internal static extern int UnlockFileRegion(SafeHandle fd, long offset, long length);
+ [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LockFileRegion", SetLastError=true)]
+ internal static extern int LockFileRegion(SafeHandle fd, long offset, long length, LockType lockType);
}
}
/// <param name="length">The range to be locked.</param>
private void LockInternal(long position, long length)
{
- CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length));
+ CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_WRLCK));
}
/// <summary>Allows access by other processes to all or part of a file that was previously locked.</summary>
/// <param name="length">The range to be unlocked.</param>
private void UnlockInternal(long position, long length)
{
- CheckFileCall(Interop.Sys.UnlockFileRegion(_fileHandle, position, length));
+ CheckFileCall(Interop.Sys.LockFileRegion(_fileHandle, position, length, Interop.Sys.LockType.F_UNLCK));
}
/// <summary>Sets the current position of this stream to the given value.</summary>