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