mount.h revision 3151
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.10 1994/09/22 01:05:03 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 struct vfsconf *vfsconf[];
212
213#ifdef __STDC__
214struct nameidata;
215struct mbuf;
216#endif
217
218struct vfsops {
219	int	(*vfs_mount)	__P((struct mount *mp, char *path, caddr_t data,
220				    struct nameidata *ndp, struct proc *p));
221	int	(*vfs_start)	__P((struct mount *mp, int flags,
222				    struct proc *p));
223	int	(*vfs_unmount)	__P((struct mount *mp, int mntflags,
224				    struct proc *p));
225	int	(*vfs_root)	__P((struct mount *mp, struct vnode **vpp));
226	int	(*vfs_quotactl)	__P((struct mount *mp, int cmds, uid_t uid,
227				    caddr_t arg, struct proc *p));
228	int	(*vfs_statfs)	__P((struct mount *mp, struct statfs *sbp,
229				    struct proc *p));
230	int	(*vfs_sync)	__P((struct mount *mp, int waitfor,
231				    struct ucred *cred, struct proc *p));
232	int	(*vfs_vget)	__P((struct mount *mp, ino_t ino,
233				    struct vnode **vpp));
234	int	(*vfs_fhtovp)	__P((struct mount *mp, struct fid *fhp,
235				    struct mbuf *nam, struct vnode **vpp,
236				    int *exflagsp, struct ucred **credanonp));
237	int	(*vfs_vptofh)	__P((struct vnode *vp, struct fid *fhp));
238	int	(*vfs_init)	__P((void));
239};
240
241#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
242	(*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
243#define VFS_START(MP, FLAGS, P)	  (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
244#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
245#define VFS_ROOT(MP, VPP)	  (*(MP)->mnt_op->vfs_root)(MP, VPP)
246#define VFS_QUOTACTL(MP,C,U,A,P)  (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
247#define VFS_STATFS(MP, SBP, P)	  (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
248#define VFS_SYNC(MP, WAIT, C, P)  (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
249#define VFS_VGET(MP, INO, VPP)	  (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
250#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
251	(*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
252#define	VFS_VPTOFH(VP, FIDP)	  (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
253
254#ifdef VFS_LKM
255#include <sys/conf.h>
256#include <sys/exec.h>
257#include <sys/sysent.h>
258#include <sys/lkm.h>
259
260#define VFS_SET(vfsops, fsname, index, flags) \
261	static struct vfsconf _fs_vfsops = { \
262		&vfsops, \
263		#fsname, \
264		index, \
265		0, \
266		flags \
267	}; \
268	extern struct linker_set MODVNOPS; \
269	MOD_VFS(#fsname,index,&MODVNOPS,&_fs_vfsops); \
270	int \
271	fsname ## _mod(struct lkm_table *lkmtp, int cmd, int ver) { \
272		DISPATCH(lkmtp, cmd, ver, nosys, nosys, nosys); }
273#else
274
275#define VFS_SET(vfsops, fsname, index, flags) \
276	static struct vfsconf _fs_vfsops = { \
277		&vfsops, \
278		#fsname, \
279		index, \
280		1, \
281		flags \
282	}; \
283	DATA_SET(vfs_set,_fs_vfsops)
284#endif /* VFS_LKM */
285
286#endif /* KERNEL */
287
288/*
289 * Flags for various system call interfaces.
290 *
291 * waitfor flags to vfs_sync() and getfsstat()
292 */
293#define MNT_WAIT	1
294#define MNT_NOWAIT	2
295
296/*
297 * Generic file handle
298 */
299struct fhandle {
300	fsid_t	fh_fsid;	/* File system id of mount point */
301	struct	fid fh_fid;	/* File sys specific id */
302};
303typedef struct fhandle	fhandle_t;
304
305#ifdef KERNEL
306#include <net/radix.h>
307#include <sys/socket.h>		/* XXX for AF_MAX */
308
309/*
310 * Network address lookup element
311 */
312struct netcred {
313	struct	radix_node netc_rnodes[2];
314	int	netc_exflags;
315	struct	ucred netc_anon;
316};
317
318/*
319 * Network export information
320 */
321struct netexport {
322	struct	netcred ne_defexported;		      /* Default export */
323	struct	radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
324};
325#endif /* KERNEL */
326
327/*
328 * Export arguments for local filesystem mount calls.
329 */
330struct export_args {
331	int	ex_flags;		/* export related flags */
332	uid_t	ex_root;		/* mapping for root uid */
333	struct	ucred ex_anon;		/* mapping for anonymous user */
334	struct	sockaddr *ex_addr;	/* net address to which exported */
335	int	ex_addrlen;		/* and the net address length */
336	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
337	int	ex_masklen;		/* and the smask length */
338};
339
340/*
341 * Arguments to mount UFS-based filesystems
342 */
343struct ufs_args {
344	char	*fspec;			/* block special device to mount */
345	struct	export_args export;	/* network export information */
346};
347
348#ifdef MFS
349/*
350 * Arguments to mount MFS
351 */
352struct mfs_args {
353	char	*fspec;			/* name to export for statfs */
354	struct	export_args export;	/* if exported MFSes are supported */
355	caddr_t	base;			/* base of file system in memory */
356	u_long size;			/* size of file system */
357};
358#endif /* MFS */
359
360#ifdef MSDOSFS
361/*
362 *  Arguments to mount MSDOS filesystems.
363 */
364struct msdosfs_args {
365	char	*fspec;		/* blocks special holding the fs to mount */
366	struct	export_args export;	/* network export information */
367	uid_t	uid;		/* uid that owns msdosfs files */
368	gid_t	gid;		/* gid that owns msdosfs files */
369	mode_t	mask;		/* mask to be applied for msdosfs perms */
370};
371#endif
372
373#ifdef CD9660
374/*
375 * Arguments to mount ISO 9660 filesystems.
376 */
377struct iso_args {
378	char *fspec;			/* block special device to mount */
379	struct	export_args export;	/* network export info */
380	int flags;			/* mounting flags, see below */
381
382};
383#define ISOFSMNT_NORRIP		0x00000001 /* disable Rock Ridge Ext.*/
384#define ISOFSMNT_GENS		0x00000002 /* enable generation numbers */
385#define ISOFSMNT_EXTATT		0x00000004 /* enable extended attributes */
386#endif /* CD9660 */
387
388#ifdef NFS
389/*
390 * File Handle (32 bytes for version 2), variable up to 1024 for version 3
391 */
392union nfsv2fh {
393	fhandle_t	fh_generic;
394	u_char		fh_bytes[32];
395};
396typedef union nfsv2fh nfsv2fh_t;
397
398/*
399 * Arguments to mount NFS
400 */
401struct nfs_args {
402	struct sockaddr	*addr;		/* file server address */
403	int		addrlen;	/* length of address */
404	int		sotype;		/* Socket type */
405	int		proto;		/* and Protocol */
406	nfsv2fh_t	*fh;		/* File handle to be mounted */
407	int		flags;		/* flags */
408	int		wsize;		/* write size in bytes */
409	int		rsize;		/* read size in bytes */
410	int		timeo;		/* initial timeout in .1 secs */
411	int		retrans;	/* times to retry send */
412	int		maxgrouplist;	/* Max. size of group list */
413	int		readahead;	/* # of blocks to readahead */
414	int		leaseterm;	/* Term (sec) of lease */
415	int		deadthresh;	/* Retrans threshold */
416	char		*hostname;	/* server's name */
417};
418
419
420/*
421 * NFS mount option flags
422 */
423#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
424#define	NFSMNT_WSIZE		0x00000002  /* set write size */
425#define	NFSMNT_RSIZE		0x00000004  /* set read size */
426#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
427#define	NFSMNT_RETRANS		0x00000010  /* set number of request retrys */
428#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
429#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
430#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
431#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
432#define	NFSMNT_MYWRITE		0x00000200  /* Assume writes were mine */
433#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
434#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
435#define	NFSMNT_RDIRALOOK	0x00001000  /* Do lookup with readdir (nqnfs) */
436#define	NFSMNT_LEASETERM	0x00002000  /* set lease term (nqnfs) */
437#define	NFSMNT_READAHEAD	0x00004000  /* set read ahead */
438#define	NFSMNT_DEADTHRESH	0x00008000  /* set dead server retry thresh */
439#define	NFSMNT_NQLOOKLEASE	0x00010000  /* Get lease for lookup */
440#define	NFSMNT_RESVPORT		0x00020000  /* Allocate a reserved port */
441#define	NFSMNT_INTERNAL		0xffe00000  /* Bits set internally */
442#define	NFSMNT_MNTD		0x00200000  /* Mnt server for mnt point */
443#define	NFSMNT_DISMINPROG	0x00400000  /* Dismount in progress */
444#define	NFSMNT_DISMNT		0x00800000  /* Dismounted */
445#define	NFSMNT_SNDLOCK		0x01000000  /* Send socket lock */
446#define	NFSMNT_WANTSND		0x02000000  /* Want above */
447#define	NFSMNT_RCVLOCK		0x04000000  /* Rcv socket lock */
448#define	NFSMNT_WANTRCV		0x08000000  /* Want above */
449#define	NFSMNT_WAITAUTH		0x10000000  /* Wait for authentication */
450#define	NFSMNT_HASAUTH		0x20000000  /* Has authenticator */
451#define	NFSMNT_WANTAUTH		0x40000000  /* Wants an authenticator */
452#define	NFSMNT_AUTHERR		0x80000000  /* Authentication error */
453#endif /* NFS */
454
455#ifdef KERNEL
456/*
457 * exported vnode operations
458 */
459int	dounmount __P((struct mount *, int, struct proc *));
460struct	mount *getvfs __P((fsid_t *));      /* return vfs given fsid */
461int	vflush __P((struct mount *mp, struct vnode *skipvp, int flags));
462int	vfs_export			    /* process mount export info */
463	  __P((struct mount *, struct netexport *, struct export_args *));
464struct	netcred *vfs_export_lookup	    /* lookup host in fs export list */
465	  __P((struct mount *, struct netexport *, struct mbuf *));
466int	vfs_lock __P((struct mount *));         /* lock a vfs */
467int	vfs_mountedon __P((struct vnode *));    /* is a vfs mounted on vp */
468void	vfs_unlock __P((struct mount *));       /* unlock a vfs */
469int	vfs_busy __P((struct mount *));         /* mark a vfs  busy */
470void	vfs_unbusy __P((struct mount *));       /* mark a vfs not busy */
471extern	TAILQ_HEAD(mntlist, mount) mountlist;	/* mounted filesystem list */
472extern	struct vfsops *vfssw[];			/* filesystem type table */
473
474#else /* KERNEL */
475
476#include <sys/cdefs.h>
477
478__BEGIN_DECLS
479int	fstatfs __P((int, struct statfs *));
480int	getfh __P((const char *, fhandle_t *));
481int	getfsstat __P((struct statfs *, long, int));
482int	getmntinfo __P((struct statfs **, int));
483int	mount __P((int, const char *, int, void *));
484int	statfs __P((const char *, struct statfs *));
485int	unmount __P((const char *, int));
486
487/* C library stuff */
488struct	vfsconf *getvfsbyname __P((const char *));
489struct	vfsconf *getvfsbytype __P((int));
490struct	vfsconf *getvfsent __P((void));
491void	setvfsent __P((int));
492void	endvfsent __P((void));
493int	vfsisloadable __P((const char *));
494int	vfsload __P((const char *));
495__END_DECLS
496
497#endif /* KERNEL */
498
499#endif /* !_SYS_MOUNT_H_ */
500