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