VirtualBox

Ignore:
Timestamp:
May 31, 2019 7:20:16 PM (6 years ago)
Author:
vboxsync
Message:

SharedFolderSvc: Fixed shared folder duplication after restoring state with root id gaps. bugref:9402

Location:
trunk/src/VBox/HostServices/SharedFolders
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedFolders/VBoxSharedFoldersSvc.cpp

    r78699 r78903  
    300300                                 "Saved SHFLCLIENTDATA enmErrorStyle value %d is not known/valid!", pClient->enmErrorStyle);
    301301
     302    /* Drop the root IDs of all configured mappings before restoring: */
     303    vbsfMappingLoadingStart();
     304
    302305    /* We don't actually (fully) restore the state; we simply check if the current state is as we it expect it to be. */
    303306    for (SHFLROOT i = 0; i < SHFL_MAX_MAPPINGS; i++)
     
    418421        }
    419422    }
     423
     424    /* Make sure all mappings have root IDs (global folders changes, VM
     425       config changes (paranoia)): */
     426    vbsfMappingLoadingDone();
     427
    420428    Log(("SharedFolders host service: successfully loaded state\n"));
    421429#else
  • trunk/src/VBox/HostServices/SharedFolders/mappings.cpp

    r77498 r78903  
    9696}
    9797
     98/**
     99 * Called before loading mappings from saved state to drop the root IDs.
     100 */
     101void vbsfMappingLoadingStart(void)
     102{
     103    for (SHFLROOT idRoot = 0; idRoot < RT_ELEMENTS(g_aIndexFromRoot); idRoot++)
     104        g_aIndexFromRoot[idRoot] = SHFL_ROOT_NIL;
     105
     106    for (SHFLROOT i = 0; i < RT_ELEMENTS(g_FolderMapping); i++)
     107        g_FolderMapping[i].fLoadedRootId = false;
     108}
     109
     110/**
     111 * Called when a mapping is loaded to restore the root ID and make sure it
     112 * exists.
     113 *
     114 * @returns VBox status code.
     115 */
    98116int vbsfMappingLoaded(const MAPPING *pLoadedMapping, SHFLROOT root)
    99117{
     
    138156
    139157            /* Actual index is i. Remember that when the guest uses 'root' it is actually 'i'. */
    140             /** @todo This will not work with global shared folders, as these can change
    141              *        while state is saved and these blind assignments may hid new ones.  */
     158            AssertLogRelMsg(g_aIndexFromRoot[root] == SHFL_ROOT_NIL,
     159                            ("idRoot=%u: current %u ([%s]), new %u (%ls [%s])\n",
     160                             root, g_aIndexFromRoot[root], g_FolderMapping[g_aIndexFromRoot[root]].pszFolderName,
     161                             pLoadedMapping->pMapName->String.utf16, pLoadedMapping->pszFolderName));
    142162            g_aIndexFromRoot[root] = i;
    143163
     
    158178                           pLoadedMapping->fSymlinksCreate, /* fMissing = */ true, /* fPlaceholder = */ true);
    159179}
     180
     181/**
     182 * Called after loading mappings from saved state to make sure every mapping has
     183 * a root ID.
     184 */
     185void vbsfMappingLoadingDone(void)
     186{
     187    for (SHFLROOT iMapping = 0; iMapping < RT_ELEMENTS(g_FolderMapping); iMapping++)
     188        if (g_FolderMapping[iMapping].fValid)
     189        {
     190            AssertLogRel(g_FolderMapping[iMapping].pMapName);
     191            AssertLogRel(g_FolderMapping[iMapping].pszFolderName);
     192
     193            SHFLROOT idRoot;
     194            for (idRoot = 0; idRoot < RT_ELEMENTS(g_aIndexFromRoot); idRoot++)
     195                if (g_aIndexFromRoot[idRoot] == iMapping)
     196                    break;
     197            if (idRoot >= RT_ELEMENTS(g_aIndexFromRoot))
     198            {
     199                for (idRoot = 0; idRoot < RT_ELEMENTS(g_aIndexFromRoot); idRoot++)
     200                    if (g_aIndexFromRoot[idRoot] == SHFL_ROOT_NIL)
     201                        break;
     202                if (idRoot < RT_ELEMENTS(g_aIndexFromRoot))
     203                    g_aIndexFromRoot[idRoot] = iMapping;
     204                else
     205                    LogRel(("SharedFolders: Warning! No free root ID entry for mapping #%u: %ls [%s]\n", iMapping,
     206                            g_FolderMapping[iMapping].pMapName->String.ucs2, g_FolderMapping[iMapping].pszFolderName));
     207            }
     208        }
     209
     210    /* Log the root ID mappings: */
     211    if (LogRelIs2Enabled())
     212        for (SHFLROOT idRoot = 0; idRoot < RT_ELEMENTS(g_aIndexFromRoot); idRoot++)
     213        {
     214            SHFLROOT const iMapping = g_aIndexFromRoot[idRoot];
     215            if (iMapping != SHFL_ROOT_NIL)
     216                LogRel2(("SharedFolders: idRoot %u: iMapping #%u: %ls [%s]\n", idRoot, iMapping,
     217                         g_FolderMapping[iMapping].pMapName->String.ucs2, g_FolderMapping[iMapping].pszFolderName));
     218        }
     219}
     220
    160221
    161222MAPPING *vbsfMappingGetByRoot(SHFLROOT root)
  • trunk/src/VBox/HostServices/SharedFolders/mappings.h

    r76570 r78903  
    7474bool vbsfIsHostMappingCaseSensitive(SHFLROOT root);
    7575
    76 int vbsfMappingLoaded(MAPPING const *pLoadedMapping, SHFLROOT root);
     76void vbsfMappingLoadingStart(void);
     77int  vbsfMappingLoaded(MAPPING const *pLoadedMapping, SHFLROOT root);
     78void vbsfMappingLoadingDone(void);
    7779PMAPPING vbsfMappingGetByRoot(SHFLROOT root);
    7880
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