Home | History | Annotate | Line # | Download | only in union
union.h revision 1.24.2.1
      1  1.24.2.1     rmind /*	$NetBSD: union.h,v 1.24.2.1 2014/05/18 17:46:07 rmind Exp $	*/
      2       1.1  jdolecek 
      3       1.1  jdolecek /*
      4       1.1  jdolecek  * Copyright (c) 1994 The Regents of the University of California.
      5       1.8       agc  * All rights reserved.
      6       1.8       agc  *
      7       1.8       agc  * This code is derived from software donated to Berkeley by
      8       1.8       agc  * Jan-Simon Pendry.
      9       1.8       agc  *
     10       1.8       agc  * Redistribution and use in source and binary forms, with or without
     11       1.8       agc  * modification, are permitted provided that the following conditions
     12       1.8       agc  * are met:
     13       1.8       agc  * 1. Redistributions of source code must retain the above copyright
     14       1.8       agc  *    notice, this list of conditions and the following disclaimer.
     15       1.8       agc  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.8       agc  *    notice, this list of conditions and the following disclaimer in the
     17       1.8       agc  *    documentation and/or other materials provided with the distribution.
     18       1.8       agc  * 3. Neither the name of the University nor the names of its contributors
     19       1.8       agc  *    may be used to endorse or promote products derived from this software
     20       1.8       agc  *    without specific prior written permission.
     21       1.8       agc  *
     22       1.8       agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23       1.8       agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24       1.8       agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25       1.8       agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26       1.8       agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27       1.8       agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28       1.8       agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.8       agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30       1.8       agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31       1.8       agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.8       agc  * SUCH DAMAGE.
     33       1.8       agc  *
     34       1.8       agc  *	@(#)union.h	8.9 (Berkeley) 12/10/94
     35       1.8       agc  */
     36       1.8       agc 
     37       1.8       agc /*
     38       1.1  jdolecek  * Copyright (c) 1994 Jan-Simon Pendry.
     39       1.1  jdolecek  * All rights reserved.
     40       1.1  jdolecek  *
     41       1.1  jdolecek  * This code is derived from software donated to Berkeley by
     42       1.1  jdolecek  * Jan-Simon Pendry.
     43       1.1  jdolecek  *
     44       1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     45       1.1  jdolecek  * modification, are permitted provided that the following conditions
     46       1.1  jdolecek  * are met:
     47       1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     48       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     49       1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     50       1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     51       1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     52       1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     53       1.1  jdolecek  *    must display the following acknowledgement:
     54       1.1  jdolecek  *	This product includes software developed by the University of
     55       1.1  jdolecek  *	California, Berkeley and its contributors.
     56       1.1  jdolecek  * 4. Neither the name of the University nor the names of its contributors
     57       1.1  jdolecek  *    may be used to endorse or promote products derived from this software
     58       1.1  jdolecek  *    without specific prior written permission.
     59       1.1  jdolecek  *
     60       1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61       1.1  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62       1.1  jdolecek  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63       1.1  jdolecek  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64       1.1  jdolecek  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65       1.1  jdolecek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66       1.1  jdolecek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67       1.1  jdolecek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68       1.1  jdolecek  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69       1.1  jdolecek  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70       1.1  jdolecek  * SUCH DAMAGE.
     71       1.1  jdolecek  *
     72       1.1  jdolecek  *	@(#)union.h	8.9 (Berkeley) 12/10/94
     73       1.1  jdolecek  */
     74       1.1  jdolecek 
     75      1.12  christos #ifndef _MISCFS_UNION_H_
     76      1.12  christos #define _MISCFS_UNION_H_
     77      1.12  christos 
     78       1.1  jdolecek struct union_args {
     79       1.1  jdolecek 	char		*target;	/* Target of loopback  */
     80       1.1  jdolecek 	int		mntflags;	/* Options on the mount */
     81       1.1  jdolecek };
     82       1.1  jdolecek 
     83       1.1  jdolecek #define UNMNT_ABOVE	0x0001		/* Target appears below mount point */
     84       1.1  jdolecek #define UNMNT_BELOW	0x0002		/* Target appears below mount point */
     85       1.1  jdolecek #define UNMNT_REPLACE	0x0003		/* Target replaces mount point */
     86       1.1  jdolecek #define UNMNT_OPMASK	0x0003
     87       1.1  jdolecek 
     88       1.1  jdolecek #define UNMNT_BITS "\177\20" \
     89       1.9      yamt     "b\00above\0b\01below\0b\02replace\0"
     90       1.1  jdolecek 
     91      1.15      elad #ifdef _KERNEL
     92      1.15      elad 
     93       1.1  jdolecek struct union_mount {
     94       1.1  jdolecek 	struct vnode	*um_uppervp;
     95       1.1  jdolecek 	struct vnode	*um_lowervp;
     96      1.15      elad 	kauth_cred_t	um_cred;	/* Credentials of user calling mount */
     97       1.1  jdolecek 	int		um_cmode;	/* cmask from mount process */
     98       1.1  jdolecek 	int		um_op;		/* Operation mode */
     99       1.1  jdolecek };
    100       1.1  jdolecek 
    101       1.1  jdolecek /*
    102       1.1  jdolecek  * DEFDIRMODE is the mode bits used to create a shadow directory.
    103       1.1  jdolecek  */
    104       1.1  jdolecek #define	UN_DIRMODE	(S_IRWXU|S_IRWXG|S_IRWXO)
    105       1.1  jdolecek #define	UN_FILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
    106       1.1  jdolecek 
    107       1.1  jdolecek /*
    108      1.22   hannken  * A cache of vnode references.
    109      1.22   hannken  * Lock requirements are:
    110      1.22   hannken  *
    111      1.22   hannken  *	:	stable
    112      1.22   hannken  *	c	unheadlock[hash]
    113      1.22   hannken  *	l	un_lock
    114      1.22   hannken  *	m	un_lock or vnode lock to read, un_lock and
    115      1.22   hannken  *			exclusive vnode lock to write
    116      1.22   hannken  *	v	vnode lock to read, exclusive vnode lock to write
    117      1.22   hannken  *
    118      1.22   hannken  * Lock order is vnode then un_lock.
    119       1.1  jdolecek  */
    120       1.1  jdolecek struct union_node {
    121      1.22   hannken 	kmutex_t		un_lock;
    122      1.22   hannken 	LIST_ENTRY(union_node)	un_cache;	/* c: Hash chain */
    123      1.22   hannken 	struct vnode		*un_vnode;	/* :: Back pointer */
    124      1.22   hannken 	struct vnode	        *un_uppervp;	/* m: overlaying object */
    125      1.22   hannken 	struct vnode	        *un_lowervp;	/* v: underlying object */
    126      1.22   hannken 	struct vnode		*un_dirvp;	/* v: Parent dir of uppervp */
    127      1.22   hannken 	struct vnode		*un_pvp;	/* v: Parent vnode */
    128      1.22   hannken 	char			*un_path;	/* v: saved component name */
    129      1.22   hannken 	int			un_openl;	/* v: # of opens on lowervp */
    130      1.22   hannken 	unsigned int		un_cflags;	/* c: cache flags */
    131      1.22   hannken 	struct vnode		**un_dircache;	/* v: cached union stack */
    132      1.22   hannken 	off_t			un_uppersz;	/* l: size of upper object */
    133      1.22   hannken 	off_t			un_lowersz;	/* l: size of lower object */
    134       1.1  jdolecek };
    135       1.1  jdolecek 
    136       1.1  jdolecek #define UN_CACHED	0x10		/* In union cache */
    137       1.1  jdolecek 
    138      1.11   xtraeme extern int union_allocvp(struct vnode **, struct mount *,
    139       1.1  jdolecek 				struct vnode *, struct vnode *,
    140       1.1  jdolecek 				struct componentname *, struct vnode *,
    141      1.11   xtraeme 				struct vnode *, int);
    142      1.19   hannken extern int union_check_rmdir(struct union_node *, kauth_cred_t);
    143      1.15      elad extern int union_copyfile(struct vnode *, struct vnode *, kauth_cred_t,
    144      1.15      elad     struct lwp *);
    145      1.15      elad extern int union_copyup(struct union_node *, int, kauth_cred_t,
    146      1.15      elad     struct lwp *);
    147      1.11   xtraeme extern void union_diruncache(struct union_node *);
    148      1.16     pooka extern int union_dowhiteout(struct union_node *, kauth_cred_t);
    149      1.11   xtraeme extern int union_mkshadow(struct union_mount *, struct vnode *,
    150      1.15      elad     struct componentname *, struct vnode **);
    151      1.11   xtraeme extern int union_mkwhiteout(struct union_mount *, struct vnode *,
    152      1.21   hannken     struct componentname *, struct union_node *);
    153      1.11   xtraeme extern int union_vn_create(struct vnode **, struct union_node *,
    154      1.15      elad     struct lwp *);
    155      1.15      elad extern int union_cn_close(struct vnode *, int, kauth_cred_t,
    156      1.15      elad     struct lwp *);
    157      1.11   xtraeme extern void union_removed_upper(struct union_node *un);
    158      1.11   xtraeme extern struct vnode *union_lowervp(struct vnode *);
    159      1.11   xtraeme extern void union_newlower(struct union_node *, struct vnode *);
    160      1.11   xtraeme extern void union_newupper(struct union_node *, struct vnode *);
    161      1.11   xtraeme extern void union_newsize(struct vnode *, off_t, off_t);
    162      1.13  christos int union_readdirhook(struct vnode **, struct file *, struct lwp *);
    163       1.1  jdolecek 
    164       1.1  jdolecek #define	MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
    165       1.1  jdolecek #define	VTOUNION(vp) ((struct union_node *)(vp)->v_data)
    166       1.1  jdolecek #define	UNIONTOV(un) ((un)->un_vnode)
    167       1.1  jdolecek #define	LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
    168       1.1  jdolecek #define	UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
    169       1.1  jdolecek #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
    170      1.22   hannken #define LOCKVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : (vp))
    171       1.1  jdolecek 
    172      1.11   xtraeme extern int (**union_vnodeop_p)(void *);
    173       1.1  jdolecek 
    174      1.11   xtraeme void union_init(void);
    175      1.23   hannken void union_reinit(void);
    176      1.11   xtraeme void union_done(void);
    177      1.11   xtraeme int union_freevp(struct vnode *);
    178       1.1  jdolecek 
    179       1.1  jdolecek #endif /* _KERNEL */
    180      1.12  christos #endif /* _MISCFS_UNION_H_ */
    181