xref: /xnu-10002.81.5/bsd/miscfs/bindfs/bindfs.h (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1*5e3eaea3SApple OSS Distributions /*
2*5e3eaea3SApple OSS Distributions  * Copyright (c) 2019 Apple Inc. All rights reserved.
3*5e3eaea3SApple OSS Distributions  *
4*5e3eaea3SApple OSS Distributions  * @APPLE_LICENSE_HEADER_START@
5*5e3eaea3SApple OSS Distributions  *
6*5e3eaea3SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*5e3eaea3SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*5e3eaea3SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*5e3eaea3SApple OSS Distributions  * compliance with the License. Please obtain a copy of the License at
10*5e3eaea3SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this
11*5e3eaea3SApple OSS Distributions  * file.
12*5e3eaea3SApple OSS Distributions  *
13*5e3eaea3SApple OSS Distributions  * The Original Code and all software distributed under the License are
14*5e3eaea3SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*5e3eaea3SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*5e3eaea3SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*5e3eaea3SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*5e3eaea3SApple OSS Distributions  * Please see the License for the specific language governing rights and
19*5e3eaea3SApple OSS Distributions  * limitations under the License.
20*5e3eaea3SApple OSS Distributions  *
21*5e3eaea3SApple OSS Distributions  * @APPLE_LICENSE_HEADER_END@
22*5e3eaea3SApple OSS Distributions  */
23*5e3eaea3SApple OSS Distributions 
24*5e3eaea3SApple OSS Distributions /*-
25*5e3eaea3SApple OSS Distributions  * Portions Copyright (c) 1992, 1993
26*5e3eaea3SApple OSS Distributions  *  The Regents of the University of California.  All rights reserved.
27*5e3eaea3SApple OSS Distributions  *
28*5e3eaea3SApple OSS Distributions  * This code is derived from software donated to Berkeley by
29*5e3eaea3SApple OSS Distributions  * Jan-Simon Pendry.
30*5e3eaea3SApple OSS Distributions  *
31*5e3eaea3SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
32*5e3eaea3SApple OSS Distributions  * modification, are permitted provided that the following conditions
33*5e3eaea3SApple OSS Distributions  * are met:
34*5e3eaea3SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
35*5e3eaea3SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
36*5e3eaea3SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
37*5e3eaea3SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
38*5e3eaea3SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
39*5e3eaea3SApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
40*5e3eaea3SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
41*5e3eaea3SApple OSS Distributions  *    without specific prior written permission.
42*5e3eaea3SApple OSS Distributions  *
43*5e3eaea3SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44*5e3eaea3SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45*5e3eaea3SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46*5e3eaea3SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47*5e3eaea3SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48*5e3eaea3SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49*5e3eaea3SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50*5e3eaea3SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51*5e3eaea3SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52*5e3eaea3SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53*5e3eaea3SApple OSS Distributions  * SUCH DAMAGE.
54*5e3eaea3SApple OSS Distributions  *
55*5e3eaea3SApple OSS Distributions  *  @(#)null.h  8.3 (Berkeley) 8/20/94
56*5e3eaea3SApple OSS Distributions  *
57*5e3eaea3SApple OSS Distributions  * $FreeBSD$
58*5e3eaea3SApple OSS Distributions  */
59*5e3eaea3SApple OSS Distributions 
60*5e3eaea3SApple OSS Distributions #ifndef FS_BIND_H
61*5e3eaea3SApple OSS Distributions #define FS_BIND_H
62*5e3eaea3SApple OSS Distributions 
63*5e3eaea3SApple OSS Distributions #include <sys/appleapiopts.h>
64*5e3eaea3SApple OSS Distributions #include <libkern/libkern.h>
65*5e3eaea3SApple OSS Distributions #include <sys/vnode.h>
66*5e3eaea3SApple OSS Distributions #include <sys/vnode_if.h>
67*5e3eaea3SApple OSS Distributions #include <sys/ubc.h>
68*5e3eaea3SApple OSS Distributions #include <vfs/vfs_support.h>
69*5e3eaea3SApple OSS Distributions #include <sys/lock.h>
70*5e3eaea3SApple OSS Distributions 
71*5e3eaea3SApple OSS Distributions #include <sys/cdefs.h>
72*5e3eaea3SApple OSS Distributions #include <sys/types.h>
73*5e3eaea3SApple OSS Distributions #include <sys/syslimits.h>
74*5e3eaea3SApple OSS Distributions 
75*5e3eaea3SApple OSS Distributions #if KERNEL
76*5e3eaea3SApple OSS Distributions #include <libkern/tree.h>
77*5e3eaea3SApple OSS Distributions #else
78*5e3eaea3SApple OSS Distributions #include <System/libkern/tree.h>
79*5e3eaea3SApple OSS Distributions #endif
80*5e3eaea3SApple OSS Distributions 
81*5e3eaea3SApple OSS Distributions //#define BINDFS_DEBUG 0
82*5e3eaea3SApple OSS Distributions 
83*5e3eaea3SApple OSS Distributions #define BINDM_CACHE 0x0001
84*5e3eaea3SApple OSS Distributions #define BINDM_CASEINSENSITIVE 0x0000000000000002
85*5e3eaea3SApple OSS Distributions 
86*5e3eaea3SApple OSS Distributions typedef int (*vop_t)(void *);
87*5e3eaea3SApple OSS Distributions 
88*5e3eaea3SApple OSS Distributions struct bind_mount {
89*5e3eaea3SApple OSS Distributions 	struct vnode * bindm_rootvp;       /* Reference to root bind_node (inode 1) */
90*5e3eaea3SApple OSS Distributions 	struct vnode * bindm_lowerrootvp;  /* reference to the root of the tree we are
91*5e3eaea3SApple OSS Distributions 	                                    * relocating (in the other file system) */
92*5e3eaea3SApple OSS Distributions 	uint32_t bindm_lowerrootvid;       /* store the lower root vid so we can check
93*5e3eaea3SApple OSS Distributions 	                                    * before we build the shadow vnode lazily */
94*5e3eaea3SApple OSS Distributions 	uint64_t bindm_flags;
95*5e3eaea3SApple OSS Distributions };
96*5e3eaea3SApple OSS Distributions 
97*5e3eaea3SApple OSS Distributions #ifdef KERNEL
98*5e3eaea3SApple OSS Distributions 
99*5e3eaea3SApple OSS Distributions #define BIND_FLAG_HASHED 0x000000001
100*5e3eaea3SApple OSS Distributions 
101*5e3eaea3SApple OSS Distributions /*
102*5e3eaea3SApple OSS Distributions  * A cache of vnode references
103*5e3eaea3SApple OSS Distributions  */
104*5e3eaea3SApple OSS Distributions struct bind_node {
105*5e3eaea3SApple OSS Distributions 	LIST_ENTRY(bind_node) bind_hash; /* Hash list */
106*5e3eaea3SApple OSS Distributions 	struct vnode * bind_lowervp;     /* VREFed once */
107*5e3eaea3SApple OSS Distributions 	struct vnode * bind_vnode;       /* Back pointer */
108*5e3eaea3SApple OSS Distributions 	uint32_t bind_lowervid;          /* vid for lowervp to detect lowervp getting recycled out
109*5e3eaea3SApple OSS Distributions 	                                  *  from under us */
110*5e3eaea3SApple OSS Distributions 	uint32_t bind_myvid;
111*5e3eaea3SApple OSS Distributions 	uint32_t bind_flags;
112*5e3eaea3SApple OSS Distributions };
113*5e3eaea3SApple OSS Distributions 
114*5e3eaea3SApple OSS Distributions struct vnodeop_desc_fake {
115*5e3eaea3SApple OSS Distributions 	int vdesc_offset;
116*5e3eaea3SApple OSS Distributions 	const char * vdesc_name;
117*5e3eaea3SApple OSS Distributions 	/* other stuff */
118*5e3eaea3SApple OSS Distributions };
119*5e3eaea3SApple OSS Distributions 
120*5e3eaea3SApple OSS Distributions #define BINDV_NOUNLOCK 0x0001
121*5e3eaea3SApple OSS Distributions #define BINDV_DROP 0x0002
122*5e3eaea3SApple OSS Distributions 
123*5e3eaea3SApple OSS Distributions #define MOUNTTOBINDMOUNT(mp) ((struct bind_mount *)(vfs_fsprivate(mp)))
124*5e3eaea3SApple OSS Distributions #define VTOBIND(vp) ((struct bind_node *)vnode_fsnode(vp))
125*5e3eaea3SApple OSS Distributions #define BINDTOV(xp) ((xp)->bind_vnode)
126*5e3eaea3SApple OSS Distributions 
127*5e3eaea3SApple OSS Distributions __BEGIN_DECLS
128*5e3eaea3SApple OSS Distributions 
129*5e3eaea3SApple OSS Distributions int bindfs_init(struct vfsconf * vfsp);
130*5e3eaea3SApple OSS Distributions int bindfs_destroy(void);
131*5e3eaea3SApple OSS Distributions int bind_nodeget(
132*5e3eaea3SApple OSS Distributions 	struct mount * mp, struct vnode * lowervp, struct vnode * dvp, struct vnode ** vpp, struct componentname * cnp, int root);
133*5e3eaea3SApple OSS Distributions int bind_hashget(struct mount * mp, struct vnode * lowervp, struct vnode ** vpp);
134*5e3eaea3SApple OSS Distributions int bind_getnewvnode(
135*5e3eaea3SApple OSS Distributions 	struct mount * mp, struct vnode * lowervp, struct vnode * dvp, struct vnode ** vpp, struct componentname * cnp, int root);
136*5e3eaea3SApple OSS Distributions void bind_hashrem(struct bind_node * xp);
137*5e3eaea3SApple OSS Distributions 
138*5e3eaea3SApple OSS Distributions int bindfs_getbackingvnode(vnode_t in_vp, vnode_t* out_vpp);
139*5e3eaea3SApple OSS Distributions 
140*5e3eaea3SApple OSS Distributions #define BINDVPTOLOWERVP(vp) (VTOBIND(vp)->bind_lowervp)
141*5e3eaea3SApple OSS Distributions #define BINDVPTOLOWERVID(vp) (VTOBIND(vp)->bind_lowervid)
142*5e3eaea3SApple OSS Distributions #define BINDVPTOMYVID(vp) (VTOBIND(vp)->bind_myvid)
143*5e3eaea3SApple OSS Distributions 
144*5e3eaea3SApple OSS Distributions extern const struct vnodeopv_desc bindfs_vnodeop_opv_desc;
145*5e3eaea3SApple OSS Distributions 
146*5e3eaea3SApple OSS Distributions extern vop_t * bindfs_vnodeop_p;
147*5e3eaea3SApple OSS Distributions 
148*5e3eaea3SApple OSS Distributions __END_DECLS
149*5e3eaea3SApple OSS Distributions 
150*5e3eaea3SApple OSS Distributions #ifdef BINDFS_DEBUG
151*5e3eaea3SApple OSS Distributions #define BINDFSDEBUG(format, args...) printf("DEBUG: BindFS %s: " format, __FUNCTION__, ##args)
152*5e3eaea3SApple OSS Distributions #else
153*5e3eaea3SApple OSS Distributions #define BINDFSDEBUG(format, args...)
154*5e3eaea3SApple OSS Distributions #endif /* BINDFS_DEBUG */
155*5e3eaea3SApple OSS Distributions 
156*5e3eaea3SApple OSS Distributions #define BINDFSERROR(format, args...) printf("ERROR: BindFS %s: " format, __FUNCTION__, ##args)
157*5e3eaea3SApple OSS Distributions 
158*5e3eaea3SApple OSS Distributions #endif /* KERNEL */
159*5e3eaea3SApple OSS Distributions 
160*5e3eaea3SApple OSS Distributions #endif
161