int vboxvfs_init(struct vfsconf *vfsp)
{
    int rc;

    /* Initialize the R0 guest library. */
    rc = VbglR0SfInit();
    if (RT_FAILURE(rc))
        return ENXIO;

    /* Connect to the host service. */
    rc = VbglR0SfConnect(&g_vboxSFClient);
    if (RT_FAILURE(rc))
    {
        printf("Failed to get connection to host! rc=%d\n", rc);
        VbglR0SfTerm();
        return ENXIO;
    }

    rc = VbglR0SfSetUtf8(&g_vboxSFClient);
    if (RT_FAILURE (rc))
    {
        printf("VbglR0SfSetUtf8 failed, rc=%d\n", rc);
        VbglR0SfDisconnect(&g_vboxSFClient);
        VbglR0SfTerm();
        return EPROTO;
    }

    printf("Successfully loaded shared folder module\n");

    return 0;
}
RT_C_DECLS_END


/**
 * Connect to VBoxGuest and host shared folders service.
 *
 * @returns true if connected, false if not.
 */
bool vboxSfDwnConnect(void)
{
    /*
     * Grab VBoxGuest - since it's a dependency of this module, it shouldn't be hard.
     */
    if (!g_pVBoxGuest)
    {
        OSDictionary *pServiceMatcher = IOService::serviceMatching("org_virtualbox_VBoxGuest");
        if (pServiceMatcher)
        {
            IOService *pVBoxGuest = IOService::waitForMatchingService(pServiceMatcher, 10 * RT_NS_1SEC);
            if (pVBoxGuest)
                g_pVBoxGuest = pVBoxGuest;
            else
                LogRel(("vboxSfDwnConnect: IOService::waitForMatchingService failed!!\n"));
        }
        else
            LogRel(("vboxSfDwnConnect: serviceMatching failed\n"));
    }

    if (g_pVBoxGuest)
    {
        /*
         * Get hold of the shared folders service if we haven't already.
         */
        if (g_SfClientDarwin.handle != NULL)
            return true;

        int rc = VbglR0SfConnect(&g_SfClientDarwin);
        if (RT_SUCCESS(rc))
        {
            rc = VbglR0SfSetUtf8(&g_SfClientDarwin);
            if (RT_SUCCESS(rc))
                return true;

            LogRel(("VBoxSF: VbglR0SfSetUtf8 failed: %Rrc\n", rc));

            VbglR0SfDisconnect(&g_SfClientDarwin);
            g_SfClientDarwin.handle = NULL;
        }
        else
            LogRel(("VBoxSF: VbglR0SfConnect failed: %Rrc\n", rc));
    }

    return false;
}
Example #3
0
/* Module initialization/finalization handlers */
static int __init init(void)
{
    int rcVBox;
    int rcRet = 0;
    int err;

    TRACE();

    if (sizeof(struct vbsf_mount_info_new) > PAGE_SIZE)
    {
        printk(KERN_ERR
                "Mount information structure is too large %lu\n"
                "Must be less than or equal to %lu\n",
                (unsigned long)sizeof (struct vbsf_mount_info_new),
                (unsigned long)PAGE_SIZE);
        return -EINVAL;
    }

    err = register_filesystem(&vboxsf_fs_type);
    if (err)
    {
        LogFunc(("register_filesystem err=%d\n", err));
        return err;
    }

    rcVBox = VbglR0SfInit();
    if (RT_FAILURE(rcVBox))
    {
        LogRelFunc(("VbglR0SfInit failed, rc=%d\n", rcVBox));
        rcRet = -EPROTO;
        goto fail0;
    }

    rcVBox = VbglR0SfConnect(&client_handle);
    if (RT_FAILURE(rcVBox))
    {
        LogRelFunc(("VbglR0SfConnect failed, rc=%d\n", rcVBox));
        rcRet = -EPROTO;
        goto fail1;
    }

    rcVBox = VbglR0SfSetUtf8(&client_handle);
    if (RT_FAILURE(rcVBox))
    {
        LogRelFunc(("VbglR0SfSetUtf8 failed, rc=%d\n", rcVBox));
        rcRet = -EPROTO;
        goto fail2;
    }

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    if (!follow_symlinks)
    {
        rcVBox = VbglR0SfSetSymlinks(&client_handle);
        if (RT_FAILURE(rcVBox))
        {
            printk(KERN_WARNING
                     "vboxsf: Host unable to show symlinks, rc=%d\n",
                     rcVBox);
        }
    }
#endif

    printk(KERN_DEBUG
            "vboxsf: Successfully loaded version " VBOX_VERSION_STRING
            " (interface " RT_XSTR(VMMDEV_VERSION) ")\n");

    return 0;

fail2:
    VbglR0SfDisconnect(&client_handle);

fail1:
    VbglR0SfTerm();

fail0:
    unregister_filesystem(&vboxsf_fs_type);
    return rcRet;
}