// Grabs a file lock
@cli.System.Security.SecuritySafeCriticalAttribute.Annotation
static int lock0(FileDescriptor fd, boolean blocking, long pos, long size, boolean shared) throws IOException
{
FileStream fs = (FileStream)fd.getStream();
if (winNT)
{
int LOCKFILE_FAIL_IMMEDIATELY = 1;
int LOCKFILE_EXCLUSIVE_LOCK = 2;
int ERROR_LOCK_VIOLATION = 33;
int flags = 0;
OVERLAPPED o = new OVERLAPPED();
o.OffsetLow = (int)pos;
o.OffsetHigh = (int)(pos >> 32);
if (!blocking)
{
flags |= LOCKFILE_FAIL_IMMEDIATELY;
}
if (!shared)
{
flags |= LOCKFILE_EXCLUSIVE_LOCK;
}
int result = LockFileEx(fs.get_SafeFileHandle(), flags, 0, (int)size, (int)(size >> 32), o);
if (result == 0)
{
int error = cli.System.Runtime.InteropServices.Marshal.GetLastWin32Error();
if (!blocking && error == ERROR_LOCK_VIOLATION)
{
return NO_LOCK;
}
throw new IOException("Lock failed");
}
return LOCKED;
}
else
{
try
{
if (false) throw new cli.System.ArgumentOutOfRangeException();
for (;;)
{
try
{
if (false) throw new cli.System.IO.IOException();
if (false) throw new cli.System.ObjectDisposedException("");
fs.Lock(pos, size);
return shared ? RET_EX_LOCK : LOCKED;
}
catch (cli.System.IO.IOException x)
{
if (!blocking)