VirtualBox

Changeset 21172 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Jul 2, 2009 3:31:19 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
49464
Message:

Shared folders host service: fixed load state failure, when the order of mappings is changed.

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

Legend:

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

    r14215 r21172  
    2424#include <iprt/string.h>
    2525
    26 MAPPING FolderMapping[SHFL_MAX_MAPPINGS];
     26/* Shared folders order in the saved state and in the FolderMapping can differ.
     27 * So a translation array of root handle is needed.
     28 */
     29
     30static MAPPING FolderMapping[SHFL_MAX_MAPPINGS];
     31static SHFLROOT aIndexFromRoot[SHFL_MAX_MAPPINGS];
     32
     33void vbsfMappingInit(void)
     34{
     35    int root;
     36    for (root = 0; root < RT_ELEMENTS(aIndexFromRoot); root++)
     37    {
     38        aIndexFromRoot[root] = ~0;
     39    }
     40}
     41
     42int vbsfMappingLoaded (const MAPPING *pLoadedMapping, SHFLROOT root)
     43{
     44    /* Mapping loaded from the saved state with the index. Which means
     45     * the guest uses the iMapping as root handle for this folder.
     46     * Check whether there is the same mapping in FolderMapping and
     47     * update the aIndexFromRoot.
     48     *
     49     * Also update the mapping properties, which were lost: cMappings.
     50     */
     51    if (root >= SHFL_MAX_MAPPINGS)
     52    {
     53        return VERR_INVALID_PARAMETER;
     54    }
     55
     56    int i;
     57
     58    for (i = 0; i < RT_ELEMENTS(FolderMapping); i++)
     59    {
     60        MAPPING *pMapping = &FolderMapping[i];
     61
     62        /* Equal? */
     63        if (   pLoadedMapping->fValid == pMapping->fValid
     64            && ShflStringSizeOfBuffer(pLoadedMapping->pMapName) == ShflStringSizeOfBuffer(pMapping->pMapName)
     65            && memcmp(pLoadedMapping->pMapName, pMapping->pMapName, ShflStringSizeOfBuffer(pMapping->pMapName)) == 0)
     66        {
     67            /* Actual index is i. */
     68            aIndexFromRoot[root] = i;
     69
     70            /* Update the mapping properties. */
     71            pMapping->cMappings = pLoadedMapping->cMappings;
     72
     73            return VINF_SUCCESS;
     74        }
     75    }
     76
     77    return VERR_INVALID_PARAMETER;
     78}
     79
     80MAPPING *vbsfMappingGetByRoot(SHFLROOT root)
     81{
     82    if (root < RT_ELEMENTS(aIndexFromRoot))
     83    {
     84        int iMapping = aIndexFromRoot[root];
     85
     86        if (0 <= iMapping && iMapping < RT_ELEMENTS(FolderMapping))
     87        {
     88            return &FolderMapping[iMapping];
     89        }
     90    }
     91
     92    return NULL;
     93}
     94
     95static SHFLROOT vbsfMappingGetRootFromIndex(int iMapping)
     96{
     97    int root;
     98    for (root = 0; root < RT_ELEMENTS(aIndexFromRoot); root++)
     99    {
     100        if (iMapping == aIndexFromRoot[root])
     101        {
     102            return root;
     103        }
     104    }
     105
     106    return ~0;
     107}
     108
     109static MAPPING *vbsfMappingGetByName (PRTUTF16 utf16Name, SHFLROOT *pRoot)
     110{
     111    int i;
     112
     113    for (i=0;i<SHFL_MAX_MAPPINGS;i++)
     114    {
     115        if (FolderMapping[i].fValid == true)
     116        {
     117            if (!RTUtf16LocaleICmp(FolderMapping[i].pMapName->String.ucs2, utf16Name))
     118            {
     119                SHFLROOT root = vbsfMappingGetRootFromIndex(i);
     120               
     121                if (root != ~0)
     122                {
     123                    if (pRoot)
     124                    {
     125                        *pRoot = root;
     126                    }
     127                    return &FolderMapping[i];
     128                }
     129                else
     130                {
     131                    AssertFailed();
     132                }
     133            }
     134        }
     135    }
     136
     137    return NULL;
     138}
     139
     140static void vbsfRootHandleAdd(int iMapping)
     141{
     142    int root;
     143
     144    for (root = 0; root < RT_ELEMENTS(aIndexFromRoot); root++)
     145    {
     146        if (aIndexFromRoot[root] == ~0)
     147        {
     148            aIndexFromRoot[root] = iMapping;
     149            return;
     150        }
     151    }
     152
     153    AssertFailed();
     154    return;
     155}
     156
     157static void vbsfRootHandleRemove(int iMapping)
     158{
     159    int root;
     160
     161    for (root = 0; root < RT_ELEMENTS(aIndexFromRoot); root++)
     162    {
     163        if (aIndexFromRoot[root] == iMapping)
     164        {
     165            aIndexFromRoot[root] = ~0;
     166            return;
     167        }
     168    }
     169
     170    AssertFailed();
     171    return;
     172}
     173
    27174
    28175
     
    98245            }
    99246            FolderMapping[i].fHostCaseSensitive = RT_SUCCESS(rc) ? prop.fCaseSensitive : false;
     247            vbsfRootHandleAdd(i);
    100248            break;
    101249        }
     
    135283                FolderMapping[i].pMapName    = NULL;
    136284                FolderMapping[i].fValid      = false;
     285                vbsfRootHandleRemove(i);
    137286                break;
    138287            }
     
    151300PCRTUTF16 vbsfMappingsQueryHostRoot (SHFLROOT root, uint32_t *pcbRoot)
    152301{
    153     if (root > SHFL_MAX_MAPPINGS)
     302    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     303    if (pFolderMapping == NULL)
    154304    {
    155305        AssertFailed();
     
    157307    }
    158308
    159     *pcbRoot = FolderMapping[root].pFolderName->u16Size;
    160     return &FolderMapping[root].pFolderName->String.ucs2[0];
     309    *pcbRoot = pFolderMapping->pFolderName->u16Size;
     310    return &pFolderMapping->pFolderName->String.ucs2[0];
    161311}
    162312
    163313bool vbsfIsGuestMappingCaseSensitive (SHFLROOT root)
    164314{
    165     if (root > SHFL_MAX_MAPPINGS)
     315    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     316    if (pFolderMapping == NULL)
    166317    {
    167318        AssertFailed();
     
    169320    }
    170321
    171     return FolderMapping[root].fGuestCaseSensitive;
     322    return pFolderMapping->fGuestCaseSensitive;
    172323}
    173324
    174325bool vbsfIsHostMappingCaseSensitive (SHFLROOT root)
    175326{
    176     if (root > SHFL_MAX_MAPPINGS)
     327    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     328    if (pFolderMapping == NULL)
    177329    {
    178330        AssertFailed();
     
    180332    }
    181333
    182     return FolderMapping[root].fHostCaseSensitive;
     334    return pFolderMapping->fHostCaseSensitive;
    183335}
    184336
     
    194346    for (uint32_t i=0;i<cMaxMappings;i++)
    195347    {
    196         if (FolderMapping[i].fValid == true)
     348        MAPPING *pFolderMapping = vbsfMappingGetByRoot(i);
     349        if (pFolderMapping != NULL && pFolderMapping->fValid == true)
    197350        {
    198351            pMappings[*pcMappings].u32Status = SHFL_MS_NEW;
     
    214367             pClient, root, pString));
    215368
    216     if (root >= SHFL_MAX_MAPPINGS)
     369    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     370    if (pFolderMapping == NULL)
     371    {
    217372        return VERR_INVALID_PARAMETER;
     373    }
    218374
    219375    if (BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8))
     
    224380    }
    225381
    226     if (FolderMapping[root].fValid == true)
    227     {
    228         pString->u16Length = FolderMapping[root].pMapName->u16Length;
    229         memcpy(pString->String.ucs2, FolderMapping[root].pMapName->String.ucs2, pString->u16Size);
     382    if (pFolderMapping->fValid == true)
     383    {
     384        pString->u16Length = pFolderMapping->pMapName->u16Length;
     385        memcpy(pString->String.ucs2, pFolderMapping->pMapName->String.ucs2, pString->u16Size);
    230386    }
    231387    else
     
    244400             pClient, root));
    245401
    246     if (root >= SHFL_MAX_MAPPINGS)
     402    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     403    if (pFolderMapping == NULL)
     404    {
    247405        return VERR_INVALID_PARAMETER;
    248 
    249     if (FolderMapping[root].fValid == true)
    250         *fWritable = FolderMapping[root].fWritable;
     406    }
     407
     408    if (pFolderMapping->fValid == true)
     409        *fWritable = pFolderMapping->fWritable;
    251410    else
    252411        rc = VERR_FILE_NOT_FOUND;
     
    257416}
    258417
    259 static int vbsfQueryMappingIndex (PRTUTF16 utf16Name, size_t *pIndex)
    260 {
    261     size_t i;
    262 
    263     for (i=0;i<SHFL_MAX_MAPPINGS;i++)
    264     {
    265         if (FolderMapping[i].fValid == true)
    266         {
    267             if (!RTUtf16LocaleICmp(FolderMapping[i].pMapName->String.ucs2, utf16Name))
    268             {
    269                 *pIndex = i;
    270                 return 0;
    271             }
    272         }
    273     }
    274     return -1;
    275 }
    276 
    277418int vbsfMapFolder (SHFLCLIENTDATA *pClient, PSHFLSTRING pszMapName, RTUTF16 delimiter, bool fCaseSensitive, SHFLROOT *pRoot)
    278419{
    279     size_t index;
     420    MAPPING *pFolderMapping = NULL;
    280421
    281422    if (BIT_FLAG(pClient->fu32Flags, SHFL_CF_UTF8))
     
    306447            return rc;
    307448
    308         rc = vbsfQueryMappingIndex (utf16Name, &index);
     449        pFolderMapping = vbsfMappingGetByName(utf16Name, pRoot);
    309450        RTUtf16Free (utf16Name);
    310 
    311         if (rc)
    312         {
    313             // AssertMsgFailed(("vbsfMapFolder: map %s not found!!\n",
    314             //                 pszMapName->String.utf8));
    315             return VERR_FILE_NOT_FOUND;
    316         }
    317451    }
    318452    else
    319453    {
    320         if (vbsfQueryMappingIndex (pszMapName->String.ucs2, &index))
    321         {
    322             // AssertMsgFailed(("vbsfMapFolder: map %ls not found!!\n",
    323             //                  pszMapName->String.ucs2));
    324             return VERR_FILE_NOT_FOUND;
    325         }
    326     }
    327 
    328     FolderMapping[index].cMappings++;
    329     Assert(FolderMapping[index].cMappings == 1 || FolderMapping[index].fGuestCaseSensitive == fCaseSensitive);
    330     FolderMapping[index].fGuestCaseSensitive = fCaseSensitive;
    331     *pRoot = (SHFLROOT)index;
     454        pFolderMapping = vbsfMappingGetByName(pszMapName->String.ucs2, pRoot);
     455    }
     456
     457    if (!pFolderMapping)
     458    {
     459        return VERR_FILE_NOT_FOUND;
     460    }
     461
     462    pFolderMapping->cMappings++;
     463    Assert(pFolderMapping->cMappings == 1 || pFolderMapping->fGuestCaseSensitive == fCaseSensitive);
     464    pFolderMapping->fGuestCaseSensitive = fCaseSensitive;
    332465    return VINF_SUCCESS;
    333466}
     
    337470    int rc = VINF_SUCCESS;
    338471
    339     if (root > SHFL_MAX_MAPPINGS)
     472    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     473    if (pFolderMapping == NULL)
    340474    {
    341475        AssertFailed();
     
    343477    }
    344478
    345     Assert(FolderMapping[root].fValid == true && FolderMapping[root].cMappings > 0);
    346     if (FolderMapping[root].cMappings > 0)
    347         FolderMapping[root].cMappings--;
     479    Assert(pFolderMapping->fValid == true && pFolderMapping->cMappings > 0);
     480    if (pFolderMapping->cMappings > 0)
     481        pFolderMapping->cMappings--;
    348482
    349483    Log(("vbsfUnmapFolder\n"));
  • trunk/src/VBox/HostServices/SharedFolders/mappings.h

    r8155 r21172  
    3636} MAPPING, *PMAPPING;
    3737
    38 extern MAPPING FolderMapping[SHFL_MAX_MAPPINGS];
     38void vbsfMappingInit(void);
    3939
    4040bool vbsfMappingQuery(uint32_t iMapping, PMAPPING *pMapping);
     
    5454bool          vbsfIsHostMappingCaseSensitive (SHFLROOT root);
    5555
     56int vbsfMappingLoaded (const MAPPING *pLoadedMapping, SHFLROOT root);
     57MAPPING *vbsfMappingGetByRoot(SHFLROOT root);
     58
    5659#endif /* !___MAPPINGS_H */
    5760
  • trunk/src/VBox/HostServices/SharedFolders/service.cpp

    r20584 r21172  
    136136    for (int i=0;i<SHFL_MAX_MAPPINGS;i++)
    137137    {
    138         rc = SSMR3PutU32(pSSM, FolderMapping[i].cMappings);
     138        /* Mapping are saved in the order of increasing root handle values. */
     139        MAPPING *pFolderMapping = vbsfMappingGetByRoot(i);
     140
     141        rc = SSMR3PutU32(pSSM, pFolderMapping? pFolderMapping->cMappings: 0);
    139142        AssertRCReturn(rc, rc);
    140143
    141         rc = SSMR3PutBool(pSSM, FolderMapping[i].fValid);
     144        rc = SSMR3PutBool(pSSM, pFolderMapping? pFolderMapping->fValid: false);
    142145        AssertRCReturn(rc, rc);
    143146
    144         if (FolderMapping[i].fValid)
     147        if (pFolderMapping && pFolderMapping->fValid)
    145148        {
    146149            uint32_t len;
    147150
    148             len = ShflStringSizeOfBuffer(FolderMapping[i].pFolderName);
     151            len = ShflStringSizeOfBuffer(pFolderMapping->pFolderName);
    149152            rc = SSMR3PutU32(pSSM, len);
    150153            AssertRCReturn(rc, rc);
    151154
    152             rc = SSMR3PutMem(pSSM, FolderMapping[i].pFolderName, len);
     155            rc = SSMR3PutMem(pSSM, pFolderMapping->pFolderName, len);
    153156            AssertRCReturn(rc, rc);
    154157
    155             len = ShflStringSizeOfBuffer(FolderMapping[i].pMapName);
     158            len = ShflStringSizeOfBuffer(pFolderMapping->pMapName);
    156159            rc = SSMR3PutU32(pSSM, len);
    157160            AssertRCReturn(rc, rc);
    158161
    159             rc = SSMR3PutMem(pSSM, FolderMapping[i].pMapName, len);
     162            rc = SSMR3PutMem(pSSM, pFolderMapping->pMapName, len);
    160163            AssertRCReturn(rc, rc);
    161164
    162             rc = SSMR3PutBool(pSSM, FolderMapping[i].fHostCaseSensitive);
     165            rc = SSMR3PutBool(pSSM, pFolderMapping->fHostCaseSensitive);
    163166            AssertRCReturn(rc, rc);
    164167
    165             rc = SSMR3PutBool(pSSM, FolderMapping[i].fGuestCaseSensitive);
     168            rc = SSMR3PutBool(pSSM, pFolderMapping->fGuestCaseSensitive);
    166169            AssertRCReturn(rc, rc);
    167170        }
     
    203206    for (int i=0;i<SHFL_MAX_MAPPINGS;i++)
    204207    {
    205         if (FolderMapping[i].pFolderName)
    206         {
    207             LogRel(("SharedFolders host service: loading folder [%ls]\n",
    208                     FolderMapping[i].pFolderName->String.ucs2));
    209         }
    210 
    211         bool fValid;
    212 
     208        /* Load the saved mapping description and try to find it in the mappings. */
     209        MAPPING mapping;
     210        memset (&mapping, 0, sizeof (mapping));
     211       
    213212        /* restore the folder mapping counter. */
    214         rc = SSMR3GetU32(pSSM, &FolderMapping[i].cMappings);
     213        rc = SSMR3GetU32(pSSM, &mapping.cMappings);
    215214        AssertRCReturn(rc, rc);
    216215
    217         rc = SSMR3GetBool(pSSM, &fValid);
     216        rc = SSMR3GetBool(pSSM, &mapping.fValid);
    218217        AssertRCReturn(rc, rc);
    219218
    220         if (fValid != FolderMapping[i].fValid)
    221         {
    222             LogRel(("SharedFolders host service: unexpected saved state %d, should be %d\n",
    223                     fValid, FolderMapping[i].fValid));
    224             return VERR_SSM_UNEXPECTED_DATA;
    225         }
    226 
    227         if (FolderMapping[i].fValid)
    228         {
    229             PSHFLSTRING pName;
    230 
    231             /* Check the host path name. */
    232             rc = SSMR3GetU32(pSSM, &len);
     219        if (mapping.fValid)
     220        {
     221            uint32_t cbFolderName;
     222            PSHFLSTRING pFolderName;
     223
     224            uint32_t cbMapName;
     225            PSHFLSTRING pMapName;
     226
     227            /* Load the host path name. */
     228            rc = SSMR3GetU32(pSSM, &cbFolderName);
    233229            AssertRCReturn(rc, rc);
    234230
    235             if (len != ShflStringSizeOfBuffer(FolderMapping[i].pFolderName))
    236             {
    237                 LogRel(("SharedFolders host service: unexpected saved name length %d, should be %d\n",
    238                         len, ShflStringSizeOfBuffer(FolderMapping[i].pFolderName)));
    239                 return VERR_SSM_UNEXPECTED_DATA;
    240             }
    241 
    242             pName = (PSHFLSTRING)RTMemAlloc(len);
    243             Assert(pName);
    244             if (pName == NULL)
    245                 return VERR_NO_MEMORY;
    246 
    247             rc = SSMR3GetMem(pSSM, pName, len);
     231            pFolderName = (PSHFLSTRING)RTMemAlloc(cbFolderName);
     232            AssertReturn(pFolderName != NULL, VERR_NO_MEMORY);
     233
     234            rc = SSMR3GetMem(pSSM, pFolderName, cbFolderName);
    248235            AssertRCReturn(rc, rc);
    249236
    250             if (memcmp(FolderMapping[i].pFolderName, pName, len))
    251             {
    252                 LogRel(("SharedFolders host service: unexpected saved name\n%.*Rhxd\nshould be\n%.*Rhxd\n",
    253                         len, pName, len, FolderMapping[i].pFolderName));
    254                 RTMemFree(pName);
    255                 return VERR_SSM_UNEXPECTED_DATA;
    256             }
    257             RTMemFree(pName);
    258 
    259             /* Check the map name. */
    260             rc = SSMR3GetU32(pSSM, &len);
     237            /* Load the map name. */
     238            rc = SSMR3GetU32(pSSM, &cbMapName);
    261239            AssertRCReturn(rc, rc);
    262240
    263             if (len != ShflStringSizeOfBuffer(FolderMapping[i].pMapName))
    264             {
    265                 LogRel(("SharedFolders host service: unexpected saved map length %d, should be %d\n",
    266                         len, ShflStringSizeOfBuffer(FolderMapping[i].pMapName)));
    267                 return VERR_SSM_UNEXPECTED_DATA;
    268             }
    269 
    270             pName = (PSHFLSTRING)RTMemAlloc(len);
    271             Assert(pName);
    272             if (pName == NULL)
    273                 return VERR_NO_MEMORY;
    274 
    275             rc = SSMR3GetMem(pSSM, pName, len);
     241            pMapName = (PSHFLSTRING)RTMemAlloc(cbMapName);
     242            AssertReturn(pMapName != NULL, VERR_NO_MEMORY);
     243
     244            rc = SSMR3GetMem(pSSM, pMapName, cbMapName);
    276245            AssertRCReturn(rc, rc);
    277246
    278             if (memcmp(FolderMapping[i].pMapName, pName, len))
    279             {
    280                 LogRel(("SharedFolders host service: unexpected saved map\n%.*Rhxd\nshould be\n%.*Rhxd\n",
    281                         len, pName, len, FolderMapping[i].pMapName));
    282                 RTMemFree(pName);
    283                 return VERR_SSM_UNEXPECTED_DATA;
    284             }
    285             RTMemFree(pName);
    286 
    287             bool fCaseSensitive;
    288 
    289             rc = SSMR3GetBool(pSSM, &fCaseSensitive);
     247            rc = SSMR3GetBool(pSSM, &mapping.fHostCaseSensitive);
    290248            AssertRCReturn(rc, rc);
    291             if (FolderMapping[i].fHostCaseSensitive != fCaseSensitive)
    292             {
    293                 LogRel(("SharedFolders host service: unexpected saved case %d, should be %d\n",
    294                         fCaseSensitive, FolderMapping[i].fHostCaseSensitive));
    295                 return VERR_SSM_UNEXPECTED_DATA;
    296             }
    297 
    298             rc = SSMR3GetBool(pSSM, &FolderMapping[i].fGuestCaseSensitive);
     249
     250            rc = SSMR3GetBool(pSSM, &mapping.fGuestCaseSensitive);
     251            AssertRCReturn(rc, rc);
     252
     253            mapping.pFolderName = pFolderName;
     254            mapping.pMapName = pMapName;
     255
     256            /* 'i' is the root handle of the saved mapping. */
     257            rc = vbsfMappingLoaded (&mapping, i);
     258
     259            RTMemFree(pMapName);
     260            RTMemFree(pFolderName);
     261
    299262            AssertRCReturn(rc, rc);
    300263        }
     
    13531316        rc = vbsfInitHandleTable();
    13541317        AssertRC(rc);
     1318
     1319        vbsfMappingInit();
    13551320    }
    13561321
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