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