1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 *
4 * Definitions for mount interface. This describes the in the kernel build
5 * linkedlist with mounted filesystems.
6 *
7 * Author: Marco van Wieringen <mvw@planets.elm.net>
8 *
9 */
10 #ifndef _LINUX_MOUNT_H
11 #define _LINUX_MOUNT_H
12
13 #include <linux/types.h>
14 #include <asm/barrier.h>
15
16 struct super_block;
17 struct dentry;
18 struct user_namespace;
19 struct file_system_type;
20 struct fs_context;
21 struct file;
22 struct path;
23
24 #define MNT_NOSUID 0x01
25 #define MNT_NODEV 0x02
26 #define MNT_NOEXEC 0x04
27 #define MNT_NOATIME 0x08
28 #define MNT_NODIRATIME 0x10
29 #define MNT_RELATIME 0x20
30 #define MNT_READONLY 0x40 /* does the user want this to be r/o? */
31 #define MNT_NOSYMFOLLOW 0x80
32
33 #define MNT_SHRINKABLE 0x100
34 #define MNT_WRITE_HOLD 0x200
35
36 #define MNT_SHARED 0x1000 /* if the vfsmount is a shared mount */
37 #define MNT_UNBINDABLE 0x2000 /* if the vfsmount is a unbindable mount */
38 /*
39 * MNT_SHARED_MASK is the set of flags that should be cleared when a
40 * mount becomes shared. Currently, this is only the flag that says a
41 * mount cannot be bind mounted, since this is how we create a mount
42 * that shares events with another mount. If you add a new MNT_*
43 * flag, consider how it interacts with shared mounts.
44 */
45 #define MNT_SHARED_MASK (MNT_UNBINDABLE)
46 #define MNT_USER_SETTABLE_MASK (MNT_NOSUID | MNT_NODEV | MNT_NOEXEC \
47 | MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME \
48 | MNT_READONLY | MNT_NOSYMFOLLOW)
49 #define MNT_ATIME_MASK (MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME )
50
51 #define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \
52 MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED | \
53 MNT_CURSOR)
54
55 #define MNT_INTERNAL 0x4000
56
57 #define MNT_LOCK_ATIME 0x040000
58 #define MNT_LOCK_NOEXEC 0x080000
59 #define MNT_LOCK_NOSUID 0x100000
60 #define MNT_LOCK_NODEV 0x200000
61 #define MNT_LOCK_READONLY 0x400000
62 #define MNT_LOCKED 0x800000
63 #define MNT_DOOMED 0x1000000
64 #define MNT_SYNC_UMOUNT 0x2000000
65 #define MNT_MARKED 0x4000000
66 #define MNT_UMOUNT 0x8000000
67 #define MNT_CURSOR 0x10000000
68
69 struct vfsmount {
70 struct dentry *mnt_root; /* root of the mounted tree */
71 struct super_block *mnt_sb; /* pointer to superblock */
72 int mnt_flags;
73 struct user_namespace *mnt_userns;
74 } __randomize_layout;
75
mnt_user_ns(const struct vfsmount * mnt)76 static inline struct user_namespace *mnt_user_ns(const struct vfsmount *mnt)
77 {
78 /* Pairs with smp_store_release() in do_idmap_mount(). */
79 return smp_load_acquire(&mnt->mnt_userns);
80 }
81
82 extern int mnt_want_write(struct vfsmount *mnt);
83 extern int mnt_want_write_file(struct file *file);
84 extern void mnt_drop_write(struct vfsmount *mnt);
85 extern void mnt_drop_write_file(struct file *file);
86 extern void mntput(struct vfsmount *mnt);
87 extern struct vfsmount *mntget(struct vfsmount *mnt);
88 extern struct vfsmount *mnt_clone_internal(const struct path *path);
89 extern bool __mnt_is_readonly(struct vfsmount *mnt);
90 extern bool mnt_may_suid(struct vfsmount *mnt);
91
92 extern struct vfsmount *clone_private_mount(const struct path *path);
93 extern int __mnt_want_write(struct vfsmount *);
94 extern void __mnt_drop_write(struct vfsmount *);
95
96 extern struct vfsmount *fc_mount(struct fs_context *fc);
97 extern struct vfsmount *vfs_create_mount(struct fs_context *fc);
98 extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
99 int flags, const char *name,
100 void *data);
101 extern struct vfsmount *vfs_submount(const struct dentry *mountpoint,
102 struct file_system_type *type,
103 const char *name, void *data);
104
105 extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list);
106 extern void mark_mounts_for_expiry(struct list_head *mounts);
107
108 extern dev_t name_to_dev_t(const char *name);
109 extern bool path_is_mountpoint(const struct path *path);
110
111 extern bool our_mnt(struct vfsmount *mnt);
112
113 extern struct vfsmount *kern_mount(struct file_system_type *);
114 extern void kern_unmount(struct vfsmount *mnt);
115 extern int may_umount_tree(struct vfsmount *);
116 extern int may_umount(struct vfsmount *);
117 extern long do_mount(const char *, const char __user *,
118 const char *, unsigned long, void *);
119 extern struct vfsmount *collect_mounts(const struct path *);
120 extern void drop_collected_mounts(struct vfsmount *);
121 extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
122 struct vfsmount *);
123 extern void kern_unmount_array(struct vfsmount *mnt[], unsigned int num);
124
125 #endif /* _LINUX_MOUNT_H */
126