• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
4  *
5  * Basic fspick() test.
6  */
7 #include "tst_test.h"
8 #include "lapi/fsmount.h"
9 
10 #define MNTPOINT		"mntpoint"
11 #define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
12 
13 static struct tcase {
14 	char *name;
15 	unsigned int flags;
16 } tcases[] = {
17 	TCASE_ENTRY(FSPICK_CLOEXEC),
18 	TCASE_ENTRY(FSPICK_SYMLINK_NOFOLLOW),
19 	TCASE_ENTRY(FSPICK_NO_AUTOMOUNT),
20 	TCASE_ENTRY(FSPICK_EMPTY_PATH),
21 };
22 
run(unsigned int n)23 static void run(unsigned int n)
24 {
25 	struct tcase *tc = &tcases[n];
26 	int fspick_fd;
27 
28 	TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
29 	if (fspick_fd == -1) {
30 		tst_res(TFAIL | TTERRNO, "fspick() failed");
31 		return;
32 	}
33 
34 	TEST(fsconfig(fspick_fd, FSCONFIG_SET_STRING, "sync", "false", 0));
35 	if (TST_RET == -1) {
36 		tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_STRING) failed");
37 		goto out;
38 	}
39 
40 	TEST(fsconfig(fspick_fd, FSCONFIG_SET_FLAG, "ro", NULL, 0));
41 	if (TST_RET == -1) {
42 		tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_FLAG) failed");
43 		goto out;
44 	}
45 
46 	TEST(fsconfig(fspick_fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0));
47 	if (TST_RET == -1) {
48 		tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_CMD_RECONFIGURE) failed");
49 		goto out;
50 	}
51 
52 	tst_res(TPASS, "%s: fspick() passed", tc->name);
53 
54 out:
55 	SAFE_CLOSE(fspick_fd);
56 }
57 
58 static struct tst_test test = {
59 	.tcnt = ARRAY_SIZE(tcases),
60 	.test = run,
61 	.setup = fsopen_supported_by_kernel,
62 	.needs_root = 1,
63 	.mount_device = 1,
64 	.mntpoint = MNTPOINT,
65 	.all_filesystems = 1,
66 	.skip_filesystems = (const char *const []){"fuse", NULL},
67 };
68