xref: /illumos-gate/usr/src/uts/common/sys/vfs.h (revision bd670b35a010421b6e1a5536c34453a827007c81)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * Portions of this source code were derived from Berkeley 4.3 BSD
31  * under license from the Regents of the University of California.
32  */
33 
34 #ifndef _SYS_VFS_H
35 #define	_SYS_VFS_H
36 
37 #include <sys/types.h>
38 #include <sys/t_lock.h>
39 #include <sys/cred.h>
40 #include <sys/vnode.h>
41 #include <sys/statvfs.h>
42 #include <sys/refstr.h>
43 #include <sys/avl.h>
44 #include <sys/time.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 /*
51  * Data associated with mounted file systems.
52  */
53 
54 /*
55  * Operations vector.  This is used internal to the kernel; file systems
56  * supply their list of operations via vfs_setfsops().
57  */
58 
59 typedef struct vfsops vfsops_t;
60 
61 /*
62  * File system identifier. Should be unique (at least per machine).
63  */
64 typedef struct {
65 	int val[2];			/* file system id type */
66 } fsid_t;
67 
68 /*
69  * File identifier.  Should be unique per filesystem on a single
70  * machine.  This is typically called by a stateless file server
71  * in order to generate "file handles".
72  *
73  * Do not change the definition of struct fid ... fid_t without
74  * letting the CacheFS group know about it!  They will have to do at
75  * least two things, in the same change that changes this structure:
76  *   1. change CFSVERSION in usr/src/uts/common/sys/fs/cachefs_fs.h
77  *   2. put the old version # in the canupgrade array
78  *	in cachfs_upgrade() in usr/src/cmd/fs.d/cachefs/fsck/fsck.c
79  * This is necessary because CacheFS stores FIDs on disk.
80  *
81  * Many underlying file systems cast a struct fid into other
82  * file system dependent structures which may require 4 byte alignment.
83  * Because a fid starts with a short it may not be 4 byte aligned, the
84  * fid_pad will force the alignment.
85  */
86 #define	MAXFIDSZ	64
87 #define	OLD_MAXFIDSZ	16
88 
89 typedef struct fid {
90 	union {
91 		long fid_pad;
92 		struct {
93 			ushort_t len;	/* length of data in bytes */
94 			char	data[MAXFIDSZ]; /* data (variable len) */
95 		} _fid;
96 	} un;
97 } fid_t;
98 
99 #ifdef _SYSCALL32
100 /*
101  * Solaris 64 - use old-style cache format with 32-bit aligned fid for on-disk
102  * struct compatibility.
103  */
104 typedef struct fid32 {
105 	union {
106 		int32_t fid_pad;
107 		struct {
108 			uint16_t  len;   /* length of data in bytes */
109 			char    data[MAXFIDSZ]; /* data (variable len) */
110 		} _fid;
111 	} un;
112 } fid32_t;
113 #else /* not _SYSCALL32 */
114 #define	fid32	fid
115 typedef fid_t	fid32_t;
116 #endif /* _SYSCALL32 */
117 
118 #define	fid_len		un._fid.len
119 #define	fid_data	un._fid.data
120 
121 /*
122  * Structure defining a mount option for a filesystem.
123  * option names are found in mntent.h
124  */
125 typedef struct mntopt {
126 	char	*mo_name;	/* option name */
127 	char	**mo_cancel;	/* list of options cancelled by this one */
128 	char	*mo_arg;	/* argument string for this option */
129 	int	mo_flags;	/* flags for this mount option */
130 	void	*mo_data;	/* filesystem specific data */
131 } mntopt_t;
132 
133 /*
134  * Flags that apply to mount options
135  */
136 
137 #define	MO_SET		0x01		/* option is set */
138 #define	MO_NODISPLAY	0x02		/* option not listed in mnttab */
139 #define	MO_HASVALUE	0x04		/* option takes a value */
140 #define	MO_IGNORE	0x08		/* option ignored by parser */
141 #define	MO_DEFAULT	MO_SET		/* option is on by default */
142 #define	MO_TAG		0x10		/* flags a tag set by user program */
143 #define	MO_EMPTY	0x20		/* empty space in option table */
144 
145 #define	VFS_NOFORCEOPT	0x01		/* honor MO_IGNORE (don't set option) */
146 #define	VFS_DISPLAY	0x02		/* Turn off MO_NODISPLAY bit for opt */
147 #define	VFS_NODISPLAY	0x04		/* Turn on MO_NODISPLAY bit for opt */
148 #define	VFS_CREATEOPT	0x08		/* Create the opt if it's not there */
149 
150 /*
151  * Structure holding mount option strings for the mounted file system.
152  */
153 typedef struct mntopts {
154 	uint_t		mo_count;		/* number of entries in table */
155 	mntopt_t	*mo_list;		/* list of mount options */
156 } mntopts_t;
157 
158 /*
159  * The kstat structures associated with the vopstats are kept in an
160  * AVL tree.  This is to avoid the case where a file system does not
161  * use a unique fsid_t for each vfs (e.g., namefs).  In order to do
162  * this, we need a structure that the AVL tree can use that also
163  * references the kstat.
164  * Note that the vks_fsid is generated from the value reported by
165  * VFS_STATVFS().
166  */
167 typedef struct vskstat_anchor {
168 	avl_node_t	vsk_node;	/* Required for use by AVL routines */
169 	kstat_t		*vsk_ksp;	/* kstat structure for vopstats */
170 	ulong_t		vsk_fsid;	/* fsid associated w/this FS */
171 } vsk_anchor_t;
172 
173 extern avl_tree_t	vskstat_tree;
174 extern kmutex_t		vskstat_tree_lock;
175 
176 /*
177  * Private vfs data, NOT to be used by a file system implementation.
178  */
179 
180 #define	VFS_FEATURE_MAXSZ	4
181 
182 typedef struct vfs_impl {
183 	/* Counted array - Bitmap of vfs features */
184 	uint32_t	vi_featureset[VFS_FEATURE_MAXSZ];
185 	/*
186 	 * Support for statistics on the vnode operations
187 	 */
188 	vsk_anchor_t	*vi_vskap;		/* anchor for vopstats' kstat */
189 	vopstats_t	*vi_fstypevsp;		/* ptr to per-fstype vopstats */
190 	vopstats_t	vi_vopstats;		/* per-mount vnode op stats */
191 
192 	timespec_t	vi_hrctime; 		/* High-res creation time */
193 } vfs_impl_t;
194 
195 
196 /*
197  * Structure per mounted file system.  Each mounted file system has
198  * an array of operations and an instance record.
199  *
200  * The file systems are kept on a doubly linked circular list headed by
201  * "rootvfs".
202  * File system implementations should not access this list;
203  * it's intended for use only in the kernel's vfs layer.
204  *
205  * Each zone also has its own list of mounts, containing filesystems mounted
206  * somewhere within the filesystem tree rooted at the zone's rootpath.  The
207  * list is doubly linked to match the global list.
208  *
209  * mnttab locking: the in-kernel mnttab uses the vfs_mntpt, vfs_resource and
210  * vfs_mntopts fields in the vfs_t. mntpt and resource are refstr_ts that
211  * are set at mount time and can only be modified during a remount.
212  * It is safe to read these fields if you can prevent a remount on the vfs,
213  * or through the convenience funcs vfs_getmntpoint() and vfs_getresource().
214  * The mntopts field may only be accessed through the provided convenience
215  * functions, as it is protected by the vfs list lock. Modifying a mount
216  * option requires grabbing the vfs list write lock, which can be a very
217  * high latency lock.
218  */
219 struct zone;		/* from zone.h */
220 struct fem_head;	/* from fem.h */
221 
222 typedef struct vfs {
223 	struct vfs	*vfs_next;		/* next VFS in VFS list */
224 	struct vfs	*vfs_prev;		/* prev VFS in VFS list */
225 
226 /* vfs_op should not be used directly.  Accessor functions are provided */
227 	vfsops_t	*vfs_op;		/* operations on VFS */
228 
229 	struct vnode	*vfs_vnodecovered;	/* vnode mounted on */
230 	uint_t		vfs_flag;		/* flags */
231 	uint_t		vfs_bsize;		/* native block size */
232 	int		vfs_fstype;		/* file system type index */
233 	fsid_t		vfs_fsid;		/* file system id */
234 	void		*vfs_data;		/* private data */
235 	dev_t		vfs_dev;		/* device of mounted VFS */
236 	ulong_t		vfs_bcount;		/* I/O count (accounting) */
237 	struct vfs	*vfs_list;		/* sync list pointer */
238 	struct vfs	*vfs_hash;		/* hash list pointer */
239 	ksema_t		vfs_reflock;		/* mount/unmount/sync lock */
240 	uint_t		vfs_count;		/* vfs reference count */
241 	mntopts_t	vfs_mntopts;		/* options mounted with */
242 	refstr_t	*vfs_resource;		/* mounted resource name */
243 	refstr_t	*vfs_mntpt;		/* mount point name */
244 	time_t		vfs_mtime;		/* time we were mounted */
245 	vfs_impl_t 	*vfs_implp;		/* impl specific data */
246 	/*
247 	 * Zones support.  Note that the zone that "owns" the mount isn't
248 	 * necessarily the same as the zone in which the zone is visible.
249 	 * That is, vfs_zone and (vfs_zone_next|vfs_zone_prev) may refer to
250 	 * different zones.
251 	 */
252 	struct zone	*vfs_zone;		/* zone that owns the mount */
253 	struct vfs	*vfs_zone_next;		/* next VFS visible in zone */
254 	struct vfs	*vfs_zone_prev;		/* prev VFS visible in zone */
255 
256 	struct fem_head	*vfs_femhead;		/* fs monitoring */
257 	minor_t		vfs_lofi_minor;		/* minor if lofi mount */
258 } vfs_t;
259 
260 #define	vfs_featureset	vfs_implp->vi_featureset
261 #define	vfs_vskap	vfs_implp->vi_vskap
262 #define	vfs_fstypevsp	vfs_implp->vi_fstypevsp
263 #define	vfs_vopstats	vfs_implp->vi_vopstats
264 #define	vfs_hrctime	vfs_implp->vi_hrctime
265 
266 /*
267  * VFS flags.
268  */
269 #define	VFS_RDONLY	0x01		/* read-only vfs */
270 #define	VFS_NOMNTTAB	0x02		/* vfs not seen in mnttab */
271 #define	VFS_NOSETUID	0x08		/* setuid disallowed */
272 #define	VFS_REMOUNT	0x10		/* modify mount options only */
273 #define	VFS_NOTRUNC	0x20		/* does not truncate long file names */
274 #define	VFS_UNLINKABLE	0x40		/* unlink(2) can be applied to root */
275 #define	VFS_PXFS	0x80		/* clustering: global fs proxy vfs */
276 #define	VFS_UNMOUNTED	0x100		/* file system has been unmounted */
277 #define	VFS_NBMAND	0x200		/* allow non-blocking mandatory locks */
278 #define	VFS_XATTR	0x400		/* fs supports extended attributes */
279 #define	VFS_NODEVICES	0x800		/* device-special files disallowed */
280 #define	VFS_NOEXEC	0x1000		/* executables disallowed */
281 #define	VFS_STATS	0x2000		/* file system can collect stats */
282 #define	VFS_XID		0x4000		/* file system supports extended ids */
283 
284 #define	VFS_NORESOURCE	"unspecified_resource"
285 #define	VFS_NOMNTPT	"unspecified_mountpoint"
286 
287 /*
288  * VFS features are implemented as bits set in the vfs_t.
289  * The vfs_feature_t typedef is a 64-bit number that will translate
290  * into an element in an array of bitmaps and a bit in that element.
291  * Developers must not depend on the implementation of this and
292  * need to use vfs_has_feature()/vfs_set_feature() routines.
293  */
294 typedef	uint64_t	vfs_feature_t;
295 
296 #define	VFSFT_XVATTR		0x100000001	/* Supports xvattr for attrs */
297 #define	VFSFT_CASEINSENSITIVE	0x100000002	/* Supports case-insensitive */
298 #define	VFSFT_NOCASESENSITIVE	0x100000004	/* NOT case-sensitive */
299 #define	VFSFT_DIRENTFLAGS	0x100000008	/* Supports dirent flags */
300 #define	VFSFT_ACLONCREATE	0x100000010	/* Supports ACL on create */
301 #define	VFSFT_ACEMASKONACCESS	0x100000020	/* Can use ACEMASK for access */
302 #define	VFSFT_SYSATTR_VIEWS	0x100000040	/* Supports sysattr view i/f */
303 #define	VFSFT_ACCESS_FILTER	0x100000080	/* dirents filtered by access */
304 #define	VFSFT_REPARSE		0x100000100	/* Supports reparse point */
305 
306 /*
307  * Argument structure for mount(2).
308  *
309  * Flags are defined in <sys/mount.h>.
310  *
311  * Note that if the MS_SYSSPACE bit is set in flags, the pointer fields in
312  * this structure are to be interpreted as kernel addresses.  File systems
313  * should be prepared for this possibility.
314  */
315 struct mounta {
316 	char	*spec;
317 	char	*dir;
318 	int	flags;
319 	char	*fstype;
320 	char	*dataptr;
321 	int	datalen;
322 	char	*optptr;
323 	int	optlen;
324 };
325 
326 /*
327  * Reasons for calling the vfs_mountroot() operation.
328  */
329 enum whymountroot { ROOT_INIT, ROOT_REMOUNT, ROOT_UNMOUNT};
330 typedef enum whymountroot whymountroot_t;
331 
332 /*
333  * Reasons for calling the VFS_VNSTATE():
334  */
335 enum vntrans {
336 	VNTRANS_EXISTS,
337 	VNTRANS_IDLED,
338 	VNTRANS_RECLAIMED,
339 	VNTRANS_DESTROYED
340 };
341 typedef enum vntrans vntrans_t;
342 
343 /*
344  * VFS_OPS defines all the vfs operations.  It is used to define
345  * the vfsops structure (below) and the fs_func_p union (vfs_opreg.h).
346  */
347 #define	VFS_OPS								\
348 	int	(*vfs_mount)(vfs_t *, vnode_t *, struct mounta *, cred_t *); \
349 	int	(*vfs_unmount)(vfs_t *, int, cred_t *);			\
350 	int	(*vfs_root)(vfs_t *, vnode_t **);			\
351 	int	(*vfs_statvfs)(vfs_t *, statvfs64_t *);			\
352 	int	(*vfs_sync)(vfs_t *, short, cred_t *);			\
353 	int	(*vfs_vget)(vfs_t *, vnode_t **, fid_t *);		\
354 	int	(*vfs_mountroot)(vfs_t *, enum whymountroot);		\
355 	void	(*vfs_freevfs)(vfs_t *);				\
356 	int	(*vfs_vnstate)(vfs_t *, vnode_t *, vntrans_t)	/* NB: No ";" */
357 
358 /*
359  * Operations supported on virtual file system.
360  */
361 struct vfsops {
362 	VFS_OPS;	/* Signature of all vfs operations (vfsops) */
363 };
364 
365 extern int	fsop_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *);
366 extern int	fsop_unmount(vfs_t *, int, cred_t *);
367 extern int	fsop_root(vfs_t *, vnode_t **);
368 extern int	fsop_statfs(vfs_t *, statvfs64_t *);
369 extern int	fsop_sync(vfs_t *, short, cred_t *);
370 extern int	fsop_vget(vfs_t *, vnode_t **, fid_t *);
371 extern int	fsop_mountroot(vfs_t *, enum whymountroot);
372 extern void	fsop_freefs(vfs_t *);
373 extern int	fsop_sync_by_kind(int, short, cred_t *);
374 extern int	fsop_vnstate(vfs_t *, vnode_t *, vntrans_t);
375 
376 #define	VFS_MOUNT(vfsp, mvp, uap, cr) fsop_mount(vfsp, mvp, uap, cr)
377 #define	VFS_UNMOUNT(vfsp, flag, cr) fsop_unmount(vfsp, flag, cr)
378 #define	VFS_ROOT(vfsp, vpp) fsop_root(vfsp, vpp)
379 #define	VFS_STATVFS(vfsp, sp) fsop_statfs(vfsp, sp)
380 #define	VFS_SYNC(vfsp, flag, cr) fsop_sync(vfsp, flag, cr)
381 #define	VFS_VGET(vfsp, vpp, fidp) fsop_vget(vfsp, vpp, fidp)
382 #define	VFS_MOUNTROOT(vfsp, init) fsop_mountroot(vfsp, init)
383 #define	VFS_FREEVFS(vfsp) fsop_freefs(vfsp)
384 #define	VFS_VNSTATE(vfsp, vn, ns)	fsop_vnstate(vfsp, vn, ns)
385 
386 #define	VFSNAME_MOUNT		"mount"
387 #define	VFSNAME_UNMOUNT		"unmount"
388 #define	VFSNAME_ROOT		"root"
389 #define	VFSNAME_STATVFS		"statvfs"
390 #define	VFSNAME_SYNC		"sync"
391 #define	VFSNAME_VGET		"vget"
392 #define	VFSNAME_MOUNTROOT	"mountroot"
393 #define	VFSNAME_FREEVFS		"freevfs"
394 #define	VFSNAME_VNSTATE		"vnstate"
395 /*
396  * Filesystem type switch table.
397  */
398 
399 typedef struct vfssw {
400 	char		*vsw_name;	/* type name -- max len _ST_FSTYPSZ */
401 	int		(*vsw_init) (int, char *);
402 				/* init routine (for non-loadable fs only) */
403 	int		vsw_flag;	/* flags */
404 	mntopts_t	vsw_optproto;	/* mount options table prototype */
405 	uint_t		vsw_count;	/* count of references */
406 	kmutex_t	vsw_lock;	/* lock to protect vsw_count */
407 	vfsops_t	vsw_vfsops;	/* filesystem operations vector */
408 } vfssw_t;
409 
410 /*
411  * Filesystem type definition record.  All file systems must export a record
412  * of this type through their modlfs structure.  N.B., changing the version
413  * number requires a change in sys/modctl.h.
414  */
415 
416 typedef struct vfsdef_v5 {
417 	int		def_version;	/* structure version, must be first */
418 	char		*name;		/* filesystem type name */
419 	int		(*init) (int, char *);	/* init routine */
420 	int		flags;		/* filesystem flags */
421 	mntopts_t	*optproto;	/* mount options table prototype */
422 } vfsdef_v5;
423 
424 typedef struct vfsdef_v5 vfsdef_t;
425 
426 enum {
427 	VFSDEF_VERSION = 5
428 };
429 
430 /*
431  * flags for vfssw and vfsdef
432  */
433 #define	VSW_HASPROTO	0x01	/* struct has a mount options prototype */
434 #define	VSW_CANRWRO	0x02	/* file system can transition from rw to ro */
435 #define	VSW_CANREMOUNT	0x04	/* file system supports remounts */
436 #define	VSW_NOTZONESAFE	0x08	/* zone_enter(2) should fail for these files */
437 #define	VSW_VOLATILEDEV	0x10	/* vfs_dev can change each time fs is mounted */
438 #define	VSW_STATS	0x20	/* file system can collect stats */
439 #define	VSW_XID		0x40	/* file system supports extended ids */
440 #define	VSW_CANLOFI	0x80	/* file system supports lofi mounts */
441 
442 #define	VSW_INSTALLED	0x8000	/* this vsw is associated with a file system */
443 
444 #if defined(_KERNEL)
445 /*
446  * Public operations.
447  */
448 struct umounta;
449 struct statvfsa;
450 struct fstatvfsa;
451 
452 void	vfs_freevfsops(vfsops_t *);
453 int	vfs_freevfsops_by_type(int);
454 void	vfs_setops(vfs_t *, vfsops_t *);
455 vfsops_t *vfs_getops(vfs_t *vfsp);
456 int	vfs_matchops(vfs_t *, vfsops_t *);
457 int	vfs_can_sync(vfs_t *vfsp);
458 vfs_t	*vfs_alloc(int);
459 void	vfs_free(vfs_t *);
460 void	vfs_init(vfs_t *vfsp, vfsops_t *, void *);
461 void	vfsimpl_setup(vfs_t *vfsp);
462 void	vfsimpl_teardown(vfs_t *vfsp);
463 void	vn_exists(vnode_t *);
464 void	vn_idle(vnode_t *);
465 void	vn_reclaim(vnode_t *);
466 void	vn_invalid(vnode_t *);
467 
468 int	rootconf(void);
469 int	svm_rootconf(void);
470 int	domount(char *, struct mounta *, vnode_t *, struct cred *,
471 	    struct vfs **);
472 int	dounmount(struct vfs *, int, cred_t *);
473 int	vfs_lock(struct vfs *);
474 int	vfs_rlock(struct vfs *);
475 void	vfs_lock_wait(struct vfs *);
476 void	vfs_rlock_wait(struct vfs *);
477 void	vfs_unlock(struct vfs *);
478 int	vfs_lock_held(struct vfs *);
479 struct	_kthread *vfs_lock_owner(struct vfs *);
480 void	sync(void);
481 void	vfs_sync(int);
482 void	vfs_mountroot(void);
483 void	vfs_add(vnode_t *, struct vfs *, int);
484 void	vfs_remove(struct vfs *);
485 
486 /* VFS feature routines */
487 void	vfs_set_feature(vfs_t *, vfs_feature_t);
488 int	vfs_has_feature(vfs_t *, vfs_feature_t);
489 void	vfs_propagate_features(vfs_t *, vfs_t *);
490 
491 /* The following functions are not for general use by filesystems */
492 
493 void	vfs_createopttbl(mntopts_t *, const char *);
494 void	vfs_copyopttbl(const mntopts_t *, mntopts_t *);
495 void	vfs_mergeopttbl(const mntopts_t *, const mntopts_t *, mntopts_t *);
496 void	vfs_freeopttbl(mntopts_t *);
497 void	vfs_parsemntopts(mntopts_t *, char *, int);
498 int	vfs_buildoptionstr(const mntopts_t *, char *, int);
499 struct mntopt *vfs_hasopt(const mntopts_t *, const char *);
500 void	vfs_mnttab_modtimeupd(void);
501 
502 void	vfs_clearmntopt(struct vfs *, const char *);
503 void	vfs_setmntopt(struct vfs *, const char *, const char *, int);
504 void	vfs_setresource(struct vfs *, const char *);
505 void	vfs_setmntpoint(struct vfs *, const char *);
506 refstr_t *vfs_getresource(const struct vfs *);
507 refstr_t *vfs_getmntpoint(const struct vfs *);
508 int	vfs_optionisset(const struct vfs *, const char *, char **);
509 int	vfs_settag(uint_t, uint_t, const char *, const char *, cred_t *);
510 int	vfs_clrtag(uint_t, uint_t, const char *, const char *, cred_t *);
511 void	vfs_syncall(void);
512 void	vfs_syncprogress(void);
513 void	vfsinit(void);
514 void	vfs_unmountall(void);
515 void	vfs_make_fsid(fsid_t *, dev_t, int);
516 void	vfs_addmip(dev_t, struct vfs *);
517 void	vfs_delmip(struct vfs *);
518 int	vfs_devismounted(dev_t);
519 int	vfs_devmounting(dev_t, struct vfs *);
520 int	vfs_opsinuse(vfsops_t *);
521 struct vfs *getvfs(fsid_t *);
522 struct vfs *vfs_dev2vfsp(dev_t);
523 struct vfs *vfs_mntpoint2vfsp(const char *);
524 struct vfssw *allocate_vfssw(const char *);
525 struct vfssw *vfs_getvfssw(const char *);
526 struct vfssw *vfs_getvfsswbyname(const char *);
527 struct vfssw *vfs_getvfsswbyvfsops(vfsops_t *);
528 void	vfs_refvfssw(struct vfssw *);
529 void	vfs_unrefvfssw(struct vfssw *);
530 uint_t	vf_to_stf(uint_t);
531 void	vfs_mnttab_modtime(timespec_t *);
532 void	vfs_mnttab_poll(timespec_t *, struct pollhead **);
533 
534 void	vfs_list_lock(void);
535 void	vfs_list_read_lock(void);
536 void	vfs_list_unlock(void);
537 void	vfs_list_add(struct vfs *);
538 void	vfs_list_remove(struct vfs *);
539 void	vfs_hold(vfs_t *vfsp);
540 void	vfs_rele(vfs_t *vfsp);
541 void	fs_freevfs(vfs_t *);
542 void	vfs_root_redev(vfs_t *vfsp, dev_t ndev, int fstype);
543 
544 int	vfs_zone_change_safe(vfs_t *);
545 
546 int	vfs_get_lofi(vfs_t *, vnode_t **);
547 
548 #define	VFSHASH(maj, min) (((int)((maj)+(min))) & (vfshsz - 1))
549 #define	VFS_ON_LIST(vfsp) \
550 	((vfsp)->vfs_next != (vfsp) && (vfsp)->vfs_next != NULL)
551 
552 /*
553  * Globals.
554  */
555 
556 extern struct vfssw vfssw[];		/* table of filesystem types */
557 extern krwlock_t vfssw_lock;
558 extern char rootfstype[];		/* name of root fstype */
559 extern const int nfstype;		/* # of elements in vfssw array */
560 extern vfsops_t *EIO_vfsops;		/* operations for vfs being torn-down */
561 
562 /*
563  * The following variables are private to the the kernel's vfs layer.  File
564  * system implementations should not access them.
565  */
566 extern struct vfs *rootvfs;		/* ptr to root vfs structure */
567 typedef struct {
568 	struct vfs *rvfs_head;		/* head vfs in chain */
569 	kmutex_t rvfs_lock;		/* mutex protecting this chain */
570 	uint32_t rvfs_len;		/* length of this chain */
571 } rvfs_t;
572 extern rvfs_t *rvfs_list;
573 extern int vfshsz;			/* # of elements in rvfs_head array */
574 extern const mntopts_t vfs_mntopts;	/* globally recognized options */
575 
576 #endif /* defined(_KERNEL) */
577 
578 #define	VFS_HOLD(vfsp) { \
579 	vfs_hold(vfsp); \
580 }
581 
582 #define	VFS_RELE(vfsp)	{ \
583 	vfs_rele(vfsp); \
584 }
585 
586 #define	VFS_INIT(vfsp, op, data) { \
587 	vfs_init((vfsp), (op), (data)); \
588 }
589 
590 
591 #define	VFS_INSTALLED(vfsswp)	(((vfsswp)->vsw_flag & VSW_INSTALLED) != 0)
592 #define	ALLOCATED_VFSSW(vswp)		((vswp)->vsw_name[0] != '\0')
593 #define	RLOCK_VFSSW()			(rw_enter(&vfssw_lock, RW_READER))
594 #define	RUNLOCK_VFSSW()			(rw_exit(&vfssw_lock))
595 #define	WLOCK_VFSSW()			(rw_enter(&vfssw_lock, RW_WRITER))
596 #define	WUNLOCK_VFSSW()			(rw_exit(&vfssw_lock))
597 #define	VFSSW_LOCKED()			(RW_LOCK_HELD(&vfssw_lock))
598 #define	VFSSW_WRITE_LOCKED()		(RW_WRITE_HELD(&vfssw_lock))
599 /*
600  * VFS_SYNC flags.
601  */
602 #define	SYNC_ATTR	0x01		/* sync attributes only */
603 #define	SYNC_CLOSE	0x02		/* close open file */
604 #define	SYNC_ALL	0x04		/* force to sync all fs */
605 
606 #ifdef	__cplusplus
607 }
608 #endif
609 
610 #endif	/* _SYS_VFS_H */
611