blob: 55a4abaf671550020f5ea00c73c989f50be90ebe [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 *
4 * Definitions for mount interface. This describes the in the kernel build
5 * linkedlist with mounted filesystems.
6 *
7 * Author: Marco van Wieringen <[email protected]>
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10#ifndef _LINUX_MOUNT_H
11#define _LINUX_MOUNT_H
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Andrew Mortond53d9f12005-07-12 13:58:07 -070013#include <linux/types.h>
Al Viro59df85d2022-03-01 19:56:53 -050014#include <asm/barrier.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
David Howells726c3342006-06-23 02:02:58 -070016struct super_block;
David Howells726c3342006-06-23 02:02:58 -070017struct dentry;
Al Viro59df85d2022-03-01 19:56:53 -050018struct user_namespace;
19struct file_system_type;
Al Viro8f2918892018-11-04 06:48:34 -050020struct fs_context;
Al Viro59df85d2022-03-01 19:56:53 -050021struct file;
22struct path;
David Howells726c3342006-06-23 02:02:58 -070023
Ram Pai07b20882005-11-07 17:19:07 -050024#define MNT_NOSUID 0x01
25#define MNT_NODEV 0x02
26#define MNT_NOEXEC 0x04
Christoph Hellwigfc33a7b2006-01-09 20:52:17 -080027#define MNT_NOATIME 0x08
28#define MNT_NODIRATIME 0x10
Valerie Henson47ae32d2006-12-13 00:34:34 -080029#define MNT_RELATIME 0x20
Dave Hansen2e4b7fc2008-02-15 14:38:00 -080030#define MNT_READONLY 0x40 /* does the user want this to be r/o? */
Mattias Nisslerdab741e02020-08-27 11:09:46 -060031#define MNT_NOSYMFOLLOW 0x80
Miklos Szeredibf066c72006-01-08 01:03:19 -080032
Trond Myklebust5528f9112006-06-09 09:34:17 -040033#define MNT_SHRINKABLE 0x100
[email protected]d3ef3d72009-04-26 20:25:54 +100034#define MNT_WRITE_HOLD 0x200
Trond Myklebust5528f9112006-06-09 09:34:17 -040035
Christoph Hellwigfc33a7b2006-01-09 20:52:17 -080036#define MNT_SHARED 0x1000 /* if the vfsmount is a shared mount */
37#define MNT_UNBINDABLE 0x2000 /* if the vfsmount is a unbindable mount */
Valerie Aurora495d6c92010-01-26 14:20:47 -050038/*
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)
Eric W. Biedermana6138db2014-07-28 16:26:53 -070046#define MNT_USER_SETTABLE_MASK (MNT_NOSUID | MNT_NODEV | MNT_NOEXEC \
47 | MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME \
Mattias Nisslerdab741e02020-08-27 11:09:46 -060048 | MNT_READONLY | MNT_NOSYMFOLLOW)
Eric W. Biederman9566d672014-07-28 17:26:07 -070049#define MNT_ATIME_MASK (MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME )
Valerie Aurora495d6c92010-01-26 14:20:47 -050050
Al Virof2ebb3a2014-02-27 09:35:45 -050051#define MNT_INTERNAL_FLAGS (MNT_SHARED | MNT_WRITE_HOLD | MNT_INTERNAL | \
Miklos Szeredi9f6c61f2020-05-14 16:44:24 +020052 MNT_DOOMED | MNT_SYNC_UMOUNT | MNT_MARKED | \
53 MNT_CURSOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Al Viro80893522010-02-05 09:30:46 -050055#define MNT_INTERNAL 0x4000
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Eric W. Biederman9566d672014-07-28 17:26:07 -070057#define MNT_LOCK_ATIME 0x040000
58#define MNT_LOCK_NOEXEC 0x080000
59#define MNT_LOCK_NOSUID 0x100000
60#define MNT_LOCK_NODEV 0x200000
Eric W. Biederman90563b12013-03-22 03:10:15 -070061#define MNT_LOCK_READONLY 0x400000
Eric W. Biederman5ff9d8a2013-03-29 21:04:39 -070062#define MNT_LOCKED 0x800000
Al Viro48a066e2013-09-29 22:06:07 -040063#define MNT_DOOMED 0x1000000
64#define MNT_SYNC_UMOUNT 0x2000000
Al Virof2ebb3a2014-02-27 09:35:45 -050065#define MNT_MARKED 0x4000000
Eric W. Biederman590ce4bc2014-12-22 18:30:08 -060066#define MNT_UMOUNT 0x8000000
Miklos Szeredi9f6c61f2020-05-14 16:44:24 +020067#define MNT_CURSOR 0x10000000
Eric W. Biederman90563b12013-03-22 03:10:15 -070068
Ram Pai07b20882005-11-07 17:19:07 -050069struct vfsmount {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 struct dentry *mnt_root; /* root of the mounted tree */
71 struct super_block *mnt_sb; /* pointer to superblock */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 int mnt_flags;
Christian Braunera6435942021-01-21 14:19:20 +010073 struct user_namespace *mnt_userns;
Kees Cook3859a272016-10-28 01:22:25 -070074} __randomize_layout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Christian Braunera6435942021-01-21 14:19:20 +010076static inline struct user_namespace *mnt_user_ns(const struct vfsmount *mnt)
77{
Christian Brauner9caccd42021-01-21 14:19:54 +010078 /* Pairs with smp_store_release() in do_idmap_mount(). */
79 return smp_load_acquire(&mnt->mnt_userns);
Christian Braunera6435942021-01-21 14:19:20 +010080}
81
Dave Hansen83660252008-02-15 14:37:30 -080082extern int mnt_want_write(struct vfsmount *mnt);
[email protected]96029c42009-04-26 20:25:55 +100083extern int mnt_want_write_file(struct file *file);
Dave Hansen83660252008-02-15 14:37:30 -080084extern void mnt_drop_write(struct vfsmount *mnt);
Al Viro2a79f172011-12-09 08:06:57 -050085extern void mnt_drop_write_file(struct file *file);
Nick Pigginb3e19d92011-01-07 17:50:11 +110086extern void mntput(struct vfsmount *mnt);
87extern struct vfsmount *mntget(struct vfsmount *mnt);
Al Viroca71cf72016-11-20 19:45:28 -050088extern struct vfsmount *mnt_clone_internal(const struct path *path);
David Howells43f5e652018-11-01 23:07:25 +000089extern bool __mnt_is_readonly(struct vfsmount *mnt);
Andy Lutomirski380cf5b2016-06-23 16:41:05 -050090extern bool mnt_may_suid(struct vfsmount *mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Al Viroca71cf72016-11-20 19:45:28 -050092extern struct vfsmount *clone_private_mount(const struct path *path);
Al Viro9419a312019-04-04 21:04:13 -040093extern int __mnt_want_write(struct vfsmount *);
94extern void __mnt_drop_write(struct vfsmount *);
Miklos Szeredic771d682014-10-24 00:14:36 +020095
Al Viro8f2918892018-11-04 06:48:34 -050096extern struct vfsmount *fc_mount(struct fs_context *fc);
97extern struct vfsmount *vfs_create_mount(struct fs_context *fc);
Trond Myklebustbb4a58b2006-06-09 09:34:15 -040098extern struct vfsmount *vfs_kern_mount(struct file_system_type *type,
99 int flags, const char *name,
100 void *data);
Eric W. Biederman93faccbb2017-02-01 06:06:16 +1300101extern struct vfsmount *vfs_submount(const struct dentry *mountpoint,
102 struct file_system_type *type,
103 const char *name, void *data);
Trond Myklebustbb4a58b2006-06-09 09:34:15 -0400104
David Howellsea5b7782011-01-14 19:10:03 +0000105extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern void mark_mounts_for_expiry(struct list_head *mounts);
107
Dan Ehrenberge6e20a72015-02-10 15:20:49 -0800108extern dev_t name_to_dev_t(const char *name);
Ian Kentc6609c02016-11-24 08:03:41 +1100109extern bool path_is_mountpoint(const struct path *path);
110
Al Viro70f8d9c2022-03-02 17:49:09 -0500111extern bool our_mnt(struct vfsmount *mnt);
112
113extern struct vfsmount *kern_mount(struct file_system_type *);
114extern void kern_unmount(struct vfsmount *mnt);
115extern int may_umount_tree(struct vfsmount *);
116extern int may_umount(struct vfsmount *);
117extern long do_mount(const char *, const char __user *,
118 const char *, unsigned long, void *);
119extern struct vfsmount *collect_mounts(const struct path *);
120extern void drop_collected_mounts(struct vfsmount *);
121extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,
122 struct vfsmount *);
Miklos Szeredidf820f82020-06-04 10:48:19 +0200123extern void kern_unmount_array(struct vfsmount *mnt[], unsigned int num);
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif /* _LINUX_MOUNT_H */