VirtualBox

Changeset 31025 in vbox


Ignore:
Timestamp:
Jul 22, 2010 11:43:25 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63945
Message:

Quick VbglR3SharedFolder* api review.

Location:
trunk
Files:
3 edited

Legend:

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

    r31002 r31025  
    514514 * Structure containing mapping information for a shared folder.
    515515 */
    516 struct VBGLR3SHAREDFOLDERMAPPING
     516typedef struct VBGLR3SHAREDFOLDERMAPPING
    517517{
    518518    /** Mapping status. */
     
    520520    /** Root handle. */
    521521    uint32_t u32Root;
    522 };
     522} VBGLR3SHAREDFOLDERMAPPING;
     523/** Pointer to a shared folder mapping information struct. */
    523524typedef VBGLR3SHAREDFOLDERMAPPING *PVBGLR3SHAREDFOLDERMAPPING;
    524 /** @todo Docs. */
     525
    525526VBGLR3DECL(int)     VbglR3SharedFolderConnect(uint32_t *pu32ClientId);
    526527VBGLR3DECL(int)     VbglR3SharedFolderDisconnect(uint32_t u32ClientId);
    527 VBGLR3DECL(int)     VbglR3SharedFolderGetMappings(uint32_t                   u32ClientId,  bool      bAutoMountOnly,
    528                                                   VBGLR3SHAREDFOLDERMAPPING  paMappings[], uint32_t  cbMappings,
    529                                                   uint32_t                  *pcMapCount);
    530 VBGLR3DECL(int)     VbglR3SharedFolderGetName(uint32_t   u32ClientId,uint32_t  u32Root,
    531                                               char     **ppszName,   uint32_t *pcbLen);
     528VBGLR3DECL(int)     VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool fAutoMountOnly,
     529                                                  PVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cbMappings,
     530                                                  uint32_t *pcMappings);
     531VBGLR3DECL(int)     VbglR3SharedFolderGetName(uint32_t  u32ClientId,uint32_t u32Root, char **ppszName);
    532532/** @}  */
    533533# endif /* VBOX_WITH_SHARED_FOLDERS defined */
  • trunk/src/VBox/Additions/common/VBoxControl/VBoxControl.cpp

    r31002 r31025  
    12981298        uint32_t cMappings = 64; /* See shflsvc.h for define; should be used later. */
    12991299        uint32_t cbMappings = cMappings * sizeof(VBGLR3SHAREDFOLDERMAPPING);
    1300         VBGLR3SHAREDFOLDERMAPPING *pMappings = (VBGLR3SHAREDFOLDERMAPPING*)RTMemAlloc(cbMappings);
    1301 
    1302         if (pMappings)
     1300        VBGLR3SHAREDFOLDERMAPPING *paMappings = (PVBGLR3SHAREDFOLDERMAPPING)RTMemAlloc(cbMappings);
     1301
     1302        if (paMappings)
    13031303        {
    13041304            rc = VbglR3SharedFolderGetMappings(u32ClientId, fOnlyShowAutoMount,
    1305                                                pMappings, cbMappings,
     1305                                               paMappings, cbMappings,
    13061306                                               &cMappings);
    13071307            if (RT_SUCCESS(rc))
     
    13111311                for (uint32_t i = 0; i < cMappings; i++)
    13121312                {
    1313                     char *ppszName = NULL;
    1314                     uint32_t pcbLen = 0;
    1315                     rc = VbglR3SharedFolderGetName(u32ClientId, pMappings[i].u32Root,
    1316                                                    &ppszName, &pcbLen);
     1313                    char *pszName;
     1314                    rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszName);
    13171315                    if (RT_SUCCESS(rc))
    13181316                    {
    1319                         RTPrintf("%02u - %s\n", i + 1, ppszName);
    1320                         RTStrFree(ppszName);
     1317                        RTPrintf("%02u - %s\n", i + 1, pszName);
     1318                        RTStrFree(pszName);
    13211319                    }
    13221320                    else
    13231321                        VBoxControlError("Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
    1324                                          pMappings[i].u32Root, rc);
     1322                                         paMappings[i].u32Root, rc);
    13251323                }
    13261324                if (cMappings == 0)
     
    13291327            else
    13301328                VBoxControlError("Error while getting the shared folder mappings, rc = %Rrc\n", rc);
    1331             RTMemFree(pMappings);
     1329            RTMemFree(paMappings);
    13321330        }
    13331331        else
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibSharedFolders.cpp

    r31013 r31025  
    3838
    3939#include "VBGLR3Internal.h"
     40
    4041
    4142/**
     
    9091 * @returns VBox status code.
    9192 * @param   u32ClientId     The client id returned by VbglR3InvsSvcConnect().
    92  * @param   bAutoMountOnly  Flag whether only auto-mounted shared folders should be reported.
     93 * @param   fAutoMountOnly  Flag whether only auto-mounted shared folders
     94 *                          should be reported.
    9395 * @param   paMappings      Pointer to a preallocated array which will retrieve the mapping info.
    9496 * @param   cbMappings      Size (in bytes) of the provided array.
    95  * @param   pcMapCount      Number of mappings returned.
     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).
    96113 */
    97 VBGLR3DECL(int) VbglR3SharedFolderGetMappings(uint32_t                   u32ClientId,  bool      bAutoMountOnly,
    98                                               VBGLR3SHAREDFOLDERMAPPING  paMappings[], uint32_t cbMappings,
    99                                               uint32_t                  *pcMapCount)
     114VBGLR3DECL(int) VbglR3SharedFolderGetMappings(uint32_t u32ClientId, bool fAutoMountOnly,
     115                                              PVBGLR3SHAREDFOLDERMAPPING paMappings, uint32_t cbMappings,
     116                                              uint32_t *pcMappings)
    100117{
    101     int rc;
    102 
    103     AssertPtr(pcMapCount);
     118    AssertPtr(pcMappings);
    104119
    105120    VBoxSFQueryMappings Msg;
     
    111126
    112127    /* Set the mapping flags. */
    113     uint32_t u32Flags = 0; /* @todo SHFL_MF_UTF8 is not implemented yet. */
    114     if (bAutoMountOnly) /* We only want the mappings which get auto-mounted. */
     128    uint32_t u32Flags = 0; /** @todo SHFL_MF_UTF8 is not implemented yet. */
     129    if (fAutoMountOnly) /* We only want the mappings which get auto-mounted. */
    115130        u32Flags |= SHFL_MF_AUTOMOUNT;
    116131    VbglHGCMParmUInt32Set(&Msg.flags, u32Flags);
    117132
    118133    /* Init the rest of the message. */
    119     VbglHGCMParmUInt32Set(&Msg.numberOfMappings, *pcMapCount);
     134    VbglHGCMParmUInt32Set(&Msg.numberOfMappings, *pcMappings);
    120135    VbglHGCMParmPtrSet(&Msg.mappings, &paMappings[0], cbMappings);
    121136
    122     rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
     137    int rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    123138    if (RT_SUCCESS(rc))
    124139    {
    125         VbglHGCMParmUInt32Get(&Msg.numberOfMappings, pcMapCount);
     140        VbglHGCMParmUInt32Get(&Msg.numberOfMappings, pcMappings);
    126141        rc = Msg.callInfo.result;
    127142    }
     
    136151 * @param   u32ClientId     The client id returned by VbglR3InvsSvcConnect().
    137152 * @param   u32Root         Root ID of shared folder to get the name for.
    138  * @param   ppszName        Name of the shared folder.
    139  * @param   pcbLen          Length (in bytes) of shared folder name.
     153 * @param   ppszName        Where to return the name string.  This shall be
     154 *                          freed by calling RTStrFree.
    140155 */
    141 VBGLR3DECL(int) VbglR3SharedFolderGetName(uint32_t   u32ClientId, uint32_t  u32Root,
    142                                           char     **ppszName,    uint32_t *pcbLen)
     156VBGLR3DECL(int) VbglR3SharedFolderGetName(uint32_t u32ClientId, uint32_t u32Root, char **ppszName)
    143157{
    144     int rc;
    145 
    146158    AssertPtr(ppszName);
    147     AssertPtr(pcbLen);
    148159
    149160    VBoxSFQueryMapName Msg;
     
    154165    Msg.callInfo.cParms = 2;
    155166
    156     uint32_t cbString = sizeof(SHFLSTRING) + SHFL_MAX_LEN;
     167    int         rc;
     168    uint32_t    cbString = sizeof(SHFLSTRING) + SHFL_MAX_LEN;
    157169    PSHFLSTRING pString = (PSHFLSTRING)RTMemAlloc(cbString);
    158170    if (pString)
     
    168180        {
    169181            *ppszName = NULL;
    170             rc = RTUtf16ToUtf8Ex((PCRTUTF16)&pString->String.ucs2, RTSTR_MAX,
    171                                  ppszName, (size_t)pcbLen, NULL);
     182            rc = RTUtf16ToUtf8(&pString->String.ucs2[0], ppszName);
    172183            if (RT_SUCCESS(rc))
    173                 rc = Msg.callInfo.result;
     184                rc = Msg.callInfo.result; /** @todo r=bird: Shouldn't you check this *before* doing the conversion? */
    174185        }
    175186        RTMemFree(pString);
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