From: Christian Brauner Date: Mon, 16 Aug 2021 14:45:17 +0000 (+0200) Subject: include: add mount-api-utils.h X-Git-Tag: v2.39-rc1~339 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=013e0db4d0763ebfb210be95901f8994057af035;p=thirdparty%2Futil-linux.git include: add mount-api-utils.h Signed-off-by: Christian Brauner --- diff --git a/configure.ac b/configure.ac index 7992236881..432f7e7250 100644 --- a/configure.ac +++ b/configure.ac @@ -498,6 +498,8 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ [AC_DEFINE([HAVE_TM_GMTOFF], [1], [Does struct tm have a field tm_gmtoff?]) ]) +AC_CHECK_TYPES([struct mount_attr], [], [], [[#include ]]) + AC_CHECK_MEMBERS([struct termios.c_line],,, [[#include ]]) @@ -560,8 +562,11 @@ AC_CHECK_FUNCS([ \ newlocale \ mempcpy \ mkostemp \ + move_mount \ + mount_setattr \ nanosleep \ ntp_gettime \ + open_tree \ personality \ pidfd_open \ pidfd_send_signal \ diff --git a/include/Makemodule.am b/include/Makemodule.am index b7937b1c50..7c6a7587f6 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -42,6 +42,7 @@ dist_noinst_HEADERS += \ include/md5.h \ include/minix.h \ include/monotonic.h \ + include/mount-api-utils.h \ include/namespace.h \ include/nls.h \ include/optutils.h \ diff --git a/include/mount-api-utils.h b/include/mount-api-utils.h new file mode 100644 index 0000000000..4d3396ec41 --- /dev/null +++ b/include/mount-api-utils.h @@ -0,0 +1,132 @@ +#ifndef UTIL_LINUX_MOUNT_API_UTILS +#define UTIL_LINUX_MOUNT_API_UTILS + +#if defined(__linux__) +#include + +/* + * Scope all of this beneath mount_setattr(). If this syscall is available all + * other syscalls must as well. Otherwise we're dealing with a partial backport + * of syscalls. + */ + +# if defined(SYS_mount_setattr) + +/* Accepted by both open_tree() and mount_setattr(). */ +#ifndef AT_RECURSIVE +#define AT_RECURSIVE 0x8000 +#endif + +#ifndef OPEN_TREE_CLONE +#define OPEN_TREE_CLONE 1 +#endif + +#ifndef OPEN_TREE_CLOEXEC +#define OPEN_TREE_CLOEXEC O_CLOEXEC +#endif + +# ifndef HAVE_OPEN_TREE +static inline int open_tree(int dfd, const char *filename, unsigned int flags) +{ + return syscall(__NR_open_tree, dfd, filename, flags); +} +# endif + +#ifndef MOVE_MOUNT_F_SYMLINKS +#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ +#endif + +#ifndef MOVE_MOUNT_F_AUTOMOUNTS +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ +#endif + +#ifndef MOVE_MOUNT_F_EMPTY_PATH +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ +#endif + +#ifndef MOVE_MOUNT_T_SYMLINKS +#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ +#endif + +#ifndef MOVE_MOUNT_T_AUTOMOUNTS +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ +#endif + +#ifndef MOVE_MOUNT_T_EMPTY_PATH +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ +#endif + +#ifndef MOVE_MOUNT__MASK +#define MOVE_MOUNT__MASK 0x00000077 +#endif + +# ifndef HAVE_MOVE_MOUNT +static inline int move_mount(int from_dfd, const char *from_pathname, int to_dfd, + const char *to_pathname, unsigned int flags) +{ + return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, + to_pathname, flags); +} +# endif + +#ifndef MOUNT_ATTR_RDONLY +#define MOUNT_ATTR_RDONLY 0x00000001 +#endif + +#ifndef MOUNT_ATTR_NOSUID +#define MOUNT_ATTR_NOSUID 0x00000002 +#endif + +#ifndef MOUNT_ATTR_NOEXEC +#define MOUNT_ATTR_NOEXEC 0x00000008 +#endif + +#ifndef MOUNT_ATTR_NODIRATIME +#define MOUNT_ATTR_NODIRATIME 0x00000080 +#endif + +#ifndef MOUNT_ATTR__ATIME +#define MOUNT_ATTR__ATIME 0x00000070 +#endif + +#ifndef MOUNT_ATTR_RELATIME +#define MOUNT_ATTR_RELATIME 0x00000000 +#endif + +#ifndef MOUNT_ATTR_NOATIME +#define MOUNT_ATTR_NOATIME 0x00000010 +#endif + +#ifndef MOUNT_ATTR_STRICTATIME +#define MOUNT_ATTR_STRICTATIME 0x00000020 +#endif + +#ifndef MOUNT_ATTR_IDMAP +#define MOUNT_ATTR_IDMAP 0x00100000 +#endif + +# ifndef HAVE_STRUCT_MOUNT_ATTR +# include +struct mount_attr { + __u64 attr_set; + __u64 attr_clr; + __u64 propagation; + __u64 userns_fd; +}; +# endif + +# ifndef HAVE_MOUNT_SETATTR +static inline int mount_setattr(int dfd, const char *path, unsigned int flags, + struct mount_attr *attr, size_t size) +{ + return syscall(__NR_mount_setattr, dfd, path, flags, attr, size); +} +# endif + +#define UL_HAVE_MOUNT_API 1 + +# endif + +#endif /* __linux__ */ +#endif /* UTIL_LINUX_MOUNT_API_UTILS */ +