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