VBoxGuestR3LibSharedFolders.cpp revision c08d89470d5384eaa863a8a371c0e4a38e9ded60
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/* $Id$ */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/** @file
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * VBoxGuestR3Lib - Ring-3 Support Library for VirtualBox guest additions, shared folders.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/*
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * Copyright (C) 2010 Oracle Corporation
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * available from http://www.virtualbox.org. This file is free software;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * General Public License (GPL) as published by the Free Software
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * The contents of this file may alternatively be used under the terms
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * of the Common Development and Distribution License Version 1.0
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * VirtualBox OSE distribution, in which case the provisions of the
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * CDDL are applicable instead of those of the GPL.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * You may elect to license modified versions of this file under the
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * terms and conditions of either the GPL or the CDDL or both.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/*******************************************************************************
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync* Header Files *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync*******************************************************************************/
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <iprt/string.h>
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <iprt/mem.h>
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <iprt/assert.h>
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <iprt/cpp/autores.h>
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <iprt/stdarg.h>
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <VBox/log.h>
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include <VBox/shflsvc.h> /** @todo File should be moved to VBox/HostServices/SharedFolderSvc.h */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync#include "VBGLR3Internal.h"
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/**
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * Connects to the shared folder service.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @returns VBox status code
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @param pu32ClientId Where to put the client id on success. The client id
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * must be passed to all the other calls to the service.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsyncVBGLR3DECL(int) VbglR3SharedFolderConnect(uint32_t *pu32ClientId)
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync{
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VBoxGuestHGCMConnectInfo Info;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Info.result = VERR_WRONG_ORDER;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync RT_ZERO(Info.Loc.u);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync strcpy(Info.Loc.u.host.achName, "VBoxSharedFolders");
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync Info.u32ClientID = UINT32_MAX; /* try make valgrind shut up. */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CONNECT, &Info, sizeof(Info));
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync if (RT_SUCCESS(rc))
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync {
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync rc = Info.result;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync if (RT_SUCCESS(rc))
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *pu32ClientId = Info.u32ClientID;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync }
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync return rc;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync}
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/**
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * Disconnect from the shared folder service.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @returns VBox status code.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsyncVBGLR3DECL(int) VbglR3SharedFolderDisconnect(uint32_t u32ClientId)
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync{
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VBoxGuestHGCMDisconnectInfo Info;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Info.result = VERR_WRONG_ORDER;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Info.u32ClientID = u32ClientId;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_DISCONNECT, &Info, sizeof(Info));
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync if (RT_SUCCESS(rc))
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync rc = Info.result;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync return rc;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync}
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync/**
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync * Checks whether a shared folder share exists or not.
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync *
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync * @returns True if shared folder exists, false if not.
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync * @param u32ClientId The client id returned by VbglR3InfoSvcConnect().
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync * @param pszShareName Shared folder name to check.
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync */
6d22c1a25757a476158a4ed2b463f6baf09ae813vboxsyncVBGLR3DECL(bool) VbglR3SharedFolderExists(uint32_t u32ClientId, const char *pszShareName)
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync{
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync AssertPtr(pszShareName);
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync uint32_t cMappings;
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync VBGLR3SHAREDFOLDERMAPPING *paMappings;
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync /** @todo Use some caching here? */
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync bool fFound = false;
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync int rc = VbglR3SharedFolderGetMappings(u32ClientId, true /* Only process auto-mounted folders */,
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync &paMappings, &cMappings);
c08d89470d5384eaa863a8a371c0e4a38e9ded60vboxsync if (RT_SUCCESS(rc) && cMappings)
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync {
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync for (uint32_t i = 0; i < cMappings && !fFound; i++)
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync {
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync char *pszName = NULL;
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszName);
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync if ( RT_SUCCESS(rc)
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync && *pszName)
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync {
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync if (RTStrICmp(pszName, pszShareName) == 0)
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync fFound = true;
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync RTStrFree(pszName);
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync }
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync }
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync RTMemFree(paMappings);
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync }
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync return fFound;
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync}
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync
3e6da1894f26075b74820b75bf5ef7e4a64070edvboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/**
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * Get the list of available shared folders.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @returns VBox status code.
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * @param u32ClientId The client id returned by VbglR3SharedFolderConnect().
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync * @param fAutoMountOnly Flag whether only auto-mounted shared folders
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync * should be reported.
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * @param ppaMappings Allocated array which will retrieve the mapping info. Needs
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * to be freed with VbglR3SharedFolderFreeMappings() later.
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * @param pcMappings The number of mappings returned in @a ppaMappings.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync */
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsyncVBGLR3DECL(int) VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool fAutoMountOnly,
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync PVBGLR3SHAREDFOLDERMAPPING *ppaMappings, uint32_t *pcMappings)
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync{
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync AssertPtr(pcMappings);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VBoxSFQueryMappings Msg;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.result = VERR_WRONG_ORDER;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.u32ClientID = u32ClientId;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.u32Function = SHFL_FN_QUERY_MAPPINGS;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.cParms = 3;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync /* Set the mapping flags. */
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync uint32_t u32Flags = 0; /** @todo SHFL_MF_UTF8 is not implemented yet. */
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync if (fAutoMountOnly) /* We only want the mappings which get auto-mounted. */
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync u32Flags |= SHFL_MF_AUTOMOUNT;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync /*
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * Prepare and get the actual mappings from the host service.
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync */
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync int rc = VINF_SUCCESS;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync uint32_t cMappings = 8; /* Should be a good default value. */
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync uint32_t cbSize = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync VBGLR3SHAREDFOLDERMAPPING *ppaMappingsTemp = (PVBGLR3SHAREDFOLDERMAPPING)RTMemAllocZ(cbSize);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync if (ppaMappingsTemp == NULL)
f655cf8b865e5960fa2e54012ae8481b4303f441vboxsync return VERR_NO_MEMORY;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync *pcMappings = 0;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync do
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync VbglHGCMParmUInt32Set(&Msg.numberOfMappings, cMappings);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync VbglHGCMParmPtrSet(&Msg.mappings, ppaMappingsTemp, cbSize);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync if (RT_SUCCESS(rc))
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync rc = Msg.callInfo.result;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync if (RT_SUCCESS(rc))
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync VbglHGCMParmUInt32Get(&Msg.numberOfMappings, pcMappings);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync /* Do we have more mappings than we have allocated space for? */
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync if (rc == VINF_BUFFER_OVERFLOW)
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync cMappings = *pcMappings;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync cbSize = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync void *pvNew = RTMemRealloc(ppaMappingsTemp, cbSize);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync AssertPtrBreakStmt(pvNew, rc = VERR_NO_MEMORY);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync ppaMappingsTemp = (PVBGLR3SHAREDFOLDERMAPPING)pvNew;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync }
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync }
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync }
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync } while (rc == VINF_BUFFER_OVERFLOW);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
f655cf8b865e5960fa2e54012ae8481b4303f441vboxsync if ( ppaMappingsTemp
f655cf8b865e5960fa2e54012ae8481b4303f441vboxsync && (RT_FAILURE(rc) || !*pcMappings))
c08d89470d5384eaa863a8a371c0e4a38e9ded60vboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync RTMemFree(ppaMappingsTemp);
c08d89470d5384eaa863a8a371c0e4a38e9ded60vboxsync ppaMappingsTemp = NULL;
c08d89470d5384eaa863a8a371c0e4a38e9ded60vboxsync }
c08d89470d5384eaa863a8a371c0e4a38e9ded60vboxsync
c08d89470d5384eaa863a8a371c0e4a38e9ded60vboxsync *ppaMappings = ppaMappingsTemp;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync return rc;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync}
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync/**
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * Frees the shared folder mappings allocated by
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * VbglR3SharedFolderGetMappings() before.
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync *
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync * @param paMappings What
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync */
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsyncVBGLR3DECL(void) VbglR3SharedFolderFreeMappings(PVBGLR3SHAREDFOLDERMAPPING paMappings)
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync{
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync RTMemFree(paMappings);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync}
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync/**
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * Get the real name of a shared folder.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync *
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @returns VBox status code.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @param u32ClientId The client id returned by VbglR3InvsSvcConnect().
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync * @param u32Root Root ID of shared folder to get the name for.
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync * @param ppszName Where to return the name string. This shall be
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync * freed by calling RTStrFree.
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync */
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsyncVBGLR3DECL(int) VbglR3SharedFolderGetName(uint32_t u32ClientId, uint32_t u32Root, char **ppszName)
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync{
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync AssertPtr(ppszName);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VBoxSFQueryMapName Msg;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.result = VERR_WRONG_ORDER;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.u32ClientID = u32ClientId;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.u32Function = SHFL_FN_QUERY_MAP_NAME;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync Msg.callInfo.cParms = 2;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync int rc;
dd90fee6b212c87998fe80f39a1645e4bbe1acb9vboxsync uint32_t cbString = sizeof(SHFLSTRING) + SHFL_MAX_LEN;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync PSHFLSTRING pString = (PSHFLSTRING)RTMemAlloc(cbString);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync if (pString)
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync {
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync RT_ZERO(*pString);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync ShflStringInitBuffer(pString, SHFL_MAX_LEN);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VbglHGCMParmUInt32Set(&Msg.root, u32Root);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync VbglHGCMParmPtrSet(&Msg.name, pString, cbString);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync if (RT_SUCCESS(rc))
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync rc = Msg.callInfo.result;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync if (RT_SUCCESS(rc))
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync {
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync *ppszName = NULL;
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync rc = RTUtf16ToUtf8(&pString->String.ucs2[0], ppszName);
ba31bc205e96548d3557ae82087dc020a52b6a0avboxsync }
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync }
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync RTMemFree(pString);
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync }
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync else
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync rc = VERR_INVALID_PARAMETER;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync return rc;
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync}
5923a1e1a9eff5786a4dc5a281e11b7dc4fd0811vboxsync
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync/**
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * Retrieves the prefix for a shared folder mount point. If no prefix
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * is set in the guest properties "sf_" is returned.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync *
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * @returns VBox status code.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * @param ppszPrefix Where to return the prefix string. This shall be
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync * freed by calling RTStrFree.
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync */
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsyncVBGLR3DECL(int) VbglR3SharedFolderGetMountPrefix(char **ppszPrefix)
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync{
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync AssertPtrReturn(ppszPrefix, VERR_INVALID_POINTER);
f450e6365ee42333841dd494583809428b504e37vboxsync int rc;
f450e6365ee42333841dd494583809428b504e37vboxsync#ifdef VBOX_WITH_GUEST_PROPS
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync uint32_t u32ClientIdGuestProp;
f450e6365ee42333841dd494583809428b504e37vboxsync rc = VbglR3GuestPropConnect(&u32ClientIdGuestProp);
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync if (RT_SUCCESS(rc))
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync {
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync rc = VbglR3GuestPropReadValueAlloc(u32ClientIdGuestProp, "/VirtualBox/GuestAdd/SharedFolders/MountPrefix", ppszPrefix);
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync if (rc == VERR_NOT_FOUND) /* No prefix set? Then set the default. */
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync {
f450e6365ee42333841dd494583809428b504e37vboxsync#endif
4a4a02cc2a09b5e3c55908c6995182c6b038e398vboxsync rc = RTStrDupEx(ppszPrefix, "sf_");
f450e6365ee42333841dd494583809428b504e37vboxsync#ifdef VBOX_WITH_GUEST_PROPS
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync }
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync VbglR3GuestPropDisconnect(u32ClientIdGuestProp);
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync }
f450e6365ee42333841dd494583809428b504e37vboxsync#endif
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync return rc;
7753dc7a3bcd14c9ec9d969cbc1a0155b0673c06vboxsync}
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync/**
04b02ffb8824a60fd37777bc1f7d2f35104a274cvboxsync * Retrieves the mount root directory for auto-mounted shared
04b02ffb8824a60fd37777bc1f7d2f35104a274cvboxsync * folders. mount point. If no string is set (VERR_NOT_FOUND)
04b02ffb8824a60fd37777bc1f7d2f35104a274cvboxsync * it's up on the caller (guest) to decide where to mount.
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync *
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync * @returns VBox status code.
04b02ffb8824a60fd37777bc1f7d2f35104a274cvboxsync * @param ppszDir Where to return the directory
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync * string. This shall be freed by
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync * calling RTStrFree.
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync */
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsyncVBGLR3DECL(int) VbglR3SharedFolderGetMountDir(char **ppszDir)
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync{
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync AssertPtrReturn(ppszDir, VERR_INVALID_POINTER);
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync int rc;
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync#ifdef VBOX_WITH_GUEST_PROPS
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync uint32_t u32ClientIdGuestProp;
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync rc = VbglR3GuestPropConnect(&u32ClientIdGuestProp);
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync if (RT_SUCCESS(rc))
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync {
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync rc = VbglR3GuestPropReadValueAlloc(u32ClientIdGuestProp, "/VirtualBox/GuestAdd/SharedFolders/MountDir", ppszDir);
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync VbglR3GuestPropDisconnect(u32ClientIdGuestProp);
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync }
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync#endif
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync return rc;
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync}
4bb5cfa1f4d9e95d7d34b5d6ede18d9f4d433bc6vboxsync