2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1989, 1991, 1993
33 * The Regents of the University of California. All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * @(#)mount.h 8.21 (Berkeley) 5/20/95
66 #ifndef _SYS_MOUNT_INTERNAL_H_
67 #define _SYS_MOUNT_INTERNAL_H_
69 #include <sys/appleapiopts.h>
71 #include <sys/ucred.h>
73 #include <sys/kernel_types.h>
74 #include <sys/namei.h>
76 #include <sys/queue.h>
78 #include <net/radix.h>
79 #include <sys/socket.h> /* XXX for AF_MAX */
80 #include <sys/vfs_context.h> /* XXX for AF_MAX */
81 #include <sys/mount.h>
82 #include <sys/cdefs.h>
85 * Structure per mounted file system. Each mounted file system has an
86 * array of operations and an instance record. The file systems are
87 * put on a doubly linked list.
89 TAILQ_HEAD(vnodelst
, vnode
);
92 TAILQ_ENTRY(mount
) mnt_list
; /* mount list */
93 int32_t mnt_count
; /* reference on the mount */
94 lck_mtx_t mnt_mlock
; /* mutex that protects mount point */
95 struct vfsops
*mnt_op
; /* operations on fs */
96 struct vfstable
*mnt_vtable
; /* configuration info */
97 struct vnode
*mnt_vnodecovered
; /* vnode we mounted on */
98 struct vnodelst mnt_vnodelist
; /* list of vnodes this mount */
99 struct vnodelst mnt_workerqueue
; /* list of vnodes this mount */
100 struct vnodelst mnt_newvnodes
; /* list of vnodes this mount */
101 int mnt_flag
; /* flags */
102 int mnt_kern_flag
; /* kernel only flags */
103 int mnt_lflag
; /* mount life cycle flags */
104 int mnt_maxsymlinklen
; /* max size of short symlink */
105 struct vfsstatfs mnt_vfsstat
; /* cache of filesystem stats */
106 qaddr_t mnt_data
; /* private data */
107 /* Cached values of the IO constraints for the device */
108 u_int32_t mnt_maxreadcnt
; /* Max. byte count for read */
109 u_int32_t mnt_maxwritecnt
; /* Max. byte count for write */
110 u_int32_t mnt_segreadcnt
; /* Max. segment count for read */
111 u_int32_t mnt_segwritecnt
; /* Max. segment count for write */
112 u_int32_t mnt_maxsegreadsize
; /* Max. segment read size */
113 u_int32_t mnt_maxsegwritesize
; /* Max. segment write size */
114 u_int32_t mnt_devblocksize
; /* the underlying device block size */
115 lck_rw_t mnt_rwlock
; /* mutex readwrite lock */
116 lck_mtx_t mnt_renamelock
; /* mutex that serializes renames that change shape of tree */
117 vnode_t mnt_devvp
; /* the device mounted on for local file systems */
118 int32_t mnt_crossref
; /* refernces to cover lookups crossing into mp */
119 int32_t mnt_iterref
; /* refernces to cover iterations; drained makes it -ve */
121 /* XXX 3762912 hack to support HFS filesystem 'owner' */
126 /* XXX 3762912 hack to support HFS filesystem 'owner' */
127 #define vfs_setowner(_mp, _uid, _gid) do {(_mp)->mnt_fsowner = (_uid); (_mp)->mnt_fsgroup = (_gid); } while (0)
130 /* mount point to which dead vps point to */
131 extern struct mount
* dead_mountp
;
134 * Internal filesystem control flags stored in mnt_kern_flag.
136 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot proceed
137 * past the mount point. This keeps the subtree stable during mounts
140 * Note: We are counting down on new bit assignments. This is
141 * because the bits here were broken out from the high bits
142 * of the mount flags.
144 #define MNTK_LOCK_LOCAL 0x00100000 /* advisory locking is done above the VFS itself */
145 #define MNTK_VIRTUALDEV 0x00200000 /* mounted on a virtual device i.e. a disk image */
146 #define MNTK_ROOTDEV 0x00400000 /* this filesystem resides on the same device as the root */
147 #define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
148 #define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
149 #define MNTK_WANTRDWR 0x04000000 /* upgrade to read/write requested */
151 #define MNT_REVEND 0x08000000 /* Reverse endian FS */
152 #endif /* REV_ENDIAN_FS */
153 #define MNTK_FRCUNMOUNT 0x10000000 /* Forced unmount wanted. */
154 #define MNTK_AUTH_OPAQUE 0x20000000 /* authorisation decisions are not made locally */
155 #define MNTK_AUTH_OPAQUE_ACCESS 0x40000000 /* VNOP_ACCESS is reliable for remote auth */
156 #define MNTK_EXTENDED_SECURITY 0x80000000 /* extended security supported */
158 #define MNT_LBUSY 0x00000001 /* mount is busy */
159 #define MNT_LUNMOUNT 0x00000002 /* mount in unmount */
160 #define MNT_LFORCE 0x00000004 /* mount in forced unmount */
161 #define MNT_LDRAIN 0x00000008 /* mount in drain */
162 #define MNT_LITER 0x00000010 /* mount in iteration */
163 #define MNT_LNEWVN 0x00000020 /* mount has new vnodes created */
164 #define MNT_LWAIT 0x00000040 /* wait for unmount op */
165 #define MNT_LITERWAIT 0x00000080 /* mount in iteration */
166 #define MNT_LDEAD 0x00000100 /* mount already unmounted*/
170 * Generic file handle
172 #define NFS_MAX_FH_SIZE 64
173 #define NFSV2_MAX_FH_SIZE 32
175 int fh_len
; /* length of file handle */
176 unsigned char fh_data
[NFS_MAX_FH_SIZE
]; /* file handle value */
178 typedef struct fhandle fhandle_t
;
183 * Filesystem configuration information. One of these exists for each
184 * type of filesystem supported by the kernel. These are searched at
185 * mount time to identify the requested filesystem.
188 /* THE FOLLOWING SHOULD KEEP THE SAME FOR user compat with sysctl */
189 struct vfsops
*vfc_vfsops
; /* filesystem operations vector */
190 char vfc_name
[MFSNAMELEN
]; /* filesystem type name */
191 int vfc_typenum
; /* historic filesystem type number */
192 int vfc_refcount
; /* number mounted of this type */
193 int vfc_flags
; /* permanent flags */
194 int (*vfc_mountroot
)(mount_t
, vnode_t
, vfs_context_t
); /* if != NULL, routine to mount root */
195 struct vfstable
*vfc_next
; /* next in list */
196 /* Till the above we SHOULD KEEP THE SAME FOR user compat with sysctl */
197 int vfc_threadsafe
; /* FS is thread & premeption safe */
198 lck_mtx_t vfc_lock
; /* for non-threaded file systems */
199 int vfc_vfsflags
; /* for optional types */
200 void * vfc_descptr
; /* desc table allocated address */
201 int vfc_descsize
; /* size allocated for desc table */
202 int vfc_64bitready
; /* The file system is ready for 64bit */
205 #define VFC_VFSLOCALARGS 0x02
206 #define VFC_VFSGENERICARGS 0x04
207 #define VFC_VFSNATIVEXATTR 0x10
210 extern int maxvfsconf
; /* highest defined filesystem type */
211 extern struct vfstable
*vfsconf
; /* head of list of filesystem types */
212 extern int maxvfsslots
; /* Maximum slots available to be used */
213 extern int numused_vfsslots
; /* number of slots already used */
215 /* the following two are xnu private */
216 struct vfstable
* vfstable_add(struct vfstable
*);
217 int vfstable_del(struct vfstable
*);
220 struct vfsmount_args
{
227 void * mnt_fsdata
; /* FS specific */
234 * LP64 version of statfs structure.
235 * NOTE - must be kept in sync with struct statfs in mount.h
237 #if __DARWIN_ALIGN_NATURAL
238 #pragma options align=natural
242 short f_otype
; /* TEMPORARY SHADOW COPY OF f_type */
243 short f_oflags
; /* TEMPORARY SHADOW COPY OF f_flags */
244 user_long_t f_bsize
; /* fundamental file system block size */
245 user_long_t f_iosize
; /* optimal transfer block size */
246 user_long_t f_blocks
; /* total data blocks in file system */
247 user_long_t f_bfree
; /* free blocks in fs */
248 user_long_t f_bavail
; /* free blocks avail to non-superuser */
249 user_long_t f_files
; /* total file nodes in file system */
250 user_long_t f_ffree
; /* free file nodes in fs */
251 fsid_t f_fsid
; /* file system id */
252 uid_t f_owner
; /* user that mounted the filesystem */
253 short f_reserved1
; /* spare for later */
254 short f_type
; /* type of filesystem */
255 user_long_t f_flags
; /* copy of mount exported flags */
256 user_long_t f_reserved2
[2]; /* reserved for future use */
257 char f_fstypename
[MFSNAMELEN
]; /* fs type name */
258 char f_mntonname
[MNAMELEN
]; /* directory on which mounted */
259 char f_mntfromname
[MNAMELEN
];/* mounted filesystem */
261 char f_reserved3
[0]; /* For alignment */
262 user_long_t f_reserved4
[0]; /* For future use */
264 char f_reserved3
; /* For alignment */
265 user_long_t f_reserved4
[4]; /* For future use */
269 #if __DARWIN_ALIGN_NATURAL
270 #pragma options align=reset
275 extern TAILQ_HEAD(mntlist
, mount
) mountlist
;
276 void mount_list_lock(void);
277 void mount_list_unlock(void);
278 void mount_lock_init(mount_t
);
279 void mount_lock_destroy(mount_t
);
280 void mount_lock(mount_t
);
281 void mount_unlock(mount_t
);
282 void mount_lock_renames(mount_t
);
283 void mount_unlock_renames(mount_t
);
284 void mount_ref(mount_t
, int);
285 void mount_drop(mount_t
, int);
287 /* vfs_rootmountalloc should be kept as a private api */
288 errno_t
vfs_rootmountalloc(const char *, const char *, mount_t
*mpp
);
289 errno_t
vfs_init_io_attributes(vnode_t
, mount_t
);
291 int vfs_mountroot(void);
292 void vfs_unmountall(void);
293 int safedounmount(struct mount
*, int, struct proc
*);
294 int dounmount(struct mount
*, int, struct proc
*);
296 /* xnuy internal api */
297 void mount_dropcrossref(mount_t
, vnode_t
, int);
298 int validfsnode(mount_t
);
299 mount_t
mount_lookupby_volfsid(int, int);
300 mount_t
mount_list_lookupby_fsid(fsid_t
*, int, int);
301 int mount_iterref(mount_t
, int);
302 int mount_isdrained(mount_t
, int);
303 void mount_iterdrop(mount_t
);
304 void mount_iterdrain(mount_t
);
305 void mount_iterreset(mount_t
);
309 #endif /* !_SYS_MOUNT_INTERNAL_H_ */