]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/mount.h
xnu-1504.7.4.tar.gz
[apple/xnu.git] / bsd / sys / mount.h
CommitLineData
1c79356b 1/*
593a1d5f 2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29/*
30 * Copyright (c) 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)mount.h 8.21 (Berkeley) 5/20/95
62 */
2d21ac55
A
63/*
64 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
65 * support for mandatory and extensible security protections. This notice
66 * is included in support of clause 2.2 (b) of the Apple Public License,
67 * Version 2.0.
68 */
69
1c79356b
A
70
71#ifndef _SYS_MOUNT_H_
72#define _SYS_MOUNT_H_
73
9bccf70c 74#include <sys/appleapiopts.h>
91447636
A
75#include <sys/cdefs.h>
76#include <sys/attr.h> /* needed for vol_capabilities_attr_t */
77
1c79356b 78#ifndef KERNEL
91447636 79#include <stdint.h>
1c79356b 80#include <sys/ucred.h>
91447636 81#include <sys/queue.h> /* XXX needed for user builds */
593a1d5f 82#include <Availability.h>
91447636
A
83#else
84#include <sys/kernel_types.h>
b0d623f7 85#include <uuid/uuid.h>
1c79356b 86#endif
1c79356b
A
87
88typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
89
1c79356b
A
90/*
91 * file system statistics
92 */
93
94#define MFSNAMELEN 15 /* length of fs type name, not inc. null */
2d21ac55 95#define MFSTYPENAMELEN 16 /* length of fs type name including null */
b0d623f7
A
96
97#if __DARWIN_64_BIT_INO_T
98#define MNAMELEN MAXPATHLEN /* length of buffer for returned name */
99#else /* ! __DARWIN_64_BIT_INO_T */
100#define MNAMELEN 90 /* length of buffer for returned name */
101#endif /* __DARWIN_64_BIT_INO_T */
1c79356b 102
2d21ac55
A
103#define __DARWIN_STRUCT_STATFS64 { \
104 uint32_t f_bsize; /* fundamental file system block size */ \
105 int32_t f_iosize; /* optimal transfer block size */ \
106 uint64_t f_blocks; /* total data blocks in file system */ \
107 uint64_t f_bfree; /* free blocks in fs */ \
108 uint64_t f_bavail; /* free blocks avail to non-superuser */ \
109 uint64_t f_files; /* total file nodes in file system */ \
110 uint64_t f_ffree; /* free file nodes in fs */ \
111 fsid_t f_fsid; /* file system id */ \
112 uid_t f_owner; /* user that mounted the filesystem */ \
113 uint32_t f_type; /* type of filesystem */ \
114 uint32_t f_flags; /* copy of mount exported flags */ \
115 uint32_t f_fssubtype; /* fs sub-type (flavor) */ \
116 char f_fstypename[MFSTYPENAMELEN]; /* fs type name */ \
117 char f_mntonname[MAXPATHLEN]; /* directory on which mounted */ \
118 char f_mntfromname[MAXPATHLEN]; /* mounted filesystem */ \
119 uint32_t f_reserved[8]; /* For future use */ \
120}
121
593a1d5f
A
122#if !__DARWIN_ONLY_64_BIT_INO_T
123
2d21ac55
A
124struct statfs64 __DARWIN_STRUCT_STATFS64;
125
593a1d5f
A
126#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
127
2d21ac55
A
128#if __DARWIN_64_BIT_INO_T
129
130struct statfs __DARWIN_STRUCT_STATFS64;
131
132#else /* !__DARWIN_64_BIT_INO_T */
133
91447636
A
134/*
135 * LP64 - WARNING - must be kept in sync with struct user_statfs in mount_internal.h.
136 */
1c79356b
A
137struct statfs {
138 short f_otype; /* TEMPORARY SHADOW COPY OF f_type */
139 short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */
140 long f_bsize; /* fundamental file system block size */
141 long f_iosize; /* optimal transfer block size */
142 long f_blocks; /* total data blocks in file system */
143 long f_bfree; /* free blocks in fs */
144 long f_bavail; /* free blocks avail to non-superuser */
145 long f_files; /* total file nodes in file system */
146 long f_ffree; /* free file nodes in fs */
147 fsid_t f_fsid; /* file system id */
148 uid_t f_owner; /* user that mounted the filesystem */
149 short f_reserved1; /* spare for later */
150 short f_type; /* type of filesystem */
2d21ac55 151 long f_flags; /* copy of mount exported flags */
1c79356b
A
152 long f_reserved2[2]; /* reserved for future use */
153 char f_fstypename[MFSNAMELEN]; /* fs type name */
154 char f_mntonname[MNAMELEN]; /* directory on which mounted */
155 char f_mntfromname[MNAMELEN];/* mounted filesystem */
1c79356b
A
156 char f_reserved3; /* For alignment */
157 long f_reserved4[4]; /* For future use */
1c79356b
A
158};
159
2d21ac55 160#endif /* __DARWIN_64_BIT_INO_T */
91447636 161
0c530ab8 162#pragma pack(4)
91447636
A
163
164struct vfsstatfs {
165 uint32_t f_bsize; /* fundamental file system block size */
166 size_t f_iosize; /* optimal transfer block size */
167 uint64_t f_blocks; /* total data blocks in file system */
168 uint64_t f_bfree; /* free blocks in fs */
169 uint64_t f_bavail; /* free blocks avail to non-superuser */
170 uint64_t f_bused; /* free blocks avail to non-superuser */
171 uint64_t f_files; /* total file nodes in file system */
172 uint64_t f_ffree; /* free file nodes in fs */
173 fsid_t f_fsid; /* file system id */
174 uid_t f_owner; /* user that mounted the filesystem */
175 uint64_t f_flags; /* copy of mount exported flags */
176 char f_fstypename[MFSTYPENAMELEN];/* fs type name inclus */
177 char f_mntonname[MAXPATHLEN];/* directory on which mounted */
178 char f_mntfromname[MAXPATHLEN];/* mounted filesystem */
179 uint32_t f_fssubtype; /* fs sub-type (flavor) */
180 void *f_reserved[2]; /* For future use == 0 */
181};
182
0c530ab8 183#pragma pack()
91447636 184
2d21ac55
A
185#ifdef KERNEL
186/*
187 * Kernel level support for the VFS_GETATTR(), VFS_SETATTR() for use in
188 * implementation of filesystem KEXTs, and by the vfs_getattr() and
189 * vfs_setattr() KPIs.
190 */
191
91447636
A
192#define VFSATTR_INIT(s) ((s)->f_supported = (s)->f_active = 0LL)
193#define VFSATTR_SET_SUPPORTED(s, a) ((s)->f_supported |= VFSATTR_ ## a)
194#define VFSATTR_IS_SUPPORTED(s, a) ((s)->f_supported & VFSATTR_ ## a)
195#define VFSATTR_CLEAR_ACTIVE(s, a) ((s)->f_active &= ~VFSATTR_ ## a)
196#define VFSATTR_IS_ACTIVE(s, a) ((s)->f_active & VFSATTR_ ## a)
197#define VFSATTR_ALL_SUPPORTED(s) (((s)->f_active & (s)->f_supported) == (s)->f_active)
198#define VFSATTR_WANTED(s, a) ((s)->f_active |= VFSATTR_ ## a)
199#define VFSATTR_RETURN(s, a, x) do { (s)-> a = (x); VFSATTR_SET_SUPPORTED(s, a);} while(0)
200
201#define VFSATTR_f_objcount (1LL<< 0)
202#define VFSATTR_f_filecount (1LL<< 1)
203#define VFSATTR_f_dircount (1LL<< 2)
204#define VFSATTR_f_maxobjcount (1LL<< 3)
205#define VFSATTR_f_bsize (1LL<< 4)
206#define VFSATTR_f_iosize (1LL<< 5)
207#define VFSATTR_f_blocks (1LL<< 6)
208#define VFSATTR_f_bfree (1LL<< 7)
209#define VFSATTR_f_bavail (1LL<< 8)
210#define VFSATTR_f_bused (1LL<< 9)
211#define VFSATTR_f_files (1LL<< 10)
212#define VFSATTR_f_ffree (1LL<< 11)
213#define VFSATTR_f_fsid (1LL<< 12)
214#define VFSATTR_f_owner (1LL<< 13)
215#define VFSATTR_f_capabilities (1LL<< 14)
216#define VFSATTR_f_attributes (1LL<< 15)
217#define VFSATTR_f_create_time (1LL<< 16)
218#define VFSATTR_f_modify_time (1LL<< 17)
219#define VFSATTR_f_access_time (1LL<< 18)
220#define VFSATTR_f_backup_time (1LL<< 19)
221#define VFSATTR_f_fssubtype (1LL<< 20)
222#define VFSATTR_f_vol_name (1LL<< 21)
223#define VFSATTR_f_signature (1LL<< 22)
224#define VFSATTR_f_carbon_fsid (1LL<< 23)
b0d623f7 225#define VFSATTR_f_uuid (1LL<< 24)
91447636 226
1c79356b 227/*
2d21ac55 228 * Argument structure.
1c79356b 229 */
0c530ab8 230#pragma pack(4)
b0d623f7
A
231/*
232 * Note: the size of the vfs_attr structure can change.
233 * A kext should only reference the fields that are
234 * marked as active; it should not depend on the actual
235 * size of the structure or attempt to copy it.
236 */
91447636
A
237struct vfs_attr {
238 uint64_t f_supported;
239 uint64_t f_active;
240
241 uint64_t f_objcount; /* number of filesystem objects in volume */
242 uint64_t f_filecount; /* ... files */
243 uint64_t f_dircount; /* ... directories */
244 uint64_t f_maxobjcount; /* maximum number of filesystem objects */
245
246 uint32_t f_bsize; /* block size for the below size values */
247 size_t f_iosize; /* optimal transfer block size */
248 uint64_t f_blocks; /* total data blocks in file system */
249 uint64_t f_bfree; /* free blocks in fs */
250 uint64_t f_bavail; /* free blocks avail to non-superuser */
251 uint64_t f_bused; /* blocks in use */
252 uint64_t f_files; /* total file nodes in file system */
253 uint64_t f_ffree; /* free file nodes in fs */
254 fsid_t f_fsid; /* file system id */
255 uid_t f_owner; /* user that mounted the filesystem */
256
257 vol_capabilities_attr_t f_capabilities;
258 vol_attributes_attr_t f_attributes;
259
260 struct timespec f_create_time; /* creation time */
261 struct timespec f_modify_time; /* last modification time */
262 struct timespec f_access_time; /* time of last access */
263 struct timespec f_backup_time; /* last backup time */
264
265 uint32_t f_fssubtype; /* filesystem subtype */
266
267 char *f_vol_name; /* volume name */
268
269 uint16_t f_signature; /* used for ATTR_VOL_SIGNATURE, Carbon's FSVolumeInfo.signature */
270 uint16_t f_carbon_fsid; /* same as Carbon's FSVolumeInfo.filesystemID */
b0d623f7 271 uuid_t f_uuid; /* file system UUID (version 3 or 5), available in 10.6 and later */
1c79356b 272};
91447636 273
0c530ab8 274#pragma pack()
1c79356b 275
2d21ac55
A
276#endif /* KERNEL */
277
1c79356b
A
278/*
279 * User specifiable flags.
280 *
281 * Unmount uses MNT_FORCE flag.
282 */
283#define MNT_RDONLY 0x00000001 /* read only filesystem */
284#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */
285#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
286#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
287#define MNT_NODEV 0x00000010 /* don't interpret special files */
288#define MNT_UNION 0x00000020 /* union with underlying filesystem */
289#define MNT_ASYNC 0x00000040 /* file system written asynchronously */
d1ecb069 290#define MNT_CPROTECT 0x00000080 /* file system supports content protection */
1c79356b
A
291
292/*
293 * NFS export related mount flags.
294 */
1c79356b 295#define MNT_EXPORTED 0x00000100 /* file system is exported */
b7266188
A
296#ifdef PRIVATE
297#define MNT_IMGSRC 0x00000200
298#endif /* CONFIG_IMGSRC_ACCESS */
1c79356b 299
2d21ac55
A
300/*
301 * MAC labeled / "quarantined" flag
302 */
303#define MNT_QUARANTINE 0x00000400 /* file system is quarantined */
304
1c79356b
A
305/*
306 * Flags set by internal operations.
307 */
308#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
309#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
310#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
2d21ac55
A
311#define MNT_DOVOLFS 0x00008000 /* FS supports volfs (deprecated flag in Mac OS X 10.5) */
312
313
314#define MNT_DONTBROWSE 0x00100000 /* file system is not appropriate path to user data */
315#define MNT_IGNORE_OWNERSHIP 0x00200000 /* VFS will ignore ownership information on filesystem objects */
316#define MNT_AUTOMOUNTED 0x00400000 /* filesystem was mounted by automounter */
317#define MNT_JOURNALED 0x00800000 /* filesystem is journaled */
318#define MNT_NOUSERXATTR 0x01000000 /* Don't allow user extended attributes */
319#define MNT_DEFWRITE 0x02000000 /* filesystem should defer writes */
320#define MNT_MULTILABEL 0x04000000 /* MAC support for individual labels */
321#define MNT_NOATIME 0x10000000 /* disable update of file access time */
322
323/* backwards compatibility only */
324#define MNT_UNKNOWNPERMISSIONS MNT_IGNORE_OWNERSHIP
325
1c79356b
A
326
327/*
328 * XXX I think that this could now become (~(MNT_CMDFLAGS))
329 * but the 'mount' program may need changing to handle this.
330 */
331#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
332 MNT_NOSUID | MNT_NODEV | MNT_UNION | \
2d21ac55
A
333 MNT_ASYNC | MNT_EXPORTED | MNT_QUARANTINE | \
334 MNT_LOCAL | MNT_QUOTA | \
1c79356b 335 MNT_ROOTFS | MNT_DOVOLFS | MNT_DONTBROWSE | \
2d21ac55 336 MNT_IGNORE_OWNERSHIP | MNT_AUTOMOUNTED | MNT_JOURNALED | \
d1ecb069 337 MNT_NOUSERXATTR | MNT_DEFWRITE | MNT_MULTILABEL | MNT_NOATIME | MNT_CPROTECT )
1c79356b
A
338/*
339 * External filesystem command modifier flags.
340 * Unmount can use the MNT_FORCE flag.
341 * XXX These are not STATES and really should be somewhere else.
342 * External filesystem control flags.
343 */
344#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
1c79356b
A
345#define MNT_RELOAD 0x00040000 /* reload filesystem data */
346#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
91447636
A
347#define MNT_CMDFLAGS (MNT_UPDATE|MNT_RELOAD|MNT_FORCE)
348
349
1c79356b 350
1c79356b
A
351/*
352 * Sysctl CTL_VFS definitions.
353 *
354 * Second level identifier specifies which filesystem. Second level
355 * identifier VFS_GENERIC returns information about all filesystems.
356 */
357#define VFS_GENERIC 0 /* generic filesystem information */
358#define VFS_NUMMNTOPS 1 /* int: total num of vfs mount/unmount operations */
359/*
360 * Third level identifiers for VFS_GENERIC are given below; third
361 * level identifiers for specific filesystems are given in their
362 * mount specific header files.
363 */
364#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
365#define VFS_CONF 2 /* struct: vfsconf for filesystem given
366 as next argument */
91447636 367#define VFS_SET_PACKAGE_EXTS 3 /* set package extension list */
55e303ae 368
1c79356b
A
369/*
370 * Flags for various system call interfaces.
371 *
372 * waitfor flags to vfs_sync() and getfsstat()
373 */
b0d623f7 374#define MNT_WAIT 1 /* synchronized I/O file integrity completion */
1c79356b 375#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
b0d623f7 376#define MNT_DWAIT 4 /* synchronized I/O data integrity completion */
1c79356b 377
1c79356b 378
91447636
A
379#ifndef KERNEL
380struct mount;
381typedef struct mount * mount_t;
382struct vnode;
383typedef struct vnode * vnode_t;
384#endif
1c79356b 385
b0d623f7 386/* Reserved fields preserve binary compatibility */
1c79356b 387struct vfsconf {
b0d623f7 388 uint32_t vfc_reserved1; /* opaque */
1c79356b
A
389 char vfc_name[MFSNAMELEN]; /* filesystem type name */
390 int vfc_typenum; /* historic filesystem type number */
391 int vfc_refcount; /* number mounted of this type */
392 int vfc_flags; /* permanent flags */
b0d623f7
A
393 uint32_t vfc_reserved2; /* opaque */
394 uint32_t vfc_reserved3; /* opaque */
1c79356b
A
395};
396
55e303ae
A
397struct vfsidctl {
398 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */
399 fsid_t vc_fsid; /* fsid to operate on. */
400 void *vc_ptr; /* pointer to data structure. */
401 size_t vc_len; /* sizeof said structure. */
402 u_int32_t vc_spare[12]; /* spare (must be zero). */
403};
404
91447636 405
55e303ae
A
406/* vfsidctl API version. */
407#define VFS_CTL_VERS1 0x01
408
91447636 409#ifdef KERNEL
91447636
A
410struct user_vfsidctl {
411 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */
412 fsid_t vc_fsid; /* fsid to operate on. */
0c530ab8 413 user_addr_t vc_ptr __attribute((aligned(8))); /* pointer to data structure. */
91447636
A
414 user_size_t vc_len; /* sizeof said structure. */
415 u_int32_t vc_spare[12]; /* spare (must be zero). */
416};
417
b0d623f7
A
418struct user32_vfsidctl {
419 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */
420 fsid_t vc_fsid; /* fsid to operate on. */
421 user32_addr_t vc_ptr; /* pointer to data structure. */
422 user32_size_t vc_len; /* sizeof said structure. */
423 u_int32_t vc_spare[12]; /* spare (must be zero). */
424};
425
426union union_vfsidctl { /* the fields vc_vers and vc_fsid are compatible */
427 struct user32_vfsidctl vc32;
428 struct user_vfsidctl vc64;
429};
430
91447636
A
431#endif /* KERNEL */
432
55e303ae
A
433/*
434 * New style VFS sysctls, do not reuse/conflict with the namespace for
435 * private sysctls.
436 */
437#define VFS_CTL_STATFS 0x00010001 /* statfs */
438#define VFS_CTL_UMOUNT 0x00010002 /* unmount */
439#define VFS_CTL_QUERY 0x00010003 /* anything wrong? (vfsquery) */
440#define VFS_CTL_NEWADDR 0x00010004 /* reconnect to new address */
441#define VFS_CTL_TIMEO 0x00010005 /* set timeout for vfs notification */
e5568f75 442#define VFS_CTL_NOLOCKS 0x00010006 /* disable file locking */
55e303ae
A
443
444struct vfsquery {
445 u_int32_t vq_flags;
446 u_int32_t vq_spare[31];
447};
448
449/* vfsquery flags */
450#define VQ_NOTRESP 0x0001 /* server down */
451#define VQ_NEEDAUTH 0x0002 /* server bad auth */
452#define VQ_LOWDISK 0x0004 /* we're low on space */
453#define VQ_MOUNT 0x0008 /* new filesystem arrived */
454#define VQ_UNMOUNT 0x0010 /* filesystem has left */
455#define VQ_DEAD 0x0020 /* filesystem is dead, needs force unmount */
91447636 456#define VQ_ASSIST 0x0040 /* filesystem needs assistance from external program */
e5568f75 457#define VQ_NOTRESPLOCK 0x0080 /* server lockd down */
91447636 458#define VQ_UPDATE 0x0100 /* filesystem information has changed */
b0d623f7
A
459#define VQ_VERYLOWDISK 0x0200 /* file system has *very* little disk space left */
460#define VQ_SYNCEVENT 0x0400 /* a sync just happened */
55e303ae
A
461#define VQ_FLAG0800 0x0800 /* placeholder */
462#define VQ_FLAG1000 0x1000 /* placeholder */
463#define VQ_FLAG2000 0x2000 /* placeholder */
464#define VQ_FLAG4000 0x4000 /* placeholder */
465#define VQ_FLAG8000 0x8000 /* placeholder */
466
55e303ae 467
9bccf70c 468#ifdef KERNEL
1c79356b 469
91447636
A
470/* Structure for setting device IO parameters per mount point */
471struct vfsioattr {
472 u_int32_t io_maxreadcnt; /* Max. byte count for read */
473 u_int32_t io_maxwritecnt; /* Max. byte count for write */
474 u_int32_t io_segreadcnt; /* Max. segment count for read */
475 u_int32_t io_segwritecnt; /* Max. segment count for write */
476 u_int32_t io_maxsegreadsize; /* Max. segment read size */
477 u_int32_t io_maxsegwritesize; /* Max. segment write size */
478 u_int32_t io_devblocksize; /* the underlying device block size */
2d21ac55
A
479 u_int32_t io_flags; /* flags for underlying device */
480 void * io_reserved[2]; /* extended attribute information */
91447636
A
481};
482
2d21ac55 483#define VFS_IOATTR_FLAGS_FUA 0x01 /* Write-through cache supported */
1c79356b
A
484
485/*
91447636 486 * Filesystem Registration information
1c79356b 487 */
2d21ac55
A
488#define VFS_TBLTHREADSAFE 0x0001
489#define VFS_TBLFSNODELOCK 0x0002
490#define VFS_TBLNOTYPENUM 0x0008
491#define VFS_TBLLOCALVOL 0x0010
492#define VFS_TBL64BITREADY 0x0020
493#define VFS_TBLNATIVEXATTR 0x0040
494#define VFS_TBLDIRLINKS 0x0080
495#define VFS_TBLUNMOUNT_PREFLIGHT 0x0100 /* does a preflight check before unmounting */
496#define VFS_TBLGENERICMNTARGS 0x0200 /* force generic mount args for local fs */
497#define VFS_TBLREADDIR_EXTENDED 0x0400 /* fs supports VNODE_READDIR_EXTENDED */
498#define VFS_TBLNOMACLABEL 0x1000
b0d623f7
A
499#define VFS_TBLVNOP_PAGEINV2 0x2000
500#define VFS_TBLVNOP_PAGEOUTV2 0x4000
501
91447636
A
502
503struct vfs_fsentry {
504 struct vfsops * vfe_vfsops; /* vfs operations */
505 int vfe_vopcnt; /* # of vnodeopv_desc being registered (reg, spec, fifo ...) */
506 struct vnodeopv_desc ** vfe_opvdescs; /* null terminated; */
507 int vfe_fstypenum; /* historic filesystem type number */
508 char vfe_fsname[MFSNAMELEN]; /* filesystem type name */
509 uint32_t vfe_flags; /* defines the FS capabilities */
510 void * vfe_reserv[2]; /* reserved for future use; set this to zero*/
511 };
512
513
1c79356b
A
514
515struct vfsops {
b0d623f7
A
516 /*!
517 @function vfs_mount
518 @abstract Perform filesystem-specific operations required for mounting.
519 @discussion Typical operations include setting the mount-specific data with vfs_setfsprivate().
520 Note that if a mount call fails, the filesystem must clean up any state it has constructed, because
521 vfs-level mount code will not clean it up.
522 @param mp Mount structure for the newly mounted filesystem.
523 @param devvp Device that the filesystem is mounted from.
524 @param data Filesystem-specific data passed down from userspace.
525 @param context Context to authenticate for mount.
526 @return 0 for success, else an error code. Once success is returned, the filesystem should be ready to go active;
527 VFS will not ask again.
528 */
91447636 529 int (*vfs_mount)(struct mount *mp, vnode_t devvp, user_addr_t data, vfs_context_t context);
b0d623f7
A
530
531 /*!
532 @function vfs_start
533 @abstract Mark a mount as ready to be used.
534 @discussion After receiving this calldown, a filesystem will be hooked into the mount list and should expect
535 calls down from the VFS layer.
536 @param mp Mount structure being activated.
537 @param flags Unused.
538 @param context Context to authenticate for mount.
539 @return Return value is ignored.
540 */
91447636 541 int (*vfs_start)(struct mount *mp, int flags, vfs_context_t context);
b0d623f7
A
542
543 /*!
544 @function vfs_unmount
545 @abstract Perform filesystem-specific cleanup as part of unmount.
546 @discussion If the unmount downcall succeeds, VFS considers itself authorized to destroy all
547 state related to the mount.
548 @param mp Mount structure to unmount.
549 @param mntflags MNT_FORCE indicates that we wish to unmount even if there are active vnodes.
550 @param context Context to authenticate for unmount.
551 @return 0 for success, else an error code.
552 */
91447636 553 int (*vfs_unmount)(struct mount *mp, int mntflags, vfs_context_t context);
b0d623f7
A
554
555 /*!
556 @function vfs_root
557 @abstract Get the root vnode of a filesystem.
558 @discussion Upon success, should return with an iocount held on the root vnode which the caller will
559 drop with vnode_put().
560 @param mp Mount for which to get the root.
561 @param vpp Destination for root vnode.
562 @param context Context to authenticate for getting the root.
563 @return 0 for success, else an error code.
564 */
91447636 565 int (*vfs_root)(struct mount *mp, struct vnode **vpp, vfs_context_t context);
b0d623f7
A
566
567 /*!
568 @function vfs_quotactl
569 @abstract Manipulate quotas for a volume.
570 @param mp Mount for which to manipulate quotas.
571 @param cmds Detailed in "quotactl" manual page.
572 @param uid Detailed in "quotactl" manual page.
573 @param arg Detailed in "quotactl" manual page.
574 @param context Context to authenticate for changing quotas.
575 @return 0 for success, else an error code.
576 */
91447636 577 int (*vfs_quotactl)(struct mount *mp, int cmds, uid_t uid, caddr_t arg, vfs_context_t context);
b0d623f7
A
578
579 /*!
580 @function vfs_getattr
581 @abstract Get filesystem attributes.
582 @discussion See VFSATTR_RETURN, VFSATTR_ACTIVE, VFSATTR_SET_SUPPORTED, VFSATTR_WANTED macros.
583 @param mp Mount for which to get parameters.
584 @param vfa Container for specifying which attributes are desired and which attributes the filesystem
585 supports, as well as for returning results.
586 @param ctx Context to authenticate for getting filesystem attributes.
587 @return 0 for success, else an error code.
588 */
91447636
A
589 int (*vfs_getattr)(struct mount *mp, struct vfs_attr *, vfs_context_t context);
590/* int (*vfs_statfs)(struct mount *mp, struct vfsstatfs *sbp, vfs_context_t context);*/
b0d623f7
A
591
592 /*!
593 @function vfs_sync
594 @abstract Flush all filesystem data to backing store.
595 @discussion vfs_sync will be called as part of the sync() system call and during unmount.
596 @param mp Mountpoint to sync.
597 @param waitfor MNT_WAIT: flush synchronously, waiting for all data to be written before returning. MNT_NOWAIT: start I/O but do not wait for it.
598 @param ctx Context to authenticate for the sync.
599 @return 0 for success, else an error code.
600 */
91447636 601 int (*vfs_sync)(struct mount *mp, int waitfor, vfs_context_t context);
b0d623f7
A
602
603 /*!
604 @function vfs_vget
605 @abstract Get a vnode by file id (inode number).
606 @discussion This routine is chiefly used to build paths to vnodes. Result should be turned with an iocount that the
607 caller will drop with vnode_put().
608 @param mp Mount against which to look up inode number.
609 @param ino File ID for desired file, as found through a readdir.
610 @param vpp Destination for vnode.
611 @return 0 for success, else an error code.
612 */
91447636 613 int (*vfs_vget)(struct mount *mp, ino64_t ino, struct vnode **vpp, vfs_context_t context);
b0d623f7
A
614
615 /*!
616 @function vfs_fhtovp
617 @abstract Get the vnode corresponding to a file handle.
618 @discussion Filesystems can return handles to files which are independent of their (transient) vnode identities.
619 vfs_thtovp converts that persistent handle back to a vnode. The vnode should be returned with an iocount which
620 the caller will drop with vnode_put().
621 @param mp Mount against which to look up file handle.
622 @param fhlen Size of file handle structure, as returned by vfs_vptofh.
623 @param fhp Pointer to handle.
624 @param vpp Destination for vnode.
625 @param ctx Context against which to authenticate the file-handle conversion.
626 @return 0 for success, else an error code.
627 */
91447636
A
628 int (*vfs_fhtovp)(struct mount *mp, int fhlen, unsigned char *fhp, struct vnode **vpp,
629 vfs_context_t context);
b0d623f7
A
630
631 /*!
632 @function vfs_vptofh
633 @abstract Get a persistent handle corresponding to a vnode.
634 @param mp Mount against which to convert the vnode to a handle.
635 @param fhlen Size of buffer provided for handle; set to size of actual handle returned.
636 @param fhp Pointer to buffer in which to place handle data.
637 @param ctx Context against which to authenticate the file-handle request.
638 @return 0 for success, else an error code.
639 */
91447636 640 int (*vfs_vptofh)(struct vnode *vp, int *fhlen, unsigned char *fhp, vfs_context_t context);
b0d623f7
A
641
642 /*!
643 @function vfs_init
644 @abstract Prepare a filesystem for having instances mounted.
645 @discussion This routine is called once, before any particular instance of a filesystem
646 is mounted; it allows the filesystem to initialize whatever global data structures
647 are shared across all mounts. If this returns successfully, a filesystem should be ready to have
648 instances mounted.
649 @param vfsconf Configuration information. Currently, the only useful data are the filesystem name,
650 typenum, and flags. The flags field will be either 0 or MNT_LOCAL. Many filesystems ignore this
651 parameter.
652 @return 0 for success, else an error code.
653 */
91447636 654 int (*vfs_init)(struct vfsconf *);
b0d623f7
A
655
656 /*!
657 @function vfs_sysctl
658 @abstract Broad interface for querying and controlling filesystem.
659 @discussion VFS defines VFS_CTL_QUERY as a generic status request which is answered
660 with the VQ_* macros in a "struct vfsquery."
661 A filesystem may also define implementation-specific commands. See "man 3 sysctl"
662 for the meaning of sysctl parameters.
663 @param context Context against which to authenticate command.
664 @return 0 for success, else an error code.
665 */
91447636 666 int (*vfs_sysctl)(int *, u_int, user_addr_t, size_t *, user_addr_t, size_t, vfs_context_t context);
b0d623f7
A
667
668 /*!
669 @function vfs_setattr
670 @abstract Set filesystem attributes.
671 @discussion The other side of the vfs_getattr coin. Currently only called to set volume name.
672 @param mp Mount on which to set attributes.
673 @param vfa VFS attribute structure containing requested attributes to set and their values. Currently
674 will only be called with f_vol_name set.
675 @param context Context against which to authenticate attribute change.
676 @return 0 for success, else an error code.
677 */
91447636
A
678 int (*vfs_setattr)(struct mount *mp, struct vfs_attr *, vfs_context_t context);
679 void *vfs_reserved[7];
1c79356b
A
680};
681
1c79356b
A
682
683/*
91447636 684 * flags passed into vfs_iterate
1c79356b 685 */
1c79356b
A
686
687/*
91447636 688 * return values from callback
1c79356b 689 */
91447636
A
690#define VFS_RETURNED 0 /* done with vnode, reference can be dropped */
691#define VFS_RETURNED_DONE 1 /* done with vnode, reference can be dropped, terminate iteration */
692#define VFS_CLAIMED 2 /* don't drop reference */
693#define VFS_CLAIMED_DONE 3 /* don't drop reference, terminate iteration */
1c79356b 694
91447636
A
695
696__BEGIN_DECLS
b0d623f7 697#ifdef BSD_KERNEL_PRIVATE
91447636
A
698extern int VFS_MOUNT(mount_t, vnode_t, user_addr_t, vfs_context_t);
699extern int VFS_START(mount_t, int, vfs_context_t);
700extern int VFS_UNMOUNT(mount_t, int, vfs_context_t);
701extern int VFS_ROOT(mount_t, vnode_t *, vfs_context_t);
702extern int VFS_QUOTACTL(mount_t, int, uid_t, caddr_t, vfs_context_t);
2d21ac55
A
703extern int VFS_GETATTR(mount_t, struct vfs_attr *, vfs_context_t);
704extern int VFS_SETATTR(mount_t, struct vfs_attr *, vfs_context_t);
91447636
A
705extern int VFS_SYNC(mount_t, int, vfs_context_t);
706extern int VFS_VGET(mount_t, ino64_t, vnode_t *, vfs_context_t);
707extern int VFS_FHTOVP(mount_t, int, unsigned char *, vnode_t *, vfs_context_t);
708extern int VFS_VPTOFH(vnode_t, int *, unsigned char *, vfs_context_t);
b0d623f7
A
709#endif /* BSD_KERNEL_PRIVATE */
710/*
711 * prototypes for exported VFS operations
712 */
91447636 713
b0d623f7
A
714/*!
715 @function vfs_fsadd
716 @abstract Register a filesystem with VFS.
717 @discussion Typically called by a filesystem Kernel Extension when it is loaded.
718 @param vfe Filesystem information: table of vfs operations, list of vnode operation tables,
719 filesystem type number (can be omitted with VFS_TBLNOTYPENUM flag), name, flags.
720 @param handle Opaque handle which will be passed to vfs_fsremove.
721 @return 0 for success, else an error code.
722 */
91447636 723int vfs_fsadd(struct vfs_fsentry *, vfstable_t *);
b0d623f7
A
724
725/*!
726 @function vfs_fsremove
727 @abstract Unregister a filesystem with VFS.
728 @discussion Typically called by a filesystem Kernel Extension when it is unloaded.
729 @param handle Handle which was returned by vfs_fsadd.
730 @return 0 for success, else an error code.
731 */
91447636 732int vfs_fsremove(vfstable_t);
b0d623f7
A
733
734/*!
735 @function vfs_iterate
736 @abstract Iterate over all mountpoints with a callback. Used, for example, by sync().
737 @param flags Unused.
738 @param callback Function which takes a mount and arbitrary passed-in "arg," and returns one of VFS_RETURNED_DONE or VFS_CLAIMED_DONE: end
739 iteration and return success. VFS_RETURNED or VFS_CLAIMED: continue iterating. Anything else: continue iterating.
740 @param arg Arbitrary data to pass to callback.
741 @return 0 for success, else an error code.
742 */
91447636
A
743int vfs_iterate(int, int (*)(struct mount *, void *), void *);
744
b0d623f7
A
745/*!
746 @function vfs_init_io_attributes
747 @abstract Set I/O attributes on a mountpoint based on device properties.
748 @param devvp Block device vnode from which a filesystem is being mounted.
749 @param mp Mountpoint whose I/O parameters to initialize.
750 @return 0 for success, else an error code.
751 */
752int vfs_init_io_attributes(vnode_t, mount_t);
753
754/*!
755 @function vfs_flags
756 @abstract Retrieve mount flags.
757 @discussion Results will be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS.
758 @param mp Mount whose flags to grab.
759 @return Flags.
760 */
91447636 761uint64_t vfs_flags(mount_t);
b0d623f7
A
762
763/*!
764 @function vfs_setflags
765 @abstract Set flags on a mount.
766 @discussion Sets mount flags to the bitwise "OR" of their current value and the specified bits. Often
767 used by a filesystem as part of the mount process.
768 @param mp Mount whose flags to set.
769 @param flags Flags to activate. Must be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS.
770 @return Flags.
771 */
91447636 772void vfs_setflags(mount_t, uint64_t);
b0d623f7
A
773
774/*!
775 @function vfs_clearflags
776 @abstract Clear flags on a mount.
777 @discussion Sets mount flags to the bitwise "AND" of their current value and the complement of the specified bits.
778 @param mp Mount whose flags to set.
779 @param flags Flags to deactivate. Must be in the bitwise "OR" of MNT_VISFLAGMASK and MNT_CMDFLAGS.
780 @return void.
781 */
91447636
A
782void vfs_clearflags(mount_t, uint64_t);
783
b0d623f7
A
784/*!
785 @function vfs_issynchronous
786 @abstract Determine if writes to a filesystem occur synchronously.
787 @param mp Mount to test.
788 @return Nonzero if writes occur synchronously, else 0.
789 */
91447636 790int vfs_issynchronous(mount_t);
b0d623f7
A
791
792/*!
793 @function vfs_iswriteupgrade
794 @abstract Determine if a filesystem is mounted read-only but a request has been made to upgrade
795 to read-write.
796 @param mp Mount to test.
797 @return Nonzero if a request has been made to update from read-only to read-write, else 0.
798 */
91447636 799int vfs_iswriteupgrade(mount_t);
b0d623f7
A
800
801/*!
802 @function vfs_isupdate
803 @abstract Determine if a mount update is in progress.
804 @param mp Mount to test.
805 @return Nonzero if a mount update is in progress, 0 otherwise.
806 */
91447636 807int vfs_isupdate(mount_t);
b0d623f7
A
808
809/*!
810 @function vfs_isreload
811 @abstract Determine if a reload of filesystem data is in progress. This can only be the case
812 for a read-only filesystem; all data is brought in from secondary storage.
813 @param mp Mount to test.
814 @return Nonzero if a request has been made to reload data, else 0.
815 */
91447636 816int vfs_isreload(mount_t);
b0d623f7
A
817
818/*!
819 @function vfs_isforce
820 @abstract Determine if a forced unmount is in progress.
821 @discussion A forced unmount invalidates open files.
822 @param mp Mount to test.
823 @return Nonzero if a request has been made to forcibly unmount, else 0.
824 */
91447636 825int vfs_isforce(mount_t);
b0d623f7
A
826
827/*!
828 @function vfs_isunmount
829 @abstract Determine if an unmount is in progress.
830 @discussion This is an unsynchronized snapshot of the mount state. It should only be called
831 if the mount is known to be valid, e.g. there are known to be live files on that volume.
832 @param mp Mount to test.
833 @return Nonzero if an unmount is in progress, else zero.
834 */
835int vfs_isunmount(mount_t mp);
836
837/*!
838 @function vfs_isrdonly
839 @abstract Determine if a filesystem is mounted read-only.
840 @param mp Mount to test.
841 @return Nonzero if filesystem is mounted read-only, else 0.
842 */
91447636 843int vfs_isrdonly(mount_t);
b0d623f7
A
844
845/*!
846 @function vfs_isrdwr
847 @abstract Determine if a filesystem is mounted with writes enabled.
848 @param mp Mount to test.
849 @return Nonzero if filesystem is mounted read-write, else 0.
850 */
91447636 851int vfs_isrdwr(mount_t);
b0d623f7
A
852
853/*!
854 @function vfs_authopaque
855 @abstract Determine if a filesystem's authorization decisions occur remotely.
856 @param mp Mount to test.
857 @return Nonzero if filesystem authorization is controlled remotely, else 0.
858 */
91447636 859int vfs_authopaque(mount_t);
b0d623f7
A
860
861/*!
862 @function vfs_authopaqueaccess
863 @abstract Check if a filesystem is marked as having reliable remote VNOP_ACCESS support.
864 @param mp Mount to test.
865 @return Nonzero if VNOP_ACCESS is supported remotely, else 0.
866 */
91447636 867int vfs_authopaqueaccess(mount_t);
b0d623f7
A
868
869/*!
870 @function vfs_setauthopaque
871 @abstract Mark a filesystem as having authorization decisions controlled remotely.
872 @param mp Mount to mark.
873 @return void.
874 */
91447636 875void vfs_setauthopaque(mount_t);
b0d623f7
A
876
877/*!
878 @function vfs_setauthopaqueaccess
879 @abstract Mark a filesystem as having remote VNOP_ACCESS support.
880 @param mp Mount to mark.
881 @return void.
882 */
91447636 883void vfs_setauthopaqueaccess(mount_t);
b0d623f7
A
884
885/*!
886 @function vfs_clearauthopaque
887 @abstract Mark a filesystem as not having remote authorization decisions.
888 @param mp Mount to mark.
889 @return void.
890 */
91447636 891void vfs_clearauthopaque(mount_t);
b0d623f7
A
892
893/*!
894 @function vfs_clearauthopaque
895 @abstract Mark a filesystem as not having remote VNOP_ACCESS support.
896 @param mp Mount to mark.
897 @return void.
898 */
91447636 899void vfs_clearauthopaqueaccess(mount_t);
b0d623f7
A
900
901/*!
902 @function vfs_setextendedsecurity
903 @abstract Mark a filesystem as supporting security controls beyond POSIX permissions.
904 @discussion Specific controls include ACLs, file owner UUIDs, and group UUIDs.
905 @param mp Mount to test.
906 @return void.
907 */
91447636 908void vfs_setextendedsecurity(mount_t);
b0d623f7
A
909
910/*!
911 @function vfs_clearextendedsecurity
912 @abstract Mark a filesystem as NOT supporting security controls beyond POSIX permissions.
913 @discussion Specific controls include ACLs, file owner UUIDs, and group UUIDs.
914 @param mp Mount to test.
915 @return void.
916 */
91447636 917void vfs_clearextendedsecurity(mount_t);
b0d623f7
A
918
919/*!
920 @function vfs_setlocklocal
921 @abstract Mark a filesystem as using VFS-level advisory locking support.
922 @discussion Advisory locking operations will not call down to the filesystem if this flag is set.
923 @param mp Mount to mark.
924 @return void.
925 */
91447636 926void vfs_setlocklocal(mount_t);
b0d623f7
A
927
928/*!
929 @function vfs_authcache_ttl
930 @abstract Determine the time-to-live of cached authorized credentials for files in this filesystem.
931 @discussion If a filesystem is set to allow caching credentials, the VFS layer can authorize
932 previously-authorized actions from the same vfs_context_t without calling down to the filesystem (though
933 it will not deny based on the cache).
934 @param mp Mount for which to check cache lifetime.
935 @return Cache lifetime in seconds. CACHED_RIGHT_INFINITE_TTL indicates that credentials never expire.
936 */
2d21ac55 937int vfs_authcache_ttl(mount_t);
b0d623f7
A
938
939/*!
940 @function vfs_setauthcache_ttl
941 @abstract Enable credential caching and set time-to-live of cached authorized credentials for files in this filesystem.
942 @discussion If a filesystem is set to allow caching credentials, the VFS layer can authorize
943 previously-authorized actions from the same vfs_context_t without calling down to the filesystem (though
944 it will not deny based on the cache).
945 @param mp Mount for which to set cache lifetime.
946 @return void.
947 */
2d21ac55 948void vfs_setauthcache_ttl(mount_t, int);
b0d623f7
A
949
950/*!
951 @function vfs_clearauthcache_ttl
952 @abstract Remove time-to-live controls for cached credentials on a filesytem. Filesystems with remote authorization
953 decisions (opaque) will still have KAUTH_VNODE_SEARCH rights cached for a default of CACHED_LOOKUP_RIGHT_TTL seconds.
954 @param mp Mount for which to clear cache lifetime.
955 @return void.
956 */
2d21ac55 957void vfs_clearauthcache_ttl(mount_t);
91447636 958
2d21ac55
A
959/*
960 * return value from vfs_cachedrights_ttl if
961 * neither MNTK_AUTH_OPAQUE | MNTK_AUTH_CACHE_TTL
962 * is set in mnt_kern_flag.. it indicates
963 * that no TTL is being applied to the vnode rights cache
964 */
965#define CACHED_RIGHT_INFINITE_TTL ~0
91447636 966
b0d623f7
A
967/*!
968 @function vfs_maxsymlen
969 @abstract Get the maximum length of a symbolic link on a filesystem.
970 @param mp Mount from which to get symlink length cap.
971 @return Max symlink length.
972 */
91447636 973uint32_t vfs_maxsymlen(mount_t);
b0d623f7
A
974
975/*!
976 @function vfs_setmaxsymlen
977 @abstract Set the maximum length of a symbolic link on a filesystem.
978 @param mp Mount on which to set symlink length cap.
979 @param symlen Length to set.
980 @return Max symlink length.
981 */
91447636 982void vfs_setmaxsymlen(mount_t, uint32_t);
b0d623f7
A
983
984/*!
985 @function vfs_fsprivate
986 @abstract Get filesystem-private mount data.
987 @discussion A filesystem generally has an internal mount structure which it attaches to the VFS-level mount structure
988 as part of the mounting process.
989 @param mp Mount for which to get private data.
990 @return Private data.
991 */
91447636 992void * vfs_fsprivate(mount_t);
b0d623f7
A
993
994/*!
995 @function vfs_setfsprivate
996 @abstract Set filesystem-private mount data.
997 @discussion A filesystem generally has an internal mount structure which it attaches to the VFS-level mount structure
998 as part of the mounting process.
999 @param mp Mount for which to set private data.
1000 @return Void.
1001 */
91447636
A
1002void vfs_setfsprivate(mount_t, void *mntdata);
1003
b0d623f7
A
1004/*!
1005 @function vfs_statfs
1006 @abstract Get information about filesystem status.
1007 @discussion Each filesystem has a struct vfsstatfs associated with it which is updated as events occur; this function
1008 returns a pointer to it. Note that the data in the structure will continue to change over time and also that it may
1009 be quite stale of vfs_update_vfsstat has not been called recently.
1010 @param mp Mount for which to get vfsstatfs pointer.
1011 @return Pointer to vfsstatfs.
1012 */
91447636 1013struct vfsstatfs * vfs_statfs(mount_t);
2d21ac55
A
1014#define VFS_USER_EVENT 0
1015#define VFS_KERNEL_EVENT 1
b0d623f7
A
1016
1017/*!
1018 @function vfs_update_vfsstat
1019 @abstract Update cached filesystem status information in the VFS mount structure.
1020 @discussion Each filesystem has a struct vfsstatfs associated with it which is updated as events occur; this function
1021 updates it so that the structure pointer returned by vfs_statfs() returns a pointer to fairly recent data.
1022 @param mp Mount for which to update cached status information.
1023 @param ctx Context to authenticate against for call down to filesystem.
1024 @param eventtype VFS_USER_EVENT: need for update is driven by user-level request; perform additional authentication.
1025 VFS_KERNEL_EVENT: need for update is driven by in-kernel events. Skip extra authentication.
1026 @return 0 for success, or an error code for authentication failure or problem with call to filesystem to
1027 request information.
1028 */
2d21ac55 1029int vfs_update_vfsstat(mount_t, vfs_context_t, int eventtype);
91447636 1030
b0d623f7
A
1031/*!
1032 @function vfs_typenum
1033 @abstract Get (archaic) filesystem type number.
1034 @discussion Filesystem type numbers are an old construct; most filesystems just get a number assigned based on
1035 the order in which they are registered with the system.
1036 @param mp Mount for which to get type number.
1037 @return Type number.
1038 */
91447636 1039int vfs_typenum(mount_t);
b0d623f7
A
1040
1041/*!
1042 @function vfs_name
1043 @abstract Copy filesystem name into a buffer.
1044 @discussion Get filesystem name; this refers to the filesystem type of which a mount is an instantiation,
1045 rather than a name specific to the mountpoint.
1046 @param mp Mount for which to get name.
1047 @param buffer Destination for name; length should be at least MFSNAMELEN.
1048 @return void.
1049 */
91447636 1050void vfs_name(mount_t, char *);
b0d623f7
A
1051
1052/*!
1053 @function vfs_devblocksize
1054 @abstract Get the block size of the device underlying a mount.
1055 @param mp Mount for which to get block size.
1056 @return Block size.
1057 */
91447636 1058int vfs_devblocksize(mount_t);
b0d623f7
A
1059
1060/*!
1061 @function vfs_ioattr
1062 @abstract Get I/O attributes associated with a mounpoint.
1063 @param mp Mount for which to get attributes. If NULL, system defaults are filled into ioattrp.
1064 @param ioattrp Destination for results.
1065 @return void.
1066 */
91447636 1067void vfs_ioattr(mount_t, struct vfsioattr *);
b0d623f7
A
1068
1069/*!
1070 @function vfs_setioattr
1071 @abstract Set I/O attributes associated with a mounpoint.
1072 @param mp Mount for which to set attributes.
1073 @param ioattrp Structure containing I/O parameters; all fields must be filled in.
1074 @return void.
1075 */
91447636 1076void vfs_setioattr(mount_t, struct vfsioattr *);
b0d623f7
A
1077
1078/*!
1079 @function vfs_64bitready
1080 @abstract Check if the filesystem associated with a mountpoint is marked ready for interaction with 64-bit user processes.
1081 @param mp Mount to test.
1082 @return Nonzero if filesystem is ready for 64-bit; 0 otherwise.
1083 */
91447636
A
1084int vfs_64bitready(mount_t);
1085
1086
2d21ac55 1087#define LK_NOWAIT 1
b0d623f7
A
1088/*!
1089 @function vfs_busy
1090 @abstract "Busy" a mountpoint.
1091 @discussion vfs_busy() will "busy" a mountpoint, preventing unmounts from taking off, by taking its reader-writer lock
1092 in a shared manner. If a mount is dead,
1093 it will fail; if an unmount is in progress, depending on flags, it will either fail immediately or block
1094 until the unmount completes (then failing if the unmount has succeeded, or potentially succeeding if unmounting failed).
1095 A successful vfs_busy() must be followed by a vfs_unbusy() to release the lock on the mount.
1096 @param mp Mount to busy.
1097 @param flags LK_NOWAIT: fail with ENOENT if an unmount is in progress.
1098 @return 0 for success, with a lock held; an error code otherwise, with no lock held.
1099 */
91447636 1100int vfs_busy(mount_t, int);
b0d623f7
A
1101
1102/*!
1103 @function vfs_unbusy
1104 @abstract "Unbusy" a mountpoint by releasing its read-write lock.
1105 @discussion A successful vfs_busy() must be followed by a vfs_unbusy() to release the lock on the mount.
1106 @param mp Mount to unbusy.
1107 @return void.
1108 */
91447636
A
1109void vfs_unbusy(mount_t);
1110
b0d623f7
A
1111/*!
1112 @function vfs_getnewfsid
1113 @abstract Generate a unique filesystem ID for a mount and store it in the mount structure.
1114 @discussion Filesystem IDs are returned as part of "struct statfs." This function is typically
1115 called as part of file-system specific mount code (i.e. through VFS_MOUNT).
1116 @param mp Mount to set an ID for.
1117 @return void.
1118 */
91447636 1119void vfs_getnewfsid(struct mount *);
b0d623f7
A
1120
1121/*!
1122 @function vfs_getvfs
1123 @abstract Given a filesystem ID, look up a mount structure.
1124 @param fsid Filesystem ID to look up.
1125 @return Mountpoint if found, else NULL. Note unmounting mountpoints can be returned.
1126 */
91447636 1127mount_t vfs_getvfs(fsid_t *);
b0d623f7
A
1128
1129/*!
1130 @function vfs_mountedon
1131 @abstract Check whether a given block device has a filesystem mounted on it.
1132 @discussion Note that this is NOT a check for a covered vnode (the directory upon which
1133 a filesystem is mounted)--it is a test for whether a block device is being used as the source
1134 of a filesystem. Note that a block device marked as being mounted on cannot be opened.
1135 @param vp The vnode to test.
1136 @return EBUSY if vnode is indeed the source of a filesystem; 0 if it is not.
1137 */
91447636 1138int vfs_mountedon(struct vnode *);
b0d623f7
A
1139
1140/*!
1141 @function vfs_unmountbyfsid
1142 @abstract Find a filesystem by ID and unmount it.
1143 @param fsid ID of filesystem to unmount, as found through (for example) statfs.
1144 @param flags MNT_FORCE: forcibly invalidate files open on the mount (though in-flight I/O operations
1145 will be allowed to complete).
1146 @param ctx Context against which to authenticate unmount operation.
1147 @return 0 for succcess, nonero for failure.
1148 */
2d21ac55 1149int vfs_unmountbyfsid(fsid_t *, int, vfs_context_t);
91447636 1150
b0d623f7
A
1151/*!
1152 @function vfs_event_signal
1153 @abstract Post a kqueue-style event on a filesystem (EVFILT_FS).
1154 @param fsid Unused.
1155 @param event Events to post.
1156 @param data Unused.
1157 @return void.
1158 */
55e303ae 1159void vfs_event_signal(fsid_t *, u_int32_t, intptr_t);
b0d623f7
A
1160/*!
1161 @function vfs_event_init
1162 @abstract This function should not be called by kexts.
1163 */
1164void vfs_event_init(void); /* XXX We should not export this */
1165#ifdef KERNEL_PRIVATE
1166int vfs_getattr(mount_t mp, struct vfs_attr *vfa, vfs_context_t ctx);
1167int vfs_setattr(mount_t mp, struct vfs_attr *vfa, vfs_context_t ctx);
1168int vfs_extendedsecurity(mount_t);
1169mount_t vfs_getvfs_by_mntonname(char *);
1170void vfs_markdependency(mount_t);
1171vnode_t vfs_vnodecovered(mount_t mp); /* Returns vnode with an iocount that must be released with vnode_put() */
1172void * vfs_mntlabel(mount_t mp); /* Safe to cast to "struct label*"; returns "void*" to limit dependence of mount.h on security headers. */
d1ecb069 1173void vfs_setunmountpreflight(mount_t mp);
b0d623f7 1174#endif /* KERNEL_PRIVATE */
91447636
A
1175__END_DECLS
1176
1177#endif /* KERNEL */
1c79356b 1178
91447636
A
1179#ifndef KERNEL
1180
1181/*
1182 * Generic file handle
1183 */
2d21ac55
A
1184#define NFS_MAX_FH_SIZE NFSV4_MAX_FH_SIZE
1185#define NFSV4_MAX_FH_SIZE 128
1186#define NFSV3_MAX_FH_SIZE 64
91447636
A
1187#define NFSV2_MAX_FH_SIZE 32
1188struct fhandle {
1189 int fh_len; /* length of file handle */
1190 unsigned char fh_data[NFS_MAX_FH_SIZE]; /* file handle value */
1191};
1192typedef struct fhandle fhandle_t;
1c79356b 1193
1c79356b
A
1194
1195__BEGIN_DECLS
91447636 1196int fhopen(const struct fhandle *, int);
2d21ac55 1197int fstatfs(int, struct statfs *) __DARWIN_INODE64(fstatfs);
593a1d5f
A
1198#if !__DARWIN_ONLY_64_BIT_INO_T
1199int fstatfs64(int, struct statfs64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
1200#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
91447636 1201int getfh(const char *, fhandle_t *);
2d21ac55 1202int getfsstat(struct statfs *, int, int) __DARWIN_INODE64(getfsstat);
593a1d5f
A
1203#if !__DARWIN_ONLY_64_BIT_INO_T
1204int getfsstat64(struct statfs64 *, int, int) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
1205#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
2d21ac55 1206int getmntinfo(struct statfs **, int) __DARWIN_INODE64(getmntinfo);
593a1d5f
A
1207#if !__DARWIN_ONLY_64_BIT_INO_T
1208int getmntinfo64(struct statfs64 **, int) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
1209#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
91447636 1210int mount(const char *, const char *, int, void *);
2d21ac55 1211int statfs(const char *, struct statfs *) __DARWIN_INODE64(statfs);
593a1d5f
A
1212#if !__DARWIN_ONLY_64_BIT_INO_T
1213int statfs64(const char *, struct statfs64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5,__MAC_10_6,__IPHONE_NA,__IPHONE_NA);
1214#endif /* !__DARWIN_ONLY_64_BIT_INO_T */
91447636
A
1215int unmount(const char *, int);
1216int getvfsbyname(const char *, struct vfsconf *);
1c79356b
A
1217__END_DECLS
1218
1219#endif /* KERNEL */
1220#endif /* !_SYS_MOUNT_H_ */