1 | /* $Id: vboxfs_vfs.c 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox File System for Solaris Guests, VFS implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #include <VBox/log.h>
|
---|
38 | #include <VBox/version.h>
|
---|
39 | #include <iprt/dbg.h>
|
---|
40 |
|
---|
41 | #include <sys/types.h>
|
---|
42 | #include <sys/mntent.h>
|
---|
43 | #include <sys/param.h>
|
---|
44 | #include <sys/modctl.h>
|
---|
45 | #include <sys/mount.h>
|
---|
46 | #include <sys/policy.h>
|
---|
47 | #include <sys/atomic.h>
|
---|
48 | #include <sys/sysmacros.h>
|
---|
49 | #include <sys/ddi.h>
|
---|
50 | #include <sys/sunddi.h>
|
---|
51 | #include <sys/vfs.h>
|
---|
52 | #if !defined(VBOX_VFS_SOLARIS_10U6)
|
---|
53 | # include <sys/vfs_opreg.h>
|
---|
54 | #endif
|
---|
55 | #include <sys/pathname.h>
|
---|
56 | #include <sys/cmn_err.h>
|
---|
57 | #include <sys/vmsystm.h>
|
---|
58 | #undef u /* /usr/include/sys/user.h:249:1 is where this is defined to (curproc->p_user). very cool. */
|
---|
59 |
|
---|
60 | #include "vboxfs_prov.h"
|
---|
61 | #include "vboxfs_vnode.h"
|
---|
62 | #include "vboxfs_vfs.h"
|
---|
63 | #include "vboxfs.h"
|
---|
64 |
|
---|
65 |
|
---|
66 | #define VBOXSOLQUOTE2(x) #x
|
---|
67 | #define VBOXSOLQUOTE(x) VBOXSOLQUOTE2(x)
|
---|
68 | /** The module name. */
|
---|
69 | #define DEVICE_NAME "vboxfs"
|
---|
70 | /** The module description as seen in 'modinfo'. */
|
---|
71 | #define DEVICE_DESC "VirtualBox ShrdFS"
|
---|
72 |
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * Shared Folders filesystem implementation of the Solaris VFS interfaces.
|
---|
76 | * Much of this is cookie cutter code for Solaris filesystem implementation.
|
---|
77 | */
|
---|
78 |
|
---|
79 | /* forward declarations */
|
---|
80 | static int sffs_init(int fstype, char *name);
|
---|
81 | static int sffs_mount(vfs_t *, vnode_t *, struct mounta *, cred_t *);
|
---|
82 | static int sffs_unmount(vfs_t *vfsp, int flag, cred_t *cr);
|
---|
83 | static int sffs_root(vfs_t *vfsp, vnode_t **vpp);
|
---|
84 | static int sffs_statvfs(vfs_t *vfsp, statvfs64_t *sbp);
|
---|
85 |
|
---|
86 | static mntopt_t sffs_options[] = {
|
---|
87 | /* Option Cancels Opt Arg Flags Data */
|
---|
88 | {"uid", NULL, NULL, MO_HASVALUE, NULL},
|
---|
89 | {"gid", NULL, NULL, MO_HASVALUE, NULL},
|
---|
90 | {"dmode", NULL, NULL, MO_HASVALUE, NULL},
|
---|
91 | {"fmode", NULL, NULL, MO_HASVALUE, NULL},
|
---|
92 | {"dmask", NULL, NULL, MO_HASVALUE, NULL},
|
---|
93 | {"fmask", NULL, NULL, MO_HASVALUE, NULL},
|
---|
94 | {"stat_ttl", NULL, NULL, MO_HASVALUE, NULL},
|
---|
95 | {"fsync", NULL, NULL, 0, NULL},
|
---|
96 | {"tag", NULL, NULL, MO_HASVALUE, NULL}
|
---|
97 | };
|
---|
98 |
|
---|
99 | static mntopts_t sffs_options_table = {
|
---|
100 | sizeof (sffs_options) / sizeof (mntopt_t),
|
---|
101 | sffs_options
|
---|
102 | };
|
---|
103 |
|
---|
104 | static vfsdef_t sffs_vfsdef = {
|
---|
105 | VFSDEF_VERSION,
|
---|
106 | DEVICE_NAME,
|
---|
107 | sffs_init,
|
---|
108 | VSW_HASPROTO,
|
---|
109 | &sffs_options_table
|
---|
110 | };
|
---|
111 |
|
---|
112 | static int sffs_fstype;
|
---|
113 | static int sffs_major; /* major number for device */
|
---|
114 |
|
---|
115 | kmutex_t sffs_minor_lock;
|
---|
116 | int sffs_minor; /* minor number for device */
|
---|
117 |
|
---|
118 | /** Whether to use the old-style map_addr()/choose_addr() routines. */
|
---|
119 | bool g_fVBoxVFS_SolOldAddrMap;
|
---|
120 | /** The map_addr()/choose_addr() hooks callout table structure. */
|
---|
121 | VBoxVFS_SolAddrMap g_VBoxVFS_SolAddrMap;
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * Module linkage information
|
---|
125 | */
|
---|
126 | static struct modlfs modlfs = {
|
---|
127 | &mod_fsops,
|
---|
128 | DEVICE_DESC " " VBOX_VERSION_STRING "r" VBOXSOLQUOTE(VBOX_SVN_REV),
|
---|
129 | &sffs_vfsdef
|
---|
130 | };
|
---|
131 |
|
---|
132 | static struct modlinkage modlinkage = {
|
---|
133 | MODREV_1, &modlfs, NULL
|
---|
134 | };
|
---|
135 |
|
---|
136 | static sfp_connection_t *sfprov = NULL;
|
---|
137 |
|
---|
138 | int
|
---|
139 | _init()
|
---|
140 | {
|
---|
141 | RTDBGKRNLINFO hKrnlDbgInfo;
|
---|
142 | int rc = RTR0DbgKrnlInfoOpen(&hKrnlDbgInfo, 0 /* fFlags */);
|
---|
143 | if (RT_SUCCESS(rc))
|
---|
144 | {
|
---|
145 | rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlDbgInfo, NULL /* pszModule */, "plat_map_align_amount", NULL /* ppvSymbol */);
|
---|
146 | if (RT_SUCCESS(rc))
|
---|
147 | {
|
---|
148 | #if defined(VBOX_VFS_SOLARIS_10U6)
|
---|
149 | g_VBoxVFS_SolAddrMap.MapAddr.pfnSol_map_addr = (void *)map_addr;
|
---|
150 | #else
|
---|
151 | g_VBoxVFS_SolAddrMap.ChooseAddr.pfnSol_choose_addr = (void *)choose_addr;
|
---|
152 | #endif
|
---|
153 | }
|
---|
154 | else
|
---|
155 | {
|
---|
156 | g_fVBoxVFS_SolOldAddrMap = true;
|
---|
157 | #if defined(VBOX_VFS_SOLARIS_10U6)
|
---|
158 | g_VBoxVFS_SolAddrMap.MapAddr.pfnSol_map_addr_old = (void *)map_addr;
|
---|
159 | #else
|
---|
160 | g_VBoxVFS_SolAddrMap.ChooseAddr.pfnSol_choose_addr_old = (void *)choose_addr;
|
---|
161 | #endif
|
---|
162 | }
|
---|
163 |
|
---|
164 | RTR0DbgKrnlInfoRelease(hKrnlDbgInfo);
|
---|
165 | }
|
---|
166 | else
|
---|
167 | {
|
---|
168 | cmn_err(CE_NOTE, "RTR0DbgKrnlInfoOpen failed. rc=%d\n", rc);
|
---|
169 | return rc;
|
---|
170 | }
|
---|
171 |
|
---|
172 | return (mod_install(&modlinkage));
|
---|
173 | }
|
---|
174 |
|
---|
175 | int
|
---|
176 | _info(struct modinfo *modinfop)
|
---|
177 | {
|
---|
178 | return (mod_info(&modlinkage, modinfop));
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | int
|
---|
183 | _fini()
|
---|
184 | {
|
---|
185 | int error;
|
---|
186 |
|
---|
187 | error = mod_remove(&modlinkage);
|
---|
188 | if (error)
|
---|
189 | return (error);
|
---|
190 |
|
---|
191 | /*
|
---|
192 | * Tear down the operations vectors
|
---|
193 | */
|
---|
194 | sffs_vnode_fini();
|
---|
195 | (void) vfs_freevfsops_by_type(sffs_fstype);
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * close connection to the provider
|
---|
199 | */
|
---|
200 | sfprov_disconnect(sfprov);
|
---|
201 | return (0);
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | static int
|
---|
206 | sffs_init(int fstype, char *name)
|
---|
207 | {
|
---|
208 | #if defined(VBOX_VFS_SOLARIS_10U6)
|
---|
209 | static const fs_operation_def_t sffs_vfsops_template[] = {
|
---|
210 | VFSNAME_MOUNT, sffs_mount,
|
---|
211 | VFSNAME_UNMOUNT, sffs_unmount,
|
---|
212 | VFSNAME_ROOT, sffs_root,
|
---|
213 | VFSNAME_STATVFS, sffs_statvfs,
|
---|
214 | NULL, NULL
|
---|
215 | };
|
---|
216 | #else
|
---|
217 | static const fs_operation_def_t sffs_vfsops_template[] = {
|
---|
218 | VFSNAME_MOUNT, { .vfs_mount = sffs_mount },
|
---|
219 | VFSNAME_UNMOUNT, { .vfs_unmount = sffs_unmount },
|
---|
220 | VFSNAME_ROOT, { .vfs_root = sffs_root },
|
---|
221 | VFSNAME_STATVFS, { .vfs_statvfs = sffs_statvfs },
|
---|
222 | NULL, NULL
|
---|
223 | };
|
---|
224 | #endif
|
---|
225 | int error;
|
---|
226 |
|
---|
227 | ASSERT(fstype != 0);
|
---|
228 | sffs_fstype = fstype;
|
---|
229 | LogFlowFunc(("sffs_init() name=%s\n", name));
|
---|
230 |
|
---|
231 | /*
|
---|
232 | * This may seem a silly way to do things for now. But the code
|
---|
233 | * is structured to easily allow it to be used on other hypervisors
|
---|
234 | * which would have a different implementation of the provider.
|
---|
235 | * Hopefully that'll never happen. :)
|
---|
236 | */
|
---|
237 | sfprov = sfprov_connect(SFPROV_VERSION);
|
---|
238 | if (sfprov == NULL) {
|
---|
239 | cmn_err(CE_WARN, "sffs_init: couldn't init sffs provider");
|
---|
240 | return (ENODEV);
|
---|
241 | }
|
---|
242 |
|
---|
243 | error = sfprov_set_show_symlinks();
|
---|
244 | if (error != 0) {
|
---|
245 | cmn_err(CE_WARN, "sffs_init: host unable to show symlinks, "
|
---|
246 | "rc=%d\n", error);
|
---|
247 | }
|
---|
248 |
|
---|
249 | error = vfs_setfsops(fstype, sffs_vfsops_template, NULL);
|
---|
250 | if (error != 0) {
|
---|
251 | cmn_err(CE_WARN, "sffs_init: bad vfs ops template");
|
---|
252 | return (error);
|
---|
253 | }
|
---|
254 |
|
---|
255 | error = sffs_vnode_init();
|
---|
256 | if (error != 0) {
|
---|
257 | (void) vfs_freevfsops_by_type(fstype);
|
---|
258 | cmn_err(CE_WARN, "sffs_init: bad vnode ops template");
|
---|
259 | return (error);
|
---|
260 | }
|
---|
261 |
|
---|
262 | if ((sffs_major = getudev()) == (major_t)-1) {
|
---|
263 | cmn_err(CE_WARN, "sffs_init: Can't get unique device number.");
|
---|
264 | sffs_major = 0;
|
---|
265 | }
|
---|
266 | mutex_init(&sffs_minor_lock, NULL, MUTEX_DEFAULT, NULL);
|
---|
267 | return (0);
|
---|
268 | }
|
---|
269 |
|
---|
270 | /*
|
---|
271 | * wrapper for pn_get
|
---|
272 | */
|
---|
273 | static int
|
---|
274 | sf_pn_get(char *rawpath, struct mounta *uap, char **outpath)
|
---|
275 | {
|
---|
276 | pathname_t path;
|
---|
277 | int error;
|
---|
278 |
|
---|
279 | error = pn_get(rawpath, (uap->flags & MS_SYSSPACE) ? UIO_SYSSPACE :
|
---|
280 | UIO_USERSPACE, &path);
|
---|
281 | if (error) {
|
---|
282 | LogFlowFunc(("pn_get(%s) failed\n", rawpath));
|
---|
283 | return (error);
|
---|
284 | }
|
---|
285 | *outpath = kmem_alloc(path.pn_pathlen + 1, KM_SLEEP);
|
---|
286 | strcpy(*outpath, path.pn_path);
|
---|
287 | pn_free(&path);
|
---|
288 | return (0);
|
---|
289 | }
|
---|
290 |
|
---|
291 | #ifdef DEBUG_ramshankar
|
---|
292 | static void
|
---|
293 | sffs_print(sffs_data_t *sffs)
|
---|
294 | {
|
---|
295 | cmn_err(CE_NOTE, "sffs_data_t at 0x%p\n", sffs);
|
---|
296 | cmn_err(CE_NOTE, " vfs_t *sf_vfsp = 0x%p\n", sffs->sf_vfsp);
|
---|
297 | cmn_err(CE_NOTE, " vnode_t *sf_rootnode = 0x%p\n", sffs->sf_rootnode);
|
---|
298 | cmn_err(CE_NOTE, " uid_t sf_uid = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_uid);
|
---|
299 | cmn_err(CE_NOTE, " gid_t sf_gid = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_gid);
|
---|
300 | cmn_err(CE_NOTE, " mode_t sf_dmode = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_dmode);
|
---|
301 | cmn_err(CE_NOTE, " mode_t sf_fmode = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_fmode);
|
---|
302 | cmn_err(CE_NOTE, " mode_t sf_dmask = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_dmask);
|
---|
303 | cmn_err(CE_NOTE, " mode_t sf_fmask = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_fmask);
|
---|
304 | cmn_err(CE_NOTE, " char *sf_share_name = %s\n", sffs->sf_share_name);
|
---|
305 | cmn_err(CE_NOTE, " char *sf_mntpath = %s\n", sffs->sf_mntpath);
|
---|
306 | cmn_err(CE_NOTE, " sfp_mount_t *sf_handle = 0x%p\n", sffs->sf_handle);
|
---|
307 | }
|
---|
308 | #endif
|
---|
309 |
|
---|
310 | static int
|
---|
311 | sffs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
|
---|
312 | {
|
---|
313 | sffs_data_t *sffs;
|
---|
314 | char *mount_point = NULL;
|
---|
315 | char *share_name = NULL;
|
---|
316 | int error;
|
---|
317 | dev_t dev;
|
---|
318 | uid_t uid = 0;
|
---|
319 | gid_t gid = 0;
|
---|
320 | mode_t dmode = ~0U;
|
---|
321 | mode_t fmode = ~0U;
|
---|
322 | mode_t dmask = 0;
|
---|
323 | mode_t fmask = 0;
|
---|
324 | int stat_ttl = DEF_STAT_TTL_MS;
|
---|
325 | int fsync = 0;
|
---|
326 | char *optval;
|
---|
327 | long val;
|
---|
328 | char *path;
|
---|
329 | sfp_mount_t *handle;
|
---|
330 | sfnode_t *sfnode;
|
---|
331 |
|
---|
332 | /*
|
---|
333 | * check we have permission to do the mount
|
---|
334 | */
|
---|
335 | LogFlowFunc(("sffs_mount() started\n"));
|
---|
336 | error = secpolicy_fs_mount(cr, mvp, vfsp);
|
---|
337 | if (error != 0)
|
---|
338 | return (error);
|
---|
339 |
|
---|
340 | /*
|
---|
341 | * Mount point must be a directory
|
---|
342 | */
|
---|
343 | if (mvp->v_type != VDIR)
|
---|
344 | return (ENOTDIR);
|
---|
345 |
|
---|
346 | /*
|
---|
347 | * no support for remount (what is it?)
|
---|
348 | */
|
---|
349 | if (uap->flags & MS_REMOUNT)
|
---|
350 | return (ENOTSUP);
|
---|
351 |
|
---|
352 | /*
|
---|
353 | * Ensure that nothing else is actively in/under the mount point
|
---|
354 | */
|
---|
355 | mutex_enter(&mvp->v_lock);
|
---|
356 | if ((uap->flags & MS_OVERLAY) == 0 &&
|
---|
357 | (mvp->v_count != 1 || (mvp->v_flag & VROOT))) {
|
---|
358 | mutex_exit(&mvp->v_lock);
|
---|
359 | return (EBUSY);
|
---|
360 | }
|
---|
361 | mutex_exit(&mvp->v_lock);
|
---|
362 |
|
---|
363 | /*
|
---|
364 | * check for read only has to be done early
|
---|
365 | */
|
---|
366 | if (uap->flags & MS_RDONLY) {
|
---|
367 | vfsp->vfs_flag |= VFS_RDONLY;
|
---|
368 | vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
|
---|
369 | }
|
---|
370 |
|
---|
371 | /*
|
---|
372 | * UID to use for all files
|
---|
373 | */
|
---|
374 | if (vfs_optionisset(vfsp, "uid", &optval) &&
|
---|
375 | ddi_strtol(optval, NULL, 10, &val) == 0 &&
|
---|
376 | (uid_t)val == val)
|
---|
377 | uid = val;
|
---|
378 |
|
---|
379 | /*
|
---|
380 | * GID to use for all files
|
---|
381 | */
|
---|
382 | if (vfs_optionisset(vfsp, "gid", &optval) &&
|
---|
383 | ddi_strtol(optval, NULL, 10, &val) == 0 &&
|
---|
384 | (gid_t)val == val)
|
---|
385 | gid = val;
|
---|
386 |
|
---|
387 | /*
|
---|
388 | * dmode to use for all directories
|
---|
389 | */
|
---|
390 | if (vfs_optionisset(vfsp, "dmode", &optval) &&
|
---|
391 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
392 | (mode_t)val == val)
|
---|
393 | dmode = val;
|
---|
394 |
|
---|
395 | /*
|
---|
396 | * fmode to use for all files
|
---|
397 | */
|
---|
398 | if (vfs_optionisset(vfsp, "fmode", &optval) &&
|
---|
399 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
400 | (mode_t)val == val)
|
---|
401 | fmode = val;
|
---|
402 |
|
---|
403 | /*
|
---|
404 | * dmask to use for all directories
|
---|
405 | */
|
---|
406 | if (vfs_optionisset(vfsp, "dmask", &optval) &&
|
---|
407 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
408 | (mode_t)val == val)
|
---|
409 | dmask = val;
|
---|
410 |
|
---|
411 | /*
|
---|
412 | * fmask to use for all files
|
---|
413 | */
|
---|
414 | if (vfs_optionisset(vfsp, "fmask", &optval) &&
|
---|
415 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
416 | (mode_t)val == val)
|
---|
417 | fmask = val;
|
---|
418 |
|
---|
419 | /*
|
---|
420 | * umask to use for all directories & files
|
---|
421 | */
|
---|
422 | if (vfs_optionisset(vfsp, "umask", &optval) &&
|
---|
423 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
424 | (mode_t)val == val)
|
---|
425 | dmask = fmask = val;
|
---|
426 |
|
---|
427 | /*
|
---|
428 | * ttl to use for stat caches
|
---|
429 | */
|
---|
430 | if (vfs_optionisset(vfsp, "stat_ttl", &optval) &&
|
---|
431 | ddi_strtol(optval, NULL, 10, &val) == 0 &&
|
---|
432 | (int)val == val)
|
---|
433 | {
|
---|
434 | stat_ttl = val;
|
---|
435 | }
|
---|
436 | else
|
---|
437 | vfs_setmntopt(vfsp, "stat_ttl", VBOXSOLQUOTE(DEF_STAT_TTL_MS), 0);
|
---|
438 |
|
---|
439 | /*
|
---|
440 | * whether to honor fsync
|
---|
441 | */
|
---|
442 | if (vfs_optionisset(vfsp, "fsync", &optval))
|
---|
443 | fsync = 1;
|
---|
444 |
|
---|
445 | /*
|
---|
446 | * Any unknown options are an error
|
---|
447 | */
|
---|
448 | if ((uap->flags & MS_DATA) && uap->datalen > 0) {
|
---|
449 | cmn_err(CE_WARN, "sffs: unknown mount options specified");
|
---|
450 | return (EINVAL);
|
---|
451 | }
|
---|
452 |
|
---|
453 | /*
|
---|
454 | * get the mount point pathname
|
---|
455 | */
|
---|
456 | error = sf_pn_get(uap->dir, uap, &mount_point);
|
---|
457 | if (error)
|
---|
458 | return (error);
|
---|
459 |
|
---|
460 | /*
|
---|
461 | * find what we are mounting
|
---|
462 | */
|
---|
463 | error = sf_pn_get(uap->spec, uap, &share_name);
|
---|
464 | if (error) {
|
---|
465 | kmem_free(mount_point, strlen(mount_point) + 1);
|
---|
466 | return (error);
|
---|
467 | }
|
---|
468 |
|
---|
469 | /*
|
---|
470 | * Invoke Hypervisor mount interface before proceeding
|
---|
471 | */
|
---|
472 | error = sfprov_mount(sfprov, share_name, &handle);
|
---|
473 | if (error) {
|
---|
474 | kmem_free(share_name, strlen(share_name) + 1);
|
---|
475 | kmem_free(mount_point, strlen(mount_point) + 1);
|
---|
476 | return (error);
|
---|
477 | }
|
---|
478 |
|
---|
479 | /*
|
---|
480 | * find an available minor device number for this mount
|
---|
481 | */
|
---|
482 | mutex_enter(&sffs_minor_lock);
|
---|
483 | do {
|
---|
484 | sffs_minor = (sffs_minor + 1) & L_MAXMIN32;
|
---|
485 | dev = makedevice(sffs_major, sffs_minor);
|
---|
486 | } while (vfs_devismounted(dev));
|
---|
487 | mutex_exit(&sffs_minor_lock);
|
---|
488 |
|
---|
489 | /*
|
---|
490 | * allocate and fill in the sffs structure
|
---|
491 | */
|
---|
492 | sffs = kmem_alloc(sizeof (*sffs), KM_SLEEP);
|
---|
493 | sffs->sf_vfsp = vfsp;
|
---|
494 | sffs->sf_handle = handle;
|
---|
495 | sffs->sf_handle->sf_uid = uid;
|
---|
496 | sffs->sf_handle->sf_gid = gid;
|
---|
497 | sffs->sf_handle->sf_dmode = dmode;
|
---|
498 | sffs->sf_handle->sf_fmode = fmode;
|
---|
499 | sffs->sf_handle->sf_dmask = dmask;
|
---|
500 | sffs->sf_handle->sf_fmask = fmask;
|
---|
501 | sffs->sf_stat_ttl = stat_ttl;
|
---|
502 | sffs->sf_fsync = fsync;
|
---|
503 | sffs->sf_share_name = share_name;
|
---|
504 | sffs->sf_mntpath = mount_point;
|
---|
505 | sffs->sf_ino = 3; /* root mount point is always '3' */
|
---|
506 |
|
---|
507 | /*
|
---|
508 | * fill in the vfs structure
|
---|
509 | */
|
---|
510 | vfsp->vfs_data = (caddr_t)sffs;
|
---|
511 | vfsp->vfs_fstype = sffs_fstype;
|
---|
512 | vfsp->vfs_dev = dev;
|
---|
513 | vfsp->vfs_bsize = PAGESIZE; /* HERE JOE ??? */
|
---|
514 | vfsp->vfs_flag |= VFS_NOTRUNC; /* HERE JOE ???? */
|
---|
515 | vfs_make_fsid(&vfsp->vfs_fsid, dev, sffs_fstype);
|
---|
516 |
|
---|
517 | /*
|
---|
518 | * create the root vnode.
|
---|
519 | * XXX JOE What should the path be here? is "/" really right?
|
---|
520 | * other options?
|
---|
521 | */
|
---|
522 | path = kmem_alloc(2, KM_SLEEP);
|
---|
523 | strcpy(path, ".");
|
---|
524 | mutex_enter(&sffs_lock);
|
---|
525 | sfnode = sfnode_make(sffs, path, VDIR, NULL, NULL, NULL, 0);
|
---|
526 | sffs->sf_rootnode = sfnode_get_vnode(sfnode);
|
---|
527 | sffs->sf_rootnode->v_flag |= VROOT;
|
---|
528 | sffs->sf_rootnode->v_vfsp = vfsp;
|
---|
529 | mutex_exit(&sffs_lock);
|
---|
530 |
|
---|
531 | LogFlowFunc(("sffs_mount() success sffs=0x%p\n", sffs));
|
---|
532 | #ifdef DEBUG_ramshankar
|
---|
533 | sffs_print(sffs);
|
---|
534 | #endif
|
---|
535 | return (error);
|
---|
536 | }
|
---|
537 |
|
---|
538 | static int
|
---|
539 | sffs_unmount(vfs_t *vfsp, int flag, cred_t *cr)
|
---|
540 | {
|
---|
541 | sffs_data_t *sffs = (sffs_data_t *)vfsp->vfs_data;
|
---|
542 | int error;
|
---|
543 |
|
---|
544 | /*
|
---|
545 | * generic security check
|
---|
546 | */
|
---|
547 | LogFlowFunc(("sffs_unmount() of sffs=0x%p\n", sffs));
|
---|
548 | if ((error = secpolicy_fs_unmount(cr, vfsp)) != 0)
|
---|
549 | return (error);
|
---|
550 |
|
---|
551 | /*
|
---|
552 | * forced unmount is not supported by this file system
|
---|
553 | * and thus, ENOTSUP, is being returned.
|
---|
554 | */
|
---|
555 | if (flag & MS_FORCE) {
|
---|
556 | LogFlowFunc(("sffs_unmount(MS_FORCE) returns ENOSUP\n"));
|
---|
557 | return (ENOTSUP);
|
---|
558 | }
|
---|
559 |
|
---|
560 | /*
|
---|
561 | * Mark the file system unmounted.
|
---|
562 | */
|
---|
563 | vfsp->vfs_flag |= VFS_UNMOUNTED;
|
---|
564 |
|
---|
565 | /*
|
---|
566 | * Make sure nothing is still in use.
|
---|
567 | */
|
---|
568 | if (sffs_purge(sffs) != 0) {
|
---|
569 | vfsp->vfs_flag &= ~VFS_UNMOUNTED;
|
---|
570 | LogFlowFunc(("sffs_unmount() returns EBUSY\n"));
|
---|
571 | return (EBUSY);
|
---|
572 | }
|
---|
573 |
|
---|
574 | /*
|
---|
575 | * Invoke Hypervisor unmount interface before proceeding
|
---|
576 | */
|
---|
577 | error = sfprov_unmount(sffs->sf_handle);
|
---|
578 | if (error != 0) {
|
---|
579 | /* TBD anything here? */
|
---|
580 | }
|
---|
581 |
|
---|
582 | kmem_free(sffs->sf_share_name, strlen(sffs->sf_share_name) + 1);
|
---|
583 | kmem_free(sffs->sf_mntpath, strlen(sffs->sf_mntpath) + 1);
|
---|
584 | kmem_free(sffs, sizeof(*sffs));
|
---|
585 | LogFlowFunc(("sffs_unmount() done\n"));
|
---|
586 | return (0);
|
---|
587 | }
|
---|
588 |
|
---|
589 | /*
|
---|
590 | * return the vnode for the root of the mounted file system
|
---|
591 | */
|
---|
592 | static int
|
---|
593 | sffs_root(vfs_t *vfsp, vnode_t **vpp)
|
---|
594 | {
|
---|
595 | sffs_data_t *sffs = (sffs_data_t *)vfsp->vfs_data;
|
---|
596 | vnode_t *vp = sffs->sf_rootnode;
|
---|
597 |
|
---|
598 | VN_HOLD(vp);
|
---|
599 | *vpp = vp;
|
---|
600 | return (0);
|
---|
601 | }
|
---|
602 |
|
---|
603 | /*
|
---|
604 | * get some stats.. fake up the rest
|
---|
605 | */
|
---|
606 | static int
|
---|
607 | sffs_statvfs(vfs_t *vfsp, statvfs64_t *sbp)
|
---|
608 | {
|
---|
609 | sffs_data_t *sffs = (sffs_data_t *)vfsp->vfs_data;
|
---|
610 | sffs_fsinfo_t fsinfo;
|
---|
611 | dev32_t d32;
|
---|
612 | int error;
|
---|
613 |
|
---|
614 | bzero(sbp, sizeof(*sbp));
|
---|
615 | error = sfprov_get_fsinfo(sffs->sf_handle, &fsinfo);
|
---|
616 | if (error != 0)
|
---|
617 | return (error);
|
---|
618 |
|
---|
619 | sbp->f_bsize = fsinfo.blksize;
|
---|
620 | sbp->f_frsize = fsinfo.blksize;
|
---|
621 |
|
---|
622 | sbp->f_bfree = fsinfo.blksavail;
|
---|
623 | sbp->f_bavail = fsinfo.blksavail;
|
---|
624 | sbp->f_files = fsinfo.blksavail / 4; /* some kind of reasonable value */
|
---|
625 | sbp->f_ffree = fsinfo.blksavail / 4;
|
---|
626 | sbp->f_favail = fsinfo.blksavail / 4;
|
---|
627 |
|
---|
628 | sbp->f_blocks = fsinfo.blksused + sbp->f_bavail;
|
---|
629 |
|
---|
630 | (void) cmpldev(&d32, vfsp->vfs_dev);
|
---|
631 | sbp->f_fsid = d32;
|
---|
632 | strcpy(&sbp->f_basetype[0], "sffs");
|
---|
633 | sbp->f_flag |= ST_NOSUID;
|
---|
634 |
|
---|
635 | if (fsinfo.readonly)
|
---|
636 | sbp->f_flag |= ST_RDONLY;
|
---|
637 |
|
---|
638 | sbp->f_namemax = fsinfo.maxnamesize;
|
---|
639 | return (0);
|
---|
640 | }
|
---|
641 |
|
---|