1 /*
2  * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
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
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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  */
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 
70 
71 #ifndef _SYS_MOUNT_H_
72 #define _SYS_MOUNT_H_
73 
74 #include <sys/appleapiopts.h>
75 #include <sys/cdefs.h>
76 #include <sys/attr.h>           /* needed for vol_capabilities_attr_t */
77 #include <os/base.h>
78 
79 #include <stdint.h>
80 #include <sys/ucred.h>
81 #include <sys/queue.h>          /* XXX needed for user builds */
82 #include <Availability.h>
83 
84 #include <sys/_types/_fsid_t.h> /* file system id type */
85 
86 /*
87  * file system statistics
88  */
89 
90 #define MFSNAMELEN      15      /* length of fs type name, not inc. null */
91 #define MFSTYPENAMELEN  16      /* length of fs type name including null */
92 
93 #if __DARWIN_64_BIT_INO_T
94 #define MNAMELEN        MAXPATHLEN      /* length of buffer for returned name */
95 #else /* ! __DARWIN_64_BIT_INO_T */
96 #define MNAMELEN        90              /* length of buffer for returned name */
97 #endif /* __DARWIN_64_BIT_INO_T */
98 
99 #define MNT_EXT_ROOT_DATA_VOL      0x00000001      /* Data volume of root volume group */
100 
101 #define __DARWIN_STRUCT_STATFS64 { \
102 	uint32_t	f_bsize;        /* fundamental file system block size */ \
103 	int32_t		f_iosize;       /* optimal transfer block size */ \
104 	uint64_t	f_blocks;       /* total data blocks in file system */ \
105 	uint64_t	f_bfree;        /* free blocks in fs */ \
106 	uint64_t	f_bavail;       /* free blocks avail to non-superuser */ \
107 	uint64_t	f_files;        /* total file nodes in file system */ \
108 	uint64_t	f_ffree;        /* free file nodes in fs */ \
109 	fsid_t		f_fsid;         /* file system id */ \
110 	uid_t		f_owner;        /* user that mounted the filesystem */ \
111 	uint32_t	f_type;         /* type of filesystem */ \
112 	uint32_t	f_flags;        /* copy of mount exported flags */ \
113 	uint32_t	f_fssubtype;    /* fs sub-type (flavor) */ \
114 	char		f_fstypename[MFSTYPENAMELEN];   /* fs type name */ \
115 	char		f_mntonname[MAXPATHLEN];        /* directory on which mounted */ \
116 	char		f_mntfromname[MAXPATHLEN];      /* mounted filesystem */ \
117 	uint32_t    f_flags_ext;    /* extended flags */ \
118 	uint32_t	f_reserved[7];  /* For future use */ \
119 }
120 
121 #if !__DARWIN_ONLY_64_BIT_INO_T
122 
123 struct statfs64 __DARWIN_STRUCT_STATFS64;
124 
125 #endif /* !__DARWIN_ONLY_64_BIT_INO_T */
126 
127 #if __DARWIN_64_BIT_INO_T
128 
129 struct statfs __DARWIN_STRUCT_STATFS64;
130 
131 #else /* !__DARWIN_64_BIT_INO_T */
132 
133 /*
134  * LP64 - WARNING - must be kept in sync with struct user_statfs in mount_internal.h.
135  */
136 struct statfs {
137 	short   f_otype;                /* TEMPORARY SHADOW COPY OF f_type */
138 	short   f_oflags;               /* TEMPORARY SHADOW COPY OF f_flags */
139 	long    f_bsize;                /* fundamental file system block size */
140 	long    f_iosize;               /* optimal transfer block size */
141 	long    f_blocks;               /* total data blocks in file system */
142 	long    f_bfree;                /* free blocks in fs */
143 	long    f_bavail;               /* free blocks avail to non-superuser */
144 	long    f_files;                /* total file nodes in file system */
145 	long    f_ffree;                /* free file nodes in fs */
146 	fsid_t  f_fsid;                 /* file system id */
147 	uid_t   f_owner;                /* user that mounted the filesystem */
148 	short   f_reserved1;    /* spare for later */
149 	short   f_type;                 /* type of filesystem */
150 	long    f_flags;                /* copy of mount exported flags */
151 	long    f_reserved2[2]; /* reserved for future use */
152 	char    f_fstypename[MFSNAMELEN]; /* fs type name */
153 	char    f_mntonname[MNAMELEN];  /* directory on which mounted */
154 	char    f_mntfromname[MNAMELEN];/* mounted filesystem */
155 	char    f_reserved3;    /* For alignment */
156 	long    f_reserved4[4]; /* For future use */
157 };
158 
159 #endif /* __DARWIN_64_BIT_INO_T */
160 
161 #pragma pack(4)
162 
163 struct vfsstatfs {
164 	uint32_t        f_bsize;        /* fundamental file system block size */
165 	size_t          f_iosize;       /* optimal transfer block size */
166 	uint64_t        f_blocks;       /* total data blocks in file system */
167 	uint64_t        f_bfree;        /* free blocks in fs */
168 	uint64_t        f_bavail;       /* free blocks avail to non-superuser */
169 	uint64_t        f_bused;        /* free blocks avail to non-superuser */
170 	uint64_t        f_files;        /* total file nodes in file system */
171 	uint64_t        f_ffree;        /* free file nodes in fs */
172 	fsid_t          f_fsid;         /* file system id */
173 	uid_t           f_owner;        /* user that mounted the filesystem */
174 	uint64_t        f_flags;        /* copy of mount exported flags */
175 	char            f_fstypename[MFSTYPENAMELEN];/* fs type name inclus */
176 	char            f_mntonname[MAXPATHLEN];/* directory on which mounted */
177 	char            f_mntfromname[MAXPATHLEN];/* mounted filesystem */
178 	uint32_t        f_fssubtype;     /* fs sub-type (flavor) */
179 	void            *f_reserved[2];         /* For future use == 0 */
180 };
181 
182 #pragma pack()
183 
184 
185 /*
186  * User specifiable flags.
187  *
188  * Unmount uses MNT_FORCE flag.
189  */
190 #define MNT_RDONLY      0x00000001      /* read only filesystem */
191 #define MNT_SYNCHRONOUS 0x00000002      /* file system written synchronously */
192 #define MNT_NOEXEC      0x00000004      /* can't exec from filesystem */
193 #define MNT_NOSUID      0x00000008      /* don't honor setuid bits on fs */
194 #define MNT_NODEV       0x00000010      /* don't interpret special files */
195 #define MNT_UNION       0x00000020      /* union with underlying filesystem */
196 #define MNT_ASYNC       0x00000040      /* file system written asynchronously */
197 #define MNT_CPROTECT    0x00000080      /* file system supports content protection */
198 
199 /*
200  * NFS export related mount flags.
201  */
202 #define MNT_EXPORTED    0x00000100      /* file system is exported */
203 
204 /*
205  * Denotes storage which can be removed from the system by the user.
206  */
207 
208 #define MNT_REMOVABLE   0x00000200
209 
210 /*
211  * MAC labeled / "quarantined" flag
212  */
213 #define MNT_QUARANTINE  0x00000400      /* file system is quarantined */
214 
215 /*
216  * Flags set by internal operations.
217  */
218 #define MNT_LOCAL       0x00001000      /* filesystem is stored locally */
219 #define MNT_QUOTA       0x00002000      /* quotas are enabled on filesystem */
220 #define MNT_ROOTFS      0x00004000      /* identifies the root filesystem */
221 #define MNT_DOVOLFS     0x00008000      /* FS supports volfs (deprecated flag in Mac OS X 10.5) */
222 
223 
224 #define MNT_DONTBROWSE  0x00100000      /* file system is not appropriate path to user data */
225 #define MNT_IGNORE_OWNERSHIP 0x00200000 /* VFS will ignore ownership information on filesystem objects */
226 #define MNT_AUTOMOUNTED 0x00400000      /* filesystem was mounted by automounter */
227 #define MNT_JOURNALED   0x00800000      /* filesystem is journaled */
228 #define MNT_NOUSERXATTR 0x01000000      /* Don't allow user extended attributes */
229 #define MNT_DEFWRITE    0x02000000      /* filesystem should defer writes */
230 #define MNT_MULTILABEL  0x04000000      /* MAC support for individual labels */
231 #define MNT_NOATIME             0x10000000      /* disable update of file access time */
232 #define MNT_SNAPSHOT    0x40000000 /* The mount is a snapshot */
233 #define MNT_STRICTATIME 0x80000000      /* enable strict update of file access time */
234 
235 /* backwards compatibility only */
236 #define MNT_UNKNOWNPERMISSIONS MNT_IGNORE_OWNERSHIP
237 
238 
239 /*
240  * XXX I think that this could now become (~(MNT_CMDFLAGS))
241  * but the 'mount' program may need changing to handle this.
242  */
243 #define MNT_VISFLAGMASK (MNT_RDONLY	| MNT_SYNCHRONOUS | MNT_NOEXEC	| \
244 	                MNT_NOSUID	| MNT_NODEV	| MNT_UNION	| \
245 	                MNT_ASYNC	| MNT_EXPORTED	| MNT_QUARANTINE | \
246 	                MNT_LOCAL	| MNT_QUOTA | MNT_REMOVABLE | \
247 	                MNT_ROOTFS	| MNT_DOVOLFS	| MNT_DONTBROWSE | \
248 	                MNT_IGNORE_OWNERSHIP | MNT_AUTOMOUNTED | MNT_JOURNALED | \
249 	                MNT_NOUSERXATTR | MNT_DEFWRITE	| MNT_MULTILABEL | \
250 	                MNT_NOATIME | MNT_STRICTATIME | MNT_SNAPSHOT | MNT_CPROTECT)
251 /*
252  * External filesystem command modifier flags.
253  * Unmount can use the MNT_FORCE flag.
254  * XXX These are not STATES and really should be somewhere else.
255  * External filesystem control flags.
256  */
257 #define MNT_UPDATE      0x00010000      /* not a real mount, just an update */
258 #define MNT_NOBLOCK     0x00020000      /* don't block unmount if not responding */
259 #define MNT_RELOAD      0x00040000      /* reload filesystem data */
260 #define MNT_FORCE       0x00080000      /* force unmount or readonly change */
261 #define MNT_CMDFLAGS    (MNT_UPDATE|MNT_NOBLOCK|MNT_RELOAD|MNT_FORCE)
262 
263 
264 
265 /*
266  * Sysctl CTL_VFS definitions.
267  *
268  * Second level identifier specifies which filesystem. Second level
269  * identifier VFS_GENERIC returns information about all filesystems.
270  */
271 #define VFS_GENERIC             0       /* generic filesystem information */
272 #define VFS_NUMMNTOPS           1       /* int: total num of vfs mount/unmount operations */
273 /*
274  * Third level identifiers for VFS_GENERIC are given below; third
275  * level identifiers for specific filesystems are given in their
276  * mount specific header files.
277  */
278 #define VFS_MAXTYPENUM  1       /* int: highest defined filesystem type */
279 #define VFS_CONF        2       /* struct: vfsconf for filesystem given
280 	                         *  as next argument */
281 
282 /*
283  * Flags for various system call interfaces.
284  *
285  * waitfor flags to vfs_sync() and getfsstat()
286  */
287 #define MNT_WAIT        1       /* synchronized I/O file integrity completion */
288 #define MNT_NOWAIT      2       /* start all I/O, but do not wait for it */
289 #define MNT_DWAIT       4       /* synchronized I/O data integrity completion */
290 
291 
292 #if !defined(KERNEL) && !defined(_KERN_SYS_KERNELTYPES_H_) /* also defined in kernel_types.h */
293 struct mount;
294 typedef struct mount * mount_t;
295 struct vnode;
296 typedef struct vnode * vnode_t;
297 #endif
298 
299 /* Reserved fields preserve binary compatibility */
300 struct vfsconf {
301 	uint32_t vfc_reserved1;         /* opaque */
302 	char    vfc_name[MFSNAMELEN];   /* filesystem type name */
303 	int     vfc_typenum;            /* historic filesystem type number */
304 	int     vfc_refcount;           /* number mounted of this type */
305 	int     vfc_flags;              /* permanent flags */
306 	uint32_t vfc_reserved2;         /* opaque */
307 	uint32_t vfc_reserved3;         /* opaque */
308 };
309 
310 struct vfsidctl {
311 	int             vc_vers;        /* should be VFSIDCTL_VERS1 (below) */
312 	fsid_t          vc_fsid;        /* fsid to operate on. */
313 	void            *vc_ptr;        /* pointer to data structure. */
314 	size_t          vc_len;         /* sizeof said structure. */
315 	u_int32_t       vc_spare[12];   /* spare (must be zero). */
316 };
317 
318 
319 /* vfsidctl API version. */
320 #define VFS_CTL_VERS1   0x01
321 
322 
323 /*
324  * New style VFS sysctls, do not reuse/conflict with the namespace for
325  * private sysctls.
326  */
327 #define VFS_CTL_OSTATFS 0x00010001      /* old legacy statfs */
328 #define VFS_CTL_UMOUNT  0x00010002      /* unmount */
329 #define VFS_CTL_QUERY   0x00010003      /* anything wrong? (vfsquery) */
330 #define VFS_CTL_NEWADDR 0x00010004      /* reconnect to new address */
331 #define VFS_CTL_TIMEO   0x00010005      /* set timeout for vfs notification */
332 #define VFS_CTL_NOLOCKS 0x00010006      /* disable file locking */
333 #define VFS_CTL_SADDR   0x00010007      /* get server address */
334 #define VFS_CTL_DISC    0x00010008      /* server disconnected */
335 #define VFS_CTL_SERVERINFO  0x00010009  /* information about fs server */
336 #define VFS_CTL_NSTATUS 0x0001000A      /* netfs mount status */
337 #define VFS_CTL_STATFS64 0x0001000B     /* statfs64 */
338 
339 /*
340  * Automatically select the correct VFS_CTL_*STATFS* flavor based
341  * on what "struct statfs" layout the client will use.
342  */
343 #if __DARWIN_64_BIT_INO_T
344 #define VFS_CTL_STATFS  VFS_CTL_STATFS64
345 #else
346 #define VFS_CTL_STATFS  VFS_CTL_OSTATFS
347 #endif
348 
349 struct vfsquery {
350 	u_int32_t       vq_flags;
351 	u_int32_t       vq_spare[31];
352 };
353 
354 struct vfs_server {
355 	int32_t  vs_minutes;                    /* minutes until server goes down. */
356 	u_int8_t vs_server_name[MAXHOSTNAMELEN * 3]; /* UTF8 server name to display (null terminated) */
357 };
358 
359 /*
360  * NetFS mount status - returned by VFS_CTL_NSTATUS
361  */
362 struct netfs_status {
363 	u_int32_t       ns_status;              // Current status of mount (vfsquery flags)
364 	char            ns_mountopts[512];      // Significant mount options
365 	uint32_t        ns_waittime;            // Time waiting for reply (sec)
366 	uint32_t        ns_threadcount;         // Number of threads blocked on network calls
367 	uint64_t        ns_threadids[0];        // Thread IDs of those blocked threads
368 };
369 
370 /* vfsquery flags */
371 #define VQ_NOTRESP      0x0001  /* server down */
372 #define VQ_NEEDAUTH     0x0002  /* server bad auth */
373 #define VQ_LOWDISK      0x0004  /* we're low on space */
374 #define VQ_MOUNT        0x0008  /* new filesystem arrived */
375 #define VQ_UNMOUNT      0x0010  /* filesystem has left */
376 #define VQ_DEAD         0x0020  /* filesystem is dead, needs force unmount */
377 #define VQ_ASSIST       0x0040  /* filesystem needs assistance from external program */
378 #define VQ_NOTRESPLOCK  0x0080  /* server lockd down */
379 #define VQ_UPDATE       0x0100  /* filesystem information has changed */
380 #define VQ_VERYLOWDISK  0x0200  /* file system has *very* little disk space left */
381 #define VQ_SYNCEVENT    0x0400  /* a sync just happened (not set by kernel starting Mac OS X 10.9) */
382 #define VQ_SERVEREVENT  0x0800  /* server issued notification/warning */
383 #define VQ_QUOTA        0x1000  /* a user quota has been hit */
384 #define VQ_NEARLOWDISK          0x2000  /* Above lowdisk and below desired disk space */
385 #define VQ_DESIRED_DISK         0x4000  /* the desired disk space */
386 #define VQ_FREE_SPACE_CHANGE    0x8000  /* free disk space has significantly changed */
387 #define VQ_FLAG10000    0x10000  /* placeholder */
388 
389 
390 
391 
392 /*
393  * Generic file handle
394  */
395 #define NFS_MAX_FH_SIZE         NFSV4_MAX_FH_SIZE
396 #define NFSV4_MAX_FH_SIZE       128
397 #define NFSV3_MAX_FH_SIZE       64
398 #define NFSV2_MAX_FH_SIZE       32
399 struct fhandle {
400 	unsigned int    fh_len;                         /* length of file handle */
401 	unsigned char   fh_data[NFS_MAX_FH_SIZE];       /* file handle value */
402 };
403 typedef struct fhandle  fhandle_t;
404 
405 
406 __BEGIN_DECLS
407 int     fhopen(const struct fhandle *, int);
408 int     fstatfs(int, struct statfs *) __DARWIN_INODE64(fstatfs);
409 #if !__DARWIN_ONLY_64_BIT_INO_T
410 int     fstatfs64(int, struct statfs64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
411 #endif /* !__DARWIN_ONLY_64_BIT_INO_T */
412 int     getfh(const char *, fhandle_t *);
413 int     getfsstat(struct statfs *, int, int) __DARWIN_INODE64(getfsstat);
414 #if !__DARWIN_ONLY_64_BIT_INO_T
415 int     getfsstat64(struct statfs64 *, int, int) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
416 #endif /* !__DARWIN_ONLY_64_BIT_INO_T */
417 int     getmntinfo(struct statfs **, int) __DARWIN_INODE64(getmntinfo);
418 int     getmntinfo_r_np(struct statfs **, int) __DARWIN_INODE64(getmntinfo_r_np)
419 __OSX_AVAILABLE(10.13) __IOS_AVAILABLE(11.0)
420 __TVOS_AVAILABLE(11.0) __WATCHOS_AVAILABLE(4.0);
421 #if !__DARWIN_ONLY_64_BIT_INO_T
422 int     getmntinfo64(struct statfs64 **, int) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
423 #endif /* !__DARWIN_ONLY_64_BIT_INO_T */
424 int     mount(const char *, const char *, int, void *);
425 int     fmount(const char *, int, int, void *) __OSX_AVAILABLE(10.13) __IOS_AVAILABLE(11.0) __TVOS_AVAILABLE(11.0) __WATCHOS_AVAILABLE(4.0);
426 int     statfs(const char *, struct statfs *) __DARWIN_INODE64(statfs);
427 #if !__DARWIN_ONLY_64_BIT_INO_T
428 int     statfs64(const char *, struct statfs64 *) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_5, __MAC_10_6, __IPHONE_NA, __IPHONE_NA);
429 #endif /* !__DARWIN_ONLY_64_BIT_INO_T */
430 int     unmount(const char *, int);
431 int     getvfsbyname(const char *, struct vfsconf *);
432 __END_DECLS
433 
434 #endif /* !_SYS_MOUNT_H_ */