VirtualBox

Ignore:
Timestamp:
Dec 5, 2018 9:38:00 PM (6 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.

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