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 LAPI_FSMOUNT_H__
8 #define LAPI_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 static inline 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 static inline 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 static inline 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 static inline 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 static inline int move_mount(int from_dirfd, const char *from_pathname,
49 int to_dirfd, const char *to_pathname,
50 unsigned int flags)
51 {
52 return tst_syscall(__NR_move_mount, from_dirfd, from_pathname, to_dirfd,
53 to_pathname, flags);
54 }
55 #endif /* HAVE_MOVE_MOUNT */
56
57 #ifndef HAVE_OPEN_TREE
open_tree(int dirfd,const char * pathname,unsigned int flags)58 static inline int open_tree(int dirfd, const char *pathname, unsigned int flags)
59 {
60 return tst_syscall(__NR_open_tree, dirfd, pathname, flags);
61 }
62 #endif /* HAVE_OPEN_TREE */
63
64 /*
65 * New headers added in kernel after 5.2 release, create them for old userspace.
66 */
67
68 #ifndef OPEN_TREE_CLONE
69
70 /*
71 * open_tree() flags.
72 */
73 #define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */
74 #define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */
75
76 /*
77 * move_mount() flags.
78 */
79 #define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */
80 #define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */
81 #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
82 #define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */
83 #define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */
84 #define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
85 #define MOVE_MOUNT__MASK 0x00000077
86
87 /*
88 * fsopen() flags.
89 */
90 #define FSOPEN_CLOEXEC 0x00000001
91
92 /*
93 * fspick() flags.
94 */
95 #define FSPICK_CLOEXEC 0x00000001
96 #define FSPICK_SYMLINK_NOFOLLOW 0x00000002
97 #define FSPICK_NO_AUTOMOUNT 0x00000004
98 #define FSPICK_EMPTY_PATH 0x00000008
99
100 /*
101 * The type of fsconfig() call made.
102 */
103 enum fsconfig_command {
104 FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */
105 FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */
106 FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */
107 FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */
108 FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */
109 FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */
110 FSCONFIG_CMD_CREATE = 6, /* Invoke superblock creation */
111 FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */
112 };
113
114 /*
115 * fsmount() flags.
116 */
117 #define FSMOUNT_CLOEXEC 0x00000001
118
119 /*
120 * Mount attributes.
121 */
122 #define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
123 #define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */
124 #define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */
125 #define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */
126 #define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */
127 #define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
128 #define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
129 #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
130 #define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */
131
132 #endif /* OPEN_TREE_CLONE */
133
fsopen_supported_by_kernel(void)134 static inline void fsopen_supported_by_kernel(void)
135 {
136 long ret;
137
138 if ((tst_kvercmp(5, 2, 0)) < 0) {
139 /* Check if the syscall is backported on an older kernel */
140 ret = syscall(__NR_fsopen, NULL, 0);
141 if (ret != -1)
142 SAFE_CLOSE(ret);
143 else if (errno == ENOSYS)
144 tst_brk(TCONF, "Test not supported on kernel version < v5.2");
145 }
146 }
147
148 #endif /* LAPI_FSMOUNT_H__ */
149