aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHorst Birthelmer <hbirthelmer@ddn.com>2024-11-20 16:14:43 +0100
committerBernd Schubert <bernd.schubert@fastmail.fm>2024-11-27 13:38:56 +0100
commit4ec109d1c447bbf5be05854e32d8683bb1df5a80 (patch)
tree4283922b8aee6846ea111499285174232ed062b8 /test
parent8b34ed03682bb7806a6083b05187c4fc5475a135 (diff)
downloadlibfuse-4ec109d1c447bbf5be05854e32d8683bb1df5a80.tar.gz
support FUSE_TMPFILE in the low level API
Note that name hashes and using paths as parameters makes it very hard to support anonymous files in the high level API. Known Issues: - tests have to bail out when O_TMPFILE is not supported. This will always be the case with high level passthrough implementations. - test_create_and_link_tmpfile has to be skipped due to unidentified problems with github runner
Diffstat (limited to 'test')
-rw-r--r--test/stracedecode.c1
-rw-r--r--test/test_syscalls.c100
2 files changed, 101 insertions, 0 deletions
diff --git a/test/stracedecode.c b/test/stracedecode.c
index 940438a..01bf523 100644
--- a/test/stracedecode.c
+++ b/test/stracedecode.c
@@ -38,6 +38,7 @@ static struct {
[FUSE_SETLKW] = { "SETLKW" },
[FUSE_ACCESS] = { "ACCESS" },
[FUSE_CREATE] = { "CREATE" },
+ [FUSE_TMPFILE] = { "TMPFILE" },
[FUSE_INTERRUPT] = { "INTERRUPT" },
[FUSE_BMAP] = { "BMAP" },
[FUSE_DESTROY] = { "DESTROY" },
diff --git a/test/test_syscalls.c b/test/test_syscalls.c
index 2ba55de..7a2389d 100644
--- a/test/test_syscalls.c
+++ b/test/test_syscalls.c
@@ -1957,6 +1957,104 @@ static int do_test_create_ro_dir(int flags, const char *flags_str)
return 0;
}
+/* this tests open with O_TMPFILE
+ note that this will only work with the fuse low level api
+ you will get ENOTSUP with the high level api */
+static int test_create_tmpfile(void)
+{
+ rmdir(testdir);
+ int res = mkdir(testdir, 0777);
+ if (res)
+ return -1;
+
+ start_test("create tmpfile");
+
+ int fd = open(testdir, O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);
+ if(fd == -1) {
+ if (errno == ENOTSUP) {
+ /* don't bother if we're working on an old kernel
+ or on the high level API */
+ return 0;
+ }
+
+ PERROR("open O_TMPFILE | O_RDWR");
+ return -1;
+ }
+ close(fd);
+
+ fd = open(testdir, O_TMPFILE | O_WRONLY | O_EXCL, S_IRUSR | S_IWUSR);
+ if(fd == -1){
+ PERROR("open with O_TMPFILE | O_WRONLY | O_EXCL");
+ return -1;
+ };
+ close(fd);
+
+ fd = open(testdir, O_TMPFILE | O_RDONLY, S_IRUSR);
+ if (fd != -1) {
+ ERROR("open with O_TMPFILE | O_RDONLY succeeded");
+ return -1;
+ }
+
+ success();
+ return 0;
+}
+
+static int test_create_and_link_tmpfile(void)
+{
+ /* skip this test for now since the github runner will fail in the linkat call below */
+ return 0;
+
+ rmdir(testdir);
+ unlink(testfile);
+
+ int res = mkdir(testdir, 0777);
+ if (res)
+ return -1;
+
+ start_test("create and link tmpfile");
+
+ int fd = open(testdir, O_TMPFILE | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
+ if(fd == -1) {
+ if (errno == ENOTSUP) {
+ /* don't bother if we're working on an old kernel
+ or on the high level API */
+ return 0;
+ }
+ PERROR("open with O_TMPFILE | O_RDWR | O_EXCL");
+ return -1;
+ }
+
+ if (!linkat(fd, "", AT_FDCWD, testfile, AT_EMPTY_PATH)) {
+ ERROR("linkat succeeded on a tmpfile opened with O_EXCL");
+ return -1;
+ }
+ close(fd);
+
+ fd = open(testdir, O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);
+ if(fd == -1) {
+ PERROR("open O_TMPFILE");
+ return -1;
+ }
+
+ if (check_nonexist(testfile)) {
+ return -1;
+ }
+
+ if (linkat(fd, "", AT_FDCWD, testfile, AT_EMPTY_PATH)) {
+ PERROR("linkat tempfile");
+ return -1;
+ }
+ close(fd);
+
+ if (check_nlink(testfile, 1)) {
+ return -1;
+ }
+ unlink(testfile);
+
+ success();
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int err = 0;
@@ -2085,6 +2183,8 @@ int main(int argc, char *argv[])
err += test_create_ro_dir(O_CREAT | O_WRONLY);
err += test_create_ro_dir(O_CREAT | O_TRUNC);
err += test_copy_file_range();
+ err += test_create_tmpfile();
+ err += test_create_and_link_tmpfile();
unlink(testfile2);
unlink(testsock);