]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/sys/mount.h
xnu-344.tar.gz
[apple/xnu.git] / bsd / sys / mount.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
23/*
24 * Copyright (c) 1989, 1991, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * @(#)mount.h 8.21 (Berkeley) 5/20/95
56 */
57
58#ifndef _SYS_MOUNT_H_
59#define _SYS_MOUNT_H_
60
61#include <sys/appleapiopts.h>
62#ifndef KERNEL
63#include <sys/ucred.h>
64#endif
65#include <sys/queue.h>
66#include <sys/lock.h>
67#include <net/radix.h>
68#include <sys/socket.h> /* XXX for AF_MAX */
69
70typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
71
72/*
73 * File identifier.
74 * These are unique per filesystem on a single machine.
75 */
76#define MAXFIDSZ 16
77
78struct fid {
79 u_short fid_len; /* length of data in bytes */
80 u_short fid_reserved; /* force longword alignment */
81 char fid_data[MAXFIDSZ]; /* data (variable length) */
82};
83
84/*
85 * file system statistics
86 */
87
88#define MFSNAMELEN 15 /* length of fs type name, not inc. null */
89#define MNAMELEN 90 /* length of buffer for returned name */
90
91struct statfs {
92 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
93 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
94 long f_bsize; /* fundamental file system block size */
95 long f_iosize; /* optimal transfer block size */
96 long f_blocks; /* total data blocks in file system */
97 long f_bfree; /* free blocks in fs */
98 long f_bavail; /* free blocks avail to non-superuser */
99 long f_files; /* total file nodes in file system */
100 long f_ffree; /* free file nodes in fs */
101 fsid_t f_fsid; /* file system id */
102 uid_t f_owner; /* user that mounted the filesystem */
103 short f_reserved1; /* spare for later */
104 short f_type; /* type of filesystem */
105 long f_flags; /* copy of mount exported flags */
106 long f_reserved2[2]; /* reserved for future use */
107 char f_fstypename[MFSNAMELEN]; /* fs type name */
108 char f_mntonname[MNAMELEN]; /* directory on which mounted */
109 char f_mntfromname[MNAMELEN];/* mounted filesystem */
110#if COMPAT_GETFSSTAT
111 char f_reserved3[0]; /* For alignment */
112 long f_reserved4[0]; /* For future use */
113#else
114 char f_reserved3; /* For alignment */
115 long f_reserved4[4]; /* For future use */
116#endif
117};
118
119#ifdef __APPLE_API_PRIVATE
120/*
121 * Structure per mounted file system. Each mounted file system has an
122 * array of operations and an instance record. The file systems are
123 * put on a doubly linked list.
124 */
125LIST_HEAD(vnodelst, vnode);
126
127struct mount {
128 CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */
129 struct vfsops *mnt_op; /* operations on fs */
130 struct vfsconf *mnt_vfc; /* configuration info */
131 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
132 struct vnodelst mnt_vnodelist; /* list of vnodes this mount */
133 struct lock__bsd__ mnt_lock; /* mount structure lock */
134 int mnt_flag; /* flags */
135 int mnt_kern_flag; /* kernel only flags */
136 int mnt_maxsymlinklen; /* max size of short symlink */
137 struct statfs mnt_stat; /* cache of filesystem stats */
138 qaddr_t mnt_data; /* private data */
139 /* Cached values of the IO constraints for the device */
140 u_int32_t mnt_maxreadcnt; /* Max. byte count for read */
141 u_int32_t mnt_maxwritecnt; /* Max. byte count for write */
142 u_int16_t mnt_segreadcnt; /* Max. segment count for read */
143 u_int16_t mnt_segwritecnt; /* Max. segment count for write */
144};
145#endif /* __APPLE_API_PRIVATE */
146
147/*
148 * User specifiable flags.
149 *
150 * Unmount uses MNT_FORCE flag.
151 */
152#define MNT_RDONLY 0x00000001 /* read only filesystem */
153#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */
154#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
155#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
156#define MNT_NODEV 0x00000010 /* don't interpret special files */
157#define MNT_UNION 0x00000020 /* union with underlying filesystem */
158#define MNT_ASYNC 0x00000040 /* file system written asynchronously */
159#define MNT_DONTBROWSE 0x00100000 /* file system is not appropriate path to user data */
160#define MNT_UNKNOWNPERMISSIONS 0x00200000 /* no known mapping for uid/gid in permissions information on disk */
161#define MNT_AUTOMOUNTED 0x00400000 /* filesystem was mounted by automounter */
162
163/*
164 * NFS export related mount flags.
165 */
166#define MNT_EXRDONLY 0x00000080 /* exported read only */
167#define MNT_EXPORTED 0x00000100 /* file system is exported */
168#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
169#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
170#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */
171
172/*
173 * Flags set by internal operations.
174 */
175#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
176#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
177#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
178#define MNT_DOVOLFS 0x00008000 /* FS supports volfs */
179#define MNT_FIXEDSCRIPTENCODING 0x10000000 /* FS supports only fixed script encoding [HFS] */
180
181/*
182 * XXX I think that this could now become (~(MNT_CMDFLAGS))
183 * but the 'mount' program may need changing to handle this.
184 */
185#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
186 MNT_NOSUID | MNT_NODEV | MNT_UNION | \
187 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \
188 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \
189 MNT_LOCAL | MNT_QUOTA | \
190 MNT_ROOTFS | MNT_DOVOLFS | MNT_DONTBROWSE | \
191 MNT_UNKNOWNPERMISSIONS | MNT_AUTOMOUNTED | MNT_FIXEDSCRIPTENCODING )
192/*
193 * External filesystem command modifier flags.
194 * Unmount can use the MNT_FORCE flag.
195 * XXX These are not STATES and really should be somewhere else.
196 * External filesystem control flags.
197 */
198#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
199#define MNT_DELEXPORT 0x00020000 /* delete export host lists */
200#define MNT_RELOAD 0x00040000 /* reload filesystem data */
201#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
202#define MNT_CMDFLAGS (MNT_UPDATE|MNT_DELEXPORT|MNT_RELOAD|MNT_FORCE)
203
204/*
205 * Internal filesystem control flags stored in mnt_kern_flag.
206 *
207 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
208 * past the mount point. This keeps the subtree stable during mounts
209 * and unmounts.
210 */
211#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
212#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
213#define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
214#if REV_ENDIAN_FS
215#define MNT_REVEND 0x08000000 /* Reverse endian FS */
216#endif /* REV_ENDIAN_FS */
217/*
218 * Sysctl CTL_VFS definitions.
219 *
220 * Second level identifier specifies which filesystem. Second level
221 * identifier VFS_GENERIC returns information about all filesystems.
222 */
223#define VFS_GENERIC 0 /* generic filesystem information */
224#define VFS_NUMMNTOPS 1 /* int: total num of vfs mount/unmount operations */
225/*
226 * Third level identifiers for VFS_GENERIC are given below; third
227 * level identifiers for specific filesystems are given in their
228 * mount specific header files.
229 */
230#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
231#define VFS_CONF 2 /* struct: vfsconf for filesystem given
232 as next argument */
233/*
234 * Flags for various system call interfaces.
235 *
236 * waitfor flags to vfs_sync() and getfsstat()
237 */
238#define MNT_WAIT 1 /* synchronously wait for I/O to complete */
239#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
240
241/*
242 * Generic file handle
243 */
244struct fhandle {
245 fsid_t fh_fsid; /* File system id of mount point */
246 struct fid fh_fid; /* File sys specific id */
247};
248typedef struct fhandle fhandle_t;
249
250/*
251 * Export arguments for local filesystem mount calls.
252 */
253struct export_args {
254 int ex_flags; /* export related flags */
255 uid_t ex_root; /* mapping for root uid */
256 struct ucred ex_anon; /* mapping for anonymous user */
257 struct sockaddr *ex_addr; /* net address to which exported */
258 int ex_addrlen; /* and the net address length */
259 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
260 int ex_masklen; /* and the smask length */
261};
262
263#ifdef __APPLE_API_UNSTABLE
264/*
265 * Filesystem configuration information. One of these exists for each
266 * type of filesystem supported by the kernel. These are searched at
267 * mount time to identify the requested filesystem.
268 */
269struct vfsconf {
270 struct vfsops *vfc_vfsops; /* filesystem operations vector */
271 char vfc_name[MFSNAMELEN]; /* filesystem type name */
272 int vfc_typenum; /* historic filesystem type number */
273 int vfc_refcount; /* number mounted of this type */
274 int vfc_flags; /* permanent flags */
275 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */
276 struct vfsconf *vfc_next; /* next in list */
277};
278
279#endif /*__APPLE_API_UNSTABLE */
280
281#ifdef KERNEL
282#ifdef __APPLE_API_UNSTABLE
283extern int maxvfsconf; /* highest defined filesystem type */
284extern struct vfsconf *vfsconf; /* head of list of filesystem types */
285extern int maxvfsslots; /* Maximum slots available to be used */
286extern int numused_vfsslots; /* number of slots already used */
287
288int vfsconf_add __P((struct vfsconf *));
289int vfsconf_del __P((char *));
290
291/*
292 * Operations supported on mounted file system.
293 */
294#ifdef __STDC__
295struct nameidata;
296struct mbuf;
297#endif
298
299struct vfsops {
300 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data,
301 struct nameidata *ndp, struct proc *p));
302 int (*vfs_start) __P((struct mount *mp, int flags,
303 struct proc *p));
304 int (*vfs_unmount) __P((struct mount *mp, int mntflags,
305 struct proc *p));
306 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp));
307 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid,
308 caddr_t arg, struct proc *p));
309 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp,
310 struct proc *p));
311 int (*vfs_sync) __P((struct mount *mp, int waitfor,
312 struct ucred *cred, struct proc *p));
313 int (*vfs_vget) __P((struct mount *mp, void *ino,
314 struct vnode **vpp));
315 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp,
316 struct mbuf *nam, struct vnode **vpp,
317 int *exflagsp, struct ucred **credanonp));
318 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp));
319 int (*vfs_init) __P((struct vfsconf *));
320 int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *,
321 size_t, struct proc *));
322};
323
324#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
325 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
326#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
327#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
328#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP)
329#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
330#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
331#define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
332#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
333#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
334 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
335#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
336
337/*
338 * Network address lookup element
339 */
340struct netcred {
341 struct radix_node netc_rnodes[2];
342 int netc_exflags;
343 struct ucred netc_anon;
344};
345
346/*
347 * Network export information
348 */
349struct netexport {
350 struct netcred ne_defexported; /* Default export */
351 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
352};
353
354/*
355 * exported vnode operations
356 */
357int vfs_busy __P((struct mount *, int, struct slock *, struct proc *));
358int vfs_export __P((struct mount *, struct netexport *,
359 struct export_args *));
360struct netcred *vfs_export_lookup __P((struct mount *, struct netexport *,
361 struct mbuf *));
362void vfs_getnewfsid __P((struct mount *));
363struct mount *vfs_getvfs __P((fsid_t *));
364int vfs_mountedon __P((struct vnode *));
365void vfs_unbusy __P((struct mount *, struct proc *));
366#ifdef __APPLE_API_PRIVATE
367int vfs_mountroot __P((void));
368int vfs_rootmountalloc __P((char *, char *, struct mount **));
369void vfs_unmountall __P((void));
370#endif /* __APPLE_API_PRIVATE */
371extern CIRCLEQ_HEAD(mntlist, mount) mountlist;
372extern struct slock mountlist_slock;
373
374#endif /* __APPLE_API_UNSTABLE */
375#else /* !KERNEL */
376
377#include <sys/cdefs.h>
378
379__BEGIN_DECLS
380int fstatfs __P((int, struct statfs *));
381int getfh __P((const char *, fhandle_t *));
382int getfsstat __P((struct statfs *, long, int));
383int getmntinfo __P((struct statfs **, int));
384int mount __P((const char *, const char *, int, void *));
385int statfs __P((const char *, struct statfs *));
386int unmount __P((const char *, int));
387int getvfsbyname __P((const char *, struct vfsconf *));
388__END_DECLS
389
390#endif /* KERNEL */
391#endif /* !_SYS_MOUNT_H_ */