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