xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/fcntl/fcntl11.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /*
2*49cdfc7eSAndroid Build Coastguard Worker  *
3*49cdfc7eSAndroid Build Coastguard Worker  *   Copyright (c) International Business Machines  Corp., 2001
4*49cdfc7eSAndroid Build Coastguard Worker  *
5*49cdfc7eSAndroid Build Coastguard Worker  *   This program is free software;  you can redistribute it and/or modify
6*49cdfc7eSAndroid Build Coastguard Worker  *   it under the terms of the GNU General Public License as published by
7*49cdfc7eSAndroid Build Coastguard Worker  *   the Free Software Foundation; either version 2 of the License, or
8*49cdfc7eSAndroid Build Coastguard Worker  *   (at your option) any later version.
9*49cdfc7eSAndroid Build Coastguard Worker  *
10*49cdfc7eSAndroid Build Coastguard Worker  *   This program is distributed in the hope that it will be useful,
11*49cdfc7eSAndroid Build Coastguard Worker  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12*49cdfc7eSAndroid Build Coastguard Worker  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13*49cdfc7eSAndroid Build Coastguard Worker  *   the GNU General Public License for more details.
14*49cdfc7eSAndroid Build Coastguard Worker  *
15*49cdfc7eSAndroid Build Coastguard Worker  *   You should have received a copy of the GNU General Public License
16*49cdfc7eSAndroid Build Coastguard Worker  *   along with this program;  if not, write to the Free Software
17*49cdfc7eSAndroid Build Coastguard Worker  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*49cdfc7eSAndroid Build Coastguard Worker  */
19*49cdfc7eSAndroid Build Coastguard Worker 
20*49cdfc7eSAndroid Build Coastguard Worker /*
21*49cdfc7eSAndroid Build Coastguard Worker  * NAME
22*49cdfc7eSAndroid Build Coastguard Worker  *	fcntl11.c
23*49cdfc7eSAndroid Build Coastguard Worker  *
24*49cdfc7eSAndroid Build Coastguard Worker  * DESCRIPTION
25*49cdfc7eSAndroid Build Coastguard Worker  *	Testcase to check locking of regions of a file
26*49cdfc7eSAndroid Build Coastguard Worker  *
27*49cdfc7eSAndroid Build Coastguard Worker  * ALGORITHM
28*49cdfc7eSAndroid Build Coastguard Worker  *	Test changing lock sections around a write lock
29*49cdfc7eSAndroid Build Coastguard Worker  *
30*49cdfc7eSAndroid Build Coastguard Worker  * USAGE
31*49cdfc7eSAndroid Build Coastguard Worker  *	fcntl11
32*49cdfc7eSAndroid Build Coastguard Worker  *
33*49cdfc7eSAndroid Build Coastguard Worker  * HISTORY
34*49cdfc7eSAndroid Build Coastguard Worker  *	07/2001 Ported by Wayne Boyer
35*49cdfc7eSAndroid Build Coastguard Worker  *
36*49cdfc7eSAndroid Build Coastguard Worker  * RESTRICTIONS
37*49cdfc7eSAndroid Build Coastguard Worker  *	None
38*49cdfc7eSAndroid Build Coastguard Worker  */
39*49cdfc7eSAndroid Build Coastguard Worker 
40*49cdfc7eSAndroid Build Coastguard Worker #include <fcntl.h>
41*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <sys/stat.h>
45*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
46*49cdfc7eSAndroid Build Coastguard Worker #include <inttypes.h>
47*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
48*49cdfc7eSAndroid Build Coastguard Worker #include "safe_macros.h"
49*49cdfc7eSAndroid Build Coastguard Worker 
50*49cdfc7eSAndroid Build Coastguard Worker #define STRINGSIZE	27
51*49cdfc7eSAndroid Build Coastguard Worker #define STRING		"abcdefghijklmnopqrstuvwxyz\n"
52*49cdfc7eSAndroid Build Coastguard Worker #define STOP		0xFFF0
53*49cdfc7eSAndroid Build Coastguard Worker 
54*49cdfc7eSAndroid Build Coastguard Worker int parent_pipe[2];
55*49cdfc7eSAndroid Build Coastguard Worker int child_pipe[2];
56*49cdfc7eSAndroid Build Coastguard Worker int fd;
57*49cdfc7eSAndroid Build Coastguard Worker pid_t parent_pid, child_pid;
58*49cdfc7eSAndroid Build Coastguard Worker 
59*49cdfc7eSAndroid Build Coastguard Worker void parent_put();
60*49cdfc7eSAndroid Build Coastguard Worker void parent_get();
61*49cdfc7eSAndroid Build Coastguard Worker void child_put();
62*49cdfc7eSAndroid Build Coastguard Worker void child_get();
63*49cdfc7eSAndroid Build Coastguard Worker void stop_child();
64*49cdfc7eSAndroid Build Coastguard Worker void compare_lock(struct flock *, short, short, int, int, pid_t);
65*49cdfc7eSAndroid Build Coastguard Worker void unlock_file();
66*49cdfc7eSAndroid Build Coastguard Worker void do_test(struct flock *, short, short, int, int);
67*49cdfc7eSAndroid Build Coastguard Worker void catch_child();
68*49cdfc7eSAndroid Build Coastguard Worker char *str_type();
69*49cdfc7eSAndroid Build Coastguard Worker int do_lock(int, short, short, int, int);
70*49cdfc7eSAndroid Build Coastguard Worker 
71*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "fcntl11";
72*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 1;
73*49cdfc7eSAndroid Build Coastguard Worker 
74*49cdfc7eSAndroid Build Coastguard Worker int fail;
75*49cdfc7eSAndroid Build Coastguard Worker 
cleanup(void)76*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
77*49cdfc7eSAndroid Build Coastguard Worker {
78*49cdfc7eSAndroid Build Coastguard Worker 	tst_rmdir();
79*49cdfc7eSAndroid Build Coastguard Worker 
80*49cdfc7eSAndroid Build Coastguard Worker }
81*49cdfc7eSAndroid Build Coastguard Worker 
setup(void)82*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
83*49cdfc7eSAndroid Build Coastguard Worker {
84*49cdfc7eSAndroid Build Coastguard Worker 	char *buf = STRING;
85*49cdfc7eSAndroid Build Coastguard Worker 	char template[PATH_MAX];
86*49cdfc7eSAndroid Build Coastguard Worker 	struct sigaction act;
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker 	tst_sig(FORK, DEF_HANDLER, cleanup);
89*49cdfc7eSAndroid Build Coastguard Worker 	tst_tmpdir();
90*49cdfc7eSAndroid Build Coastguard Worker 
91*49cdfc7eSAndroid Build Coastguard Worker 	umask(0);
92*49cdfc7eSAndroid Build Coastguard Worker 
93*49cdfc7eSAndroid Build Coastguard Worker 	TEST_PAUSE;
94*49cdfc7eSAndroid Build Coastguard Worker 
95*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_PIPE(cleanup, parent_pipe);
96*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_PIPE(cleanup, child_pipe);
97*49cdfc7eSAndroid Build Coastguard Worker 	parent_pid = getpid();
98*49cdfc7eSAndroid Build Coastguard Worker 	snprintf(template, PATH_MAX, "fcntl11XXXXXX");
99*49cdfc7eSAndroid Build Coastguard Worker 
100*49cdfc7eSAndroid Build Coastguard Worker 	if ((fd = mkstemp(template)) < 0)
101*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "Couldn't open temp file! errno = %d", errno);
102*49cdfc7eSAndroid Build Coastguard Worker 
103*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_WRITE(cleanup, SAFE_WRITE_ANY, fd, buf, STRINGSIZE);
104*49cdfc7eSAndroid Build Coastguard Worker 
105*49cdfc7eSAndroid Build Coastguard Worker 	memset(&act, 0, sizeof(act));
106*49cdfc7eSAndroid Build Coastguard Worker 	act.sa_handler = catch_child;
107*49cdfc7eSAndroid Build Coastguard Worker 	sigemptyset(&act.sa_mask);
108*49cdfc7eSAndroid Build Coastguard Worker 	sigaddset(&act.sa_mask, SIGCHLD);
109*49cdfc7eSAndroid Build Coastguard Worker 	if ((sigaction(SIGCHLD, &act, NULL)) < 0)
110*49cdfc7eSAndroid Build Coastguard Worker 		tst_brkm(TBROK | TERRNO, cleanup,
111*49cdfc7eSAndroid Build Coastguard Worker 			 "sigaction(SIGCHLD, ..) failed");
112*49cdfc7eSAndroid Build Coastguard Worker }
113*49cdfc7eSAndroid Build Coastguard Worker 
do_child(void)114*49cdfc7eSAndroid Build Coastguard Worker void do_child(void)
115*49cdfc7eSAndroid Build Coastguard Worker {
116*49cdfc7eSAndroid Build Coastguard Worker 	struct flock fl;
117*49cdfc7eSAndroid Build Coastguard Worker 
118*49cdfc7eSAndroid Build Coastguard Worker 	close(parent_pipe[1]);
119*49cdfc7eSAndroid Build Coastguard Worker 	close(child_pipe[0]);
120*49cdfc7eSAndroid Build Coastguard Worker 	while (1) {
121*49cdfc7eSAndroid Build Coastguard Worker 		child_get(&fl);
122*49cdfc7eSAndroid Build Coastguard Worker 		if (fcntl(fd, F_GETLK, &fl) < 0)
123*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
124*49cdfc7eSAndroid Build Coastguard Worker 		child_put(&fl);
125*49cdfc7eSAndroid Build Coastguard Worker 	}
126*49cdfc7eSAndroid Build Coastguard Worker }
127*49cdfc7eSAndroid Build Coastguard Worker 
do_lock(int cmd,short type,short whence,int start,int len)128*49cdfc7eSAndroid Build Coastguard Worker int do_lock(int cmd, short type, short whence, int start, int len)
129*49cdfc7eSAndroid Build Coastguard Worker {
130*49cdfc7eSAndroid Build Coastguard Worker 	struct flock fl;
131*49cdfc7eSAndroid Build Coastguard Worker 
132*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_type = type;
133*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_whence = whence;
134*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_start = start;
135*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_len = len;
136*49cdfc7eSAndroid Build Coastguard Worker 	return (fcntl(fd, cmd, &fl));
137*49cdfc7eSAndroid Build Coastguard Worker }
138*49cdfc7eSAndroid Build Coastguard Worker 
do_test(struct flock * fl,short type,short whence,int start,int len)139*49cdfc7eSAndroid Build Coastguard Worker void do_test(struct flock *fl, short type, short whence, int start, int len)
140*49cdfc7eSAndroid Build Coastguard Worker {
141*49cdfc7eSAndroid Build Coastguard Worker 	fl->l_type = type;
142*49cdfc7eSAndroid Build Coastguard Worker 	fl->l_whence = whence;
143*49cdfc7eSAndroid Build Coastguard Worker 	fl->l_start = start;
144*49cdfc7eSAndroid Build Coastguard Worker 	fl->l_len = len;
145*49cdfc7eSAndroid Build Coastguard Worker 	fl->l_pid = (short)0;
146*49cdfc7eSAndroid Build Coastguard Worker 
147*49cdfc7eSAndroid Build Coastguard Worker 	parent_put(fl);
148*49cdfc7eSAndroid Build Coastguard Worker 	parent_get(fl);
149*49cdfc7eSAndroid Build Coastguard Worker }
150*49cdfc7eSAndroid Build Coastguard Worker 
151*49cdfc7eSAndroid Build Coastguard Worker void
compare_lock(struct flock * fl,short type,short whence,int start,int len,pid_t pid)152*49cdfc7eSAndroid Build Coastguard Worker compare_lock(struct flock *fl, short type, short whence, int start, int len,
153*49cdfc7eSAndroid Build Coastguard Worker 	     pid_t pid)
154*49cdfc7eSAndroid Build Coastguard Worker {
155*49cdfc7eSAndroid Build Coastguard Worker 	if (fl->l_type != type)
156*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "lock type is wrong should be %s is %s",
157*49cdfc7eSAndroid Build Coastguard Worker 			 str_type(type), str_type(fl->l_type));
158*49cdfc7eSAndroid Build Coastguard Worker 
159*49cdfc7eSAndroid Build Coastguard Worker 	if (fl->l_whence != whence)
160*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "lock whence is wrong should be %d is %d",
161*49cdfc7eSAndroid Build Coastguard Worker 			 whence, fl->l_whence);
162*49cdfc7eSAndroid Build Coastguard Worker 
163*49cdfc7eSAndroid Build Coastguard Worker 	if (fl->l_start != start)
164*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "region starts in wrong place, should be "
165*49cdfc7eSAndroid Build Coastguard Worker 			 "%d is %" PRId64, start, (int64_t) fl->l_start);
166*49cdfc7eSAndroid Build Coastguard Worker 
167*49cdfc7eSAndroid Build Coastguard Worker 	if (fl->l_len != len)
168*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL,
169*49cdfc7eSAndroid Build Coastguard Worker 			 "region length is wrong, should be %d is %" PRId64,
170*49cdfc7eSAndroid Build Coastguard Worker 			 len, (int64_t) fl->l_len);
171*49cdfc7eSAndroid Build Coastguard Worker 
172*49cdfc7eSAndroid Build Coastguard Worker 	if (fl->l_pid != pid)
173*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL, "locking pid is wrong, should be %d is %d",
174*49cdfc7eSAndroid Build Coastguard Worker 			 pid, fl->l_pid);
175*49cdfc7eSAndroid Build Coastguard Worker }
176*49cdfc7eSAndroid Build Coastguard Worker 
unlock_file(void)177*49cdfc7eSAndroid Build Coastguard Worker void unlock_file(void)
178*49cdfc7eSAndroid Build Coastguard Worker {
179*49cdfc7eSAndroid Build Coastguard Worker 	struct flock fl;
180*49cdfc7eSAndroid Build Coastguard Worker 
181*49cdfc7eSAndroid Build Coastguard Worker 	if (do_lock(F_SETLK, (short)F_UNLCK, (short)0, 0, 0) < 0)
182*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TFAIL | TERRNO, "fcntl on file failed");
183*49cdfc7eSAndroid Build Coastguard Worker 	do_test(&fl, F_WRLCK, 0, 0, 0);
184*49cdfc7eSAndroid Build Coastguard Worker 	compare_lock(&fl, (short)F_UNLCK, (short)0, 0, 0, (pid_t) 0);
185*49cdfc7eSAndroid Build Coastguard Worker }
186*49cdfc7eSAndroid Build Coastguard Worker 
str_type(int type)187*49cdfc7eSAndroid Build Coastguard Worker char *str_type(int type)
188*49cdfc7eSAndroid Build Coastguard Worker {
189*49cdfc7eSAndroid Build Coastguard Worker 	static char buf[20];
190*49cdfc7eSAndroid Build Coastguard Worker 
191*49cdfc7eSAndroid Build Coastguard Worker 	switch (type) {
192*49cdfc7eSAndroid Build Coastguard Worker 	case F_RDLCK:
193*49cdfc7eSAndroid Build Coastguard Worker 		return ("F_RDLCK");
194*49cdfc7eSAndroid Build Coastguard Worker 	case F_WRLCK:
195*49cdfc7eSAndroid Build Coastguard Worker 		return ("F_WRLCK");
196*49cdfc7eSAndroid Build Coastguard Worker 	case F_UNLCK:
197*49cdfc7eSAndroid Build Coastguard Worker 		return ("F_UNLCK");
198*49cdfc7eSAndroid Build Coastguard Worker 	default:
199*49cdfc7eSAndroid Build Coastguard Worker 		sprintf(buf, "BAD VALUE: %d", type);
200*49cdfc7eSAndroid Build Coastguard Worker 		return (buf);
201*49cdfc7eSAndroid Build Coastguard Worker 	}
202*49cdfc7eSAndroid Build Coastguard Worker }
203*49cdfc7eSAndroid Build Coastguard Worker 
parent_put(struct flock * l)204*49cdfc7eSAndroid Build Coastguard Worker void parent_put(struct flock *l)
205*49cdfc7eSAndroid Build Coastguard Worker {
206*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_WRITE(cleanup, SAFE_WRITE_ALL, parent_pipe[1], l, sizeof(*l));
207*49cdfc7eSAndroid Build Coastguard Worker }
208*49cdfc7eSAndroid Build Coastguard Worker 
parent_get(struct flock * l)209*49cdfc7eSAndroid Build Coastguard Worker void parent_get(struct flock *l)
210*49cdfc7eSAndroid Build Coastguard Worker {
211*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_READ(cleanup, 1, child_pipe[0], l, sizeof(*l));
212*49cdfc7eSAndroid Build Coastguard Worker }
213*49cdfc7eSAndroid Build Coastguard Worker 
child_put(struct flock * l)214*49cdfc7eSAndroid Build Coastguard Worker void child_put(struct flock *l)
215*49cdfc7eSAndroid Build Coastguard Worker {
216*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_WRITE(NULL, SAFE_WRITE_ALL, child_pipe[1], l, sizeof(*l));
217*49cdfc7eSAndroid Build Coastguard Worker }
218*49cdfc7eSAndroid Build Coastguard Worker 
child_get(struct flock * l)219*49cdfc7eSAndroid Build Coastguard Worker void child_get(struct flock *l)
220*49cdfc7eSAndroid Build Coastguard Worker {
221*49cdfc7eSAndroid Build Coastguard Worker 	SAFE_READ(NULL, 1, parent_pipe[0], l, sizeof(*l));
222*49cdfc7eSAndroid Build Coastguard Worker 	if (l->l_type == (short)STOP)
223*49cdfc7eSAndroid Build Coastguard Worker 		exit(0);
224*49cdfc7eSAndroid Build Coastguard Worker }
225*49cdfc7eSAndroid Build Coastguard Worker 
stop_child(void)226*49cdfc7eSAndroid Build Coastguard Worker void stop_child(void)
227*49cdfc7eSAndroid Build Coastguard Worker {
228*49cdfc7eSAndroid Build Coastguard Worker 	struct flock fl;
229*49cdfc7eSAndroid Build Coastguard Worker 
230*49cdfc7eSAndroid Build Coastguard Worker 	signal(SIGCHLD, SIG_DFL);
231*49cdfc7eSAndroid Build Coastguard Worker 	fl.l_type = STOP;
232*49cdfc7eSAndroid Build Coastguard Worker 	parent_put(&fl);
233*49cdfc7eSAndroid Build Coastguard Worker 	wait(0);
234*49cdfc7eSAndroid Build Coastguard Worker }
235*49cdfc7eSAndroid Build Coastguard Worker 
catch_child(void)236*49cdfc7eSAndroid Build Coastguard Worker void catch_child(void)
237*49cdfc7eSAndroid Build Coastguard Worker {
238*49cdfc7eSAndroid Build Coastguard Worker 	tst_brkm(TFAIL, cleanup, "Unexpected death of child process");
239*49cdfc7eSAndroid Build Coastguard Worker }
240*49cdfc7eSAndroid Build Coastguard Worker 
main(int ac,char ** av)241*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
242*49cdfc7eSAndroid Build Coastguard Worker {
243*49cdfc7eSAndroid Build Coastguard Worker 	struct flock tl;
244*49cdfc7eSAndroid Build Coastguard Worker 
245*49cdfc7eSAndroid Build Coastguard Worker 	int lc;
246*49cdfc7eSAndroid Build Coastguard Worker 
247*49cdfc7eSAndroid Build Coastguard Worker 	tst_parse_opts(ac, av, NULL, NULL);
248*49cdfc7eSAndroid Build Coastguard Worker 
249*49cdfc7eSAndroid Build Coastguard Worker 	setup();		/* global setup */
250*49cdfc7eSAndroid Build Coastguard Worker 
251*49cdfc7eSAndroid Build Coastguard Worker 	/* Check for looping state if -i option is given */
252*49cdfc7eSAndroid Build Coastguard Worker 	for (lc = 0; TEST_LOOPING(lc); lc++) {
253*49cdfc7eSAndroid Build Coastguard Worker 		/* reset tst_count in case we are looping */
254*49cdfc7eSAndroid Build Coastguard Worker 		tst_count = 0;
255*49cdfc7eSAndroid Build Coastguard Worker 
256*49cdfc7eSAndroid Build Coastguard Worker 		if ((child_pid = tst_fork()) == 0) /* parent */
257*49cdfc7eSAndroid Build Coastguard Worker 			do_child();
258*49cdfc7eSAndroid Build Coastguard Worker 		else if (child_pid == -1)
259*49cdfc7eSAndroid Build Coastguard Worker 			tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
260*49cdfc7eSAndroid Build Coastguard Worker 
261*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_CLOSE(cleanup, parent_pipe[0]);
262*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_CLOSE(cleanup, child_pipe[1]);
263*49cdfc7eSAndroid Build Coastguard Worker 
264*49cdfc7eSAndroid Build Coastguard Worker /* //block1: */
265*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 1");
266*49cdfc7eSAndroid Build Coastguard Worker 
267*49cdfc7eSAndroid Build Coastguard Worker 		/*
268*49cdfc7eSAndroid Build Coastguard Worker 		 * Add a write lock to the middle of the file and a read
269*49cdfc7eSAndroid Build Coastguard Worker 		 * at the begining
270*49cdfc7eSAndroid Build Coastguard Worker 		 */
271*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
272*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
273*49cdfc7eSAndroid Build Coastguard Worker 
274*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 1, 5) < 0)
275*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
276*49cdfc7eSAndroid Build Coastguard Worker 
277*49cdfc7eSAndroid Build Coastguard Worker 		/*
278*49cdfc7eSAndroid Build Coastguard Worker 		 * Test read lock
279*49cdfc7eSAndroid Build Coastguard Worker 		 */
280*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, F_WRLCK, 0, 0, 0);
281*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 1, 5, parent_pid);
282*49cdfc7eSAndroid Build Coastguard Worker 
283*49cdfc7eSAndroid Build Coastguard Worker 		/*
284*49cdfc7eSAndroid Build Coastguard Worker 		 * Test write lock
285*49cdfc7eSAndroid Build Coastguard Worker 		 */
286*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, F_WRLCK, 0, 6, 0);
287*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid);
288*49cdfc7eSAndroid Build Coastguard Worker 
289*49cdfc7eSAndroid Build Coastguard Worker 		/*
290*49cdfc7eSAndroid Build Coastguard Worker 		 * Test that the rest of the file is unlocked
291*49cdfc7eSAndroid Build Coastguard Worker 		 */
292*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, F_WRLCK, 0, 15, 0);
293*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0);
294*49cdfc7eSAndroid Build Coastguard Worker 
295*49cdfc7eSAndroid Build Coastguard Worker 		/*
296*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
297*49cdfc7eSAndroid Build Coastguard Worker 		 */
298*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
299*49cdfc7eSAndroid Build Coastguard Worker 
300*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 1");
301*49cdfc7eSAndroid Build Coastguard Worker 
302*49cdfc7eSAndroid Build Coastguard Worker /* //block2: */
303*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 2");
304*49cdfc7eSAndroid Build Coastguard Worker 
305*49cdfc7eSAndroid Build Coastguard Worker 		/*
306*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock at the middle of the file and a
307*49cdfc7eSAndroid Build Coastguard Worker 		 * read lock just before
308*49cdfc7eSAndroid Build Coastguard Worker 		 */
309*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
310*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
311*49cdfc7eSAndroid Build Coastguard Worker 
312*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 5, 5) < 0)
313*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
314*49cdfc7eSAndroid Build Coastguard Worker 
315*49cdfc7eSAndroid Build Coastguard Worker 		/*
316*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
317*49cdfc7eSAndroid Build Coastguard Worker 		 */
318*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
319*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 5, 5, parent_pid);
320*49cdfc7eSAndroid Build Coastguard Worker 
321*49cdfc7eSAndroid Build Coastguard Worker 		/*
322*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the write lock.
323*49cdfc7eSAndroid Build Coastguard Worker 		 */
324*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 10, 0);
325*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid);
326*49cdfc7eSAndroid Build Coastguard Worker 
327*49cdfc7eSAndroid Build Coastguard Worker 		/*
328*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked.
329*49cdfc7eSAndroid Build Coastguard Worker 		 */
330*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
331*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0);
332*49cdfc7eSAndroid Build Coastguard Worker 
333*49cdfc7eSAndroid Build Coastguard Worker 		/*
334*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
335*49cdfc7eSAndroid Build Coastguard Worker 		 */
336*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
337*49cdfc7eSAndroid Build Coastguard Worker 
338*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 2");
339*49cdfc7eSAndroid Build Coastguard Worker 
340*49cdfc7eSAndroid Build Coastguard Worker /* //block3: */
341*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 3");
342*49cdfc7eSAndroid Build Coastguard Worker 
343*49cdfc7eSAndroid Build Coastguard Worker 		/*
344*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock in the middle and a read lock that
345*49cdfc7eSAndroid Build Coastguard Worker 		 * ends at the first byte of the write lock
346*49cdfc7eSAndroid Build Coastguard Worker 		 */
347*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
348*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
349*49cdfc7eSAndroid Build Coastguard Worker 
350*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 5, 6) < 0)
351*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
352*49cdfc7eSAndroid Build Coastguard Worker 
353*49cdfc7eSAndroid Build Coastguard Worker 		/*
354*49cdfc7eSAndroid Build Coastguard Worker 		 * Test read lock
355*49cdfc7eSAndroid Build Coastguard Worker 		 */
356*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
357*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 5, 6, parent_pid);
358*49cdfc7eSAndroid Build Coastguard Worker 
359*49cdfc7eSAndroid Build Coastguard Worker 		/*
360*49cdfc7eSAndroid Build Coastguard Worker 		 * Test write lock
361*49cdfc7eSAndroid Build Coastguard Worker 		 */
362*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 11, 0);
363*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 11, 4, parent_pid);
364*49cdfc7eSAndroid Build Coastguard Worker 
365*49cdfc7eSAndroid Build Coastguard Worker 		/*
366*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked.
367*49cdfc7eSAndroid Build Coastguard Worker 		 */
368*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
369*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0);
370*49cdfc7eSAndroid Build Coastguard Worker 
371*49cdfc7eSAndroid Build Coastguard Worker 		/*
372*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
373*49cdfc7eSAndroid Build Coastguard Worker 		 */
374*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
375*49cdfc7eSAndroid Build Coastguard Worker 
376*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 3");
377*49cdfc7eSAndroid Build Coastguard Worker 
378*49cdfc7eSAndroid Build Coastguard Worker /* //block4: */
379*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 4");
380*49cdfc7eSAndroid Build Coastguard Worker 
381*49cdfc7eSAndroid Build Coastguard Worker 		/*
382*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock on the middle of the file and a read
383*49cdfc7eSAndroid Build Coastguard Worker 		 * lock that overlaps the front of the write.
384*49cdfc7eSAndroid Build Coastguard Worker 		 */
385*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
386*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
387*49cdfc7eSAndroid Build Coastguard Worker 
388*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 5, 8) < 0)
389*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
390*49cdfc7eSAndroid Build Coastguard Worker 
391*49cdfc7eSAndroid Build Coastguard Worker 		/*
392*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
393*49cdfc7eSAndroid Build Coastguard Worker 		 */
394*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 5, 0);
395*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 5, 8, parent_pid);
396*49cdfc7eSAndroid Build Coastguard Worker 
397*49cdfc7eSAndroid Build Coastguard Worker 		/*
398*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the write lock
399*49cdfc7eSAndroid Build Coastguard Worker 		 */
400*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 13, 0);
401*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 13, 2, parent_pid);
402*49cdfc7eSAndroid Build Coastguard Worker 
403*49cdfc7eSAndroid Build Coastguard Worker 		/*
404*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked.
405*49cdfc7eSAndroid Build Coastguard Worker 		 */
406*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
407*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 0, 0);
408*49cdfc7eSAndroid Build Coastguard Worker 
409*49cdfc7eSAndroid Build Coastguard Worker 		/*
410*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
411*49cdfc7eSAndroid Build Coastguard Worker 		 */
412*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
413*49cdfc7eSAndroid Build Coastguard Worker 
414*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 4");
415*49cdfc7eSAndroid Build Coastguard Worker 
416*49cdfc7eSAndroid Build Coastguard Worker /* //block5: */
417*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 5");
418*49cdfc7eSAndroid Build Coastguard Worker 
419*49cdfc7eSAndroid Build Coastguard Worker 		/*
420*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock in the middle of a file and a read
421*49cdfc7eSAndroid Build Coastguard Worker 		 * lock in the middle of it
422*49cdfc7eSAndroid Build Coastguard Worker 		 */
423*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 10) < 0)
424*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
425*49cdfc7eSAndroid Build Coastguard Worker 
426*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 13, 5) < 0)
427*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
428*49cdfc7eSAndroid Build Coastguard Worker 
429*49cdfc7eSAndroid Build Coastguard Worker 		/*
430*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the first write lock
431*49cdfc7eSAndroid Build Coastguard Worker 		 */
432*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
433*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 3, parent_pid);
434*49cdfc7eSAndroid Build Coastguard Worker 
435*49cdfc7eSAndroid Build Coastguard Worker 		/*
436*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
437*49cdfc7eSAndroid Build Coastguard Worker 		 */
438*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 13, 0);
439*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 13, 5, parent_pid);
440*49cdfc7eSAndroid Build Coastguard Worker 
441*49cdfc7eSAndroid Build Coastguard Worker 		/*
442*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the second write lock
443*49cdfc7eSAndroid Build Coastguard Worker 		 */
444*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 18, 0);
445*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 18, 2, parent_pid);
446*49cdfc7eSAndroid Build Coastguard Worker 
447*49cdfc7eSAndroid Build Coastguard Worker 		/*
448*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked
449*49cdfc7eSAndroid Build Coastguard Worker 		 */
450*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 20, 0);
451*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, 0);
452*49cdfc7eSAndroid Build Coastguard Worker 
453*49cdfc7eSAndroid Build Coastguard Worker 		/*
454*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above.
455*49cdfc7eSAndroid Build Coastguard Worker 		 */
456*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
457*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 5");
458*49cdfc7eSAndroid Build Coastguard Worker 
459*49cdfc7eSAndroid Build Coastguard Worker /* //block6: */
460*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 6");
461*49cdfc7eSAndroid Build Coastguard Worker 		/*
462*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock in the middle of the file and a read
463*49cdfc7eSAndroid Build Coastguard Worker 		 * lock that overlaps the end
464*49cdfc7eSAndroid Build Coastguard Worker 		 */
465*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
466*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
467*49cdfc7eSAndroid Build Coastguard Worker 
468*49cdfc7eSAndroid Build Coastguard Worker 		/*
469*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a read lock on the whole file
470*49cdfc7eSAndroid Build Coastguard Worker 		 */
471*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 13, 5) < 0)
472*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
473*49cdfc7eSAndroid Build Coastguard Worker 
474*49cdfc7eSAndroid Build Coastguard Worker 		/*
475*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the write lock
476*49cdfc7eSAndroid Build Coastguard Worker 		 */
477*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
478*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 3, parent_pid);
479*49cdfc7eSAndroid Build Coastguard Worker 
480*49cdfc7eSAndroid Build Coastguard Worker 		/*
481*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
482*49cdfc7eSAndroid Build Coastguard Worker 		 */
483*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 13, 0);
484*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 13, 5, parent_pid);
485*49cdfc7eSAndroid Build Coastguard Worker 
486*49cdfc7eSAndroid Build Coastguard Worker 		/*
487*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked
488*49cdfc7eSAndroid Build Coastguard Worker 		 */
489*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 18, 0);
490*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 18, 0, 0);
491*49cdfc7eSAndroid Build Coastguard Worker 
492*49cdfc7eSAndroid Build Coastguard Worker 		/*
493*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
494*49cdfc7eSAndroid Build Coastguard Worker 		 */
495*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
496*49cdfc7eSAndroid Build Coastguard Worker 
497*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 6");
498*49cdfc7eSAndroid Build Coastguard Worker 
499*49cdfc7eSAndroid Build Coastguard Worker /* //block7: */
500*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 7");
501*49cdfc7eSAndroid Build Coastguard Worker 
502*49cdfc7eSAndroid Build Coastguard Worker 		/*
503*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock in the middle of the file and a read
504*49cdfc7eSAndroid Build Coastguard Worker 		 * lock starting at the last byte of the write lock
505*49cdfc7eSAndroid Build Coastguard Worker 		 */
506*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
507*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
508*49cdfc7eSAndroid Build Coastguard Worker 
509*49cdfc7eSAndroid Build Coastguard Worker 		/*
510*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a read lock on the whole file.
511*49cdfc7eSAndroid Build Coastguard Worker 		 */
512*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 14, 5) < 0)
513*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
514*49cdfc7eSAndroid Build Coastguard Worker 
515*49cdfc7eSAndroid Build Coastguard Worker 		/*
516*49cdfc7eSAndroid Build Coastguard Worker 		 * Test write lock
517*49cdfc7eSAndroid Build Coastguard Worker 		 */
518*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
519*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 4, parent_pid);
520*49cdfc7eSAndroid Build Coastguard Worker 
521*49cdfc7eSAndroid Build Coastguard Worker 		/*
522*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
523*49cdfc7eSAndroid Build Coastguard Worker 		 */
524*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 14, 0);
525*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 14, 5, parent_pid);
526*49cdfc7eSAndroid Build Coastguard Worker 
527*49cdfc7eSAndroid Build Coastguard Worker 		/*
528*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the end of the file is unlocked
529*49cdfc7eSAndroid Build Coastguard Worker 		 */
530*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 19, 0);
531*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 19, 0, 0);
532*49cdfc7eSAndroid Build Coastguard Worker 
533*49cdfc7eSAndroid Build Coastguard Worker 		/*
534*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
535*49cdfc7eSAndroid Build Coastguard Worker 		 */
536*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
537*49cdfc7eSAndroid Build Coastguard Worker 
538*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 7");
539*49cdfc7eSAndroid Build Coastguard Worker 
540*49cdfc7eSAndroid Build Coastguard Worker /* //block8: */
541*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 8");
542*49cdfc7eSAndroid Build Coastguard Worker 
543*49cdfc7eSAndroid Build Coastguard Worker 		/*
544*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock in the middle of the file and a read
545*49cdfc7eSAndroid Build Coastguard Worker 		 * lock that starts just after the last byte of the
546*49cdfc7eSAndroid Build Coastguard Worker 		 * write lock.
547*49cdfc7eSAndroid Build Coastguard Worker 		 */
548*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
549*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
550*49cdfc7eSAndroid Build Coastguard Worker 
551*49cdfc7eSAndroid Build Coastguard Worker 		/*
552*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a read lock on the whole file
553*49cdfc7eSAndroid Build Coastguard Worker 		 */
554*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 15, 5) < 0)
555*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
556*49cdfc7eSAndroid Build Coastguard Worker 
557*49cdfc7eSAndroid Build Coastguard Worker 		/*
558*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the write lock
559*49cdfc7eSAndroid Build Coastguard Worker 		 */
560*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
561*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid);
562*49cdfc7eSAndroid Build Coastguard Worker 
563*49cdfc7eSAndroid Build Coastguard Worker 		/*
564*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
565*49cdfc7eSAndroid Build Coastguard Worker 		 */
566*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 15, 0);
567*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 15, 5, parent_pid);
568*49cdfc7eSAndroid Build Coastguard Worker 
569*49cdfc7eSAndroid Build Coastguard Worker 		/*
570*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked
571*49cdfc7eSAndroid Build Coastguard Worker 		 */
572*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 20, 0);
573*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 20, 0, 0);
574*49cdfc7eSAndroid Build Coastguard Worker 
575*49cdfc7eSAndroid Build Coastguard Worker 		/*
576*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
577*49cdfc7eSAndroid Build Coastguard Worker 		 */
578*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
579*49cdfc7eSAndroid Build Coastguard Worker 
580*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 8");
581*49cdfc7eSAndroid Build Coastguard Worker 
582*49cdfc7eSAndroid Build Coastguard Worker /* //block9: */
583*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Enter block 9");
584*49cdfc7eSAndroid Build Coastguard Worker 
585*49cdfc7eSAndroid Build Coastguard Worker 		/*
586*49cdfc7eSAndroid Build Coastguard Worker 		 * Set a write lock at the middle of the file and a read
587*49cdfc7eSAndroid Build Coastguard Worker 		 * lock that starts past the end of the write lock.
588*49cdfc7eSAndroid Build Coastguard Worker 		 */
589*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_WRLCK, (short)0, 10, 5) < 0)
590*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
591*49cdfc7eSAndroid Build Coastguard Worker 
592*49cdfc7eSAndroid Build Coastguard Worker 		if (do_lock(F_SETLK, (short)F_RDLCK, (short)0, 16, 5) < 0)
593*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TFAIL | TERRNO, "fcntl on file failed");
594*49cdfc7eSAndroid Build Coastguard Worker 
595*49cdfc7eSAndroid Build Coastguard Worker 		/*
596*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the write lock
597*49cdfc7eSAndroid Build Coastguard Worker 		 */
598*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 0, 0);
599*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_WRLCK, (short)0, 10, 5, parent_pid);
600*49cdfc7eSAndroid Build Coastguard Worker 
601*49cdfc7eSAndroid Build Coastguard Worker 		/*
602*49cdfc7eSAndroid Build Coastguard Worker 		 * Test that byte in between is unlocked
603*49cdfc7eSAndroid Build Coastguard Worker 		 */
604*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 15, 1);
605*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 15, 1, 0);
606*49cdfc7eSAndroid Build Coastguard Worker 
607*49cdfc7eSAndroid Build Coastguard Worker 		/*
608*49cdfc7eSAndroid Build Coastguard Worker 		 * Test the read lock
609*49cdfc7eSAndroid Build Coastguard Worker 		 */
610*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 16, 0);
611*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_RDLCK, (short)0, 16, 5, parent_pid);
612*49cdfc7eSAndroid Build Coastguard Worker 
613*49cdfc7eSAndroid Build Coastguard Worker 		/*
614*49cdfc7eSAndroid Build Coastguard Worker 		 * Test to make sure the rest of the file is unlocked
615*49cdfc7eSAndroid Build Coastguard Worker 		 */
616*49cdfc7eSAndroid Build Coastguard Worker 		do_test(&tl, (short)F_WRLCK, (short)0, 21, 0);
617*49cdfc7eSAndroid Build Coastguard Worker 		compare_lock(&tl, (short)F_UNLCK, (short)0, 21, 0, 0);
618*49cdfc7eSAndroid Build Coastguard Worker 
619*49cdfc7eSAndroid Build Coastguard Worker 		/*
620*49cdfc7eSAndroid Build Coastguard Worker 		 * remove all the locks set above
621*49cdfc7eSAndroid Build Coastguard Worker 		 */
622*49cdfc7eSAndroid Build Coastguard Worker 		unlock_file();
623*49cdfc7eSAndroid Build Coastguard Worker 
624*49cdfc7eSAndroid Build Coastguard Worker 		tst_resm(TINFO, "Exit block 9");
625*49cdfc7eSAndroid Build Coastguard Worker 
626*49cdfc7eSAndroid Build Coastguard Worker 		stop_child();
627*49cdfc7eSAndroid Build Coastguard Worker 		SAFE_CLOSE(cleanup, fd);
628*49cdfc7eSAndroid Build Coastguard Worker 	}
629*49cdfc7eSAndroid Build Coastguard Worker 	cleanup();
630*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
631*49cdfc7eSAndroid Build Coastguard Worker }
632