| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <fcntl.h> |
| 5 |
#include <linux/fs.h> |
| 6 |
#include <linux/mount.h> /* IWYU pragma: export */ |
| 7 |
#include <stddef.h> |
| 8 |
#include <stdint.h> |
| 9 |
#include <sys/ioctl.h> |
| 10 |
|
| 11 |
/* Since glibc-2.37 (774058d72942249f71d74e7f2b639f77184160a6), sys/mount.h includes linux/mount.h, and |
| 12 |
* we can safely include both headers in the same source file. However, we cannot do that with older glibc. |
| 13 |
* To avoid conflicts, let's not use glibc's sys/mount.h, and provide our own minimal implementation. |
| 14 |
* Fortunately, most of definitions we need are covered by linux/fs.h and linux/mount.h, so only one enum |
| 15 |
* and a few function prototypes need to be defined here. */ |
| 16 |
|
| 17 |
/* Possible value for FLAGS parameter of `umount2'. */ |
| 18 |
enum |
| 19 |
{ |
| 20 |
MNT_FORCE = 1, /* Force unmounting. */ |
| 21 |
#define MNT_FORCE MNT_FORCE |
| 22 |
MNT_DETACH = 2, /* Just detach from the tree. */ |
| 23 |
#define MNT_DETACH MNT_DETACH |
| 24 |
MNT_EXPIRE = 4, /* Mark for expiry. */ |
| 25 |
#define MNT_EXPIRE MNT_EXPIRE |
| 26 |
UMOUNT_NOFOLLOW = 8 /* Don't follow symlink on umount. */ |
| 27 |
#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW |
| 28 |
}; |
| 29 |
|
| 30 |
/* Mount a filesystem. */ |
| 31 |
extern int mount(const char *__special_file, const char *__dir, const char *__fstype, unsigned long int __rwflag, const void *__data); |
| 32 |
|
| 33 |
/* Unmount a filesystem. */ |
| 34 |
extern int umount(const char *__special_file); |
| 35 |
|
| 36 |
/* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */ |
| 37 |
extern int umount2(const char *__special_file, int __flags); |
| 38 |
|
| 39 |
/* Open the filesystem referenced by FS_NAME so it can be configured for mounting. */ |
| 40 |
/* Defined since glibc-2.36. |
| 41 |
* Supported since kernel v5.2 (24dcb3d90a1f67fe08c68a004af37df059d74005). */ |
| 42 |
int fsopen_shim(const char *fsname, unsigned flags); |
| 43 |
#define fsopen fsopen_shim |
| 44 |
|
| 45 |
/* Create a mount representation for the FD created by fsopen using |
| 46 |
FLAGS with ATTR_FLAGS describing how the mount is to be performed. */ |
| 47 |
/* Defined since glibc-2.36. |
| 48 |
* Supported since kernel v5.2 (93766fbd2696c2c4453dd8e1070977e9cd4e6b6d). */ |
| 49 |
int fsmount_shim(int fd, unsigned flags, unsigned ms_flags); |
| 50 |
#define fsmount fsmount_shim |
| 51 |
|
| 52 |
/* Add the mounted FROM_DFD referenced by FROM_PATHNAME filesystem returned |
| 53 |
by fsmount in the hierarchy in the place TO_DFD reference by TO_PATHNAME |
| 54 |
using FLAGS. */ |
| 55 |
/* Defined since glibc-2.36. |
| 56 |
* Supported since kernel v5.2 (2db154b3ea8e14b04fee23e3fdfd5e9d17fbc6ae). */ |
| 57 |
int move_mount_shim(int from_dfd, const char *from_pathname, int to_dfd, const char *to_pathname, unsigned flags); |
| 58 |
#define move_mount move_mount_shim |
| 59 |
|
| 60 |
/* Set parameters and trigger CMD action on the FD context. KEY, VALUE, |
| 61 |
and AUX are used depending ng of the CMD. */ |
| 62 |
/* Defined since glibc-2.36. |
| 63 |
* Supported since kernel v5.2 (ecdab150fddb42fe6a739335257949220033b782). */ |
| 64 |
int fsconfig_shim(int fd, unsigned cmd, const char *key, const void *value, int aux); |
| 65 |
#define fsconfig fsconfig_shim |
| 66 |
|
| 67 |
/* Open the mount point FILENAME in directory DFD using FLAGS. */ |
| 68 |
/* Defined since glibc-2.36. |
| 69 |
* Supported since kernel v5.2 (a07b20004793d8926f78d63eb5980559f7813404). */ |
| 70 |
int open_tree_shim(int dfd, const char *filename, unsigned flags); |
| 71 |
#define open_tree open_tree_shim |
| 72 |
|
| 73 |
/* Change the mount properties of the mount or an entire mount tree. If |
| 74 |
PATH is a relative pathname, then it is interpreted relative to the |
| 75 |
directory referred to by the file descriptor dirfd. Otherwise if DFD is |
| 76 |
the special value AT_FDCWD then PATH is interpreted relative to the current |
| 77 |
working directory of the calling process. */ |
| 78 |
/* Defined since glibc-2.36. |
| 79 |
* Supported since kernel v5.12 (2a1867219c7b27f928e2545782b86daaf9ad50bd). */ |
| 80 |
int mount_setattr_shim(int dfd, const char *path, unsigned flags, struct mount_attr *attr, size_t size); |
| 81 |
#define mount_setattr mount_setattr_shim |
| 82 |
|
| 83 |
/* Not defined in glibc yet as of glibc-2.41. |
| 84 |
* Supported since kernel v6.15 (c4a16820d90199409c9bf01c4f794e1e9e8d8fd8). */ |
| 85 |
int open_tree_attr_shim(int dfd, const char *filename, unsigned int flags, struct mount_attr *attr, size_t size); |
| 86 |
#define open_tree_attr open_tree_attr_shim |