xref: /original-bsd/sys/sys/mount.h (revision 898c7514)
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.20 (Berkeley) 05/10/95
8  */
9 
10 #ifndef KERNEL
11 #include <sys/ucred.h>
12 #endif
13 #include <sys/queue.h>
14 #include <net/radix.h>
15 #include <sys/socket.h>		/* XXX for AF_MAX */
16 
17 typedef struct { int32_t val[2]; } fsid_t;	/* file system id type */
18 
19 /*
20  * File identifier.
21  * These are unique per filesystem on a single machine.
22  */
23 #define	MAXFIDSZ	16
24 
25 struct fid {
26 	u_short		fid_len;		/* length of data in bytes */
27 	u_short		fid_reserved;		/* force longword alignment */
28 	char		fid_data[MAXFIDSZ];	/* data (variable length) */
29 };
30 
31 /*
32  * file system statistics
33  */
34 
35 #define MFSNAMELEN	16	/* length of fs type name, including null */
36 #define	MNAMELEN	90	/* length of buffer for returned name */
37 
38 struct statfs {
39 	short	f_type;			/* filesystem type number */
40 	short	f_flags;		/* copy of mount flags */
41 	long	f_bsize;		/* fundamental file system block size */
42 	long	f_iosize;		/* optimal transfer block size */
43 	long	f_blocks;		/* total data blocks in file system */
44 	long	f_bfree;		/* free blocks in fs */
45 	long	f_bavail;		/* free blocks avail to non-superuser */
46 	long	f_files;		/* total file nodes in file system */
47 	long	f_ffree;		/* free file nodes in fs */
48 	fsid_t	f_fsid;			/* file system id */
49 	uid_t	f_owner;		/* user that mounted the filesystem */
50 	long	f_spare[4];		/* spare for later */
51 	char	f_fstypename[MFSNAMELEN]; /* fs type name */
52 	char	f_mntonname[MNAMELEN];	/* directory on which mounted */
53 	char	f_mntfromname[MNAMELEN];/* mounted filesystem */
54 };
55 
56 /*
57  * Structure per mounted file system.  Each mounted file system has an
58  * array of operations and an instance record.  The file systems are
59  * put on a doubly linked list.
60  */
61 LIST_HEAD(vnodelst, vnode);
62 
63 struct mount {
64 	CIRCLEQ_ENTRY(mount) mnt_list;		/* mount list */
65 	struct vfsops	*mnt_op;		/* operations on fs */
66 	struct vfsconf	*mnt_vfc;		/* configuration info */
67 	struct vnode	*mnt_vnodecovered;	/* vnode we mounted on */
68 	struct vnodelst	mnt_vnodelist;		/* list of vnodes this mount */
69 	int		mnt_flag;		/* flags */
70 	int		mnt_maxsymlinklen;	/* max size of short symlink */
71 	struct statfs	mnt_stat;		/* cache of filesystem stats */
72 	qaddr_t		mnt_data;		/* private data */
73 };
74 
75 /*
76  * Mount flags.
77  *
78  * Unmount uses MNT_FORCE flag.
79  */
80 #define	MNT_RDONLY	0x00000001	/* read only filesystem */
81 #define	MNT_SYNCHRONOUS	0x00000002	/* file system written synchronously */
82 #define	MNT_NOEXEC	0x00000004	/* can't exec from filesystem */
83 #define	MNT_NOSUID	0x00000008	/* don't honor setuid bits on fs */
84 #define	MNT_NODEV	0x00000010	/* don't interpret special files */
85 #define	MNT_UNION	0x00000020	/* union with underlying filesystem */
86 #define	MNT_ASYNC	0x00000040	/* file system written asynchronously */
87 
88 /*
89  * exported mount flags.
90  */
91 #define	MNT_EXRDONLY	0x00000080	/* exported read only */
92 #define	MNT_EXPORTED	0x00000100	/* file system is exported */
93 #define	MNT_DEFEXPORTED	0x00000200	/* exported to the world */
94 #define	MNT_EXPORTANON	0x00000400	/* use anon uid mapping for everyone */
95 #define	MNT_EXKERB	0x00000800	/* exported with Kerberos uid mapping */
96 
97 /*
98  * Flags set by internal operations.
99  */
100 #define	MNT_LOCAL	0x00001000	/* filesystem is stored locally */
101 #define	MNT_QUOTA	0x00002000	/* quotas are enabled on filesystem */
102 #define	MNT_ROOTFS	0x00004000	/* identifies the root filesystem */
103 
104 /*
105  * Mask of flags that are visible to statfs()
106  */
107 #define	MNT_VISFLAGMASK	0x0000ffff
108 
109 /*
110  * filesystem control flags.
111  *
112  * MNT_MLOCK lock the mount entry so that name lookup cannot proceed
113  * past the mount point.  This keeps the subtree stable during mounts
114  * and unmounts.
115  */
116 #define	MNT_UPDATE	0x00010000	/* not a real mount, just an update */
117 #define	MNT_DELEXPORT	0x00020000	/* delete export host lists */
118 #define	MNT_RELOAD	0x00040000	/* reload filesystem data */
119 #define	MNT_FORCE	0x00080000	/* force unmount or readonly change */
120 #define	MNT_MLOCK	0x00100000	/* lock so that subtree is stable */
121 #define	MNT_MWAIT	0x00200000	/* someone is waiting for lock */
122 #define MNT_MPBUSY	0x00400000	/* scan of mount point in progress */
123 #define MNT_MPWANT	0x00800000	/* waiting for mount point */
124 #define MNT_UNMOUNT	0x01000000	/* unmount in progress */
125 #define MNT_WANTRDWR	0x02000000	/* want upgrade to read/write */
126 
127 /*
128  * Sysctl CTL_VFS definitions.
129  *
130  * Second level identifier specifies which filesystem. Second level
131  * identifier VFS_GENERIC returns information about all filesystems.
132  */
133 #define	VFS_GENERIC		0	/* generic filesystem information */
134 /*
135  * Third level identifiers for VFS_GENERIC are given below; third
136  * level identifiers for specific filesystems are given in their
137  * mount specific header files.
138  */
139 #define VFS_MAXTYPENUM	1	/* int: highest defined filesystem type */
140 #define VFS_CONF	2	/* struct: vfsconf for filesystem given
141 				   as next argument */
142 
143 /*
144  * Flags for various system call interfaces.
145  *
146  * waitfor flags to vfs_sync() and getfsstat()
147  */
148 #define MNT_WAIT	1
149 #define MNT_NOWAIT	2
150 
151 /*
152  * Generic file handle
153  */
154 struct fhandle {
155 	fsid_t	fh_fsid;	/* File system id of mount point */
156 	struct	fid fh_fid;	/* File sys specific id */
157 };
158 typedef struct fhandle	fhandle_t;
159 
160 /*
161  * Export arguments for local filesystem mount calls.
162  */
163 struct export_args {
164 	int	ex_flags;		/* export related flags */
165 	uid_t	ex_root;		/* mapping for root uid */
166 	struct	ucred ex_anon;		/* mapping for anonymous user */
167 	struct	sockaddr *ex_addr;	/* net address to which exported */
168 	int	ex_addrlen;		/* and the net address length */
169 	struct	sockaddr *ex_mask;	/* mask of valid bits in saddr */
170 	int	ex_masklen;		/* and the smask length */
171 };
172 
173 /*
174  * Filesystem configuration information. One of these exists for each
175  * type of filesystem supported by the kernel. These are searched at
176  * mount time to identify the requested filesystem.
177  */
178 struct vfsconf {
179 	struct	vfsops *vfc_vfsops;	/* filesystem operations vector */
180 	char	vfc_name[MFSNAMELEN];	/* filesystem type name */
181 	int	vfc_typenum;		/* historic filesystem type number */
182 	int	vfc_refcount;		/* number mounted of this type */
183 	int	vfc_flags;		/* permanent flags */
184 	int	(*vfc_mountroot)(void);	/* if != NULL, routine to mount root */
185 	struct	vfsconf *vfc_next;	/* next in list */
186 };
187 
188 #ifdef KERNEL
189 
190 extern int maxvfsconf;		/* highest defined filesystem type */
191 extern struct vfsconf *vfsconf;	/* head of list of filesystem types */
192 
193 /*
194  * Operations supported on mounted file system.
195  */
196 #ifdef __STDC__
197 struct nameidata;
198 struct mbuf;
199 #endif
200 
201 struct vfsops {
202 	int	(*vfs_mount)	__P((struct mount *mp, char *path, caddr_t data,
203 				    struct nameidata *ndp, struct proc *p));
204 	int	(*vfs_start)	__P((struct mount *mp, int flags,
205 				    struct proc *p));
206 	int	(*vfs_unmount)	__P((struct mount *mp, int mntflags,
207 				    struct proc *p));
208 	int	(*vfs_root)	__P((struct mount *mp, struct vnode **vpp));
209 	int	(*vfs_quotactl)	__P((struct mount *mp, int cmds, uid_t uid,
210 				    caddr_t arg, struct proc *p));
211 	int	(*vfs_statfs)	__P((struct mount *mp, struct statfs *sbp,
212 				    struct proc *p));
213 	int	(*vfs_sync)	__P((struct mount *mp, int waitfor,
214 				    struct ucred *cred, struct proc *p));
215 	int	(*vfs_vget)	__P((struct mount *mp, ino_t ino,
216 				    struct vnode **vpp));
217 	int	(*vfs_fhtovp)	__P((struct mount *mp, struct fid *fhp,
218 				    struct mbuf *nam, struct vnode **vpp,
219 				    int *exflagsp, struct ucred **credanonp));
220 	int	(*vfs_vptofh)	__P((struct vnode *vp, struct fid *fhp));
221 	int	(*vfs_init)	__P((struct vfsconf *));
222 	int	(*vfs_sysctl)	__P((int *, u_int, void *, size_t *, void *,
223 				    size_t, struct proc *));
224 };
225 
226 #define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
227 	(*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
228 #define VFS_START(MP, FLAGS, P)	  (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
229 #define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
230 #define VFS_ROOT(MP, VPP)	  (*(MP)->mnt_op->vfs_root)(MP, VPP)
231 #define VFS_QUOTACTL(MP,C,U,A,P)  (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
232 #define VFS_STATFS(MP, SBP, P)	  (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
233 #define VFS_SYNC(MP, WAIT, C, P)  (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
234 #define VFS_VGET(MP, INO, VPP)	  (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
235 #define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
236 	(*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
237 #define	VFS_VPTOFH(VP, FIDP)	  (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
238 
239 /*
240  * Network address lookup element
241  */
242 struct netcred {
243 	struct	radix_node netc_rnodes[2];
244 	int	netc_exflags;
245 	struct	ucred netc_anon;
246 };
247 
248 /*
249  * Network export information
250  */
251 struct netexport {
252 	struct	netcred ne_defexported;		      /* Default export */
253 	struct	radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
254 };
255 
256 /*
257  * exported vnode operations
258  */
259 int	vfs_export			    /* process mount export info */
260 	  __P((struct mount *, struct netexport *, struct export_args *));
261 struct	mount *vfs_getvfs __P((fsid_t *));      /* return vfs given fsid */
262 struct	netcred *vfs_export_lookup	    /* lookup host in fs export list */
263 	  __P((struct mount *, struct netexport *, struct mbuf *));
264 void	vfs_getnewfsid __P((struct mount *));   /* create a unique fsid */
265 int	vfs_lock __P((struct mount *));     /* lock a vfs */
266 int	vfs_mountedon __P((struct vnode *));/* is a vfs mounted on vp */
267 int	vfs_mountroot __P((void));	    /* find and mount root filesystem */
268 int	vfs_rootmountalloc		    /* alloc root mount structure */
269 	  __P((char *, char *, struct mount **));
270 void	vfs_unlock __P((struct mount *));   /* unlock a vfs */
271 void	vfs_unmountall __P((void));	    /* unmount all filesystems */
272 extern	CIRCLEQ_HEAD(mntlist, mount) mountlist;	/* mounted filesystem list */
273 
274 #else /* !KERNEL */
275 
276 #include <sys/cdefs.h>
277 
278 __BEGIN_DECLS
279 int	fstatfs __P((int, struct statfs *));
280 int	getfh __P((const char *, fhandle_t *));
281 int	getfsstat __P((struct statfs *, long, int));
282 int	getmntinfo __P((struct statfs **, int));
283 int	mount __P((const char *, const char *, int, void *));
284 int	statfs __P((const char *, struct statfs *));
285 int	unmount __P((const char *, int));
286 __END_DECLS
287 
288 #endif /* KERNEL */
289