VirtualBox

Changeset 31052 in vbox


Ignore:
Timestamp:
Jul 23, 2010 12:10:41 PM (14 years ago)
Author:
vboxsync
Message:

Shared Folders/AutoMount: Update.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxGuestLib.h

    r31025 r31052  
    527527VBGLR3DECL(int)     VbglR3SharedFolderDisconnect(uint32_t u32ClientId);
    528528VBGLR3DECL(int)     VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool fAutoMountOnly,
    529                                                   PVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cbMappings,
    530                                                   uint32_t *pcMappings);
     529                                                  PVBGLR3SHAREDFOLDERMAPPING *ppaMappings, uint32_t *pcMappings);
     530VBGLR3DECL(void)    VbglR3SharedFolderFreeMappings(PVBGLR3SHAREDFOLDERMAPPING paMappings);
    531531VBGLR3DECL(int)     VbglR3SharedFolderGetName(uint32_t  u32ClientId,uint32_t u32Root, char **ppszName);
    532532/** @}  */
  • trunk/include/VBox/shflsvc.h

    r31002 r31052  
    379379    SHFLROOT root;
    380380} SHFLMAPPING;
    381 
     381/** Pointer to a SHFLMAPPING structure. */
    382382typedef SHFLMAPPING *PSHFLMAPPING;
    383383
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxSharedFolders.cpp

    r31027 r31052  
    2525int VBoxSharedFoldersAutoMount(void)
    2626{
     27#if 0
    2728    uint32_t u32ClientId;
    2829    int rc = VbglR3SharedFolderConnect(&u32ClientId);
     
    9798    }
    9899    return rc;
     100#endif
     101    return 0;
    99102}
    100103
  • trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp

    r31041 r31052  
    12741274    bool usageOK = true;
    12751275    bool fOnlyShowAutoMount = false;
    1276     if (   argc == 1
    1277         && (   RTStrICmp(argv[0], "-automount") == 0
     1276    if (argc == 1)
     1277    {
     1278        if (   RTStrICmp(argv[0], "-automount") == 0
    12781279            || RTStrICmp(argv[0], "/automount") == 0)
    1279        )
    1280     {
    1281         fOnlyShowAutoMount = true;
     1280        {
     1281            fOnlyShowAutoMount = true;
     1282        }
     1283        else
     1284            usageOK = false;
    12821285    }
    12831286    else if (argc > 1)
     
    12961299    else
    12971300    {
    1298         uint32_t cMappings = 64; /* See shflsvc.h for define; should be used later. */
    1299         uint32_t cbMappings = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
    1300         VBGLR3SHAREDFOLDERMAPPING *paMappings = (PVBGLR3SHAREDFOLDERMAPPING)RTMemAlloc(cbMappings);
    1301 
    1302         if (paMappings)
    1303         {
    1304             rc = VbglR3SharedFolderGetMappings(u32ClientId, fOnlyShowAutoMount,
    1305                                                paMappings, cbMappings,
    1306                                                &cMappings);
    1307             if (RT_SUCCESS(rc))
     1301        PVBGLR3SHAREDFOLDERMAPPING paMappings;
     1302        uint32_t cMappings;
     1303        rc = VbglR3SharedFolderGetMappings(u32ClientId, fOnlyShowAutoMount,
     1304                                           &paMappings, &cMappings);
     1305        if (RT_SUCCESS(rc))
     1306        {
     1307            if (fOnlyShowAutoMount)
     1308                RTPrintf("Auto-mounted Shared Folder mappings (%u):\n\n", cMappings);
     1309            else
     1310                RTPrintf("Shared Folder mappings (%u):\n\n", cMappings);
     1311
     1312            for (uint32_t i = 0; i < cMappings; i++)
    13081313            {
    1309                 /* Maximum mappings, see shflsvc.h */
    1310                 if (cMappings > 64)
    1311                     cMappings = 64;
    1312                 RTPrintf("Shared Folder Mappings (%u):\n\n", cMappings);
    1313                 for (uint32_t i = 0; i < cMappings; i++)
     1314                char *pszName;
     1315                rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszName);
     1316                if (RT_SUCCESS(rc))
    13141317                {
    1315                     char *pszName;
    1316                     rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszName);
    1317                     if (RT_SUCCESS(rc))
    1318                     {
    1319                         RTPrintf("%02u - %s\n", i + 1, pszName);
    1320                         RTStrFree(pszName);
    1321                     }
    1322                     else
    1323                         VBoxControlError("Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
    1324                                          paMappings[i].u32Root, rc);
     1318                    RTPrintf("%02u - %s\n", i + 1, pszName);
     1319                    RTStrFree(pszName);
    13251320                }
    1326                 if (cMappings == 0)
    1327                     RTPrintf("No Shared Folders available.\n");
     1321                else
     1322                    VBoxControlError("Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
     1323                                     paMappings[i].u32Root, rc);
    13281324            }
    1329             else
    1330                 VBoxControlError("Error while getting the shared folder mappings, rc = %Rrc\n", rc);
    1331             RTMemFree(paMappings);
     1325            if (cMappings == 0)
     1326                RTPrintf("No Shared Folders available.\n");
     1327            VbglR3SharedFolderFreeMappings(paMappings);
    13321328        }
    13331329        else
    1334             rc = VERR_NO_MEMORY;
     1330            VBoxControlError("Error while getting the shared folder mappings, rc = %Rrc\n", rc);
    13351331        VbglR3SharedFolderDisconnect(u32ClientId);
    13361332    }
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibSharedFolders.cpp

    r31025 r31052  
    9090 *
    9191 * @returns VBox status code.
    92  * @param   u32ClientId     The client id returned by VbglR3InvsSvcConnect().
     92 * @param   u32ClientId     The client id returned by VbglR3SharedFolderConnect().
    9393 * @param   fAutoMountOnly  Flag whether only auto-mounted shared folders
    9494 *                          should be reported.
    95  * @param   paMappings      Pointer to a preallocated array which will retrieve the mapping info.
    96  * @param   cbMappings      Size (in bytes) of the provided array.
    97  * @param   pcMappings      On input, the size of @a paMappings gives as an
    98  *                          item count.  On output, the number of mappings
    99  *                          returned in @a paMappings.
    100  *
    101  * @todo    r=bird: cbMappings and @a *pcMappings overlap.  The better API
    102  *          would be to change cbMappings to cMappings (the entries are fixed
    103  *          sized) and move the move the input aspect of @a *pcMappings to it.
    104  *
    105  *          However, it would be better if this function would do the array
    106  *          allocation.  This way you could deal with too-much-data conditions
    107  *          here (or hide the max-number-of-shared-folders-per-vm-define).
    108  *          Then paMappings would become ppaMappings and cbMappings could be
    109  *          removed altogether. *pcMappings would only be output.  A
    110  *          corresponding VbglR3SharedFolderFreeMappings would be required for
    111  *          a 100% clean API (this is an (/going to be) offical API for C/C++
    112  *          programs).
     95 * @param   ppaMappings     Allocated array which will retrieve the mapping info.  Needs
     96 *                          to be freed with VbglR3SharedFolderFreeMappings() later.
     97 * @param   pcMappings      The number of mappings returned in @a ppaMappings.
    11398 */
    11499VBGLR3DECL(int) VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool fAutoMountOnly,
    115                                               PVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cbMappings,
    116                                               uint32_t *pcMappings)
     100                                              PVBGLR3SHAREDFOLDERMAPPING *ppaMappings, uint32_t *pcMappings)
    117101{
    118102    AssertPtr(pcMappings);
     
    131115    VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
    132116
    133     /* Init the rest of the message. */
    134     VbglHGCMParmUInt32Set(&Msg.numberOfMappings, *pcMappings);
    135     VbglHGCMParmPtrSet(&Msg.mappings, &paMappings[0], cbMappings);
    136 
    137     int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    138     if (RT_SUCCESS(rc))
     117    /*
     118     * Prepare and get the actual mappings from the host service.
     119     */
     120    int rc = VINF_SUCCESS;
     121    uint32_t cMappings = 8; /* Should be a good default value. */
     122    uint32_t cbSize = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
     123    VBGLR3SHAREDFOLDERMAPPING *ppaMappingsTemp = (PVBGLR3SHAREDFOLDERMAPPING)RTMemAllocZ(cbSize);
     124    if (ppaMappingsTemp == NULL)
     125        rc = VERR_NO_MEMORY;
     126
     127    *pcMappings = 0;
     128    do
    139129    {
    140         VbglHGCMParmUInt32Get(&Msg.numberOfMappings, pcMappings);
    141         rc = Msg.callInfo.result;
    142     }
    143     return rc;
     130        VbglHGCMParmUInt32Set(&Msg.numberOfMappings, cMappings);
     131        VbglHGCMParmPtrSet(&Msg.mappings, ppaMappingsTemp, cbSize);
     132
     133        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     134        if (RT_SUCCESS(rc))
     135        {
     136            rc = Msg.callInfo.result;
     137            if (RT_SUCCESS(rc))
     138            {
     139                VbglHGCMParmUInt32Get(&Msg.numberOfMappings, pcMappings);
     140
     141                /* Do we have more mappings than we have allocated space for? */
     142                if (rc == VINF_BUFFER_OVERFLOW)
     143                {
     144                    cMappings = *pcMappings;
     145                    cbSize = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
     146                    void *pvNew = RTMemRealloc(ppaMappingsTemp, cbSize);
     147                    AssertPtrBreakStmt(pvNew, rc = VERR_NO_MEMORY);
     148                    ppaMappingsTemp = (PVBGLR3SHAREDFOLDERMAPPING)pvNew;
     149                }
     150                else
     151                    *ppaMappings = ppaMappingsTemp;
     152            }
     153        }
     154    } while (rc == VINF_BUFFER_OVERFLOW);
     155
     156    if (RT_FAILURE(rc) && ppaMappingsTemp)
     157        RTMemFree(ppaMappingsTemp);
     158
     159    return rc;
     160}
     161
     162
     163/**
     164 * Frees the shared folder mappings allocated by
     165 * VbglR3SharedFolderGetMappings() before.
     166 *
     167 * @param   paMappings     What
     168 */
     169VBGLR3DECL(void) VbglR3SharedFolderFreeMappings(PVBGLR3SHAREDFOLDERMAPPING paMappings)
     170{
     171    RTMemFree(paMappings);
    144172}
    145173
     
    179207        if (RT_SUCCESS(rc))
    180208        {
    181             *ppszName = NULL;
    182             rc = RTUtf16ToUtf8(&pString->String.ucs2[0], ppszName);
     209            rc = Msg.callInfo.result;
    183210            if (RT_SUCCESS(rc))
    184                 rc = Msg.callInfo.result; /** @todo r=bird: Shouldn't you check this *before* doing the conversion? */
     211            {
     212                *ppszName = NULL;
     213                rc = RTUtf16ToUtf8(&pString->String.ucs2[0], ppszName);
     214            }
    185215        }
    186216        RTMemFree(pString);
  • trunk/src/VBox/HostServices/SharedFolders/mappings.cpp

    r31002 r31052  
    3737}
    3838
    39 int vbsfMappingLoaded (const MAPPING *pLoadedMapping, SHFLROOT root)
     39int vbsfMappingLoaded(const PMAPPING pLoadedMapping, SHFLROOT root)
    4040{
    4141    /* Mapping loaded from the saved state with the index. Which means
     
    173173 * We are always executed from one specific HGCM thread. So thread safe.
    174174 */
    175 int vbsfMappingsAdd (PSHFLSTRING pFolderName, PSHFLSTRING pMapName,
    176                      uint32_t    fWritable,   uint32_t    fAutoMount)
     175int vbsfMappingsAdd(PSHFLSTRING pFolderName, PSHFLSTRING pMapName,
     176                    uint32_t fWritable, uint32_t fAutoMount)
    177177{
    178178    unsigned i;
     
    255255}
    256256
    257 int vbsfMappingsRemove (PSHFLSTRING pMapName)
     257int vbsfMappingsRemove(PSHFLSTRING pMapName)
    258258{
    259259    unsigned i;
     
    294294}
    295295
    296 PCRTUTF16 vbsfMappingsQueryHostRoot (SHFLROOT root, uint32_t *pcbRoot)
     296PCRTUTF16 vbsfMappingsQueryHostRoot(SHFLROOT root, uint32_t *pcbRoot)
    297297{
    298298    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     
    307307}
    308308
    309 bool vbsfIsGuestMappingCaseSensitive (SHFLROOT root)
     309bool vbsfIsGuestMappingCaseSensitive(SHFLROOT root)
    310310{
    311311    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     
    319319}
    320320
    321 bool vbsfIsHostMappingCaseSensitive (SHFLROOT root)
     321bool vbsfIsHostMappingCaseSensitive(SHFLROOT root)
    322322{
    323323    MAPPING *pFolderMapping = vbsfMappingGetByRoot(root);
     
    331331}
    332332
    333 int vbsfMappingsQuery (SHFLCLIENTDATA *pClient, SHFLMAPPING *pMappings, uint32_t *pcMappings)
     333/**
     334 * Note: If pMappings/*pcMappings is smaller than the actual amount of mappings
     335 *       that *could* have been returned *pcMappings contains the required buffer size
     336 *       so that the caller can retry the operation if wanted.
     337 */
     338int vbsfMappingsQuery(PSHFLCLIENTDATA pClient, PSHFLMAPPING pMappings, uint32_t *pcMappings)
    334339{
    335340    int rc = VINF_SUCCESS;
    336     uint32_t cMaxMappings = RT_MIN(*pcMappings, SHFL_MAX_MAPPINGS);
     341
     342    uint32_t cMappings = 0; /* Will contain actual valid mappings. */
     343    uint32_t idx = 0;       /* Current index in mappings buffer. */
    337344
    338345    LogFlow(("vbsfMappingsQuery: pClient = %p, pMappings = %p, pcMappings = %p, *pcMappings = %d\n",
    339346             pClient, pMappings, pcMappings, *pcMappings));
    340347
    341     *pcMappings = 0;
    342     for (uint32_t i=0;i<cMaxMappings;i++)
     348    for (uint32_t i = 0; i < SHFL_MAX_MAPPINGS; i++)
    343349    {
    344350        MAPPING *pFolderMapping = vbsfMappingGetByRoot(i);
     
    346352            && pFolderMapping->fValid == true)
    347353        {
    348             /* Skip mappings which are not marked for auto-mounting if
    349              * the SHFL_MF_AUTOMOUNT flag ist set. */
    350             if (   (pClient->fu32Flags & SHFL_MF_AUTOMOUNT)
    351                 && !pFolderMapping->fAutoMount)
    352                 continue;
    353 
    354             pMappings[*pcMappings].u32Status = SHFL_MS_NEW;
    355             pMappings[*pcMappings].root = i;
    356             *pcMappings = *pcMappings + 1;
    357         }
    358     }
     354            if (idx < *pcMappings)
     355            {
     356                /* Skip mappings which are not marked for auto-mounting if
     357                 * the SHFL_MF_AUTOMOUNT flag ist set. */
     358                if (   (pClient->fu32Flags & SHFL_MF_AUTOMOUNT)
     359                    && !pFolderMapping->fAutoMount)
     360                    continue;
     361
     362                pMappings[idx].u32Status = SHFL_MS_NEW;
     363                pMappings[idx].root = i;
     364                idx++;
     365            }
     366            cMappings++;
     367        }
     368    }
     369
     370    /* Return actual number of mappings, regardless whether the handed in
     371     * mapping buffer was big enough. */
     372    *pcMappings = cMappings;
     373
    359374    LogFlow(("vbsfMappingsQuery: return rc = %Rrc\n", rc));
    360375    return rc;
    361376}
    362377
    363 int vbsfMappingsQueryName (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pString)
     378int vbsfMappingsQueryName(PSHFLCLIENTDATA pClient, SHFLROOT root, SHFLSTRING *pString)
    364379{
    365380    int rc = VINF_SUCCESS;
     
    394409}
    395410
    396 int vbsfMappingsQueryWritable (SHFLCLIENTDATA *pClient, SHFLROOT root, bool *fWritable)
     411int vbsfMappingsQueryWritable(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fWritable)
    397412{
    398413    int rc = VINF_SUCCESS;
     
    417432}
    418433
    419 int vbsfMappingsQueryAutoMount (SHFLCLIENTDATA *pClient, SHFLROOT root, bool *fAutoMount)
     434int vbsfMappingsQueryAutoMount(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fAutoMount)
    420435{
    421436    int rc = VINF_SUCCESS;
     
    440455}
    441456
    442 int vbsfMapFolder (SHFLCLIENTDATA *pClient, PSHFLSTRING pszMapName, RTUTF16 delimiter, bool fCaseSensitive, SHFLROOT *pRoot)
     457int vbsfMapFolder(PSHFLCLIENTDATA pClient, PSHFLSTRING pszMapName,
     458                  RTUTF16 delimiter, bool fCaseSensitive, SHFLROOT *pRoot)
    443459{
    444460    MAPPING *pFolderMapping = NULL;
     
    490506}
    491507
    492 int vbsfUnmapFolder (SHFLCLIENTDATA *pClient, SHFLROOT root)
     508int vbsfUnmapFolder(PSHFLCLIENTDATA pClient, SHFLROOT root)
    493509{
    494510    int rc = VINF_SUCCESS;
  • trunk/src/VBox/HostServices/SharedFolders/mappings.h

    r31002 r31052  
    3131    bool        fWritable;
    3232    bool        fAutoMount;
    33 } MAPPING, *PMAPPING;
     33} MAPPING;
     34/** Pointer to a MAPPING structure. */
     35typedef MAPPING *PMAPPING;
    3436
    3537void vbsfMappingInit(void);
     
    4042int vbsfMappingsRemove(PSHFLSTRING pMapName);
    4143
    42 int vbsfMappingsQuery(SHFLCLIENTDATA *pClient, SHFLMAPPING *pMappings, uint32_t *pcMappings);
    43 int vbsfMappingsQueryName(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pString);
    44 int vbsfMappingsQueryWritable(SHFLCLIENTDATA *pClient, SHFLROOT root, bool *fWritable);
     44int vbsfMappingsQuery(PSHFLCLIENTDATA pClient, PSHFLMAPPING pMappings, uint32_t *pcMappings);
     45int vbsfMappingsQueryName(PSHFLCLIENTDATA pClient, SHFLROOT root, SHFLSTRING *pString);
     46int vbsfMappingsQueryWritable(PSHFLCLIENTDATA pClient, SHFLROOT root, bool *fWritable);
    4547
    46 int vbsfMapFolder(SHFLCLIENTDATA *pClient, PSHFLSTRING pszMapName, RTUTF16 delimiter, bool fCaseSensitive, SHFLROOT *pRoot);
    47 int vbsfUnmapFolder(SHFLCLIENTDATA *pClient, SHFLROOT root);
     48int vbsfMapFolder(PSHFLCLIENTDATA pClient, PSHFLSTRING pszMapName, RTUTF16 delimiter, bool fCaseSensitive, SHFLROOT *pRoot);
     49int vbsfUnmapFolder(PSHFLCLIENTDATA pClient, SHFLROOT root);
    4850
    49 PCRTUTF16 vbsfMappingsQueryHostRoot (SHFLROOT root, uint32_t *pcbRoot);
    50 bool vbsfIsGuestMappingCaseSensitive (SHFLROOT root);
    51 bool vbsfIsHostMappingCaseSensitive (SHFLROOT root);
     51PCRTUTF16 vbsfMappingsQueryHostRoot(SHFLROOT root, uint32_t *pcbRoot);
     52bool vbsfIsGuestMappingCaseSensitive(SHFLROOT root);
     53bool vbsfIsHostMappingCaseSensitive(SHFLROOT root);
    5254
    53 int vbsfMappingLoaded (const MAPPING *pLoadedMapping, SHFLROOT root);
    54 MAPPING *vbsfMappingGetByRoot(SHFLROOT root);
     55int vbsfMappingLoaded(const PMAPPING pLoadedMapping, SHFLROOT root);
     56PMAPPING vbsfMappingGetByRoot(SHFLROOT root);
    5557
    5658#endif /* !___MAPPINGS_H */
  • trunk/src/VBox/HostServices/SharedFolders/service.cpp

    r31002 r31052  
    44
    55/*
    6  * Copyright (C) 2006-2007 Oracle Corporation
     6 * Copyright (C) 2006-2010 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    327327                    if (RT_SUCCESS(rc))
    328328                    {
     329                        /* Report that there are more mappings to get if
     330                         * handed in buffer is too small. */
     331                        if (paParms[1].u.uint32 < cMappings)
     332                            rc = VINF_BUFFER_OVERFLOW;
     333
    329334                        /* Update parameters. */
    330335                        paParms[1].u.uint32 = cMappings;
  • trunk/src/VBox/HostServices/SharedFolders/shfl.h

    r28800 r31052  
    44
    55/*
    6  * Copyright (C) 2006-2007 Oracle Corporation
     6 * Copyright (C) 2006-2010 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4646    /** Client flags */
    4747    uint32_t fu32Flags;
    48 
     48    /** Path delimiter. */
    4949    RTUTF16  PathDelimiter;
    5050} SHFLCLIENTDATA;
    51 
     51/** Pointer to a SHFLCLIENTDATA structure. */
     52typedef SHFLCLIENTDATA *PSHFLCLIENTDATA;
    5253
    5354#endif /* !___SHFL_H */
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