Home | History | Annotate | Line # | Download | only in union
union.h revision 1.6
      1 /*	$NetBSD: union.h,v 1.6 2003/06/29 18:43:27 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 The Regents of the University of California.
      5  * Copyright (c) 1994 Jan-Simon Pendry.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software donated to Berkeley by
      9  * Jan-Simon Pendry.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the University of
     22  *	California, Berkeley and its contributors.
     23  * 4. Neither the name of the University nor the names of its contributors
     24  *    may be used to endorse or promote products derived from this software
     25  *    without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  * SUCH DAMAGE.
     38  *
     39  *	@(#)union.h	8.9 (Berkeley) 12/10/94
     40  */
     41 
     42 struct union_args {
     43 	char		*target;	/* Target of loopback  */
     44 	int		mntflags;	/* Options on the mount */
     45 };
     46 
     47 #define UNMNT_ABOVE	0x0001		/* Target appears below mount point */
     48 #define UNMNT_BELOW	0x0002		/* Target appears below mount point */
     49 #define UNMNT_REPLACE	0x0003		/* Target replaces mount point */
     50 #define UNMNT_OPMASK	0x0003
     51 
     52 #define UNMNT_BITS "\177\20" \
     53     "b\00above\0b\01below\0b\02replace"
     54 
     55 struct union_mount {
     56 	struct vnode	*um_uppervp;
     57 	struct vnode	*um_lowervp;
     58 	struct ucred	*um_cred;	/* Credentials of user calling mount */
     59 	int		um_cmode;	/* cmask from mount process */
     60 	int		um_op;		/* Operation mode */
     61 };
     62 
     63 #ifdef _KERNEL
     64 
     65 /*
     66  * DEFDIRMODE is the mode bits used to create a shadow directory.
     67  */
     68 #define	UN_DIRMODE	(S_IRWXU|S_IRWXG|S_IRWXO)
     69 #define	UN_FILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
     70 
     71 /*
     72  * A cache of vnode references
     73  */
     74 struct union_node {
     75 	LIST_ENTRY(union_node)	un_cache;	/* Hash chain */
     76 	struct vnode		*un_vnode;	/* Back pointer */
     77 	struct vnode	        *un_uppervp;	/* overlaying object */
     78 	struct vnode	        *un_lowervp;	/* underlying object */
     79 	struct vnode		*un_dirvp;	/* Parent dir of uppervp */
     80 	struct vnode		*un_pvp;	/* Parent vnode */
     81 	char			*un_path;	/* saved component name */
     82 	int			un_hash;	/* saved un_path hash value */
     83 	int			un_openl;	/* # of opens on lowervp */
     84 	unsigned int		un_flags;
     85 	struct vnode		**un_dircache;	/* cached union stack */
     86 	off_t			un_uppersz;	/* size of upper object */
     87 	off_t			un_lowersz;	/* size of lower object */
     88 #ifdef DIAGNOSTIC
     89 	pid_t			un_pid;
     90 #endif
     91 };
     92 
     93 #define UN_WANTED	0x01
     94 #define UN_LOCKED	0x02
     95 #define UN_ULOCK	0x04		/* Upper node is locked */
     96 #define UN_KLOCK	0x08		/* Keep upper node locked on vput */
     97 #define UN_CACHED	0x10		/* In union cache */
     98 #define UN_DRAINING	0x20		/* upper node lock is draining */
     99 #define UN_DRAINED	0x40		/* upper node lock is drained */
    100 
    101 extern int union_allocvp __P((struct vnode **, struct mount *,
    102 				struct vnode *, struct vnode *,
    103 				struct componentname *, struct vnode *,
    104 				struct vnode *, int));
    105 extern int union_copyfile __P((struct vnode *, struct vnode *,
    106 					struct ucred *, struct lwp *));
    107 extern int union_copyup __P((struct union_node *, int, struct ucred *,
    108 				struct lwp *));
    109 extern void union_diruncache __P((struct union_node *));
    110 extern int union_dowhiteout __P((struct union_node *, struct ucred *,
    111 					struct lwp *));
    112 extern int union_mkshadow __P((struct union_mount *, struct vnode *,
    113 				struct componentname *, struct vnode **));
    114 extern int union_mkwhiteout __P((struct union_mount *, struct vnode *,
    115 				struct componentname *, char *));
    116 extern int union_vn_create __P((struct vnode **, struct union_node *,
    117 				struct lwp *));
    118 extern int union_cn_close __P((struct vnode *, int, struct ucred *,
    119 				struct lwp *));
    120 extern void union_removed_upper __P((struct union_node *un));
    121 extern struct vnode *union_lowervp __P((struct vnode *));
    122 extern void union_newlower __P((struct union_node *, struct vnode *));
    123 extern void union_newupper __P((struct union_node *, struct vnode *));
    124 extern void union_newsize __P((struct vnode *, off_t, off_t));
    125 int union_readdirhook(struct vnode **, struct file *, struct lwp *);
    126 
    127 #define	MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
    128 #define	VTOUNION(vp) ((struct union_node *)(vp)->v_data)
    129 #define	UNIONTOV(un) ((un)->un_vnode)
    130 #define	LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
    131 #define	UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
    132 #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
    133 
    134 extern int (**union_vnodeop_p) __P((void *));
    135 
    136 void union_init __P((void));
    137 void union_done __P((void));
    138 int union_freevp __P((struct vnode *));
    139 
    140 #endif /* _KERNEL */
    141