Lines 1-6
Link Here
|
1 |
--- src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c.orig 2017-04-28 16:59:22.000000000 +0200 |
1 |
--- src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c.orig 2019-01-25 18:12:34 UTC |
2 |
+++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c 2017-07-12 19:24:26.109029000 +0200 |
2 |
+++ src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c |
3 |
@@ -1,10 +1,5 @@ |
3 |
@@ -1,8 +1,3 @@ |
4 |
-/* $Id: vboxvfs_vfsops.c $ */ |
4 |
-/* $Id: vboxvfs_vfsops.c $ */ |
5 |
-/** @file |
5 |
-/** @file |
6 |
- * Description. |
6 |
- * Description. |
Lines 7-17
Link Here
|
7 |
- */ |
7 |
- */ |
8 |
- |
8 |
- |
9 |
/* |
9 |
/* |
10 |
* Copyright (C) 2008-2017 Oracle Corporation |
10 |
* Copyright (C) 2008-2019 Oracle Corporation |
11 |
* |
11 |
* |
12 |
* This file is part of VirtualBox Open Source Edition (OSE), as |
12 |
@@ -14,245 +9,478 @@ |
13 |
* available from http://www.virtualbox.org. This file is free software; |
|
|
14 |
@@ -14,245 +9,479 @@ |
15 |
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the |
13 |
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the |
16 |
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. |
14 |
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. |
17 |
*/ |
15 |
*/ |
Lines 38-57
Link Here
|
38 |
+#include <sys/sbuf.h> |
36 |
+#include <sys/sbuf.h> |
39 |
|
37 |
|
40 |
-#include <iprt/mem.h> |
38 |
-#include <iprt/mem.h> |
41 |
- |
|
|
42 |
-#define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data) |
43 |
- |
44 |
-static int vboxvfs_version = VBOXVFS_VERSION; |
45 |
+#include <geom/geom.h> |
39 |
+#include <geom/geom.h> |
46 |
+#include <geom/geom_vfs.h> |
40 |
+#include <geom/geom_vfs.h> |
47 |
|
41 |
|
|
|
42 |
+#include "vboxvfs.h" |
43 |
+ |
44 |
#define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data) |
45 |
|
46 |
-static int vboxvfs_version = VBOXVFS_VERSION; |
47 |
+#ifdef MALLOC_DECLARE |
48 |
+MALLOC_DEFINE(M_VBOXVFS, "vboxvfs", "VBOX VFS"); |
49 |
+#endif |
50 |
|
48 |
-SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem"); |
51 |
-SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem"); |
49 |
-SYSCTL_INT(_vfs_vboxvfs, OID_AUTO, version, CTLFLAG_RD, &vboxvfs_version, 0, ""); |
52 |
-SYSCTL_INT(_vfs_vboxvfs, OID_AUTO, version, CTLFLAG_RD, &vboxvfs_version, 0, ""); |
50 |
+#include "vboxvfs.h" |
53 |
+static sfp_connection_t *sfprov = NULL; |
51 |
|
54 |
|
52 |
-/* global connection to the host service. */ |
55 |
-/* global connection to the host service. */ |
53 |
-static VBGLSFCLIENT g_vboxSFClient; |
56 |
-static VBGLSFCLIENT g_vboxSFClient; |
54 |
+#define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data) |
57 |
+static int vboxfs_version = VBOXVFS_VERSION; |
|
|
58 |
+u_int vboxvfs_debug = 1; |
55 |
|
59 |
|
56 |
-static vfs_init_t vboxvfs_init; |
60 |
-static vfs_init_t vboxvfs_init; |
57 |
-static vfs_uninit_t vboxvfs_uninit; |
61 |
-static vfs_uninit_t vboxvfs_uninit; |
Lines 61-67
Link Here
|
61 |
-static vfs_quotactl_t vboxvfs_quotactl; |
65 |
-static vfs_quotactl_t vboxvfs_quotactl; |
62 |
-static vfs_statfs_t vboxvfs_statfs; |
66 |
-static vfs_statfs_t vboxvfs_statfs; |
63 |
-static vfs_unmount_t vboxvfs_unmount; |
67 |
-static vfs_unmount_t vboxvfs_unmount; |
64 |
- |
68 |
+SYSCTL_NODE(_vfs, OID_AUTO, vboxfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem"); |
|
|
69 |
+SYSCTL_INT(_vfs_vboxfs, OID_AUTO, version, CTLFLAG_RD, &vboxfs_version, 0, ""); |
70 |
+SYSCTL_UINT(_vfs_vboxfs, OID_AUTO, debug, CTLFLAG_RW, &vboxvfs_debug, 0, "Debug level"); |
71 |
|
65 |
-static struct vfsops vboxvfs_vfsops = { |
72 |
-static struct vfsops vboxvfs_vfsops = { |
66 |
- .vfs_init = vboxvfs_init, |
73 |
- .vfs_init = vboxvfs_init, |
67 |
- .vfs_cmount = vboxvfs_cmount, |
74 |
- .vfs_cmount = vboxvfs_cmount, |
Lines 72-90
Link Here
|
72 |
- .vfs_sync = vfs_stdsync, |
79 |
- .vfs_sync = vfs_stdsync, |
73 |
- .vfs_uninit = vboxvfs_uninit, |
80 |
- .vfs_uninit = vboxvfs_uninit, |
74 |
- .vfs_unmount = vboxvfs_unmount, |
81 |
- .vfs_unmount = vboxvfs_unmount, |
75 |
+#ifdef MALLOC_DECLARE |
|
|
76 |
+MALLOC_DEFINE(M_VBOXVFS, "vboxvfs", "VBOX VFS"); |
77 |
+#endif |
78 |
+ |
79 |
+static sfp_connection_t *sfprov = NULL; |
80 |
+ |
81 |
+static int vboxfs_version = VBOXVFS_VERSION; |
82 |
+u_int vboxvfs_debug = 1; |
83 |
+ |
84 |
+SYSCTL_NODE(_vfs, OID_AUTO, vboxfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem"); |
85 |
+SYSCTL_INT(_vfs_vboxfs, OID_AUTO, version, CTLFLAG_RD, &vboxfs_version, 0, ""); |
86 |
+SYSCTL_UINT(_vfs_vboxfs, OID_AUTO, debug, CTLFLAG_RW, &vboxvfs_debug, 0, "Debug level"); |
87 |
+ |
88 |
+static vfs_init_t vboxfs_init; |
82 |
+static vfs_init_t vboxfs_init; |
89 |
+static vfs_uninit_t vboxfs_uninit; |
83 |
+static vfs_uninit_t vboxfs_uninit; |
90 |
+static vfs_cmount_t vboxfs_cmount; |
84 |
+static vfs_cmount_t vboxfs_cmount; |
Lines 141-157
Link Here
|
141 |
{ |
135 |
{ |
142 |
- struct vboxvfs_mount_info args; |
136 |
- struct vboxvfs_mount_info args; |
143 |
- int rc = 0; |
137 |
- int rc = 0; |
144 |
- |
|
|
145 |
- printf("%s: Enter\n", __FUNCTION__); |
146 |
- |
147 |
- rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info)); |
148 |
- if (rc) |
149 |
- return rc; |
150 |
+ struct vboxfs_node *nnode; |
138 |
+ struct vboxfs_node *nnode; |
151 |
|
139 |
|
152 |
- ma = mount_argf(ma, "uid", "%d", args.uid); |
140 |
- printf("%s: Enter\n", __FUNCTION__); |
153 |
- ma = mount_argf(ma, "gid", "%d", args.gid); |
|
|
154 |
- ma = mount_arg(ma, "from", args.name, -1); |
155 |
+ if ((mp->mnt_kern_flag & MNTK_UNMOUNT) != 0) { |
141 |
+ if ((mp->mnt_kern_flag & MNTK_UNMOUNT) != 0) { |
156 |
+ /* |
142 |
+ /* |
157 |
+ * When a new tmpfs node is created for fully |
143 |
+ * When a new tmpfs node is created for fully |
Lines 169-178
Link Here
|
169 |
+ */ |
155 |
+ */ |
170 |
+ return (EBUSY); |
156 |
+ return (EBUSY); |
171 |
+ } |
157 |
+ } |
172 |
+ |
158 |
|
|
|
159 |
- rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info)); |
160 |
- if (rc) |
161 |
- return rc; |
173 |
+ nnode = (struct vboxfs_node *)uma_zalloc_arg( |
162 |
+ nnode = (struct vboxfs_node *)uma_zalloc_arg( |
174 |
+ vsfmp->sf_node_pool, vsfmp, M_WAITOK); |
163 |
+ vsfmp->sf_node_pool, vsfmp, M_WAITOK); |
175 |
+ |
164 |
|
|
|
165 |
- ma = mount_argf(ma, "uid", "%d", args.uid); |
166 |
- ma = mount_argf(ma, "gid", "%d", args.gid); |
167 |
- ma = mount_arg(ma, "from", args.name, -1); |
176 |
+ /* Generic initialization. */ |
168 |
+ /* Generic initialization. */ |
177 |
+ nnode->sf_type = type; |
169 |
+ nnode->sf_type = type; |
178 |
+ nnode->sf_ino = vsfmp->sf_ino++; |
170 |
+ nnode->sf_ino = vsfmp->sf_ino++; |
Lines 179-185
Link Here
|
179 |
+ nnode->sf_path = strdup(fullpath, M_VBOXVFS); |
171 |
+ nnode->sf_path = strdup(fullpath, M_VBOXVFS); |
180 |
+ nnode->sf_parent = parent; |
172 |
+ nnode->sf_parent = parent; |
181 |
+ nnode->vboxfsmp = vsfmp; |
173 |
+ nnode->vboxfsmp = vsfmp; |
182 |
+ |
174 |
|
|
|
175 |
- rc = kernel_mount(ma, flags); |
183 |
+ /* Type-specific initialization. */ |
176 |
+ /* Type-specific initialization. */ |
184 |
+ switch (nnode->sf_type) { |
177 |
+ switch (nnode->sf_type) { |
185 |
+ case VBLK: |
178 |
+ case VBLK: |
Lines 190-204
Link Here
|
190 |
+ case VLNK: |
183 |
+ case VLNK: |
191 |
+ case VREG: |
184 |
+ case VREG: |
192 |
+ break; |
185 |
+ break; |
193 |
+ |
186 |
|
|
|
187 |
- printf("%s: Leave rc=%d\n", __FUNCTION__, rc); |
194 |
+ default: |
188 |
+ default: |
195 |
+ panic("vboxfs_alloc_node: type %p %d", nnode, (int)nnode->sf_type); |
189 |
+ panic("vboxfs_alloc_node: type %p %d", nnode, (int)nnode->sf_type); |
196 |
+ } |
190 |
+ } |
197 |
|
191 |
|
198 |
- rc = kernel_mount(ma, flags); |
|
|
199 |
- |
200 |
- printf("%s: Leave rc=%d\n", __FUNCTION__, rc); |
201 |
- |
202 |
- return rc; |
192 |
- return rc; |
203 |
+ *node = nnode; |
193 |
+ *node = nnode; |
204 |
+ return 0; |
194 |
+ return 0; |
Lines 219-251
Link Here
|
219 |
- struct sf_glob_info *pShFlGlobalInfo; |
209 |
- struct sf_glob_info *pShFlGlobalInfo; |
220 |
- SHFLSTRING *pShFlShareName = NULL; |
210 |
- SHFLSTRING *pShFlShareName = NULL; |
221 |
- int cbShFlShareName; |
211 |
- int cbShFlShareName; |
222 |
- |
212 |
|
223 |
- printf("%s: Enter\n", __FUNCTION__); |
213 |
- printf("%s: Enter\n", __FUNCTION__); |
224 |
- |
|
|
225 |
- if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS)) |
226 |
- return EOPNOTSUPP; |
227 |
- |
228 |
- if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts)) |
229 |
- { |
230 |
- vfs_mount_error(mp, "%s", "Invalid option"); |
231 |
- return EINVAL; |
232 |
- } |
233 |
- |
234 |
- rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare); |
235 |
- if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe) |
236 |
- return EINVAL; |
237 |
- |
238 |
- rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption); |
239 |
- if ((rc != ENOENT) && (rc || cbOption != sizeof(gid))) |
240 |
- return EINVAL; |
241 |
- |
242 |
- rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption); |
243 |
- if ((rc != ENOENT) && (rc || cbOption != sizeof(uid))) |
244 |
- return EINVAL; |
245 |
|
246 |
- pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info)); |
247 |
- if (!pShFlGlobalInfo) |
248 |
- return ENOMEM; |
249 |
+#ifdef INVARIANTS |
214 |
+#ifdef INVARIANTS |
250 |
+ TMPFS_NODE_LOCK(node); |
215 |
+ TMPFS_NODE_LOCK(node); |
251 |
+ MPASS(node->sf_vnode == NULL); |
216 |
+ MPASS(node->sf_vnode == NULL); |
Lines 255-270
Link Here
|
255 |
+ if (node->sf_path) |
220 |
+ if (node->sf_path) |
256 |
+ free(node->sf_path, M_VBOXVFS); |
221 |
+ free(node->sf_path, M_VBOXVFS); |
257 |
|
222 |
|
258 |
- cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1; |
223 |
- if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS)) |
259 |
- pShFlShareName = RTMemAllocZ(cbShFlShareName); |
224 |
- return EOPNOTSUPP; |
260 |
- if (!pShFlShareName) |
|
|
261 |
- return VERR_NO_MEMORY; |
262 |
+ uma_zfree(vboxfs->sf_node_pool, node); |
225 |
+ uma_zfree(vboxfs->sf_node_pool, node); |
263 |
+} |
226 |
+} |
264 |
|
227 |
|
265 |
- pShFlShareName->u16Length = cbShare; |
228 |
- if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts)) |
266 |
- pShFlShareName->u16Size = cbShare + 1; |
229 |
- { |
267 |
- memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1); |
230 |
- vfs_mount_error(mp, "%s", "Invalid option"); |
|
|
231 |
- return EINVAL; |
232 |
- } |
268 |
+static int |
233 |
+static int |
269 |
+vboxfs_cmount(struct mntarg *ma, void *data, uint64_t flags) |
234 |
+vboxfs_cmount(struct mntarg *ma, void *data, uint64_t flags) |
270 |
+{ |
235 |
+{ |
Lines 271-284
Link Here
|
271 |
+ struct vboxfs_mount_info args; |
236 |
+ struct vboxfs_mount_info args; |
272 |
+ int error = 0; |
237 |
+ int error = 0; |
273 |
|
238 |
|
274 |
- rc = VbglR0SfMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map); |
239 |
- rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare); |
275 |
- RTMemFree(pShFlShareName); |
240 |
- if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe) |
|
|
241 |
- return EINVAL; |
276 |
+ if (data == NULL) |
242 |
+ if (data == NULL) |
277 |
+ return (EINVAL); |
243 |
+ return (EINVAL); |
278 |
+ error = copyin(data, &args, sizeof(struct vboxfs_mount_info)); |
244 |
+ error = copyin(data, &args, sizeof(struct vboxfs_mount_info)); |
279 |
+ if (error) |
245 |
+ if (error) |
280 |
+ return (error); |
246 |
+ return (error); |
281 |
+ |
247 |
|
|
|
248 |
- rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption); |
249 |
- if ((rc != ENOENT) && (rc || cbOption != sizeof(gid))) |
250 |
- return EINVAL; |
282 |
+ ma = mount_argf(ma, "uid", "%d", args.uid); |
251 |
+ ma = mount_argf(ma, "uid", "%d", args.uid); |
283 |
+ ma = mount_argf(ma, "gid", "%d", args.gid); |
252 |
+ ma = mount_argf(ma, "gid", "%d", args.gid); |
284 |
+ ma = mount_argf(ma, "file_mode", "%d", args.fmode); |
253 |
+ ma = mount_argf(ma, "file_mode", "%d", args.fmode); |
Lines 285-301
Link Here
|
285 |
+ ma = mount_argf(ma, "dir_mode", "%d", args.dmode); |
254 |
+ ma = mount_argf(ma, "dir_mode", "%d", args.dmode); |
286 |
+ ma = mount_arg(ma, "from", args.name, -1); |
255 |
+ ma = mount_arg(ma, "from", args.name, -1); |
287 |
|
256 |
|
288 |
- if (RT_FAILURE (rc)) |
257 |
- rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption); |
289 |
- { |
258 |
- if ((rc != ENOENT) && (rc || cbOption != sizeof(uid))) |
290 |
- RTMemFree(pShFlGlobalInfo); |
259 |
- return EINVAL; |
291 |
- printf("VbglR0SfMapFolder failed rc=%d\n", rc); |
|
|
292 |
- return EPROTO; |
293 |
- } |
294 |
+ return (kernel_mount(ma, flags)); |
260 |
+ return (kernel_mount(ma, flags)); |
295 |
+} |
261 |
+} |
296 |
|
262 |
|
297 |
- pShFlGlobalInfo->uid = uid; |
263 |
- pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info)); |
298 |
- pShFlGlobalInfo->gid = gid; |
264 |
- if (!pShFlGlobalInfo) |
|
|
265 |
- return ENOMEM; |
299 |
+static const char *vboxfs_opts[] = { |
266 |
+static const char *vboxfs_opts[] = { |
300 |
+ "fstype", |
267 |
+ "fstype", |
301 |
+ "fspath", |
268 |
+ "fspath", |
Lines 308-314
Link Here
|
308 |
+ NULL |
275 |
+ NULL |
309 |
+}; |
276 |
+}; |
310 |
|
277 |
|
311 |
- mp->mnt_data = pShFlGlobalInfo; |
278 |
- cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1; |
|
|
279 |
- pShFlShareName = RTMemAllocZ(cbShFlShareName); |
280 |
- if (!pShFlShareName) |
281 |
- return VERR_NO_MEMORY; |
312 |
+#define VBOX_INTOPT(optname, val, base) do { \ |
282 |
+#define VBOX_INTOPT(optname, val, base) do { \ |
313 |
+ char *ep, *optarg = NULL; \ |
283 |
+ char *ep, *optarg = NULL; \ |
314 |
+ if (vfs_getopt(opts, optname, (void **)&optarg, NULL) == 0) { \ |
284 |
+ if (vfs_getopt(opts, optname, (void **)&optarg, NULL) == 0) { \ |
Lines 328-393
Link Here
|
328 |
+ } \ |
298 |
+ } \ |
329 |
+} while (0) |
299 |
+} while (0) |
330 |
|
300 |
|
331 |
- /** @todo root vnode. */ |
301 |
- pShFlShareName->u16Length = cbShare; |
|
|
302 |
- pShFlShareName->u16Size = cbShare + 1; |
303 |
- memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1); |
332 |
+static int |
304 |
+static int |
333 |
+vboxfs_node_ctor(void *mem, int size, void *arg, int flags) |
305 |
+vboxfs_node_ctor(void *mem, int size, void *arg, int flags) |
334 |
+{ |
306 |
+{ |
335 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
307 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
336 |
|
308 |
|
337 |
- vfs_getnewfsid(mp); |
309 |
- rc = VbglR0SfMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map); |
338 |
- vfs_mountedfrom(mp, pszShare); |
310 |
- RTMemFree(pShFlShareName); |
339 |
+ node->sf_vnode = NULL; |
311 |
+ node->sf_vnode = NULL; |
340 |
+ node->sf_vpstate = 0; |
312 |
+ node->sf_vpstate = 0; |
341 |
|
313 |
|
342 |
- printf("%s: Leave rc=0\n", __FUNCTION__); |
314 |
- if (RT_FAILURE (rc)) |
|
|
315 |
- { |
316 |
- RTMemFree(pShFlGlobalInfo); |
317 |
- printf("VbglR0SfMapFolder failed rc=%d\n", rc); |
318 |
- return EPROTO; |
319 |
- } |
343 |
+ return (0); |
320 |
+ return (0); |
344 |
+} |
321 |
+} |
345 |
|
322 |
|
346 |
- return 0; |
323 |
- pShFlGlobalInfo->uid = uid; |
|
|
324 |
- pShFlGlobalInfo->gid = gid; |
347 |
+static void |
325 |
+static void |
348 |
+vboxfs_node_dtor(void *mem, int size, void *arg) |
326 |
+vboxfs_node_dtor(void *mem, int size, void *arg) |
349 |
+{ |
327 |
+{ |
350 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
328 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
351 |
+ node->sf_type = VNON; |
329 |
+ node->sf_type = VNON; |
352 |
} |
330 |
+} |
353 |
|
331 |
|
354 |
-static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td) |
332 |
- mp->mnt_data = pShFlGlobalInfo; |
355 |
+static int |
333 |
+static int |
356 |
+vboxfs_node_init(void *mem, int size, int flags) |
334 |
+vboxfs_node_init(void *mem, int size, int flags) |
357 |
{ |
335 |
+{ |
358 |
- struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp); |
|
|
359 |
- int rc; |
360 |
- int flags = 0; |
361 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
336 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
362 |
+ node->sf_ino = 0; |
337 |
+ node->sf_ino = 0; |
363 |
|
338 |
|
364 |
- rc = VbglR0SfUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map); |
339 |
- /** @todo root vnode. */ |
365 |
- if (RT_FAILURE(rc)) |
|
|
366 |
- printf("Failed to unmap shared folder\n"); |
367 |
+ mtx_init(&node->sf_interlock, "tmpfs node interlock", NULL, MTX_DEF); |
340 |
+ mtx_init(&node->sf_interlock, "tmpfs node interlock", NULL, MTX_DEF); |
368 |
|
341 |
|
369 |
- if (mntflags & MNT_FORCE) |
342 |
- vfs_getnewfsid(mp); |
370 |
- flags |= FORCECLOSE; |
343 |
- vfs_mountedfrom(mp, pszShare); |
371 |
+ return (0); |
344 |
+ return (0); |
372 |
+} |
345 |
+} |
373 |
|
346 |
|
374 |
- /* There is 1 extra root vnode reference (vnode_root). */ |
347 |
- printf("%s: Leave rc=0\n", __FUNCTION__); |
375 |
- rc = vflush(mp, 1, flags, td); |
|
|
376 |
- if (rc) |
377 |
- return rc; |
378 |
+static void |
348 |
+static void |
379 |
+vboxfs_node_fini(void *mem, int size) |
349 |
+vboxfs_node_fini(void *mem, int size) |
380 |
+{ |
350 |
+{ |
381 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
351 |
+ struct vboxfs_node *node = (struct vboxfs_node *)mem; |
382 |
|
352 |
|
|
|
353 |
- return 0; |
383 |
+ mtx_destroy(&node->sf_interlock); |
354 |
+ mtx_destroy(&node->sf_interlock); |
384 |
+} |
355 |
} |
385 |
|
356 |
|
386 |
- RTMemFree(pShFlGlobalInfo); |
357 |
-static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td) |
387 |
- mp->mnt_data = NULL; |
|
|
388 |
+static int |
358 |
+static int |
389 |
+vboxfs_mount(struct mount *mp) |
359 |
+vboxfs_mount(struct mount *mp) |
390 |
+{ |
360 |
{ |
|
|
361 |
- struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp); |
362 |
- int rc; |
363 |
- int flags = 0; |
391 |
+ struct vboxfs_mnt *vboxfsmp = NULL; |
364 |
+ struct vboxfs_mnt *vboxfsmp = NULL; |
392 |
+ struct vfsoptlist *opts = mp->mnt_optnew; |
365 |
+ struct vfsoptlist *opts = mp->mnt_optnew; |
393 |
+ sfp_mount_t *handle = NULL; |
366 |
+ sfp_mount_t *handle = NULL; |
Lines 399-425
Link Here
|
399 |
+ uid_t uid = 0; |
372 |
+ uid_t uid = 0; |
400 |
+ gid_t gid = 0; |
373 |
+ gid_t gid = 0; |
401 |
+ struct vboxfs_node *root; |
374 |
+ struct vboxfs_node *root; |
402 |
+ |
375 |
|
|
|
376 |
- rc = VbglR0SfUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map); |
377 |
- if (RT_FAILURE(rc)) |
378 |
- printf("Failed to unmap shared folder\n"); |
403 |
+ if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS)) |
379 |
+ if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS)) |
404 |
+ return (EOPNOTSUPP); |
380 |
+ return (EOPNOTSUPP); |
405 |
+ |
381 |
|
|
|
382 |
- if (mntflags & MNT_FORCE) |
383 |
- flags |= FORCECLOSE; |
406 |
+ if (vfs_filteropt(opts, vboxfs_opts)) { |
384 |
+ if (vfs_filteropt(opts, vboxfs_opts)) { |
407 |
+ vfs_mount_error(mp, "%s", "Invalid option"); |
385 |
+ vfs_mount_error(mp, "%s", "Invalid option"); |
408 |
+ return (EINVAL); |
386 |
+ return (EINVAL); |
409 |
+ } |
387 |
+ } |
410 |
+ |
388 |
|
|
|
389 |
- /* There is 1 extra root vnode reference (vnode_root). */ |
390 |
- rc = vflush(mp, 1, flags, td); |
391 |
- if (rc) |
392 |
- return rc; |
411 |
+ VBOX_INTOPT("uid", uid, 10); |
393 |
+ VBOX_INTOPT("uid", uid, 10); |
412 |
+ VBOX_INTOPT("gid", gid, 10); |
394 |
+ VBOX_INTOPT("gid", gid, 10); |
413 |
+ VBOX_INTOPT("file_mode", file_mode, 8); |
395 |
+ VBOX_INTOPT("file_mode", file_mode, 8); |
414 |
+ VBOX_INTOPT("dir_mode", dir_mode, 8); |
396 |
+ VBOX_INTOPT("dir_mode", dir_mode, 8); |
415 |
+ VBOX_INTOPT("ro", readonly, 10); |
397 |
+ VBOX_INTOPT("ro", readonly, 10); |
416 |
+ |
398 |
|
417 |
+ error = vfs_getopt(opts, "from", (void **)&share_name, &share_len); |
399 |
+ error = vfs_getopt(opts, "from", (void **)&share_name, &share_len); |
418 |
+ if (error != 0 || share_len == 0) { |
400 |
+ if (error != 0 || share_len == 0) { |
419 |
+ vfs_mount_error(mp, "Invalid from"); |
401 |
+ vfs_mount_error(mp, "Invalid from"); |
420 |
+ return (EINVAL); |
402 |
+ return (EINVAL); |
421 |
+ } |
403 |
+ } |
422 |
+ |
404 |
|
|
|
405 |
- RTMemFree(pShFlGlobalInfo); |
406 |
- mp->mnt_data = NULL; |
423 |
+ vboxfsmp = malloc(sizeof(struct vboxfs_mnt), M_VBOXVFS, M_WAITOK | M_ZERO); |
407 |
+ vboxfsmp = malloc(sizeof(struct vboxfs_mnt), M_VBOXVFS, M_WAITOK | M_ZERO); |
424 |
+ vboxfsmp->sf_uid = uid; |
408 |
+ vboxfsmp->sf_uid = uid; |
425 |
+ vboxfsmp->sf_gid = gid; |
409 |
+ vboxfsmp->sf_gid = gid; |
Lines 427-433
Link Here
|
427 |
+ vboxfsmp->sf_dmode = dir_mode & (S_IRWXU | S_IRWXG | S_IRWXO); |
411 |
+ vboxfsmp->sf_dmode = dir_mode & (S_IRWXU | S_IRWXG | S_IRWXO); |
428 |
+ vboxfsmp->sf_ino = 3; |
412 |
+ vboxfsmp->sf_ino = 3; |
429 |
+ vboxfsmp->sf_stat_ttl = 200; |
413 |
+ vboxfsmp->sf_stat_ttl = 200; |
430 |
+ |
414 |
|
|
|
415 |
- return 0; |
431 |
+ /* Invoke Hypervisor mount interface before proceeding */ |
416 |
+ /* Invoke Hypervisor mount interface before proceeding */ |
432 |
+ error = sfprov_mount(share_name, &handle); |
417 |
+ error = sfprov_mount(share_name, &handle); |
433 |
+ if (error) |
418 |
+ if (error) |
Lines 466-472
Link Here
|
466 |
+ |
451 |
+ |
467 |
+ MNT_ILOCK(mp); |
452 |
+ MNT_ILOCK(mp); |
468 |
+ mp->mnt_data = vboxfsmp; |
453 |
+ mp->mnt_data = vboxfsmp; |
469 |
+ bzero(&mp->mnt_stat.f_fsid, sizeof(&mp->mnt_stat.f_fsid)); |
|
|
470 |
+ /* f_fsid is int32_t but serial is uint32_t, convert */ |
454 |
+ /* f_fsid is int32_t but serial is uint32_t, convert */ |
471 |
+ memcpy(&mp->mnt_stat.f_fsid, &fsinfo.serial, sizeof(mp->mnt_stat.f_fsid)); |
455 |
+ memcpy(&mp->mnt_stat.f_fsid, &fsinfo.serial, sizeof(mp->mnt_stat.f_fsid)); |
472 |
+ mp->mnt_flag |= MNT_LOCAL; |
456 |
+ mp->mnt_flag |= MNT_LOCAL; |
Lines 480-487
Link Here
|
480 |
+#endif |
464 |
+#endif |
481 |
+ MNT_IUNLOCK(mp); |
465 |
+ MNT_IUNLOCK(mp); |
482 |
+ vfs_mountedfrom(mp, share_name); |
466 |
+ vfs_mountedfrom(mp, share_name); |
483 |
|
467 |
+ |
484 |
- return 0; |
|
|
485 |
+ return (0); |
468 |
+ return (0); |
486 |
} |
469 |
} |
487 |
|
470 |
|
Lines 502-556
Link Here
|
502 |
+ struct thread *td; |
485 |
+ struct thread *td; |
503 |
+ int error; |
486 |
+ int error; |
504 |
+ int flags; |
487 |
+ int flags; |
505 |
+ |
488 |
|
|
|
489 |
- printf("%s: Enter\n", __FUNCTION__); |
506 |
+ vboxfsmp = VFSTOVBOXFS(mp); |
490 |
+ vboxfsmp = VFSTOVBOXFS(mp); |
507 |
+ td = curthread; |
491 |
+ td = curthread; |
508 |
+ flags = 0; |
492 |
+ flags = 0; |
509 |
+ if (mntflags & MNT_FORCE) |
493 |
+ if (mntflags & MNT_FORCE) |
510 |
+ flags |= FORCECLOSE; |
494 |
+ flags |= FORCECLOSE; |
511 |
+ |
495 |
|
|
|
496 |
- vp = pShFlGlobalInfo->vnode_root; |
497 |
- VREF(vp); |
512 |
+ error = vflush(mp, 0, flags, td); |
498 |
+ error = vflush(mp, 0, flags, td); |
513 |
+ if (error) |
499 |
+ if (error) |
514 |
+ return (error); |
500 |
+ return (error); |
515 |
+ |
501 |
|
|
|
502 |
- vn_lock(vp, flags | LK_RETRY, td); |
503 |
- *vpp = vp; |
516 |
+ /* Invoke Hypervisor unmount interface before proceeding */ |
504 |
+ /* Invoke Hypervisor unmount interface before proceeding */ |
517 |
+ error = sfprov_unmount(vboxfsmp->sf_handle); |
505 |
+ error = sfprov_unmount(vboxfsmp->sf_handle); |
518 |
+ if (error != 0) { |
506 |
+ if (error != 0) { |
519 |
+ /* TBD anything here? */ |
507 |
+ /* TBD anything here? */ |
520 |
+ } |
508 |
+ } |
521 |
+ |
509 |
|
|
|
510 |
- printf("%s: Leave\n", __FUNCTION__); |
522 |
+ uma_zdestroy(vboxfsmp->sf_node_pool); |
511 |
+ uma_zdestroy(vboxfsmp->sf_node_pool); |
523 |
+ |
512 |
|
|
|
513 |
- return rc; |
524 |
+ free(vboxfsmp, M_VBOXVFS); |
514 |
+ free(vboxfsmp, M_VBOXVFS); |
525 |
+ MNT_ILOCK(mp); |
515 |
+ MNT_ILOCK(mp); |
526 |
+ mp->mnt_data = NULL; |
516 |
+ mp->mnt_data = NULL; |
527 |
+ mp->mnt_flag &= ~MNT_LOCAL; |
517 |
+ mp->mnt_flag &= ~MNT_LOCAL; |
528 |
+ MNT_IUNLOCK(mp); |
518 |
+ MNT_IUNLOCK(mp); |
529 |
|
519 |
+ |
530 |
- printf("%s: Enter\n", __FUNCTION__); |
|
|
531 |
- |
532 |
- vp = pShFlGlobalInfo->vnode_root; |
533 |
- VREF(vp); |
534 |
+ return (0); |
520 |
+ return (0); |
535 |
+} |
521 |
} |
536 |
|
522 |
|
537 |
- vn_lock(vp, flags | LK_RETRY, td); |
523 |
-static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td) |
538 |
- *vpp = vp; |
|
|
539 |
+static int |
524 |
+static int |
540 |
+vboxfs_root(struct mount *mp, int flags, struct vnode **vpp) |
525 |
+vboxfs_root(struct mount *mp, int flags, struct vnode **vpp) |
541 |
+{ |
526 |
{ |
|
|
527 |
- return EOPNOTSUPP; |
542 |
+ int error; |
528 |
+ int error; |
543 |
+ error = vboxfs_alloc_vp(mp, VFSTOVBOXFS(mp)->sf_root, flags, vpp); |
529 |
+ error = vboxfs_alloc_vp(mp, VFSTOVBOXFS(mp)->sf_root, flags, vpp); |
544 |
|
530 |
+ |
545 |
- printf("%s: Leave\n", __FUNCTION__); |
|
|
546 |
+ if (!error) |
531 |
+ if (!error) |
547 |
+ (*vpp)->v_vflag |= VV_ROOT; |
532 |
+ (*vpp)->v_vflag |= VV_ROOT; |
548 |
|
533 |
+ |
549 |
- return rc; |
|
|
550 |
+ return error; |
534 |
+ return error; |
551 |
} |
535 |
} |
552 |
|
536 |
|
553 |
-static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td) |
537 |
-int vboxvfs_init(struct vfsconf *vfsp) |
554 |
+/* |
538 |
+/* |
555 |
+ * Do operation associated with quotas, not supported |
539 |
+ * Do operation associated with quotas, not supported |
556 |
+ */ |
540 |
+ */ |
Lines 557-582
Link Here
|
557 |
+static int |
541 |
+static int |
558 |
+vboxfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg) |
542 |
+vboxfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg) |
559 |
{ |
543 |
{ |
560 |
- return EOPNOTSUPP; |
544 |
- int rc; |
561 |
+ return (EOPNOTSUPP); |
545 |
+ return (EOPNOTSUPP); |
562 |
} |
546 |
+} |
563 |
|
547 |
|
564 |
-int vboxvfs_init(struct vfsconf *vfsp) |
548 |
- /* Initialize the R0 guest library. */ |
|
|
549 |
- rc = VbglR0SfInit(); |
550 |
- if (RT_FAILURE(rc)) |
551 |
- return ENXIO; |
565 |
+/* |
552 |
+/* |
566 |
+ * Initialize the filesystem globals. |
553 |
+ * Initialize the filesystem globals. |
567 |
+ */ |
554 |
+ */ |
568 |
+static int |
555 |
+static int |
569 |
+vboxfs_init(struct vfsconf *vfsp) |
556 |
+vboxfs_init(struct vfsconf *vfsp) |
570 |
{ |
557 |
+{ |
571 |
- int rc; |
|
|
572 |
+ int error; |
558 |
+ int error; |
573 |
|
559 |
|
574 |
- /* Initialize the R0 guest library. */ |
|
|
575 |
- rc = VbglR0SfInit(); |
576 |
- if (RT_FAILURE(rc)) |
577 |
- return ENXIO; |
578 |
+ DROP_GIANT(); |
579 |
|
580 |
- /* Connect to the host service. */ |
560 |
- /* Connect to the host service. */ |
581 |
- rc = VbglR0SfConnect(&g_vboxSFClient); |
561 |
- rc = VbglR0SfConnect(&g_vboxSFClient); |
582 |
- if (RT_FAILURE(rc)) |
562 |
- if (RT_FAILURE(rc)) |
Lines 585-612
Link Here
|
585 |
- VbglR0SfTerm(); |
565 |
- VbglR0SfTerm(); |
586 |
- return ENXIO; |
566 |
- return ENXIO; |
587 |
- } |
567 |
- } |
|
|
568 |
+ DROP_GIANT(); |
569 |
|
570 |
- rc = VbglR0SfSetUtf8(&g_vboxSFClient); |
571 |
- if (RT_FAILURE (rc)) |
572 |
- { |
573 |
- printf("VbglR0SfSetUtf8 failed, rc=%d\n", rc); |
574 |
- VbglR0SfDisconnect(&g_vboxSFClient); |
575 |
- VbglR0SfTerm(); |
576 |
- return EPROTO; |
577 |
- } |
588 |
+ sfprov = sfprov_connect(SFPROV_VERSION); |
578 |
+ sfprov = sfprov_connect(SFPROV_VERSION); |
589 |
+ if (sfprov == NULL) { |
579 |
+ if (sfprov == NULL) { |
590 |
+ printf("%s: couldn't connect to sf provider", __func__); |
580 |
+ printf("%s: couldn't connect to sf provider", __func__); |
591 |
+ return (ENODEV); |
581 |
+ return (ENODEV); |
592 |
+ } |
582 |
+ } |
593 |
+ |
583 |
|
|
|
584 |
- printf("Successfully loaded shared folder module\n"); |
594 |
+ error = sfprov_set_show_symlinks(); |
585 |
+ error = sfprov_set_show_symlinks(); |
595 |
+ if (error != 0) |
586 |
+ if (error != 0) |
596 |
+ printf("%s: host unable to show symlinks, error=%d\n", |
587 |
+ printf("%s: host unable to show symlinks, error=%d\n", |
597 |
+ __func__, error); |
588 |
+ __func__, error); |
598 |
|
589 |
|
599 |
- rc = VbglR0SfSetUtf8(&g_vboxSFClient); |
|
|
600 |
- if (RT_FAILURE (rc)) |
601 |
- { |
602 |
- printf("VbglR0SfSetUtf8 failed, rc=%d\n", rc); |
603 |
- VbglR0SfDisconnect(&g_vboxSFClient); |
604 |
- VbglR0SfTerm(); |
605 |
- return EPROTO; |
606 |
- } |
607 |
- |
608 |
- printf("Successfully loaded shared folder module\n"); |
609 |
- |
610 |
- return 0; |
590 |
- return 0; |
611 |
+ PICKUP_GIANT(); |
591 |
+ PICKUP_GIANT(); |
612 |
+ return (0); |
592 |
+ return (0); |