Skip to content

Commit ea50eab

Browse files
Wei Gao via ltpmetan-ucw
authored andcommitted
fcntl40.c: Test fcntl using F_CREATED_QUERY
Signed-off-by: Wei Gao <wegao@suse.com> This is new test case for fcntl using new F_CREATED_QUERY operation. Based on a kernel selftest commit d0fe8920cbe4. Signed-off-by: Wei Gao <wegao@suse.com> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
1 parent 28d823a commit ea50eab

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

include/lapi/fcntl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@
154154
# define RENAME_WHITEOUT (1 << 2)
155155
#endif
156156

157+
#ifndef F_LINUX_SPECIFIC_BASE
158+
#define F_LINUX_SPECIFIC_BASE 1024
159+
#endif
160+
161+
#ifndef F_CREATED_QUERY
162+
#define F_CREATED_QUERY (F_LINUX_SPECIFIC_BASE + 4)
163+
#endif
164+
157165
/* splice, vmsplice, tee */
158166

159167
#ifndef SPLICE_F_NONBLOCK

runtest/syscalls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ fcntl38 fcntl38
362362
fcntl38_64 fcntl38_64
363363
fcntl39 fcntl39
364364
fcntl39_64 fcntl39_64
365+
fcntl40 fcntl40
366+
fcntl40_64 fcntl40_64
365367

366368
fdatasync01 fdatasync01
367369
fdatasync02 fdatasync02

testcases/kernel/syscalls/fcntl/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@
7272
/fcntl38_64
7373
/fcntl39
7474
/fcntl39_64
75+
/fcntl40
76+
/fcntl40_64
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (C) 2024 SUSE Wei Gao <wegao@suse.com>
4+
*/
5+
6+
/*\
7+
* Basic test for fcntl using F_CREATED_QUERY.
8+
* Verify if the fcntl() syscall is recognizing whether a file has been
9+
* created or not via O_CREAT when O_CLOEXEC is also used.
10+
*
11+
* Test is based on a kernel selftests commit d0fe8920cbe4.
12+
*/
13+
14+
#include "lapi/fcntl.h"
15+
#include "tst_test.h"
16+
17+
#define TEST_NAME "LTP_FCNTL_CREATED_QUERY_TEST"
18+
19+
static void verify_fcntl(void)
20+
{
21+
int fd;
22+
23+
fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
24+
25+
/* We didn't create "/dev/null". */
26+
TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
27+
SAFE_CLOSE(fd);
28+
29+
fd = SAFE_OPEN(TEST_NAME, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
30+
31+
TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
32+
SAFE_CLOSE(fd);
33+
34+
fd = SAFE_OPEN(TEST_NAME, O_RDONLY | O_CLOEXEC);
35+
36+
/* We're opening it again, so no positive creation check. */
37+
TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
38+
SAFE_CLOSE(fd);
39+
SAFE_UNLINK(TEST_NAME);
40+
}
41+
42+
static struct tst_test test = {
43+
.test_all = verify_fcntl,
44+
.needs_tmpdir = 1,
45+
.min_kver = "6.12",
46+
};

0 commit comments

Comments
 (0)