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;
}
int vboxvfs_uninit(struct vfsconf *vfsp)
{
    VbglR0SfDisconnect(&g_vboxSFClient);
    VbglR0SfTerm();

    return 0;
}
Example #3
0
static void __exit fini(void)
{
    TRACE();

    VbglR0SfDisconnect(&client_handle);
    VbglR0SfTerm();
    unregister_filesystem(&vboxsf_fs_type);
}
/**
 * Start the kernel module.
 */
static kern_return_t vboxSfDwnModuleLoad(struct kmod_info *pKModInfo, void *pvData)
{
    RT_NOREF(pKModInfo, pvData);
#ifdef DEBUG
    printf("vboxSfDwnModuleLoad\n");
    RTLogBackdoorPrintf("vboxSfDwnModuleLoad\n");
#endif

    /*
     * Initialize IPRT and the ring-0 guest library.
     */
    int rc = RTR0Init(0);
    if (RT_SUCCESS(rc))
    {
        rc = VbglR0SfInit();
        if (RT_SUCCESS(rc))
        {
            /*
             * Register the file system.
             */
            rc = vfs_fsadd(&g_VBoxSfFsEntry, &g_pVBoxSfVfsTableEntry);
            if (rc == 0)
            {
                /*
                 * Try find VBoxGuest and connect to the shared folders service on the host.
                 */
                /** @todo should we just ignore the error here and retry at mount time?
                 * Technically, VBoxGuest should be available since it's one of our
                 * dependencies... */
                vboxSfDwnConnect();

                /*
                 * We're done for now.  We'll deal with
                 */
                LogRel(("VBoxSF: loaded\n"));
                return KERN_SUCCESS;
            }

            printf("VBoxSF: vfs_fsadd failed: %d\n", rc);
            RTLogBackdoorPrintf("VBoxSF: vfs_fsadd failed: %d\n", rc);
            VbglR0SfTerm();
        }
        else
        {
            printf("VBoxSF: VbglR0SfInit failed: %d\n", rc);
            RTLogBackdoorPrintf("VBoxSF: VbglR0SfInit failed: %Rrc\n", rc);
        }
        RTR0Term();
    }
    else
    {
        printf("VBoxSF: RTR0Init failed: %d\n", rc);
        RTLogBackdoorPrintf("VBoxSF: RTR0Init failed: %Rrc\n", rc);
    }
    return KERN_FAILURE;
}
/**
 * Stop the kernel module.
 */
static kern_return_t vboxSfDwnModuleUnload(struct kmod_info *pKModInfo, void *pvData)
{
    RT_NOREF(pKModInfo, pvData);
#ifdef DEBUG
    printf("vboxSfDwnModuleUnload\n");
    RTLogBackdoorPrintf("vboxSfDwnModuleUnload\n");
#endif


    /*
     * Are we busy?  If so fail.  Otherwise try deregister the file system.
     */
    if (g_cVBoxSfMounts > 0)
    {
        LogRel(("VBoxSF: Refusing to unload with %u active mounts\n", g_cVBoxSfMounts));
        return KERN_NO_ACCESS;
    }

    if (g_pVBoxSfVfsTableEntry)
    {
        int rc = vfs_fsremove(g_pVBoxSfVfsTableEntry);
        if (rc != 0)
        {
            LogRel(("VBoxSF: vfs_fsremove failed: %d\n", rc));
            return KERN_NO_ACCESS;
        }
    }

    /*
     * Disconnect and terminate libraries we're using.
     */
    if (g_SfClientDarwin.handle != NULL)
    {
        VbglR0SfDisconnect(&g_SfClientDarwin);
        g_SfClientDarwin.handle = NULL;
    }

    if (g_pVBoxGuest)
    {
        g_pVBoxGuest->release();
        g_pVBoxGuest = NULL;
    }

    VbglR0SfTerm();
    RTR0Term();
    return KERN_SUCCESS;
}
Example #6
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;
}