Example #1
0
int vboxvfs_init(struct vfsconf *vfsp)
{
    int rc;

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

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

    rc = vboxCallSetUtf8 (&g_vboxSFClient);
    if (RT_FAILURE (rc))
    {
        printf("vboxCallSetUtf8 failed, rc=%d\n", rc);
        vboxDisconnect(&g_vboxSFClient);
        vboxUninit();
        return EPROTO;
    }

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

    return 0;
}
/**
 * KEXT Module BSD entry point
 */
static kern_return_t VBoxVFSModuleLoad(struct kmod_info *pKModInfo, void *pvData)
{
    int rc;

    /* Initialize the R0 guest library. */
#if 0
    rc = vboxInit();
    if (RT_FAILURE(rc))
        return KERN_FAILURE;
#endif

    PINFO("VirtualBox " VBOX_VERSION_STRING " shared folders "
          "driver is loaded");

    return KERN_SUCCESS;
}
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 = vboxInit();
    if (RT_FAILURE(rcVBox))
    {
        LogRelFunc(("vboxInit failed, rc=%d\n", rcVBox));
        rcRet = -EPROTO;
        goto fail0;
    }

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

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

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
    if (!follow_symlinks)
    {
        rcVBox = vboxCallSetSymlinks(&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:
    vboxDisconnect(&client_handle);

fail1:
    vboxUninit();

fail0:
    unregister_filesystem(&vboxsf_fs_type);
    return rcRet;
}
/**
 * Start this service.
 */
bool org_virtualbox_VBoxVFS::start(IOService *pProvider)
{
    int rc;

    if (!IOService::start(pProvider))
        return false;

    /* Low level initialization should be performed only once */
    if (!ASMAtomicCmpXchgBool(&g_fInstantiated, true, false))
    {
        IOService::stop(pProvider);
        return false;
    }

    /* Wait for VBoxGuest to be started */
    coreService = waitForCoreService();
    if (coreService)
    {
        rc = vboxInit();
        if (RT_SUCCESS(rc))
        {
            /* Connect to the host service. */
            rc = vboxConnect(&g_vboxSFClient);
            if (RT_SUCCESS(rc))
            {
                PINFO("VBox client connected");
                rc = vboxCallSetUtf8(&g_vboxSFClient);
                if (RT_SUCCESS(rc))
                {
                    rc = VBoxVFSRegisterFilesystem();
                    if (RT_SUCCESS(rc))
                    {
                        registerService();
                        PINFO("Successfully started I/O kit class instance");
                        return true;
                    }
                    PERROR("Unable to register VBoxVFS filesystem");
                }
                else
                {
                    PERROR("vboxCallSetUtf8 failed: rc=%d", rc);
                }
                vboxDisconnect(&g_vboxSFClient);
            }
            else
            {
                PERROR("Failed to get connection to host: rc=%d", rc);
            }
            vboxUninit();
        }
        else
        {
            PERROR("Failed to initialize low level library");
        }
        coreService->release();
    }
    else
    {
        PERROR("VBoxGuest KEXT not started");
    }

    ASMAtomicXchgBool(&g_fInstantiated, false);
    IOService::stop(pProvider);

    return false;
}