1
/* Copyright (C) 2000-2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#if defined(__NETWARE__)
17
#include "../mysys/my_lock.c"
20
#undef MAP_TO_USE_RAID /* Avoid RAID mappings */
21
#include <my_global.h>
23
#include <mysys_err.h>
24
#include <my_pthread.h>
25
#include <thr_alarm.h>
28
/* Lock a part of a file */
30
int my_lock(File fd,int locktype,my_off_t start,my_off_t length,myf MyFlags)
36
DBUG_ENTER("my_lock");
37
DBUG_PRINT("my",("Fd: %d Op: %d start: %ld Length: %ld MyFlags: %d",
38
fd,locktype,(ulong) start,(ulong) length,MyFlags));
39
if (my_disable_locking)
40
DBUG_RETURN(0); /* purecov: inspected */
41
m_lock.l_type=(short) locktype;
43
m_lock.l_start=(long) start;
44
m_lock.l_len=(long) length;
45
wait_for_alarm=(MyFlags & MY_DONT_WAIT ? MY_HOW_OFTEN_TO_ALARM :
47
if (fcntl(fd,F_SETLK,&m_lock) != -1) /* Check if we can lock */
48
DBUG_RETURN(0); /* Ok, file locked */
49
DBUG_PRINT("info",("Was locked, trying with alarm"));
50
if (!thr_alarm(&alarmed,wait_for_alarm,&alarm_buff))
53
while ((value=fcntl(fd,F_SETLKW,&m_lock)) && !thr_got_alarm(&alarmed) &&
55
thr_end_alarm(&alarmed);
63
if (errno == EINTR || errno == EACCES)
64
my_errno=EAGAIN; /* Easier to check for this */
70
if (locktype == F_UNLCK)
71
my_error(EE_CANTUNLOCK,MYF(ME_BELL+ME_WAITTANG),errno);
73
my_error(EE_CANTLOCK,MYF(ME_BELL+ME_WAITTANG),errno);
75
DBUG_PRINT("error",("errno: %d",errno));