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