From: Yu Watanabe Date: Mon, 3 Mar 2025 14:26:38 +0000 (+0900) Subject: basic: introduce our own sys/mount.h implementation X-Git-Tag: v258-rc1~1195^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec32732043550ec311dfb0e7be4e7f114366dd24;p=thirdparty%2Fsystemd.git 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. --- diff --git a/meson.build b/meson.build index f69ead2ddc9..6ef51069d9f 100644 --- a/meson.build +++ b/meson.build @@ -567,28 +567,13 @@ conf.set_quoted('LONG_MAX_STR', '@0@'.format(long_max)) foreach ident : [ ['struct dirent64', '''##include '''], # for musl, but only for compile time check, see dirent-util.h - ['struct mount_attr', '''#include '''], # since glibc-2.36 ['struct sched_attr', '''#include '''], # since glibc-2.41 ] # We get -1 if the size cannot be determined have = cc.sizeof(ident[0], prefix : ident[1], args : '-D_GNU_SOURCE') > 0 - - if ident[0] == 'struct mount_attr' - if have - want_linux_fs_h = false - else - have = cc.sizeof(ident[0], - prefix : ident[1] + '\n#include ', - args : '-D_GNU_SOURCE') > 0 - want_linux_fs_h = have - endif - endif - conf.set10('HAVE_' + ident[0].underscorify().to_upper(), have) endforeach -conf.set10('WANT_LINUX_FS_H', want_linux_fs_h) - foreach ident : [ ['set_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use ['get_mempolicy', '''#include '''], # declared at numaif.h provided by libnuma, which we do not use @@ -602,6 +587,7 @@ foreach ident : [ ['fsconfig', '''#include '''], # since glibc-2.36 ['fsmount', '''#include '''], # since glibc-2.36 ['fsopen', '''#include '''], # since glibc-2.36 + ['fspick', '''#include '''], # since glibc-2.36 ['mount_setattr', '''#include '''], # since glibc-2.36 ['move_mount', '''#include '''], # since glibc-2.36 ['open_tree', '''#include '''], # since glibc-2.36 diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c index 39fdf970a71..2f3457daa9c 100644 --- a/src/basic/chattr-util.c +++ b/src/basic/chattr-util.c @@ -4,7 +4,6 @@ #include #include #include -#include #include "bitfield.h" #include "chattr-util.h" diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h index 1fe38e32b15..17804dc1a42 100644 --- a/src/basic/chattr-util.h +++ b/src/basic/chattr-util.h @@ -2,7 +2,6 @@ #pragma once #include -#include #include #include diff --git a/src/basic/efivars.c b/src/basic/efivars.c index bebe302184f..8ae36de960d 100644 --- a/src/basic/efivars.c +++ b/src/basic/efivars.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -18,6 +17,7 @@ #include "io-util.h" #include "macro.h" #include "memory-util.h" +#include "missing_fs.h" #include "stdio-util.h" #include "strv.h" #include "time-util.h" diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 8329c44a56b..a6a63454fca 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -2,9 +2,6 @@ #include #include -#if WANT_LINUX_FS_H -#include -#endif #include #include #include diff --git a/src/basic/linux/btrfs.h b/src/basic/linux/btrfs.h index c00a5b41f48..d078ee8fcff 100644 --- a/src/basic/linux/btrfs.h +++ b/src/basic/linux/btrfs.h @@ -26,9 +26,7 @@ extern "C" { #include #include -#if WANT_LINUX_FS_H #include -#endif #define BTRFS_IOCTL_MAGIC 0x94 #define BTRFS_VOL_NAME_MAX 255 diff --git a/src/basic/linux/fs.h b/src/basic/linux/fs.h new file mode 100644 index 00000000000..be1833be4dc --- /dev/null +++ b/src/basic/linux/fs.h @@ -0,0 +1,564 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_FS_H +#define _LINUX_FS_H + +/* + * This file has definitions for some important file table structures + * and constants and structures used by various generic file system + * ioctl's. Please do not make any changes in this file before + * sending patches for review to linux-fsdevel@vger.kernel.org and + * linux-api@vger.kernel.org. + */ + +#include +#include +#include +#include + +/* Use of MS_* flags within the kernel is restricted to core mount(2) code. */ +#include + +/* + * It's silly to have NR_OPEN bigger than NR_FILE, but you can change + * the file limit at runtime and only root can increase the per-process + * nr_file rlimit, so it's safe to set up a ridiculously high absolute + * upper limit on files-per-process. + * + * Some programs (notably those using select()) may have to be + * recompiled to take full advantage of the new limits.. + */ + +/* Fixed constants first: */ +#undef NR_OPEN +#define INR_OPEN_CUR 1024 /* Initial setting for nfile rlimits */ +#define INR_OPEN_MAX 4096 /* Hard limit for nfile rlimits */ + +#define BLOCK_SIZE_BITS 10 +#define BLOCK_SIZE (1</maps ioctl */ +#define PROCMAP_QUERY _IOWR(PROCFS_IOCTL_MAGIC, 17, struct procmap_query) + +enum procmap_query_flags { + /* + * VMA permission flags. + * + * Can be used as part of procmap_query.query_flags field to look up + * only VMAs satisfying specified subset of permissions. E.g., specifying + * PROCMAP_QUERY_VMA_READABLE only will return both readable and read/write VMAs, + * while having PROCMAP_QUERY_VMA_READABLE | PROCMAP_QUERY_VMA_WRITABLE will only + * return read/write VMAs, though both executable/non-executable and + * private/shared will be ignored. + * + * PROCMAP_QUERY_VMA_* flags are also returned in procmap_query.vma_flags + * field to specify actual VMA permissions. + */ + PROCMAP_QUERY_VMA_READABLE = 0x01, + PROCMAP_QUERY_VMA_WRITABLE = 0x02, + PROCMAP_QUERY_VMA_EXECUTABLE = 0x04, + PROCMAP_QUERY_VMA_SHARED = 0x08, + /* + * Query modifier flags. + * + * By default VMA that covers provided address is returned, or -ENOENT + * is returned. With PROCMAP_QUERY_COVERING_OR_NEXT_VMA flag set, closest + * VMA with vma_start > addr will be returned if no covering VMA is + * found. + * + * PROCMAP_QUERY_FILE_BACKED_VMA instructs query to consider only VMAs that + * have file backing. Can be combined with PROCMAP_QUERY_COVERING_OR_NEXT_VMA + * to iterate all VMAs with file backing. + */ + PROCMAP_QUERY_COVERING_OR_NEXT_VMA = 0x10, + PROCMAP_QUERY_FILE_BACKED_VMA = 0x20, +}; + +/* + * Input/output argument structured passed into ioctl() call. It can be used + * to query a set of VMAs (Virtual Memory Areas) of a process. + * + * Each field can be one of three kinds, marked in a short comment to the + * right of the field: + * - "in", input argument, user has to provide this value, kernel doesn't modify it; + * - "out", output argument, kernel sets this field with VMA data; + * - "in/out", input and output argument; user provides initial value (used + * to specify maximum allowable buffer size), and kernel sets it to actual + * amount of data written (or zero, if there is no data). + * + * If matching VMA is found (according to criterias specified by + * query_addr/query_flags, all the out fields are filled out, and ioctl() + * returns 0. If there is no matching VMA, -ENOENT will be returned. + * In case of any other error, negative error code other than -ENOENT is + * returned. + * + * Most of the data is similar to the one returned as text in /proc//maps + * file, but procmap_query provides more querying flexibility. There are no + * consistency guarantees between subsequent ioctl() calls, but data returned + * for matched VMA is self-consistent. + */ +struct procmap_query { + /* Query struct size, for backwards/forward compatibility */ + __u64 size; + /* + * Query flags, a combination of enum procmap_query_flags values. + * Defines query filtering and behavior, see enum procmap_query_flags. + * + * Input argument, provided by user. Kernel doesn't modify it. + */ + __u64 query_flags; /* in */ + /* + * Query address. By default, VMA that covers this address will + * be looked up. PROCMAP_QUERY_* flags above modify this default + * behavior further. + * + * Input argument, provided by user. Kernel doesn't modify it. + */ + __u64 query_addr; /* in */ + /* VMA starting (inclusive) and ending (exclusive) address, if VMA is found. */ + __u64 vma_start; /* out */ + __u64 vma_end; /* out */ + /* VMA permissions flags. A combination of PROCMAP_QUERY_VMA_* flags. */ + __u64 vma_flags; /* out */ + /* VMA backing page size granularity. */ + __u64 vma_page_size; /* out */ + /* + * VMA file offset. If VMA has file backing, this specifies offset + * within the file that VMA's start address corresponds to. + * Is set to zero if VMA has no backing file. + */ + __u64 vma_offset; /* out */ + /* Backing file's inode number, or zero, if VMA has no backing file. */ + __u64 inode; /* out */ + /* Backing file's device major/minor number, or zero, if VMA has no backing file. */ + __u32 dev_major; /* out */ + __u32 dev_minor; /* out */ + /* + * If set to non-zero value, signals the request to return VMA name + * (i.e., VMA's backing file's absolute path, with " (deleted)" suffix + * appended, if file was unlinked from FS) for matched VMA. VMA name + * can also be some special name (e.g., "[heap]", "[stack]") or could + * be even user-supplied with prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME). + * + * Kernel will set this field to zero, if VMA has no associated name. + * Otherwise kernel will return actual amount of bytes filled in + * user-supplied buffer (see vma_name_addr field below), including the + * terminating zero. + * + * If VMA name is longer that user-supplied maximum buffer size, + * -E2BIG error is returned. + * + * If this field is set to non-zero value, vma_name_addr should point + * to valid user space memory buffer of at least vma_name_size bytes. + * If set to zero, vma_name_addr should be set to zero as well + */ + __u32 vma_name_size; /* in/out */ + /* + * If set to non-zero value, signals the request to extract and return + * VMA's backing file's build ID, if the backing file is an ELF file + * and it contains embedded build ID. + * + * Kernel will set this field to zero, if VMA has no backing file, + * backing file is not an ELF file, or ELF file has no build ID + * embedded. + * + * Build ID is a binary value (not a string). Kernel will set + * build_id_size field to exact number of bytes used for build ID. + * If build ID is requested and present, but needs more bytes than + * user-supplied maximum buffer size (see build_id_addr field below), + * -E2BIG error will be returned. + * + * If this field is set to non-zero value, build_id_addr should point + * to valid user space memory buffer of at least build_id_size bytes. + * If set to zero, build_id_addr should be set to zero as well + */ + __u32 build_id_size; /* in/out */ + /* + * User-supplied address of a buffer of at least vma_name_size bytes + * for kernel to fill with matched VMA's name (see vma_name_size field + * description above for details). + * + * Should be set to zero if VMA name should not be returned. + */ + __u64 vma_name_addr; /* in */ + /* + * User-supplied address of a buffer of at least build_id_size bytes + * for kernel to fill with matched VMA's ELF build ID, if available + * (see build_id_size field description above for details). + * + * Should be set to zero if build ID should not be returned. + */ + __u64 build_id_addr; /* in */ +}; + +#endif /* _LINUX_FS_H */ diff --git a/src/basic/linux/fscrypt.h b/src/basic/linux/fscrypt.h new file mode 100644 index 00000000000..76badefbeb6 --- /dev/null +++ b/src/basic/linux/fscrypt.h @@ -0,0 +1,195 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * fscrypt user API + * + * These ioctls can be used on filesystems that support fscrypt. See the + * "User API" section of Documentation/filesystems/fscrypt.rst. + */ +#ifndef _LINUX_FSCRYPT_H +#define _LINUX_FSCRYPT_H + +#include +#include + +/* Encryption policy flags */ +#define FSCRYPT_POLICY_FLAGS_PAD_4 0x00 +#define FSCRYPT_POLICY_FLAGS_PAD_8 0x01 +#define FSCRYPT_POLICY_FLAGS_PAD_16 0x02 +#define FSCRYPT_POLICY_FLAGS_PAD_32 0x03 +#define FSCRYPT_POLICY_FLAGS_PAD_MASK 0x03 +#define FSCRYPT_POLICY_FLAG_DIRECT_KEY 0x04 +#define FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64 0x08 +#define FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 0x10 + +/* Encryption algorithms */ +#define FSCRYPT_MODE_AES_256_XTS 1 +#define FSCRYPT_MODE_AES_256_CTS 4 +#define FSCRYPT_MODE_AES_128_CBC 5 +#define FSCRYPT_MODE_AES_128_CTS 6 +#define FSCRYPT_MODE_SM4_XTS 7 +#define FSCRYPT_MODE_SM4_CTS 8 +#define FSCRYPT_MODE_ADIANTUM 9 +#define FSCRYPT_MODE_AES_256_HCTR2 10 +/* If adding a mode number > 10, update FSCRYPT_MODE_MAX in fscrypt_private.h */ + +/* + * Legacy policy version; ad-hoc KDF and no key verification. + * For new encrypted directories, use fscrypt_policy_v2 instead. + * + * Careful: the .version field for this is actually 0, not 1. + */ +#define FSCRYPT_POLICY_V1 0 +#define FSCRYPT_KEY_DESCRIPTOR_SIZE 8 +struct fscrypt_policy_v1 { + __u8 version; + __u8 contents_encryption_mode; + __u8 filenames_encryption_mode; + __u8 flags; + __u8 master_key_descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE]; +}; + +/* + * Process-subscribed "logon" key description prefix and payload format. + * Deprecated; prefer FS_IOC_ADD_ENCRYPTION_KEY instead. + */ +#define FSCRYPT_KEY_DESC_PREFIX "fscrypt:" +#define FSCRYPT_KEY_DESC_PREFIX_SIZE 8 +#define FSCRYPT_MAX_KEY_SIZE 64 +struct fscrypt_key { + __u32 mode; + __u8 raw[FSCRYPT_MAX_KEY_SIZE]; + __u32 size; +}; + +/* + * New policy version with HKDF and key verification (recommended). + */ +#define FSCRYPT_POLICY_V2 2 +#define FSCRYPT_KEY_IDENTIFIER_SIZE 16 +struct fscrypt_policy_v2 { + __u8 version; + __u8 contents_encryption_mode; + __u8 filenames_encryption_mode; + __u8 flags; + __u8 log2_data_unit_size; + __u8 __reserved[3]; + __u8 master_key_identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]; +}; + +/* Struct passed to FS_IOC_GET_ENCRYPTION_POLICY_EX */ +struct fscrypt_get_policy_ex_arg { + __u64 policy_size; /* input/output */ + union { + __u8 version; + struct fscrypt_policy_v1 v1; + struct fscrypt_policy_v2 v2; + } policy; /* output */ +}; + +/* + * v1 policy keys are specified by an arbitrary 8-byte key "descriptor", + * matching fscrypt_policy_v1::master_key_descriptor. + */ +#define FSCRYPT_KEY_SPEC_TYPE_DESCRIPTOR 1 + +/* + * v2 policy keys are specified by a 16-byte key "identifier" which the kernel + * calculates as a cryptographic hash of the key itself, + * matching fscrypt_policy_v2::master_key_identifier. + */ +#define FSCRYPT_KEY_SPEC_TYPE_IDENTIFIER 2 + +/* + * Specifies a key, either for v1 or v2 policies. This doesn't contain the + * actual key itself; this is just the "name" of the key. + */ +struct fscrypt_key_specifier { + __u32 type; /* one of FSCRYPT_KEY_SPEC_TYPE_* */ + __u32 __reserved; + union { + __u8 __reserved[32]; /* reserve some extra space */ + __u8 descriptor[FSCRYPT_KEY_DESCRIPTOR_SIZE]; + __u8 identifier[FSCRYPT_KEY_IDENTIFIER_SIZE]; + } u; +}; + +/* + * Payload of Linux keyring key of type "fscrypt-provisioning", referenced by + * fscrypt_add_key_arg::key_id as an alternative to fscrypt_add_key_arg::raw. + */ +struct fscrypt_provisioning_key_payload { + __u32 type; + __u32 __reserved; + __u8 raw[]; +}; + +/* Struct passed to FS_IOC_ADD_ENCRYPTION_KEY */ +struct fscrypt_add_key_arg { + struct fscrypt_key_specifier key_spec; + __u32 raw_size; + __u32 key_id; + __u32 __reserved[8]; + __u8 raw[]; +}; + +/* Struct passed to FS_IOC_REMOVE_ENCRYPTION_KEY */ +struct fscrypt_remove_key_arg { + struct fscrypt_key_specifier key_spec; +#define FSCRYPT_KEY_REMOVAL_STATUS_FLAG_FILES_BUSY 0x00000001 +#define FSCRYPT_KEY_REMOVAL_STATUS_FLAG_OTHER_USERS 0x00000002 + __u32 removal_status_flags; /* output */ + __u32 __reserved[5]; +}; + +/* Struct passed to FS_IOC_GET_ENCRYPTION_KEY_STATUS */ +struct fscrypt_get_key_status_arg { + /* input */ + struct fscrypt_key_specifier key_spec; + __u32 __reserved[6]; + + /* output */ +#define FSCRYPT_KEY_STATUS_ABSENT 1 +#define FSCRYPT_KEY_STATUS_PRESENT 2 +#define FSCRYPT_KEY_STATUS_INCOMPLETELY_REMOVED 3 + __u32 status; +#define FSCRYPT_KEY_STATUS_FLAG_ADDED_BY_SELF 0x00000001 + __u32 status_flags; + __u32 user_count; + __u32 __out_reserved[13]; +}; + +#define FS_IOC_SET_ENCRYPTION_POLICY _IOR('f', 19, struct fscrypt_policy_v1) +#define FS_IOC_GET_ENCRYPTION_PWSALT _IOW('f', 20, __u8[16]) +#define FS_IOC_GET_ENCRYPTION_POLICY _IOW('f', 21, struct fscrypt_policy_v1) +#define FS_IOC_GET_ENCRYPTION_POLICY_EX _IOWR('f', 22, __u8[9]) /* size + version */ +#define FS_IOC_ADD_ENCRYPTION_KEY _IOWR('f', 23, struct fscrypt_add_key_arg) +#define FS_IOC_REMOVE_ENCRYPTION_KEY _IOWR('f', 24, struct fscrypt_remove_key_arg) +#define FS_IOC_REMOVE_ENCRYPTION_KEY_ALL_USERS _IOWR('f', 25, struct fscrypt_remove_key_arg) +#define FS_IOC_GET_ENCRYPTION_KEY_STATUS _IOWR('f', 26, struct fscrypt_get_key_status_arg) +#define FS_IOC_GET_ENCRYPTION_NONCE _IOR('f', 27, __u8[16]) + +/**********************************************************************/ + +/* old names; don't add anything new here! */ +#define fscrypt_policy fscrypt_policy_v1 +#define FS_KEY_DESCRIPTOR_SIZE FSCRYPT_KEY_DESCRIPTOR_SIZE +#define FS_POLICY_FLAGS_PAD_4 FSCRYPT_POLICY_FLAGS_PAD_4 +#define FS_POLICY_FLAGS_PAD_8 FSCRYPT_POLICY_FLAGS_PAD_8 +#define FS_POLICY_FLAGS_PAD_16 FSCRYPT_POLICY_FLAGS_PAD_16 +#define FS_POLICY_FLAGS_PAD_32 FSCRYPT_POLICY_FLAGS_PAD_32 +#define FS_POLICY_FLAGS_PAD_MASK FSCRYPT_POLICY_FLAGS_PAD_MASK +#define FS_POLICY_FLAG_DIRECT_KEY FSCRYPT_POLICY_FLAG_DIRECT_KEY +#define FS_POLICY_FLAGS_VALID 0x07 /* contains old flags only */ +#define FS_ENCRYPTION_MODE_INVALID 0 /* never used */ +#define FS_ENCRYPTION_MODE_AES_256_XTS FSCRYPT_MODE_AES_256_XTS +#define FS_ENCRYPTION_MODE_AES_256_GCM 2 /* never used */ +#define FS_ENCRYPTION_MODE_AES_256_CBC 3 /* never used */ +#define FS_ENCRYPTION_MODE_AES_256_CTS FSCRYPT_MODE_AES_256_CTS +#define FS_ENCRYPTION_MODE_AES_128_CBC FSCRYPT_MODE_AES_128_CBC +#define FS_ENCRYPTION_MODE_AES_128_CTS FSCRYPT_MODE_AES_128_CTS +#define FS_ENCRYPTION_MODE_ADIANTUM FSCRYPT_MODE_ADIANTUM +#define FS_KEY_DESC_PREFIX FSCRYPT_KEY_DESC_PREFIX +#define FS_KEY_DESC_PREFIX_SIZE FSCRYPT_KEY_DESC_PREFIX_SIZE +#define FS_MAX_KEY_SIZE FSCRYPT_MAX_KEY_SIZE + +#endif /* _LINUX_FSCRYPT_H */ diff --git a/src/basic/linux/limits.h b/src/basic/linux/limits.h new file mode 100644 index 00000000000..c3547f07605 --- /dev/null +++ b/src/basic/linux/limits.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_LIMITS_H +#define _LINUX_LIMITS_H + +#define NR_OPEN 1024 + +#define NGROUPS_MAX 65536 /* supplemental group IDs are available */ +#define ARG_MAX 131072 /* # bytes of args + environ for exec() */ +#define LINK_MAX 127 /* # links a file may have */ +#define MAX_CANON 255 /* size of the canonical input queue */ +#define MAX_INPUT 255 /* size of the type-ahead buffer */ +#define NAME_MAX 255 /* # chars in a file name */ +#define PATH_MAX 4096 /* # chars in a path name including nul */ +#define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */ +#define XATTR_NAME_MAX 255 /* # chars in an extended attribute name */ +#define XATTR_SIZE_MAX 65536 /* size of an extended attribute value (64k) */ +#define XATTR_LIST_MAX 65536 /* size of extended attribute namelist (64k) */ + +#define RTSIG_MAX 32 + +#endif diff --git a/src/basic/linux/mount.h b/src/basic/linux/mount.h new file mode 100644 index 00000000000..f3c51f221bd --- /dev/null +++ b/src/basic/linux/mount.h @@ -0,0 +1,227 @@ +#ifndef _LINUX_MOUNT_H +#define _LINUX_MOUNT_H + +#include + +/* + * These are the fs-independent mount-flags: up to 32 flags are supported + * + * Usage of these is restricted within the kernel to core mount(2) code and + * callers of sys_mount() only. Filesystems should be using the SB_* + * equivalent instead. + */ +#define MS_RDONLY 1 /* Mount read-only */ +#define MS_NOSUID 2 /* Ignore suid and sgid bits */ +#define MS_NODEV 4 /* Disallow access to device special files */ +#define MS_NOEXEC 8 /* Disallow program execution */ +#define MS_SYNCHRONOUS 16 /* Writes are synced at once */ +#define MS_REMOUNT 32 /* Alter flags of a mounted FS */ +#define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ +#define MS_DIRSYNC 128 /* Directory modifications are synchronous */ +#define MS_NOSYMFOLLOW 256 /* Do not follow symlinks */ +#define MS_NOATIME 1024 /* Do not update access times. */ +#define MS_NODIRATIME 2048 /* Do not update directory access times */ +#define MS_BIND 4096 +#define MS_MOVE 8192 +#define MS_REC 16384 +#define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. + MS_VERBOSE is deprecated. */ +#define MS_SILENT 32768 +#define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ +#define MS_UNBINDABLE (1<<17) /* change to unbindable */ +#define MS_PRIVATE (1<<18) /* change to private */ +#define MS_SLAVE (1<<19) /* change to slave */ +#define MS_SHARED (1<<20) /* change to shared */ +#define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ +#define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ +#define MS_I_VERSION (1<<23) /* Update inode I_version field */ +#define MS_STRICTATIME (1<<24) /* Always perform atime updates */ +#define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */ + +/* These sb flags are internal to the kernel */ +#define MS_SUBMOUNT (1<<26) +#define MS_NOREMOTELOCK (1<<27) +#define MS_NOSEC (1<<28) +#define MS_BORN (1<<29) +#define MS_ACTIVE (1<<30) +#define MS_NOUSER (1<<31) + +/* + * Superblock flags that can be altered by MS_REMOUNT + */ +#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|\ + MS_LAZYTIME) + +/* + * Old magic mount flag and mask + */ +#define MS_MGC_VAL 0xC0ED0000 +#define MS_MGC_MSK 0xffff0000 + +/* + * open_tree() flags. + */ +#define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */ +#define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */ + +/* + * move_mount() flags. + */ +#define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */ +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */ +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */ +#define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */ +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */ +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */ +#define MOVE_MOUNT_SET_GROUP 0x00000100 /* Set sharing group instead */ +#define MOVE_MOUNT_BENEATH 0x00000200 /* Mount beneath top mount */ +#define MOVE_MOUNT__MASK 0x00000377 + +/* + * fsopen() flags. + */ +#define FSOPEN_CLOEXEC 0x00000001 + +/* + * fspick() flags. + */ +#define FSPICK_CLOEXEC 0x00000001 +#define FSPICK_SYMLINK_NOFOLLOW 0x00000002 +#define FSPICK_NO_AUTOMOUNT 0x00000004 +#define FSPICK_EMPTY_PATH 0x00000008 + +/* + * The type of fsconfig() call made. + */ +enum fsconfig_command { + FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */ + FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */ + FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */ + FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */ + FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */ + FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */ + FSCONFIG_CMD_CREATE = 6, /* Create new or reuse existing superblock */ + FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */ + FSCONFIG_CMD_CREATE_EXCL = 8, /* Create new superblock, fail if reusing existing superblock */ +}; + +/* + * fsmount() flags. + */ +#define FSMOUNT_CLOEXEC 0x00000001 + +/* + * Mount attributes. + */ +#define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */ +#define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */ +#define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */ +#define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */ +#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */ +#define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */ +#define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */ +#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */ +#define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */ +#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */ + +/* + * mount_setattr() + */ +struct mount_attr { + __u64 attr_set; + __u64 attr_clr; + __u64 propagation; + __u64 userns_fd; +}; + +/* List of all mount_attr versions. */ +#define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */ + + +/* + * Structure for getting mount/superblock/filesystem info with statmount(2). + * + * The interface is similar to statx(2): individual fields or groups can be + * selected with the @mask argument of statmount(). Kernel will set the @mask + * field according to the supported fields. + * + * If string fields are selected, then the caller needs to pass a buffer that + * has space after the fixed part of the structure. Nul terminated strings are + * copied there and offsets relative to @str are stored in the relevant fields. + * If the buffer is too small, then EOVERFLOW is returned. The actually used + * size is returned in @size. + */ +struct statmount { + __u32 size; /* Total size, including strings */ + __u32 mnt_opts; /* [str] Options (comma separated, escaped) */ + __u64 mask; /* What results were written */ + __u32 sb_dev_major; /* Device ID */ + __u32 sb_dev_minor; + __u64 sb_magic; /* ..._SUPER_MAGIC */ + __u32 sb_flags; /* SB_{RDONLY,SYNCHRONOUS,DIRSYNC,LAZYTIME} */ + __u32 fs_type; /* [str] Filesystem type */ + __u64 mnt_id; /* Unique ID of mount */ + __u64 mnt_parent_id; /* Unique ID of parent (for root == mnt_id) */ + __u32 mnt_id_old; /* Reused IDs used in proc/.../mountinfo */ + __u32 mnt_parent_id_old; + __u64 mnt_attr; /* MOUNT_ATTR_... */ + __u64 mnt_propagation; /* MS_{SHARED,SLAVE,PRIVATE,UNBINDABLE} */ + __u64 mnt_peer_group; /* ID of shared peer group */ + __u64 mnt_master; /* Mount receives propagation from this ID */ + __u64 propagate_from; /* Propagation from in current namespace */ + __u32 mnt_root; /* [str] Root of mount relative to root of fs */ + __u32 mnt_point; /* [str] Mountpoint relative to current root */ + __u64 mnt_ns_id; /* ID of the mount namespace */ + __u32 fs_subtype; /* [str] Subtype of fs_type (if any) */ + __u32 sb_source; /* [str] Source string of the mount */ + __u32 opt_num; /* Number of fs options */ + __u32 opt_array; /* [str] Array of nul terminated fs options */ + __u32 opt_sec_num; /* Number of security options */ + __u32 opt_sec_array; /* [str] Array of nul terminated security options */ + __u64 __spare2[46]; + char str[]; /* Variable size part containing strings */ +}; + +/* + * Structure for passing mount ID and miscellaneous parameters to statmount(2) + * and listmount(2). + * + * For statmount(2) @param represents the request mask. + * For listmount(2) @param represents the last listed mount id (or zero). + */ +struct mnt_id_req { + __u32 size; + __u32 spare; + __u64 mnt_id; + __u64 param; + __u64 mnt_ns_id; +}; + +/* List of all mnt_id_req versions. */ +#define MNT_ID_REQ_SIZE_VER0 24 /* sizeof first published struct */ +#define MNT_ID_REQ_SIZE_VER1 32 /* sizeof second published struct */ + +/* + * @mask bits for statmount(2) + */ +#define STATMOUNT_SB_BASIC 0x00000001U /* Want/got sb_... */ +#define STATMOUNT_MNT_BASIC 0x00000002U /* Want/got mnt_... */ +#define STATMOUNT_PROPAGATE_FROM 0x00000004U /* Want/got propagate_from */ +#define STATMOUNT_MNT_ROOT 0x00000008U /* Want/got mnt_root */ +#define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */ +#define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */ +#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */ +#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */ +#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */ +#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */ +#define STATMOUNT_OPT_ARRAY 0x00000400U /* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U /* Want/got opt_sec... */ + +/* + * Special @mnt_id values that can be passed to listmount + */ +#define LSMT_ROOT 0xffffffffffffffff /* root mount */ +#define LISTMOUNT_REVERSE (1 << 0) /* List later mounts first */ + +#endif /* _LINUX_MOUNT_H */ diff --git a/src/basic/linux/update.sh b/src/basic/linux/update.sh index 6c173252379..31dcddaf95d 100755 --- a/src/basic/linux/update.sh +++ b/src/basic/linux/update.sh @@ -21,10 +21,6 @@ for i in *.h */*.h; do # set AUTOFS_DEV_IOCTL_VERSION_MINOR to 0 sed -r -i '/^#define[[:space:]]+AUTOFS_DEV_IOCTL_VERSION_MINOR/ s/[0-9]+/0/' "$i" ;; - btrfs.h) - # guard linux/fs.h include to avoid conflict with glibc 2.36 - sed -r -i 's/^(#include )/#if WANT_LINUX_FS_H\n\1\n#endif/' "$i" - ;; dm-ioctl.h) # set DM_VERSION_MINOR to 27 sed -r -i '/^#define[[:space:]]+DM_VERSION_MINOR/ s/[0-9]+/27/' "$i" diff --git a/src/basic/missing_fs.h b/src/basic/missing_fs.h index 79c43c72f7e..dfd79504bcb 100644 --- a/src/basic/missing_fs.h +++ b/src/basic/missing_fs.h @@ -1,81 +1,49 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +/* temporary undef definitions in bits/uio-ext.h, which is included by sys/uio.h */ +#include + +#define __RWF_HIPRI_SAVED__ RWF_HIPRI +#undef RWF_HIPRI +#define __RWF_DSYNC_SAVED__ RWF_DSYNC +#undef RWF_DSYNC +#define __RWF_SYNC_SAVED__ RWF_SYNC +#undef RWF_SYNC +#define __RWF_NOWAIT_SAVED__ RWF_NOWAIT +#undef RWF_NOWAIT +#define __RWF_APPEND_SAVED__ RWF_APPEND +#undef RWF_APPEND +#define __RWF_NOAPPEND_SAVED__ RWF_NOAPPEND +#undef RWF_NOAPPEND +#if defined(RWF_ATOMIC) +#define __RWF_ATOMIC_SAVED__ RWF_ATOMIC +#undef RWF_ATOMIC +#else +#define __RWF_ATOMIC_SAVED__ 0x00000040 +#endif +#if defined(RWF_DONTCACHE) +#define __RWF_DONTCACHE_SAVED__ RWF_DONTCACHE +#undef RWF_DONTCACHE +#else +#define __RWF_DONTCACHE_SAVED__ 0x00000080 +#endif + +#include +#include +#include #include "macro.h" -/* linux/fs.h */ -#ifndef BLKGETDISKSEQ /* 7957d93bf32bc211415827e44fdd9cdf1388df59 (5.15) */ -#define BLKGETDISKSEQ _IOR(0x12,128,__u64) -#endif - -/* linux/fs.h or sys/mount.h */ -#ifndef MS_MOVE -# define MS_MOVE 8192 -#else -assert_cc(MS_MOVE == 8192); -#endif - -#ifndef MS_REC -# define MS_REC 16384 -#else -assert_cc(MS_REC == 16384); -#endif - -#ifndef MS_PRIVATE -# define MS_PRIVATE (1<<18) -#else -assert_cc(MS_PRIVATE == (1<<18)); -#endif - -#ifndef MS_SLAVE -# define MS_SLAVE (1<<19) -#else -assert_cc(MS_SLAVE == (1<<19)); -#endif - -#ifndef MS_SHARED -# define MS_SHARED (1<<20) -#else -assert_cc(MS_SHARED == (1<<20)); -#endif - -#ifndef MS_RELATIME -# define MS_RELATIME (1<<21) -#else -assert_cc(MS_RELATIME == (1<<21)); -#endif - -#ifndef MS_KERNMOUNT -# define MS_KERNMOUNT (1<<22) -#else -assert_cc(MS_KERNMOUNT == (1<<22)); -#endif - -#ifndef MS_I_VERSION -# define MS_I_VERSION (1<<23) -#else -assert_cc(MS_I_VERSION == (1<<23)); -#endif - -#ifndef MS_STRICTATIME -# define MS_STRICTATIME (1<<24) -#else -assert_cc(MS_STRICTATIME == (1 << 24)); -#endif - -#ifndef MS_LAZYTIME -# define MS_LAZYTIME (1<<25) -#else -assert_cc(MS_LAZYTIME == (1<<25)); -#endif - -#ifndef FS_PROJINHERIT_FL -# define FS_PROJINHERIT_FL 0x20000000 -#else -assert_cc(FS_PROJINHERIT_FL == 0x20000000); -#endif +/* check RWF_xyz are redefined by linux/fs.h */ +assert_cc(RWF_HIPRI == __RWF_HIPRI_SAVED__); +assert_cc(RWF_DSYNC == __RWF_DSYNC_SAVED__); +assert_cc(RWF_SYNC == __RWF_SYNC_SAVED__); +assert_cc(RWF_NOWAIT == __RWF_NOWAIT_SAVED__); +assert_cc(RWF_APPEND == __RWF_APPEND_SAVED__); +assert_cc(RWF_NOAPPEND == __RWF_NOAPPEND_SAVED__); +assert_cc(RWF_ATOMIC == __RWF_ATOMIC_SAVED__); +assert_cc(RWF_DONTCACHE == __RWF_DONTCACHE_SAVED__); /* Not exposed yet. Defined at fs/ext4/ext4.h */ #ifndef EXT4_IOC_RESIZE_FS diff --git a/src/basic/missing_mount.h b/src/basic/missing_mount.h deleted file mode 100644 index d6e16e556e5..00000000000 --- a/src/basic/missing_mount.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -#pragma once - -#include - -#include "macro.h" - -/* dab741e0e02bd3c4f5e2e97be74b39df2523fc6e (5.10) */ -#ifndef MS_NOSYMFOLLOW -# define MS_NOSYMFOLLOW 256 -#else -assert_cc(MS_NOSYMFOLLOW == 256); -#endif diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index ebdb1c30b95..53dcd69d9e4 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -4,7 +4,6 @@ /* Missing glibc definitions to access certain kernel APIs */ #include -#include #include #include #include @@ -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); diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index cb79d621a1f..9e376e5a88c 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -3,9 +3,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "chase.h" @@ -15,7 +12,6 @@ #include "fs-util.h" #include "missing_fcntl.h" #include "missing_fs.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir.h" #include "mountpoint-util.h" diff --git a/src/basic/namespace-util.c b/src/basic/namespace-util.c index 99cece16740..322cba4cf36 100644 --- a/src/basic/namespace-util.c +++ b/src/basic/namespace-util.c @@ -3,9 +3,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "errno-util.h" #include "fd-util.h" diff --git a/src/basic/sys/mount.h b/src/basic/sys/mount.h new file mode 100644 index 00000000000..13a3ba68515 --- /dev/null +++ b/src/basic/sys/mount.h @@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "missing_fcntl.h" +#include "missing_fs.h" +#include "missing_syscall_def.h" + +/* Possible value for FLAGS parameter of `umount2'. */ +enum +{ + MNT_FORCE = 1, /* Force unmounting. */ +#define MNT_FORCE MNT_FORCE + MNT_DETACH = 2, /* Just detach from the tree. */ +#define MNT_DETACH MNT_DETACH + MNT_EXPIRE = 4, /* Mark for expiry. */ +#define MNT_EXPIRE MNT_EXPIRE + UMOUNT_NOFOLLOW = 8 /* Don't follow symlink on umount. */ +#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW +}; + +/* Mount a filesystem. */ +extern int mount(const char *__special_file, const char *__dir, const char *__fstype, unsigned long int __rwflag, const void *__data) __THROW; + +/* Unmount a filesystem. */ +extern int umount(const char *__special_file) __THROW; + +/* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */ +extern int umount2(const char *__special_file, int __flags) __THROW; + +/* Open the filesystem referenced by FS_NAME so it can be configured for + mouting. */ +#if HAVE_FSOPEN +extern int fsopen(const char *__fs_name, unsigned int __flags) __THROW; +#else +static inline int missing_fsopen(const char *fsname, unsigned flags) { + return syscall(__NR_fsopen, fsname, flags); +} +# define fsopen missing_fsopen +#endif + +/* Create a mount representation for the FD created by fsopen using + FLAGS with ATTR_FLAGS describing how the mount is to be performed. */ +#if HAVE_FSMOUNT +extern int fsmount(int __fd, unsigned int __flags, unsigned int __ms_flags) __THROW; +#else +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 + +/* Add the mounted FROM_DFD referenced by FROM_PATHNAME filesystem returned + by fsmount in the hierarchy in the place TO_DFD reference by TO_PATHNAME + using FLAGS. */ +#if HAVE_MOVE_MOUNT +extern int move_mount(int __from_dfd, const char *__from_pathname, int __to_dfd, const char *__to_pathname, unsigned int flags) __THROW; +#else +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 + +/* Set parameters and trigger CMD action on the FD context. KEY, VALUE, + and AUX are used depending ng of the CMD. */ +#if HAVE_FSCONFIG +extern int fsconfig(int __fd, unsigned int __cmd, const char *__key, const void *__value, int __aux) __THROW; +#else +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 + +/* Equivalent of fopen for an existing mount point. */ +#if HAVE_FSPICK +extern int fspick(int __dfd, const char *__path, unsigned int __flags) __THROW; +#endif + +/* Open the mount point FILENAME in directory DFD using FLAGS. */ +#if HAVE_OPEN_TREE +extern int open_tree(int __dfd, const char *__filename, unsigned int __flags) __THROW; +#else +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 + +/* Change the mount properties of the mount or an entire mount tree. If + PATH is a relative pathname, then it is interpreted relative to the + directory referred to by the file descriptor dirfd. Otherwise if DFD is + the special value AT_FDCWD then PATH is interpreted relative to the current + working directory of the calling process. */ +#if HAVE_MOUNT_SETATTR +extern int mount_setattr(int __dfd, const char *__path, unsigned int __flags, struct mount_attr *__uattr, size_t __usize) __THROW; +#else +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 diff --git a/src/core/execute.c b/src/core/execute.c index 2cc4d7e6593..1b6fe5b31af 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -14,8 +14,6 @@ #include #include -#include /* Must be included after */ - #include "sd-messages.h" #include "af-list.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index dde7a55f4ff..2eb3ed4cf4d 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include "limits-util.h" #include "load-fragment.h" #include "log.h" +#include "missing_fs.h" #include "mountpoint-util.h" #include "nulstr-util.h" #include "open-file.h" diff --git a/src/core/namespace.c b/src/core/namespace.c index 54dd4abd773..c99233ce65b 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -7,9 +7,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "base-filesystem.h" diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index fa009bdacfd..a61bd01c164 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -8,9 +8,6 @@ #include #include #include -#if WANT_LINUX_FS_H -# include -#endif #include "sd-daemon.h" #include "sd-journal.h" @@ -43,7 +40,6 @@ #include "main-func.h" #include "memory-util.h" #include "memstream-util.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "namespace-util.h" diff --git a/src/growfs/growfs.c b/src/growfs/growfs.c index c1ee18ac271..cb653ba0c76 100644 --- a/src/growfs/growfs.c +++ b/src/growfs/growfs.c @@ -8,12 +8,6 @@ #include #include #include -/* This needs to be included after sys/mount.h, as since [0] linux/btrfs.h - * includes linux/fs.h causing build errors - * See: https://github.com/systemd/systemd/issues/8507 - * [0] https://github.com/torvalds/linux/commit/a28135303a669917002f569aecebd5758263e4aa - */ -#include #include "sd-device.h" @@ -30,6 +24,7 @@ #include "format-util.h" #include "log.h" #include "main-func.h" +#include "missing_fs.h" #include "mountpoint-util.h" #include "parse-util.h" #include "pretty-print.h" diff --git a/src/home/homed-manager.c b/src/home/homed-manager.c index e628e1a389e..d49693a2e0a 100644 --- a/src/home/homed-manager.c +++ b/src/home/homed-manager.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include @@ -36,6 +35,7 @@ #include "homed-manager.h" #include "homed-varlink.h" #include "io-util.h" +#include "missing_fs.h" #include "mkdir.h" #include "notify-recv.h" #include "openssl-util.h" diff --git a/src/home/homework-cifs.c b/src/home/homework-cifs.c index f665c75d7f6..e10ef9ccddd 100644 --- a/src/home/homework-cifs.c +++ b/src/home/homework-cifs.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#if WANT_LINUX_FS_H -#include -#endif #include "dirent-util.h" #include "fd-util.h" diff --git a/src/home/homework-fscrypt.c b/src/home/homework-fscrypt.c index 3a9d4ea8918..03ad3da1b26 100644 --- a/src/home/homework-fscrypt.c +++ b/src/home/homework-fscrypt.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include @@ -14,6 +13,7 @@ #include "homework-quota.h" #include "keyring-util.h" #include "memory-util.h" +#include "missing_fs.h" #include "missing_keyctl.h" #include "missing_syscall.h" #include "mkdir.h" diff --git a/src/home/homework-mount.c b/src/home/homework-mount.c index 8d32adb2707..d6bb9649735 100644 --- a/src/home/homework-mount.c +++ b/src/home/homework-mount.c @@ -2,9 +2,6 @@ #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "fd-util.h" @@ -13,7 +10,6 @@ #include "home-util.h" #include "homework-mount.h" #include "homework.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir.h" #include "mount-util.h" diff --git a/src/home/homework.h b/src/home/homework.h index fb2b43edd63..138483bbc64 100644 --- a/src/home/homework.h +++ b/src/home/homework.h @@ -8,7 +8,7 @@ #include "cryptsetup-util.h" #include "homework-password-cache.h" #include "loop-util.h" -#include "missing_fs.h" /* for FS_KEY_DESCRIPTOR_SIZE, do not include linux/fs.h */ +#include "missing_fs.h" #include "missing_keyctl.h" #include "missing_syscall.h" #include "user-record.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 602d1f1ac33..6400995a9e8 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "sd-daemon.h" #include "sd-event.h" @@ -18,6 +16,7 @@ #include "install-file.h" #include "io-util.h" #include "machine-pool.h" +#include "missing_fs.h" #include "mkdir-label.h" #include "path-util.h" #include "pretty-print.h" diff --git a/src/import/import-tar.c b/src/import/import-tar.c index e82159cb528..b95596c50c3 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "sd-daemon.h" #include "sd-event.h" @@ -18,6 +16,7 @@ #include "install-file.h" #include "io-util.h" #include "machine-pool.h" +#include "missing_fs.h" #include "mkdir-label.h" #include "path-util.h" #include "pretty-print.h" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index f3e6b3af8c3..ab2c6a05419 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include "sd-daemon.h" @@ -17,6 +16,7 @@ #include "import-util.h" #include "install-file.h" #include "macro.h" +#include "missing_fs.h" #include "mkdir-label.h" #include "path-util.h" #include "pull-common.h" diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 1a154d92759..40b44100603 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -29,6 +28,7 @@ #include "journal-internal.h" #include "lookup3.h" #include "memory-util.h" +#include "missing_fs.h" #include "path-util.h" #include "prioq.h" #include "random-util.h" diff --git a/src/mountfsd/mountwork.c b/src/mountfsd/mountwork.c index 96cea432adc..41a8736066d 100644 --- a/src/mountfsd/mountwork.c +++ b/src/mountfsd/mountwork.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#if WANT_LINUX_FS_H -#include -#endif #include #include "sd-daemon.h" @@ -20,7 +17,6 @@ #include "io-util.h" #include "json-util.h" #include "main-func.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "namespace-util.h" #include "nsresource.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 92724e53f87..1737d1ef0ae 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -4,9 +4,6 @@ #include #include #include -#if HAVE_SELINUX -#include -#endif #include #include #include diff --git a/src/nsresourced/nsresourcework.c b/src/nsresourced/nsresourcework.c index f5b6a96d070..a088ff124e3 100644 --- a/src/nsresourced/nsresourcework.c +++ b/src/nsresourced/nsresourcework.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include "lock-util.h" #include "main-func.h" #include "missing_magic.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/nsresourced/test-userns-restrict.c b/src/nsresourced/test-userns-restrict.c index f509321ba89..d6df02428e5 100644 --- a/src/nsresourced/test-userns-restrict.c +++ b/src/nsresourced/test-userns-restrict.c @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "fd-util.h" #include "main-func.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "namespace-util.h" #include "process-util.h" diff --git a/src/nsresourced/userns-restrict.c b/src/nsresourced/userns-restrict.c index d57061e8fbd..f23526c55f4 100644 --- a/src/nsresourced/userns-restrict.c +++ b/src/nsresourced/userns-restrict.c @@ -5,13 +5,13 @@ #if HAVE_VMLINUX_H #include +#include #include "bpf-dlopen.h" #include "bpf-link.h" #include "fd-util.h" #include "fs-util.h" #include "lsm-util.h" -#include "missing_mount.h" #include "mkdir.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/repart/repart.c b/src/repart/repart.c index 88333550247..dd81a9726d6 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -52,6 +51,7 @@ #include "logarithm.h" #include "loop-util.h" #include "main-func.h" +#include "missing_fs.h" #include "mkdir.h" #include "mkfs-util.h" #include "mount-util.h" diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 9ae22d8aa56..8f33691ca36 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -3,8 +3,6 @@ #include #include #include -#include -#include #include #include #include @@ -26,6 +24,7 @@ #include "fs-util.h" #include "io-util.h" #include "macro.h" +#include "missing_fs.h" #include "path-util.h" #include "rm-rf.h" #include "smack-util.h" diff --git a/src/shared/copy.c b/src/shared/copy.c index 6a008f2dbe8..d780906ca9b 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index d6afa53a6bf..d545e0976aa 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -36,6 +35,7 @@ #include "log.h" #include "loop-util.h" #include "macro.h" +#include "missing_fs.h" #include "mkdir.h" #include "nulstr-util.h" #include "os-util.h" diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index b6563f9ab32..d9db618cf0f 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -54,7 +54,6 @@ #include "import-util.h" #include "io-util.h" #include "json-util.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c index 658128d8bd2..2aca788fb8e 100644 --- a/src/shared/hibernate-util.c +++ b/src/shared/hibernate-util.c @@ -3,7 +3,6 @@ Copyright © 2018 Dell Inc. ***/ -#include #include #include #include @@ -21,6 +20,7 @@ #include "fileio.h" #include "hibernate-util.h" #include "log.h" +#include "missing_fs.h" #include "parse-util.h" #include "path-util.h" #include "proc-cmdline.h" diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 3eba8dcb073..5b2c25067d7 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include "fs-util.h" #include "fileio.h" #include "loop-util.h" +#include "missing_fs.h" #include "parse-util.h" #include "path-util.h" #include "random-util.h" diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 3ff15a22141..b43ea73b9b1 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -7,9 +7,6 @@ #include #include #include -#if WANT_LINUX_FS_H -#include -#endif #include "alloc-util.h" #include "chase.h" @@ -25,7 +22,6 @@ #include "initrd-util.h" #include "label-util.h" #include "libmount-util.h" -#include "missing_mount.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" diff --git a/src/shared/resize-fs.c b/src/shared/resize-fs.c index b1c4a49da1a..47759a19c2b 100644 --- a/src/shared/resize-fs.c +++ b/src/shared/resize-fs.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 33220abe714..ce6a43101e5 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -10,7 +10,6 @@ #include "fs-util.h" #include "libmount-util.h" #include "missing_magic.h" -#include "missing_mount.h" #include "mkdir.h" #include "mount-util.h" #include "mountpoint-util.h" diff --git a/src/test/test-stat-util.c b/src/test/test-stat-util.c index e8091e048ce..c5aacc32f1a 100644 --- a/src/test/test-stat-util.c +++ b/src/test/test-stat-util.c @@ -12,7 +12,6 @@ #include "fd-util.h" #include "fs-util.h" #include "macro.h" -#include "missing_mount.h" #include "mount-util.h" #include "mountpoint-util.h" #include "namespace-util.h" diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 971e46a032f..a3a36e99f40 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -45,6 +44,7 @@ #include "log.h" #include "macro.h" #include "main-func.h" +#include "missing_fs.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index af711d8d88b..b166b228f31 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -1,13 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include "device-util.h" #include "errno-util.h" #include "fd-util.h" +#include "missing_fs.h" #include "string-util.h" #include "strxcpyx.h" #include "udev-builtin.h"