Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/mntfs/mntvfsops.c
+++ new/usr/src/uts/common/fs/mntfs/mntvfsops.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 */
24 24
25 25 #include <sys/types.h>
26 26 #include <sys/param.h>
27 27 #include <sys/cmn_err.h>
28 28 #include <sys/cred.h>
29 29 #include <sys/debug.h>
30 30 #include <sys/errno.h>
31 31 #include <sys/proc.h>
32 32 #include <sys/procfs.h>
33 33 #include <sys/stat.h>
34 34 #include <sys/statvfs.h>
35 35 #include <sys/sysmacros.h>
36 36 #include <sys/systm.h>
37 37 #include <sys/var.h>
38 38 #include <sys/vfs.h>
39 39 #include <sys/vfs_opreg.h>
40 40 #include <sys/vnode.h>
41 41 #include <sys/mode.h>
42 42 #include <sys/signal.h>
43 43 #include <sys/user.h>
44 44 #include <sys/mount.h>
45 45 #include <sys/bitmap.h>
46 46 #include <sys/kmem.h>
47 47 #include <sys/policy.h>
48 48 #include <fs/fs_subr.h>
49 49 #include <sys/fs/mntdata.h>
50 50 #include <sys/zone.h>
51 51
52 52 /*
53 53 * This is the loadable module wrapper.
54 54 */
55 55 #include <sys/modctl.h>
56 56
57 57 static int mntinit(int, char *);
58 58
59 59 static mntopts_t mnt_mntopts = {
60 60 0,
61 61 NULL
62 62 };
63 63
64 64 static vfsdef_t vfw = {
65 65 VFSDEF_VERSION,
66 66 "mntfs",
67 67 mntinit,
68 68 VSW_HASPROTO|VSW_STATS|VSW_ZMOUNT,
69 69 &mnt_mntopts
70 70 };
71 71
↓ open down ↓ |
71 lines elided |
↑ open up ↑ |
72 72 /*
73 73 * Module linkage information for the kernel.
74 74 */
75 75 extern struct mod_ops mod_fsops;
76 76
77 77 static struct modlfs modlfs = {
78 78 &mod_fsops, "mount information file system", &vfw
79 79 };
80 80
81 81 static struct modlinkage modlinkage = {
82 - MODREV_1, (void *)&modlfs, NULL
82 + MODREV_1, { (void *)&modlfs, NULL }
83 83 };
84 84
85 85 int
86 86 _init(void)
87 87 {
88 88 return (mod_install(&modlinkage));
89 89 }
90 90
91 91 int
92 92 _info(struct modinfo *modinfop)
93 93 {
94 94 return (mod_info(&modlinkage, modinfop));
95 95 }
96 96
97 97 /*
98 98 * N.B.
99 99 * No _fini routine. The module cannot be unloaded once loaded.
100 100 * The NO_UNLOAD_STUB in modstubs.s must change if this module
101 101 * is ever modified to become unloadable.
102 102 */
103 103
104 104 extern int mntfstype;
105 105 static major_t mnt_major;
106 106 static minor_t mnt_minor;
107 107 static kmutex_t mnt_minor_lock;
108 108
109 109 /*
110 110 * /mnttab VFS operations vector.
111 111 */
112 112 static int mntmount(), mntunmount(), mntroot(), mntstatvfs();
113 113
114 114 static void
115 115 mntinitrootnode(mntnode_t *mnp)
116 116 {
117 117 struct vnode *vp;
118 118
119 119 bzero((caddr_t)mnp, sizeof (*mnp));
120 120
121 121 mnp->mnt_vnode = vn_alloc(KM_SLEEP);
122 122
123 123 vp = MTOV(mnp);
124 124
↓ open down ↓ |
32 lines elided |
↑ open up ↑ |
125 125 vp->v_flag = VROOT|VNOCACHE|VNOMAP|VNOSWAP|VNOMOUNT;
126 126 vn_setops(vp, mntvnodeops);
127 127 vp->v_type = VREG;
128 128 vp->v_data = (caddr_t)mnp;
129 129 }
130 130
131 131 static int
132 132 mntinit(int fstype, char *name)
133 133 {
134 134 static const fs_operation_def_t mnt_vfsops_template[] = {
135 - VFSNAME_MOUNT, { .vfs_mount = mntmount },
136 - VFSNAME_UNMOUNT, { .vfs_unmount = mntunmount },
137 - VFSNAME_ROOT, { .vfs_root = mntroot },
138 - VFSNAME_STATVFS, { .vfs_statvfs = mntstatvfs },
139 - NULL, NULL
135 + { VFSNAME_MOUNT, { .vfs_mount = mntmount } },
136 + { VFSNAME_UNMOUNT, { .vfs_unmount = mntunmount } },
137 + { VFSNAME_ROOT, { .vfs_root = mntroot } },
138 + { VFSNAME_STATVFS, { .vfs_statvfs = mntstatvfs } },
139 + { NULL, { NULL } }
140 140 };
141 141 extern const fs_operation_def_t mnt_vnodeops_template[];
142 142 int error;
143 143
144 144 mntfstype = fstype;
145 145 ASSERT(mntfstype != 0);
146 146 /*
147 147 * Associate VFS ops vector with this fstype.
148 148 */
149 149 error = vfs_setfsops(fstype, mnt_vfsops_template, NULL);
150 150 if (error != 0) {
151 151 cmn_err(CE_WARN, "mntinit: bad vfs ops template");
152 152 return (error);
153 153 }
154 154
155 155 /* Vnode ops too. */
156 156
157 157 error = vn_make_ops(name, mnt_vnodeops_template, &mntvnodeops);
158 158 if (error != 0) {
159 159 (void) vfs_freevfsops_by_type(fstype);
160 160 cmn_err(CE_WARN, "mntinit: bad vnode ops template");
161 161 return (error);
162 162 }
163 163
164 164 /*
165 165 * Assign a unique "device" number (used by stat(2)).
166 166 */
167 167 if ((mnt_major = getudev()) == (major_t)-1) {
168 168 cmn_err(CE_WARN, "mntinit: can't get unique device number");
169 169 mnt_major = 0;
170 170 }
171 171 mutex_init(&mnt_minor_lock, NULL, MUTEX_DEFAULT, NULL);
172 172
173 173 return (0);
174 174 }
175 175
176 176 /* ARGSUSED */
177 177 static int
178 178 mntmount(struct vfs *vfsp, struct vnode *mvp,
179 179 struct mounta *uap, struct cred *cr)
180 180 {
181 181 mntdata_t *mnt;
182 182 mntnode_t *mnp;
183 183 zone_t *zone = curproc->p_zone;
184 184
185 185 if (secpolicy_fs_mount(cr, mvp, vfsp) != 0)
186 186 return (EPERM);
187 187
188 188 /*
189 189 * You can only mount mnttab in your current zone.
190 190 */
191 191 if (zone == global_zone) {
192 192 zone_t *mntzone;
193 193
194 194 mntzone = zone_find_by_path(refstr_value(vfsp->vfs_mntpt));
195 195 ASSERT(mntzone != NULL);
196 196 zone_rele(mntzone);
197 197 if (mntzone != zone)
198 198 return (EBUSY);
199 199 }
200 200
201 201 /*
202 202 * Having the resource be anything but "mnttab" doesn't make sense
203 203 */
204 204 vfs_setresource(vfsp, "mnttab", 0);
205 205
206 206 mnt = kmem_zalloc(sizeof (*mnt), KM_SLEEP);
207 207 mutex_enter(&mvp->v_lock);
208 208 if ((uap->flags & MS_OVERLAY) == 0 &&
209 209 (mvp->v_count > 1 || (mvp->v_flag & VROOT))) {
210 210 mutex_exit(&mvp->v_lock);
211 211 kmem_free(mnt, sizeof (*mnt));
212 212 return (EBUSY);
213 213 }
214 214 mutex_exit(&mvp->v_lock);
215 215
216 216 zone_init_ref(&mnt->mnt_zone_ref);
217 217 zone_hold_ref(zone, &mnt->mnt_zone_ref, ZONE_REF_MNTFS);
218 218 mnp = &mnt->mnt_node;
219 219
220 220 vfsp->vfs_fstype = mntfstype;
221 221 vfsp->vfs_data = (caddr_t)mnt;
222 222 /*
223 223 * find an available minor device number for this mount.
224 224 */
225 225 mutex_enter(&mnt_minor_lock);
226 226 do {
227 227 mnt_minor = (mnt_minor + 1) & L_MAXMIN32;
228 228 vfsp->vfs_dev = makedevice(mnt_major, mnt_minor);
229 229 } while (vfs_devismounted(vfsp->vfs_dev));
230 230 mutex_exit(&mnt_minor_lock);
231 231 vfs_make_fsid(&vfsp->vfs_fsid, vfsp->vfs_dev, mntfstype);
232 232 vfsp->vfs_bsize = DEV_BSIZE;
233 233 mntinitrootnode(mnp);
234 234 MTOV(mnp)->v_vfsp = vfsp;
235 235 mnp->mnt_mountvp = mvp;
236 236 vn_exists(MTOV(mnp));
237 237 return (0);
238 238 }
239 239
240 240 /* ARGSUSED */
241 241 static int
242 242 mntunmount(struct vfs *vfsp, int flag, struct cred *cr)
243 243 {
244 244 mntdata_t *mnt = (mntdata_t *)vfsp->vfs_data;
245 245 vnode_t *vp = MTOV(&mnt->mnt_node);
246 246
247 247 if (secpolicy_fs_unmount(cr, vfsp) != 0)
248 248 return (EPERM);
249 249
250 250 /*
251 251 * Ensure that no /mnttab vnodes are in use on this mount point.
252 252 */
253 253 mutex_enter(&vp->v_lock);
254 254 if (vp->v_count > 1 || mnt->mnt_nopen > 0) {
255 255 mutex_exit(&vp->v_lock);
256 256 return (EBUSY);
257 257 }
258 258
259 259 mutex_exit(&vp->v_lock);
260 260 zone_rele_ref(&mnt->mnt_zone_ref, ZONE_REF_MNTFS);
261 261 vn_invalid(vp);
262 262 vn_free(vp);
263 263 kmem_free(mnt, sizeof (*mnt));
264 264 return (0);
265 265 }
266 266
267 267 /* ARGSUSED */
268 268 static int
269 269 mntroot(struct vfs *vfsp, struct vnode **vpp)
270 270 {
271 271 mntnode_t *mnp = &((mntdata_t *)vfsp->vfs_data)->mnt_node;
272 272 struct vnode *vp = MTOV(mnp);
273 273
274 274 VN_HOLD(vp);
275 275 *vpp = vp;
276 276 return (0);
277 277 }
278 278
279 279 static int
280 280 mntstatvfs(struct vfs *vfsp, struct statvfs64 *sp)
281 281 {
282 282 dev32_t d32;
283 283
284 284 bzero((caddr_t)sp, sizeof (*sp));
285 285 sp->f_bsize = DEV_BSIZE;
286 286 sp->f_frsize = DEV_BSIZE;
287 287 sp->f_blocks = (fsblkcnt64_t)0;
288 288 sp->f_bfree = (fsblkcnt64_t)0;
289 289 sp->f_bavail = (fsblkcnt64_t)0;
290 290 sp->f_files = (fsfilcnt64_t)1;
291 291 sp->f_ffree = (fsfilcnt64_t)0;
292 292 sp->f_favail = (fsfilcnt64_t)0;
293 293 (void) cmpldev(&d32, vfsp->vfs_dev);
294 294 sp->f_fsid = d32;
295 295 (void) strcpy(sp->f_basetype, vfssw[mntfstype].vsw_name);
296 296 sp->f_flag = vf_to_stf(vfsp->vfs_flag);
297 297 sp->f_namemax = 64; /* quite arbitrary */
298 298 bzero(sp->f_fstr, sizeof (sp->f_fstr));
299 299 (void) strcpy(sp->f_fstr, "/mnttab");
300 300 (void) strcpy(&sp->f_fstr[8], "/mnttab");
301 301 return (0);
302 302 }
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX