Changeset 39594 in vbox for trunk/src/VBox/HostServices
- Timestamp:
- Dec 13, 2011 10:09:12 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/SharedFolders/vbsf.cpp
r39586 r39594 5 5 6 6 /* 7 * Copyright (C) 2006-20 07Oracle Corporation7 * Copyright (C) 2006-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 51 51 */ 52 52 53 void vbsfStripLastComponent 53 void vbsfStripLastComponent(char *pszFullPath, uint32_t cbFullPathRoot) 54 54 { 55 55 RTUNICP cp; … … 81 81 } 82 82 83 s = RTStrNextCp 83 s = RTStrNextCp(s); 84 84 } 85 85 … … 139 139 strcat(pDirEntry->szName, szWildCard); 140 140 141 rc = RTDirOpenFiltered 141 rc = RTDirOpenFiltered(&hSearch, pDirEntry->szName, RTDIRFILTER_WINNT); 142 142 *(pszStartComponent-1) = RTPATH_DELIMITER; 143 143 if (RT_FAILURE(rc)) … … 248 248 } 249 249 250 static int vbsfBuildFullPath 251 252 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) 253 253 { 254 254 int rc = VINF_SUCCESS; … … 258 258 /* Query UCS2 root prefix for the path, cbRoot is the length in bytes including trailing (RTUTF16)0. */ 259 259 uint32_t cbRoot = 0; 260 PCRTUTF16 pwszRoot = vbsfMappingsQueryHostRoot 260 PCRTUTF16 pwszRoot = vbsfMappingsQueryHostRoot(root, &cbRoot); 261 261 262 262 if (!pwszRoot || cbRoot == 0) … … 273 273 rc = vbsfPathCheck((const char *)&pPath->String.utf8[0], pPath->u16Length); 274 274 275 if (RT_SUCCESS 276 { 277 rc = RTUtf16ToUtf8 278 } 279 280 if (RT_SUCCESS 275 if (RT_SUCCESS(rc)) 276 { 277 rc = RTUtf16ToUtf8(pwszRoot, &utf8Root); 278 } 279 280 if (RT_SUCCESS(rc)) 281 281 { 282 282 size_t cbUtf8Root, cbUtf8FullPath; 283 283 char *utf8FullPath; 284 284 285 cbUtf8Root = strlen 285 cbUtf8Root = strlen(utf8Root); 286 286 cbUtf8FullPath = cbUtf8Root + 1 + pPath->u16Length + 1; 287 utf8FullPath = (char *) RTMemAllocZ 287 utf8FullPath = (char *) RTMemAllocZ(cbUtf8FullPath); 288 288 289 289 if (!utf8FullPath) … … 295 295 else 296 296 { 297 memcpy 298 memcpy 299 300 297 memcpy(utf8FullPath, utf8Root, cbUtf8Root); 298 memcpy(utf8FullPath + cbUtf8Root + 1, 299 &pPath->String.utf8[0], 300 pPath->u16Length); 301 301 302 302 utf8FullPath[cbUtf8Root] = '/'; … … 308 308 } 309 309 310 RTStrFree 310 RTStrFree(utf8Root); 311 311 } 312 312 else 313 313 { 314 Log 314 Log(("vbsfBuildFullPath: RTUtf16ToUtf8 failed with %Rrc\n", rc)); 315 315 } 316 316 } … … 329 329 // Is 8 times length enough for decomposed in worst case...? 330 330 cbPathLength = sizeof(SHFLSTRING) + pPathParameter->u16Length * 8 + 2; 331 pPath = (SHFLSTRING *)RTMemAllocZ 331 pPath = (SHFLSTRING *)RTMemAllocZ(cbPathLength); 332 332 if (!pPath) 333 333 { … … 358 358 * in worst case. 359 359 */ 360 uint32_t cbFullPath = (cbRoot/sizeof (RTUTF16) + ShflStringLength(pPath)) * 4;361 362 pszFullPath = (char *)RTMemAllocZ 360 uint32_t cbFullPath = (cbRoot/sizeof(RTUTF16) + ShflStringLength(pPath)) * 4; 361 362 pszFullPath = (char *)RTMemAllocZ(cbFullPath); 363 363 364 364 if (!pszFullPath) … … 370 370 uint32_t cb = cbFullPath; 371 371 372 rc = RTUtf16ToUtf8Ex 372 rc = RTUtf16ToUtf8Ex(pwszRoot, RTSTR_MAX, &pszFullPath, cb, NULL); 373 373 if (RT_FAILURE(rc)) 374 374 { … … 417 417 src++; /* we already appended a delimiter to the first part */ 418 418 419 rc = RTUtf16ToUtf8Ex 419 rc = RTUtf16ToUtf8Ex(src, RTSTR_MAX, &dst, cb, NULL); 420 420 if (RT_FAILURE(rc)) 421 421 { … … 428 428 } 429 429 430 uint32_t l = (uint32_t)strlen 430 uint32_t l = (uint32_t)strlen(dst); 431 431 432 432 /* Verify that the path is under the root directory. */ … … 457 457 } 458 458 459 if (RT_SUCCESS 459 if (RT_SUCCESS(rc)) 460 460 { 461 461 /* When the host file system is case sensitive and the guest expects a case insensitive fs, then problems can occur */ 462 if ( vbsfIsHostMappingCaseSensitive 462 if ( vbsfIsHostMappingCaseSensitive(root) 463 463 && !vbsfIsGuestMappingCaseSensitive(root)) 464 464 { … … 600 600 } 601 601 602 static void vbsfFreeFullPath 603 { 604 RTMemFree 602 static void vbsfFreeFullPath(char *pszFullPath) 603 { 604 RTMemFree(pszFullPath); 605 605 } 606 606 … … 845 845 * @retval pParms->Info On success the parameters of the file opened or created 846 846 */ 847 static int vbsfOpenFile 847 static int vbsfOpenFile(SHFLCLIENTDATA *pClient, const char *pszPath, SHFLCREATEPARMS *pParms) 848 848 { 849 849 LogFlow(("vbsfOpenFile: pszPath = %s, pParms = %p\n", pszPath, pParms)); … … 871 871 rc = RTFileOpen(&pHandle->file.Handle, pszPath, fOpen); 872 872 } 873 if (RT_FAILURE 873 if (RT_FAILURE(rc)) 874 874 { 875 875 switch (rc) … … 968 968 969 969 /* Get file information */ 970 rc = RTFileQueryInfo 970 rc = RTFileQueryInfo(pHandle->file.Handle, &info, RTFSOBJATTRADD_NOTHING); 971 971 if (RT_SUCCESS(rc)) 972 972 { … … 1045 1045 pParms->Result = SHFL_FILE_CREATED; 1046 1046 rc = RTDirCreate(pszPath, fMode); 1047 if (RT_FAILURE 1047 if (RT_FAILURE(rc)) 1048 1048 { 1049 1049 switch (rc) … … 1064 1064 { 1065 1065 /* Open the directory now */ 1066 rc = RTDirOpen 1066 rc = RTDirOpen(&pHandle->dir.Handle, pszPath); 1067 1067 if (RT_SUCCESS(rc)) 1068 1068 { 1069 1069 RTFSOBJINFO info; 1070 1070 1071 rc = RTDirQueryInfo 1071 rc = RTDirQueryInfo(pHandle->dir.Handle, &info, RTFSOBJATTRADD_NOTHING); 1072 1072 if (RT_SUCCESS(rc)) 1073 1073 { … … 1116 1116 } 1117 1117 1118 static int vbsfCloseDir 1118 static int vbsfCloseDir(SHFLFILEHANDLE *pHandle) 1119 1119 { 1120 1120 int rc = VINF_SUCCESS; … … 1123 1123 pHandle->dir.Handle, pHandle->dir.SearchHandle)); 1124 1124 1125 RTDirClose 1125 RTDirClose(pHandle->dir.Handle); 1126 1126 1127 1127 if (pHandle->dir.SearchHandle) … … 1140 1140 1141 1141 1142 static int vbsfCloseFile 1142 static int vbsfCloseFile(SHFLFILEHANDLE *pHandle) 1143 1143 { 1144 1144 int rc = VINF_SUCCESS; … … 1147 1147 pHandle->file.Handle)); 1148 1148 1149 rc = RTFileClose 1149 rc = RTFileClose(pHandle->file.Handle); 1150 1150 1151 1151 LogFlow(("vbsfCloseFile: rc = %d\n", rc)); … … 1237 1237 * pParms->Result return value and whether pParms->Handle is valid. 1238 1238 */ 1239 int vbsfCreate 1239 int vbsfCreate(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLSTRING *pPath, uint32_t cbPath, SHFLCREATEPARMS *pParms) 1240 1240 { 1241 1241 int rc = VINF_SUCCESS; … … 1254 1254 uint32_t cbFullPathRoot = 0; 1255 1255 1256 rc = vbsfBuildFullPath 1257 1258 if (RT_SUCCESS 1256 rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot); 1257 1258 if (RT_SUCCESS(rc)) 1259 1259 { 1260 1260 /* Reset return value in case client forgot to do so. … … 1295 1295 if (BIT_FLAG(pParms->CreateFlags, SHFL_CF_OPEN_TARGET_DIRECTORY)) 1296 1296 { 1297 vbsfStripLastComponent 1297 vbsfStripLastComponent(pszFullPath, cbFullPathRoot); 1298 1298 pParms->CreateFlags &= ~SHFL_CF_ACT_MASK_IF_EXISTS; 1299 1299 pParms->CreateFlags &= ~SHFL_CF_ACT_MASK_IF_NEW; … … 1319 1319 /* is the guest allowed to write to this share? */ 1320 1320 bool fWritable; 1321 rc = vbsfMappingsQueryWritable 1321 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 1322 1322 if (RT_FAILURE(rc) || !fWritable) 1323 1323 rc = VERR_WRITE_PROTECT; … … 1332 1332 else 1333 1333 { 1334 rc = vbsfOpenFile 1334 rc = vbsfOpenFile(pClient, pszFullPath, pParms); 1335 1335 } 1336 1336 } … … 1360 1360 } 1361 1361 #endif 1362 int vbsfClose 1362 int vbsfClose(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle) 1363 1363 { 1364 1364 int rc = VINF_SUCCESS; … … 1447 1447 } 1448 1448 #endif 1449 int vbsfWrite 1449 int vbsfWrite(SHFLCLIENTDATA *pClient, SHFLROOT root, SHFLHANDLE Handle, uint64_t offset, uint32_t *pcbBuffer, uint8_t *pBuffer) 1450 1450 { 1451 1451 SHFLFILEHANDLE *pHandle = vbsfQueryFileHandle(pClient, Handle); … … 1464 1464 * XXX Actually this check was still done in vbsfCreate() -- RTFILE_O_WRITE cannot be set if vbsfMappingsQueryWritable() failed. */ 1465 1465 bool fWritable; 1466 rc = vbsfMappingsQueryWritable 1466 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 1467 1467 if (RT_FAILURE(rc) || !fWritable) 1468 1468 return VERR_WRITE_PROTECT; … … 1574 1574 Assert(pHandle->dir.pLastValidEntry == 0); 1575 1575 1576 rc = vbsfBuildFullPath 1577 1578 if (RT_SUCCESS 1579 { 1580 rc = RTDirOpenFiltered 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); 1581 1581 1582 1582 /* free the path string */ 1583 1583 vbsfFreeFullPath(pszFullPath); 1584 1584 1585 if (RT_FAILURE 1585 if (RT_FAILURE(rc)) 1586 1586 goto end; 1587 1587 } … … 1625 1625 } 1626 1626 1627 cbNeeded = RT_OFFSETOF 1627 cbNeeded = RT_OFFSETOF(SHFLDIRINFO, name.String); 1628 1628 if (fUtf8) 1629 1629 cbNeeded += pDirEntry->cbName + 1; … … 1658 1658 dst = &pSFDEntry->name.String.utf8[0]; 1659 1659 1660 memcpy 1660 memcpy(dst, src, pDirEntry->cbName + 1); 1661 1661 1662 1662 pSFDEntry->name.u16Size = pDirEntry->cbName + 1; … … 1683 1683 CFMutableStringRef inStr = ::CFStringCreateMutable(NULL, 0); 1684 1684 1685 ::CFStringAppendCharacters(inStr, (UniChar *)pwszString, RTUtf16Len 1685 ::CFStringAppendCharacters(inStr, (UniChar *)pwszString, RTUtf16Len(pwszString)); 1686 1686 ::CFStringNormalize(inStr, kCFStringNormalizationFormC); 1687 1687 ucs2Length = ::CFStringGetLength(inStr); … … 1695 1695 } 1696 1696 #endif 1697 pSFDEntry->name.u16Length = (uint32_t)RTUtf16Len 1697 pSFDEntry->name.u16Length = (uint32_t)RTUtf16Len(pSFDEntry->name.String.ucs2) * 2; 1698 1698 pSFDEntry->name.u16Size = pSFDEntry->name.u16Length + 2; 1699 1699 … … 1702 1702 1703 1703 // adjust cbNeeded (it was overestimated before) 1704 cbNeeded = RT_OFFSETOF 1704 cbNeeded = RT_OFFSETOF(SHFLDIRINFO, name.String) + pSFDEntry->name.u16Size; 1705 1705 } 1706 1706 … … 1757 1757 uint32_t cbFullPathRoot = 0; 1758 1758 1759 rc = vbsfBuildFullPath 1760 1761 if (RT_SUCCESS 1759 rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, &cbFullPathRoot); 1760 1761 if (RT_SUCCESS(rc)) 1762 1762 { 1763 1763 rc = RTSymlinkRead(pszFullPath, (char *) pBuffer, cbBuffer); … … 1977 1977 1978 1978 ShflStringInitBuffer(&dummy, sizeof(dummy)); 1979 rc = vbsfBuildFullPath 1980 1981 if (RT_SUCCESS 1979 rc = vbsfBuildFullPath(pClient, root, &dummy, 0, &pszFullPath, NULL); 1980 1981 if (RT_SUCCESS(rc)) 1982 1982 { 1983 1983 rc = RTFsQuerySizes(pszFullPath, &pSFDEntry->ullTotalAllocationBytes, &pSFDEntry->ullAvailableAllocationBytes, &pSFDEntry->ulBytesPerAllocationUnit, &pSFDEntry->ulBytesPerSector); … … 2055 2055 /* is the guest allowed to write to this share? */ 2056 2056 bool fWritable; 2057 int rc = vbsfMappingsQueryWritable 2057 int rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 2058 2058 if (RT_FAILURE(rc) || !fWritable) 2059 2059 return VERR_WRITE_PROTECT; … … 2196 2196 char *pszFullPath = NULL; 2197 2197 2198 rc = vbsfBuildFullPath 2199 if (RT_SUCCESS 2198 rc = vbsfBuildFullPath(pClient, root, pPath, cbPath, &pszFullPath, NULL); 2199 if (RT_SUCCESS(rc)) 2200 2200 { 2201 2201 /* is the guest allowed to write to this share? */ 2202 2202 bool fWritable; 2203 rc = vbsfMappingsQueryWritable 2203 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 2204 2204 if (RT_FAILURE(rc) || !fWritable) 2205 2205 rc = VERR_WRITE_PROTECT; 2206 2206 2207 if (RT_SUCCESS 2207 if (RT_SUCCESS(rc)) 2208 2208 { 2209 2209 if (flags & SHFL_REMOVE_SYMLINK) … … 2255 2255 char *pszFullPathDest = NULL; 2256 2256 2257 rc = vbsfBuildFullPath 2257 rc = vbsfBuildFullPath(pClient, root, pSrc, pSrc->u16Size, &pszFullPathSrc, NULL); 2258 2258 if (rc != VINF_SUCCESS) 2259 2259 return rc; 2260 2260 2261 rc = vbsfBuildFullPath 2261 rc = vbsfBuildFullPath(pClient, root, pDest, pDest->u16Size, &pszFullPathDest, NULL, false, true); 2262 2262 if (RT_SUCCESS (rc)) 2263 2263 { … … 2266 2266 /* is the guest allowed to write to this share? */ 2267 2267 bool fWritable; 2268 rc = vbsfMappingsQueryWritable 2268 rc = vbsfMappingsQueryWritable(pClient, root, &fWritable); 2269 2269 if (RT_FAILURE(rc) || !fWritable) 2270 2270 rc = VERR_WRITE_PROTECT; 2271 2271 2272 if (RT_SUCCESS 2272 if (RT_SUCCESS(rc)) 2273 2273 { 2274 2274 if (flags & SHFL_RENAME_FILE) … … 2315 2315 return VERR_NOT_IMPLEMENTED; 2316 2316 2317 rc = vbsfBuildFullPath 2317 rc = vbsfBuildFullPath(pClient, root, pNewPath, pNewPath->u16Size, &pszFullNewPath, NULL); 2318 2318 if (rc != VINF_SUCCESS) 2319 2319 return rc; 2320 2320 2321 2321 rc = RTSymlinkCreate(pszFullNewPath, (const char *)pOldPath->String.utf8, RTSYMLINKTYPE_UNKNOWN); 2322 if (RT_SUCCESS 2322 if (RT_SUCCESS(rc)) 2323 2323 { 2324 2324 RTFSOBJINFO info; … … 2339 2339 int vbsfDisconnect(SHFLCLIENTDATA *pClient) 2340 2340 { 2341 for (int i=0; i<SHFLHANDLE_MAX;i++)2341 for (int i=0; i<SHFLHANDLE_MAX; i++) 2342 2342 { 2343 2343 SHFLHANDLE Handle = (SHFLHANDLE)i;
Note:
See TracChangeset
for help on using the changeset viewer.