union.h revision 1.8 1 1.8 agc /* $NetBSD: union.h,v 1.8 2003/08/07 16:31:40 agc 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.1 jdolecek struct union_args {
76 1.1 jdolecek char *target; /* Target of loopback */
77 1.1 jdolecek int mntflags; /* Options on the mount */
78 1.1 jdolecek };
79 1.1 jdolecek
80 1.1 jdolecek #define UNMNT_ABOVE 0x0001 /* Target appears below mount point */
81 1.1 jdolecek #define UNMNT_BELOW 0x0002 /* Target appears below mount point */
82 1.1 jdolecek #define UNMNT_REPLACE 0x0003 /* Target replaces mount point */
83 1.1 jdolecek #define UNMNT_OPMASK 0x0003
84 1.1 jdolecek
85 1.1 jdolecek #define UNMNT_BITS "\177\20" \
86 1.1 jdolecek "b\00above\0b\01below\0b\02replace"
87 1.1 jdolecek
88 1.1 jdolecek struct union_mount {
89 1.1 jdolecek struct vnode *um_uppervp;
90 1.1 jdolecek struct vnode *um_lowervp;
91 1.1 jdolecek struct ucred *um_cred; /* Credentials of user calling mount */
92 1.1 jdolecek int um_cmode; /* cmask from mount process */
93 1.1 jdolecek int um_op; /* Operation mode */
94 1.1 jdolecek };
95 1.1 jdolecek
96 1.1 jdolecek #ifdef _KERNEL
97 1.1 jdolecek
98 1.1 jdolecek /*
99 1.1 jdolecek * DEFDIRMODE is the mode bits used to create a shadow directory.
100 1.1 jdolecek */
101 1.1 jdolecek #define UN_DIRMODE (S_IRWXU|S_IRWXG|S_IRWXO)
102 1.1 jdolecek #define UN_FILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
103 1.1 jdolecek
104 1.1 jdolecek /*
105 1.1 jdolecek * A cache of vnode references
106 1.1 jdolecek */
107 1.1 jdolecek struct union_node {
108 1.1 jdolecek LIST_ENTRY(union_node) un_cache; /* Hash chain */
109 1.1 jdolecek struct vnode *un_vnode; /* Back pointer */
110 1.1 jdolecek struct vnode *un_uppervp; /* overlaying object */
111 1.1 jdolecek struct vnode *un_lowervp; /* underlying object */
112 1.1 jdolecek struct vnode *un_dirvp; /* Parent dir of uppervp */
113 1.1 jdolecek struct vnode *un_pvp; /* Parent vnode */
114 1.1 jdolecek char *un_path; /* saved component name */
115 1.1 jdolecek int un_hash; /* saved un_path hash value */
116 1.1 jdolecek int un_openl; /* # of opens on lowervp */
117 1.1 jdolecek unsigned int un_flags;
118 1.1 jdolecek struct vnode **un_dircache; /* cached union stack */
119 1.1 jdolecek off_t un_uppersz; /* size of upper object */
120 1.1 jdolecek off_t un_lowersz; /* size of lower object */
121 1.1 jdolecek #ifdef DIAGNOSTIC
122 1.1 jdolecek pid_t un_pid;
123 1.1 jdolecek #endif
124 1.1 jdolecek };
125 1.1 jdolecek
126 1.1 jdolecek #define UN_WANTED 0x01
127 1.1 jdolecek #define UN_LOCKED 0x02
128 1.1 jdolecek #define UN_ULOCK 0x04 /* Upper node is locked */
129 1.1 jdolecek #define UN_KLOCK 0x08 /* Keep upper node locked on vput */
130 1.1 jdolecek #define UN_CACHED 0x10 /* In union cache */
131 1.1 jdolecek #define UN_DRAINING 0x20 /* upper node lock is draining */
132 1.1 jdolecek #define UN_DRAINED 0x40 /* upper node lock is drained */
133 1.1 jdolecek
134 1.1 jdolecek extern int union_allocvp __P((struct vnode **, struct mount *,
135 1.1 jdolecek struct vnode *, struct vnode *,
136 1.1 jdolecek struct componentname *, struct vnode *,
137 1.6 thorpej struct vnode *, int));
138 1.1 jdolecek extern int union_copyfile __P((struct vnode *, struct vnode *,
139 1.7 fvdl struct ucred *, struct proc *));
140 1.1 jdolecek extern int union_copyup __P((struct union_node *, int, struct ucred *,
141 1.7 fvdl struct proc *));
142 1.1 jdolecek extern void union_diruncache __P((struct union_node *));
143 1.1 jdolecek extern int union_dowhiteout __P((struct union_node *, struct ucred *,
144 1.7 fvdl struct proc *));
145 1.1 jdolecek extern int union_mkshadow __P((struct union_mount *, struct vnode *,
146 1.1 jdolecek struct componentname *, struct vnode **));
147 1.1 jdolecek extern int union_mkwhiteout __P((struct union_mount *, struct vnode *,
148 1.1 jdolecek struct componentname *, char *));
149 1.1 jdolecek extern int union_vn_create __P((struct vnode **, struct union_node *,
150 1.7 fvdl struct proc *));
151 1.1 jdolecek extern int union_cn_close __P((struct vnode *, int, struct ucred *,
152 1.7 fvdl struct proc *));
153 1.1 jdolecek extern void union_removed_upper __P((struct union_node *un));
154 1.1 jdolecek extern struct vnode *union_lowervp __P((struct vnode *));
155 1.1 jdolecek extern void union_newlower __P((struct union_node *, struct vnode *));
156 1.1 jdolecek extern void union_newupper __P((struct union_node *, struct vnode *));
157 1.1 jdolecek extern void union_newsize __P((struct vnode *, off_t, off_t));
158 1.7 fvdl int union_readdirhook(struct vnode **, struct file *, struct proc *);
159 1.1 jdolecek
160 1.1 jdolecek #define MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
161 1.1 jdolecek #define VTOUNION(vp) ((struct union_node *)(vp)->v_data)
162 1.1 jdolecek #define UNIONTOV(un) ((un)->un_vnode)
163 1.1 jdolecek #define LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
164 1.1 jdolecek #define UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
165 1.1 jdolecek #define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
166 1.1 jdolecek
167 1.1 jdolecek extern int (**union_vnodeop_p) __P((void *));
168 1.1 jdolecek
169 1.1 jdolecek void union_init __P((void));
170 1.1 jdolecek void union_done __P((void));
171 1.1 jdolecek int union_freevp __P((struct vnode *));
172 1.1 jdolecek
173 1.1 jdolecek #endif /* _KERNEL */
174