1*1a710239Sad /*- 2*1a710239Sad * Copyright (c) 1994 The Regents of the University of California. 3*1a710239Sad * Copyright (c) 1994 Jan-Simon Pendry. 4*1a710239Sad * Copyright (c) 2005, 2006 Masanori Ozawa <ozawa@ongs.co.jp>, ONGS Inc. 5*1a710239Sad * Copyright (c) 2006 Daichi Goto <daichi@freebsd.org> 6*1a710239Sad * All rights reserved. 7*1a710239Sad * 8*1a710239Sad * This code is derived from software donated to Berkeley by 9*1a710239Sad * Jan-Simon Pendry. 10*1a710239Sad * 11*1a710239Sad * Redistribution and use in source and binary forms, with or without 12*1a710239Sad * modification, are permitted provided that the following conditions 13*1a710239Sad * are met: 14*1a710239Sad * 1. Redistributions of source code must retain the above copyright 15*1a710239Sad * notice, this list of conditions and the following disclaimer. 16*1a710239Sad * 2. Redistributions in binary form must reproduce the above copyright 17*1a710239Sad * notice, this list of conditions and the following disclaimer in the 18*1a710239Sad * documentation and/or other materials provided with the distribution. 19*1a710239Sad * 4. Neither the name of the University nor the names of its contributors 20*1a710239Sad * may be used to endorse or promote products derived from this software 21*1a710239Sad * without specific prior written permission. 22*1a710239Sad * 23*1a710239Sad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24*1a710239Sad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25*1a710239Sad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26*1a710239Sad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27*1a710239Sad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28*1a710239Sad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29*1a710239Sad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30*1a710239Sad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31*1a710239Sad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32*1a710239Sad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33*1a710239Sad * SUCH DAMAGE. 34*1a710239Sad * 35*1a710239Sad * @(#)union.h 8.9 (Berkeley) 12/10/94 36*1a710239Sad * $FreeBSD: src/sys/fs/unionfs/union.h,v 1.36 2007/10/14 13:55:38 daichi Exp $ 37*1a710239Sad */ 38*1a710239Sad 39*1a710239Sad #ifndef _MISCFS_UNION_H_ 40*1a710239Sad #define _MISCFS_UNION_H_ 41*1a710239Sad 42*1a710239Sad #define UNIONFS_DEBUG 43*1a710239Sad 44*1a710239Sad struct union_args { 45*1a710239Sad char *target; /* Target of loopback */ 46*1a710239Sad int mntflags; /* Options on the mount */ 47*1a710239Sad }; 48*1a710239Sad #define unionfs_args union_args 49*1a710239Sad 50*1a710239Sad #define UNMNT_ABOVE 0x0001 /* Target appears below mount point */ 51*1a710239Sad #define UNMNT_BELOW 0x0002 /* Target appears below mount point */ 52*1a710239Sad #define UNMNT_REPLACE 0x0003 /* Target replaces mount point */ 53*1a710239Sad #define UNMNT_OPMASK 0x0003 54*1a710239Sad 55*1a710239Sad #define UNMNT_BITS "\177\20" \ 56*1a710239Sad "b\00above\0b\01below\0b\02replace\0" 57*1a710239Sad 58*1a710239Sad #ifdef _KERNEL 59*1a710239Sad 60*1a710239Sad /* copy method of attr from lower to upper */ 61*1a710239Sad typedef enum _unionfs_copymode { 62*1a710239Sad UNIONFS_TRADITIONAL = 0, 63*1a710239Sad UNIONFS_TRANSPARENT, 64*1a710239Sad UNIONFS_MASQUERADE 65*1a710239Sad } unionfs_copymode; 66*1a710239Sad 67*1a710239Sad /* whiteout policy of upper layer */ 68*1a710239Sad typedef enum _unionfs_whitemode { 69*1a710239Sad UNIONFS_WHITE_ALWAYS = 0, 70*1a710239Sad UNIONFS_WHITE_WHENNEEDED 71*1a710239Sad } unionfs_whitemode; 72*1a710239Sad 73*1a710239Sad struct unionfs_mount { 74*1a710239Sad struct vnode *um_lowervp; /* VREFed once */ 75*1a710239Sad struct vnode *um_uppervp; /* VREFed once */ 76*1a710239Sad struct vnode *um_rootvp; /* ROOT vnode */ 77*1a710239Sad kmutex_t um_lock; 78*1a710239Sad unionfs_copymode um_copymode; 79*1a710239Sad unionfs_whitemode um_whitemode; 80*1a710239Sad uid_t um_uid; 81*1a710239Sad gid_t um_gid; 82*1a710239Sad int um_op; /* Operation mode */ 83*1a710239Sad u_short um_udir; 84*1a710239Sad u_short um_ufile; 85*1a710239Sad }; 86*1a710239Sad 87*1a710239Sad /* unionfs status list */ 88*1a710239Sad struct unionfs_node_status { 89*1a710239Sad LIST_ENTRY(unionfs_node_status) uns_list; /* Status list */ 90*1a710239Sad pid_t uns_pid; /* current process id */ 91*1a710239Sad lwpid_t uns_lid; /* current thread id */ 92*1a710239Sad int uns_node_flag; /* uns flag */ 93*1a710239Sad int uns_lower_opencnt; /* open count of lower */ 94*1a710239Sad int uns_upper_opencnt; /* open count of upper */ 95*1a710239Sad int uns_lower_openmode; /* open mode of lower */ 96*1a710239Sad int uns_readdir_status; /* read status of readdir */ 97*1a710239Sad }; 98*1a710239Sad 99*1a710239Sad /* union node status flags */ 100*1a710239Sad #define UNS_OPENL_4_READDIR 0x01 /* open lower layer for readdir */ 101*1a710239Sad 102*1a710239Sad /* A cache of vnode references */ 103*1a710239Sad struct unionfs_node { 104*1a710239Sad struct vnode *un_lowervp; /* lower side vnode */ 105*1a710239Sad struct vnode *un_uppervp; /* upper side vnode */ 106*1a710239Sad struct vnode *un_dvp; /* parent unionfs vnode */ 107*1a710239Sad struct vnode *un_vnode; /* Back pointer */ 108*1a710239Sad LIST_HEAD(, unionfs_node_status) un_unshead; /* unionfs status head */ 109*1a710239Sad char *un_path; /* path */ 110*1a710239Sad int un_flag; /* unionfs node flag */ 111*1a710239Sad }; 112*1a710239Sad 113*1a710239Sad /* 114*1a710239Sad * unionfs node flags 115*1a710239Sad * It needs the vnode with exclusive lock, when changing the un_flag variable. 116*1a710239Sad */ 117*1a710239Sad #define UNIONFS_OPENEXTL 0x01 /* openextattr (lower) */ 118*1a710239Sad #define UNIONFS_OPENEXTU 0x02 /* openextattr (upper) */ 119*1a710239Sad 120*1a710239Sad #define MOUNTTOUNIONFSMOUNT(mp) ((struct unionfs_mount *)((mp)->mnt_data)) 121*1a710239Sad #define VTOUNIONFS(vp) ((struct unionfs_node *)(vp)->v_data) 122*1a710239Sad #define UNIONFSTOV(xp) ((xp)->un_vnode) 123*1a710239Sad 124*1a710239Sad int unionfs_nodeget(struct mount *mp, struct vnode *uppervp, struct vnode *lowervp, struct vnode *dvp, struct vnode **vpp, struct componentname *cnp); 125*1a710239Sad void unionfs_noderem(struct vnode *vp); 126*1a710239Sad void unionfs_get_node_status(struct unionfs_node *unp, struct unionfs_node_status **unspp); 127*1a710239Sad void unionfs_tryrem_node_status(struct unionfs_node *unp, struct unionfs_node_status *unsp); 128*1a710239Sad 129*1a710239Sad int unionfs_check_rmdir(struct vnode *vp, kauth_cred_t cred); 130*1a710239Sad int unionfs_copyfile(struct unionfs_node *unp, int docopy, kauth_cred_t cred); 131*1a710239Sad void unionfs_create_uppervattr_core(struct unionfs_mount *ump, struct vattr *lva, struct vattr *uva); 132*1a710239Sad int unionfs_create_uppervattr(struct unionfs_mount *ump, struct vnode *lvp, struct vattr *uva, kauth_cred_t cred); 133*1a710239Sad int unionfs_mkshadowdir(struct unionfs_mount *ump, struct vnode *duvp, struct unionfs_node *unp, struct componentname *cnp); 134*1a710239Sad int unionfs_mkwhiteout(struct vnode *dvp, struct componentname *cnp, const char *path); 135*1a710239Sad int unionfs_relookup_for_create(struct vnode *dvp, struct componentname *cnp); 136*1a710239Sad int unionfs_relookup_for_delete(struct vnode *dvp, struct componentname *cnp); 137*1a710239Sad int unionfs_relookup_for_rename(struct vnode *dvp, struct componentname *cnp); 138*1a710239Sad 139*1a710239Sad #ifdef DIAGNOSTIC 140*1a710239Sad struct vnode *unionfs_checklowervp(struct vnode *vp, const char *fil, int lno); 141*1a710239Sad struct vnode *unionfs_checkuppervp(struct vnode *vp, const char *fil, int lno); 142*1a710239Sad #define UNIONFSVPTOLOWERVP(vp) unionfs_checklowervp((vp), __FILE__, __LINE__) 143*1a710239Sad #define UNIONFSVPTOUPPERVP(vp) unionfs_checkuppervp((vp), __FILE__, __LINE__) 144*1a710239Sad #else 145*1a710239Sad #define UNIONFSVPTOLOWERVP(vp) (VTOUNIONFS(vp)->un_lowervp) 146*1a710239Sad #define UNIONFSVPTOUPPERVP(vp) (VTOUNIONFS(vp)->un_uppervp) 147*1a710239Sad #endif 148*1a710239Sad 149*1a710239Sad extern int (**unionfs_vnodeop_p)(void *); 150*1a710239Sad 151*1a710239Sad #ifdef MALLOC_DECLARE 152*1a710239Sad MALLOC_DECLARE(M_UNIONFSPATH); 153*1a710239Sad #endif 154*1a710239Sad 155*1a710239Sad #ifdef UNIONFS_DEBUG 156*1a710239Sad #define UNIONFSDEBUG(format, args...) printf(format ,## args) 157*1a710239Sad #else 158*1a710239Sad #define UNIONFSDEBUG(format, args...) 159*1a710239Sad #endif /* UNIONFS_DEBUG */ 160*1a710239Sad 161*1a710239Sad #endif /* _KERNEL */ 162*1a710239Sad #endif /* _MISCFS_UNION_H_ */ 163