basic: introduce our own sys/mount.h implementation
To resolve conflict with sys/mount.h and linux/mount.h or linux/fs.h. The conflict between sys/mount.h and linux/mount.h is resolved in glibc-2.37 (774058d72942249f71d74e7f2b639f77184160a6), but our baseline is still glibc-2.31. Also, even with the version or newer, still sys/mount.h conflicts with linux/fs.h, which is included by linux/btrfs.h. This introduces our own implementation of sys/mount.h, that can be simultaneously included with linux/mount.h and linux/fs.h. This also imports linux/fs.h, linux/mount.h, and several other dependent headers. The introduced sys/mount.h header itself may not be enough simple, but by using the header, we can drop most of workarounds in other source files.
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
/* Missing glibc definitions to access certain kernel APIs */
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/time_types.h>
|
||||
#include <signal.h>
|
||||
#include <sys/syscall.h>
|
||||
@@ -213,201 +212,6 @@ static inline int missing_close_range(unsigned first_fd, unsigned end_fd, unsign
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#if !HAVE_MOUNT_SETATTR
|
||||
/* since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd) */
|
||||
|
||||
#if !HAVE_STRUCT_MOUNT_ATTR
|
||||
struct mount_attr {
|
||||
uint64_t attr_set;
|
||||
uint64_t attr_clr;
|
||||
uint64_t propagation;
|
||||
uint64_t userns_fd;
|
||||
};
|
||||
#else
|
||||
struct mount_attr;
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_RDONLY
|
||||
#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_NOSUID
|
||||
#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_NODEV
|
||||
#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_NOEXEC
|
||||
#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR__ATIME
|
||||
#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_RELATIME
|
||||
#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_NOATIME
|
||||
#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_STRICTATIME
|
||||
#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_NODIRATIME
|
||||
#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_IDMAP
|
||||
#define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_NOSYMFOLLOW
|
||||
#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */
|
||||
#endif
|
||||
|
||||
#ifndef MOUNT_ATTR_SIZE_VER0
|
||||
#define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */
|
||||
#endif
|
||||
|
||||
#ifndef AT_RECURSIVE
|
||||
#define AT_RECURSIVE 0x8000
|
||||
#endif
|
||||
|
||||
static inline int missing_mount_setattr(
|
||||
int dfd,
|
||||
const char *path,
|
||||
unsigned flags,
|
||||
struct mount_attr *attr,
|
||||
size_t size) {
|
||||
|
||||
return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
|
||||
}
|
||||
|
||||
# define mount_setattr missing_mount_setattr
|
||||
#endif
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#if !HAVE_OPEN_TREE
|
||||
/* since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */
|
||||
|
||||
#ifndef OPEN_TREE_CLONE
|
||||
#define OPEN_TREE_CLONE 1
|
||||
#endif
|
||||
|
||||
#ifndef OPEN_TREE_CLOEXEC
|
||||
#define OPEN_TREE_CLOEXEC O_CLOEXEC
|
||||
#endif
|
||||
|
||||
static inline int missing_open_tree(
|
||||
int dfd,
|
||||
const char *filename,
|
||||
unsigned flags) {
|
||||
|
||||
return syscall(__NR_open_tree, dfd, filename, flags);
|
||||
}
|
||||
|
||||
# define open_tree missing_open_tree
|
||||
#endif
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#ifndef MOVE_MOUNT_BENEATH
|
||||
#define MOVE_MOUNT_BENEATH 0x00000200
|
||||
#endif
|
||||
|
||||
#if !HAVE_MOVE_MOUNT
|
||||
/* since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */
|
||||
|
||||
#ifndef MOVE_MOUNT_F_EMPTY_PATH
|
||||
#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
|
||||
#endif
|
||||
|
||||
#ifndef MOVE_MOUNT_T_EMPTY_PATH
|
||||
#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
|
||||
#endif
|
||||
|
||||
static inline int missing_move_mount(
|
||||
int from_dfd,
|
||||
const char *from_pathname,
|
||||
int to_dfd,
|
||||
const char *to_pathname,
|
||||
unsigned flags) {
|
||||
|
||||
return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd, to_pathname, flags);
|
||||
}
|
||||
|
||||
# define move_mount missing_move_mount
|
||||
#endif
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#if !HAVE_FSOPEN
|
||||
/* since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */
|
||||
|
||||
#ifndef FSOPEN_CLOEXEC
|
||||
#define FSOPEN_CLOEXEC 0x00000001
|
||||
#endif
|
||||
|
||||
static inline int missing_fsopen(const char *fsname, unsigned flags) {
|
||||
return syscall(__NR_fsopen, fsname, flags);
|
||||
}
|
||||
|
||||
# define fsopen missing_fsopen
|
||||
#endif
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#if !HAVE_FSCONFIG
|
||||
/* since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */
|
||||
|
||||
#ifndef FSCONFIG_SET_FLAG
|
||||
#define FSCONFIG_SET_FLAG 0 /* Set parameter, supplying no value */
|
||||
#endif
|
||||
|
||||
#ifndef FSCONFIG_SET_STRING
|
||||
#define FSCONFIG_SET_STRING 1 /* Set parameter, supplying a string value */
|
||||
#endif
|
||||
|
||||
#ifndef FSCONFIG_SET_FD
|
||||
#define FSCONFIG_SET_FD 5 /* Set parameter, supplying an object by fd */
|
||||
#endif
|
||||
|
||||
#ifndef FSCONFIG_CMD_CREATE
|
||||
#define FSCONFIG_CMD_CREATE 6 /* Invoke superblock creation */
|
||||
#endif
|
||||
|
||||
static inline int missing_fsconfig(int fd, unsigned cmd, const char *key, const void *value, int aux) {
|
||||
return syscall(__NR_fsconfig, fd, cmd, key, value, aux);
|
||||
}
|
||||
|
||||
# define fsconfig missing_fsconfig
|
||||
#endif
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#if !HAVE_FSMOUNT
|
||||
/* since kernel v5.2 for (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d, d8076bdb56af5e5918376cd1573a6b0007fc1a89) */
|
||||
|
||||
#ifndef FSMOUNT_CLOEXEC
|
||||
#define FSMOUNT_CLOEXEC 0x00000001
|
||||
#endif
|
||||
|
||||
static inline int missing_fsmount(int fd, unsigned flags, unsigned ms_flags) {
|
||||
return syscall(__NR_fsmount, fd, flags, ms_flags);
|
||||
}
|
||||
|
||||
# define fsmount missing_fsmount
|
||||
#endif
|
||||
|
||||
/* ======================================================================= */
|
||||
|
||||
#if !HAVE_GETDENTS64
|
||||
static inline ssize_t missing_getdents64(int fd, void *buffer, size_t length) {
|
||||
return syscall(__NR_getdents64, fd, buffer, length);
|
||||
|
||||
Reference in New Issue
Block a user