mount.h revision 73286
1/*
2 * Copyright (c) 1989, 1991, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)mount.h	8.21 (Berkeley) 5/20/95
34 * $FreeBSD: head/sys/sys/mount.h 73286 2001-03-01 21:00:17Z adrian $
35 */
36
37#ifndef _SYS_MOUNT_H_
38#define _SYS_MOUNT_H_
39
40#include <sys/ucred.h>
41#include <sys/queue.h>
42#ifdef _KERNEL
43#include <sys/lock.h>
44#endif
45
46typedef struct fsid { int32_t val[2]; } fsid_t;	/* file system id type */
47
48/*
49 * File identifier.
50 * These are unique per filesystem on a single machine.
51 */
52#define	MAXFIDSZ	16
53
54struct fid {
55	u_short		fid_len;		/* length of data in bytes */
56	u_short		fid_reserved;		/* force longword alignment */
57	char		fid_data[MAXFIDSZ];	/* data (variable length) */
58};
59
60/*
61 * file system statistics
62 */
63
64#define MFSNAMELEN	16	/* length of fs type name, including null */
65#ifdef __i386__
66#define	MNAMELEN	80	/* length of buffer for returned name */
67#endif
68#if defined(__alpha__) || defined(__ia64__)
69#define	MNAMELEN	72	/* length of buffer for returned name */
70#endif
71
72struct statfs {
73	long	f_spare2;		/* placeholder */
74	long	f_bsize;		/* fundamental file system block size */
75	long	f_iosize;		/* optimal transfer block size */
76	long	f_blocks;		/* total data blocks in file system */
77	long	f_bfree;		/* free blocks in fs */
78	long	f_bavail;		/* free blocks avail to non-superuser */
79	long	f_files;		/* total file nodes in file system */
80	long	f_ffree;		/* free file nodes in fs */
81	fsid_t	f_fsid;			/* file system id */
82	uid_t	f_owner;		/* user that mounted the filesystem */
83	int	f_type;			/* type of filesystem */
84	int	f_flags;		/* copy of mount exported flags */
85	long    f_syncwrites;		/* count of sync writes since mount */
86	long    f_asyncwrites;		/* count of async writes since mount */
87	char	f_fstypename[MFSNAMELEN]; /* fs type name */
88	char	f_mntonname[MNAMELEN];	/* directory on which mounted */
89	long    f_syncreads;		/* count of sync reads since mount */
90	long    f_asyncreads;		/* count of async reads since mount */
91	short	f_spares1;		/* unused spare */
92	char	f_mntfromname[MNAMELEN];/* mounted filesystem */
93	short	f_spares2;		/* unused spare */
94	long    f_spare[2];		/* unused spare */
95};
96
97#ifdef _KERNEL
98/*
99 * Structure per mounted file system.  Each mounted file system has an
100 * array of operations and an instance record.  The file systems are
101 * put on a doubly linked list.
102 */
103LIST_HEAD(vnodelst, vnode);
104
105struct mount {
106	TAILQ_ENTRY(mount) mnt_list;		/* mount list */
107	struct vfsops	*mnt_op;		/* operations on fs */
108	struct vfsconf	*mnt_vfc;		/* configuration info */
109	struct vnode	*mnt_vnodecovered;	/* vnode we mounted on */
110	struct vnode	*mnt_syncer;		/* syncer vnode */
111	struct vnodelst	mnt_vnodelist;		/* list of vnodes this mount */
112	struct lock	mnt_lock;		/* mount structure lock */
113	int		mnt_writeopcount;	/* write syscalls in progress */
114	int		mnt_flag;		/* flags shared with user */
115	int		mnt_kern_flag;		/* kernel only flags */
116	int		mnt_maxsymlinklen;	/* max size of short symlink */
117	struct statfs	mnt_stat;		/* cache of filesystem stats */
118	qaddr_t		mnt_data;		/* private data */
119	time_t		mnt_time;		/* last time written*/
120	u_int		mnt_iosize_max;		/* max IO request size */
121};
122#endif /* _KERNEL */
123
124/*
125 * User specifiable flags.
126 */
127#define	MNT_RDONLY	0x00000001	/* read only filesystem */
128#define	MNT_SYNCHRONOUS	0x00000002	/* file system written synchronously */
129#define	MNT_NOEXEC	0x00000004	/* can't exec from filesystem */
130#define	MNT_NOSUID	0x00000008	/* don't honor setuid bits on fs */
131#define	MNT_NODEV	0x00000010	/* don't interpret special files */
132#define	MNT_UNION	0x00000020	/* union with underlying filesystem */
133#define	MNT_ASYNC	0x00000040	/* file system written asynchronously */
134#define	MNT_SUIDDIR	0x00100000	/* special handling of SUID on dirs */
135#define	MNT_SOFTDEP	0x00200000	/* soft updates being done */
136#define	MNT_NOSYMFOLLOW	0x00400000	/* do not follow symlinks */
137#define	MNT_NOATIME	0x10000000	/* disable update of file access time */
138#define	MNT_NOCLUSTERR	0x40000000	/* disable cluster read */
139#define	MNT_NOCLUSTERW	0x80000000	/* disable cluster write */
140
141/*
142 * NFS export related mount flags.
143 */
144#define	MNT_EXRDONLY	0x00000080	/* exported read only */
145#define	MNT_EXPORTED	0x00000100	/* file system is exported */
146#define	MNT_DEFEXPORTED	0x00000200	/* exported to the world */
147#define	MNT_EXPORTANON	0x00000400	/* use anon uid mapping for everyone */
148#define	MNT_EXKERB	0x00000800	/* exported with Kerberos uid mapping */
149#define	MNT_EXPUBLIC	0x20000000	/* public export (WebNFS) */
150
151/*
152 * Flags set by internal operations,
153 * but visible to the user.
154 * XXX some of these are not quite right.. (I've never seen the root flag set)
155 */
156#define	MNT_LOCAL	0x00001000	/* filesystem is stored locally */
157#define	MNT_QUOTA	0x00002000	/* quotas are enabled on filesystem */
158#define	MNT_ROOTFS	0x00004000	/* identifies the root filesystem */
159#define	MNT_USER	0x00008000	/* mounted by a user */
160#define	MNT_IGNORE	0x00800000	/* do not show entry in df */
161
162/*
163 * Mask of flags that are visible to statfs()
164 * XXX I think that this could now become (~(MNT_CMDFLAGS))
165 * but the 'mount' program may need changing to handle this.
166 */
167#define	MNT_VISFLAGMASK	(MNT_RDONLY	| MNT_SYNCHRONOUS | MNT_NOEXEC	| \
168			MNT_NOSUID	| MNT_NODEV	| MNT_UNION	| \
169			MNT_ASYNC	| MNT_EXRDONLY	| MNT_EXPORTED	| \
170			MNT_DEFEXPORTED	| MNT_EXPORTANON| MNT_EXKERB	| \
171			MNT_LOCAL	| MNT_USER	| MNT_QUOTA	| \
172			MNT_ROOTFS	| MNT_NOATIME	| MNT_NOCLUSTERR| \
173			MNT_NOCLUSTERW	| MNT_SUIDDIR	| MNT_SOFTDEP	| \
174			MNT_IGNORE	| MNT_EXPUBLIC	| MNT_NOSYMFOLLOW)
175/*
176 * External filesystem command modifier flags.
177 * Unmount can use the MNT_FORCE flag.
178 * XXX These are not STATES and really should be somewhere else.
179 */
180#define	MNT_UPDATE	0x00010000	/* not a real mount, just an update */
181#define	MNT_DELEXPORT	0x00020000	/* delete export host lists */
182#define	MNT_RELOAD	0x00040000	/* reload filesystem data */
183#define	MNT_FORCE	0x00080000	/* force unmount or readonly change */
184#define	MNT_SNAPSHOT	0x01000000	/* snapshot the filesystem */
185#define MNT_CMDFLAGS   (MNT_UPDATE	| MNT_DELEXPORT	| MNT_RELOAD	| \
186			MNT_FORCE	| MNT_SNAPSHOT)
187/*
188 * Still available
189 */
190#define	MNT_SPARE1	0x02000000
191#define	MNT_SPARE2	0x04000000
192#define	MNT_SPARE3	0x08000000
193/*
194 * Internal filesystem control flags stored in mnt_kern_flag.
195 *
196 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
197 * past the mount point.  This keeps the subtree stable during mounts
198 * and unmounts.
199 */
200#define MNTK_UNMOUNT	0x01000000	/* unmount in progress */
201#define	MNTK_MWAIT	0x02000000	/* waiting for unmount to finish */
202#define MNTK_WANTRDWR	0x04000000	/* upgrade to read/write requested */
203#define	MNTK_SUSPEND	0x08000000	/* request write suspension */
204#define	MNTK_SUSPENDED	0x10000000	/* write operations are suspended */
205
206/*
207 * Sysctl CTL_VFS definitions.
208 *
209 * Second level identifier specifies which filesystem. Second level
210 * identifier VFS_VFSCONF returns information about all filesystems.
211 * Second level identifier VFS_GENERIC is non-terminal.
212 */
213#define	VFS_VFSCONF		0	/* get configured filesystems */
214#define	VFS_GENERIC		0	/* generic filesystem information */
215/*
216 * Third level identifiers for VFS_GENERIC are given below; third
217 * level identifiers for specific filesystems are given in their
218 * mount specific header files.
219 */
220#define VFS_MAXTYPENUM	1	/* int: highest defined filesystem type */
221#define VFS_CONF	2	/* struct: vfsconf for filesystem given
222				   as next argument */
223
224/*
225 * Flags for various system call interfaces.
226 *
227 * waitfor flags to vfs_sync() and getfsstat()
228 */
229#define MNT_WAIT	1	/* synchronously wait for I/O to complete */
230#define MNT_NOWAIT	2	/* start all I/O, but do not wait for it */
231#define MNT_LAZY	3	/* push data not written by filesystem syncer */
232
233/*
234 * Generic file handle
235 */
236struct fhandle {
237	fsid_t	fh_fsid;	/* File system id of mount point */
238	struct	fid fh_fid;	/* File sys specific id */
239};
240typedef struct fhandle	fhandle_t;
241
242/*
243 * Export arguments for local filesystem mount calls.
244 */
245struct export_args {
246	int	ex_flags;		/* export related flags */
247	uid_t	ex_root;		/* mapping for root uid */
248	struct	xucred ex_anon;		/* mapping for anonymous user */
249	struct	sockaddr *ex_addr;	/* net address to which exported */
250	u_char	ex_addrlen;		/* and the net address length */
251	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
252	u_char	ex_masklen;		/* and the smask length */
253	char	*ex_indexfile;		/* index file for WebNFS URLs */
254};
255
256/*
257 * Structure holding information for a publicly exported filesystem
258 * (WebNFS). Currently the specs allow just for one such filesystem.
259 */
260struct nfs_public {
261	int		np_valid;	/* Do we hold valid information */
262	fhandle_t	np_handle;	/* Filehandle for pub fs (internal) */
263	struct mount	*np_mount;	/* Mountpoint of exported fs */
264	char		*np_index;	/* Index file */
265};
266
267/*
268 * Filesystem configuration information. One of these exists for each
269 * type of filesystem supported by the kernel. These are searched at
270 * mount time to identify the requested filesystem.
271 */
272struct vfsconf {
273	struct	vfsops *vfc_vfsops;	/* filesystem operations vector */
274	char	vfc_name[MFSNAMELEN];	/* filesystem type name */
275	int	vfc_typenum;		/* historic filesystem type number */
276	int	vfc_refcount;		/* number mounted of this type */
277	int	vfc_flags;		/* permanent flags */
278	struct	vfsconf *vfc_next;	/* next in list */
279};
280
281struct ovfsconf {
282	void	*vfc_vfsops;
283	char	vfc_name[32];
284	int	vfc_index;
285	int	vfc_refcount;
286	int	vfc_flags;
287};
288
289/*
290 * NB: these flags refer to IMPLEMENTATION properties, not properties of
291 * any actual mounts; i.e., it does not make sense to change the flags.
292 */
293#define	VFCF_STATIC	0x00010000	/* statically compiled into kernel */
294#define	VFCF_NETWORK	0x00020000	/* may get data over the network */
295#define	VFCF_READONLY	0x00040000	/* writes are not implemented */
296#define VFCF_SYNTHETIC	0x00080000	/* data does not represent real files */
297#define	VFCF_LOOPBACK	0x00100000	/* aliases some other mounted FS */
298#define	VFCF_UNICODE	0x00200000	/* stores file names as Unicode*/
299
300#ifdef _KERNEL
301
302#ifdef MALLOC_DECLARE
303MALLOC_DECLARE(M_MOUNT);
304#endif
305extern int maxvfsconf;		/* highest defined filesystem type */
306extern int nfs_mount_type;	/* vfc_typenum for nfs, or -1 */
307extern struct vfsconf *vfsconf;	/* head of list of filesystem types */
308
309/*
310 * Operations supported on mounted file system.
311 */
312#ifdef __STDC__
313struct nameidata;
314struct mbuf;
315struct mount_args;
316#endif
317
318struct vfsops {
319	int	(*vfs_mount)	__P((struct mount *mp, char *path, caddr_t data,
320				    struct nameidata *ndp, struct proc *p));
321	int	(*vfs_start)	__P((struct mount *mp, int flags,
322				    struct proc *p));
323	int	(*vfs_unmount)	__P((struct mount *mp, int mntflags,
324				    struct proc *p));
325	int	(*vfs_root)	__P((struct mount *mp, struct vnode **vpp));
326	int	(*vfs_quotactl)	__P((struct mount *mp, int cmds, uid_t uid,
327				    caddr_t arg, struct proc *p));
328	int	(*vfs_statfs)	__P((struct mount *mp, struct statfs *sbp,
329				    struct proc *p));
330	int	(*vfs_sync)	__P((struct mount *mp, int waitfor,
331				    struct ucred *cred, struct proc *p));
332	int	(*vfs_vget)	__P((struct mount *mp, ino_t ino,
333				    struct vnode **vpp));
334	int	(*vfs_fhtovp)	__P((struct mount *mp, struct fid *fhp,
335				    struct vnode **vpp));
336	int	(*vfs_checkexp) __P((struct mount *mp, struct sockaddr *nam,
337				    int *extflagsp, struct ucred **credanonp));
338	int	(*vfs_vptofh)	__P((struct vnode *vp, struct fid *fhp));
339	int	(*vfs_init)	__P((struct vfsconf *));
340	int	(*vfs_uninit)	__P((struct vfsconf *));
341	int	(*vfs_extattrctl) __P((struct mount *mp, int cmd,
342					const char *attrname, caddr_t arg,
343					struct proc *p));
344};
345
346#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
347	(*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
348#define VFS_START(MP, FLAGS, P)	  (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
349#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
350#define VFS_ROOT(MP, VPP)	  (*(MP)->mnt_op->vfs_root)(MP, VPP)
351#define VFS_QUOTACTL(MP,C,U,A,P)  (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
352#define VFS_STATFS(MP, SBP, P)	  (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
353#define VFS_SYNC(MP, WAIT, C, P)  (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
354#define VFS_VGET(MP, INO, VPP)	  (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
355#define VFS_FHTOVP(MP, FIDP, VPP) \
356	(*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP)
357#define	VFS_VPTOFH(VP, FIDP)	  (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
358#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED) \
359	(*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED)
360#define VFS_EXTATTRCTL(MP, C, N, A, P) \
361	(*(MP)->mnt_op->vfs_extattrctl)(MP, C, N, A, P)
362
363#include <sys/module.h>
364
365#define VFS_SET(vfsops, fsname, flags) \
366	static struct vfsconf fsname ## _vfsconf = {		\
367		&vfsops,					\
368		#fsname,					\
369		-1,						\
370		0,						\
371		flags						\
372	};							\
373	static moduledata_t fsname ## _mod = {			\
374		#fsname,					\
375		vfs_modevent,					\
376		& fsname ## _vfsconf				\
377	};							\
378	DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE)
379
380#include <net/radix.h>
381
382#define	AF_MAX		33	/* XXX */
383
384/*
385 * Network address lookup element
386 */
387struct netcred {
388	struct	radix_node netc_rnodes[2];
389	int	netc_exflags;
390	struct	ucred netc_anon;
391};
392
393/*
394 * Network export information
395 */
396struct netexport {
397	struct	netcred ne_defexported;		      /* Default export */
398	struct	radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
399};
400
401extern	char *mountrootfsname;
402
403/*
404 * exported vnode operations
405 */
406int	dounmount __P((struct mount *, int, struct proc *));
407int	vfs_mount __P((struct proc *p, char *type, char *path, int flags,
408	    void *data));
409int	vfs_setpublicfs			    /* set publicly exported fs */
410	  __P((struct mount *, struct netexport *, struct export_args *));
411int	vfs_lock __P((struct mount *));         /* lock a vfs */
412void	vfs_msync __P((struct mount *, int));
413void	vfs_unlock __P((struct mount *));       /* unlock a vfs */
414int	vfs_busy __P((struct mount *, int, struct mtx *, struct proc *));
415int	vfs_export			    /* process mount export info */
416	  __P((struct mount *, struct netexport *, struct export_args *));
417struct	netcred *vfs_export_lookup	    /* lookup host in fs export list */
418	  __P((struct mount *, struct netexport *, struct sockaddr *));
419int	vfs_allocate_syncvnode __P((struct mount *));
420void	vfs_getnewfsid __P((struct mount *));
421dev_t	vfs_getrootfsid __P((struct mount *));
422struct	mount *vfs_getvfs __P((fsid_t *));      /* return vfs given fsid */
423int	vfs_modevent __P((module_t, int, void *));
424int	vfs_mountedon __P((struct vnode *));    /* is a vfs mounted on vp */
425int	vfs_rootmountalloc __P((char *, char *, struct mount **));
426void	vfs_unbusy __P((struct mount *, struct proc *));
427void	vfs_unmountall __P((void));
428int	vfs_register __P((struct vfsconf *));
429int	vfs_unregister __P((struct vfsconf *));
430extern	TAILQ_HEAD(mntlist, mount) mountlist;	/* mounted filesystem list */
431extern	struct mtx mountlist_mtx;
432extern	struct nfs_public nfs_pub;
433
434/*
435 * Declarations for these vfs default operations are located in
436 * kern/vfs_default.c, they should be used instead of making "dummy"
437 * functions or casting entries in the VFS op table to "enopnotsupp()".
438 */
439int	vfs_stdmount __P((struct mount *mp, char *path, caddr_t data,
440		struct nameidata *ndp, struct proc *p));
441int	vfs_stdstart __P((struct mount *mp, int flags, struct proc *p));
442int	vfs_stdunmount __P((struct mount *mp, int mntflags, struct proc *p));
443int	vfs_stdroot __P((struct mount *mp, struct vnode **vpp));
444int	vfs_stdquotactl __P((struct mount *mp, int cmds, uid_t uid,
445		caddr_t arg, struct proc *p));
446int	vfs_stdstatfs __P((struct mount *mp, struct statfs *sbp, struct proc *p));
447int	vfs_stdsync __P((struct mount *mp, int waitfor, struct ucred *cred,
448		struct proc *p));
449int	vfs_stdvget __P((struct mount *mp, ino_t ino, struct vnode **vpp));
450int	vfs_stdfhtovp __P((struct mount *mp, struct fid *fhp, struct vnode **vpp));
451int	vfs_stdcheckexp __P((struct mount *mp, struct sockaddr *nam,
452	   int *extflagsp, struct ucred **credanonp));
453int	vfs_stdvptofh __P((struct vnode *vp, struct fid *fhp));
454int	vfs_stdinit __P((struct vfsconf *));
455int	vfs_stduninit __P((struct vfsconf *));
456int	vfs_stdextattrctl __P((struct mount *mp, int cmd, const char *attrname,
457		caddr_t arg, struct proc *p));
458
459/* XXX - these should be indirect functions!!! */
460int	softdep_process_worklist __P((struct mount *));
461int	softdep_fsync __P((struct vnode *));
462#else /* !_KERNEL */
463
464#include <sys/cdefs.h>
465
466struct stat;
467
468__BEGIN_DECLS
469int	fhopen __P((const struct fhandle *, int));
470int	fhstat __P((const struct fhandle *, struct stat *));
471int	fhstatfs __P((const struct fhandle *, struct statfs *));
472int	fstatfs __P((int, struct statfs *));
473int	getfh __P((const char *, fhandle_t *));
474int	getfsstat __P((struct statfs *, long, int));
475int	getmntinfo __P((struct statfs **, int));
476int	mount __P((const char *, const char *, int, void *));
477int	statfs __P((const char *, struct statfs *));
478int	unmount __P((const char *, int));
479
480/* C library stuff */
481void	endvfsent __P((void));
482struct	ovfsconf *getvfsbyname __P((const char *));
483struct	ovfsconf *getvfsbytype __P((int));
484struct	ovfsconf *getvfsent __P((void));
485#define	getvfsbyname	new_getvfsbyname
486int	new_getvfsbyname __P((const char *, struct vfsconf *));
487void	setvfsent __P((int));
488int	vfsisloadable __P((const char *));
489int	vfsload __P((const char *));
490__END_DECLS
491
492#endif /* _KERNEL */
493
494#endif /* !_SYS_MOUNT_H_ */
495