From: Wei Gao via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY
Date: Sat, 28 Dec 2024 06:44:16 -0500 [thread overview]
Message-ID: <20241228114416.12653-1-wegao@suse.com> (raw)
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/lapi/fcntl.h | 8 ++++
runtest/syscalls | 2 +
testcases/kernel/syscalls/fcntl/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl40.c | 52 ++++++++++++++++++++++
4 files changed, 64 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl40.c
diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index 761331798..7c0502488 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -154,6 +154,14 @@
# define RENAME_WHITEOUT (1 << 2)
#endif
+#ifndef F_LINUX_SPECIFIC_BASE
+#define F_LINUX_SPECIFIC_BASE 1024
+#endif
+
+#ifndef F_CREATED_QUERY
+#define F_CREATED_QUERY (F_LINUX_SPECIFIC_BASE + 4)
+#endif
+
/* splice, vmsplice, tee */
#ifndef SPLICE_F_NONBLOCK
diff --git a/runtest/syscalls b/runtest/syscalls
index ded035ee8..43e493eb1 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -363,6 +363,8 @@ fcntl38 fcntl38
fcntl38_64 fcntl38_64
fcntl39 fcntl39
fcntl39_64 fcntl39_64
+fcntl40 fcntl40
+fcntl40_64 fcntl40_64
fdatasync01 fdatasync01
fdatasync02 fdatasync02
diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore
index e60176973..e3486ee45 100644
--- a/testcases/kernel/syscalls/fcntl/.gitignore
+++ b/testcases/kernel/syscalls/fcntl/.gitignore
@@ -72,3 +72,5 @@
/fcntl38_64
/fcntl39
/fcntl39_64
+/fcntl40
+/fcntl40_64
diff --git a/testcases/kernel/syscalls/fcntl/fcntl40.c b/testcases/kernel/syscalls/fcntl/fcntl40.c
new file mode 100644
index 000000000..ef03becef
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl40.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE Wei Gao <wegao@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Basic test for fcntl using F_CREATED_QUERY.
+ *
+ * It is based on the following kernel commit:
+ * commit d0fe8920cbe42547798fd806f078eeaaba05df18
+ * Author: Christian Brauner brauner@kernel.org
+ * Date: Wed Jul 24 15:15:36 2024 +0200
+ */
+
+#include "lapi/fcntl.h"
+#include "tst_test.h"
+
+static void verify_fcntl(void)
+{
+ for (int i = 0; i < 101; i++) {
+ int fd;
+ char path[PATH_MAX];
+
+ fd = SAFE_OPEN("/dev/null", O_RDONLY | O_CLOEXEC);
+
+ /* We didn't create "/dev/null". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ close(fd);
+
+ sprintf(path, "aaaa_%d", i);
+ fd = SAFE_OPEN(path, O_CREAT | O_RDONLY | O_CLOEXEC, 0600);
+
+ /* We created "aaaa_%d". */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 1);
+ close(fd);
+
+ fd = SAFE_OPEN(path, O_RDONLY | O_CLOEXEC);
+
+ /* We're opening it again, so no positive creation check. */
+ TST_EXP_EQ_LI(fcntl(fd, F_CREATED_QUERY, 0), 0);
+ close(fd);
+ unlink(path);
+ }
+}
+
+static struct tst_test test = {
+ .test_all = verify_fcntl,
+ .needs_tmpdir = 1,
+ .min_kver = "6.12",
+};
--
2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2024-12-28 11:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-28 11:44 Wei Gao via ltp [this message]
2025-02-20 12:34 ` [LTP] [PATCH v1] fcntl40.c: Test fcntl using F_CREATED_QUERY Andrea Cervesato via ltp
2025-03-01 6:31 ` [LTP] [PATCH v2] " Wei Gao via ltp
2025-03-03 8:24 ` Andrea Cervesato via ltp
2025-04-01 7:56 ` [LTP] [PATCH v3] " Wei Gao via ltp
2025-04-02 10:29 ` Cyril Hrubis
2025-04-03 6:58 ` [LTP] [PATCH v4] " Wei Gao via ltp
2025-04-07 11:31 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241228114416.12653-1-wegao@suse.com \
--to=ltp@lists.linux.it \
--cc=wegao@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.