union.h revision 7090
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1994 The Regents of the University of California.
31541Srgrimes * Copyright (c) 1994 Jan-Simon Pendry.
41541Srgrimes * All rights reserved.
51541Srgrimes *
61541Srgrimes * This code is derived from software donated to Berkeley by
71541Srgrimes * Jan-Simon Pendry.
81541Srgrimes *
91541Srgrimes * Redistribution and use in source and binary forms, with or without
101541Srgrimes * modification, are permitted provided that the following conditions
111541Srgrimes * are met:
121541Srgrimes * 1. Redistributions of source code must retain the above copyright
131541Srgrimes *    notice, this list of conditions and the following disclaimer.
141541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151541Srgrimes *    notice, this list of conditions and the following disclaimer in the
161541Srgrimes *    documentation and/or other materials provided with the distribution.
171541Srgrimes * 3. All advertising materials mentioning features or use of this software
181541Srgrimes *    must display the following acknowledgement:
191541Srgrimes *	This product includes software developed by the University of
201541Srgrimes *	California, Berkeley and its contributors.
211541Srgrimes * 4. Neither the name of the University nor the names of its contributors
221541Srgrimes *    may be used to endorse or promote products derived from this software
231541Srgrimes *    without specific prior written permission.
241541Srgrimes *
251541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
261541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
271541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
281541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
331541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
341541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
351541Srgrimes * SUCH DAMAGE.
361541Srgrimes *
371541Srgrimes *	@(#)union.h	8.2 (Berkeley) 2/17/94
387090Sbde * $Id: union.h,v 1.2 1994/08/02 07:45:42 davidg Exp $
391541Srgrimes */
401541Srgrimes
411541Srgrimesstruct union_args {
421541Srgrimes	char		*target;	/* Target of loopback  */
431541Srgrimes	int		mntflags;	/* Options on the mount */
441541Srgrimes};
451541Srgrimes
461541Srgrimes#define UNMNT_ABOVE	0x0001		/* Target appears below mount point */
471541Srgrimes#define UNMNT_BELOW	0x0002		/* Target appears below mount point */
481541Srgrimes#define UNMNT_REPLACE	0x0003		/* Target replaces mount point */
491541Srgrimes#define UNMNT_OPMASK	0x0003
501541Srgrimes
511541Srgrimesstruct union_mount {
521541Srgrimes	struct vnode	*um_uppervp;
531541Srgrimes	struct vnode	*um_lowervp;
541541Srgrimes	struct ucred	*um_cred;	/* Credentials of user calling mount */
551541Srgrimes	int		um_cmode;	/* cmask from mount process */
561541Srgrimes	int		um_op;		/* Operation mode */
571541Srgrimes};
581541Srgrimes
591541Srgrimes#ifdef KERNEL
601541Srgrimes
611541Srgrimes/*
621541Srgrimes * DEFDIRMODE is the mode bits used to create a shadow directory.
631541Srgrimes */
641541Srgrimes#define VRWXMODE (VREAD|VWRITE|VEXEC)
651541Srgrimes#define VRWMODE (VREAD|VWRITE)
661541Srgrimes#define UN_DIRMODE ((VRWXMODE)|(VRWXMODE>>3)|(VRWXMODE>>6))
671541Srgrimes#define UN_FILEMODE ((VRWMODE)|(VRWMODE>>3)|(VRWMODE>>6))
681541Srgrimes
691541Srgrimes/*
701541Srgrimes * A cache of vnode references
711541Srgrimes */
721541Srgrimesstruct union_node {
731541Srgrimes	LIST_ENTRY(union_node)	un_cache;	/* Hash chain */
741541Srgrimes	struct vnode		*un_vnode;	/* Back pointer */
751541Srgrimes	struct vnode	        *un_uppervp;	/* overlaying object */
761541Srgrimes	struct vnode	        *un_lowervp;	/* underlying object */
771541Srgrimes	struct vnode		*un_dirvp;	/* Parent dir of uppervp */
781541Srgrimes	char			*un_path;	/* saved component name */
791541Srgrimes	int			un_hash;	/* saved un_path hash value */
801541Srgrimes	int			un_openl;	/* # of opens on lowervp */
811541Srgrimes	int			un_flags;
821541Srgrimes#ifdef DIAGNOSTIC
831541Srgrimes	pid_t			un_pid;
841541Srgrimes#endif
851541Srgrimes};
861541Srgrimes
871541Srgrimes#define UN_WANT		0x01
881541Srgrimes#define UN_LOCKED	0x02
891541Srgrimes#define UN_ULOCK	0x04		/* Upper node is locked */
901541Srgrimes#define UN_KLOCK	0x08		/* Keep upper node locked on vput */
911541Srgrimes
921541Srgrimesextern int union_allocvp __P((struct vnode **, struct mount *,
931541Srgrimes				struct vnode *, struct vnode *,
941541Srgrimes				struct componentname *, struct vnode *,
951541Srgrimes				struct vnode *));
967090Sbdeextern int union_freevp __P((struct vnode *));
971541Srgrimesextern int union_copyfile __P((struct proc *, struct ucred *,
981541Srgrimes				struct vnode *, struct vnode *));
991541Srgrimesextern int union_mkshadow __P((struct union_mount *, struct vnode *,
1001541Srgrimes				struct componentname *, struct vnode **));
1011541Srgrimesextern int union_vn_create __P((struct vnode **, struct union_node *,
1021541Srgrimes				struct proc *));
1037090Sbdeextern int union_vn_close __P((struct vnode *, int, struct ucred *,
1047090Sbde				struct proc *));
1051541Srgrimesextern int union_cn_close __P((struct vnode *, int, struct ucred *,
1061541Srgrimes				struct proc *));
1071541Srgrimesextern void union_removed_upper __P((struct union_node *un));
1081541Srgrimesextern struct vnode *union_lowervp __P((struct vnode *));
1091541Srgrimesextern void union_newlower __P((struct union_node *, struct vnode *));
1101541Srgrimesextern void union_newupper __P((struct union_node *, struct vnode *));
1111541Srgrimes
1121541Srgrimes#define	MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
1131541Srgrimes#define	VTOUNION(vp) ((struct union_node *)(vp)->v_data)
1141541Srgrimes#define	UNIONTOV(un) ((un)->un_vnode)
1151541Srgrimes#define	LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
1161541Srgrimes#define	UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
1171541Srgrimes#define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
1181541Srgrimes
1191541Srgrimesextern int (**union_vnodeop_p)();
1201541Srgrimesextern struct vfsops union_vfsops;
1211541Srgrimes#endif /* KERNEL */
122