1139776Simp/*- 21541Srgrimes * Copyright (c) 1994 The Regents of the University of California. 31541Srgrimes * Copyright (c) 1994 Jan-Simon Pendry. 4164829Srodrigc * Copyright (c) 2005, 2006 Masanori Ozawa <ozawa@ongs.co.jp>, ONGS Inc. 5164829Srodrigc * Copyright (c) 2006 Daichi Goto <daichi@freebsd.org> 61541Srgrimes * All rights reserved. 71541Srgrimes * 81541Srgrimes * This code is derived from software donated to Berkeley by 91541Srgrimes * Jan-Simon Pendry. 101541Srgrimes * 111541Srgrimes * Redistribution and use in source and binary forms, with or without 121541Srgrimes * modification, are permitted provided that the following conditions 131541Srgrimes * are met: 141541Srgrimes * 1. Redistributions of source code must retain the above copyright 151541Srgrimes * notice, this list of conditions and the following disclaimer. 161541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 171541Srgrimes * notice, this list of conditions and the following disclaimer in the 181541Srgrimes * documentation and/or other materials provided with the distribution. 191541Srgrimes * 4. Neither the name of the University nor the names of its contributors 201541Srgrimes * may be used to endorse or promote products derived from this software 211541Srgrimes * without specific prior written permission. 221541Srgrimes * 231541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331541Srgrimes * SUCH DAMAGE. 341541Srgrimes * 3522521Sdyson * @(#)union.h 8.9 (Berkeley) 12/10/94 3650477Speter * $FreeBSD: releng/10.3/sys/fs/unionfs/union.h 185283 2008-11-25 03:18:35Z daichi $ 371541Srgrimes */ 381541Srgrimes 39164829Srodrigc#ifdef _KERNEL 401541Srgrimes 41164829Srodrigc/* copy method of attr from lower to upper */ 42164829Srodrigctypedef enum _unionfs_copymode { 43164829Srodrigc UNIONFS_TRADITIONAL = 0, 44164829Srodrigc UNIONFS_TRANSPARENT, 45164829Srodrigc UNIONFS_MASQUERADE 46164829Srodrigc} unionfs_copymode; 47164829Srodrigc 48172643Sdaichi/* whiteout policy of upper layer */ 49172643Sdaichitypedef enum _unionfs_whitemode { 50172643Sdaichi UNIONFS_WHITE_ALWAYS = 0, 51172643Sdaichi UNIONFS_WHITE_WHENNEEDED 52172643Sdaichi} unionfs_whitemode; 53172643Sdaichi 54164829Srodrigcstruct unionfs_mount { 55164829Srodrigc struct vnode *um_lowervp; /* VREFed once */ 56164829Srodrigc struct vnode *um_uppervp; /* VREFed once */ 57164829Srodrigc struct vnode *um_rootvp; /* ROOT vnode */ 58164829Srodrigc unionfs_copymode um_copymode; 59172643Sdaichi unionfs_whitemode um_whitemode; 60164829Srodrigc uid_t um_uid; 61164829Srodrigc gid_t um_gid; 62164829Srodrigc u_short um_udir; 63164829Srodrigc u_short um_ufile; 641541Srgrimes}; 651541Srgrimes 66164829Srodrigc/* unionfs status list */ 67164829Srodrigcstruct unionfs_node_status { 68164829Srodrigc LIST_ENTRY(unionfs_node_status) uns_list; /* Status list */ 69178491Sdaichi pid_t uns_pid; /* current process id */ 70164829Srodrigc int uns_node_flag; /* uns flag */ 71164829Srodrigc int uns_lower_opencnt; /* open count of lower */ 72164829Srodrigc int uns_upper_opencnt; /* open count of upper */ 73164829Srodrigc int uns_lower_openmode; /* open mode of lower */ 74164829Srodrigc int uns_readdir_status; /* read status of readdir */ 75164829Srodrigc}; 761541Srgrimes 77164829Srodrigc/* union node status flags */ 78164829Srodrigc#define UNS_OPENL_4_READDIR 0x01 /* open lower layer for readdir */ 7951688Sdillon 80164829Srodrigc/* A cache of vnode references */ 81164829Srodrigcstruct unionfs_node { 82164829Srodrigc struct vnode *un_lowervp; /* lower side vnode */ 83164829Srodrigc struct vnode *un_uppervp; /* upper side vnode */ 84164829Srodrigc struct vnode *un_dvp; /* parent unionfs vnode */ 85164829Srodrigc struct vnode *un_vnode; /* Back pointer */ 86178483Sdaichi LIST_HEAD(, unionfs_node_status) un_unshead; 87178483Sdaichi /* unionfs status head */ 88178483Sdaichi LIST_HEAD(unionfs_node_hashhead, unionfs_node) *un_hashtbl; 89178483Sdaichi /* dir vnode hash table */ 90178483Sdaichi LIST_ENTRY(unionfs_node) un_hash; /* hash list entry */ 91178483Sdaichi u_long un_hashmask; /* bit mask */ 92164829Srodrigc char *un_path; /* path */ 93164829Srodrigc int un_flag; /* unionfs node flag */ 941541Srgrimes}; 951541Srgrimes 96172637Sdaichi/* 97172637Sdaichi * unionfs node flags 98172637Sdaichi * It needs the vnode with exclusive lock, when changing the un_flag variable. 99172637Sdaichi */ 100172637Sdaichi#define UNIONFS_OPENEXTL 0x01 /* openextattr (lower) */ 101172637Sdaichi#define UNIONFS_OPENEXTU 0x02 /* openextattr (upper) */ 1021541Srgrimes 103164829Srodrigc#define MOUNTTOUNIONFSMOUNT(mp) ((struct unionfs_mount *)((mp)->mnt_data)) 104164829Srodrigc#define VTOUNIONFS(vp) ((struct unionfs_node *)(vp)->v_data) 105164829Srodrigc#define UNIONFSTOV(xp) ((xp)->un_vnode) 10651688Sdillon 107164829Srodrigcint unionfs_init(struct vfsconf *vfsp); 108164829Srodrigcint unionfs_uninit(struct vfsconf *vfsp); 109164829Srodrigcint unionfs_nodeget(struct mount *mp, struct vnode *uppervp, struct vnode *lowervp, struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct thread *td); 110172637Sdaichivoid unionfs_noderem(struct vnode *vp, struct thread *td); 111164829Srodrigcvoid unionfs_get_node_status(struct unionfs_node *unp, struct thread *td, struct unionfs_node_status **unspp); 112178491Sdaichivoid unionfs_tryrem_node_status(struct unionfs_node *unp, struct unionfs_node_status *unsp); 11351688Sdillon 114164829Srodrigcint unionfs_check_rmdir(struct vnode *vp, struct ucred *cred, struct thread *td); 115164829Srodrigcint unionfs_copyfile(struct unionfs_node *unp, int docopy, struct ucred *cred, struct thread *td); 116164829Srodrigcvoid unionfs_create_uppervattr_core(struct unionfs_mount *ump, struct vattr *lva, struct vattr *uva, struct thread *td); 117164829Srodrigcint unionfs_create_uppervattr(struct unionfs_mount *ump, struct vnode *lvp, struct vattr *uva, struct ucred *cred, struct thread *td); 118164829Srodrigcint unionfs_mkshadowdir(struct unionfs_mount *ump, struct vnode *duvp, struct unionfs_node *unp, struct componentname *cnp, struct thread *td); 119164829Srodrigcint unionfs_mkwhiteout(struct vnode *dvp, struct componentname *cnp, struct thread *td, char *path); 120185283Sdaichiint unionfs_relookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, struct componentname *cn, struct thread *td, char *path, int pathlen, u_long nameiop); 121164829Srodrigcint unionfs_relookup_for_create(struct vnode *dvp, struct componentname *cnp, struct thread *td); 122164829Srodrigcint unionfs_relookup_for_delete(struct vnode *dvp, struct componentname *cnp, struct thread *td); 123164829Srodrigcint unionfs_relookup_for_rename(struct vnode *dvp, struct componentname *cnp, struct thread *td); 12451688Sdillon 125164829Srodrigc#ifdef DIAGNOSTIC 126164829Srodrigcstruct vnode *unionfs_checklowervp(struct vnode *vp, char *fil, int lno); 127164829Srodrigcstruct vnode *unionfs_checkuppervp(struct vnode *vp, char *fil, int lno); 128164829Srodrigc#define UNIONFSVPTOLOWERVP(vp) unionfs_checklowervp((vp), __FILE__, __LINE__) 129164829Srodrigc#define UNIONFSVPTOUPPERVP(vp) unionfs_checkuppervp((vp), __FILE__, __LINE__) 130164829Srodrigc#else 131164829Srodrigc#define UNIONFSVPTOLOWERVP(vp) (VTOUNIONFS(vp)->un_lowervp) 132164829Srodrigc#define UNIONFSVPTOUPPERVP(vp) (VTOUNIONFS(vp)->un_uppervp) 133164829Srodrigc#endif 1341541Srgrimes 135164829Srodrigcextern struct vop_vector unionfs_vnodeops; 13640852Speter 137164829Srodrigc#ifdef MALLOC_DECLARE 138164829SrodrigcMALLOC_DECLARE(M_UNIONFSNODE); 139164829SrodrigcMALLOC_DECLARE(M_UNIONFSPATH); 140164829Srodrigc#endif 1411541Srgrimes 142164829Srodrigc#ifdef UNIONFS_DEBUG 143164829Srodrigc#define UNIONFSDEBUG(format, args...) printf(format ,## args) 144164829Srodrigc#else 145164829Srodrigc#define UNIONFSDEBUG(format, args...) 146164829Srodrigc#endif /* UNIONFS_DEBUG */ 14751688Sdillon 148164829Srodrigc#endif /* _KERNEL */ 149