union.h revision 51688
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 *
3722521Sdyson *	@(#)union.h	8.9 (Berkeley) 12/10/94
3850477Speter * $FreeBSD: head/sys/fs/unionfs/union.h 51688 1999-09-26 20:52:41Z dillon $
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 {
5251688Sdillon	struct vnode	*um_uppervp;	/* UN_ULOCK holds locking state */
5351688Sdillon	struct vnode	*um_lowervp;	/* Left unlocked */
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
6151688Sdillon#ifndef DIAGNOSTIC
6251688Sdillon#define DIAGNOSTIC
6351688Sdillon#endif
6451688Sdillon
651541Srgrimes/*
661541Srgrimes * DEFDIRMODE is the mode bits used to create a shadow directory.
671541Srgrimes */
681541Srgrimes#define VRWXMODE (VREAD|VWRITE|VEXEC)
691541Srgrimes#define VRWMODE (VREAD|VWRITE)
701541Srgrimes#define UN_DIRMODE ((VRWXMODE)|(VRWXMODE>>3)|(VRWXMODE>>6))
711541Srgrimes#define UN_FILEMODE ((VRWMODE)|(VRWMODE>>3)|(VRWMODE>>6))
721541Srgrimes
731541Srgrimes/*
7451688Sdillon * A cache of vnode references	(hangs off v_data)
7551688Sdillon *
7651688Sdillon * Placing un_lock as the first elements theoretically allows us to
7751688Sdillon * use the vop_stdlock functions.  However, we need to make sure of
7851688Sdillon * certain side effects so we will still punch in our own code.
791541Srgrimes */
801541Srgrimesstruct union_node {
8151688Sdillon	struct lock		un_lock;
821541Srgrimes	LIST_ENTRY(union_node)	un_cache;	/* Hash chain */
831541Srgrimes	struct vnode		*un_vnode;	/* Back pointer */
841541Srgrimes	struct vnode	        *un_uppervp;	/* overlaying object */
851541Srgrimes	struct vnode	        *un_lowervp;	/* underlying object */
861541Srgrimes	struct vnode		*un_dirvp;	/* Parent dir of uppervp */
8722521Sdyson	struct vnode		*un_pvp;	/* Parent vnode */
881541Srgrimes	char			*un_path;	/* saved component name */
891541Srgrimes	int			un_hash;	/* saved un_path hash value */
901541Srgrimes	int			un_openl;	/* # of opens on lowervp */
9151688Sdillon	int			un_exclcnt;	/* exclusive count */
9222521Sdyson	unsigned int		un_flags;
9322521Sdyson	struct vnode		**un_dircache;	/* cached union stack */
9422521Sdyson	off_t			un_uppersz;	/* size of upper object */
9522521Sdyson	off_t			un_lowersz;	/* size of lower object */
961541Srgrimes#ifdef DIAGNOSTIC
971541Srgrimes	pid_t			un_pid;
981541Srgrimes#endif
991541Srgrimes};
1001541Srgrimes
10151688Sdillon/*
10251688Sdillon * XXX UN_ULOCK -	indicates that the uppervp is locked
10351688Sdillon *
10451688Sdillon * UN_CACHED -	node is in the union cache
10551688Sdillon */
1061541Srgrimes
10751688Sdillon/*#define UN_ULOCK	0x04*/	/* Upper node is locked */
10851688Sdillon#define UN_CACHED	0x10	/* In union cache */
10951688Sdillon
11051688Sdillon/*
11151688Sdillon * Hash table locking flags
11251688Sdillon */
11351688Sdillon
11451688Sdillon#define UNVP_WANT	0x01
11551688Sdillon#define UNVP_LOCKED	0x02
11651688Sdillon
1171541Srgrimesextern int union_allocvp __P((struct vnode **, struct mount *,
11851688Sdillon				struct vnode *,
11951688Sdillon				struct vnode *,
1201541Srgrimes				struct componentname *, struct vnode *,
12122521Sdyson				struct vnode *, int));
1227090Sbdeextern int union_freevp __P((struct vnode *));
12322582Smppextern struct vnode *union_dircache __P((struct vnode *, struct proc *));
12422521Sdysonextern int union_copyup __P((struct union_node *, int, struct ucred *,
12522521Sdyson				struct proc *));
12622521Sdysonextern int union_dowhiteout __P((struct union_node *, struct ucred *,
12722521Sdyson					struct proc *));
1281541Srgrimesextern int union_mkshadow __P((struct union_mount *, struct vnode *,
1291541Srgrimes				struct componentname *, struct vnode **));
13022521Sdysonextern int union_mkwhiteout __P((struct union_mount *, struct vnode *,
13122521Sdyson				struct componentname *, char *));
1321541Srgrimesextern int union_cn_close __P((struct vnode *, int, struct ucred *,
1331541Srgrimes				struct proc *));
1341541Srgrimesextern void union_removed_upper __P((struct union_node *un));
1351541Srgrimesextern struct vnode *union_lowervp __P((struct vnode *));
13622521Sdysonextern void union_newsize __P((struct vnode *, off_t, off_t));
13751688Sdillonextern void union_vm_coherency __P((struct vnode *, struct uio *, int));
1381541Srgrimes
13940852Speterextern int (*union_dircheckp) __P((struct proc *, struct vnode **,
14040852Speter				 struct file *));
14140852Speter
1421541Srgrimes#define	MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
1431541Srgrimes#define	VTOUNION(vp) ((struct union_node *)(vp)->v_data)
1441541Srgrimes#define	UNIONTOV(un) ((un)->un_vnode)
1451541Srgrimes#define	LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
1461541Srgrimes#define	UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
1471541Srgrimes#define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
1481541Srgrimes
14951688Sdillon#define UDEBUG(x)	if (uniondebug) printf x
15051688Sdillon#define UDEBUG_ENABLED	1
15151688Sdillon
15212158Sbdeextern vop_t **union_vnodeop_p;
1531541Srgrimesextern struct vfsops union_vfsops;
15451688Sdillonextern int uniondebug;
15551688Sdillon
1561541Srgrimes#endif /* KERNEL */
157