1/*-
   2 * SPDX-License-Identifier: BSD-3-Clause
   3 *
   4 * Copyright (c) 1989, 1991, 1993
   5 *	The Regents of the University of California.  All rights reserved.
   6 *
   7 * Redistribution and use in source and binary forms, with or without
   8 * modification, are permitted provided that the following conditions
   9 * are met:
  10 * 1. Redistributions of source code must retain the above copyright
  11 *    notice, this list of conditions and the following disclaimer.
  12 * 2. Redistributions in binary form must reproduce the above copyright
  13 *    notice, this list of conditions and the following disclaimer in the
  14 *    documentation and/or other materials provided with the distribution.
  15 * 3. Neither the name of the University nor the names of its contributors
  16 *    may be used to endorse or promote products derived from this software
  17 *    without specific prior written permission.
  18 *
  19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29 * SUCH DAMAGE.
  30 *
  31 *	@(#)mount.h	8.21 (Berkeley) 5/20/95
  32 */
  33
  34#ifndef _SYS_MOUNT_H_
  35#define _SYS_MOUNT_H_
  36
  37#include <sys/ucred.h>
  38#include <sys/queue.h>
  39#ifdef _KERNEL
  40#include <sys/types.h>
  41#include <sys/lock.h>
  42#include <sys/lockmgr.h>
  43#include <sys/tslog.h>
  44#include <sys/_mutex.h>
  45#include <sys/_sx.h>
  46#endif
  47
  48/*
  49 * NOTE: When changing statfs structure, mount structure, MNT_* flags or
  50 * MNTK_* flags also update DDB show mount command in vfs_subr.c.
  51 */
  52
  53typedef struct fsid { int32_t val[2]; } fsid_t;	/* filesystem id type */
  54
  55/* Returns non-zero if fsids are different. */
  56static __inline int
  57fsidcmp(const fsid_t *a, const fsid_t *b)
  58{
  59	return (a->val[0] != b->val[0] || a->val[1] != b->val[1]);
  60}
  61
  62/*
  63 * File identifier.
  64 * These are unique per filesystem on a single machine.
  65 *
  66 * Note that the offset of fid_data is 4 bytes, so care must be taken to avoid
  67 * undefined behavior accessing unaligned fields within an embedded struct.
  68 */
  69#define	MAXFIDSZ	16
  70
  71struct fid {
  72	u_short		fid_len;		/* length of data in bytes */
  73	u_short		fid_data0;		/* force longword alignment */
  74	char		fid_data[MAXFIDSZ];	/* data (variable length) */
  75};
  76
  77/*
  78 * filesystem statistics
  79 */
  80#define	MFSNAMELEN	16		/* length of type name including null */
  81#define	MNAMELEN	1024		/* size of on/from name bufs */
  82#define	STATFS_VERSION	0x20140518	/* current version number */
  83struct statfs {
  84	uint32_t f_version;		/* structure version number */
  85	uint32_t f_type;		/* type of filesystem */
  86	uint64_t f_flags;		/* copy of mount exported flags */
  87	uint64_t f_bsize;		/* filesystem fragment size */
  88	uint64_t f_iosize;		/* optimal transfer block size */
  89	uint64_t f_blocks;		/* total data blocks in filesystem */
  90	uint64_t f_bfree;		/* free blocks in filesystem */
  91	int64_t	 f_bavail;		/* free blocks avail to non-superuser */
  92	uint64_t f_files;		/* total file nodes in filesystem */
  93	int64_t	 f_ffree;		/* free nodes avail to non-superuser */
  94	uint64_t f_syncwrites;		/* count of sync writes since mount */
  95	uint64_t f_asyncwrites;		/* count of async writes since mount */
  96	uint64_t f_syncreads;		/* count of sync reads since mount */
  97	uint64_t f_asyncreads;		/* count of async reads since mount */
  98	uint32_t f_nvnodelistsize;	/* # of vnodes */
  99	uint32_t f_spare0;		/* unused spare */
 100	uint64_t f_spare[9];		/* unused spare */
 101	uint32_t f_namemax;		/* maximum filename length */
 102	uid_t	  f_owner;		/* user that mounted the filesystem */
 103	fsid_t	  f_fsid;		/* filesystem id */
 104	char	  f_charspare[80];	    /* spare string space */
 105	char	  f_fstypename[MFSNAMELEN]; /* filesystem type name */
 106	char	  f_mntfromname[MNAMELEN];  /* mounted filesystem */
 107	char	  f_mntonname[MNAMELEN];    /* directory on which mounted */
 108};
 109
 110#if defined(_WANT_FREEBSD11_STATFS) || defined(_KERNEL)
 111#define	FREEBSD11_STATFS_VERSION	0x20030518 /* current version number */
 112struct freebsd11_statfs {
 113	uint32_t f_version;		/* structure version number */
 114	uint32_t f_type;		/* type of filesystem */
 115	uint64_t f_flags;		/* copy of mount exported flags */
 116	uint64_t f_bsize;		/* filesystem fragment size */
 117	uint64_t f_iosize;		/* optimal transfer block size */
 118	uint64_t f_blocks;		/* total data blocks in filesystem */
 119	uint64_t f_bfree;		/* free blocks in filesystem */
 120	int64_t	 f_bavail;		/* free blocks avail to non-superuser */
 121	uint64_t f_files;		/* total file nodes in filesystem */
 122	int64_t	 f_ffree;		/* free nodes avail to non-superuser */
 123	uint64_t f_syncwrites;		/* count of sync writes since mount */
 124	uint64_t f_asyncwrites;		/* count of async writes since mount */
 125	uint64_t f_syncreads;		/* count of sync reads since mount */
 126	uint64_t f_asyncreads;		/* count of async reads since mount */
 127	uint64_t f_spare[10];		/* unused spare */
 128	uint32_t f_namemax;		/* maximum filename length */
 129	uid_t	  f_owner;		/* user that mounted the filesystem */
 130	fsid_t	  f_fsid;		/* filesystem id */
 131	char	  f_charspare[80];	/* spare string space */
 132	char	  f_fstypename[16];	/* filesystem type name */
 133	char	  f_mntfromname[88];	/* mounted filesystem */
 134	char	  f_mntonname[88];	/* directory on which mounted */
 135};
 136#endif /* _WANT_FREEBSD11_STATFS || _KERNEL */
 137
 138#ifdef _KERNEL
 139#define	OMFSNAMELEN	16	/* length of fs type name, including null */
 140#define	OMNAMELEN	(88 - 2 * sizeof(long))	/* size of on/from name bufs */
 141
 142/* XXX getfsstat.2 is out of date with write and read counter changes here. */
 143/* XXX statfs.2 is out of date with read counter changes here. */
 144struct ostatfs {
 145	long	f_spare2;		/* placeholder */
 146	long	f_bsize;		/* fundamental filesystem block size */
 147	long	f_iosize;		/* optimal transfer block size */
 148	long	f_blocks;		/* total data blocks in filesystem */
 149	long	f_bfree;		/* free blocks in fs */
 150	long	f_bavail;		/* free blocks avail to non-superuser */
 151	long	f_files;		/* total file nodes in filesystem */
 152	long	f_ffree;		/* free file nodes in fs */
 153	fsid_t	f_fsid;			/* filesystem id */
 154	uid_t	f_owner;		/* user that mounted the filesystem */
 155	int	f_type;			/* type of filesystem */
 156	int	f_flags;		/* copy of mount exported flags */
 157	long	f_syncwrites;		/* count of sync writes since mount */
 158	long	f_asyncwrites;		/* count of async writes since mount */
 159	char	f_fstypename[OMFSNAMELEN]; /* fs type name */
 160	char	f_mntonname[OMNAMELEN];	/* directory on which mounted */
 161	long	f_syncreads;		/* count of sync reads since mount */
 162	long	f_asyncreads;		/* count of async reads since mount */
 163	short	f_spares1;		/* unused spare */
 164	char	f_mntfromname[OMNAMELEN];/* mounted filesystem */
 165	short	f_spares2;		/* unused spare */
 166	/*
 167	 * XXX on machines where longs are aligned to 8-byte boundaries, there
 168	 * is an unnamed int32_t here.  This spare was after the apparent end
 169	 * of the struct until we bit off the read counters from f_mntonname.
 170	 */
 171	long	f_spare[2];		/* unused spare */
 172};
 173#endif	/* _KERNEL */
 174
 175#if defined(_WANT_MOUNT) || defined(_KERNEL)
 176TAILQ_HEAD(vnodelst, vnode);
 177
 178/* Mount options list */
 179TAILQ_HEAD(vfsoptlist, vfsopt);
 180struct vfsopt {
 181	TAILQ_ENTRY(vfsopt) link;
 182	char	*name;
 183	void	*value;
 184	int	len;
 185	int	pos;
 186	int	seen;
 187};
 188
 189struct mount_pcpu {
 190	int		mntp_thread_in_ops;
 191	int		mntp_ref;
 192	int		mntp_lockref;
 193	int		mntp_writeopcount;
 194};
 195
 196_Static_assert(sizeof(struct mount_pcpu) == 16,
 197    "the struct is allocated from pcpu 16 zone");
 198
 199/*
 200 * Structure for tracking a stacked filesystem mounted above another
 201 * filesystem.  This is expected to be stored in the upper FS' per-mount data.
 202 *
 203 * Lock reference:
 204 *	i - lower mount interlock
 205 *	c - constant from node initialization
 206 */
 207struct mount_upper_node {
 208	struct mount 	*mp;	/* (c) mount object for upper FS */
 209	TAILQ_ENTRY(mount_upper_node) mnt_upper_link;	/* (i) position in uppers list */
 210};
 211
 212/*
 213 * Structure per mounted filesystem.  Each mounted filesystem has an
 214 * array of operations and an instance record.  The filesystems are
 215 * put on a doubly linked list.
 216 *
 217 * Lock reference:
 218 * 	l - mnt_listmtx
 219 *	m - mountlist_mtx
 220 *	i - interlock
 221 *	v - vnode freelist mutex
 222 *	d - deferred unmount list mutex
 223 *	e - mnt_explock
 224 *
 225 * Unmarked fields are considered stable as long as a ref is held.
 226 *
 227 */
 228struct mount {
 229	int 		mnt_vfs_ops;		/* (i) pending vfs ops */
 230	int		mnt_kern_flag;		/* (i) kernel only flags */
 231	uint64_t	mnt_flag;		/* (i) flags shared with user */
 232	struct mount_pcpu *mnt_pcpu;		/* per-CPU data */
 233	struct vnode	*mnt_rootvnode;
 234	struct vnode	*mnt_vnodecovered;	/* vnode we mounted on */
 235	struct vfsops	*mnt_op;		/* operations on fs */
 236	struct vfsconf	*mnt_vfc;		/* configuration info */
 237	struct mtx __aligned(CACHE_LINE_SIZE)	mnt_mtx; /* mount structure interlock */
 238	int		mnt_gen;		/* struct mount generation */
 239#define	mnt_startzero	mnt_list
 240	TAILQ_ENTRY(mount) mnt_list;		/* (m) mount list */
 241	struct vnode	*mnt_syncer;		/* syncer vnode */
 242	int		mnt_ref;		/* (i) Reference count */
 243	struct vnodelst	mnt_nvnodelist;		/* (i) list of vnodes */
 244	int		mnt_nvnodelistsize;	/* (i) # of vnodes */
 245	int		mnt_writeopcount;	/* (i) write syscalls pending */
 246	struct vfsoptlist *mnt_opt;		/* current mount options */
 247	struct vfsoptlist *mnt_optnew;		/* new options passed to fs */
 248	struct statfs	mnt_stat;		/* cache of filesystem stats */
 249	struct ucred	*mnt_cred;		/* credentials of mounter */
 250	void *		mnt_data;		/* private data */
 251	time_t		mnt_time;		/* last time written*/
 252	int		mnt_iosize_max;		/* max size for clusters, etc */
 253	struct netexport *mnt_export;		/* (e) export list */
 254	struct label	*mnt_label;		/* MAC label for the fs */
 255	u_int		mnt_hashseed;		/* Random seed for vfs_hash */
 256	int		mnt_lockref;		/* (i) Lock reference count */
 257	int		mnt_secondary_writes;   /* (i) # of secondary writes */
 258	int		mnt_secondary_accwrites;/* (i) secondary wr. starts */
 259	struct thread	*mnt_susp_owner;	/* (i) thread owning suspension */
 260	struct ucred	*mnt_exjail;		/* (i) jail which did exports */
 261#define	mnt_endzero	mnt_gjprovider
 262	char		*mnt_gjprovider;	/* gjournal provider name */
 263	struct mtx	mnt_listmtx;
 264	struct vnodelst	mnt_lazyvnodelist;	/* (l) list of lazy vnodes */
 265	int		mnt_lazyvnodelistsize;	/* (l) # of lazy vnodes */
 266	int		mnt_upper_pending;	/* (i) # of pending ops on mnt_uppers */
 267	struct lock	mnt_explock;		/* vfs_export walkers lock */
 268	TAILQ_HEAD(, mount_upper_node) mnt_uppers; /* (i) upper mounts over us */
 269	TAILQ_HEAD(, mount_upper_node) mnt_notify; /* (i) upper mounts for notification */
 270	STAILQ_ENTRY(mount) mnt_taskqueue_link;	/* (d) our place in deferred unmount list */
 271	uint64_t	mnt_taskqueue_flags;	/* (d) unmount flags passed from taskqueue */
 272	unsigned int	mnt_unmount_retries;	/* (d) # of failed deferred unmount attempts */
 273};
 274#endif	/* _WANT_MOUNT || _KERNEL */
 275
 276#ifdef _KERNEL
 277/*
 278 * Definitions for MNT_VNODE_FOREACH_ALL.
 279 */
 280struct vnode *__mnt_vnode_next_all(struct vnode **mvp, struct mount *mp);
 281struct vnode *__mnt_vnode_first_all(struct vnode **mvp, struct mount *mp);
 282void          __mnt_vnode_markerfree_all(struct vnode **mvp, struct mount *mp);
 283
 284#define MNT_VNODE_FOREACH_ALL(vp, mp, mvp)				\
 285	for (vp = __mnt_vnode_first_all(&(mvp), (mp));			\
 286		(vp) != NULL; vp = __mnt_vnode_next_all(&(mvp), (mp)))
 287
 288#define MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp)				\
 289	do {								\
 290		MNT_ILOCK(mp);						\
 291		__mnt_vnode_markerfree_all(&(mvp), (mp));		\
 292		/* MNT_IUNLOCK(mp); -- done in above function */	\
 293		mtx_assert(MNT_MTX(mp), MA_NOTOWNED);			\
 294	} while (0)
 295
 296/*
 297 * Definitions for MNT_VNODE_FOREACH_LAZY.
 298 */
 299typedef int mnt_lazy_cb_t(struct vnode *, void *);
 300struct vnode *__mnt_vnode_next_lazy(struct vnode **mvp, struct mount *mp,
 301    mnt_lazy_cb_t *cb, void *cbarg);
 302struct vnode *__mnt_vnode_first_lazy(struct vnode **mvp, struct mount *mp,
 303    mnt_lazy_cb_t *cb, void *cbarg);
 304void          __mnt_vnode_markerfree_lazy(struct vnode **mvp, struct mount *mp);
 305
 306#define MNT_VNODE_FOREACH_LAZY(vp, mp, mvp, cb, cbarg)			\
 307	for (vp = __mnt_vnode_first_lazy(&(mvp), (mp), (cb), (cbarg));	\
 308		(vp) != NULL; 						\
 309		vp = __mnt_vnode_next_lazy(&(mvp), (mp), (cb), (cbarg)))
 310
 311#define MNT_VNODE_FOREACH_LAZY_ABORT(mp, mvp)				\
 312	__mnt_vnode_markerfree_lazy(&(mvp), (mp))
 313
 314#define	MNT_ILOCK(mp)	mtx_lock(&(mp)->mnt_mtx)
 315#define	MNT_ITRYLOCK(mp) mtx_trylock(&(mp)->mnt_mtx)
 316#define	MNT_IUNLOCK(mp)	mtx_unlock(&(mp)->mnt_mtx)
 317#define	MNT_MTX(mp)	(&(mp)->mnt_mtx)
 318
 319#define	MNT_REF(mp)	do {						\
 320	mtx_assert(MNT_MTX(mp), MA_OWNED);				\
 321	mp->mnt_ref++;							\
 322} while (0)
 323#define	MNT_REL(mp)	do {						\
 324	mtx_assert(MNT_MTX(mp), MA_OWNED);				\
 325	(mp)->mnt_ref--;						\
 326	if ((mp)->mnt_vfs_ops && (mp)->mnt_ref < 0)		\
 327		vfs_dump_mount_counters(mp);				\
 328	if ((mp)->mnt_ref == 0 && (mp)->mnt_vfs_ops)		\
 329		wakeup((mp));						\
 330} while (0)
 331
 332#endif /* _KERNEL */
 333
 334#if defined(_WANT_MNTOPTNAMES) || defined(_KERNEL)
 335struct mntoptnames {
 336	uint64_t o_opt;
 337	const char *o_name;
 338};
 339#define MNTOPT_NAMES							\
 340	{ MNT_ASYNC,		"asynchronous" },			\
 341	{ MNT_EXPORTED,		"NFS exported" },			\
 342	{ MNT_LOCAL,		"local" },				\
 343	{ MNT_NOATIME,		"noatime" },				\
 344	{ MNT_NOEXEC,		"noexec" },				\
 345	{ MNT_NOSUID,		"nosuid" },				\
 346	{ MNT_NOSYMFOLLOW,	"nosymfollow" },			\
 347	{ MNT_QUOTA,		"with quotas" },			\
 348	{ MNT_RDONLY,		"read-only" },				\
 349	{ MNT_SYNCHRONOUS,	"synchronous" },			\
 350	{ MNT_UNION,		"union" },				\
 351	{ MNT_NOCLUSTERR,	"noclusterr" },				\
 352	{ MNT_NOCLUSTERW,	"noclusterw" },				\
 353	{ MNT_SUIDDIR,		"suiddir" },				\
 354	{ MNT_SOFTDEP,		"soft-updates" },			\
 355	{ MNT_SUJ,		"journaled soft-updates" },		\
 356	{ MNT_MULTILABEL,	"multilabel" },				\
 357	{ MNT_ACLS,		"acls" },				\
 358	{ MNT_NFS4ACLS,		"nfsv4acls" },				\
 359	{ MNT_GJOURNAL,		"gjournal" },				\
 360	{ MNT_AUTOMOUNTED,	"automounted" },			\
 361	{ MNT_VERIFIED,		"verified" },				\
 362	{ MNT_UNTRUSTED,	"untrusted" },				\
 363	{ MNT_NOCOVER,		"nocover" },				\
 364	{ MNT_EMPTYDIR,		"emptydir" },				\
 365	{ MNT_UPDATE,		"update" },				\
 366	{ MNT_DELEXPORT,	"delexport" },				\
 367	{ MNT_RELOAD,		"reload" },				\
 368	{ MNT_FORCE,		"force" },				\
 369	{ MNT_SNAPSHOT,		"snapshot" },				\
 370	{ 0, NULL }
 371#endif
 372
 373/*
 374 * User specifiable flags, stored in mnt_flag.
 375 */
 376#define	MNT_RDONLY	0x0000000000000001ULL /* read only filesystem */
 377#define	MNT_SYNCHRONOUS	0x0000000000000002ULL /* fs written synchronously */
 378#define	MNT_NOEXEC	0x0000000000000004ULL /* can't exec from filesystem */
 379#define	MNT_NOSUID	0x0000000000000008ULL /* don't honor setuid fs bits */
 380#define	MNT_NFS4ACLS	0x0000000000000010ULL /* enable NFS version 4 ACLs */
 381#define	MNT_UNION	0x0000000000000020ULL /* union with underlying fs */
 382#define	MNT_ASYNC	0x0000000000000040ULL /* fs written asynchronously */
 383#define	MNT_SUIDDIR	0x0000000000100000ULL /* special SUID dir handling */
 384#define	MNT_SOFTDEP	0x0000000000200000ULL /* using soft updates */
 385#define	MNT_NOSYMFOLLOW	0x0000000000400000ULL /* do not follow symlinks */
 386#define	MNT_GJOURNAL	0x0000000002000000ULL /* GEOM journal support enabled */
 387#define	MNT_MULTILABEL	0x0000000004000000ULL /* MAC support for objects */
 388#define	MNT_ACLS	0x0000000008000000ULL /* ACL support enabled */
 389#define	MNT_NOATIME	0x0000000010000000ULL /* dont update file access time */
 390#define	MNT_NOCLUSTERR	0x0000000040000000ULL /* disable cluster read */
 391#define	MNT_NOCLUSTERW	0x0000000080000000ULL /* disable cluster write */
 392#define	MNT_SUJ		0x0000000100000000ULL /* using journaled soft updates */
 393#define	MNT_AUTOMOUNTED	0x0000000200000000ULL /* mounted by automountd(8) */
 394#define	MNT_UNTRUSTED	0x0000000800000000ULL /* filesys metadata untrusted */
 395
 396/*
 397 * NFS export related mount flags.
 398 */
 399#define	MNT_EXRDONLY	0x0000000000000080ULL	/* exported read only */
 400#define	MNT_EXPORTED	0x0000000000000100ULL	/* filesystem is exported */
 401#define	MNT_DEFEXPORTED	0x0000000000000200ULL	/* exported to the world */
 402#define	MNT_EXPORTANON	0x0000000000000400ULL	/* anon uid mapping for all */
 403#define	MNT_EXKERB	0x0000000000000800ULL	/* exported with Kerberos */
 404#define	MNT_EXPUBLIC	0x0000000020000000ULL	/* public export (WebNFS) */
 405#define	MNT_EXTLS	0x0000004000000000ULL /* require TLS */
 406#define	MNT_EXTLSCERT	0x0000008000000000ULL /* require TLS with client cert */
 407#define	MNT_EXTLSCERTUSER 0x0000010000000000ULL /* require TLS with user cert */
 408
 409/*
 410 * Flags set by internal operations, but visible to the user.
 411 */
 412#define	MNT_LOCAL	0x0000000000001000ULL /* filesystem is stored locally */
 413#define	MNT_QUOTA	0x0000000000002000ULL /* quotas are enabled on fs */
 414#define	MNT_ROOTFS	0x0000000000004000ULL /* identifies the root fs */
 415#define	MNT_USER	0x0000000000008000ULL /* mounted by a user */
 416#define	MNT_IGNORE	0x0000000000800000ULL /* do not show entry in df */
 417#define	MNT_VERIFIED	0x0000000400000000ULL /* filesystem is verified */
 418
 419/*
 420 * Mask of flags that are visible to statfs().
 421 * XXX I think that this could now become (~(MNT_CMDFLAGS))
 422 * but the 'mount' program may need changing to handle this.
 423 */
 424#define	MNT_VISFLAGMASK	(MNT_RDONLY	| MNT_SYNCHRONOUS | MNT_NOEXEC	| \
 425			MNT_NOSUID	| MNT_UNION	| MNT_SUJ	| \
 426			MNT_ASYNC	| MNT_EXRDONLY	| MNT_EXPORTED	| \
 427			MNT_DEFEXPORTED	| MNT_EXPORTANON| MNT_EXKERB	| \
 428			MNT_LOCAL	| MNT_USER	| MNT_QUOTA	| \
 429			MNT_ROOTFS	| MNT_NOATIME	| MNT_NOCLUSTERR| \
 430			MNT_NOCLUSTERW	| MNT_SUIDDIR	| MNT_SOFTDEP	| \
 431			MNT_IGNORE	| MNT_EXPUBLIC	| MNT_NOSYMFOLLOW | \
 432			MNT_GJOURNAL	| MNT_MULTILABEL | MNT_ACLS	| \
 433			MNT_NFS4ACLS	| MNT_AUTOMOUNTED | MNT_VERIFIED | \
 434			MNT_UNTRUSTED)
 435
 436/* Mask of flags that can be updated. */
 437#define	MNT_UPDATEMASK (MNT_NOSUID	| MNT_NOEXEC	| \
 438			MNT_SYNCHRONOUS	| MNT_UNION	| MNT_ASYNC	| \
 439			MNT_NOATIME | \
 440			MNT_NOSYMFOLLOW	| MNT_IGNORE	| \
 441			MNT_NOCLUSTERR	| MNT_NOCLUSTERW | MNT_SUIDDIR	| \
 442			MNT_ACLS	| MNT_USER	| MNT_NFS4ACLS	| \
 443			MNT_AUTOMOUNTED | MNT_UNTRUSTED)
 444
 445/*
 446 * External filesystem command modifier flags.
 447 * Unmount can use the MNT_FORCE flag.
 448 * XXX: These are not STATES and really should be somewhere else.
 449 * XXX: MNT_BYFSID and MNT_NONBUSY collide with MNT_ACLS and MNT_MULTILABEL,
 450 *      but because MNT_ACLS and MNT_MULTILABEL are only used for mount(2),
 451 *      and MNT_BYFSID and MNT_NONBUSY are only used for unmount(2),
 452 *      it's harmless.
 453 */
 454#define	MNT_UPDATE	0x0000000000010000ULL /* not real mount, just update */
 455#define	MNT_DELEXPORT	0x0000000000020000ULL /* delete export host lists */
 456#define	MNT_RELOAD	0x0000000000040000ULL /* reload filesystem data */
 457#define	MNT_FORCE	0x0000000000080000ULL /* force unmount or readonly */
 458#define	MNT_SNAPSHOT	0x0000000001000000ULL /* snapshot the filesystem */
 459#define	MNT_NONBUSY	0x0000000004000000ULL /* check vnode use counts. */
 460#define	MNT_BYFSID	0x0000000008000000ULL /* specify filesystem by ID. */
 461#define	MNT_NOCOVER	0x0000001000000000ULL /* Do not cover a mount point */
 462#define	MNT_EMPTYDIR	0x0000002000000000ULL /* Only mount on empty dir */
 463#define	MNT_RECURSE	0x0000100000000000ULL /* recursively unmount uppers */
 464#define	MNT_DEFERRED    0x0000200000000000ULL /* unmount in async context */
 465#define	MNT_CMDFLAGS   (MNT_UPDATE	| MNT_DELEXPORT	| MNT_RELOAD	| \
 466			MNT_FORCE	| MNT_SNAPSHOT	| MNT_NONBUSY	| \
 467			MNT_BYFSID	| MNT_NOCOVER	| MNT_EMPTYDIR	| \
 468			MNT_RECURSE	| MNT_DEFERRED)
 469
 470/*
 471 * Internal filesystem control flags stored in mnt_kern_flag.
 472 *
 473 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot
 474 * proceed past the mount point.  This keeps the subtree stable during
 475 * mounts and unmounts.  When non-forced unmount flushes all vnodes
 476 * from the mp queue, the MNTK_UNMOUNT flag prevents insmntque() from
 477 * queueing new vnodes.
 478 *
 479 * MNTK_UNMOUNTF permits filesystems to detect a forced unmount while
 480 * dounmount() is still waiting to lock the mountpoint. This allows
 481 * the filesystem to cancel operations that might otherwise deadlock
 482 * with the unmount attempt (used by NFS).
 483 */
 484#define MNTK_UNMOUNTF		0x00000001 /* forced unmount in progress */
 485#define MNTK_ASYNC		0x00000002 /* filtered async flag */
 486#define MNTK_SOFTDEP		0x00000004 /* async disabled by softdep */
 487#define MNTK_NOMSYNC		0x00000008 /* don't do msync */
 488#define	MNTK_DRAINING		0x00000010 /* lock draining is happening */
 489#define	MNTK_REFEXPIRE		0x00000020 /* refcount expiring is happening */
 490#define MNTK_EXTENDED_SHARED	0x00000040 /* Allow shared locking for more ops */
 491#define	MNTK_SHARED_WRITES	0x00000080 /* Allow shared locking for writes */
 492#define	MNTK_NO_IOPF		0x00000100 /* Disallow page faults during reads
 493					      and writes. Filesystem shall
 494					      properly handle i/o state on
 495					      EFAULT. */
 496#define	MNTK_RECURSE		0x00000200 /* pending recursive unmount */
 497#define	MNTK_UPPER_WAITER	0x00000400 /* waiting to drain MNTK_UPPER_PENDING */
 498/* UNUSED 			0x00000800 */
 499#define	MNTK_UNLOCKED_INSMNTQUE	0x00001000 /* fs does not lock the vnode for
 500					      insmntque */
 501#define	MNTK_UNMAPPED_BUFS	0x00002000
 502#define	MNTK_USES_BCACHE	0x00004000 /* FS uses the buffer cache. */
 503/* UNUSED			0x00008000 */
 504#define	MNTK_VMSETSIZE_BUG	0x00010000
 505#define	MNTK_UNIONFS		0x00020000 /* A hack for F_ISUNIONSTACK */
 506#define	MNTK_FPLOOKUP		0x00040000 /* fast path lookup is supported */
 507#define	MNTK_SUSPEND_ALL	0x00080000 /* Suspended by all-fs suspension */
 508#define	MNTK_TASKQUEUE_WAITER	0x00100000 /* Waiting on unmount taskqueue */
 509/* UNUSED			0x00200000 */
 510/* UNUSED			0x00400000 */
 511#define	MNTK_NOASYNC		0x00800000 /* disable async */
 512#define	MNTK_UNMOUNT		0x01000000 /* unmount in progress */
 513#define	MNTK_MWAIT		0x02000000 /* waiting for unmount to finish */
 514#define	MNTK_SUSPEND		0x08000000 /* request write suspension */
 515#define	MNTK_SUSPEND2		0x04000000 /* block secondary writes */
 516#define	MNTK_SUSPENDED		0x10000000 /* write operations are suspended */
 517#define	MNTK_NULL_NOCACHE	0x20000000 /* auto disable cache for nullfs
 518					      mounts over this fs */
 519#define MNTK_LOOKUP_SHARED	0x40000000 /* FS supports shared lock lookups */
 520/* UNUSED			0x80000000 */
 521
 522#ifdef _KERNEL
 523static inline int
 524MNT_SHARED_WRITES(struct mount *mp)
 525{
 526
 527	return (mp != NULL && (mp->mnt_kern_flag & MNTK_SHARED_WRITES) != 0);
 528}
 529
 530static inline int
 531MNT_EXTENDED_SHARED(struct mount *mp)
 532{
 533
 534	return (mp != NULL && (mp->mnt_kern_flag & MNTK_EXTENDED_SHARED) != 0);
 535}
 536#endif
 537
 538/*
 539 * Sysctl CTL_VFS definitions.
 540 *
 541 * Second level identifier specifies which filesystem. Second level
 542 * identifier VFS_VFSCONF returns information about all filesystems.
 543 * Second level identifier VFS_GENERIC is non-terminal.
 544 */
 545#define	VFS_VFSCONF		0	/* get configured filesystems */
 546#define	VFS_GENERIC		0	/* generic filesystem information */
 547/*
 548 * Third level identifiers for VFS_GENERIC are given below; third
 549 * level identifiers for specific filesystems are given in their
 550 * mount specific header files.
 551 */
 552#define VFS_MAXTYPENUM	1	/* int: highest defined filesystem type */
 553#define VFS_CONF	2	/* struct: vfsconf for filesystem given
 554				   as next argument */
 555
 556/*
 557 * Flags for various system call interfaces.
 558 *
 559 * waitfor flags to vfs_sync() and getfsstat()
 560 */
 561#define MNT_WAIT	1	/* synchronously wait for I/O to complete */
 562#define MNT_NOWAIT	2	/* start all I/O, but do not wait for it */
 563#define MNT_LAZY	3	/* push data not written by filesystem syncer */
 564#define MNT_SUSPEND	4	/* Suspend file system after sync */
 565
 566/*
 567 * Generic file handle
 568 */
 569struct fhandle {
 570	fsid_t	fh_fsid;	/* Filesystem id of mount point */
 571	struct	fid fh_fid;	/* Filesys specific id */
 572};
 573typedef struct fhandle	fhandle_t;
 574
 575/*
 576 * Old export arguments without security flavor list
 577 */
 578struct oexport_args {
 579	int	ex_flags;		/* export related flags */
 580	uid_t	ex_root;		/* mapping for root uid */
 581	struct	xucred ex_anon;		/* mapping for anonymous user */
 582	struct	sockaddr *ex_addr;	/* net address to which exported */
 583	u_char	ex_addrlen;		/* and the net address length */
 584	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
 585	u_char	ex_masklen;		/* and the smask length */
 586	char	*ex_indexfile;		/* index file for WebNFS URLs */
 587};
 588
 589/*
 590 * Not quite so old export arguments with 32bit ex_flags and xucred ex_anon.
 591 */
 592#define	MAXSECFLAVORS	5
 593struct o2export_args {
 594	int	ex_flags;		/* export related flags */
 595	uid_t	ex_root;		/* mapping for root uid */
 596	struct	xucred ex_anon;		/* mapping for anonymous user */
 597	struct	sockaddr *ex_addr;	/* net address to which exported */
 598	u_char	ex_addrlen;		/* and the net address length */
 599	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
 600	u_char	ex_masklen;		/* and the smask length */
 601	char	*ex_indexfile;		/* index file for WebNFS URLs */
 602	int	ex_numsecflavors;	/* security flavor count */
 603	int	ex_secflavors[MAXSECFLAVORS]; /* list of security flavors */
 604};
 605
 606/*
 607 * Export arguments for local filesystem mount calls.
 608 */
 609struct export_args {
 610	uint64_t ex_flags;		/* export related flags */
 611	uid_t	ex_root;		/* mapping for root uid */
 612	uid_t	ex_uid;			/* mapping for anonymous user */
 613	int	ex_ngroups;
 614	gid_t	*ex_groups;
 615	struct	sockaddr *ex_addr;	/* net address to which exported */
 616	u_char	ex_addrlen;		/* and the net address length */
 617	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
 618	u_char	ex_masklen;		/* and the smask length */
 619	char	*ex_indexfile;		/* index file for WebNFS URLs */
 620	int	ex_numsecflavors;	/* security flavor count */
 621	int	ex_secflavors[MAXSECFLAVORS]; /* list of security flavors */
 622};
 623
 624/*
 625 * Structure holding information for a publicly exported filesystem
 626 * (WebNFS). Currently the specs allow just for one such filesystem.
 627 */
 628struct nfs_public {
 629	int		np_valid;	/* Do we hold valid information */
 630	fhandle_t	np_handle;	/* Filehandle for pub fs (internal) */
 631	struct mount	*np_mount;	/* Mountpoint of exported fs */
 632	char		*np_index;	/* Index file */
 633};
 634
 635/*
 636 * Filesystem configuration information. One of these exists for each
 637 * type of filesystem supported by the kernel. These are searched at
 638 * mount time to identify the requested filesystem.
 639 *
 640 * XXX: Never change the first two arguments!
 641 */
 642struct vfsconf {
 643	u_int	vfc_version;		/* ABI version number */
 644	char	vfc_name[MFSNAMELEN];	/* filesystem type name */
 645	struct	vfsops *vfc_vfsops;	/* filesystem operations vector */
 646	struct	vfsops *vfc_vfsops_sd;	/* ... signal-deferred */
 647	int	vfc_typenum;		/* historic filesystem type number */
 648	int	vfc_refcount;		/* number mounted of this type */
 649	int	vfc_flags;		/* permanent flags */
 650	int	vfc_prison_flag;	/* prison allow.mount.* flag */
 651	struct	vfsoptdecl *vfc_opts;	/* mount options */
 652	TAILQ_ENTRY(vfsconf) vfc_list;	/* list of vfscons */
 653};
 654
 655/* Userland version of the struct vfsconf. */
 656struct xvfsconf {
 657	struct	vfsops *vfc_vfsops;	/* filesystem operations vector */
 658	char	vfc_name[MFSNAMELEN];	/* filesystem type name */
 659	int	vfc_typenum;		/* historic filesystem type number */
 660	int	vfc_refcount;		/* number mounted of this type */
 661	int	vfc_flags;		/* permanent flags */
 662	struct	vfsconf *vfc_next;	/* next in list */
 663};
 664
 665#ifndef BURN_BRIDGES
 666struct ovfsconf {
 667	void	*vfc_vfsops;
 668	char	vfc_name[32];
 669	int	vfc_index;
 670	int	vfc_refcount;
 671	int	vfc_flags;
 672};
 673#endif
 674
 675/*
 676 * NB: these flags refer to IMPLEMENTATION properties, not properties of
 677 * any actual mounts; i.e., it does not make sense to change the flags.
 678 */
 679#define	VFCF_STATIC	0x00010000	/* statically compiled into kernel */
 680#define	VFCF_NETWORK	0x00020000	/* may get data over the network */
 681#define	VFCF_READONLY	0x00040000	/* writes are not implemented */
 682#define	VFCF_SYNTHETIC	0x00080000	/* data does not represent real files */
 683#define	VFCF_LOOPBACK	0x00100000	/* aliases some other mounted FS */
 684#define	VFCF_UNICODE	0x00200000	/* stores file names as Unicode */
 685#define	VFCF_JAIL	0x00400000	/* can be mounted from within a jail */
 686#define	VFCF_DELEGADMIN	0x00800000	/* supports delegated administration */
 687#define	VFCF_SBDRY	0x01000000	/* Stop at Boundary: defer stop requests
 688					   to kernel->user (AST) transition */
 689#define	VFCF_FILEMOUNT	0x02000000	/* allow mounting files */
 690
 691typedef uint32_t fsctlop_t;
 692
 693struct vfsidctl {
 694	int		vc_vers;	/* should be VFSIDCTL_VERS1 (below) */
 695	fsid_t		vc_fsid;	/* fsid to operate on */
 696	char		vc_fstypename[MFSNAMELEN];
 697					/* type of fs 'nfs' or '*' */
 698	fsctlop_t	vc_op;		/* operation VFS_CTL_* (below) */
 699	void		*vc_ptr;	/* pointer to data structure */
 700	size_t		vc_len;		/* sizeof said structure */
 701	u_int32_t	vc_spare[12];	/* spare (must be zero) */
 702};
 703
 704/* vfsidctl API version. */
 705#define VFS_CTL_VERS1	0x01
 706
 707/*
 708 * New style VFS sysctls, do not reuse/conflict with the namespace for
 709 * private sysctls.
 710 * All "global" sysctl ops have the 33rd bit set:
 711 * 0x...1....
 712 * Private sysctl ops should have the 33rd bit unset.
 713 */
 714#define VFS_CTL_QUERY	0x00010001	/* anything wrong? (vfsquery) */
 715#define VFS_CTL_TIMEO	0x00010002	/* set timeout for vfs notification */
 716#define VFS_CTL_NOLOCKS	0x00010003	/* disable file locking */
 717
 718struct vfsquery {
 719	u_int32_t	vq_flags;
 720	u_int32_t	vq_spare[31];
 721};
 722
 723/* vfsquery flags */
 724#define VQ_NOTRESP	0x0001	/* server down */
 725#define VQ_NEEDAUTH	0x0002	/* server bad auth */
 726#define VQ_LOWDISK	0x0004	/* we're low on space */
 727#define VQ_MOUNT	0x0008	/* new filesystem arrived */
 728#define VQ_UNMOUNT	0x0010	/* filesystem has left */
 729#define VQ_DEAD		0x0020	/* filesystem is dead, needs force unmount */
 730#define VQ_ASSIST	0x0040	/* filesystem needs assistance from external
 731				   program */
 732#define VQ_NOTRESPLOCK	0x0080	/* server lockd down */
 733#define VQ_FLAG0100	0x0100	/* placeholder */
 734#define VQ_FLAG0200	0x0200	/* placeholder */
 735#define VQ_FLAG0400	0x0400	/* placeholder */
 736#define VQ_FLAG0800	0x0800	/* placeholder */
 737#define VQ_FLAG1000	0x1000	/* placeholder */
 738#define VQ_FLAG2000	0x2000	/* placeholder */
 739#define VQ_FLAG4000	0x4000	/* placeholder */
 740#define VQ_FLAG8000	0x8000	/* placeholder */
 741
 742#ifdef _KERNEL
 743/* Point a sysctl request at a vfsidctl's data. */
 744#define VCTLTOREQ(vc, req)						\
 745	do {								\
 746		(req)->newptr = (vc)->vc_ptr;				\
 747		(req)->newlen = (vc)->vc_len;				\
 748		(req)->newidx = 0;					\
 749	} while (0)
 750#endif
 751
 752struct iovec;
 753struct uio;
 754
 755#ifdef _KERNEL
 756
 757/*
 758 * vfs_busy specific flags and mask.
 759 */
 760#define	MBF_NOWAIT	0x01
 761#define	MBF_MNTLSTLOCK	0x02
 762#define	MBF_MASK	(MBF_NOWAIT | MBF_MNTLSTLOCK)
 763
 764#ifdef MALLOC_DECLARE
 765MALLOC_DECLARE(M_MOUNT);
 766MALLOC_DECLARE(M_STATFS);
 767#endif
 768extern int maxvfsconf;		/* highest defined filesystem type */
 769
 770TAILQ_HEAD(vfsconfhead, vfsconf);
 771extern struct vfsconfhead vfsconf;
 772
 773/*
 774 * Operations supported on mounted filesystem.
 775 */
 776struct mount_args;
 777struct nameidata;
 778struct sysctl_req;
 779struct mntarg;
 780
 781/*
 782 * N.B., vfs_cmount is the ancient vfsop invoked by the old mount(2) syscall.
 783 * The new way is vfs_mount.
 784 *
 785 * vfs_cmount implementations typically translate arguments from their
 786 * respective old per-FS structures into the key-value list supported by
 787 * nmount(2), then use kernel_mount(9) to mimic nmount(2) from kernelspace.
 788 *
 789 * Filesystems with mounters that use nmount(2) do not need to and should not
 790 * implement vfs_cmount.  Hopefully a future cleanup can remove vfs_cmount and
 791 * mount(2) entirely.
 792 */
 793typedef int vfs_cmount_t(struct mntarg *ma, void *data, uint64_t flags);
 794typedef int vfs_unmount_t(struct mount *mp, int mntflags);
 795typedef int vfs_root_t(struct mount *mp, int flags, struct vnode **vpp);
 796typedef	int vfs_quotactl_t(struct mount *mp, int cmds, uid_t uid, void *arg,
 797		    bool *mp_busy);
 798typedef	int vfs_statfs_t(struct mount *mp, struct statfs *sbp);
 799typedef	int vfs_sync_t(struct mount *mp, int waitfor);
 800typedef	int vfs_vget_t(struct mount *mp, ino_t ino, int flags,
 801		    struct vnode **vpp);
 802typedef	int vfs_fhtovp_t(struct mount *mp, struct fid *fhp,
 803		    int flags, struct vnode **vpp);
 804typedef	int vfs_checkexp_t(struct mount *mp, struct sockaddr *nam,
 805		    uint64_t *extflagsp, struct ucred **credanonp,
 806		    int *numsecflavors, int *secflavors);
 807typedef	int vfs_init_t(struct vfsconf *);
 808typedef	int vfs_uninit_t(struct vfsconf *);
 809typedef	int vfs_extattrctl_t(struct mount *mp, int cmd,
 810		    struct vnode *filename_vp, int attrnamespace,
 811		    const char *attrname);
 812typedef	int vfs_mount_t(struct mount *mp);
 813typedef int vfs_sysctl_t(struct mount *mp, fsctlop_t op,
 814		    struct sysctl_req *req);
 815typedef void vfs_susp_clean_t(struct mount *mp);
 816typedef void vfs_notify_lowervp_t(struct mount *mp, struct vnode *lowervp);
 817typedef void vfs_purge_t(struct mount *mp);
 818struct sbuf;
 819typedef int vfs_report_lockf_t(struct mount *mp, struct sbuf *sb);
 820
 821struct vfsops {
 822	vfs_mount_t		*vfs_mount;
 823	vfs_cmount_t		*vfs_cmount;
 824	vfs_unmount_t		*vfs_unmount;
 825	vfs_root_t		*vfs_root;
 826	vfs_root_t		*vfs_cachedroot;
 827	vfs_quotactl_t		*vfs_quotactl;
 828	vfs_statfs_t		*vfs_statfs;
 829	vfs_sync_t		*vfs_sync;
 830	vfs_vget_t		*vfs_vget;
 831	vfs_fhtovp_t		*vfs_fhtovp;
 832	vfs_checkexp_t		*vfs_checkexp;
 833	vfs_init_t		*vfs_init;
 834	vfs_uninit_t		*vfs_uninit;
 835	vfs_extattrctl_t	*vfs_extattrctl;
 836	vfs_sysctl_t		*vfs_sysctl;
 837	vfs_susp_clean_t	*vfs_susp_clean;
 838	vfs_notify_lowervp_t	*vfs_reclaim_lowervp;
 839	vfs_notify_lowervp_t	*vfs_unlink_lowervp;
 840	vfs_purge_t		*vfs_purge;
 841	vfs_report_lockf_t	*vfs_report_lockf;
 842	vfs_mount_t		*vfs_spare[6];	/* spares for ABI compat */
 843};
 844
 845vfs_statfs_t	__vfs_statfs;
 846
 847#define	VFS_MOUNT(MP) ({						\
 848	int _rc;							\
 849									\
 850	TSRAW(curthread, TS_ENTER, "VFS_MOUNT", (MP)->mnt_vfc->vfc_name);\
 851	_rc = (*(MP)->mnt_op->vfs_mount)(MP);				\
 852	TSRAW(curthread, TS_EXIT, "VFS_MOUNT", (MP)->mnt_vfc->vfc_name);\
 853	_rc; })
 854
 855#define	VFS_UNMOUNT(MP, FORCE) ({					\
 856	int _rc;							\
 857									\
 858	_rc = (*(MP)->mnt_op->vfs_unmount)(MP, FORCE);			\
 859	_rc; })
 860
 861#define	VFS_ROOT(MP, FLAGS, VPP) ({					\
 862	int _rc;							\
 863									\
 864	_rc = (*(MP)->mnt_op->vfs_root)(MP, FLAGS, VPP);		\
 865	_rc; })
 866
 867#define	VFS_CACHEDROOT(MP, FLAGS, VPP) ({				\
 868	int _rc;							\
 869									\
 870	_rc = (*(MP)->mnt_op->vfs_cachedroot)(MP, FLAGS, VPP);		\
 871	_rc; })
 872
 873#define	VFS_QUOTACTL(MP, C, U, A, MP_BUSY) ({				\
 874	int _rc;							\
 875									\
 876	_rc = (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, MP_BUSY);	\
 877	_rc; })
 878
 879#define	VFS_STATFS(MP, SBP) ({						\
 880	int _rc;							\
 881									\
 882	_rc = __vfs_statfs((MP), (SBP));				\
 883	_rc; })
 884
 885#define	VFS_SYNC(MP, WAIT) ({						\
 886	int _rc;							\
 887									\
 888	_rc = (*(MP)->mnt_op->vfs_sync)(MP, WAIT);			\
 889	_rc; })
 890
 891#define	VFS_VGET(MP, INO, FLAGS, VPP) ({				\
 892	int _rc;							\
 893									\
 894	_rc = (*(MP)->mnt_op->vfs_vget)(MP, INO, FLAGS, VPP);		\
 895	_rc; })
 896
 897#define	VFS_FHTOVP(MP, FIDP, FLAGS, VPP) ({				\
 898	int _rc;							\
 899									\
 900	_rc = (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, FLAGS, VPP);	\
 901	_rc; })
 902
 903#define	VFS_CHECKEXP(MP, NAM, EXFLG, CRED, NUMSEC, SEC) ({		\
 904	int _rc;							\
 905									\
 906	_rc = (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED, NUMSEC,\
 907	    SEC);							\
 908	_rc; })
 909
 910#define	VFS_EXTATTRCTL(MP, C, FN, NS, N) ({				\
 911	int _rc;							\
 912									\
 913	_rc = (*(MP)->mnt_op->vfs_extattrctl)(MP, C, FN, NS, N);	\
 914	_rc; })
 915
 916#define	VFS_SYSCTL(MP, OP, REQ) ({					\
 917	int _rc;							\
 918									\
 919	_rc = (*(MP)->mnt_op->vfs_sysctl)(MP, OP, REQ);			\
 920	_rc; })
 921
 922#define	VFS_SUSP_CLEAN(MP) do {						\
 923	if (*(MP)->mnt_op->vfs_susp_clean != NULL) {			\
 924		(*(MP)->mnt_op->vfs_susp_clean)(MP);			\
 925	}								\
 926} while (0)
 927
 928#define	VFS_RECLAIM_LOWERVP(MP, VP) do {				\
 929	if (*(MP)->mnt_op->vfs_reclaim_lowervp != NULL) {		\
 930		(*(MP)->mnt_op->vfs_reclaim_lowervp)((MP), (VP));	\
 931	}								\
 932} while (0)
 933
 934#define	VFS_UNLINK_LOWERVP(MP, VP) do {					\
 935	if (*(MP)->mnt_op->vfs_unlink_lowervp != NULL) {		\
 936		(*(MP)->mnt_op->vfs_unlink_lowervp)((MP), (VP));	\
 937	}								\
 938} while (0)
 939
 940#define	VFS_PURGE(MP) do {						\
 941	if (*(MP)->mnt_op->vfs_purge != NULL) {				\
 942		(*(MP)->mnt_op->vfs_purge)(MP);				\
 943	}								\
 944} while (0)
 945
 946#define VFS_KNOTE_LOCKED(vp, hint) do					\
 947{									\
 948	VN_KNOTE((vp), (hint), KNF_LISTLOCKED);				\
 949} while (0)
 950
 951#define VFS_KNOTE_UNLOCKED(vp, hint) do					\
 952{									\
 953	VN_KNOTE((vp), (hint), 0);					\
 954} while (0)
 955
 956#include <sys/module.h>
 957
 958/*
 959 * Version numbers.
 960 */
 961#define VFS_VERSION_00	0x19660120
 962#define VFS_VERSION_01	0x20121030
 963#define VFS_VERSION_02	0x20180504
 964#define VFS_VERSION	VFS_VERSION_02
 965
 966#define VFS_SET(vfsops, fsname, flags) \
 967	static struct vfsconf fsname ## _vfsconf = {		\
 968		.vfc_version = VFS_VERSION,			\
 969		.vfc_name = #fsname,				\
 970		.vfc_vfsops = &vfsops,				\
 971		.vfc_typenum = -1,				\
 972		.vfc_flags = flags,				\
 973	};							\
 974	static moduledata_t fsname ## _mod = {			\
 975		#fsname,					\
 976		vfs_modevent,					\
 977		& fsname ## _vfsconf				\
 978	};							\
 979	DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE)
 980
 981enum vfs_notify_upper_type {
 982	VFS_NOTIFY_UPPER_RECLAIM,
 983	VFS_NOTIFY_UPPER_UNLINK,
 984};
 985
 986/*
 987 * exported vnode operations
 988 */
 989
 990/* Define this to indicate that vfs_exjail_clone() exists for ZFS to use. */
 991#define	VFS_SUPPORTS_EXJAIL_CLONE	1
 992
 993int	dounmount(struct mount *, uint64_t, struct thread *);
 994
 995int	kernel_mount(struct mntarg *ma, uint64_t flags);
 996struct mntarg *mount_arg(struct mntarg *ma, const char *name, const void *val, int len);
 997struct mntarg *mount_argb(struct mntarg *ma, int flag, const char *name);
 998struct mntarg *mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...);
 999struct mntarg *mount_argsu(struct mntarg *ma, const char *name, const void *val, int len);
