1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) Linux Test Project, 2001-2012
4 * Copyright (c) International Business Machines Corp., 2001
5 */
6
7 #include <stdlib.h>
8 #include <unistd.h>
9
10 #include "nfs_flock.h"
11
lock_reg(int fd,int type,off_t offset,int whence,off_t len,int cmd)12 int lock_reg(int fd, int type, off_t offset, int whence, off_t len, int cmd)
13 {
14 struct flock lock;
15
16 lock.l_type = type;
17 lock.l_start = offset;
18 lock.l_whence = whence;
19 lock.l_len = len;
20
21 return (fcntl(fd, cmd, &lock));
22 }
23
lock_test(int fd,int type,off_t offset,int whence,int len)24 int lock_test(int fd, int type, off_t offset, int whence, int len)
25 {
26 struct flock lock;
27
28 lock.l_type = type;
29 lock.l_start = offset;
30 lock.l_whence = whence;
31 lock.l_len = len;
32
33 if (fcntl(fd, F_GETLK, &lock) < 0) {
34 perror("F_GETLK");
35 exit(2);
36 }
37
38 if (lock.l_type == F_UNLCK)
39 return (0);
40
41 return (lock.l_pid);
42 }
43