VirtualBox

source: vbox/trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF.cpp@ 75666

Last change on this file since 75666 was 75666, checked in by vboxsync, 7 years ago

darwin/VBoxSF: updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: VBoxSF.cpp 75666 2018-11-22 14:13:32Z vboxsync $ */
2/** @file
3 * VBoxSF - Darwin Shared Folders, KEXT entry points.
4 */
5
6/*
7 * Copyright (C) 2013-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DEFAULT
23#include "VBoxSFInternal.h"
24
25#include <iprt/asm.h>
26#include <iprt/assert.h>
27#include <VBox/version.h>
28#include <VBox/log.h>
29
30
31/*********************************************************************************************************************************
32* Structures and Typedefs *
33*********************************************************************************************************************************/
34/**
35 * The service class for this driver.
36 *
37 * This has one purpose: Use waitForMatchingService() to find VBoxGuest.
38 */
39class org_virtualbox_VBoxSF : public IOService
40{
41 OSDeclareDefaultStructors(org_virtualbox_VBoxSF);
42
43private:
44 IOService *waitForCoreService(void);
45
46 IOService *m_pCoreService;
47
48public:
49 virtual bool start(IOService *pProvider);
50 virtual void stop(IOService *pProvider);
51};
52
53OSDefineMetaClassAndStructors(org_virtualbox_VBoxSF, IOService);
54
55
56/*********************************************************************************************************************************
57* Global Variables *
58*********************************************************************************************************************************/
59/**
60 * Declare the module stuff.
61 */
62RT_C_DECLS_BEGIN
63static kern_return_t VBoxSfModuleLoad(struct kmod_info *pKModInfo, void *pvData);
64static kern_return_t VBoxSfModuleUnload(struct kmod_info *pKModInfo, void *pvData);
65extern kern_return_t _start(struct kmod_info *pKModInfo, void *pvData);
66extern kern_return_t _stop(struct kmod_info *pKModInfo, void *pvData);
67KMOD_EXPLICIT_DECL(VBoxVFS, VBOX_VERSION_STRING, _start, _stop)
68DECLHIDDEN(kmod_start_func_t *) _realmain = VBoxSfModuleLoad;
69DECLHIDDEN(kmod_stop_func_t *) _antimain = VBoxSfModuleUnload;
70DECLHIDDEN(int) _kext_apple_cc = __APPLE_CC__;
71RT_C_DECLS_END
72
73/** The org_virtualbox_VBoxSF instance.
74 * Used for preventing multiple instantiations. */
75static org_virtualbox_VBoxSF *g_pService = NULL;
76
77/** The shared folder service client structure. */
78VBGLSFCLIENT g_SfClient;
79/* VBoxVFS filesystem handle. Needed for FS unregistering. */
80static vfstable_t g_pVBoxSfVfsTableEntry;
81
82/** For vfs_fsentry. */
83static struct vnodeopv_desc *g_apVBoxSfVnodeOpDescList[] =
84{
85 &g_VBoxSfVnodeOpvDesc,
86};
87
88
89/** VFS registration structure. */
90static struct vfs_fsentry g_VBoxSfFsEntry =
91{
92 .vfe_vfsops = &g_VBoxSfVfsOps,
93 .vfe_vopcnt = RT_ELEMENTS(g_apVBoxSfVnodeOpDescList),
94 .vfe_opvdescs = g_apVBoxSfVnodeOpDescList,
95 .vfe_fstypenum = -1,
96 .vfe_fsname = VBOXSF_DARWIN_FS_NAME,
97 .vfe_flags = VFS_TBLTHREADSAFE /* Required. */
98 | VFS_TBLFSNODELOCK /* Required. */
99 | VFS_TBLNOTYPENUM /* No historic file system number. */
100 | VFS_TBL64BITREADY, /* Can handle 64-bit processes */
101 /** @todo add VFS_TBLREADDIR_EXTENDED */
102 .vfe_reserv = { NULL, NULL },
103};
104
105
106/**
107 * KEXT Module BSD entry point
108 */
109static kern_return_t VBoxSfModuleLoad(struct kmod_info *pKModInfo, void *pvData)
110{
111 /* Initialize the R0 guest library. */
112#if 0
113 rc = VbglR0SfInit();
114 if (RT_FAILURE(rc))
115 return KERN_FAILURE;
116#endif
117
118 PINFO("VirtualBox " VBOX_VERSION_STRING " shared folders "
119 "driver is loaded");
120
121 return KERN_SUCCESS;
122}
123
124
125/**
126 * KEXT Module BSD exit point
127 */
128static kern_return_t VBoxSfModuleUnload(struct kmod_info *pKModInfo, void *pvData)
129{
130#if 0
131 VbglR0SfTerm();
132#endif
133
134 PINFO("VirtualBox " VBOX_VERSION_STRING " shared folders driver is unloaded");
135
136 return KERN_SUCCESS;
137}
138
139/**
140 * Wait for VBoxGuest.kext to be started
141 */
142IOService *org_virtualbox_VBoxSF::waitForCoreService(void)
143{
144 OSDictionary *pServiceToMatach = serviceMatching("org_virtualbox_VBoxGuest");
145 if (pServiceToMatach)
146 {
147 /* Wait 15 seconds for VBoxGuest to be started */
148 IOService *pService = waitForMatchingService(pServiceToMatach, 15 * RT_NS_1SEC_64);
149 pServiceToMatach->release();
150 return pService;
151 }
152 PINFO("unable to create matching dictionary");
153 return NULL;
154}
155
156
157/**
158 * Start this service.
159 */
160bool org_virtualbox_VBoxSF::start(IOService *pProvider)
161{
162 if (g_pService == NULL)
163 g_pService = this;
164 else
165 {
166 printf("org_virtualbox_VBoxSF::start: g_pService=%p this=%p -> false\n", g_pService, this);
167 return false;
168 }
169
170 if (IOService::start(pProvider))
171 {
172 /*
173 * Get hold of VBoxGuest.
174 */
175 m_pCoreService = waitForCoreService();
176 if (m_pCoreService)
177 {
178 int rc = VbglR0SfInit();
179 if (RT_SUCCESS(rc))
180 {
181 /*
182 * Connect to the host service and set UTF-8 as the string encoding to use.
183 */
184 rc = VbglR0SfConnect(&g_SfClient);
185 if (RT_SUCCESS(rc))
186 {
187 rc = VbglR0SfSetUtf8(&g_SfClient);
188 if (RT_SUCCESS(rc))
189 {
190 /*
191 * Register the file system.
192 */
193 rc = vfs_fsadd(&g_VBoxSfFsEntry, &g_pVBoxSfVfsTableEntry);
194 if (rc == 0)
195 {
196 registerService();
197
198 LogRel(("VBoxSF: ready\n"));
199 return true;
200 }
201
202 LogRel(("VBoxSF: vfs_fsadd failed: %d\n", rc));
203 }
204 else
205 LogRel(("VBoxSF: VbglR0SfSetUtf8 failed: %Rrc\n", rc));
206 VbglR0SfDisconnect(&g_SfClient);
207 }
208 else
209 LogRel(("VBoxSF: VbglR0SfConnect failed: %Rrc\n", rc));
210 VbglR0SfTerm();
211 }
212 else
213 LogRel(("VBoxSF: VbglR0SfInit failed: %Rrc\n", rc));
214 m_pCoreService->release();
215 }
216 else
217 LogRel(("VBoxSF: Failed to find VBoxGuest!\n"));
218
219 IOService::stop(pProvider);
220 }
221 g_pService = NULL;
222 return false;
223}
224
225
226/**
227 * Stop this service.
228 */
229void org_virtualbox_VBoxSF::stop(IOService *pProvider)
230{
231 if (m_pCoreService == this)
232 {
233 /*
234 * Unregister the filesystem.
235 */
236 if (g_pVBoxSfVfsTableEntry != NULL)
237 {
238 int rc = vfs_fsremove(g_pVBoxSfVfsTableEntry);
239 if (rc == 0)
240 {
241 g_pVBoxSfVfsTableEntry = NULL;
242 PINFO("VBoxVFS filesystem successfully unregistered");
243 }
244 else
245 {
246 PINFO("Unable to unregister the VBoxSF filesystem (%d)", rc);
247 /** @todo how on earth do we deal with this... Gues we shouldn't be using
248 * IOService at all here. sigh. */
249 }
250 }
251 VbglR0SfDisconnect(&g_SfClient);
252 VbglR0SfTerm();
253 if (m_pCoreService)
254 m_pCoreService->release();
255
256 }
257 IOService::stop(pProvider);
258}
259
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette