xref: /onnv-gate/usr/src/uts/common/sys/vfs.h (revision 13147:5f70b43d6386)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51488Srsb  * Common Development and Distribution License (the "License").
61488Srsb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
2212633Sjohn.levon@sun.com  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
260Sstevel@tonic-gate /*	  All Rights Reserved  	*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
300Sstevel@tonic-gate  * under license from the Regents of the University of California.
310Sstevel@tonic-gate  */
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #ifndef _SYS_VFS_H
340Sstevel@tonic-gate #define	_SYS_VFS_H
350Sstevel@tonic-gate 
3613096SJordan.Vaughan@Sun.com #include <sys/zone.h>
370Sstevel@tonic-gate #include <sys/types.h>
380Sstevel@tonic-gate #include <sys/t_lock.h>
390Sstevel@tonic-gate #include <sys/cred.h>
400Sstevel@tonic-gate #include <sys/vnode.h>
410Sstevel@tonic-gate #include <sys/statvfs.h>
420Sstevel@tonic-gate #include <sys/refstr.h>
431925Srsb #include <sys/avl.h>
4410910SRobert.Harris@Sun.COM #include <sys/time.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #ifdef	__cplusplus
470Sstevel@tonic-gate extern "C" {
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate /*
510Sstevel@tonic-gate  * Data associated with mounted file systems.
520Sstevel@tonic-gate  */
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate  * Operations vector.  This is used internal to the kernel; file systems
560Sstevel@tonic-gate  * supply their list of operations via vfs_setfsops().
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate 
590Sstevel@tonic-gate typedef struct vfsops vfsops_t;
600Sstevel@tonic-gate 
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate  * File system identifier. Should be unique (at least per machine).
630Sstevel@tonic-gate  */
640Sstevel@tonic-gate typedef struct {
650Sstevel@tonic-gate 	int val[2];			/* file system id type */
660Sstevel@tonic-gate } fsid_t;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate  * File identifier.  Should be unique per filesystem on a single
700Sstevel@tonic-gate  * machine.  This is typically called by a stateless file server
710Sstevel@tonic-gate  * in order to generate "file handles".
720Sstevel@tonic-gate  *
730Sstevel@tonic-gate  * Do not change the definition of struct fid ... fid_t without
740Sstevel@tonic-gate  * letting the CacheFS group know about it!  They will have to do at
750Sstevel@tonic-gate  * least two things, in the same change that changes this structure:
760Sstevel@tonic-gate  *   1. change CFSVERSION in usr/src/uts/common/sys/fs/cachefs_fs.h
770Sstevel@tonic-gate  *   2. put the old version # in the canupgrade array
780Sstevel@tonic-gate  *	in cachfs_upgrade() in usr/src/cmd/fs.d/cachefs/fsck/fsck.c
790Sstevel@tonic-gate  * This is necessary because CacheFS stores FIDs on disk.
800Sstevel@tonic-gate  *
810Sstevel@tonic-gate  * Many underlying file systems cast a struct fid into other
820Sstevel@tonic-gate  * file system dependent structures which may require 4 byte alignment.
830Sstevel@tonic-gate  * Because a fid starts with a short it may not be 4 byte aligned, the
840Sstevel@tonic-gate  * fid_pad will force the alignment.
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate #define	MAXFIDSZ	64
870Sstevel@tonic-gate #define	OLD_MAXFIDSZ	16
880Sstevel@tonic-gate 
890Sstevel@tonic-gate typedef struct fid {
900Sstevel@tonic-gate 	union {
910Sstevel@tonic-gate 		long fid_pad;
920Sstevel@tonic-gate 		struct {
930Sstevel@tonic-gate 			ushort_t len;	/* length of data in bytes */
940Sstevel@tonic-gate 			char	data[MAXFIDSZ]; /* data (variable len) */
950Sstevel@tonic-gate 		} _fid;
960Sstevel@tonic-gate 	} un;
970Sstevel@tonic-gate } fid_t;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate #ifdef _SYSCALL32
1000Sstevel@tonic-gate /*
1010Sstevel@tonic-gate  * Solaris 64 - use old-style cache format with 32-bit aligned fid for on-disk
1020Sstevel@tonic-gate  * struct compatibility.
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate typedef struct fid32 {
1050Sstevel@tonic-gate 	union {
1060Sstevel@tonic-gate 		int32_t fid_pad;
1070Sstevel@tonic-gate 		struct {
1080Sstevel@tonic-gate 			uint16_t  len;   /* length of data in bytes */
1090Sstevel@tonic-gate 			char    data[MAXFIDSZ]; /* data (variable len) */
1100Sstevel@tonic-gate 		} _fid;
1110Sstevel@tonic-gate 	} un;
1120Sstevel@tonic-gate } fid32_t;
1130Sstevel@tonic-gate #else /* not _SYSCALL32 */
1140Sstevel@tonic-gate #define	fid32	fid
1150Sstevel@tonic-gate typedef fid_t	fid32_t;
1160Sstevel@tonic-gate #endif /* _SYSCALL32 */
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate #define	fid_len		un._fid.len
1190Sstevel@tonic-gate #define	fid_data	un._fid.data
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate  * Structure defining a mount option for a filesystem.
1230Sstevel@tonic-gate  * option names are found in mntent.h
1240Sstevel@tonic-gate  */
1250Sstevel@tonic-gate typedef struct mntopt {
1260Sstevel@tonic-gate 	char	*mo_name;	/* option name */
1270Sstevel@tonic-gate 	char	**mo_cancel;	/* list of options cancelled by this one */
1280Sstevel@tonic-gate 	char	*mo_arg;	/* argument string for this option */
1290Sstevel@tonic-gate 	int	mo_flags;	/* flags for this mount option */
1300Sstevel@tonic-gate 	void	*mo_data;	/* filesystem specific data */
1310Sstevel@tonic-gate } mntopt_t;
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate /*
1340Sstevel@tonic-gate  * Flags that apply to mount options
1350Sstevel@tonic-gate  */
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate #define	MO_SET		0x01		/* option is set */
1380Sstevel@tonic-gate #define	MO_NODISPLAY	0x02		/* option not listed in mnttab */
1390Sstevel@tonic-gate #define	MO_HASVALUE	0x04		/* option takes a value */
1400Sstevel@tonic-gate #define	MO_IGNORE	0x08		/* option ignored by parser */
1410Sstevel@tonic-gate #define	MO_DEFAULT	MO_SET		/* option is on by default */
1420Sstevel@tonic-gate #define	MO_TAG		0x10		/* flags a tag set by user program */
1430Sstevel@tonic-gate #define	MO_EMPTY	0x20		/* empty space in option table */
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate #define	VFS_NOFORCEOPT	0x01		/* honor MO_IGNORE (don't set option) */
1460Sstevel@tonic-gate #define	VFS_DISPLAY	0x02		/* Turn off MO_NODISPLAY bit for opt */
1470Sstevel@tonic-gate #define	VFS_NODISPLAY	0x04		/* Turn on MO_NODISPLAY bit for opt */
1480Sstevel@tonic-gate #define	VFS_CREATEOPT	0x08		/* Create the opt if it's not there */
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * Structure holding mount option strings for the mounted file system.
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate typedef struct mntopts {
1540Sstevel@tonic-gate 	uint_t		mo_count;		/* number of entries in table */
1550Sstevel@tonic-gate 	mntopt_t	*mo_list;		/* list of mount options */
1560Sstevel@tonic-gate } mntopts_t;
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate /*
1591488Srsb  * The kstat structures associated with the vopstats are kept in an
1601488Srsb  * AVL tree.  This is to avoid the case where a file system does not
1611488Srsb  * use a unique fsid_t for each vfs (e.g., namefs).  In order to do
1621488Srsb  * this, we need a structure that the AVL tree can use that also
1631488Srsb  * references the kstat.
1641488Srsb  * Note that the vks_fsid is generated from the value reported by
1651488Srsb  * VFS_STATVFS().
1661488Srsb  */
1671488Srsb typedef struct vskstat_anchor {
1681488Srsb 	avl_node_t	vsk_node;	/* Required for use by AVL routines */
1691488Srsb 	kstat_t		*vsk_ksp;	/* kstat structure for vopstats */
1701488Srsb 	ulong_t		vsk_fsid;	/* fsid associated w/this FS */
1711488Srsb } vsk_anchor_t;
1721488Srsb 
1731488Srsb extern avl_tree_t	vskstat_tree;
1741488Srsb extern kmutex_t		vskstat_tree_lock;
1751488Srsb 
1761488Srsb /*
1770Sstevel@tonic-gate  * Structure per mounted file system.  Each mounted file system has
1780Sstevel@tonic-gate  * an array of operations and an instance record.
1790Sstevel@tonic-gate  *
1800Sstevel@tonic-gate  * The file systems are kept on a doubly linked circular list headed by
1810Sstevel@tonic-gate  * "rootvfs".
1820Sstevel@tonic-gate  * File system implementations should not access this list;
1830Sstevel@tonic-gate  * it's intended for use only in the kernel's vfs layer.
1840Sstevel@tonic-gate  *
1850Sstevel@tonic-gate  * Each zone also has its own list of mounts, containing filesystems mounted
1860Sstevel@tonic-gate  * somewhere within the filesystem tree rooted at the zone's rootpath.  The
1870Sstevel@tonic-gate  * list is doubly linked to match the global list.
1880Sstevel@tonic-gate  *
1890Sstevel@tonic-gate  * mnttab locking: the in-kernel mnttab uses the vfs_mntpt, vfs_resource and
1900Sstevel@tonic-gate  * vfs_mntopts fields in the vfs_t. mntpt and resource are refstr_ts that
1910Sstevel@tonic-gate  * are set at mount time and can only be modified during a remount.
1920Sstevel@tonic-gate  * It is safe to read these fields if you can prevent a remount on the vfs,
1930Sstevel@tonic-gate  * or through the convenience funcs vfs_getmntpoint() and vfs_getresource().
1940Sstevel@tonic-gate  * The mntopts field may only be accessed through the provided convenience
1950Sstevel@tonic-gate  * functions, as it is protected by the vfs list lock. Modifying a mount
1960Sstevel@tonic-gate  * option requires grabbing the vfs list write lock, which can be a very
1970Sstevel@tonic-gate  * high latency lock.
1980Sstevel@tonic-gate  */
1990Sstevel@tonic-gate struct zone;		/* from zone.h */
2000Sstevel@tonic-gate struct fem_head;	/* from fem.h */
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate typedef struct vfs {
2030Sstevel@tonic-gate 	struct vfs	*vfs_next;		/* next VFS in VFS list */
2040Sstevel@tonic-gate 	struct vfs	*vfs_prev;		/* prev VFS in VFS list */
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate /* vfs_op should not be used directly.  Accessor functions are provided */
2070Sstevel@tonic-gate 	vfsops_t	*vfs_op;		/* operations on VFS */
2080Sstevel@tonic-gate 
2090Sstevel@tonic-gate 	struct vnode	*vfs_vnodecovered;	/* vnode mounted on */
2100Sstevel@tonic-gate 	uint_t		vfs_flag;		/* flags */
2110Sstevel@tonic-gate 	uint_t		vfs_bsize;		/* native block size */
2120Sstevel@tonic-gate 	int		vfs_fstype;		/* file system type index */
2130Sstevel@tonic-gate 	fsid_t		vfs_fsid;		/* file system id */
2140Sstevel@tonic-gate 	void		*vfs_data;		/* private data */
2150Sstevel@tonic-gate 	dev_t		vfs_dev;		/* device of mounted VFS */
2160Sstevel@tonic-gate 	ulong_t		vfs_bcount;		/* I/O count (accounting) */
2170Sstevel@tonic-gate 	struct vfs	*vfs_list;		/* sync list pointer */
2180Sstevel@tonic-gate 	struct vfs	*vfs_hash;		/* hash list pointer */
2190Sstevel@tonic-gate 	ksema_t		vfs_reflock;		/* mount/unmount/sync lock */
2200Sstevel@tonic-gate 	uint_t		vfs_count;		/* vfs reference count */
2210Sstevel@tonic-gate 	mntopts_t	vfs_mntopts;		/* options mounted with */
2220Sstevel@tonic-gate 	refstr_t	*vfs_resource;		/* mounted resource name */
2230Sstevel@tonic-gate 	refstr_t	*vfs_mntpt;		/* mount point name */
2240Sstevel@tonic-gate 	time_t		vfs_mtime;		/* time we were mounted */
22513096SJordan.Vaughan@Sun.com 	struct vfs_impl	*vfs_implp;		/* impl specific data */
2260Sstevel@tonic-gate 	/*
2270Sstevel@tonic-gate 	 * Zones support.  Note that the zone that "owns" the mount isn't
2280Sstevel@tonic-gate 	 * necessarily the same as the zone in which the zone is visible.
2290Sstevel@tonic-gate 	 * That is, vfs_zone and (vfs_zone_next|vfs_zone_prev) may refer to
2300Sstevel@tonic-gate 	 * different zones.
2310Sstevel@tonic-gate 	 */
2320Sstevel@tonic-gate 	struct zone	*vfs_zone;		/* zone that owns the mount */
2330Sstevel@tonic-gate 	struct vfs	*vfs_zone_next;		/* next VFS visible in zone */
2340Sstevel@tonic-gate 	struct vfs	*vfs_zone_prev;		/* prev VFS visible in zone */
2356734Sjohnlev 
2365331Samw 	struct fem_head	*vfs_femhead;		/* fs monitoring */
2376734Sjohnlev 	minor_t		vfs_lofi_minor;		/* minor if lofi mount */
2380Sstevel@tonic-gate } vfs_t;
2390Sstevel@tonic-gate 
2405331Samw #define	vfs_featureset	vfs_implp->vi_featureset
2411925Srsb #define	vfs_vskap	vfs_implp->vi_vskap
2421925Srsb #define	vfs_fstypevsp	vfs_implp->vi_fstypevsp
2431925Srsb #define	vfs_vopstats	vfs_implp->vi_vopstats
24410910SRobert.Harris@Sun.COM #define	vfs_hrctime	vfs_implp->vi_hrctime
2451925Srsb 
2460Sstevel@tonic-gate /*
2470Sstevel@tonic-gate  * VFS flags.
2480Sstevel@tonic-gate  */
2490Sstevel@tonic-gate #define	VFS_RDONLY	0x01		/* read-only vfs */
2500Sstevel@tonic-gate #define	VFS_NOMNTTAB	0x02		/* vfs not seen in mnttab */
2510Sstevel@tonic-gate #define	VFS_NOSETUID	0x08		/* setuid disallowed */
2520Sstevel@tonic-gate #define	VFS_REMOUNT	0x10		/* modify mount options only */
2530Sstevel@tonic-gate #define	VFS_NOTRUNC	0x20		/* does not truncate long file names */
2540Sstevel@tonic-gate #define	VFS_UNLINKABLE	0x40		/* unlink(2) can be applied to root */
2550Sstevel@tonic-gate #define	VFS_PXFS	0x80		/* clustering: global fs proxy vfs */
2560Sstevel@tonic-gate #define	VFS_UNMOUNTED	0x100		/* file system has been unmounted */
2570Sstevel@tonic-gate #define	VFS_NBMAND	0x200		/* allow non-blocking mandatory locks */
2580Sstevel@tonic-gate #define	VFS_XATTR	0x400		/* fs supports extended attributes */
2590Sstevel@tonic-gate #define	VFS_NODEVICES	0x800		/* device-special files disallowed */
2600Sstevel@tonic-gate #define	VFS_NOEXEC	0x1000		/* executables disallowed */
2611488Srsb #define	VFS_STATS	0x2000		/* file system can collect stats */
2624321Scasper #define	VFS_XID		0x4000		/* file system supports extended ids */
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate #define	VFS_NORESOURCE	"unspecified_resource"
2650Sstevel@tonic-gate #define	VFS_NOMNTPT	"unspecified_mountpoint"
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /*
2685331Samw  * VFS features are implemented as bits set in the vfs_t.
2695331Samw  * The vfs_feature_t typedef is a 64-bit number that will translate
2705331Samw  * into an element in an array of bitmaps and a bit in that element.
2715331Samw  * Developers must not depend on the implementation of this and
2725331Samw  * need to use vfs_has_feature()/vfs_set_feature() routines.
2735331Samw  */
2745331Samw typedef	uint64_t	vfs_feature_t;
2755331Samw 
2765331Samw #define	VFSFT_XVATTR		0x100000001	/* Supports xvattr for attrs */
2775331Samw #define	VFSFT_CASEINSENSITIVE	0x100000002	/* Supports case-insensitive */
2785331Samw #define	VFSFT_NOCASESENSITIVE	0x100000004	/* NOT case-sensitive */
2795331Samw #define	VFSFT_DIRENTFLAGS	0x100000008	/* Supports dirent flags */
2805331Samw #define	VFSFT_ACLONCREATE	0x100000010	/* Supports ACL on create */
2815331Samw #define	VFSFT_ACEMASKONACCESS	0x100000020	/* Can use ACEMASK for access */
2827757SJanice.Chang@Sun.COM #define	VFSFT_SYSATTR_VIEWS	0x100000040	/* Supports sysattr view i/f */
2839749STim.Haley@Sun.COM #define	VFSFT_ACCESS_FILTER	0x100000080	/* dirents filtered by access */
28410793Sdai.ngo@sun.com #define	VFSFT_REPARSE		0x100000100	/* Supports reparse point */
28511539SChunli.Zhang@Sun.COM #define	VFSFT_ZEROCOPY_SUPPORTED	0x100000200
28611539SChunli.Zhang@Sun.COM 				/* Support loaning /returning cache buffer */
2875331Samw /*
2880Sstevel@tonic-gate  * Argument structure for mount(2).
2890Sstevel@tonic-gate  *
2900Sstevel@tonic-gate  * Flags are defined in <sys/mount.h>.
2910Sstevel@tonic-gate  *
2920Sstevel@tonic-gate  * Note that if the MS_SYSSPACE bit is set in flags, the pointer fields in
2930Sstevel@tonic-gate  * this structure are to be interpreted as kernel addresses.  File systems
2940Sstevel@tonic-gate  * should be prepared for this possibility.
2950Sstevel@tonic-gate  */
2960Sstevel@tonic-gate struct mounta {
2970Sstevel@tonic-gate 	char	*spec;
2980Sstevel@tonic-gate 	char	*dir;
2990Sstevel@tonic-gate 	int	flags;
3000Sstevel@tonic-gate 	char	*fstype;
3010Sstevel@tonic-gate 	char	*dataptr;
3020Sstevel@tonic-gate 	int	datalen;
3030Sstevel@tonic-gate 	char	*optptr;
3040Sstevel@tonic-gate 	int	optlen;
3050Sstevel@tonic-gate };
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate /*
3080Sstevel@tonic-gate  * Reasons for calling the vfs_mountroot() operation.
3090Sstevel@tonic-gate  */
3100Sstevel@tonic-gate enum whymountroot { ROOT_INIT, ROOT_REMOUNT, ROOT_UNMOUNT};
3110Sstevel@tonic-gate typedef enum whymountroot whymountroot_t;
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate /*
3140Sstevel@tonic-gate  * Reasons for calling the VFS_VNSTATE():
3150Sstevel@tonic-gate  */
3160Sstevel@tonic-gate enum vntrans {
3170Sstevel@tonic-gate 	VNTRANS_EXISTS,
3180Sstevel@tonic-gate 	VNTRANS_IDLED,
3190Sstevel@tonic-gate 	VNTRANS_RECLAIMED,
3200Sstevel@tonic-gate 	VNTRANS_DESTROYED
3210Sstevel@tonic-gate };
3220Sstevel@tonic-gate typedef enum vntrans vntrans_t;
3230Sstevel@tonic-gate 
3243898Srsb /*
3253898Srsb  * VFS_OPS defines all the vfs operations.  It is used to define
3263898Srsb  * the vfsops structure (below) and the fs_func_p union (vfs_opreg.h).
3273898Srsb  */
3283898Srsb #define	VFS_OPS								\
3293898Srsb 	int	(*vfs_mount)(vfs_t *, vnode_t *, struct mounta *, cred_t *); \
3303898Srsb 	int	(*vfs_unmount)(vfs_t *, int, cred_t *);			\
3313898Srsb 	int	(*vfs_root)(vfs_t *, vnode_t **);			\
3323898Srsb 	int	(*vfs_statvfs)(vfs_t *, statvfs64_t *);			\
3333898Srsb 	int	(*vfs_sync)(vfs_t *, short, cred_t *);			\
3343898Srsb 	int	(*vfs_vget)(vfs_t *, vnode_t **, fid_t *);		\
3353898Srsb 	int	(*vfs_mountroot)(vfs_t *, enum whymountroot);		\
3363898Srsb 	void	(*vfs_freevfs)(vfs_t *);				\
3373898Srsb 	int	(*vfs_vnstate)(vfs_t *, vnode_t *, vntrans_t)	/* NB: No ";" */
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate /*
3400Sstevel@tonic-gate  * Operations supported on virtual file system.
3410Sstevel@tonic-gate  */
3420Sstevel@tonic-gate struct vfsops {
3433898Srsb 	VFS_OPS;	/* Signature of all vfs operations (vfsops) */
3440Sstevel@tonic-gate };
3450Sstevel@tonic-gate 
3460Sstevel@tonic-gate extern int	fsop_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *);
3470Sstevel@tonic-gate extern int	fsop_unmount(vfs_t *, int, cred_t *);
3480Sstevel@tonic-gate extern int	fsop_root(vfs_t *, vnode_t **);
3490Sstevel@tonic-gate extern int	fsop_statfs(vfs_t *, statvfs64_t *);
3500Sstevel@tonic-gate extern int	fsop_sync(vfs_t *, short, cred_t *);
3510Sstevel@tonic-gate extern int	fsop_vget(vfs_t *, vnode_t **, fid_t *);
3520Sstevel@tonic-gate extern int	fsop_mountroot(vfs_t *, enum whymountroot);
3530Sstevel@tonic-gate extern void	fsop_freefs(vfs_t *);
3540Sstevel@tonic-gate extern int	fsop_sync_by_kind(int, short, cred_t *);
3550Sstevel@tonic-gate extern int	fsop_vnstate(vfs_t *, vnode_t *, vntrans_t);
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate #define	VFS_MOUNT(vfsp, mvp, uap, cr) fsop_mount(vfsp, mvp, uap, cr)
3580Sstevel@tonic-gate #define	VFS_UNMOUNT(vfsp, flag, cr) fsop_unmount(vfsp, flag, cr)
3590Sstevel@tonic-gate #define	VFS_ROOT(vfsp, vpp) fsop_root(vfsp, vpp)
3600Sstevel@tonic-gate #define	VFS_STATVFS(vfsp, sp) fsop_statfs(vfsp, sp)
3610Sstevel@tonic-gate #define	VFS_SYNC(vfsp, flag, cr) fsop_sync(vfsp, flag, cr)
3620Sstevel@tonic-gate #define	VFS_VGET(vfsp, vpp, fidp) fsop_vget(vfsp, vpp, fidp)
3630Sstevel@tonic-gate #define	VFS_MOUNTROOT(vfsp, init) fsop_mountroot(vfsp, init)
3640Sstevel@tonic-gate #define	VFS_FREEVFS(vfsp) fsop_freefs(vfsp)
3650Sstevel@tonic-gate #define	VFS_VNSTATE(vfsp, vn, ns)	fsop_vnstate(vfsp, vn, ns)
3660Sstevel@tonic-gate 
3670Sstevel@tonic-gate #define	VFSNAME_MOUNT		"mount"
3680Sstevel@tonic-gate #define	VFSNAME_UNMOUNT		"unmount"
3690Sstevel@tonic-gate #define	VFSNAME_ROOT		"root"
3700Sstevel@tonic-gate #define	VFSNAME_STATVFS		"statvfs"
3710Sstevel@tonic-gate #define	VFSNAME_SYNC		"sync"
3720Sstevel@tonic-gate #define	VFSNAME_VGET		"vget"
3730Sstevel@tonic-gate #define	VFSNAME_MOUNTROOT	"mountroot"
3740Sstevel@tonic-gate #define	VFSNAME_FREEVFS		"freevfs"
3750Sstevel@tonic-gate #define	VFSNAME_VNSTATE		"vnstate"
3760Sstevel@tonic-gate /*
3770Sstevel@tonic-gate  * Filesystem type switch table.
3780Sstevel@tonic-gate  */
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate typedef struct vfssw {
3810Sstevel@tonic-gate 	char		*vsw_name;	/* type name -- max len _ST_FSTYPSZ */
3820Sstevel@tonic-gate 	int		(*vsw_init) (int, char *);
3830Sstevel@tonic-gate 				/* init routine (for non-loadable fs only) */
3840Sstevel@tonic-gate 	int		vsw_flag;	/* flags */
3850Sstevel@tonic-gate 	mntopts_t	vsw_optproto;	/* mount options table prototype */
3860Sstevel@tonic-gate 	uint_t		vsw_count;	/* count of references */
3870Sstevel@tonic-gate 	kmutex_t	vsw_lock;	/* lock to protect vsw_count */
3880Sstevel@tonic-gate 	vfsops_t	vsw_vfsops;	/* filesystem operations vector */
3890Sstevel@tonic-gate } vfssw_t;
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate /*
3920Sstevel@tonic-gate  * Filesystem type definition record.  All file systems must export a record
3935331Samw  * of this type through their modlfs structure.  N.B., changing the version
3945331Samw  * number requires a change in sys/modctl.h.
3950Sstevel@tonic-gate  */
3960Sstevel@tonic-gate 
3976264Srm15945 typedef struct vfsdef_v5 {
3980Sstevel@tonic-gate 	int		def_version;	/* structure version, must be first */
3990Sstevel@tonic-gate 	char		*name;		/* filesystem type name */
4000Sstevel@tonic-gate 	int		(*init) (int, char *);	/* init routine */
4010Sstevel@tonic-gate 	int		flags;		/* filesystem flags */
4020Sstevel@tonic-gate 	mntopts_t	*optproto;	/* mount options table prototype */
4036264Srm15945 } vfsdef_v5;
4040Sstevel@tonic-gate 
4056264Srm15945 typedef struct vfsdef_v5 vfsdef_t;
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate enum {
4086264Srm15945 	VFSDEF_VERSION = 5
4090Sstevel@tonic-gate };
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate  * flags for vfssw and vfsdef
4130Sstevel@tonic-gate  */
4140Sstevel@tonic-gate #define	VSW_HASPROTO	0x01	/* struct has a mount options prototype */
4150Sstevel@tonic-gate #define	VSW_CANRWRO	0x02	/* file system can transition from rw to ro */
4160Sstevel@tonic-gate #define	VSW_CANREMOUNT	0x04	/* file system supports remounts */
4170Sstevel@tonic-gate #define	VSW_NOTZONESAFE	0x08	/* zone_enter(2) should fail for these files */
4180Sstevel@tonic-gate #define	VSW_VOLATILEDEV	0x10	/* vfs_dev can change each time fs is mounted */
4191488Srsb #define	VSW_STATS	0x20	/* file system can collect stats */
4204321Scasper #define	VSW_XID		0x40	/* file system supports extended ids */
4216855Sjohnlev #define	VSW_CANLOFI	0x80	/* file system supports lofi mounts */
42212633Sjohn.levon@sun.com #define	VSW_ZMOUNT	0x100	/* file system always allowed in a zone */
4230Sstevel@tonic-gate 
4240Sstevel@tonic-gate #define	VSW_INSTALLED	0x8000	/* this vsw is associated with a file system */
4250Sstevel@tonic-gate 
42612894SRobert.Harris@Sun.COM /*
42712894SRobert.Harris@Sun.COM  * A flag for vfs_setpath().
42812894SRobert.Harris@Sun.COM  */
42912894SRobert.Harris@Sun.COM #define	VFSSP_VERBATIM	0x1	/* do not prefix the supplied path */
43012894SRobert.Harris@Sun.COM 
4310Sstevel@tonic-gate #if defined(_KERNEL)
43213096SJordan.Vaughan@Sun.com 
43313096SJordan.Vaughan@Sun.com /*
43413096SJordan.Vaughan@Sun.com  * Private vfs data, NOT to be used by a file system implementation.
43513096SJordan.Vaughan@Sun.com  */
43613096SJordan.Vaughan@Sun.com 
43713096SJordan.Vaughan@Sun.com #define	VFS_FEATURE_MAXSZ	4
43813096SJordan.Vaughan@Sun.com 
43913096SJordan.Vaughan@Sun.com typedef struct vfs_impl {
44013096SJordan.Vaughan@Sun.com 	/* Counted array - Bitmap of vfs features */
44113096SJordan.Vaughan@Sun.com 	uint32_t	vi_featureset[VFS_FEATURE_MAXSZ];
44213096SJordan.Vaughan@Sun.com 	/*
44313096SJordan.Vaughan@Sun.com 	 * Support for statistics on the vnode operations
44413096SJordan.Vaughan@Sun.com 	 */
44513096SJordan.Vaughan@Sun.com 	vsk_anchor_t	*vi_vskap;		/* anchor for vopstats' kstat */
44613096SJordan.Vaughan@Sun.com 	vopstats_t	*vi_fstypevsp;		/* ptr to per-fstype vopstats */
44713096SJordan.Vaughan@Sun.com 	vopstats_t	vi_vopstats;		/* per-mount vnode op stats */
44813096SJordan.Vaughan@Sun.com 
44913096SJordan.Vaughan@Sun.com 	timespec_t	vi_hrctime; 		/* High-res creation time */
45013096SJordan.Vaughan@Sun.com 
45113096SJordan.Vaughan@Sun.com 	zone_ref_t	vi_zone_ref;		/* reference to zone */
45213096SJordan.Vaughan@Sun.com } vfs_impl_t;
45313096SJordan.Vaughan@Sun.com 
4540Sstevel@tonic-gate /*
4550Sstevel@tonic-gate  * Public operations.
4560Sstevel@tonic-gate  */
4570Sstevel@tonic-gate struct umounta;
4580Sstevel@tonic-gate struct statvfsa;
4590Sstevel@tonic-gate struct fstatvfsa;
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate void	vfs_freevfsops(vfsops_t *);
4620Sstevel@tonic-gate int	vfs_freevfsops_by_type(int);
4630Sstevel@tonic-gate void	vfs_setops(vfs_t *, vfsops_t *);
4640Sstevel@tonic-gate vfsops_t *vfs_getops(vfs_t *vfsp);
4650Sstevel@tonic-gate int	vfs_matchops(vfs_t *, vfsops_t *);
4660Sstevel@tonic-gate int	vfs_can_sync(vfs_t *vfsp);
4675331Samw vfs_t	*vfs_alloc(int);
4685331Samw void	vfs_free(vfs_t *);
4690Sstevel@tonic-gate void	vfs_init(vfs_t *vfsp, vfsops_t *, void *);
4701925Srsb void	vfsimpl_setup(vfs_t *vfsp);
4711925Srsb void	vfsimpl_teardown(vfs_t *vfsp);
4720Sstevel@tonic-gate void	vn_exists(vnode_t *);
4730Sstevel@tonic-gate void	vn_idle(vnode_t *);
4740Sstevel@tonic-gate void	vn_reclaim(vnode_t *);
4750Sstevel@tonic-gate void	vn_invalid(vnode_t *);
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate int	rootconf(void);
4780Sstevel@tonic-gate int	svm_rootconf(void);
4790Sstevel@tonic-gate int	domount(char *, struct mounta *, vnode_t *, struct cred *,
4800Sstevel@tonic-gate 	    struct vfs **);
4810Sstevel@tonic-gate int	dounmount(struct vfs *, int, cred_t *);
4820Sstevel@tonic-gate int	vfs_lock(struct vfs *);
4830Sstevel@tonic-gate int	vfs_rlock(struct vfs *);
4840Sstevel@tonic-gate void	vfs_lock_wait(struct vfs *);
4850Sstevel@tonic-gate void	vfs_rlock_wait(struct vfs *);
4860Sstevel@tonic-gate void	vfs_unlock(struct vfs *);
4870Sstevel@tonic-gate int	vfs_lock_held(struct vfs *);
4880Sstevel@tonic-gate struct	_kthread *vfs_lock_owner(struct vfs *);
4890Sstevel@tonic-gate void	sync(void);
4900Sstevel@tonic-gate void	vfs_sync(int);
4910Sstevel@tonic-gate void	vfs_mountroot(void);
4920Sstevel@tonic-gate void	vfs_add(vnode_t *, struct vfs *, int);
4930Sstevel@tonic-gate void	vfs_remove(struct vfs *);
4940Sstevel@tonic-gate 
4955331Samw /* VFS feature routines */
4965331Samw void	vfs_set_feature(vfs_t *, vfs_feature_t);
497*13147SMark.Shellenbaum@Oracle.COM void	vfs_clear_feature(vfs_t *, vfs_feature_t);
4985331Samw int	vfs_has_feature(vfs_t *, vfs_feature_t);
4996224Smarks void	vfs_propagate_features(vfs_t *, vfs_t *);
5005331Samw 
5010Sstevel@tonic-gate /* The following functions are not for general use by filesystems */
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate void	vfs_createopttbl(mntopts_t *, const char *);
5040Sstevel@tonic-gate void	vfs_copyopttbl(const mntopts_t *, mntopts_t *);
5050Sstevel@tonic-gate void	vfs_mergeopttbl(const mntopts_t *, const mntopts_t *, mntopts_t *);
5060Sstevel@tonic-gate void	vfs_freeopttbl(mntopts_t *);
5070Sstevel@tonic-gate void	vfs_parsemntopts(mntopts_t *, char *, int);
5080Sstevel@tonic-gate int	vfs_buildoptionstr(const mntopts_t *, char *, int);
5090Sstevel@tonic-gate struct mntopt *vfs_hasopt(const mntopts_t *, const char *);
5100Sstevel@tonic-gate void	vfs_mnttab_modtimeupd(void);
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate void	vfs_clearmntopt(struct vfs *, const char *);
5130Sstevel@tonic-gate void	vfs_setmntopt(struct vfs *, const char *, const char *, int);
51412894SRobert.Harris@Sun.COM void	vfs_setresource(struct vfs *, const char *, uint32_t);
51512894SRobert.Harris@Sun.COM void	vfs_setmntpoint(struct vfs *, const char *, uint32_t);
5160Sstevel@tonic-gate refstr_t *vfs_getresource(const struct vfs *);
5170Sstevel@tonic-gate refstr_t *vfs_getmntpoint(const struct vfs *);
5180Sstevel@tonic-gate int	vfs_optionisset(const struct vfs *, const char *, char **);
5190Sstevel@tonic-gate int	vfs_settag(uint_t, uint_t, const char *, const char *, cred_t *);
5200Sstevel@tonic-gate int	vfs_clrtag(uint_t, uint_t, const char *, const char *, cred_t *);
5210Sstevel@tonic-gate void	vfs_syncall(void);
5220Sstevel@tonic-gate void	vfs_syncprogress(void);
5230Sstevel@tonic-gate void	vfsinit(void);
5240Sstevel@tonic-gate void	vfs_unmountall(void);
5250Sstevel@tonic-gate void	vfs_make_fsid(fsid_t *, dev_t, int);
5260Sstevel@tonic-gate void	vfs_addmip(dev_t, struct vfs *);
5270Sstevel@tonic-gate void	vfs_delmip(struct vfs *);
5280Sstevel@tonic-gate int	vfs_devismounted(dev_t);
5290Sstevel@tonic-gate int	vfs_devmounting(dev_t, struct vfs *);
5300Sstevel@tonic-gate int	vfs_opsinuse(vfsops_t *);
5310Sstevel@tonic-gate struct vfs *getvfs(fsid_t *);
5320Sstevel@tonic-gate struct vfs *vfs_dev2vfsp(dev_t);
5330Sstevel@tonic-gate struct vfs *vfs_mntpoint2vfsp(const char *);
5346855Sjohnlev struct vfssw *allocate_vfssw(const char *);
5356855Sjohnlev struct vfssw *vfs_getvfssw(const char *);
5366855Sjohnlev struct vfssw *vfs_getvfsswbyname(const char *);
5370Sstevel@tonic-gate struct vfssw *vfs_getvfsswbyvfsops(vfsops_t *);
5380Sstevel@tonic-gate void	vfs_refvfssw(struct vfssw *);
5390Sstevel@tonic-gate void	vfs_unrefvfssw(struct vfssw *);
5400Sstevel@tonic-gate uint_t	vf_to_stf(uint_t);
5410Sstevel@tonic-gate void	vfs_mnttab_modtime(timespec_t *);
5420Sstevel@tonic-gate void	vfs_mnttab_poll(timespec_t *, struct pollhead **);
5430Sstevel@tonic-gate 
5440Sstevel@tonic-gate void	vfs_list_lock(void);
5450Sstevel@tonic-gate void	vfs_list_read_lock(void);
5460Sstevel@tonic-gate void	vfs_list_unlock(void);
5470Sstevel@tonic-gate void	vfs_list_add(struct vfs *);
5480Sstevel@tonic-gate void	vfs_list_remove(struct vfs *);
5490Sstevel@tonic-gate void	vfs_hold(vfs_t *vfsp);
5500Sstevel@tonic-gate void	vfs_rele(vfs_t *vfsp);
5510Sstevel@tonic-gate void	fs_freevfs(vfs_t *);
5520Sstevel@tonic-gate void	vfs_root_redev(vfs_t *vfsp, dev_t ndev, int fstype);
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate int	vfs_zone_change_safe(vfs_t *);
5550Sstevel@tonic-gate 
5566734Sjohnlev int	vfs_get_lofi(vfs_t *, vnode_t **);
5576734Sjohnlev 
5580Sstevel@tonic-gate #define	VFSHASH(maj, min) (((int)((maj)+(min))) & (vfshsz - 1))
5590Sstevel@tonic-gate #define	VFS_ON_LIST(vfsp) \
5600Sstevel@tonic-gate 	((vfsp)->vfs_next != (vfsp) && (vfsp)->vfs_next != NULL)
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate /*
5630Sstevel@tonic-gate  * Globals.
5640Sstevel@tonic-gate  */
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate extern struct vfssw vfssw[];		/* table of filesystem types */
5670Sstevel@tonic-gate extern krwlock_t vfssw_lock;
5680Sstevel@tonic-gate extern char rootfstype[];		/* name of root fstype */
5690Sstevel@tonic-gate extern const int nfstype;		/* # of elements in vfssw array */
5700Sstevel@tonic-gate extern vfsops_t *EIO_vfsops;		/* operations for vfs being torn-down */
5710Sstevel@tonic-gate 
5720Sstevel@tonic-gate /*
5730Sstevel@tonic-gate  * The following variables are private to the the kernel's vfs layer.  File
5740Sstevel@tonic-gate  * system implementations should not access them.
5750Sstevel@tonic-gate  */
5760Sstevel@tonic-gate extern struct vfs *rootvfs;		/* ptr to root vfs structure */
5770Sstevel@tonic-gate typedef struct {
5780Sstevel@tonic-gate 	struct vfs *rvfs_head;		/* head vfs in chain */
5790Sstevel@tonic-gate 	kmutex_t rvfs_lock;		/* mutex protecting this chain */
5800Sstevel@tonic-gate 	uint32_t rvfs_len;		/* length of this chain */
5810Sstevel@tonic-gate } rvfs_t;
5820Sstevel@tonic-gate extern rvfs_t *rvfs_list;
5830Sstevel@tonic-gate extern int vfshsz;			/* # of elements in rvfs_head array */
5840Sstevel@tonic-gate extern const mntopts_t vfs_mntopts;	/* globally recognized options */
5850Sstevel@tonic-gate 
5860Sstevel@tonic-gate #endif /* defined(_KERNEL) */
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate #define	VFS_HOLD(vfsp) { \
5890Sstevel@tonic-gate 	vfs_hold(vfsp); \
5900Sstevel@tonic-gate }
5910Sstevel@tonic-gate 
5920Sstevel@tonic-gate #define	VFS_RELE(vfsp)	{ \
5930Sstevel@tonic-gate 	vfs_rele(vfsp); \
5940Sstevel@tonic-gate }
5950Sstevel@tonic-gate 
5961925Srsb #define	VFS_INIT(vfsp, op, data) { \
5971925Srsb 	vfs_init((vfsp), (op), (data)); \
5981925Srsb }
5990Sstevel@tonic-gate 
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate #define	VFS_INSTALLED(vfsswp)	(((vfsswp)->vsw_flag & VSW_INSTALLED) != 0)
6020Sstevel@tonic-gate #define	ALLOCATED_VFSSW(vswp)		((vswp)->vsw_name[0] != '\0')
6030Sstevel@tonic-gate #define	RLOCK_VFSSW()			(rw_enter(&vfssw_lock, RW_READER))
6040Sstevel@tonic-gate #define	RUNLOCK_VFSSW()			(rw_exit(&vfssw_lock))
6050Sstevel@tonic-gate #define	WLOCK_VFSSW()			(rw_enter(&vfssw_lock, RW_WRITER))
6060Sstevel@tonic-gate #define	WUNLOCK_VFSSW()			(rw_exit(&vfssw_lock))
6070Sstevel@tonic-gate #define	VFSSW_LOCKED()			(RW_LOCK_HELD(&vfssw_lock))
6080Sstevel@tonic-gate #define	VFSSW_WRITE_LOCKED()		(RW_WRITE_HELD(&vfssw_lock))
6090Sstevel@tonic-gate /*
6100Sstevel@tonic-gate  * VFS_SYNC flags.
6110Sstevel@tonic-gate  */
6120Sstevel@tonic-gate #define	SYNC_ATTR	0x01		/* sync attributes only */
6130Sstevel@tonic-gate #define	SYNC_CLOSE	0x02		/* close open file */
6140Sstevel@tonic-gate #define	SYNC_ALL	0x04		/* force to sync all fs */
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate #ifdef	__cplusplus
6170Sstevel@tonic-gate }
6180Sstevel@tonic-gate #endif
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate #endif	/* _SYS_VFS_H */
621