1/* $NetBSD: union.h,v 1.28 2015/02/16 10:22:00 hannken 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
78struct 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#ifdef _KERNEL
92
93struct union_mount {
94 struct vnode *um_uppervp;
95 struct vnode *um_lowervp;
96 kauth_cred_t um_cred; /* Credentials of user calling mount */
97 int um_cmode; /* cmask from mount process */
98 int um_op; /* Operation mode */
99};
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 * Lock requirements are:
110 *
111 * : stable
112 * c unheadlock[hash]
113 * l un_lock
114 * m un_lock or vnode lock to read, un_lock and
115 * exclusive vnode lock to write
116 * v vnode lock to read, exclusive vnode lock to write
117 *
118 * Lock order is vnode then un_lock.
119 */
120struct union_node {
121 kmutex_t un_lock;
122 LIST_ENTRY(union_node) un_cache; /* c: Hash chain */
123 int un_refs; /* c: Reference counter */
124 struct mount *un_mount; /* c: union mount */
125 struct vnode *un_vnode; /* :: Back pointer */
126 struct vnode *un_uppervp; /* m: overlaying object */
127 struct vnode *un_lowervp; /* v: underlying object */
128 struct vnode *un_dirvp; /* v: Parent dir of uppervp */
129 struct vnode *un_pvp; /* v: Parent vnode */
130 char *un_path; /* v: saved component name */
131 int un_openl; /* v: # of opens on lowervp */
132 unsigned int un_cflags; /* c: cache flags */
133 struct vnode **un_dircache; /* v: cached union stack */
134 off_t un_uppersz; /* l: size of upper object */
135 off_t un_lowersz; /* l: size of lower object */
136};
137
138#define UN_CACHED 0x10 /* In union cache */
139
140extern int union_allocvp(struct vnode **, struct mount *,
141 struct vnode *, struct vnode *,
142 struct componentname *, struct vnode *,
143 struct vnode *, int);
144extern int union_check_rmdir(struct union_node *, kauth_cred_t);
145extern int union_copyfile(struct vnode *, struct vnode *, kauth_cred_t,
146 struct lwp *);
147extern int union_copyup(struct union_node *, int, kauth_cred_t,
148 struct lwp *);
149extern void union_diruncache(struct union_node *);
150extern int union_dowhiteout(struct union_node *, kauth_cred_t);
151extern int union_mkshadow(struct union_mount *, struct vnode *,
152 struct componentname *, struct vnode **);
153extern int union_mkwhiteout(struct union_mount *, struct vnode *,
154 struct componentname *, struct union_node *);
155extern int union_vn_create(struct vnode **, struct union_node *,
156 struct lwp *);
157extern int union_cn_close(struct vnode *, int, kauth_cred_t,
158 struct lwp *);
159extern void union_removed_upper(struct union_node *un);
160extern struct vnode *union_lowervp(struct vnode *);
161extern void union_newlower(struct union_node *, struct vnode *);
162extern void union_newupper(struct union_node *, struct vnode *);
163extern void union_newsize(struct vnode *, off_t, off_t);
164int union_readdirhook(struct vnode **, struct file *, struct lwp *);
165
166VFS_PROTOS(union);
167
168#define MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data))
169#define VTOUNION(vp) ((struct union_node *)(vp)->v_data)
170#define UNIONTOV(un) ((un)->un_vnode)
171#define LOWERVP(vp) (VTOUNION(vp)->un_lowervp)
172#define UPPERVP(vp) (VTOUNION(vp)->un_uppervp)
173#define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp))
174#define LOCKVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : (vp))
175
176extern int (**union_vnodeop_p)(void *);
177
178void union_init(void);
179void union_reinit(void);
180void union_done(void);
181int union_freevp(struct vnode *);
182
183#endif /* _KERNEL */
184#endif /* _MISCFS_UNION_H_ */
185