Imported Upstream version 2.6.0
[debian/amanda] / common-src / amflock-posix.c
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26
27 /* moved from amflock.c by Dustin J. Mitchell <dustin@zmanda.com> */
28
29 #include "amanda.h"
30
31 static int
32 posix_lock(
33     int fd,
34     G_GNUC_UNUSED char *resource)
35 {
36     struct flock lock;
37
38     lock.l_type = F_WRLCK;
39     lock.l_start = 0;
40     lock.l_whence = SEEK_SET;
41     lock.l_len = 0; /* to EOF */
42     return fcntl(fd, F_SETLKW, &lock);
43 }
44
45 static int
46 posix_rolock(
47     int fd,
48     G_GNUC_UNUSED char *resource)
49 {
50     struct flock lock;
51
52     lock.l_type = F_RDLCK;
53     lock.l_start = 0;
54     lock.l_whence = SEEK_SET;
55     lock.l_len = 0; /* to EOF */
56     return fcntl(fd, F_SETLKW, &lock);
57 }
58
59 static int
60 posix_unlock(
61     int fd,
62     G_GNUC_UNUSED char *resource)
63 {
64     struct flock lock;
65
66     lock.l_type = F_UNLCK;
67     lock.l_start = 0;
68     lock.l_whence = SEEK_SET;
69     lock.l_len = 0; /* to EOF */
70     return fcntl(fd, F_SETLK, &lock);
71 }
72
73 amflock_impl_t amflock_posix_impl = {
74     posix_lock,
75     posix_rolock,
76     posix_unlock,
77     "posix"
78 };