1 | /* $Id: vboxfs_vfs.c 105679 2024-08-14 20:31:27Z 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 | #if defined(VBOX_VFS_SOLARIS_10U6)
|
---|
127 | struct modlfs_s10 {
|
---|
128 | struct mod_ops *fs_modops;
|
---|
129 | char *fs_linkinfo;
|
---|
130 | struct vfsdef_v3 *fs_vfsdef;
|
---|
131 | };
|
---|
132 | static struct modlfs_s10 modlfs = {
|
---|
133 | #else
|
---|
134 | static struct modlfs modlfs = {
|
---|
135 | #endif
|
---|
136 | &mod_fsops,
|
---|
137 | DEVICE_DESC " " VBOX_VERSION_STRING "r" VBOXSOLQUOTE(VBOX_SVN_REV),
|
---|
138 | &sffs_vfsdef
|
---|
139 | };
|
---|
140 |
|
---|
141 | static struct modlinkage modlinkage = {
|
---|
142 | MODREV_1, &modlfs, NULL
|
---|
143 | };
|
---|
144 |
|
---|
145 | static sfp_connection_t *sfprov = NULL;
|
---|
146 |
|
---|
147 | int
|
---|
148 | _init()
|
---|
149 | {
|
---|
150 | RTDBGKRNLINFO hKrnlDbgInfo;
|
---|
151 | int rc = RTR0DbgKrnlInfoOpen(&hKrnlDbgInfo, 0 /* fFlags */);
|
---|
152 | if (RT_SUCCESS(rc))
|
---|
153 | {
|
---|
154 | rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlDbgInfo, NULL /* pszModule */, "plat_map_align_amount", NULL /* ppvSymbol */);
|
---|
155 | if (RT_SUCCESS(rc))
|
---|
156 | {
|
---|
157 | #if defined(VBOX_VFS_SOLARIS_10U6)
|
---|
158 | g_VBoxVFS_SolAddrMap.MapAddr.pfnSol_map_addr = (void *)map_addr;
|
---|
159 | #else
|
---|
160 | g_VBoxVFS_SolAddrMap.ChooseAddr.pfnSol_choose_addr = (void *)choose_addr;
|
---|
161 | #endif
|
---|
162 | }
|
---|
163 | else
|
---|
164 | {
|
---|
165 | g_fVBoxVFS_SolOldAddrMap = true;
|
---|
166 | #if defined(VBOX_VFS_SOLARIS_10U6)
|
---|
167 | g_VBoxVFS_SolAddrMap.MapAddr.pfnSol_map_addr_old = (void *)map_addr;
|
---|
168 | #else
|
---|
169 | g_VBoxVFS_SolAddrMap.ChooseAddr.pfnSol_choose_addr_old = (void *)choose_addr;
|
---|
170 | #endif
|
---|
171 | }
|
---|
172 |
|
---|
173 | RTR0DbgKrnlInfoRelease(hKrnlDbgInfo);
|
---|
174 | }
|
---|
175 | else
|
---|
176 | {
|
---|
177 | cmn_err(CE_NOTE, "RTR0DbgKrnlInfoOpen failed. rc=%d\n", rc);
|
---|
178 | return rc;
|
---|
179 | }
|
---|
180 |
|
---|
181 | return (mod_install(&modlinkage));
|
---|
182 | }
|
---|
183 |
|
---|
184 | int
|
---|
185 | _info(struct modinfo *modinfop)
|
---|
186 | {
|
---|
187 | return (mod_info(&modlinkage, modinfop));
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | int
|
---|
192 | _fini()
|
---|
193 | {
|
---|
194 | int error;
|
---|
195 |
|
---|
196 | error = mod_remove(&modlinkage);
|
---|
197 | if (error)
|
---|
198 | return (error);
|
---|
199 |
|
---|
200 | /*
|
---|
201 | * Tear down the operations vectors
|
---|
202 | */
|
---|
203 | sffs_vnode_fini();
|
---|
204 | (void) vfs_freevfsops_by_type(sffs_fstype);
|
---|
205 |
|
---|
206 | /*
|
---|
207 | * close connection to the provider
|
---|
208 | */
|
---|
209 | sfprov_disconnect(sfprov);
|
---|
210 | return (0);
|
---|
211 | }
|
---|
212 |
|
---|
213 |
|
---|
214 | static int
|
---|
215 | sffs_init(int fstype, char *name)
|
---|
216 | {
|
---|
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 | int error;
|
---|
225 |
|
---|
226 | ASSERT(fstype != 0);
|
---|
227 | sffs_fstype = fstype;
|
---|
228 | LogFlowFunc(("sffs_init() name=%s\n", name));
|
---|
229 |
|
---|
230 | /*
|
---|
231 | * This may seem a silly way to do things for now. But the code
|
---|
232 | * is structured to easily allow it to be used on other hypervisors
|
---|
233 | * which would have a different implementation of the provider.
|
---|
234 | * Hopefully that'll never happen. :)
|
---|
235 | */
|
---|
236 | sfprov = sfprov_connect(SFPROV_VERSION);
|
---|
237 | if (sfprov == NULL) {
|
---|
238 | cmn_err(CE_WARN, "sffs_init: couldn't init sffs provider");
|
---|
239 | return (ENODEV);
|
---|
240 | }
|
---|
241 |
|
---|
242 | error = sfprov_set_show_symlinks();
|
---|
243 | if (error != 0) {
|
---|
244 | cmn_err(CE_WARN, "sffs_init: host unable to show symlinks, "
|
---|
245 | "rc=%d\n", error);
|
---|
246 | }
|
---|
247 |
|
---|
248 | error = vfs_setfsops(fstype, sffs_vfsops_template, NULL);
|
---|
249 | if (error != 0) {
|
---|
250 | cmn_err(CE_WARN, "sffs_init: bad vfs ops template");
|
---|
251 | return (error);
|
---|
252 | }
|
---|
253 |
|
---|
254 | error = sffs_vnode_init();
|
---|
255 | if (error != 0) {
|
---|
256 | (void) vfs_freevfsops_by_type(fstype);
|
---|
257 | cmn_err(CE_WARN, "sffs_init: bad vnode ops template");
|
---|
258 | return (error);
|
---|
259 | }
|
---|
260 |
|
---|
261 | if ((sffs_major = getudev()) == (major_t)-1) {
|
---|
262 | cmn_err(CE_WARN, "sffs_init: Can't get unique device number.");
|
---|
263 | sffs_major = 0;
|
---|
264 | }
|
---|
265 | mutex_init(&sffs_minor_lock, NULL, MUTEX_DEFAULT, NULL);
|
---|
266 | return (0);
|
---|
267 | }
|
---|
268 |
|
---|
269 | /*
|
---|
270 | * wrapper for pn_get
|
---|
271 | */
|
---|
272 | static int
|
---|
273 | sf_pn_get(char *rawpath, struct mounta *uap, char **outpath)
|
---|
274 | {
|
---|
275 | pathname_t path;
|
---|
276 | int error;
|
---|
277 |
|
---|
278 | error = pn_get(rawpath, (uap->flags & MS_SYSSPACE) ? UIO_SYSSPACE :
|
---|
279 | UIO_USERSPACE, &path);
|
---|
280 | if (error) {
|
---|
281 | LogFlowFunc(("pn_get(%s) failed\n", rawpath));
|
---|
282 | return (error);
|
---|
283 | }
|
---|
284 | *outpath = kmem_alloc(path.pn_pathlen + 1, KM_SLEEP);
|
---|
285 | strcpy(*outpath, path.pn_path);
|
---|
286 | pn_free(&path);
|
---|
287 | return (0);
|
---|
288 | }
|
---|
289 |
|
---|
290 | #ifdef DEBUG_ramshankar
|
---|
291 | static void
|
---|
292 | sffs_print(sffs_data_t *sffs)
|
---|
293 | {
|
---|
294 | cmn_err(CE_NOTE, "sffs_data_t at 0x%p\n", sffs);
|
---|
295 | cmn_err(CE_NOTE, " vfs_t *sf_vfsp = 0x%p\n", sffs->sf_vfsp);
|
---|
296 | cmn_err(CE_NOTE, " vnode_t *sf_rootnode = 0x%p\n", sffs->sf_rootnode);
|
---|
297 | cmn_err(CE_NOTE, " uid_t sf_uid = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_uid);
|
---|
298 | cmn_err(CE_NOTE, " gid_t sf_gid = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_gid);
|
---|
299 | cmn_err(CE_NOTE, " mode_t sf_dmode = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_dmode);
|
---|
300 | cmn_err(CE_NOTE, " mode_t sf_fmode = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_fmode);
|
---|
301 | cmn_err(CE_NOTE, " mode_t sf_dmask = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_dmask);
|
---|
302 | cmn_err(CE_NOTE, " mode_t sf_fmask = 0x%lu\n", (ulong_t)sffs->sf_handle->sf_fmask);
|
---|
303 | cmn_err(CE_NOTE, " char *sf_share_name = %s\n", sffs->sf_share_name);
|
---|
304 | cmn_err(CE_NOTE, " char *sf_mntpath = %s\n", sffs->sf_mntpath);
|
---|
305 | cmn_err(CE_NOTE, " sfp_mount_t *sf_handle = 0x%p\n", sffs->sf_handle);
|
---|
306 | }
|
---|
307 | #endif
|
---|
308 |
|
---|
309 | static int
|
---|
310 | sffs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
|
---|
311 | {
|
---|
312 | sffs_data_t *sffs;
|
---|
313 | char *mount_point = NULL;
|
---|
314 | char *share_name = NULL;
|
---|
315 | int error;
|
---|
316 | dev_t dev;
|
---|
317 | uid_t uid = 0;
|
---|
318 | gid_t gid = 0;
|
---|
319 | mode_t dmode = ~0U;
|
---|
320 | mode_t fmode = ~0U;
|
---|
321 | mode_t dmask = 0;
|
---|
322 | mode_t fmask = 0;
|
---|
323 | int stat_ttl = DEF_STAT_TTL_MS;
|
---|
324 | int fsync = 0;
|
---|
325 | char *optval;
|
---|
326 | long val;
|
---|
327 | char *path;
|
---|
328 | sfp_mount_t *handle;
|
---|
329 | sfnode_t *sfnode;
|
---|
330 |
|
---|
331 | /*
|
---|
332 | * check we have permission to do the mount
|
---|
333 | */
|
---|
334 | LogFlowFunc(("sffs_mount() started\n"));
|
---|
335 | error = secpolicy_fs_mount(cr, mvp, vfsp);
|
---|
336 | if (error != 0)
|
---|
337 | return (error);
|
---|
338 |
|
---|
339 | /*
|
---|
340 | * Mount point must be a directory
|
---|
341 | */
|
---|
342 | if (mvp->v_type != VDIR)
|
---|
343 | return (ENOTDIR);
|
---|
344 |
|
---|
345 | /*
|
---|
346 | * no support for remount (what is it?)
|
---|
347 | */
|
---|
348 | if (uap->flags & MS_REMOUNT)
|
---|
349 | return (ENOTSUP);
|
---|
350 |
|
---|
351 | /*
|
---|
352 | * Ensure that nothing else is actively in/under the mount point
|
---|
353 | */
|
---|
354 | mutex_enter(&mvp->v_lock);
|
---|
355 | if ((uap->flags & MS_OVERLAY) == 0 &&
|
---|
356 | (mvp->v_count != 1 || (mvp->v_flag & VROOT))) {
|
---|
357 | mutex_exit(&mvp->v_lock);
|
---|
358 | return (EBUSY);
|
---|
359 | }
|
---|
360 | mutex_exit(&mvp->v_lock);
|
---|
361 |
|
---|
362 | /*
|
---|
363 | * check for read only has to be done early
|
---|
364 | */
|
---|
365 | if (uap->flags & MS_RDONLY) {
|
---|
366 | vfsp->vfs_flag |= VFS_RDONLY;
|
---|
367 | vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
|
---|
368 | }
|
---|
369 |
|
---|
370 | /*
|
---|
371 | * UID to use for all files
|
---|
372 | */
|
---|
373 | if (vfs_optionisset(vfsp, "uid", &optval) &&
|
---|
374 | ddi_strtol(optval, NULL, 10, &val) == 0 &&
|
---|
375 | (uid_t)val == val)
|
---|
376 | uid = val;
|
---|
377 |
|
---|
378 | /*
|
---|
379 | * GID to use for all files
|
---|
380 | */
|
---|
381 | if (vfs_optionisset(vfsp, "gid", &optval) &&
|
---|
382 | ddi_strtol(optval, NULL, 10, &val) == 0 &&
|
---|
383 | (gid_t)val == val)
|
---|
384 | gid = val;
|
---|
385 |
|
---|
386 | /*
|
---|
387 | * dmode to use for all directories
|
---|
388 | */
|
---|
389 | if (vfs_optionisset(vfsp, "dmode", &optval) &&
|
---|
390 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
391 | (mode_t)val == val)
|
---|
392 | dmode = val;
|
---|
393 |
|
---|
394 | /*
|
---|
395 | * fmode to use for all files
|
---|
396 | */
|
---|
397 | if (vfs_optionisset(vfsp, "fmode", &optval) &&
|
---|
398 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
399 | (mode_t)val == val)
|
---|
400 | fmode = val;
|
---|
401 |
|
---|
402 | /*
|
---|
403 | * dmask to use for all directories
|
---|
404 | */
|
---|
405 | if (vfs_optionisset(vfsp, "dmask", &optval) &&
|
---|
406 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
407 | (mode_t)val == val)
|
---|
408 | dmask = val;
|
---|
409 |
|
---|
410 | /*
|
---|
411 | * fmask to use for all files
|
---|
412 | */
|
---|
413 | if (vfs_optionisset(vfsp, "fmask", &optval) &&
|
---|
414 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
415 | (mode_t)val == val)
|
---|
416 | fmask = val;
|
---|
417 |
|
---|
418 | /*
|
---|
419 | * umask to use for all directories & files
|
---|
420 | */
|
---|
421 | if (vfs_optionisset(vfsp, "umask", &optval) &&
|
---|
422 | ddi_strtol(optval, NULL, 8, &val) == 0 &&
|
---|
423 | (mode_t)val == val)
|
---|
424 | dmask = fmask = val;
|
---|
425 |
|
---|
426 | /*
|
---|
427 | * ttl to use for stat caches
|
---|
428 | */
|
---|
429 | if (vfs_optionisset(vfsp, "stat_ttl", &optval) &&
|
---|
430 | ddi_strtol(optval, NULL, 10, &val) == 0 &&
|
---|
431 | (int)val == val)
|
---|
432 | {
|
---|
433 | stat_ttl = val;
|
---|
434 | }
|
---|
435 | else
|
---|
436 | vfs_setmntopt(vfsp, "stat_ttl", VBOXSOLQUOTE(DEF_STAT_TTL_MS), 0);
|
---|
437 |
|
---|
438 | /*
|
---|
439 | * whether to honor fsync
|
---|
440 | */
|
---|
441 | if (vfs_optionisset(vfsp, "fsync", &optval))
|
---|
442 | fsync = 1;
|
---|
443 |
|
---|
444 | /*
|
---|
445 | * Any unknown options are an error
|
---|
446 | */
|
---|
447 | if ((uap->flags & MS_DATA) && uap->datalen > 0) {
|
---|
448 | cmn_err(CE_WARN, "sffs: unknown mount options specified");
|
---|
449 | return (EINVAL);
|
---|
450 | }
|
---|
451 |
|
---|
452 | /*
|
---|
453 | * get the mount point pathname
|
---|
454 | */
|
---|
455 | error = sf_pn_get(uap->dir, uap, &mount_point);
|
---|
456 | if (error)
|
---|
457 | return (error);
|
---|
458 |
|
---|
459 | /*
|
---|
460 | * find what we are mounting
|
---|
461 | */
|
---|
462 | error = sf_pn_get(uap->spec, uap, &share_name);
|
---|
463 | if (error) {
|
---|
464 | kmem_free(mount_point, strlen(mount_point) + 1);
|
---|
465 | return (error);
|
---|
466 | }
|
---|
467 |
|
---|
468 | /*
|
---|
469 | * Invoke Hypervisor mount interface before proceeding
|
---|
470 | */
|
---|
471 | error = sfprov_mount(sfprov, share_name, &handle);
|
---|
472 | if (error) {
|
---|
473 | kmem_free(share_name, strlen(share_name) + 1);
|
---|
474 | kmem_free(mount_point, strlen(mount_point) + 1);
|
---|
475 | return (error);
|
---|
476 | }
|
---|
477 |
|
---|
478 | /*
|
---|
479 | * find an available minor device number for this mount
|
---|
480 | */
|
---|
481 | mutex_enter(&sffs_minor_lock);
|
---|
482 | do {
|
---|
483 | sffs_minor = (sffs_minor + 1) & L_MAXMIN32;
|
---|
484 | dev = makedevice(sffs_major, sffs_minor);
|
---|
485 | } while (vfs_devismounted(dev));
|
---|
486 | mutex_exit(&sffs_minor_lock);
|
---|
487 |
|
---|
488 | /*
|
---|
489 | * allocate and fill in the sffs structure
|
---|
490 | */
|
---|
491 | sffs = kmem_alloc(sizeof (*sffs), KM_SLEEP);
|
---|
492 | sffs->sf_vfsp = vfsp;
|
---|
493 | sffs->sf_handle = handle;
|
---|
494 | sffs->sf_handle->sf_uid = uid;
|
---|
495 | sffs->sf_handle->sf_gid = gid;
|
---|
496 | sffs->sf_handle->sf_dmode = dmode;
|
---|
497 | sffs->sf_handle->sf_fmode = fmode;
|
---|
498 | sffs->sf_handle->sf_dmask = dmask;
|
---|
499 | sffs->sf_handle->sf_fmask = fmask;
|
---|
500 | sffs->sf_stat_ttl = stat_ttl;
|
---|
501 | sffs->sf_fsync = fsync;
|
---|
502 | sffs->sf_share_name = share_name;
|
---|
503 | sffs->sf_mntpath = mount_point;
|
---|
504 | sffs->sf_ino = 3; /* root mount point is always '3' */
|
---|
505 |
|
---|
506 | /*
|
---|
507 | * fill in the vfs structure
|
---|
508 | */
|
---|
509 | vfsp->vfs_data = (caddr_t)sffs;
|
---|
510 | vfsp->vfs_fstype = sffs_fstype;
|
---|
511 | vfsp->vfs_dev = dev;
|
---|
512 | vfsp->vfs_bsize = PAGESIZE; /* HERE JOE ??? */
|
---|
513 | vfsp->vfs_flag |= VFS_NOTRUNC; /* HERE JOE ???? */
|
---|
514 | vfs_make_fsid(&vfsp->vfs_fsid, dev, sffs_fstype);
|
---|
515 |
|
---|
516 | /*
|
---|
517 | * create the root vnode.
|
---|
518 | * XXX JOE What should the path be here? is "/" really right?
|
---|
519 | * other options?
|
---|
520 | */
|
---|
521 | path = kmem_alloc(2, KM_SLEEP);
|
---|
522 | strcpy(path, ".");
|
---|
523 | mutex_enter(&sffs_lock);
|
---|
524 | sfnode = sfnode_make(sffs, path, VDIR, NULL, NULL, NULL, 0);
|
---|
525 | sffs->sf_rootnode = sfnode_get_vnode(sfnode);
|
---|
526 | sffs->sf_rootnode->v_flag |= VROOT;
|
---|
527 | sffs->sf_rootnode->v_vfsp = vfsp;
|
---|
528 | mutex_exit(&sffs_lock);
|
---|
529 |
|
---|
530 | LogFlowFunc(("sffs_mount() success sffs=0x%p\n", sffs));
|
---|
531 | #ifdef DEBUG_ramshankar
|
---|
532 | sffs_print(sffs);
|
---|
533 | #endif
|
---|
534 | return (error);
|
---|
535 | }
|
---|
536 |
|
---|
537 | static int
|
---|
538 | sffs_unmount(vfs_t *vfsp, int flag, cred_t *cr)
|
---|
539 | {
|
---|
540 | sffs_data_t *sffs = (sffs_data_t *)vfsp->vfs_data;
|
---|
541 | int error;
|
---|
542 |
|
---|
543 | /*
|
---|
544 | * generic security check
|
---|
545 | */
|
---|
546 | LogFlowFunc(("sffs_unmount() of sffs=0x%p\n", sffs));
|
---|
547 | if ((error = secpolicy_fs_unmount(cr, vfsp)) != 0)
|
---|
548 | return (error);
|
---|
549 |
|
---|
550 | /*
|
---|
551 | * forced unmount is not supported by this file system
|
---|
552 | * and thus, ENOTSUP, is being returned.
|
---|
553 | */
|
---|
554 | if (flag & MS_FORCE) {
|
---|
555 | LogFlowFunc(("sffs_unmount(MS_FORCE) returns ENOSUP\n"));
|
---|
556 | return (ENOTSUP);
|
---|
557 | }
|
---|
558 |
|
---|
559 | /*
|
---|
560 | * Mark the file system unmounted.
|
---|
561 | */
|
---|
562 | vfsp->vfs_flag |= VFS_UNMOUNTED;
|
---|
563 |
|
---|
564 | /*
|
---|
565 | * Make sure nothing is still in use.
|
---|
566 | */
|
---|
567 | if (sffs_purge(sffs) != 0) {
|
---|
568 | vfsp->vfs_flag &= ~VFS_UNMOUNTED;
|
---|
569 | LogFlowFunc(("sffs_unmount() returns EBUSY\n"));
|
---|
570 | return (EBUSY);
|
---|
571 | }
|
---|
572 |
|
---|
573 | /*
|
---|
574 | * Invoke Hypervisor unmount interface before proceeding
|
---|
575 | */
|
---|
576 | error = sfprov_unmount(sffs->sf_handle);
|
---|
577 | if (error != 0) {
|
---|
578 | /* TBD anything here? */
|
---|
579 | }
|
---|
580 |
|
---|
581 | kmem_free(sffs->sf_share_name, strlen(sffs->sf_share_name) + 1);
|
---|
582 | kmem_free(sffs->sf_mntpath, strlen(sffs->sf_mntpath) + 1);
|
---|
583 | kmem_free(sffs, sizeof(*sffs));
|
---|
584 | LogFlowFunc(("sffs_unmount() done\n"));
|
---|
585 | return (0);
|
---|
586 | }
|
---|
587 |
|
---|
588 | /*
|
---|
589 | * return the vnode for the root of the mounted file system
|
---|
590 | */
|
---|
591 | static int
|
---|
592 | sffs_root(vfs_t *vfsp, vnode_t **vpp)
|
---|
593 | {
|
---|
594 | sffs_data_t *sffs = (sffs_data_t *)vfsp->vfs_data;
|
---|
595 | vnode_t *vp = sffs->sf_rootnode;
|
---|
596 |
|
---|
597 | VN_HOLD(vp);
|
---|
598 | *vpp = vp;
|
---|
599 | return (0);
|
---|
600 | }
|
---|
601 |
|
---|
602 | /*
|
---|
603 | * get some stats.. fake up the rest
|
---|
604 | */
|
---|
605 | static int
|
---|
606 | sffs_statvfs(vfs_t *vfsp, statvfs64_t *sbp)
|
---|
607 | {
|
---|
608 | sffs_data_t *sffs = (sffs_data_t *)vfsp->vfs_data;
|
---|
609 | sffs_fsinfo_t fsinfo;
|
---|
610 | dev32_t d32;
|
---|
611 | int error;
|
---|
612 |
|
---|
613 | bzero(sbp, sizeof(*sbp));
|
---|
614 | error = sfprov_get_fsinfo(sffs->sf_handle, &fsinfo);
|
---|
615 | if (error != 0)
|
---|
616 | return (error);
|
---|
617 |
|
---|
618 | sbp->f_bsize = fsinfo.blksize;
|
---|
619 | sbp->f_frsize = fsinfo.blksize;
|
---|
620 |
|
---|
621 | sbp->f_bfree = fsinfo.blksavail;
|
---|
622 | sbp->f_bavail = fsinfo.blksavail;
|
---|
623 | sbp->f_files = fsinfo.blksavail / 4; /* some kind of reasonable value */
|
---|
624 | sbp->f_ffree = fsinfo.blksavail / 4;
|
---|
625 | sbp->f_favail = fsinfo.blksavail / 4;
|
---|
626 |
|
---|
627 | sbp->f_blocks = fsinfo.blksused + sbp->f_bavail;
|
---|
628 |
|
---|
629 | (void) cmpldev(&d32, vfsp->vfs_dev);
|
---|
630 | sbp->f_fsid = d32;
|
---|
631 | strcpy(&sbp->f_basetype[0], "sffs");
|
---|
632 | sbp->f_flag |= ST_NOSUID;
|
---|
633 |
|
---|
634 | if (fsinfo.readonly)
|
---|
635 | sbp->f_flag |= ST_RDONLY;
|
---|
636 |
|
---|
637 | sbp->f_namemax = fsinfo.maxnamesize;
|
---|
638 | return (0);
|
---|
639 | }
|
---|
640 |
|
---|