generic: add fstests for idmapped mounts
[xfstests-dev.git] / src / idmapped-mounts / missing.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2
3 #ifndef __IDMAP_MISSING_H
4 #define __IDMAP_MISSING_H
5
6 #ifndef _GNU_SOURCE
7 #define _GNU_SOURCE
8 #endif
9 #include "../global.h"
10
11 #include <errno.h>
12 #include <linux/types.h>
13 #include <sched.h>
14 #include <signal.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <sys/types.h>
19 #include <syscall.h>
20 #include <unistd.h>
21
22 #ifndef __NR_mount_setattr
23         #if defined __alpha__
24                 #define __NR_mount_setattr 552
25         #elif defined _MIPS_SIM
26                 #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
27                         #define __NR_mount_setattr (442 + 4000)
28                 #endif
29                 #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
30                         #define __NR_mount_setattr (442 + 6000)
31                 #endif
32                 #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
33                         #define __NR_mount_setattr (442 + 5000)
34                 #endif
35         #elif defined __ia64__
36                 #define __NR_mount_setattr (442 + 1024)
37         #else
38                 #define __NR_mount_setattr 442
39         #endif
40 #endif
41
42 #ifndef __NR_open_tree
43         #if defined __alpha__
44                 #define __NR_open_tree 538
45         #elif defined _MIPS_SIM
46                 #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
47                         #define __NR_open_tree 4428
48                 #endif
49                 #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
50                         #define __NR_open_tree 6428
51                 #endif
52                 #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
53                         #define __NR_open_tree 5428
54                 #endif
55         #elif defined __ia64__
56                 #define __NR_open_tree (428 + 1024)
57         #else
58                 #define __NR_open_tree 428
59         #endif
60 #endif
61
62 #ifndef __NR_move_mount
63         #if defined __alpha__
64                 #define __NR_move_mount 539
65         #elif defined _MIPS_SIM
66                 #if _MIPS_SIM == _MIPS_SIM_ABI32        /* o32 */
67                         #define __NR_move_mount 4429
68                 #endif
69                 #if _MIPS_SIM == _MIPS_SIM_NABI32       /* n32 */
70                         #define __NR_move_mount 6429
71                 #endif
72                 #if _MIPS_SIM == _MIPS_SIM_ABI64        /* n64 */
73                         #define __NR_move_mount 5429
74                 #endif
75         #elif defined __ia64__
76                 #define __NR_move_mount (428 + 1024)
77         #else
78                 #define __NR_move_mount 429
79         #endif
80 #endif
81
82 #ifndef MNT_DETACH
83 #define MNT_DETACH 2
84 #endif
85
86 #ifndef MS_REC
87 #define MS_REC 1638
88 #endif
89
90 #ifndef MS_PRIVATE
91 #define MS_PRIVATE (1 << 18)
92 #endif
93
94 #ifndef MOVE_MOUNT_F_EMPTY_PATH
95 #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
96 #endif
97
98 #ifndef MOUNT_ATTR_IDMAP
99 #define MOUNT_ATTR_IDMAP 0x00100000
100 #endif
101
102 #ifndef OPEN_TREE_CLONE
103 #define OPEN_TREE_CLONE 1
104 #endif
105
106 #ifndef OPEN_TREE_CLOEXEC
107 #define OPEN_TREE_CLOEXEC O_CLOEXEC
108 #endif
109
110 #ifndef AT_RECURSIVE
111 #define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
112 #endif
113
114 #ifndef HAVE_STRUCT_MOUNT_ATTR
115 struct mount_attr {
116         __u64 attr_set;
117         __u64 attr_clr;
118         __u64 propagation;
119         __u64 userns_fd;
120 };
121 #endif
122
123 static inline int sys_mount_setattr(int dfd, const char *path, unsigned int flags,
124                                     struct mount_attr *attr, size_t size)
125 {
126         return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
127 }
128
129 static inline int sys_open_tree(int dfd, const char *filename, unsigned int flags)
130 {
131         return syscall(__NR_open_tree, dfd, filename, flags);
132 }
133
134 static inline int sys_move_mount(int from_dfd, const char *from_pathname, int to_dfd,
135                                  const char *to_pathname, unsigned int flags)
136 {
137         return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags);
138 }
139
140 static inline int sys_mount(const char *source, const char *target, const char *fstype,
141                             unsigned long int flags, const void *data)
142 {
143         return syscall(__NR_mount, source, target, fstype, flags, data);
144 }
145
146 static inline int sys_umount2(const char *path, int flags)
147 {
148         return syscall(__NR_umount2, path, flags);
149 }
150
151 #endif /* __IDMAP_MISSING_H */