mount.h revision 7090
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.13 (Berkeley) 3/27/94
34 * $Id: mount.h,v 1.12 1994/10/20 00:48:21 wollman Exp $
35 */
36
37#ifndef _SYS_MOUNT_H_
38#define _SYS_MOUNT_H_
39
40#ifndef KERNEL
41#include <sys/ucred.h>
42#endif
43#include <sys/queue.h>
44
45typedef struct { long val[2]; } fsid_t;		/* file system id type */
46
47/*
48 * File identifier.
49 * These are unique per filesystem on a single machine.
50 */
51#define	MAXFIDSZ	16
52
53struct fid {
54	u_short		fid_len;		/* length of data in bytes */
55	u_short		fid_reserved;		/* force longword alignment */
56	char		fid_data[MAXFIDSZ];	/* data (variable length) */
57};
58
59/*
60 * file system statistics
61 */
62
63#define MNAMELEN 90	/* length of buffer for returned name */
64
65struct statfs {
66	short	f_type;			/* type of filesystem (see below) */
67	short	f_flags;		/* copy of mount flags */
68	long	f_bsize;		/* fundamental file system block size */
69	long	f_iosize;		/* optimal transfer block size */
70	long	f_blocks;		/* total data blocks in file system */
71	long	f_bfree;		/* free blocks in fs */
72	long	f_bavail;		/* free blocks avail to non-superuser */
73	long	f_files;		/* total file nodes in file system */
74	long	f_ffree;		/* free file nodes in fs */
75	fsid_t	f_fsid;			/* file system id */
76	long	f_spare[9];		/* spare for later */
77	char	f_mntonname[MNAMELEN];	/* directory on which mounted */
78	char	f_mntfromname[MNAMELEN];/* mounted filesystem */
79};
80
81/*
82 * File system types.
83 */
84#define	MOUNT_NONE	0
85#define	MOUNT_UFS	1	/* Fast Filesystem */
86#define	MOUNT_NFS	2	/* Sun-compatible Network Filesystem */
87#define	MOUNT_MFS	3	/* Memory-based Filesystem */
88#define	MOUNT_MSDOS	4	/* MS/DOS Filesystem */
89#define	MOUNT_LFS	5	/* Log-based Filesystem */
90#define	MOUNT_LOFS	6	/* Loopback Filesystem */
91#define	MOUNT_FDESC	7	/* File Descriptor Filesystem */
92#define	MOUNT_PORTAL	8	/* Portal Filesystem */
93#define MOUNT_NULL	9	/* Minimal Filesystem Layer */
94#define MOUNT_UMAP	10	/* User/Group Identifer Remapping Filesystem */
95#define MOUNT_KERNFS	11	/* Kernel Information Filesystem */
96#define MOUNT_PROCFS	12	/* /proc Filesystem */
97#define MOUNT_AFS	13	/* Andrew Filesystem */
98#define MOUNT_CD9660	14	/* ISO9660 (aka CDROM) Filesystem */
99#define MOUNT_UNION	15	/* Union (translucent) Filesystem */
100#define	MOUNT_MAXTYPE	15
101
102#define INITMOUNTNAMES { \
103	"none",		/*  0 MOUNT_NONE */ \
104	"ufs",		/*  1 MOUNT_UFS */ \
105	"nfs",		/*  2 MOUNT_NFS */ \
106	"mfs",		/*  3 MOUNT_MFS */ \
107	"msdos",	/*  4 MOUNT_MSDOS */ \
108	"lfs",		/*  5 MOUNT_LFS */ \
109	"lofs",		/*  6 MOUNT_LOFS */ \
110	"fdesc",	/*  7 MOUNT_FDESC */ \
111	"portal",	/*  8 MOUNT_PORTAL */ \
112	"null",		/*  9 MOUNT_NULL */ \
113	"umap",		/* 10 MOUNT_UMAP */ \
114	"kernfs",	/* 11 MOUNT_KERNFS */ \
115	"procfs",	/* 12 MOUNT_PROCFS */ \
116	"afs",		/* 13 MOUNT_AFS */ \
117	"iso9660fs",	/* 14 MOUNT_CD9660 */ \
118	"union",	/* 15 MOUNT_UNION */ \
119	0,		/* 16 MOUNT_SPARE */ \
120}
121
122/*
123 * Structure per mounted file system.  Each mounted file system has an
124 * array of operations and an instance record.  The file systems are
125 * put on a doubly linked list.
126 */
127LIST_HEAD(vnodelst, vnode);
128
129struct mount {
130	TAILQ_ENTRY(mount) mnt_list;		/* mount list */
131	struct vfsops	*mnt_op;		/* operations on fs */
132	struct vnode	*mnt_vnodecovered;	/* vnode we mounted on */
133	struct vnodelst	mnt_vnodelist;		/* list of vnodes this mount */
134	int		mnt_flag;		/* flags */
135	int		mnt_maxsymlinklen;	/* max size of short symlink */
136	struct statfs	mnt_stat;		/* cache of filesystem stats */
137	qaddr_t		mnt_data;		/* private data */
138	struct vfsconf	*mnt_vfc; 		/* configuration info */
139};
140
141/*
142 * Mount flags.
143 *
144 * Unmount uses MNT_FORCE flag.
145 */
146#define	MNT_RDONLY	0x00000001	/* read only filesystem */
147#define	MNT_SYNCHRONOUS	0x00000002	/* file system written synchronously */
148#define	MNT_NOEXEC	0x00000004	/* can't exec from filesystem */
149#define	MNT_NOSUID	0x00000008	/* don't honor setuid bits on fs */
150#define	MNT_NODEV	0x00000010	/* don't interpret special files */
151#define	MNT_UNION	0x00000020	/* union with underlying filesystem */
152#define	MNT_ASYNC	0x00000040	/* file system written asynchronously */
153
154/*
155 * exported mount flags.
156 */
157#define	MNT_EXRDONLY	0x00000080	/* exported read only */
158#define	MNT_EXPORTED	0x00000100	/* file system is exported */
159#define	MNT_DEFEXPORTED	0x00000200	/* exported to the world */
160#define	MNT_EXPORTANON	0x00000400	/* use anon uid mapping for everyone */
161#define	MNT_EXKERB	0x00000800	/* exported with Kerberos uid mapping */
162
163/*
164 * Flags set by internal operations.
165 */
166#define	MNT_LOCAL	0x00001000	/* filesystem is stored locally */
167#define	MNT_QUOTA	0x00002000	/* quotas are enabled on filesystem */
168#define	MNT_ROOTFS	0x00004000	/* identifies the root filesystem */
169#define	MNT_USER	0x00008000	/* mounted by a user */
170
171/*
172 * Mask of flags that are visible to statfs()
173 */
174#define	MNT_VISFLAGMASK	0x0000ffff
175
176/*
177 * filesystem control flags.
178 *
179 * MNT_MLOCK lock the mount entry so that name lookup cannot proceed
180 * past the mount point.  This keeps the subtree stable during mounts
181 * and unmounts.
182 */
183#define	MNT_UPDATE	0x00010000	/* not a real mount, just an update */
184#define	MNT_DELEXPORT	0x00020000	/* delete export host lists */
185#define	MNT_RELOAD	0x00040000	/* reload filesystem data */
186#define	MNT_FORCE	0x00080000	/* force unmount or readonly change */
187#define	MNT_MLOCK	0x00100000	/* lock so that subtree is stable */
188#define	MNT_MWAIT	0x00200000	/* someone is waiting for lock */
189#define MNT_MPBUSY	0x00400000	/* scan of mount point in progress */
190#define MNT_MPWANT	0x00800000	/* waiting for mount point */
191#define MNT_UNMOUNT	0x01000000	/* unmount in progress */
192#define MNT_WANTRDWR	0x02000000	/* want upgrade to read/write */
193
194/*
195 * used to get configured filesystems information
196 */
197#define VFS_MAXNAMELEN 32
198struct vfsconf {
199	void *vfc_vfsops;
200	char vfc_name[VFS_MAXNAMELEN];
201	int vfc_index;
202	int vfc_refcount;
203	int vfc_flags;
204};
205
206/*
207 * Operations supported on mounted file system.
208 */
209#ifdef KERNEL
210
211extern	int	doforce;	/* Flag to permit forcible unmounting. */
212extern struct vfsconf void_vfsconf;
213extern struct vfsconf *vfsconf[];
214
215#ifdef __STDC__
216struct nameidata;
217struct mbuf;
218#endif
219
220struct vfsops {
221	int	(*vfs_mount)	__P((struct mount *mp, char *path, caddr_t data,
222				    struct nameidata *ndp, struct proc *p));
223	int	(*vfs_start)	__P((struct mount *mp, int flags,
224				    struct proc *p));
225	int	(*vfs_unmount)	__P((struct mount *mp, int mntflags,
226				    struct proc *p));
227	int	(*vfs_root)	__P((struct mount *mp, struct vnode **vpp));
228	int	(*vfs_quotactl)	__P((struct mount *mp, int cmds, uid_t uid,
229				    caddr_t arg, struct proc *p));
230	int	(*vfs_statfs)	__P((struct mount *mp, struct statfs *sbp,
231				    struct proc *p));
232	int	(*vfs_sync)	__P((struct mount *mp, int waitfor,
233				    struct ucred *cred, struct proc *p));
234	int	(*vfs_vget)	__P((struct mount *mp, ino_t ino,
235				    struct vnode **vpp));
236	int	(*vfs_fhtovp)	__P((struct mount *mp, struct fid *fhp,
237				    struct mbuf *nam, struct vnode **vpp,
238				    int *exflagsp, struct ucred **credanonp));
239	int	(*vfs_vptofh)	__P((struct vnode *vp, struct fid *fhp));
240	int	(*vfs_init)	__P((void));
241	int	(*vfs_sysctl)	__P((int *, u_int, void *, size_t *, void *, size_t,
242				     struct proc *));
243};
244
245#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
246	(*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
247#define VFS_START(MP, FLAGS, P)	  (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
248#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
249#define VFS_ROOT(MP, VPP)	  (*(MP)->mnt_op->vfs_root)(MP, VPP)
250#define VFS_QUOTACTL(MP,C,U,A,P)  (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
251#define VFS_STATFS(MP, SBP, P)	  (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
252#define VFS_SYNC(MP, WAIT, C, P)  (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
253#define VFS_VGET(MP, INO, VPP)	  (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
254#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
255	(*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
256#define	VFS_VPTOFH(VP, FIDP)	  (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
257
258#ifdef VFS_LKM
259#include <sys/conf.h>
260#include <sys/exec.h>
261#include <sys/sysent.h>
262#include <sys/lkm.h>
263
264#define VFS_SET(vfsops, fsname, index, flags) \
265	static struct vfsconf _fs_vfsops = { \
266		&vfsops, \
267		#fsname, \
268		index, \
269		0, \
270		flags \
271	}; \
272	extern struct linker_set MODVNOPS; \
273	MOD_VFS(#fsname,index,&MODVNOPS,&_fs_vfsops); \
274	int \
275	fsname ## _mod(struct lkm_table *lkmtp, int cmd, int ver) { \
276		DISPATCH(lkmtp, cmd, ver, nosys, nosys, nosys); }
277#else
278
279#define VFS_SET(vfsops, fsname, index, flags) \
280	static struct vfsconf _fs_vfsops = { \
281		&vfsops, \
282		#fsname, \
283		index, \
284		1, \
285		flags \
286	}; \
287	DATA_SET(vfs_set,_fs_vfsops)
288#endif /* VFS_LKM */
289
290#endif /* KERNEL */
291
292/*
293 * Flags for various system call interfaces.
294 *
295 * waitfor flags to vfs_sync() and getfsstat()
296 */
297#define MNT_WAIT	1
298#define MNT_NOWAIT	2
299
300/*
301 * Generic file handle
302 */
303struct fhandle {
304	fsid_t	fh_fsid;	/* File system id of mount point */
305	struct	fid fh_fid;	/* File sys specific id */
306};
307typedef struct fhandle	fhandle_t;
308
309#ifdef KERNEL
310#include <net/radix.h>
311#include <sys/socket.h>		/* XXX for AF_MAX */
312
313/*
314 * Network address lookup element
315 */
316struct netcred {
317	struct	radix_node netc_rnodes[2];
318	int	netc_exflags;
319	struct	ucred netc_anon;
320};
321
322/*
323 * Network export information
324 */
325struct netexport {
326	struct	netcred ne_defexported;		      /* Default export */
327	struct	radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
328};
329#endif /* KERNEL */
330
331/*
332 * Export arguments for local filesystem mount calls.
333 */
334struct export_args {
335	int	ex_flags;		/* export related flags */
336	uid_t	ex_root;		/* mapping for root uid */
337	struct	ucred ex_anon;		/* mapping for anonymous user */
338	struct	sockaddr *ex_addr;	/* net address to which exported */
339	int	ex_addrlen;		/* and the net address length */
340	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
341	int	ex_masklen;		/* and the smask length */
342};
343
344/*
345 * Arguments to mount UFS-based filesystems
346 */
347struct ufs_args {
348	char	*fspec;			/* block special device to mount */
349	struct	export_args export;	/* network export information */
350};
351
352#ifdef MFS
353/*
354 * Arguments to mount MFS
355 */
356struct mfs_args {
357	char	*fspec;			/* name to export for statfs */
358	struct	export_args export;	/* if exported MFSes are supported */
359	caddr_t	base;			/* base of file system in memory */
360	u_long size;			/* size of file system */
361};
362#endif /* MFS */
363
364#ifdef MSDOSFS
365/*
366 *  Arguments to mount MSDOS filesystems.
367 */
368struct msdosfs_args {
369	char	*fspec;		/* blocks special holding the fs to mount */
370	struct	export_args export;	/* network export information */
371	uid_t	uid;		/* uid that owns msdosfs files */
372	gid_t	gid;		/* gid that owns msdosfs files */
373	mode_t	mask;		/* mask to be applied for msdosfs perms */
374};
375#endif
376
377#ifdef CD9660
378/*
379 * Arguments to mount ISO 9660 filesystems.
380 */
381struct iso_args {
382	char *fspec;			/* block special device to mount */
383	struct	export_args export;	/* network export info */
384	int flags;			/* mounting flags, see below */
385
386};
387#define ISOFSMNT_NORRIP		0x00000001 /* disable Rock Ridge Ext.*/
388#define ISOFSMNT_GENS		0x00000002 /* enable generation numbers */
389#define ISOFSMNT_EXTATT		0x00000004 /* enable extended attributes */
390#endif /* CD9660 */
391
392#ifdef NFS
393/*
394 * File Handle (32 bytes for version 2), variable up to 1024 for version 3
395 */
396union nfsv2fh {
397	fhandle_t	fh_generic;
398	u_char		fh_bytes[32];
399};
400typedef union nfsv2fh nfsv2fh_t;
401
402/*
403 * Arguments to mount NFS
404 */
405struct nfs_args {
406	struct sockaddr	*addr;		/* file server address */
407	int		addrlen;	/* length of address */
408	int		sotype;		/* Socket type */
409	int		proto;		/* and Protocol */
410	nfsv2fh_t	*fh;		/* File handle to be mounted */
411	int		flags;		/* flags */
412	int		wsize;		/* write size in bytes */
413	int		rsize;		/* read size in bytes */
414	int		timeo;		/* initial timeout in .1 secs */
415	int		retrans;	/* times to retry send */
416	int		maxgrouplist;	/* Max. size of group list */
417	int		readahead;	/* # of blocks to readahead */
418	int		leaseterm;	/* Term (sec) of lease */
419	int		deadthresh;	/* Retrans threshold */
420	char		*hostname;	/* server's name */
421};
422
423
424/*
425 * NFS mount option flags
426 */
427#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
428#define	NFSMNT_WSIZE		0x00000002  /* set write size */
429#define	NFSMNT_RSIZE		0x00000004  /* set read size */
430#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
431#define	NFSMNT_RETRANS		0x00000010  /* set number of request retrys */
432#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
433#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
434#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
435#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
436#define	NFSMNT_MYWRITE		0x00000200  /* Assume writes were mine */
437#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
438#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
439#define	NFSMNT_RDIRALOOK	0x00001000  /* Do lookup with readdir (nqnfs) */
440#define	NFSMNT_LEASETERM	0x00002000  /* set lease term (nqnfs) */
441#define	NFSMNT_READAHEAD	0x00004000  /* set read ahead */
442#define	NFSMNT_DEADTHRESH	0x00008000  /* set dead server retry thresh */
443#define	NFSMNT_NQLOOKLEASE	0x00010000  /* Get lease for lookup */
444#define	NFSMNT_RESVPORT		0x00020000  /* Allocate a reserved port */
445#define	NFSMNT_INTERNAL		0xffe00000  /* Bits set internally */
446#define	NFSMNT_MNTD		0x00200000  /* Mnt server for mnt point */
447#define	NFSMNT_DISMINPROG	0x00400000  /* Dismount in progress */
448#define	NFSMNT_DISMNT		0x00800000  /* Dismounted */
449#define	NFSMNT_SNDLOCK		0x01000000  /* Send socket lock */
450#define	NFSMNT_WANTSND		0x02000000  /* Want above */
451#define	NFSMNT_RCVLOCK		0x04000000  /* Rcv socket lock */
452#define	NFSMNT_WANTRCV		0x08000000  /* Want above */
453#define	NFSMNT_WAITAUTH		0x10000000  /* Wait for authentication */
454#define	NFSMNT_HASAUTH		0x20000000  /* Has authenticator */
455#define	NFSMNT_WANTAUTH		0x40000000  /* Wants an authenticator */
456#define	NFSMNT_AUTHERR		0x80000000  /* Authentication error */
457#endif /* NFS */
458
459#ifdef KERNEL
460extern	int (*mountroot) __P((void));
461
462/*
463 * exported vnode operations
464 */
465int	dounmount __P((struct mount *, int, struct proc *));
466struct	mount *getvfs __P((fsid_t *));      /* return vfs given fsid */
467void	getnewfsid __P((struct mount *mp, int mtype));
468int	vflush __P((struct mount *mp, struct vnode *skipvp, int flags));
469int	vfs_export			    /* process mount export info */
470	  __P((struct mount *, struct netexport *, struct export_args *));
471struct	netcred *vfs_export_lookup	    /* lookup host in fs export list */
472	  __P((struct mount *, struct netexport *, struct mbuf *));
473int	vfs_lock __P((struct mount *));         /* lock a vfs */
474int	vfs_mountedon __P((struct vnode *));    /* is a vfs mounted on vp */
475void	vfs_unlock __P((struct mount *));       /* unlock a vfs */
476void	vfs_unmountall __P((void));
477int	vfs_busy __P((struct mount *));         /* mark a vfs  busy */
478void	vfs_unbusy __P((struct mount *));       /* mark a vfs not busy */
479extern	TAILQ_HEAD(mntlist, mount) mountlist;	/* mounted filesystem list */
480extern	struct vfsops *vfssw[];			/* filesystem type table */
481
482#else /* KERNEL */
483
484#include <sys/cdefs.h>
485
486__BEGIN_DECLS
487int	fstatfs __P((int, struct statfs *));
488int	getfh __P((const char *, fhandle_t *));
489int	getfsstat __P((struct statfs *, long, int));
490int	getmntinfo __P((struct statfs **, int));
491int	mount __P((int, const char *, int, void *));
492int	statfs __P((const char *, struct statfs *));
493int	unmount __P((const char *, int));
494
495/* C library stuff */
496struct	vfsconf *getvfsbyname __P((const char *));
497struct	vfsconf *getvfsbytype __P((int));
498struct	vfsconf *getvfsent __P((void));
499void	setvfsent __P((int));
500void	endvfsent __P((void));
501int	vfsisloadable __P((const char *));
502int	vfsload __P((const char *));
503__END_DECLS
504
505#endif /* KERNEL */
506
507#endif /* !_SYS_MOUNT_H_ */
508