filelock-darwin.cpp revision c97989161fbe75bc14cea477a5443bbf474dd3ad
/* $Id$ */
/** @file
* innotek Portable Runtime - File Locking, POSIX.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_FILE
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
{
/* Check arguments. */
if (fLock & ~RTFILE_LOCK_MASK)
{
return VERR_INVALID_PARAMETER;
}
/*
* Validate offset.
*/
&& ( (offLock >> 32) != 0
|| (cbLock >> 32) != 0
{
return VERR_NOT_SUPPORTED;
}
/* Prepare flock structure. */
return VINF_SUCCESS;
{
/*
* This is really bad hack for getting VDIs to work somewhat
* safely on SMB mounts.
*/
/** @todo we need to keep track of these locks really. Anyone requiring to lock more
* than one part of a file will have to fix this. */
unsigned f = 0;
if (fLock & RTFILE_LOCK_WAIT)
f |= LOCK_NB;
if (fLock & RTFILE_LOCK_WRITE)
f |= LOCK_EX;
else
f |= LOCK_SH;
return VINF_SUCCESS;
if (iErr == EWOULDBLOCK)
return VERR_FILE_LOCK_VIOLATION;
}
return VERR_FILE_LOCK_VIOLATION;
return RTErrConvertFromErrno(iErr);
}
{
/** @todo We never returns VERR_FILE_NOT_LOCKED for now. */
}
{
/*
* Validate offset.
*/
&& ( (offLock >> 32) != 0
|| (cbLock >> 32) != 0
{
return VERR_NOT_SUPPORTED;
}
/* Prepare flock structure. */
return VINF_SUCCESS;
{
/* A SMB hack, see RTFileLock. */
return VINF_SUCCESS;
}
/** @todo check error codes for non existing lock. */
return VERR_FILE_LOCK_VIOLATION;
return RTErrConvertFromErrno(iErr);
}