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