• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31 
32 #include <sys/syscall.h>
33 
34 #ifdef __NR_fcntl64
35 
36 # define TEST_SYSCALL_NAME fcntl64
37 # include "struct_flock.c"
38 
39 #define TEST_FLOCK64_EINVAL(cmd) test_flock64_einval(cmd, #cmd)
40 
41 static void
test_flock64_einval(const int cmd,const char * name)42 test_flock64_einval(const int cmd, const char *name)
43 {
44 	struct_kernel_flock64 fl = {
45 		.l_type = F_RDLCK,
46 		.l_start = 0xdefaced1facefeed,
47 		.l_len = 0xdefaced2cafef00d
48 	};
49 	syscall(TEST_SYSCALL_NR, 0, cmd, &fl);
50 	printf("%s(0, %s, {l_type=F_RDLCK, l_whence=SEEK_SET"
51 	       ", l_start=%jd, l_len=%jd}) = %s\n", TEST_SYSCALL_STR, name,
52 	       (intmax_t) fl.l_start, (intmax_t) fl.l_len, EINVAL_STR);
53 }
54 
55 static void
test_flock64(void)56 test_flock64(void)
57 {
58 	TEST_FLOCK64_EINVAL(F_SETLK64);
59 	TEST_FLOCK64_EINVAL(F_SETLKW64);
60 #ifdef F_OFD_SETLK
61 	TEST_FLOCK64_EINVAL(F_OFD_SETLK);
62 	TEST_FLOCK64_EINVAL(F_OFD_SETLKW);
63 #endif
64 
65 	struct_kernel_flock64 fl = {
66 		.l_type = F_RDLCK,
67 		.l_len = FILE_LEN
68 	};
69 	int rc = syscall(TEST_SYSCALL_NR, 0, F_SETLK64, &fl);
70 	printf("%s(0, F_SETLK64, {l_type=F_RDLCK, l_whence=SEEK_SET"
71 	       ", l_start=0, l_len=%d}) = %s\n",
72 	       TEST_SYSCALL_STR, FILE_LEN, rc ? EINVAL_STR : "0");
73 
74 	if (rc)
75 		return;
76 
77 	syscall(TEST_SYSCALL_NR, 0, F_GETLK64, &fl);
78 	printf("%s(0, F_GETLK64, {l_type=F_UNLCK, l_whence=SEEK_SET"
79 	       ", l_start=0, l_len=%d, l_pid=0}) = 0\n",
80 	       TEST_SYSCALL_STR, FILE_LEN);
81 
82 	syscall(TEST_SYSCALL_NR, 0, F_SETLK64, &fl);
83 	printf("%s(0, F_SETLK64, {l_type=F_UNLCK, l_whence=SEEK_SET"
84 	       ", l_start=0, l_len=%d}) = 0\n",
85 	       TEST_SYSCALL_STR, FILE_LEN);
86 }
87 
88 int
main(void)89 main(void)
90 {
91 	if (create_sample())
92 		return 77;
93 
94 	test_flock();
95 	test_flock64();
96 
97 	puts("+++ exited with 0 +++");
98 	return 0;
99 }
100 
101 #else
102 
103 int
main(void)104 main(void)
105 {
106 	return 77;
107 }
108 
109 #endif
110