1000void	statfs_scale_blocks(struct statfs *sf, long max_size);
1001struct vfsconf *vfs_byname(const char *);
1002struct vfsconf *vfs_byname_kld(const char *, struct thread *td, int *);
1003void	vfs_mount_destroy(struct mount *);
1004void	vfs_event_signal(fsid_t *, u_int32_t, intptr_t);
1005void	vfs_freeopts(struct vfsoptlist *opts);
1006void	vfs_deleteopt(struct vfsoptlist *opts, const char *name);
1007int	vfs_buildopts(struct uio *auio, struct vfsoptlist **options);
1008int	vfs_flagopt(struct vfsoptlist *opts, const char *name, uint64_t *w,
1009	    uint64_t val);
1010int	vfs_getopt(struct vfsoptlist *, const char *, void **, int *);
1011int	vfs_getopt_pos(struct vfsoptlist *opts, const char *name);
1012int	vfs_getopt_size(struct vfsoptlist *opts, const char *name,
1013	    off_t *value);
1014char	*vfs_getopts(struct vfsoptlist *, const char *, int *error);
1015int	vfs_copyopt(struct vfsoptlist *, const char *, void *, int);
1016int	vfs_filteropt(struct vfsoptlist *, const char **legal);
1017void	vfs_opterror(struct vfsoptlist *opts, const char *fmt, ...);
1018int	vfs_scanopt(struct vfsoptlist *opts, const char *name, const char *fmt, ...);
1019int	vfs_setopt(struct vfsoptlist *opts, const char *name, void *value,
1020	    int len);
1021int	vfs_setopt_part(struct vfsoptlist *opts, const char *name, void *value,
1022	    int len);
1023int	vfs_setopts(struct vfsoptlist *opts, const char *name,
1024	    const char *value);
1025int	vfs_setpublicfs			    /* set publicly exported fs */
1026	    (struct mount *, struct netexport *, struct export_args *);
1027void	vfs_periodic(struct mount *, int);
1028int	vfs_busy(struct mount *, int);
1029void	vfs_exjail_clone(struct mount *, struct mount *);
1030void	vfs_exjail_delete(struct prison *);
1031int	vfs_export			 /* process mount export info */
1032	    (struct mount *, struct export_args *, bool);
1033void	vfs_free_addrlist(struct netexport *);
1034void	vfs_allocate_syncvnode(struct mount *);
1035void	vfs_deallocate_syncvnode(struct mount *);
1036int	vfs_donmount(struct thread *td, uint64_t fsflags,
1037	    struct uio *fsoptions);
1038void	vfs_getnewfsid(struct mount *);
1039struct	mount *vfs_getvfs(fsid_t *);      /* return vfs given fsid */
1040struct	mount *vfs_busyfs(fsid_t *);
1041int	vfs_modevent(module_t, int, void *);
1042void	vfs_mount_error(struct mount *, const char *, ...);
1043void	vfs_mountroot(void);			/* mount our root filesystem */
1044void	vfs_mountedfrom(struct mount *, const char *from);
1045void	vfs_notify_upper(struct vnode *, enum vfs_notify_upper_type);
1046struct mount *vfs_ref_from_vp(struct vnode *);
1047void	vfs_ref(struct mount *);
1048void	vfs_rel(struct mount *);
1049struct mount *vfs_mount_alloc(struct vnode *, struct vfsconf *, const char *,
1050	    struct ucred *);
1051int	vfs_suser(struct mount *, struct thread *);
1052void	vfs_unbusy(struct mount *);
1053void	vfs_unmountall(void);
1054struct mount *vfs_register_upper_from_vp(struct vnode *,
1055	    struct mount *ump, struct mount_upper_node *);
1056void	vfs_register_for_notification(struct mount *, struct mount *,
1057	    struct mount_upper_node *);
1058void	vfs_unregister_for_notification(struct mount *,
1059	    struct mount_upper_node *);
1060void	vfs_unregister_upper(struct mount *, struct mount_upper_node *);
1061int	vfs_remount_ro(struct mount *mp);
1062int	vfs_report_lockf(struct mount *mp, struct sbuf *sb);
1063
1064extern	TAILQ_HEAD(mntlist, mount) mountlist;	/* mounted filesystem list */
1065extern	struct mtx_padalign mountlist_mtx;
1066extern	struct nfs_public nfs_pub;
1067extern	struct sx vfsconf_sx;
1068#define	vfsconf_lock()		sx_xlock(&vfsconf_sx)
1069#define	vfsconf_unlock()	sx_xunlock(&vfsconf_sx)
1070#define	vfsconf_slock()		sx_slock(&vfsconf_sx)
1071#define	vfsconf_sunlock()	sx_sunlock(&vfsconf_sx)
1072struct vnode *mntfs_allocvp(struct mount *, struct vnode *);
1073void   mntfs_freevp(struct vnode *);
1074
1075/*
1076 * Declarations for these vfs default operations are located in
1077 * kern/vfs_default.c.  They will be automatically used to replace
1078 * null entries in VFS ops tables when registering a new filesystem
1079 * type in the global table.
1080 */
1081vfs_root_t		vfs_stdroot;
1082vfs_quotactl_t		vfs_stdquotactl;
1083vfs_statfs_t		vfs_stdstatfs;
1084vfs_sync_t		vfs_stdsync;
1085vfs_sync_t		vfs_stdnosync;
1086vfs_vget_t		vfs_stdvget;
1087vfs_fhtovp_t		vfs_stdfhtovp;
1088vfs_checkexp_t		vfs_stdcheckexp;
1089vfs_init_t		vfs_stdinit;
1090vfs_uninit_t		vfs_stduninit;
1091vfs_extattrctl_t	vfs_stdextattrctl;
1092vfs_sysctl_t		vfs_stdsysctl;
1093
1094void	syncer_suspend(void);
1095void	syncer_resume(void);
1096
1097struct vnode *vfs_cache_root_clear(struct mount *);
1098void	vfs_cache_root_set(struct mount *, struct vnode *);
1099
1100void	vfs_op_barrier_wait(struct mount *);
1101void	vfs_op_enter(struct mount *);
1102void	vfs_op_exit_locked(struct mount *);
1103void	vfs_op_exit(struct mount *);
1104
1105#ifdef DIAGNOSTIC
1106void	vfs_assert_mount_counters(struct mount *);
1107void	vfs_dump_mount_counters(struct mount *);
1108#else
1109#define vfs_assert_mount_counters(mp) do { } while (0)
1110#define vfs_dump_mount_counters(mp) do { } while (0)
1111#endif
1112
1113enum mount_counter { MNT_COUNT_REF, MNT_COUNT_LOCKREF, MNT_COUNT_WRITEOPCOUNT };
1114int	vfs_mount_fetch_counter(struct mount *, enum mount_counter);
1115
1116void suspend_all_fs(void);
1117void resume_all_fs(void);
1118
1119/*
1120 * Code transitioning mnt_vfs_ops to > 0 issues IPIs until it observes
1121 * all CPUs not executing code enclosed by thread_in_ops_pcpu variable.
1122 *
1123 * This provides an invariant that by the time the last CPU is observed not
1124 * executing, everyone else entering will see the counter > 0 and exit.
1125 *
1126 * Note there is no barrier between vfs_ops and the rest of the code in the
1127 * section. It is not necessary as the writer has to wait for everyone to drain
1128 * before making any changes or only make changes safe while the section is
1129 * executed.
1130 */
1131#define	vfs_mount_pcpu(mp)		zpcpu_get(mp->mnt_pcpu)
1132#define	vfs_mount_pcpu_remote(mp, cpu)	zpcpu_get_cpu(mp->mnt_pcpu, cpu)
1133
1134#define vfs_op_thread_entered(mp) ({				\
1135	MPASS(curthread->td_critnest > 0);			\
1136	struct mount_pcpu *_mpcpu = vfs_mount_pcpu(mp);		\
1137	_mpcpu->mntp_thread_in_ops == 1;			\
1138})
1139
1140#define vfs_op_thread_enter_crit(mp, _mpcpu) ({			\
1141	bool _retval_crit = true;				\
1142	MPASS(curthread->td_critnest > 0);			\
1143	_mpcpu = vfs_mount_pcpu(mp);				\
1144	MPASS(mpcpu->mntp_thread_in_ops == 0);			\
1145	_mpcpu->mntp_thread_in_ops = 1;				\
1146	atomic_interrupt_fence();					\
1147	if (__predict_false(mp->mnt_vfs_ops > 0)) {		\
1148		vfs_op_thread_exit_crit(mp, _mpcpu);		\
1149		_retval_crit = false;				\
1150	}							\
1151	_retval_crit;						\
1152})
1153
1154#define vfs_op_thread_enter(mp, _mpcpu) ({			\
1155	bool _retval;						\
1156	critical_enter();					\
1157	_retval = vfs_op_thread_enter_crit(mp, _mpcpu);		\
1158	if (__predict_false(!_retval))				\
1159		critical_exit();				\
1160	_retval;						\
1161})
1162
1163#define vfs_op_thread_exit_crit(mp, _mpcpu) do {		\
1164	MPASS(_mpcpu == vfs_mount_pcpu(mp));			\
1165	MPASS(_mpcpu->mntp_thread_in_ops == 1);			\
1166	atomic_interrupt_fence();					\
1167	_mpcpu->mntp_thread_in_ops = 0;				\
1168} while (0)
1169
1170#define vfs_op_thread_exit(mp, _mpcpu) do {			\
1171	vfs_op_thread_exit_crit(mp, _mpcpu);			\
1172	critical_exit();					\
1173} while (0)
1174
1175#define vfs_mp_count_add_pcpu(_mpcpu, count, val) do {		\
1176	MPASS(_mpcpu->mntp_thread_in_ops == 1);			\
1177	_mpcpu->mntp_##count += val;				\
1178} while (0)
1179
1180#define vfs_mp_count_sub_pcpu(_mpcpu, count, val) do {		\
1181	MPASS(_mpcpu->mntp_thread_in_ops == 1);			\
1182	_mpcpu->mntp_##count -= val;				\
1183} while (0)
1184
1185#else /* !_KERNEL */
1186
1187#include <sys/cdefs.h>
1188
1189struct stat;
1190
1191__BEGIN_DECLS
1192int	fhlink(struct fhandle *, const char *);
1193int	fhlinkat(struct fhandle *, int, const char *);
1194int	fhopen(const struct fhandle *, int);
1195int	fhreadlink(struct fhandle *, char *, size_t);
1196int	fhstat(const struct fhandle *, struct stat *);
1197int	fhstatfs(const struct fhandle *, struct statfs *);
1198int	fstatfs(int, struct statfs *);
1199int	getfh(const char *, fhandle_t *);
1200int	getfhat(int, char *, struct fhandle *, int);
1201int	getfsstat(struct statfs *, long, int);
1202int	getmntinfo(struct statfs **, int);
1203int	lgetfh(const char *, fhandle_t *);
1204int	mount(const char *, const char *, int, void *);
1205int	nmount(struct iovec *, unsigned int, int);
1206int	statfs(const char *, struct statfs *);
1207int	unmount(const char *, int);
1208
1209/* C library stuff */
1210int	getvfsbyname(const char *, struct xvfsconf *);
1211__END_DECLS
1212
1213#endif /* _KERNEL */
1214
1215#endif /* !_SYS_MOUNT_H_ */