]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: introduce our own sys/mount.h implementation
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 14:26:38 +0000 (23:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Mar 2025 17:24:49 +0000 (02:24 +0900)
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.

49 files changed:
meson.build
src/basic/chattr-util.c
src/basic/chattr-util.h
src/basic/efivars.c
src/basic/fd-util.c
src/basic/linux/btrfs.h
src/basic/linux/fs.h [new file with mode: 0644]
src/basic/linux/fscrypt.h [new file with mode: 0644]
src/basic/linux/limits.h [new file with mode: 0644]
src/basic/linux/mount.h [new file with mode: 0644]
src/basic/linux/update.sh
src/basic/missing_fs.h
src/basic/missing_mount.h [deleted file]
src/basic/missing_syscall.h
src/basic/mountpoint-util.c
src/basic/namespace-util.c
src/basic/sys/mount.h [new file with mode: 0644]
src/core/execute.c
src/core/load-fragment.c
src/core/namespace.c
src/coredump/coredump.c
src/growfs/growfs.c
src/home/homed-manager.c
src/home/homework-cifs.c
src/home/homework-fscrypt.c
src/home/homework-mount.c
src/home/homework.h
src/import/import-raw.c
src/import/import-tar.c
src/import/pull-raw.c
src/libsystemd/sd-journal/journal-file.c
src/mountfsd/mountwork.c
src/nspawn/nspawn.c
src/nsresourced/nsresourcework.c
src/nsresourced/test-userns-restrict.c
src/nsresourced/userns-restrict.c
src/repart/repart.c
src/shared/btrfs-util.c
src/shared/copy.c
src/shared/discover-image.c
src/shared/dissect-image.c
src/shared/hibernate-util.c
src/shared/loop-util.c
src/shared/mount-util.c
src/shared/resize-fs.c
src/test/test-mount-util.c
src/test/test-stat-util.c
src/tmpfiles/tmpfiles.c
src/udev/udev-builtin-btrfs.c

index f69ead2ddc9e537c1d736edc747d26bd5a62e7a9..6ef51069d9fea51f9386c84e907d25d19f29ea0d 100644 (file)
@@ -567,28 +567,13 @@ conf.set_quoted('LONG_MAX_STR', '@0@'.format(long_max))
 
 foreach ident : [
         ['struct dirent64',   '''##include <dirent.h>'''],      # for musl, but only for compile time check, see dirent-util.h
-        ['struct mount_attr', '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['struct sched_attr', '''#include <sched.h>'''],        # 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 <linux/fs.h>',
-                                         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 <sys/syscall.h>'''],  # declared at numaif.h provided by libnuma, which we do not use
         ['get_mempolicy',     '''#include <sys/syscall.h>'''],  # declared at numaif.h provided by libnuma, which we do not use
@@ -602,6 +587,7 @@ foreach ident : [
         ['fsconfig',          '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['fsmount',           '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['fsopen',            '''#include <sys/mount.h>'''],    # since glibc-2.36
+        ['fspick',            '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['mount_setattr',     '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['move_mount',        '''#include <sys/mount.h>'''],    # since glibc-2.36
         ['open_tree',         '''#include <sys/mount.h>'''],    # since glibc-2.36
index 39fdf970a71721d20b570f588bdd92616fe1537b..2f3457daa9c8367c54a9013830d154c37df633c7 100644 (file)
@@ -4,7 +4,6 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
-#include <linux/fs.h>
 
 #include "bitfield.h"
 #include "chattr-util.h"
index 1fe38e32b15dd4e56126a22a3d8a0308b871c529..17804dc1a424513540f4f1f61ca2d20b96920088 100644 (file)
@@ -2,7 +2,6 @@
 #pragma once
 
 #include <fcntl.h>
-#include <linux/fs.h>
 #include <stdbool.h>
 #include <stddef.h>
 
index bebe302184feffa69bbc9dc58b0d4c6ce42792e9..8ae36de960dde3bcc0caaadd60e7db1d3956157f 100644 (file)
@@ -3,7 +3,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
-#include <linux/fs.h>
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -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"
index 8329c44a56b744a5460ff421912ec346ef00e86e..a6a63454fca2f5ce9bbc86114ccfeb6bfe8e941f 100644 (file)
@@ -2,9 +2,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#endif
 #include <linux/kcmp.h>
 #include <linux/magic.h>
 #include <sys/ioctl.h>
index c00a5b41f487418ae2153393651f11b002e96c41..d078ee8fcffe0479ec02b89e130fb9db97add4cf 100644 (file)
@@ -26,9 +26,7 @@ extern "C" {
 
 #include <linux/types.h>
 #include <linux/ioctl.h>
-#if WANT_LINUX_FS_H
 #include <linux/fs.h>
-#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 (file)
index 0000000..be1833b
--- /dev/null
@@ -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 <linux/limits.h>
+#include <linux/ioctl.h>
+#include <linux/types.h>
+#include <linux/fscrypt.h>
+
+/* Use of MS_* flags within the kernel is restricted to core mount(2) code. */
+#include <linux/mount.h>
+
+/*
+ * 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<<BLOCK_SIZE_BITS)
+
+/* flags for integrity meta */
+#define IO_INTEGRITY_CHK_GUARD         (1U << 0) /* enforce guard check */
+#define IO_INTEGRITY_CHK_REFTAG                (1U << 1) /* enforce ref check */
+#define IO_INTEGRITY_CHK_APPTAG                (1U << 2) /* enforce app check */
+
+#define IO_INTEGRITY_VALID_FLAGS (IO_INTEGRITY_CHK_GUARD | \
+                                 IO_INTEGRITY_CHK_REFTAG | \
+                                 IO_INTEGRITY_CHK_APPTAG)
+
+#define SEEK_SET       0       /* seek relative to beginning of file */
+#define SEEK_CUR       1       /* seek relative to current file position */
+#define SEEK_END       2       /* seek relative to end of file */
+#define SEEK_DATA      3       /* seek to the next data */
+#define SEEK_HOLE      4       /* seek to the next hole */
+#define SEEK_MAX       SEEK_HOLE
+
+#define RENAME_NOREPLACE       (1 << 0)        /* Don't overwrite target */
+#define RENAME_EXCHANGE                (1 << 1)        /* Exchange source and dest */
+#define RENAME_WHITEOUT                (1 << 2)        /* Whiteout source */
+
+struct file_clone_range {
+       __s64 src_fd;
+       __u64 src_offset;
+       __u64 src_length;
+       __u64 dest_offset;
+};
+
+struct fstrim_range {
+       __u64 start;
+       __u64 len;
+       __u64 minlen;
+};
+
+/*
+ * We include a length field because some filesystems (vfat) have an identifier
+ * that we do want to expose as a UUID, but doesn't have the standard length.
+ *
+ * We use a fixed size buffer beacuse this interface will, by fiat, never
+ * support "UUIDs" longer than 16 bytes; we don't want to force all downstream
+ * users to have to deal with that.
+ */
+struct fsuuid2 {
+       __u8    len;
+       __u8    uuid[16];
+};
+
+struct fs_sysfs_path {
+       __u8                    len;
+       __u8                    name[128];
+};
+
+/* extent-same (dedupe) ioctls; these MUST match the btrfs ioctl definitions */
+#define FILE_DEDUPE_RANGE_SAME         0
+#define FILE_DEDUPE_RANGE_DIFFERS      1
+
+/* from struct btrfs_ioctl_file_extent_same_info */
+struct file_dedupe_range_info {
+       __s64 dest_fd;          /* in - destination file */
+       __u64 dest_offset;      /* in - start of extent in destination */
+       __u64 bytes_deduped;    /* out - total # of bytes we were able
+                                * to dedupe from this file. */
+       /* status of this dedupe operation:
+        * < 0 for error
+        * == FILE_DEDUPE_RANGE_SAME if dedupe succeeds
+        * == FILE_DEDUPE_RANGE_DIFFERS if data differs
+        */
+       __s32 status;           /* out - see above description */
+       __u32 reserved;         /* must be zero */
+};
+
+/* from struct btrfs_ioctl_file_extent_same_args */
+struct file_dedupe_range {
+       __u64 src_offset;       /* in - start of extent in source */
+       __u64 src_length;       /* in - length of extent */
+       __u16 dest_count;       /* in - total elements in info array */
+       __u16 reserved1;        /* must be zero */
+       __u32 reserved2;        /* must be zero */
+       struct file_dedupe_range_info info[];
+};
+
+/* And dynamically-tunable limits and defaults: */
+struct files_stat_struct {
+       unsigned long nr_files;         /* read only */
+       unsigned long nr_free_files;    /* read only */
+       unsigned long max_files;                /* tunable */
+};
+
+struct inodes_stat_t {
+       long nr_inodes;
+       long nr_unused;
+       long dummy[5];          /* padding for sysctl ABI compatibility */
+};
+
+
+#define NR_FILE  8192  /* this can well be larger on a larger system */
+
+/*
+ * Structure for FS_IOC_FSGETXATTR[A] and FS_IOC_FSSETXATTR.
+ */
+struct fsxattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+       unsigned char   fsx_pad[8];
+};
+
+/*
+ * Flags for the fsx_xflags field
+ */
+#define FS_XFLAG_REALTIME      0x00000001      /* data in realtime volume */
+#define FS_XFLAG_PREALLOC      0x00000002      /* preallocated file extents */
+#define FS_XFLAG_IMMUTABLE     0x00000008      /* file cannot be modified */
+#define FS_XFLAG_APPEND                0x00000010      /* all writes append */
+#define FS_XFLAG_SYNC          0x00000020      /* all writes synchronous */
+#define FS_XFLAG_NOATIME       0x00000040      /* do not update access time */
+#define FS_XFLAG_NODUMP                0x00000080      /* do not include in backups */
+#define FS_XFLAG_RTINHERIT     0x00000100      /* create with rt bit set */
+#define FS_XFLAG_PROJINHERIT   0x00000200      /* create with parents projid */
+#define FS_XFLAG_NOSYMLINKS    0x00000400      /* disallow symlink creation */
+#define FS_XFLAG_EXTSIZE       0x00000800      /* extent size allocator hint */
+#define FS_XFLAG_EXTSZINHERIT  0x00001000      /* inherit inode extent size */
+#define FS_XFLAG_NODEFRAG      0x00002000      /* do not defragment */
+#define FS_XFLAG_FILESTREAM    0x00004000      /* use filestream allocator */
+#define FS_XFLAG_DAX           0x00008000      /* use DAX for IO */
+#define FS_XFLAG_COWEXTSIZE    0x00010000      /* CoW extent size allocator hint */
+#define FS_XFLAG_HASATTR       0x80000000      /* no DIFLAG for this   */
+
+/* the read-only stuff doesn't really belong here, but any other place is
+   probably as bad and I don't want to create yet another include file. */
+
+#define BLKROSET   _IO(0x12,93)        /* set device read-only (0 = read-write) */
+#define BLKROGET   _IO(0x12,94)        /* get read-only status (0 = read_write) */
+#define BLKRRPART  _IO(0x12,95)        /* re-read partition table */
+#define BLKGETSIZE _IO(0x12,96)        /* return device size /512 (long *arg) */
+#define BLKFLSBUF  _IO(0x12,97)        /* flush buffer cache */
+#define BLKRASET   _IO(0x12,98)        /* set read ahead for block device */
+#define BLKRAGET   _IO(0x12,99)        /* get current read ahead setting */
+#define BLKFRASET  _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
+#define BLKFRAGET  _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
+#define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
+#define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
+#define BLKSSZGET  _IO(0x12,104)/* get block device sector size */
+#if 0
+#define BLKPG      _IO(0x12,105)/* See blkpg.h */
+
+/* Some people are morons.  Do not use sizeof! */
+
+#define BLKELVGET  _IOR(0x12,106,size_t)/* elevator get */
+#define BLKELVSET  _IOW(0x12,107,size_t)/* elevator set */
+/* This was here just to show that the number is taken -
+   probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
+#endif
+/* A jump here: 108-111 have been used for various private purposes. */
+#define BLKBSZGET  _IOR(0x12,112,size_t)
+#define BLKBSZSET  _IOW(0x12,113,size_t)
+#define BLKGETSIZE64 _IOR(0x12,114,size_t)     /* return device size in bytes (u64 *arg) */
+#define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup)
+#define BLKTRACESTART _IO(0x12,116)
+#define BLKTRACESTOP _IO(0x12,117)
+#define BLKTRACETEARDOWN _IO(0x12,118)
+#define BLKDISCARD _IO(0x12,119)
+#define BLKIOMIN _IO(0x12,120)
+#define BLKIOOPT _IO(0x12,121)
+#define BLKALIGNOFF _IO(0x12,122)
+#define BLKPBSZGET _IO(0x12,123)
+#define BLKDISCARDZEROES _IO(0x12,124)
+#define BLKSECDISCARD _IO(0x12,125)
+#define BLKROTATIONAL _IO(0x12,126)
+#define BLKZEROOUT _IO(0x12,127)
+#define BLKGETDISKSEQ _IOR(0x12,128,__u64)
+/*
+ * A jump here: 130-136 are reserved for zoned block devices
+ * (see uapi/linux/blkzoned.h)
+ */
+
+#define BMAP_IOCTL 1           /* obsolete - kept for compatibility */
+#define FIBMAP    _IO(0x00,1)  /* bmap access */
+#define FIGETBSZ   _IO(0x00,2) /* get the block size used for bmap */
+#define FIFREEZE       _IOWR('X', 119, int)    /* Freeze */
+#define FITHAW         _IOWR('X', 120, int)    /* Thaw */
+#define FITRIM         _IOWR('X', 121, struct fstrim_range)    /* Trim */
+#define FICLONE                _IOW(0x94, 9, int)
+#define FICLONERANGE   _IOW(0x94, 13, struct file_clone_range)
+#define FIDEDUPERANGE  _IOWR(0x94, 54, struct file_dedupe_range)
+
+#define FSLABEL_MAX 256        /* Max chars for the interface; each fs may differ */
+
+#define        FS_IOC_GETFLAGS                 _IOR('f', 1, long)
+#define        FS_IOC_SETFLAGS                 _IOW('f', 2, long)
+#define        FS_IOC_GETVERSION               _IOR('v', 1, long)
+#define        FS_IOC_SETVERSION               _IOW('v', 2, long)
+#define FS_IOC_FIEMAP                  _IOWR('f', 11, struct fiemap)
+#define FS_IOC32_GETFLAGS              _IOR('f', 1, int)
+#define FS_IOC32_SETFLAGS              _IOW('f', 2, int)
+#define FS_IOC32_GETVERSION            _IOR('v', 1, int)
+#define FS_IOC32_SETVERSION            _IOW('v', 2, int)
+#define FS_IOC_FSGETXATTR              _IOR('X', 31, struct fsxattr)
+#define FS_IOC_FSSETXATTR              _IOW('X', 32, struct fsxattr)
+#define FS_IOC_GETFSLABEL              _IOR(0x94, 49, char[FSLABEL_MAX])
+#define FS_IOC_SETFSLABEL              _IOW(0x94, 50, char[FSLABEL_MAX])
+/* Returns the external filesystem UUID, the same one blkid returns */
+#define FS_IOC_GETFSUUID               _IOR(0x15, 0, struct fsuuid2)
+/*
+ * Returns the path component under /sys/fs/ that refers to this filesystem;
+ * also /sys/kernel/debug/ for filesystems with debugfs exports
+ */
+#define FS_IOC_GETFSSYSFSPATH          _IOR(0x15, 1, struct fs_sysfs_path)
+
+/*
+ * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS)
+ *
+ * Note: for historical reasons, these flags were originally used and
+ * defined for use by ext2/ext3, and then other file systems started
+ * using these flags so they wouldn't need to write their own version
+ * of chattr/lsattr (which was shipped as part of e2fsprogs).  You
+ * should think twice before trying to use these flags in new
+ * contexts, or trying to assign these flags, since they are used both
+ * as the UAPI and the on-disk encoding for ext2/3/4.  Also, we are
+ * almost out of 32-bit flags.  :-)
+ *
+ * We have recently hoisted FS_IOC_FSGETXATTR / FS_IOC_FSSETXATTR from
+ * XFS to the generic FS level interface.  This uses a structure that
+ * has padding and hence has more room to grow, so it may be more
+ * appropriate for many new use cases.
+ *
+ * Please do not change these flags or interfaces before checking with
+ * linux-fsdevel@vger.kernel.org and linux-api@vger.kernel.org.
+ */
+#define        FS_SECRM_FL                     0x00000001 /* Secure deletion */
+#define        FS_UNRM_FL                      0x00000002 /* Undelete */
+#define        FS_COMPR_FL                     0x00000004 /* Compress file */
+#define FS_SYNC_FL                     0x00000008 /* Synchronous updates */
+#define FS_IMMUTABLE_FL                        0x00000010 /* Immutable file */
+#define FS_APPEND_FL                   0x00000020 /* writes to file may only append */
+#define FS_NODUMP_FL                   0x00000040 /* do not dump file */
+#define FS_NOATIME_FL                  0x00000080 /* do not update atime */
+/* Reserved for compression usage... */
+#define FS_DIRTY_FL                    0x00000100
+#define FS_COMPRBLK_FL                 0x00000200 /* One or more compressed clusters */
+#define FS_NOCOMP_FL                   0x00000400 /* Don't compress */
+/* End compression flags --- maybe not all used */
+#define FS_ENCRYPT_FL                  0x00000800 /* Encrypted file */
+#define FS_BTREE_FL                    0x00001000 /* btree format dir */
+#define FS_INDEX_FL                    0x00001000 /* hash-indexed directory */
+#define FS_IMAGIC_FL                   0x00002000 /* AFS directory */
+#define FS_JOURNAL_DATA_FL             0x00004000 /* Reserved for ext3 */
+#define FS_NOTAIL_FL                   0x00008000 /* file tail should not be merged */
+#define FS_DIRSYNC_FL                  0x00010000 /* dirsync behaviour (directories only) */
+#define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
+#define FS_HUGE_FILE_FL                        0x00040000 /* Reserved for ext4 */
+#define FS_EXTENT_FL                   0x00080000 /* Extents */
+#define FS_VERITY_FL                   0x00100000 /* Verity protected inode */
+#define FS_EA_INODE_FL                 0x00200000 /* Inode used for large EA */
+#define FS_EOFBLOCKS_FL                        0x00400000 /* Reserved for ext4 */
+#define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
+#define FS_DAX_FL                      0x02000000 /* Inode is DAX */
+#define FS_INLINE_DATA_FL              0x10000000 /* Reserved for ext4 */
+#define FS_PROJINHERIT_FL              0x20000000 /* Create with parents projid */
+#define FS_CASEFOLD_FL                 0x40000000 /* Folder is case insensitive */
+#define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
+
+#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
+#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
+
+
+#define SYNC_FILE_RANGE_WAIT_BEFORE    1
+#define SYNC_FILE_RANGE_WRITE          2
+#define SYNC_FILE_RANGE_WAIT_AFTER     4
+#define SYNC_FILE_RANGE_WRITE_AND_WAIT (SYNC_FILE_RANGE_WRITE | \
+                                        SYNC_FILE_RANGE_WAIT_BEFORE | \
+                                        SYNC_FILE_RANGE_WAIT_AFTER)
+
+/*
+ * Flags for preadv2/pwritev2:
+ */
+
+typedef int __bitwise __kernel_rwf_t;
+
+/* high priority request, poll if possible */
+#define RWF_HIPRI      ((__kernel_rwf_t)0x00000001)
+
+/* per-IO O_DSYNC */
+#define RWF_DSYNC      ((__kernel_rwf_t)0x00000002)
+
+/* per-IO O_SYNC */
+#define RWF_SYNC       ((__kernel_rwf_t)0x00000004)
+
+/* per-IO, return -EAGAIN if operation would block */
+#define RWF_NOWAIT     ((__kernel_rwf_t)0x00000008)
+
+/* per-IO O_APPEND */
+#define RWF_APPEND     ((__kernel_rwf_t)0x00000010)
+
+/* per-IO negation of O_APPEND */
+#define RWF_NOAPPEND   ((__kernel_rwf_t)0x00000020)
+
+/* Atomic Write */
+#define RWF_ATOMIC     ((__kernel_rwf_t)0x00000040)
+
+/* buffered IO that drops the cache after reading or writing data */
+#define RWF_DONTCACHE  ((__kernel_rwf_t)0x00000080)
+
+/* mask of flags supported by the kernel */
+#define RWF_SUPPORTED  (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\
+                        RWF_APPEND | RWF_NOAPPEND | RWF_ATOMIC |\
+                        RWF_DONTCACHE)
+
+#define PROCFS_IOCTL_MAGIC 'f'
+
+/* Pagemap ioctl */
+#define PAGEMAP_SCAN   _IOWR(PROCFS_IOCTL_MAGIC, 16, struct pm_scan_arg)
+
+/* Bitmasks provided in pm_scan_args masks and reported in page_region.categories. */
+#define PAGE_IS_WPALLOWED      (1 << 0)
+#define PAGE_IS_WRITTEN                (1 << 1)
+#define PAGE_IS_FILE           (1 << 2)
+#define PAGE_IS_PRESENT                (1 << 3)
+#define PAGE_IS_SWAPPED                (1 << 4)
+#define PAGE_IS_PFNZERO                (1 << 5)
+#define PAGE_IS_HUGE           (1 << 6)
+#define PAGE_IS_SOFT_DIRTY     (1 << 7)
+
+/*
+ * struct page_region - Page region with flags
+ * @start:     Start of the region
+ * @end:       End of the region (exclusive)
+ * @categories:        PAGE_IS_* category bitmask for the region
+ */
+struct page_region {
+       __u64 start;
+       __u64 end;
+       __u64 categories;
+};
+
+/* Flags for PAGEMAP_SCAN ioctl */
+#define PM_SCAN_WP_MATCHING    (1 << 0)        /* Write protect the pages matched. */
+#define PM_SCAN_CHECK_WPASYNC  (1 << 1)        /* Abort the scan when a non-WP-enabled page is found. */
+
+/*
+ * struct pm_scan_arg - Pagemap ioctl argument
+ * @size:              Size of the structure
+ * @flags:             Flags for the IOCTL
+ * @start:             Starting address of the region
+ * @end:               Ending address of the region
+ * @walk_end           Address where the scan stopped (written by kernel).
+ *                     walk_end == end (address tags cleared) informs that the scan completed on entire range.
+ * @vec:               Address of page_region struct array for output
+ * @vec_len:           Length of the page_region struct array
+ * @max_pages:         Optional limit for number of returned pages (0 = disabled)
+ * @category_inverted: PAGE_IS_* categories which values match if 0 instead of 1
+ * @category_mask:     Skip pages for which any category doesn't match
+ * @category_anyof_mask: Skip pages for which no category matches
+ * @return_mask:       PAGE_IS_* categories that are to be reported in `page_region`s returned
+ */
+struct pm_scan_arg {
+       __u64 size;
+       __u64 flags;
+       __u64 start;
+       __u64 end;
+       __u64 walk_end;
+       __u64 vec;
+       __u64 vec_len;
+       __u64 max_pages;
+       __u64 category_inverted;
+       __u64 category_mask;
+       __u64 category_anyof_mask;
+       __u64 return_mask;
+};
+
+/* /proc/<pid>/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/<pid>/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 (file)
index 0000000..76badef
--- /dev/null
@@ -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 <linux/ioctl.h>
+#include <linux/types.h>
+
+/* 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 (file)
index 0000000..c3547f0
--- /dev/null
@@ -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 (file)
index 0000000..f3c51f2
--- /dev/null
@@ -0,0 +1,227 @@
+#ifndef _LINUX_MOUNT_H
+#define _LINUX_MOUNT_H
+
+#include <linux/types.h>
+
+/*
+ * 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 */
index 6c1732523792e3d0779b5413e7873dbe0bdaba00..31dcddaf95df666f66ae60cd6bcefbfa1dd59be6 100755 (executable)
@@ -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 <linux\/fs\.h>)/#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"
index 79c43c72f7ede74a8dea8129727869fc3aae937f..dfd79504bcb78c19cabf293d3b2fa755f2d68355 100644 (file)
@@ -1,81 +1,49 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include <linux/types.h>
+/* temporary undef definitions in bits/uio-ext.h, which is included by sys/uio.h */
+#include <sys/uio.h>
+
+#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 <linux/btrfs.h>
+#include <linux/btrfs_tree.h>
+#include <linux/fs.h>
 
 #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 (file)
index d6e16e5..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-#include <sys/mount.h>
-
-#include "macro.h"
-
-/* dab741e0e02bd3c4f5e2e97be74b39df2523fc6e (5.10) */
-#ifndef MS_NOSYMFOLLOW
-#  define MS_NOSYMFOLLOW 256
-#else
-assert_cc(MS_NOSYMFOLLOW == 256);
-#endif
index ebdb1c30b95809df4470b61509c6f657f4f4cc5e..53dcd69d9e4aba7d5da00de7ce46161822686bd1 100644 (file)
@@ -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);
index cb79d621a1fa1a7c6f8f655cdb3070fec69857c0..9e376e5a88cdaa70c22b3e549562a1ec6747ca6c 100644 (file)
@@ -3,9 +3,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mount.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#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"
index 99cece16740ab8f0e54117d13ab6031e995bb70b..322cba4cf36f1bd51b2019fde645256989ba4a65 100644 (file)
@@ -3,9 +3,6 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#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 (file)
index 0000000..13a3ba6
--- /dev/null
@@ -0,0 +1,115 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <features.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <sys/ioctl.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+
+#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
index 2cc4d7e6593517213d8cc3704b76353ccbb86f87..1b6fe5b31af8a4dbac2cae4ff251c37cdec840ac 100644 (file)
@@ -14,8 +14,6 @@
 #include <unistd.h>
 #include <utmpx.h>
 
-#include <linux/fs.h> /* Must be included after <sys/mount.h> */
-
 #include "sd-messages.h"
 
 #include "af-list.h"
index dde7a55f4ffa58c06cdabbd93ae3ea64c50bbbfa..2eb3ed4cf4d8e523b76211cbc42b8ffeabd21c04 100644 (file)
@@ -5,7 +5,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/fs.h>
 #include <linux/oom.h>
 #include <sched.h>
 #include <sys/resource.h>
@@ -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"
index 54dd4abd7733c992988820e1da131028eb074270..c99233ce65b281b41e7eab948271c8655a6567d0 100644 (file)
@@ -7,9 +7,6 @@
 #include <sys/file.h>
 #include <sys/mount.h>
 #include <unistd.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#endif
 
 #include "alloc-util.h"
 #include "base-filesystem.h"
index fa009bdacfdb9a5d7caaaa1c20c7123ac33a10f1..a61bd01c164b2e3db1d6413d96b2f839054adf84 100644 (file)
@@ -8,9 +8,6 @@
 #include <sys/auxv.h>
 #include <sys/xattr.h>
 #include <unistd.h>
-#if WANT_LINUX_FS_H
-#  include <linux/fs.h>
-#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"
index c1ee18ac2717742f7ce53f9ab9c1a49f6f6daa54..cb653ba0c76387f96b698a7a52e0220422b8f300 100644 (file)
@@ -8,12 +8,6 @@
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/vfs.h>
-/* 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 <linux/btrfs.h>
 
 #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"
index e628e1a389e457d4b812a4eec749651fab305f97..d49693a2e0a6e9a87fe97ec56eda73b7837a3533 100644 (file)
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <grp.h>
-#include <linux/fs.h>
 #include <linux/magic.h>
 #include <math.h>
 #include <openssl/pem.h>
@@ -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"
index f665c75d7f64643d7ec74dc2f0e4c90553275c13..e10ef9ccddd28049ae47e8d4ab5f4edcbe5cbc64 100644 (file)
@@ -1,9 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <sys/mount.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#endif
 
 #include "dirent-util.h"
 #include "fd-util.h"
index 3a9d4ea8918a4da09e83fbe2f35a25586fa9083c..03ad3da1b26f5eb5c7502f01005ed068ee4b59b2 100644 (file)
@@ -1,6 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <linux/fs.h>
 #include <openssl/evp.h>
 #include <openssl/sha.h>
 #include <sys/ioctl.h>
@@ -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"
index 8d32adb2707ddf5ddae1f57870f299a6fa41caab..d6bb9649735fab9e8c0bd3512376a469370fd50d 100644 (file)
@@ -2,9 +2,6 @@
 
 #include <sched.h>
 #include <sys/mount.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#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"
index fb2b43edd63fdd4c43677f7be56798a61ff78c42..138483bbc64ebbd1b48e110364ebbf942f00cacf 100644 (file)
@@ -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"
index 602d1f1ac33d9536441bf63f1327e5a47835b54d..6400995a9e832da752944d628d6bb644cfd4ab69 100644 (file)
@@ -1,7 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <linux/fs.h>
-
 #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"
index e82159cb528c9e6827d8bc6c7b3bcf1897f1938c..b95596c50c3dde903d2fa259af875eb3a00cd7f1 100644 (file)
@@ -1,7 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <linux/fs.h>
-
 #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"
index f3e6b3af8c33846ceac8cf220f76aa39a23a7048..ab2c6a054194e586d9d48faebfb8d7ca141134e3 100644 (file)
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <curl/curl.h>
-#include <linux/fs.h>
 #include <sys/xattr.h>
 
 #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"
index 1a154d927593d5ff444ea4836f7c864da5a4d859..40b441006039bc3253ac05bfdc9ecd7a90e0ce7e 100644 (file)
@@ -2,7 +2,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/fs.h>
 #include <linux/magic.h>
 #include <pthread.h>
 #include <stddef.h>
@@ -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"
index 96cea432adc5a52020c81a3832af3184b9b6497e..41a8736066d70a8465dc2b51230d5dce12d0aa8f 100644 (file)
@@ -1,9 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <sys/mount.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#endif
 #include <linux/loop.h>
 
 #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"
index 92724e53f87749c43ad0218c52f2919975520d78..1737d1ef0ae4c73c6f7ea2ef8ca46be43d84690d 100644 (file)
@@ -4,9 +4,6 @@
 #include <getopt.h>
 #include <linux/fuse.h>
 #include <linux/loop.h>
-#if HAVE_SELINUX
-#include <selinux/selinux.h>
-#endif
 #include <stdlib.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
index f5b6a96d070f6ecb530e2265c60cd4fb73118cef..a088ff124e3e803a98d1d8d579d49aa5a7eb97ed 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/veth.h>
 #include <net/if.h>
 #include <sys/eventfd.h>
+#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <utmpx.h>
@@ -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"
index f509321ba89a41273908cb10c2d6a990e80454d7..d6df02428e5ab3dc6d2da46263cfa2a4a6ad3126 100644 (file)
@@ -1,10 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <sys/eventfd.h>
+#include <sys/mount.h>
 
 #include "fd-util.h"
 #include "main-func.h"
-#include "missing_mount.h"
 #include "missing_syscall.h"
 #include "namespace-util.h"
 #include "process-util.h"
index d57061e8fbd35cdc9a0d3027557beb733145fd6e..f23526c55f472e8cad646e9abdfafd1047a148b3 100644 (file)
@@ -5,13 +5,13 @@
 #if HAVE_VMLINUX_H
 
 #include <sched.h>
+#include <sys/mount.h>
 
 #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"
index 88333550247ef113d9af8b55601f0006f8c4341c..dd81a9726d6912ccd1782fd52073ebf6ea146843 100644 (file)
@@ -6,7 +6,6 @@
 
 #include <fcntl.h>
 #include <getopt.h>
-#include <linux/fs.h>
 #include <linux/loop.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
@@ -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"
index 9ae22d8aa561d2788cccfa5097af88565027cb95..8f33691ca3631c34e4ea326f3a2a6e1545d06f60 100644 (file)
@@ -3,8 +3,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
-#include <linux/btrfs_tree.h>
-#include <linux/fs.h>
 #include <linux/loop.h>
 #include <linux/magic.h>
 #include <stddef.h>
@@ -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"
index 6a008f2dbe88063332efc06b1bd0b33cd812c68e..d780906ca9b1216e3e9e39b5417aa71619e6759c 100644 (file)
@@ -2,7 +2,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/btrfs.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
index d6afa53a6bfc65f014945c33bc1ed78b2923320f..d545e0976aa9577de96fc2c31bd7f3474d6ecc5f 100644 (file)
@@ -2,7 +2,6 @@
 
 #include <errno.h>
 #include <fcntl.h>
-#include <linux/fs.h>
 #include <linux/loop.h>
 #include <linux/magic.h>
 #include <stdio.h>
@@ -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"
index b6563f9ab32d5cc88ec7d5b5e2178957772f2fa7..d9db618cf0f23e5dc182fc573096eb50152b8398 100644 (file)
@@ -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"
index 658128d8bd25176e422392a7c0cf5555e8b7e64c..2aca788fb8ee191fff1233196d6e94abb4fd1754 100644 (file)
@@ -3,7 +3,6 @@
   Copyright © 2018 Dell Inc.
 ***/
 
-#include <linux/fs.h>
 #include <linux/magic.h>
 #include <stddef.h>
 #include <sys/ioctl.h>
@@ -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"
index 3eba8dcb0733ccd4ee24f2c620667e81ac4c52f1..5b2c25067d74258953c8cf0ca87ea44a82049a2b 100644 (file)
@@ -7,7 +7,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/blkpg.h>
-#include <linux/fs.h>
 #include <linux/loop.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
@@ -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"
index 3ff15a22141a733e489537eabfc8736e31721030..b43ea73b9b1a27acbb1108e016af9eff620f7c12 100644 (file)
@@ -7,9 +7,6 @@
 #include <sys/statvfs.h>
 #include <unistd.h>
 #include <linux/loop.h>
-#if WANT_LINUX_FS_H
-#include <linux/fs.h>
-#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"
index b1c4a49da1a353fa39ec6bea20e083424084d105..47759a19c2bf17cff7145951c4e08e8f19528ce1 100644 (file)
@@ -1,6 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <linux/btrfs.h>
 #include <linux/magic.h>
 #include <sys/ioctl.h>
 #include <sys/vfs.h>
index 33220abe714e64fd96e28407c37aa66db0c60ac6..ce6a43101e540acf93c2157b1d3633d1d138e1f2 100644 (file)
@@ -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"
index e8091e048cee29e9d5a208ec3fc27ab6c28cec7b..c5aacc32f1a4931b332bd64940ba10900971fecd 100644 (file)
@@ -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"
index 971e46a032fd488ba7500ff87f434849c052e0f1..a3a36e99f40dbfedc69486ad7e275d27dc0522f2 100644 (file)
@@ -5,7 +5,6 @@
 #include <fnmatch.h>
 #include <getopt.h>
 #include <limits.h>
-#include <linux/fs.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdlib.h>
@@ -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"
index af711d8d88ba181a9a73e2c61c6e1de68553da62..b166b228f31defcd42956af745188a69744ea5a4 100644 (file)
@@ -1,13 +1,13 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include <fcntl.h>
-#include <linux/btrfs.h>
 #include <stdlib.h>
 #include <sys/ioctl.h>
 
 #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"