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