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