]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/sys/mount.h
xnu-344.12.2.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#define MNT_JOURNALED 0x00800000 /* filesystem is journaled */
163
164/*
165 * NFS export related mount flags.
166 */
167#define MNT_EXRDONLY 0x00000080 /* exported read only */
168#define MNT_EXPORTED 0x00000100 /* file system is exported */
169#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
170#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
171#define MNT_EXKERB 0x00000800 /* exported with Kerberos uid mapping */
172
173/*
174 * Flags set by internal operations.
175 */
176#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
177#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
178#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
179#define MNT_DOVOLFS 0x00008000 /* FS supports volfs */
180#define MNT_FIXEDSCRIPTENCODING 0x10000000 /* FS supports only fixed script encoding [HFS] */
181
182/*
183 * XXX I think that this could now become (~(MNT_CMDFLAGS))
184 * but the 'mount' program may need changing to handle this.
185 */
186#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
187 MNT_NOSUID | MNT_NODEV | MNT_UNION | \
188 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \
189 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \
190 MNT_LOCAL | MNT_QUOTA | \
191 MNT_ROOTFS | MNT_DOVOLFS | MNT_DONTBROWSE | \
192 MNT_UNKNOWNPERMISSIONS | MNT_AUTOMOUNTED | MNT_JOURNALED | MNT_FIXEDSCRIPTENCODING )
193/*
194 * External filesystem command modifier flags.
195 * Unmount can use the MNT_FORCE flag.
196 * XXX These are not STATES and really should be somewhere else.
197 * External filesystem control flags.
198 */
199#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
200#define MNT_DELEXPORT 0x00020000 /* delete export host lists */
201#define MNT_RELOAD 0x00040000 /* reload filesystem data */
202#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
203#define MNT_CMDFLAGS (MNT_UPDATE|MNT_DELEXPORT|MNT_RELOAD|MNT_FORCE)
204
205/*
206 * Internal filesystem control flags stored in mnt_kern_flag.
207 *
208 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
209 * past the mount point. This keeps the subtree stable during mounts
210 * and unmounts.
211 */
212#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
213#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
214#define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
215#if REV_ENDIAN_FS
216#define MNT_REVEND 0x08000000 /* Reverse endian FS */
217#endif /* REV_ENDIAN_FS */
218/*
219 * Sysctl CTL_VFS definitions.
220 *
221 * Second level identifier specifies which filesystem. Second level
222 * identifier VFS_GENERIC returns information about all filesystems.
223 */
224#define VFS_GENERIC 0 /* generic filesystem information */
225#define VFS_NUMMNTOPS 1 /* int: total num of vfs mount/unmount operations */
226/*
227 * Third level identifiers for VFS_GENERIC are given below; third
228 * level identifiers for specific filesystems are given in their
229 * mount specific header files.
230 */
231#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
232#define VFS_CONF 2 /* struct: vfsconf for filesystem given
233 as next argument */
234/*
235 * Flags for various system call interfaces.
236 *
237 * waitfor flags to vfs_sync() and getfsstat()
238 */
239#define MNT_WAIT 1 /* synchronously wait for I/O to complete */
240#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
241
242/*
243 * Generic file handle
244 */
245struct fhandle {
246 fsid_t fh_fsid; /* File system id of mount point */
247 struct fid fh_fid; /* File sys specific id */
248};
249typedef struct fhandle fhandle_t;
250
251/*
252 * Export arguments for local filesystem mount calls.
253 */
254struct export_args {
255 int ex_flags; /* export related flags */
256 uid_t ex_root; /* mapping for root uid */
257 struct ucred ex_anon; /* mapping for anonymous user */
258 struct sockaddr *ex_addr; /* net address to which exported */
259 int ex_addrlen; /* and the net address length */
260 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
261 int ex_masklen; /* and the smask length */
262};
263
264#ifdef __APPLE_API_UNSTABLE
265/*
266 * Filesystem configuration information. One of these exists for each
267 * type of filesystem supported by the kernel. These are searched at
268 * mount time to identify the requested filesystem.
269 */
270struct vfsconf {
271 struct vfsops *vfc_vfsops; /* filesystem operations vector */
272 char vfc_name[MFSNAMELEN]; /* filesystem type name */
273 int vfc_typenum; /* historic filesystem type number */
274 int vfc_refcount; /* number mounted of this type */
275 int vfc_flags; /* permanent flags */
276 int (*vfc_mountroot)(void); /* if != NULL, routine to mount root */
277 struct vfsconf *vfc_next; /* next in list */
278};
279
280#endif /*__APPLE_API_UNSTABLE */
281
282#ifdef KERNEL
283#ifdef __APPLE_API_UNSTABLE
284extern int maxvfsconf; /* highest defined filesystem type */
285extern struct vfsconf *vfsconf; /* head of list of filesystem types */
286extern int maxvfsslots; /* Maximum slots available to be used */
287extern int numused_vfsslots; /* number of slots already used */
288
289int vfsconf_add __P((struct vfsconf *));
290int vfsconf_del __P((char *));
291
292/*
293 * Operations supported on mounted file system.
294 */
295#ifdef __STDC__
296struct nameidata;
297struct mbuf;
298#endif
299
300struct vfsops {
301 int (*vfs_mount) __P((struct mount *mp, char *path, caddr_t data,
302 struct nameidata *ndp, struct proc *p));
303 int (*vfs_start) __P((struct mount *mp, int flags,
304 struct proc *p));
305 int (*vfs_unmount) __P((struct mount *mp, int mntflags,
306 struct proc *p));
307 int (*vfs_root) __P((struct mount *mp, struct vnode **vpp));
308 int (*vfs_quotactl) __P((struct mount *mp, int cmds, uid_t uid,
309 caddr_t arg, struct proc *p));
310 int (*vfs_statfs) __P((struct mount *mp, struct statfs *sbp,
311 struct proc *p));
312 int (*vfs_sync) __P((struct mount *mp, int waitfor,
313 struct ucred *cred, struct proc *p));
314 int (*vfs_vget) __P((struct mount *mp, void *ino,
315 struct vnode **vpp));
316 int (*vfs_fhtovp) __P((struct mount *mp, struct fid *fhp,
317 struct mbuf *nam, struct vnode **vpp,
318 int *exflagsp, struct ucred **credanonp));
319 int (*vfs_vptofh) __P((struct vnode *vp, struct fid *fhp));
320 int (*vfs_init) __P((struct vfsconf *));
321 int (*vfs_sysctl) __P((int *, u_int, void *, size_t *, void *,
322 size_t, struct proc *));
323};
324
325#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
326 (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
327#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
328#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
329#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP)
330#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
331#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
332#define VFS_SYNC(MP, WAIT, C, P) (*(MP)->mnt_op->vfs_sync)(MP, WAIT, C, P)
333#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
334#define VFS_FHTOVP(MP, FIDP, NAM, VPP, EXFLG, CRED) \
335 (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, NAM, VPP, EXFLG, CRED)
336#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
337
338/*
339 * Network address lookup element
340 */
341struct netcred {
342 struct radix_node netc_rnodes[2];
343 int netc_exflags;
344 struct ucred netc_anon;
345};
346
347/*
348 * Network export information
349 */
350struct netexport {
351 struct netcred ne_defexported; /* Default export */
352 struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */
353};
354
355/*
356 * exported vnode operations
357 */
358int vfs_busy __P((struct mount *, int, struct slock *, struct proc *));
359int vfs_export __P((struct mount *, struct netexport *,
360 struct export_args *));
361struct netcred *vfs_export_lookup __P((struct mount *, struct netexport *,
362 struct mbuf *));
363void vfs_getnewfsid __P((struct mount *));
364struct mount *vfs_getvfs __P((fsid_t *));
365int vfs_mountedon __P((struct vnode *));
366void vfs_unbusy __P((struct mount *, struct proc *));
367#ifdef __APPLE_API_PRIVATE
368int vfs_mountroot __P((void));
369int vfs_rootmountalloc __P((char *, char *, struct mount **));
370void vfs_unmountall __P((void));
371#endif /* __APPLE_API_PRIVATE */
372extern CIRCLEQ_HEAD(mntlist, mount) mountlist;
373extern struct slock mountlist_slock;
374
375#endif /* __APPLE_API_UNSTABLE */
376#else /* !KERNEL */
377
378#include <sys/cdefs.h>
379
380__BEGIN_DECLS
381int fstatfs __P((int, struct statfs *));
382int getfh __P((const char *, fhandle_t *));
383int getfsstat __P((struct statfs *, long, int));
384int getmntinfo __P((struct statfs **, int));
385int mount __P((const char *, const char *, int, void *));
386int statfs __P((const char *, struct statfs *));
387int unmount __P((const char *, int));
388int getvfsbyname __P((const char *, struct vfsconf *));
389__END_DECLS
390
391#endif /* KERNEL */
392#endif /* !_SYS_MOUNT_H_ */