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