1 /* $NetBSD: union.h,v 1.10 2004/05/20 06:34:27 atatat Exp $ */ 2 3 /* 4 * Copyright (c) 1994 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software donated to Berkeley by 8 * Jan-Simon Pendry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)union.h 8.9 (Berkeley) 12/10/94 35 */ 36 37 /* 38 * Copyright (c) 1994 Jan-Simon Pendry. 39 * All rights reserved. 40 * 41 * This code is derived from software donated to Berkeley by 42 * Jan-Simon Pendry. 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by the University of 55 * California, Berkeley and its contributors. 56 * 4. Neither the name of the University nor the names of its contributors 57 * may be used to endorse or promote products derived from this software 58 * without specific prior written permission. 59 * 60 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 63 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 70 * SUCH DAMAGE. 71 * 72 * @(#)union.h 8.9 (Berkeley) 12/10/94 73 */ 74 75 struct union_args { 76 char *target; /* Target of loopback */ 77 int mntflags; /* Options on the mount */ 78 }; 79 80 #define UNMNT_ABOVE 0x0001 /* Target appears below mount point */ 81 #define UNMNT_BELOW 0x0002 /* Target appears below mount point */ 82 #define UNMNT_REPLACE 0x0003 /* Target replaces mount point */ 83 #define UNMNT_OPMASK 0x0003 84 85 #define UNMNT_BITS "\177\20" \ 86 "b\00above\0b\01below\0b\02replace\0" 87 88 struct union_mount { 89 struct vnode *um_uppervp; 90 struct vnode *um_lowervp; 91 struct ucred *um_cred; /* Credentials of user calling mount */ 92 int um_cmode; /* cmask from mount process */ 93 int um_op; /* Operation mode */ 94 }; 95 96 #ifdef _KERNEL 97 98 /* 99 * DEFDIRMODE is the mode bits used to create a shadow directory. 100 */ 101 #define UN_DIRMODE (S_IRWXU|S_IRWXG|S_IRWXO) 102 #define UN_FILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 103 104 /* 105 * A cache of vnode references 106 */ 107 struct union_node { 108 LIST_ENTRY(union_node) un_cache; /* Hash chain */ 109 struct vnode *un_vnode; /* Back pointer */ 110 struct vnode *un_uppervp; /* overlaying object */ 111 struct vnode *un_lowervp; /* underlying object */ 112 struct vnode *un_dirvp; /* Parent dir of uppervp */ 113 struct vnode *un_pvp; /* Parent vnode */ 114 char *un_path; /* saved component name */ 115 int un_hash; /* saved un_path hash value */ 116 int un_openl; /* # of opens on lowervp */ 117 unsigned int un_flags; 118 struct vnode **un_dircache; /* cached union stack */ 119 off_t un_uppersz; /* size of upper object */ 120 off_t un_lowersz; /* size of lower object */ 121 #ifdef DIAGNOSTIC 122 pid_t un_pid; 123 #endif 124 }; 125 126 #define UN_WANTED 0x01 127 #define UN_LOCKED 0x02 128 #define UN_ULOCK 0x04 /* Upper node is locked */ 129 #define UN_KLOCK 0x08 /* Keep upper node locked on vput */ 130 #define UN_CACHED 0x10 /* In union cache */ 131 #define UN_DRAINING 0x20 /* upper node lock is draining */ 132 #define UN_DRAINED 0x40 /* upper node lock is drained */ 133 134 extern int union_allocvp __P((struct vnode **, struct mount *, 135 struct vnode *, struct vnode *, 136 struct componentname *, struct vnode *, 137 struct vnode *, int)); 138 extern int union_copyfile __P((struct vnode *, struct vnode *, 139 struct ucred *, struct proc *)); 140 extern int union_copyup __P((struct union_node *, int, struct ucred *, 141 struct proc *)); 142 extern void union_diruncache __P((struct union_node *)); 143 extern int union_dowhiteout __P((struct union_node *, struct ucred *, 144 struct proc *)); 145 extern int union_mkshadow __P((struct union_mount *, struct vnode *, 146 struct componentname *, struct vnode **)); 147 extern int union_mkwhiteout __P((struct union_mount *, struct vnode *, 148 struct componentname *, char *)); 149 extern int union_vn_create __P((struct vnode **, struct union_node *, 150 struct proc *)); 151 extern int union_cn_close __P((struct vnode *, int, struct ucred *, 152 struct proc *)); 153 extern void union_removed_upper __P((struct union_node *un)); 154 extern struct vnode *union_lowervp __P((struct vnode *)); 155 extern void union_newlower __P((struct union_node *, struct vnode *)); 156 extern void union_newupper __P((struct union_node *, struct vnode *)); 157 extern void union_newsize __P((struct vnode *, off_t, off_t)); 158 int union_readdirhook(struct vnode **, struct file *, struct proc *); 159 160 #define MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data)) 161 #define VTOUNION(vp) ((struct union_node *)(vp)->v_data) 162 #define UNIONTOV(un) ((un)->un_vnode) 163 #define LOWERVP(vp) (VTOUNION(vp)->un_lowervp) 164 #define UPPERVP(vp) (VTOUNION(vp)->un_uppervp) 165 #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp)) 166 167 extern int (**union_vnodeop_p) __P((void *)); 168 169 void union_init __P((void)); 170 void union_done __P((void)); 171 int union_freevp __P((struct vnode *)); 172 173 #ifdef SYSCTL_SETUP_PROTO 174 SYSCTL_SETUP_PROTO(sysctl_vfs_union_setup); 175 #endif /* SYSCTL_SETUP_PROTO */ 176 #endif /* _KERNEL */ 177