VirtualBox

Changeset 75993 in vbox


Ignore:
Timestamp:
Dec 5, 2018 9:38:00 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
127214
Message:

SharedFolders: Track mappings made by a client session so we can unmap when the session closes, and more importantly when the VM resets.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/err.h

    r75951 r75993  
    10911091/** Requires process elevation (UAC). */
    10921092#define VERR_PROC_ELEVATION_REQUIRED        (-22419)
     1093/** Incompatible configuration requested. */
     1094#define VERR_INCOMPATIBLE_CONFIG            (-22420)
    10931095/** @} */
    10941096
  • trunk/src/VBox/HostServices/SharedFolders/mappings.cpp

    r75498 r75993  
    3232#include <iprt/path.h>
    3333#include <iprt/string.h>
     34#include <VBox/AssertGuest.h>
    3435
    3536#ifdef UNITTEST
     
    722723    }
    723724
     725    SHFLROOT RootTmp;
     726    if (!pRoot)
     727        pRoot = &RootTmp;
    724728    if (BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8))
    725729    {
     
    727731        PRTUTF16 utf16Name;
    728732
    729         rc = RTStrToUtf16 ((const char *) pszMapName->String.utf8, &utf16Name);
     733        rc = RTStrToUtf16((const char *) pszMapName->String.utf8, &utf16Name);
    730734        if (RT_FAILURE (rc))
    731735            return rc;
    732736
    733737        pFolderMapping = vbsfMappingGetByName(utf16Name, pRoot);
    734         RTUtf16Free (utf16Name);
     738        RTUtf16Free(utf16Name);
    735739    }
    736740    else
     
    744748    }
    745749
     750    /*
     751     * Check for reference count overflows and settings compatibility.
     752     * For paranoid reasons, we don't allow modifying the case sensitivity
     753     * setting while there are other mappings of a folder.
     754     */
     755    AssertLogRelReturn(*pRoot < RT_ELEMENTS(pClient->acMappings), VERR_INTERNAL_ERROR);
     756    AssertLogRelReturn(!pClient->fHasMappingCounts || pClient->acMappings[*pRoot] < _32K, VERR_TOO_MANY_OPENS);
     757    ASSERT_GUEST_LOGREL_MSG_RETURN(   pFolderMapping->cMappings == 0
     758                                   || pFolderMapping->fGuestCaseSensitive == fCaseSensitive,
     759                                   ("Incompatible case sensitivity setting: %s: %u mappings, %ssenitive, requested %ssenitive!\n",
     760                                    pFolderMapping->pszFolderName, pFolderMapping->cMappings,
     761                                    pFolderMapping->fGuestCaseSensitive ? "" : "in",  fCaseSensitive ? "" : "in"),
     762                                   VERR_INCOMPATIBLE_CONFIG);
     763
     764    /*
     765     * Go ahead and map it.
     766     */
     767    if (pClient->fHasMappingCounts)
     768        pClient->acMappings[*pRoot] += 1;
    746769    pFolderMapping->cMappings++;
    747     Assert(pFolderMapping->cMappings == 1 || pFolderMapping->fGuestCaseSensitive == fCaseSensitive);
    748770    pFolderMapping->fGuestCaseSensitive = fCaseSensitive;
     771    Log(("vbsfMmapFolder (cMappings=%u, acMappings[%u]=%u)\n", pFolderMapping->cMappings, *pRoot, pClient->acMappings[*pRoot]));
    749772    return VINF_SUCCESS;
    750773}
     
    775798        return VERR_FILE_NOT_FOUND;
    776799    }
    777 
    778800    Assert(pFolderMapping->fValid == true && pFolderMapping->cMappings > 0);
     801
     802    AssertLogRelReturn(root < RT_ELEMENTS(pClient->acMappings), VERR_INTERNAL_ERROR);
     803    AssertLogRelReturn(!pClient->fHasMappingCounts || pClient->acMappings[root] > 0, VERR_INVALID_HANDLE);
     804
     805    if (pClient->fHasMappingCounts)
     806        pClient->acMappings[root] -= 1;
     807
    779808    if (pFolderMapping->cMappings > 0)
    780809        pFolderMapping->cMappings--;
    781810
    782     if (   pFolderMapping->cMappings == 0
     811    uint32_t const cMappings = pFolderMapping->cMappings;
     812    if (   cMappings == 0
    783813        && pFolderMapping->fPlaceholder)
    784814    {
     
    790820    }
    791821
    792     Log(("vbsfUnmapFolder\n"));
     822    Log(("vbsfUnmapFolder (cMappings=%u, acMappings[%u]=%u)\n", cMappings, root, pClient->acMappings[root]));
    793823    return rc;
    794824}
  • trunk/src/VBox/HostServices/SharedFolders/service.cpp

    r75969 r75993  
    156156static DECLCALLBACK(int) svcConnect (void *, uint32_t u32ClientID, void *pvClient, uint32_t fRequestor, bool fRestoring)
    157157{
    158     RT_NOREF(u32ClientID, pvClient, fRequestor, fRestoring);
    159     int rc = VINF_SUCCESS;
    160 
     158    RT_NOREF(u32ClientID, fRequestor, fRestoring);
     159    SHFLCLIENTDATA *pClient = (SHFLCLIENTDATA *)pvClient;
    161160    Log(("SharedFolders host service: connected, u32ClientID = %u\n", u32ClientID));
    162161
    163     return rc;
     162    pClient->fHasMappingCounts = true;
     163    return VINF_SUCCESS;
    164164}
    165165
     
    264264        return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
    265265
    266     /* Restore the client data (flags + path delimiter at the moment) */
     266    /* Restore the client data (flags + path delimiter + mapping counts (new) at the moment) */
    267267    rc = SSMR3GetU32(pSSM, &len);
    268268    AssertRCReturn(rc, rc);
    269269
    270     if (len != sizeof(*pClient))
    271         return VERR_SSM_DATA_UNIT_FORMAT_CHANGED;
    272 
    273     rc = SSMR3GetMem(pSSM, pClient, sizeof(*pClient));
     270    if (len == RT_UOFFSETOF(SHFLCLIENTDATA, acMappings))
     271        pClient->fHasMappingCounts = false;
     272    else if (len != sizeof(*pClient))
     273        return SSMR3SetLoadError(pSSM, VERR_SSM_DATA_UNIT_FORMAT_CHANGED, RT_SRC_POS,
     274                                 "Saved SHFLCLIENTDATA size %u differs from current %u!\n", len, sizeof(*pClient));
     275
     276    rc = SSMR3GetMem(pSSM, pClient, len);
    274277    AssertRCReturn(rc, rc);
    275278
  • trunk/src/VBox/HostServices/SharedFolders/shfl.h

    r75498 r75993  
    2020#include <VBox/err.h>
    2121#include <VBox/hgcmsvc.h>
     22#include <VBox/shflsvc.h>
    2223
    2324#include <VBox/log.h>
     
    5455    /** Path delimiter. */
    5556    RTUTF16  PathDelimiter;
     57    /** Currently unused.   */
     58    uint8_t  bPadding;
     59    /** Set if the client has mapping usage counts.
     60     * This is for helping with saved state. */
     61    uint8_t  fHasMappingCounts;
     62    /** Mapping counts for each root ID so we can unmap the folders when the
     63     *  session disconnects or the VM resets. */
     64    uint16_t acMappings[SHFL_MAX_MAPPINGS];
    5665} SHFLCLIENTDATA;
    5766/** Pointer to a SHFLCLIENTDATA structure. */
  • trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp

    r75653 r75993  
    20712071        }
    20722072    }
     2073
     2074    for (uint32_t i = 0; i < RT_ELEMENTS(pClient->acMappings); i++)
     2075        if (pClient->acMappings[i])
     2076        {
     2077            uint16_t cMappings = pClient->acMappings[i];
     2078            while (cMappings-- > 0)
     2079                vbsfUnmapFolder(pClient, i);
     2080        }
     2081
    20732082    return VINF_SUCCESS;
    20742083}
Note: See TracChangeset for help on using the changeset viewer.

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