1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2020 Linaro Limited. All rights reserved.
4 * Author: Viresh Kumar <viresh.kumar@linaro.org>
5 */
6
7 #ifndef FSMOUNT_H__
8 #define FSMOUNT_H__
9
10 #include <sys/mount.h>
11 #include <sys/syscall.h>
12 #include <sys/types.h>
13
14 #include "config.h"
15 #include "lapi/fcntl.h"
16 #include "lapi/syscalls.h"
17
18 #ifndef HAVE_FSOPEN
fsopen(const char * fsname,unsigned int flags)19 int fsopen(const char *fsname, unsigned int flags)
20 {
21 return tst_syscall(__NR_fsopen, fsname, flags);
22 }
23 #endif /* HAVE_FSOPEN */
24
25 #ifndef HAVE_FSCONFIG
fsconfig(int fd,unsigned int cmd,const char * key,const void * value,int aux)26 int fsconfig(int fd, unsigned int cmd, const char *key,
27 const void *value, int aux)
28 {
29 return tst_syscall(__NR_fsconfig, fd, cmd, key, value, aux);
30 }
31 #endif /* HAVE_FSCONFIG */
32
33 #ifndef HAVE_FSMOUNT
fsmount(int fd,unsigned int flags,unsigned int mount_attrs)34 int fsmount(int fd, unsigned int flags, unsigned int mount_attrs)
35 {
36 return tst_syscall(__NR_fsmount, fd, flags, mount_attrs);
37 }
38 #endif /* HAVE_FSMOUNT */
39
40 #ifndef HAVE_FSPICK
fspick(int dirfd,const char * pathname,unsigned int flags)41 int fspick(int dirfd, const char *pathname, unsigned int flags)
42 {
43 return tst_syscall(__NR_fspick, dirfd, pathname, flags);
44 }
45 #endif /* HAVE_FSPICK */
46
47 #ifndef HAVE_MOVE_MOUNT
move_mount(int from_dirfd,const char * from_pathname,int to_dirfd,const char * to_pathname,unsigned int flags)48 int move_mount(int from_dirfd, const char *from_pathname, int to_dirfd,
49 const char *to_pathname, unsigned int flags)
50 {
51 return tst_syscall(__NR_move_mount, from_dirfd, from_pathname, to_dirfd,
52 to_pathname, flags);
53 }
54 #endif /* HAVE_MOVE_MOUNT */
55
56 #ifndef HAVE_OPEN_TREE
open_tree(int dirfd,const char * pathname,unsigned int flags)57 int open_tree(int dirfd, const char *pathname, unsigned int flags)
58 {
59 return tst_syscall(__NR_open_tree, dirfd, pathname, flags);
60 }
61 #endif /* HAVE_OPEN_TREE */
62
63 /*
64 * New headers added in kernel after 5.2 release, create them for old userspace.
65 */
66
67 #ifndef OPEN_TREE_CLONE
68
69 /*
70 * open_tree() flags.
71 */
72 #define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */
73 #define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */
74
75 /*
76 * move_mount() flags.
77 */
78 #define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */
79 #define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */
80 #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
81 #define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */
82 #define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */
83 #define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
84 #define MOVE_MOUNT__MASK 0x00000077
85
86 /*
87 * fsopen() flags.
88 */
89 #define FSOPEN_CLOEXEC 0x00000001
90
91 /*
92 * fspick() flags.
93 */
94 #define FSPICK_CLOEXEC 0x00000001
95 #define FSPICK_SYMLINK_NOFOLLOW 0x00000002
96 #define FSPICK_NO_AUTOMOUNT 0x00000004
97 #define FSPICK_EMPTY_PATH 0x00000008
98
99 /*
100 * The type of fsconfig() call made.
101 */
102 enum fsconfig_command {
103 FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */
104 FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */
105 FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */
106 FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */
107 FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */
108 FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */
109 FSCONFIG_CMD_CREATE = 6, /* Invoke superblock creation */
110 FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */
111 };
112
113 /*
114 * fsmount() flags.
115 */
116 #define FSMOUNT_CLOEXEC 0x00000001
117
118 /*
119 * Mount attributes.
120 */
121 #define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
122 #define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */
123 #define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */
124 #define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */
125 #define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */
126 #define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
127 #define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
128 #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
129 #define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */
130
131 #endif /* OPEN_TREE_CLONE */
132
fsopen_supported_by_kernel(void)133 void fsopen_supported_by_kernel(void)
134 {
135 if ((tst_kvercmp(5, 2, 0)) < 0) {
136 /* Check if the syscall is backported on an older kernel */
137 TEST(syscall(__NR_fsopen, NULL, 0));
138 if (TST_RET != -1)
139 SAFE_CLOSE(TST_RET);
140 else if (TST_ERR == ENOSYS)
141 tst_brk(TCONF, "Test not supported on kernel version < v5.2");
142 }
143 }
144
145 #endif /* FSMOUNT_H__ */
146