1*d117c814Shannken /* $NetBSD: union.h,v 1.30 2020/08/18 09:44:07 hannken Exp $ */ 2a0deb3e9Sjdolecek 3a0deb3e9Sjdolecek /* 4a0deb3e9Sjdolecek * Copyright (c) 1994 The Regents of the University of California. 5aad01611Sagc * All rights reserved. 6aad01611Sagc * 7aad01611Sagc * This code is derived from software donated to Berkeley by 8aad01611Sagc * Jan-Simon Pendry. 9aad01611Sagc * 10aad01611Sagc * Redistribution and use in source and binary forms, with or without 11aad01611Sagc * modification, are permitted provided that the following conditions 12aad01611Sagc * are met: 13aad01611Sagc * 1. Redistributions of source code must retain the above copyright 14aad01611Sagc * notice, this list of conditions and the following disclaimer. 15aad01611Sagc * 2. Redistributions in binary form must reproduce the above copyright 16aad01611Sagc * notice, this list of conditions and the following disclaimer in the 17aad01611Sagc * documentation and/or other materials provided with the distribution. 18aad01611Sagc * 3. Neither the name of the University nor the names of its contributors 19aad01611Sagc * may be used to endorse or promote products derived from this software 20aad01611Sagc * without specific prior written permission. 21aad01611Sagc * 22aad01611Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23aad01611Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24aad01611Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25aad01611Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26aad01611Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27aad01611Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28aad01611Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29aad01611Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30aad01611Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31aad01611Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32aad01611Sagc * SUCH DAMAGE. 33aad01611Sagc * 34aad01611Sagc * @(#)union.h 8.9 (Berkeley) 12/10/94 35aad01611Sagc */ 36aad01611Sagc 37aad01611Sagc /* 38a0deb3e9Sjdolecek * Copyright (c) 1994 Jan-Simon Pendry. 39a0deb3e9Sjdolecek * All rights reserved. 40a0deb3e9Sjdolecek * 41a0deb3e9Sjdolecek * This code is derived from software donated to Berkeley by 42a0deb3e9Sjdolecek * Jan-Simon Pendry. 43a0deb3e9Sjdolecek * 44a0deb3e9Sjdolecek * Redistribution and use in source and binary forms, with or without 45a0deb3e9Sjdolecek * modification, are permitted provided that the following conditions 46a0deb3e9Sjdolecek * are met: 47a0deb3e9Sjdolecek * 1. Redistributions of source code must retain the above copyright 48a0deb3e9Sjdolecek * notice, this list of conditions and the following disclaimer. 49a0deb3e9Sjdolecek * 2. Redistributions in binary form must reproduce the above copyright 50a0deb3e9Sjdolecek * notice, this list of conditions and the following disclaimer in the 51a0deb3e9Sjdolecek * documentation and/or other materials provided with the distribution. 52a0deb3e9Sjdolecek * 3. All advertising materials mentioning features or use of this software 53a0deb3e9Sjdolecek * must display the following acknowledgement: 54a0deb3e9Sjdolecek * This product includes software developed by the University of 55a0deb3e9Sjdolecek * California, Berkeley and its contributors. 56a0deb3e9Sjdolecek * 4. Neither the name of the University nor the names of its contributors 57a0deb3e9Sjdolecek * may be used to endorse or promote products derived from this software 58a0deb3e9Sjdolecek * without specific prior written permission. 59a0deb3e9Sjdolecek * 60a0deb3e9Sjdolecek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 61a0deb3e9Sjdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 62a0deb3e9Sjdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 63a0deb3e9Sjdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 64a0deb3e9Sjdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 65a0deb3e9Sjdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 66a0deb3e9Sjdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 67a0deb3e9Sjdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 68a0deb3e9Sjdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 69a0deb3e9Sjdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 70a0deb3e9Sjdolecek * SUCH DAMAGE. 71a0deb3e9Sjdolecek * 72a0deb3e9Sjdolecek * @(#)union.h 8.9 (Berkeley) 12/10/94 73a0deb3e9Sjdolecek */ 74a0deb3e9Sjdolecek 754bffed72Schristos #ifndef _MISCFS_UNION_H_ 764bffed72Schristos #define _MISCFS_UNION_H_ 774bffed72Schristos 78a0deb3e9Sjdolecek struct union_args { 79a0deb3e9Sjdolecek char *target; /* Target of loopback */ 80a0deb3e9Sjdolecek int mntflags; /* Options on the mount */ 81a0deb3e9Sjdolecek }; 82a0deb3e9Sjdolecek 83a0deb3e9Sjdolecek #define UNMNT_ABOVE 0x0001 /* Target appears below mount point */ 84a0deb3e9Sjdolecek #define UNMNT_BELOW 0x0002 /* Target appears below mount point */ 85a0deb3e9Sjdolecek #define UNMNT_REPLACE 0x0003 /* Target replaces mount point */ 86a0deb3e9Sjdolecek #define UNMNT_OPMASK 0x0003 87a0deb3e9Sjdolecek 88a0deb3e9Sjdolecek #define UNMNT_BITS "\177\20" \ 89589e82f2Syamt "b\00above\0b\01below\0b\02replace\0" 90a0deb3e9Sjdolecek 91fc9422c9Selad #ifdef _KERNEL 92fc9422c9Selad 93a0deb3e9Sjdolecek struct union_mount { 94a0deb3e9Sjdolecek struct vnode *um_uppervp; 95a0deb3e9Sjdolecek struct vnode *um_lowervp; 96fc9422c9Selad kauth_cred_t um_cred; /* Credentials of user calling mount */ 97a0deb3e9Sjdolecek int um_cmode; /* cmask from mount process */ 98a0deb3e9Sjdolecek int um_op; /* Operation mode */ 99a0deb3e9Sjdolecek }; 100a0deb3e9Sjdolecek 101a0deb3e9Sjdolecek /* 102a0deb3e9Sjdolecek * DEFDIRMODE is the mode bits used to create a shadow directory. 103a0deb3e9Sjdolecek */ 104a0deb3e9Sjdolecek #define UN_DIRMODE (S_IRWXU|S_IRWXG|S_IRWXO) 105a0deb3e9Sjdolecek #define UN_FILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 106a0deb3e9Sjdolecek 107a0deb3e9Sjdolecek /* 1084e825063Shannken * A cache of vnode references. 1094e825063Shannken * Lock requirements are: 1104e825063Shannken * 1114e825063Shannken * : stable 1124e825063Shannken * c unheadlock[hash] 1134e825063Shannken * l un_lock 1144e825063Shannken * m un_lock or vnode lock to read, un_lock and 1154e825063Shannken * exclusive vnode lock to write 1164e825063Shannken * v vnode lock to read, exclusive vnode lock to write 1174e825063Shannken * 1184e825063Shannken * Lock order is vnode then un_lock. 119a0deb3e9Sjdolecek */ 120a0deb3e9Sjdolecek struct union_node { 1214e825063Shannken kmutex_t un_lock; 1224e825063Shannken LIST_ENTRY(union_node) un_cache; /* c: Hash chain */ 123c20c5717Shannken int un_refs; /* c: Reference counter */ 1248596fa40Shannken struct mount *un_mount; /* c: union mount */ 1254e825063Shannken struct vnode *un_vnode; /* :: Back pointer */ 1264e825063Shannken struct vnode *un_uppervp; /* m: overlaying object */ 1274e825063Shannken struct vnode *un_lowervp; /* v: underlying object */ 1284e825063Shannken struct vnode *un_dirvp; /* v: Parent dir of uppervp */ 1294e825063Shannken struct vnode *un_pvp; /* v: Parent vnode */ 1304e825063Shannken char *un_path; /* v: saved component name */ 1314e825063Shannken int un_openl; /* v: # of opens on lowervp */ 1324e825063Shannken unsigned int un_cflags; /* c: cache flags */ 133*d117c814Shannken bool un_hooknode; /* :: from union_readdirhook */ 1344e825063Shannken struct vnode **un_dircache; /* v: cached union stack */ 1354e825063Shannken off_t un_uppersz; /* l: size of upper object */ 1364e825063Shannken off_t un_lowersz; /* l: size of lower object */ 137a0deb3e9Sjdolecek }; 138a0deb3e9Sjdolecek 139a0deb3e9Sjdolecek #define UN_CACHED 0x10 /* In union cache */ 140a0deb3e9Sjdolecek 14137ed0ed9Sxtraeme extern int union_allocvp(struct vnode **, struct mount *, 142a0deb3e9Sjdolecek struct vnode *, struct vnode *, 143a0deb3e9Sjdolecek struct componentname *, struct vnode *, 14437ed0ed9Sxtraeme struct vnode *, int); 145342315ffShannken extern int union_check_rmdir(struct union_node *, kauth_cred_t); 146fc9422c9Selad extern int union_copyfile(struct vnode *, struct vnode *, kauth_cred_t, 147fc9422c9Selad struct lwp *); 148fc9422c9Selad extern int union_copyup(struct union_node *, int, kauth_cred_t, 14995e1ffb1Schristos struct lwp *); 15037ed0ed9Sxtraeme extern void union_diruncache(struct union_node *); 151db06a930Spooka extern int union_dowhiteout(struct union_node *, kauth_cred_t); 15237ed0ed9Sxtraeme extern int union_mkshadow(struct union_mount *, struct vnode *, 15337ed0ed9Sxtraeme struct componentname *, struct vnode **); 15437ed0ed9Sxtraeme extern int union_mkwhiteout(struct union_mount *, struct vnode *, 155f937bd97Shannken struct componentname *, struct union_node *); 15637ed0ed9Sxtraeme extern int union_vn_create(struct vnode **, struct union_node *, 15795e1ffb1Schristos struct lwp *); 158fc9422c9Selad extern int union_cn_close(struct vnode *, int, kauth_cred_t, 15995e1ffb1Schristos struct lwp *); 16037ed0ed9Sxtraeme extern void union_removed_upper(struct union_node *un); 16137ed0ed9Sxtraeme extern struct vnode *union_lowervp(struct vnode *); 16237ed0ed9Sxtraeme extern void union_newsize(struct vnode *, off_t, off_t); 16395e1ffb1Schristos int union_readdirhook(struct vnode **, struct file *, struct lwp *); 164a0deb3e9Sjdolecek 1658596fa40Shannken VFS_PROTOS(union); 1668596fa40Shannken 167a0deb3e9Sjdolecek #define MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data)) 168a0deb3e9Sjdolecek #define VTOUNION(vp) ((struct union_node *)(vp)->v_data) 169a0deb3e9Sjdolecek #define UNIONTOV(un) ((un)->un_vnode) 170a0deb3e9Sjdolecek #define LOWERVP(vp) (VTOUNION(vp)->un_lowervp) 171a0deb3e9Sjdolecek #define UPPERVP(vp) (VTOUNION(vp)->un_uppervp) 172a0deb3e9Sjdolecek #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp)) 1734e825063Shannken #define LOCKVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : (vp)) 174a0deb3e9Sjdolecek 17537ed0ed9Sxtraeme extern int (**union_vnodeop_p)(void *); 176a0deb3e9Sjdolecek 17737ed0ed9Sxtraeme void union_init(void); 178035b1022Shannken void union_reinit(void); 17937ed0ed9Sxtraeme void union_done(void); 18037ed0ed9Sxtraeme int union_freevp(struct vnode *); 181a0deb3e9Sjdolecek 182a0deb3e9Sjdolecek #endif /* _KERNEL */ 1834bffed72Schristos #endif /* _MISCFS_UNION_H_ */ 184