xref: /xnu-10002.41.9/bsd/miscfs/nullfs/nullfs.h (revision 699cd48037512bf4380799317ca44ca453c82f57)
1*699cd480SApple OSS Distributions /*
2*699cd480SApple OSS Distributions  * Copyright (c) 2016 Apple Inc. All rights reserved.
3*699cd480SApple OSS Distributions  *
4*699cd480SApple OSS Distributions  * @APPLE_LICENSE_HEADER_START@
5*699cd480SApple OSS Distributions  *
6*699cd480SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*699cd480SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*699cd480SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*699cd480SApple OSS Distributions  * compliance with the License. Please obtain a copy of the License at
10*699cd480SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this
11*699cd480SApple OSS Distributions  * file.
12*699cd480SApple OSS Distributions  *
13*699cd480SApple OSS Distributions  * The Original Code and all software distributed under the License are
14*699cd480SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*699cd480SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*699cd480SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*699cd480SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*699cd480SApple OSS Distributions  * Please see the License for the specific language governing rights and
19*699cd480SApple OSS Distributions  * limitations under the License.
20*699cd480SApple OSS Distributions  *
21*699cd480SApple OSS Distributions  * @APPLE_LICENSE_HEADER_END@
22*699cd480SApple OSS Distributions  */
23*699cd480SApple OSS Distributions 
24*699cd480SApple OSS Distributions /*-
25*699cd480SApple OSS Distributions  * Portions Copyright (c) 1992, 1993
26*699cd480SApple OSS Distributions  *  The Regents of the University of California.  All rights reserved.
27*699cd480SApple OSS Distributions  *
28*699cd480SApple OSS Distributions  * This code is derived from software donated to Berkeley by
29*699cd480SApple OSS Distributions  * Jan-Simon Pendry.
30*699cd480SApple OSS Distributions  *
31*699cd480SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
32*699cd480SApple OSS Distributions  * modification, are permitted provided that the following conditions
33*699cd480SApple OSS Distributions  * are met:
34*699cd480SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
35*699cd480SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
36*699cd480SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
37*699cd480SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
38*699cd480SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
39*699cd480SApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
40*699cd480SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
41*699cd480SApple OSS Distributions  *    without specific prior written permission.
42*699cd480SApple OSS Distributions  *
43*699cd480SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44*699cd480SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45*699cd480SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46*699cd480SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47*699cd480SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48*699cd480SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49*699cd480SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50*699cd480SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51*699cd480SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52*699cd480SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53*699cd480SApple OSS Distributions  * SUCH DAMAGE.
54*699cd480SApple OSS Distributions  *
55*699cd480SApple OSS Distributions  *  @(#)null.h  8.3 (Berkeley) 8/20/94
56*699cd480SApple OSS Distributions  *
57*699cd480SApple OSS Distributions  * $FreeBSD$
58*699cd480SApple OSS Distributions  */
59*699cd480SApple OSS Distributions 
60*699cd480SApple OSS Distributions #ifndef FS_NULL_H
61*699cd480SApple OSS Distributions #define FS_NULL_H
62*699cd480SApple OSS Distributions 
63*699cd480SApple OSS Distributions #include <sys/appleapiopts.h>
64*699cd480SApple OSS Distributions #include <libkern/libkern.h>
65*699cd480SApple OSS Distributions #include <sys/vnode.h>
66*699cd480SApple OSS Distributions #include <sys/vnode_if.h>
67*699cd480SApple OSS Distributions #include <sys/ubc.h>
68*699cd480SApple OSS Distributions #include <vfs/vfs_support.h>
69*699cd480SApple OSS Distributions #include <sys/lock.h>
70*699cd480SApple OSS Distributions 
71*699cd480SApple OSS Distributions #include <sys/cdefs.h>
72*699cd480SApple OSS Distributions #include <sys/types.h>
73*699cd480SApple OSS Distributions #include <sys/syslimits.h>
74*699cd480SApple OSS Distributions 
75*699cd480SApple OSS Distributions #if KERNEL
76*699cd480SApple OSS Distributions #include <libkern/tree.h>
77*699cd480SApple OSS Distributions #else
78*699cd480SApple OSS Distributions #include <System/libkern/tree.h>
79*699cd480SApple OSS Distributions #endif
80*699cd480SApple OSS Distributions 
81*699cd480SApple OSS Distributions // #define NULLFS_DEBUG 0
82*699cd480SApple OSS Distributions 
83*699cd480SApple OSS Distributions #define NULLM_CACHE 0x0001
84*699cd480SApple OSS Distributions #define NULLM_CASEINSENSITIVE 0x0000000000000002
85*699cd480SApple OSS Distributions #define NULLM_UNVEIL 0x1ULL << 2
86*699cd480SApple OSS Distributions 
87*699cd480SApple OSS Distributions typedef int (*vop_t)(void *);
88*699cd480SApple OSS Distributions 
89*699cd480SApple OSS Distributions struct null_mount {
90*699cd480SApple OSS Distributions 	struct vnode * nullm_rootvp;       /* Reference to root null_node (inode 1) */
91*699cd480SApple OSS Distributions 	struct vnode * nullm_secondvp;     /* Reference to virtual directory vnode to wrap app
92*699cd480SApple OSS Distributions 	                                    *  bundles (inode 2) */
93*699cd480SApple OSS Distributions 	struct vnode * nullm_lowerrootvp;  /* reference to the root of the tree we are
94*699cd480SApple OSS Distributions 	                                    * relocating (in the other file system) */
95*699cd480SApple OSS Distributions 	uint32_t nullm_lowerrootvid;       /* store the lower root vid so we can check
96*699cd480SApple OSS Distributions 	                                    *  before we build the shadow vnode lazily*/
97*699cd480SApple OSS Distributions 	lck_mtx_t nullm_lock;              /* lock to protect rootvp and secondvp above */
98*699cd480SApple OSS Distributions 	uint64_t nullm_flags;
99*699cd480SApple OSS Distributions 	uid_t uid;
100*699cd480SApple OSS Distributions 	gid_t gid;
101*699cd480SApple OSS Distributions };
102*699cd480SApple OSS Distributions 
103*699cd480SApple OSS Distributions struct null_mount_conf {
104*699cd480SApple OSS Distributions 	uint64_t flags;
105*699cd480SApple OSS Distributions };
106*699cd480SApple OSS Distributions 
107*699cd480SApple OSS Distributions #ifdef KERNEL
108*699cd480SApple OSS Distributions 
109*699cd480SApple OSS Distributions #define NULL_FLAG_HASHED 0x000000001
110*699cd480SApple OSS Distributions 
111*699cd480SApple OSS Distributions /*
112*699cd480SApple OSS Distributions  * A cache of vnode references
113*699cd480SApple OSS Distributions  */
114*699cd480SApple OSS Distributions struct null_node {
115*699cd480SApple OSS Distributions 	LIST_ENTRY(null_node) null_hash; /* Hash list */
116*699cd480SApple OSS Distributions 	struct vnode * null_lowervp;     /* VREFed once */
117*699cd480SApple OSS Distributions 	struct vnode * null_vnode;       /* Back pointer */
118*699cd480SApple OSS Distributions 	uint32_t null_lowervid;          /* vid for lowervp to detect lowervp getting recycled out
119*699cd480SApple OSS Distributions 	                                  *  from under us */
120*699cd480SApple OSS Distributions 	uint32_t null_myvid;
121*699cd480SApple OSS Distributions 	uint32_t null_flags;
122*699cd480SApple OSS Distributions };
123*699cd480SApple OSS Distributions 
124*699cd480SApple OSS Distributions struct vnodeop_desc_fake {
125*699cd480SApple OSS Distributions 	int vdesc_offset;
126*699cd480SApple OSS Distributions 	const char * vdesc_name;
127*699cd480SApple OSS Distributions 	/* other stuff */
128*699cd480SApple OSS Distributions };
129*699cd480SApple OSS Distributions 
130*699cd480SApple OSS Distributions #define NULLV_NOUNLOCK 0x0001
131*699cd480SApple OSS Distributions #define NULLV_DROP 0x0002
132*699cd480SApple OSS Distributions 
133*699cd480SApple OSS Distributions #define MOUNTTONULLMOUNT(mp) ((struct null_mount *)(vfs_fsprivate(mp)))
134*699cd480SApple OSS Distributions #define VTONULL(vp) ((struct null_node *)vnode_fsnode(vp))
135*699cd480SApple OSS Distributions #define NULLTOV(xp) ((xp)->null_vnode)
136*699cd480SApple OSS Distributions 
137*699cd480SApple OSS Distributions __BEGIN_DECLS
138*699cd480SApple OSS Distributions 
139*699cd480SApple OSS Distributions int nullfs_init(struct vfsconf * vfsp);
140*699cd480SApple OSS Distributions void nullfs_init_lck(lck_mtx_t * lck);
141*699cd480SApple OSS Distributions void nullfs_destroy_lck(lck_mtx_t * lck);
142*699cd480SApple OSS Distributions int nullfs_uninit(void);
143*699cd480SApple OSS Distributions int null_nodeget(
144*699cd480SApple OSS Distributions 	struct mount * mp, struct vnode * lowervp, struct vnode * dvp, struct vnode ** vpp, struct componentname * cnp, int root);
145*699cd480SApple OSS Distributions int null_hashget(struct mount * mp, struct vnode * lowervp, struct vnode ** vpp);
146*699cd480SApple OSS Distributions int null_getnewvnode(
147*699cd480SApple OSS Distributions 	struct mount * mp, struct vnode * lowervp, struct vnode * dvp, struct vnode ** vpp, struct componentname * cnp, int root);
148*699cd480SApple OSS Distributions void null_hashrem(struct null_node * xp);
149*699cd480SApple OSS Distributions 
150*699cd480SApple OSS Distributions int nullfs_getbackingvnode(vnode_t in_vp, vnode_t* out_vpp);
151*699cd480SApple OSS Distributions 
152*699cd480SApple OSS Distributions vfs_context_t nullfs_get_patched_context(struct null_mount * null_mp, vfs_context_t ctx);
153*699cd480SApple OSS Distributions void nullfs_cleanup_patched_context(struct null_mount * null_mp, vfs_context_t ctx);
154*699cd480SApple OSS Distributions 
155*699cd480SApple OSS Distributions #define NULLVPTOLOWERVP(vp) (VTONULL(vp)->null_lowervp)
156*699cd480SApple OSS Distributions #define NULLVPTOLOWERVID(vp) (VTONULL(vp)->null_lowervid)
157*699cd480SApple OSS Distributions #define NULLVPTOMYVID(vp) (VTONULL(vp)->null_myvid)
158*699cd480SApple OSS Distributions 
159*699cd480SApple OSS Distributions extern const struct vnodeopv_desc nullfs_vnodeop_opv_desc;
160*699cd480SApple OSS Distributions 
161*699cd480SApple OSS Distributions extern vop_t * nullfs_vnodeop_p;
162*699cd480SApple OSS Distributions 
163*699cd480SApple OSS Distributions __END_DECLS
164*699cd480SApple OSS Distributions 
165*699cd480SApple OSS Distributions #ifdef NULLFS_DEBUG
166*699cd480SApple OSS Distributions #define NULLFSDEBUG(format, args...) printf(format, ##args)
167*699cd480SApple OSS Distributions #else
168*699cd480SApple OSS Distributions #define NULLFSDEBUG(format, args...)
169*699cd480SApple OSS Distributions #endif /* NULLFS_DEBUG */
170*699cd480SApple OSS Distributions 
171*699cd480SApple OSS Distributions #endif /* KERNEL */
172*699cd480SApple OSS Distributions 
173*699cd480SApple OSS Distributions #endif
174