Home | History | Annotate | Line # | Download | only in union
union.h revision 1.13
      1  1.13  christos /*	$NetBSD: union.h,v 1.13 2005/12/11 12:24:29 christos 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.1  jdolecek struct union_mount {
     92   1.1  jdolecek 	struct vnode	*um_uppervp;
     93   1.1  jdolecek 	struct vnode	*um_lowervp;
     94   1.1  jdolecek 	struct ucred	*um_cred;	/* Credentials of user calling mount */
     95   1.1  jdolecek 	int		um_cmode;	/* cmask from mount process */
     96   1.1  jdolecek 	int		um_op;		/* Operation mode */
     97   1.1  jdolecek };
     98   1.1  jdolecek 
     99   1.1  jdolecek #ifdef _KERNEL
    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.1  jdolecek  * A cache of vnode references
    109   1.1  jdolecek  */
    110   1.1  jdolecek struct union_node {
    111   1.1  jdolecek 	LIST_ENTRY(union_node)	un_cache;	/* Hash chain */
    112   1.1  jdolecek 	struct vnode		*un_vnode;	/* Back pointer */
    113   1.1  jdolecek 	struct vnode	        *un_uppervp;	/* overlaying object */
    114   1.1  jdolecek 	struct vnode	        *un_lowervp;	/* underlying object */
    115   1.1  jdolecek 	struct vnode		*un_dirvp;	/* Parent dir of uppervp */
    116   1.1  jdolecek 	struct vnode		*un_pvp;	/* Parent vnode */
    117   1.1  jdolecek 	char			*un_path;	/* saved component name */
    118   1.1  jdolecek 	int			un_hash;	/* saved un_path hash value */
    119   1.1  jdolecek 	int			un_openl;	/* # of opens on lowervp */
    120   1.1  jdolecek 	unsigned int		un_flags;
    121   1.1  jdolecek 	struct vnode		**un_dircache;	/* cached union stack */
    122   1.1  jdolecek 	off_t			un_uppersz;	/* size of upper object */
    123   1.1  jdolecek 	off_t			un_lowersz;	/* size of lower object */
    124   1.1  jdolecek #ifdef DIAGNOSTIC
    125   1.1  jdolecek 	pid_t			un_pid;
    126   1.1  jdolecek #endif
    127   1.1  jdolecek };
    128   1.1  jdolecek 
    129   1.1  jdolecek #define UN_WANTED	0x01
    130   1.1  jdolecek #define UN_LOCKED	0x02
    131   1.1  jdolecek #define UN_ULOCK	0x04		/* Upper node is locked */
    132   1.1  jdolecek #define UN_KLOCK	0x08		/* Keep upper node locked on vput */
    133   1.1  jdolecek #define UN_CACHED	0x10		/* In union cache */
    134   1.1  jdolecek #define UN_DRAINING	0x20		/* upper node lock is draining */
    135   1.1  jdolecek #define UN_DRAINED	0x40		/* upper node lock is drained */
    136   1.1  jdolecek 
    137  1.11   xtraeme extern int union_allocvp(struct vnode **, struct mount *,
    138   1.1  jdolecek 				struct vnode *, struct vnode *,
    139   1.1  jdolecek 				struct componentname *, struct vnode *,
    140  1.11   xtraeme 				struct vnode *, int);
    141  1.11   xtraeme extern int union_copyfile(struct vnode *, struct vnode *,
    142  1.13  christos 					struct ucred *, struct lwp *);
    143  1.11   xtraeme extern int union_copyup(struct union_node *, int, struct ucred *,
    144  1.13  christos 				struct lwp *);
    145  1.11   xtraeme extern void union_diruncache(struct union_node *);
    146  1.11   xtraeme extern int union_dowhiteout(struct union_node *, struct ucred *,
    147  1.13  christos 					struct lwp *);
    148  1.11   xtraeme extern int union_mkshadow(struct union_mount *, struct vnode *,
    149  1.11   xtraeme 				struct componentname *, struct vnode **);
    150  1.11   xtraeme extern int union_mkwhiteout(struct union_mount *, struct vnode *,
    151  1.11   xtraeme 				struct componentname *, char *);
    152  1.11   xtraeme extern int union_vn_create(struct vnode **, struct union_node *,
    153  1.13  christos 				struct lwp *);
    154  1.11   xtraeme extern int union_cn_close(struct vnode *, int, struct ucred *,
    155  1.13  christos 				struct lwp *);
    156  1.11   xtraeme extern void union_removed_upper(struct union_node *un);
    157  1.11   xtraeme extern struct vnode *union_lowervp(struct vnode *);
    158  1.11   xtraeme extern void union_newlower(struct union_node *, struct vnode *);
    159  1.11   xtraeme extern void union_newupper(struct union_node *, struct vnode *);
    160  1.11   xtraeme extern void union_newsize(struct vnode *, off_t, off_t);
    161  1.13  christos int union_readdirhook(struct vnode **, struct file *, struct lwp *);
    162   1.1  jdolecek 
    163   1.1  jdolecek #define	MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
    164   1.1  jdolecek #define	VTOUNION(vp) ((struct union_node *)(vp)->v_data)
    165   1.1  jdolecek #define	UNIONTOV(un) ((un)->un_vnode)
    166   1.1  jdolecek #define	LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
    167   1.1  jdolecek #define	UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
    168   1.1  jdolecek #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
    169   1.1  jdolecek 
    170  1.11   xtraeme extern int (**union_vnodeop_p)(void *);
    171   1.1  jdolecek 
    172  1.11   xtraeme void union_init(void);
    173  1.11   xtraeme void union_done(void);
    174  1.11   xtraeme int union_freevp(struct vnode *);
    175   1.1  jdolecek 
    176  1.10    atatat #ifdef SYSCTL_SETUP_PROTO
    177  1.10    atatat SYSCTL_SETUP_PROTO(sysctl_vfs_union_setup);
    178  1.10    atatat #endif /* SYSCTL_SETUP_PROTO */
    179   1.1  jdolecek #endif /* _KERNEL */
    180  1.12  christos #endif /* _MISCFS_UNION_H_ */
    181