VirtualBox

Ignore:
Timestamp:
Dec 13, 2011 10:09:12 AM (13 years ago)
Author:
vboxsync
Message:

HostServices/SharedFolders: spaces

File:
1 edited

Legend:

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

    r39586 r39594  
    55
    66/*
    7  * Copyright (C) 2006-2007 Oracle Corporation
     7 * Copyright (C) 2006-2011 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    5151 */
    5252
    53 void vbsfStripLastComponent (char *pszFullPath, uint32_t cbFullPathRoot)
     53void vbsfStripLastComponent(char *pszFullPath, uint32_t cbFullPathRoot)
    5454{
    5555    RTUNICP cp;
     
    8181        }
    8282
    83         s = RTStrNextCp (s);
     83        s = RTStrNextCp(s);
    8484    }
    8585
     
    139139    strcat(pDirEntry->szName, szWildCard);
    140140
    141     rc = RTDirOpenFiltered (&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT);
     141    rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT);
    142142    *(pszStartComponent-1) = RTPATH_DELIMITER;
    143143    if (RT_FAILURE(rc))
     
    248248}
    249249
    250 static int vbsfBuildFullPath (SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING pPath,
    251                               uint32_t cbPath, char **ppszFullPath, uint32_t *pcbFullPathRoot,
    252                               bool fWildCard = false, bool fPreserveLastComponent = false)
     250static int vbsfBuildFullPath(SHFLCLIENTDATA *pClient, SHFLROOT root, PSHFLSTRING pPath,
     251                             uint32_t cbPath, char **ppszFullPath, uint32_t *pcbFullPathRoot,
     252                             bool fWildCard = false, bool fPreserveLastComponent = false)
    253253{
    254254    int rc = VINF_SUCCESS;
     
    258258    /* Query UCS2 root prefix for the path, cbRoot is the length in bytes including trailing (RTUTF16)0. */
    259259    uint32_t cbRoot = 0;
    260     PCRTUTF16 pwszRoot = vbsfMappingsQueryHostRoot (root, &cbRoot);
     260    PCRTUTF16 pwszRoot = vbsfMappingsQueryHostRoot(root, &cbRoot);
    261261
    262262    if (!pwszRoot || cbRoot == 0)
     
    273273        rc = vbsfPathCheck((const char *)&pPath->String.utf8[0], pPath->u16Length);
    274274
    275         if (RT_SUCCESS (rc))
    276         {
    277             rc = RTUtf16ToUtf8 (pwszRoot, &utf8Root);
    278         }
    279 
    280         if (RT_SUCCESS (rc))
     275        if (RT_SUCCESS(rc))
     276        {
     277            rc = RTUtf16ToUtf8(pwszRoot, &utf8Root);
     278        }
     279
     280        if (RT_SUCCESS(rc))
    281281        {
    282282            size_t cbUtf8Root, cbUtf8FullPath;
    283283            char *utf8FullPath;
    284284
    285             cbUtf8Root = strlen (utf8Root);
     285            cbUtf8Root = strlen(utf8Root);
    286286            cbUtf8FullPath = cbUtf8Root + 1 + pPath->u16Length + 1;
    287             utf8FullPath = (char *) RTMemAllocZ (cbUtf8FullPath);
     287            utf8FullPath = (char *) RTMemAllocZ(cbUtf8FullPath);
    288288
    289289            if (!utf8FullPath)
     
    295295            else
    296296            {
    297                 memcpy (utf8FullPath, utf8Root, cbUtf8Root);
    298                 memcpy (utf8FullPath + cbUtf8Root + 1,
    299                         &pPath->String.utf8[0],
    300                         pPath->u16Length);
     297                memcpy(utf8FullPath, utf8Root, cbUtf8Root);
     298                memcpy(utf8FullPath + cbUtf8Root + 1,
     299                       &pPath->String.utf8[0],
     300                       pPath->u16Length);
    301301
    302302                utf8FullPath[cbUtf8Root] = '/';
     
    308308            }
    309309
    310             RTStrFree (utf8Root);
     310            RTStrFree(utf8Root);
    311311        }
    312312        else
    313313        {
    314             Log (("vbsfBuildFullPath: RTUtf16ToUtf8 failed with %Rrc\n", rc));
     314            Log(("vbsfBuildFullPath: RTUtf16ToUtf8 failed with %Rrc\n", rc));
    315315        }
    316316    }
     
    329329        // Is 8 times length enough for decomposed in worst case...?
    330330        cbPathLength = sizeof(SHFLSTRING) + pPathParameter->u16Length * 8 + 2;
    331         pPath = (SHFLSTRING *)RTMemAllocZ (cbPathLength);
     331        pPath = (SHFLSTRING *)RTMemAllocZ(cbPathLength);
    332332        if (!pPath)
    333333        {
     
    358358         * in worst case.
    359359         */
    360         uint32_t cbFullPath = (cbRoot/sizeof (RTUTF16) + ShflStringLength (pPath)) * 4;
    361 
    362         pszFullPath = (char *)RTMemAllocZ (cbFullPath);
     360        uint32_t cbFullPath = (cbRoot/sizeof(RTUTF16) + ShflStringLength(pPath)) * 4;
     361
     362        pszFullPath = (char *)RTMemAllocZ(cbFullPath);
    363363
    364364        if (!pszFullPath)
     
    370370            uint32_t cb = cbFullPath;
    371371
    372             rc = RTUtf16ToUtf8Ex (pwszRoot, RTSTR_MAX, &pszFullPath, cb, NULL);
     372            rc = RTUtf16ToUtf8Ex(pwszRoot, RTSTR_MAX, &pszFullPath, cb, NULL);
    373373            if (RT_FAILURE(rc))
    374374            {
     
    417417                    src++;  /* we already appended a delimiter to the first part */
    418418
    419                 rc = RTUtf16ToUtf8Ex (src, RTSTR_MAX, &dst, cb, NULL);
     419                rc = RTUtf16ToUtf8Ex(src, RTSTR_MAX, &dst, cb, NULL);
    420420                if (RT_FAILURE(rc))
    421421                {
     
    428428                }
    429429
    430                 uint32_t l = (uint32_t)strlen (dst);
     430                uint32_t l = (uint32_t)strlen(dst);
    431431
    432432                /* Verify that the path is under the root directory. */
     
    457457    }
    458458
    459     if (RT_SUCCESS (rc))
     459    if (RT_SUCCESS(rc))
    460460    {
    461461        /* When the host file system is case sensitive and the guest expects a case insensitive fs, then problems can occur */
    462         if (     vbsfIsHostMappingCaseSensitive (root)
     462        if (     vbsfIsHostMappingCaseSensitive(root)
    463463            &&  !vbsfIsGuestMappingCaseSensitive(root))
    464464        {
     
    600600}
    601601
    602 static void vbsfFreeFullPath (char *pszFullPath)
    603 {
    604     RTMemFree (pszFullPath);
     602static void vbsfFreeFullPath(char *pszFullPath)
     603{
     604    RTMemFree(pszFullPath);
    605605}
    606606
     
    845845 * @retval pParms->Info          On success the parameters of the file opened or created
    846846 */
    847 static int vbsfOpenFile (SHFLCLIENTDATA *pClient, const char *pszPath, SHFLCREATEPARMS *pParms)
     847static int vbsfOpenFile(SHFLCLIENTDATA *pClient, const char *pszPath, SHFLCREATEPARMS *pParms)
    848848{
    849849    LogFlow(("vbsfOpenFile: pszPath = %s, pParms = %p\n", pszPath, pParms));
     
    871871        rc = RTFileOpen(&pHandle->file.Handle, pszPath, fOpen);
    872872    }
    873     if (RT_FAILURE (rc))
     873    if (RT_FAILURE(rc))
    874874    {
    875875        switch (rc)
     
    968968
    969969        /* Get file information */
    970         rc = RTFileQueryInfo (pHandle->file.Handle, &info, RTFSOBJATTRADD_NOTHING);
     970        rc = RTFileQueryInfo(pHandle->file.Handle, &info, RTFSOBJATTRADD_NOTHING);
    971971        if (RT_SUCCESS(rc))
    972972        {
     
    10451045            pParms->Result = SHFL_FILE_CREATED;
    10461046            rc = RTDirCreate(pszPath, fMode);
    1047             if (RT_FAILURE (rc))
     1047            if (RT_FAILURE(rc))
    10481048            {
    10491049                switch (rc)
     
    10641064        {
    10651065            /* Open the directory now */
    1066             rc = RTDirOpen (&pHandle->dir.Handle, pszPath);
     1066            rc = RTDirOpen(&pHandle->dir.Handle, pszPath);
    10671067            if (RT_SUCCESS(rc))
    10681068            {
    10691069                RTFSOBJINFO info;
    10701070
    1071                 rc = RTDirQueryInfo (pHandle->dir.Handle, &info, RTFSOBJATTRADD_NOTHING);
     1071                rc = RTDirQueryInfo(pHandle->dir.Handle, &info, RTFSOBJATTRADD_NOTHING);
    10721072                if (RT_SUCCESS(rc))
    10731073                {
     
    11161116}
    11171117
    1118 static int vbsfCloseDir (SHFLFILEHANDLE *pHandle)
     1118static int vbsfCloseDir(SHFLFILEHANDLE *pHandle)
    11191119{
    11201120    int rc = VINF_SUCCESS;
     
    11231123             pHandle->dir.Handle, pHandle->dir.SearchHandle));
    11241124
    1125     RTDirClose (pHandle->dir.Handle);
     1125    RTDirClose(pHandle->dir.Handle);
    11261126
    11271127    if (pHandle->dir.SearchHandle)
     
    11401140
    11411141
    1142 static int vbsfCloseFile (SHFLFILEHANDLE *pHandle)
     1142static int vbsfCloseFile(SHFLFILEHANDLE *pHandle)
    11431143{
    11441144    int rc = VINF_SUCCESS;
     
    11471147             pHandle->file.Handle));
    11481148
    1149     rc = RTFileClose (pHandle->file.Handle);
     1149    rc = RTFileClose(pHandle->file.Handle);
    11501150
    11511151    LogFlow(("vbsfCloseFile: rc = %d\n", rc));
     
    12371237 *       pParms->Result return value and whether pParms->Handle is valid.
    12381238 */
    1239 int vbsfCreate (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, SHFLCREATEPARMS *pParms)
     1239int vbsfCreate(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, SHFLCREATEPARMS *pParms)
    12401240{
    12411241    int rc = VINF_SUCCESS;
     
    12541254    uint32_t cbFullPathRoot = 0;
    12551255
    1256     rc = vbsfBuildFullPath (pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot);
    1257 
    1258     if (RT_SUCCESS (rc))
     1256    rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot);
     1257
     1258    if (RT_SUCCESS(rc))
    12591259    {
    12601260        /* Reset return value in case client forgot to do so.
     
    12951295                if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_OPEN_TARGET_DIRECTORY))
    12961296                {
    1297                     vbsfStripLastComponent (pszFullPath, cbFullPathRoot);
     1297                    vbsfStripLastComponent(pszFullPath, cbFullPathRoot);
    12981298                    pParms->CreateFlags &= ~SHFL_CF_ACT_MASK_IF_EXISTS;
    12991299                    pParms->CreateFlags &= ~SHFL_CF_ACT_MASK_IF_NEW;
     
    13191319                /* is the guest allowed to write to this share? */
    13201320                bool fWritable;
    1321                 rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
     1321                rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    13221322                if (RT_FAILURE(rc) || !fWritable)
    13231323                    rc = VERR_WRITE_PROTECT;
     
    13321332                else
    13331333                {
    1334                     rc = vbsfOpenFile (pClient, pszFullPath, pParms);
     1334                    rc = vbsfOpenFile(pClient, pszFullPath, pParms);
    13351335                }
    13361336            }
     
    13601360}
    13611361#endif
    1362 int vbsfClose (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle)
     1362int vbsfClose(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle)
    13631363{
    13641364    int rc = VINF_SUCCESS;
     
    14471447}
    14481448#endif
    1449 int vbsfWrite (SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
     1449int vbsfWrite(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer)
    14501450{
    14511451    SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle);
     
    14641464     * XXX Actually this check was still done in vbsfCreate() -- RTFILE_O_WRITE cannot be set if vbsfMappingsQueryWritable() failed. */
    14651465    bool fWritable;
    1466     rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
     1466    rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    14671467    if (RT_FAILURE(rc) || !fWritable)
    14681468        return VERR_WRITE_PROTECT;
     
    15741574            Assert(pHandle->dir.pLastValidEntry == 0);
    15751575
    1576             rc = vbsfBuildFullPath (pClient, root, pPath, pPath->u16Size, &pszFullPath, NULL, true);
    1577 
    1578             if (RT_SUCCESS (rc))
    1579             {
    1580                 rc = RTDirOpenFiltered (&pHandle->dir.SearchHandle, pszFullPath, RTDIRFILTER_WINNT);
     1576            rc = vbsfBuildFullPath(pClient, root, pPath, pPath->u16Size, &pszFullPath, NULL, true);
     1577
     1578            if (RT_SUCCESS(rc))
     1579            {
     1580                rc = RTDirOpenFiltered(&pHandle->dir.SearchHandle, pszFullPath, RTDIRFILTER_WINNT);
    15811581
    15821582                /* free the path string */
    15831583                vbsfFreeFullPath(pszFullPath);
    15841584
    1585                 if (RT_FAILURE (rc))
     1585                if (RT_FAILURE(rc))
    15861586                    goto end;
    15871587            }
     
    16251625        }
    16261626
    1627         cbNeeded = RT_OFFSETOF (SHFLDIRINFO, name.String);
     1627        cbNeeded = RT_OFFSETOF(SHFLDIRINFO, name.String);
    16281628        if (fUtf8)
    16291629            cbNeeded += pDirEntry->cbName + 1;
     
    16581658            dst = &pSFDEntry->name.String.utf8[0];
    16591659
    1660             memcpy (dst, src, pDirEntry->cbName + 1);
     1660            memcpy(dst, src, pDirEntry->cbName + 1);
    16611661
    16621662            pSFDEntry->name.u16Size = pDirEntry->cbName + 1;
     
    16831683                CFMutableStringRef inStr = ::CFStringCreateMutable(NULL, 0);
    16841684
    1685                 ::CFStringAppendCharacters(inStr, (UniChar *)pwszString, RTUtf16Len (pwszString));
     1685                ::CFStringAppendCharacters(inStr, (UniChar *)pwszString, RTUtf16Len(pwszString));
    16861686                ::CFStringNormalize(inStr, kCFStringNormalizationFormC);
    16871687                ucs2Length = ::CFStringGetLength(inStr);
     
    16951695            }
    16961696#endif
    1697             pSFDEntry->name.u16Length = (uint32_t)RTUtf16Len (pSFDEntry->name.String.ucs2) * 2;
     1697            pSFDEntry->name.u16Length = (uint32_t)RTUtf16Len(pSFDEntry->name.String.ucs2) * 2;
    16981698            pSFDEntry->name.u16Size = pSFDEntry->name.u16Length + 2;
    16991699
     
    17021702
    17031703            // adjust cbNeeded (it was overestimated before)
    1704             cbNeeded = RT_OFFSETOF (SHFLDIRINFO, name.String) + pSFDEntry->name.u16Size;
     1704            cbNeeded = RT_OFFSETOF(SHFLDIRINFO, name.String) + pSFDEntry->name.u16Size;
    17051705        }
    17061706
     
    17571757    uint32_t cbFullPathRoot = 0;
    17581758
    1759     rc = vbsfBuildFullPath (pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot);
    1760 
    1761     if (RT_SUCCESS (rc))
     1759    rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot);
     1760
     1761    if (RT_SUCCESS(rc))
    17621762    {
    17631763        rc = RTSymlinkRead(pszFullPath, (char *) pBuffer, cbBuffer);
     
    19771977
    19781978    ShflStringInitBuffer(&dummy, sizeof(dummy));
    1979     rc = vbsfBuildFullPath (pClient, root, &dummy, 0, &pszFullPath, NULL);
    1980 
    1981     if (RT_SUCCESS (rc))
     1979    rc = vbsfBuildFullPath(pClient, root, &dummy, 0, &pszFullPath, NULL);
     1980
     1981    if (RT_SUCCESS(rc))
    19821982    {
    19831983        rc = RTFsQuerySizes(pszFullPath, &pSFDEntry->ullTotalAllocationBytes, &pSFDEntry->ullAvailableAllocationBytes, &pSFDEntry->ulBytesPerAllocationUnit, &pSFDEntry->ulBytesPerSector);
     
    20552055    /* is the guest allowed to write to this share? */
    20562056    bool fWritable;
    2057     int rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
     2057    int rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    20582058    if (RT_FAILURE(rc) || !fWritable)
    20592059        return VERR_WRITE_PROTECT;
     
    21962196    char *pszFullPath = NULL;
    21972197
    2198     rc = vbsfBuildFullPath (pClient, root, pPath, cbPath, &pszFullPath, NULL);
    2199     if (RT_SUCCESS (rc))
     2198    rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, NULL);
     2199    if (RT_SUCCESS(rc))
    22002200    {
    22012201        /* is the guest allowed to write to this share? */
    22022202        bool fWritable;
    2203         rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
     2203        rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    22042204        if (RT_FAILURE(rc) || !fWritable)
    22052205            rc = VERR_WRITE_PROTECT;
    22062206
    2207         if (RT_SUCCESS (rc))
     2207        if (RT_SUCCESS(rc))
    22082208        {
    22092209            if (flags & SHFL_REMOVE_SYMLINK)
     
    22552255    char *pszFullPathDest = NULL;
    22562256
    2257     rc = vbsfBuildFullPath (pClient, root, pSrc, pSrc->u16Size, &pszFullPathSrc, NULL);
     2257    rc = vbsfBuildFullPath(pClient, root, pSrc, pSrc->u16Size, &pszFullPathSrc, NULL);
    22582258    if (rc != VINF_SUCCESS)
    22592259        return rc;
    22602260
    2261     rc = vbsfBuildFullPath (pClient, root, pDest, pDest->u16Size, &pszFullPathDest, NULL, false, true);
     2261    rc = vbsfBuildFullPath(pClient, root, pDest, pDest->u16Size, &pszFullPathDest, NULL, false, true);
    22622262    if (RT_SUCCESS (rc))
    22632263    {
     
    22662266        /* is the guest allowed to write to this share? */
    22672267        bool fWritable;
    2268         rc = vbsfMappingsQueryWritable (pClient, root, &fWritable);
     2268        rc = vbsfMappingsQueryWritable(pClient, root, &fWritable);
    22692269        if (RT_FAILURE(rc) || !fWritable)
    22702270            rc = VERR_WRITE_PROTECT;
    22712271
    2272         if (RT_SUCCESS (rc))
     2272        if (RT_SUCCESS(rc))
    22732273        {
    22742274            if (flags & SHFL_RENAME_FILE)
     
    23152315        return VERR_NOT_IMPLEMENTED;
    23162316
    2317     rc = vbsfBuildFullPath (pClient, root, pNewPath, pNewPath->u16Size, &pszFullNewPath, NULL);
     2317    rc = vbsfBuildFullPath(pClient, root, pNewPath, pNewPath->u16Size, &pszFullNewPath, NULL);
    23182318    if (rc != VINF_SUCCESS)
    23192319        return rc;
    23202320
    23212321    rc = RTSymlinkCreate(pszFullNewPath, (const char *)pOldPath->String.utf8, RTSYMLINKTYPE_UNKNOWN);
    2322     if (RT_SUCCESS (rc))
     2322    if (RT_SUCCESS(rc))
    23232323    {
    23242324        RTFSOBJINFO info;
     
    23392339int vbsfDisconnect(SHFLCLIENTDATA *pClient)
    23402340{
    2341     for (int i=0;i<SHFLHANDLE_MAX;i++)
     2341    for (int i=0; i<SHFLHANDLE_MAX; i++)
    23422342    {
    23432343        SHFLHANDLE Handle = (SHFLHANDLE)i;
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