- Timestamp:
- Nov 16, 2017 2:31:25 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/dir.h
r69709 r69716 620 620 * @param fMode The mode of the new directory. 621 621 * @param fCreate Create flags, RTDIRCREATE_FLAGS_XXX. 622 * @param phSubDir Where to return the handle of the created directory. 623 * Optional. 622 624 * 623 625 * @sa RTDirCreate 624 626 */ 625 RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate );627 RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate, PRTDIR *phSubDir); 626 628 627 629 /** -
trunk/include/iprt/err.h
r69105 r69716 2079 2079 /** VFS chain doesn't end with a path only element. */ 2080 2080 #define VERR_VFS_CHAIN_NOT_PATH_ONLY (-22157) 2081 /** The path only element at the end of the VFS chain is too short to make out 2082 * the parent directory. */ 2083 #define VERR_VFS_CHAIN_TOO_SHORT_FOR_PARENT (-22158) 2081 2084 /** @} */ 2082 2085 -
trunk/include/iprt/mangling.h
r69674 r69716 2418 2418 # define RTVfsChainMsgErrorExitFailure RT_MANGLER(RTVfsChainMsgErrorExitFailure) 2419 2419 # define RTVfsChainOpenDir RT_MANGLER(RTVfsChainOpenDir) 2420 # define RTVfsChainOpenParentDir RT_MANGLER(RTVfsChainOpenParentDir) 2420 2421 # define RTVfsChainOpenFile RT_MANGLER(RTVfsChainOpenFile) 2421 2422 # define RTVfsChainOpenIoStream RT_MANGLER(RTVfsChainOpenIoStream) … … 2425 2426 # define RTVfsChainSpecFree RT_MANGLER(RTVfsChainSpecFree) 2426 2427 # define RTVfsChainSpecParse RT_MANGLER(RTVfsChainSpecParse) 2428 # define RTVfsChainSplitOffFinalPath RT_MANGLER(RTVfsChainSplitOffFinalPath) 2427 2429 # define RTVfsChainValidateOpenFileOrIoStream RT_MANGLER(RTVfsChainValidateOpenFileOrIoStream) 2428 2430 # define RTVfsDirRelease RT_MANGLER(RTVfsDirRelease) … … 2431 2433 # define RTVfsDirOpen RT_MANGLER(RTVfsDirOpen) 2432 2434 # define RTVfsDirOpenDir RT_MANGLER(RTVfsDirOpenDir) 2435 # define RTVfsDirCreateDir RT_MANGLER(RTVfsDirCreateDir) 2433 2436 # define RTVfsDirOpenFile RT_MANGLER(RTVfsDirOpenFile) 2434 2437 # define RTVfsDirOpenFileAsIoStream RT_MANGLER(RTVfsDirOpenFileAsIoStream) -
trunk/include/iprt/vfs.h
r69679 r69716 478 478 479 479 /** 480 * Creates a directory relative to @a hVfsDir. 481 * 482 * @returns IPRT status code 483 * @param hVfsDir The directory the path is relative to. 484 * @param pszRelPath The relative path to the new directory. 485 * @param fMode The file mode for the new directory. 486 * @param fFlags Directory creation flags, RTDIRCREATE_FLAGS_XXX. 487 * @param phVfsDir Where to return the handle to the newly created 488 * directory. Optional. 489 * @sa RTDirCreate, RTDirRelDirCreate 490 */ 491 RTDECL(int) RTVfsDirCreateDir(RTVFSDIR hVfsDir, const char *pszRelPath, RTFMODE fMode, uint32_t fFlags, PRTVFSDIR phVfsDir); 492 493 /** 480 494 * Create a VFS directory handle from a standard IPRT directory handle (PRTDIR). 481 495 * … … 1535 1549 RTDECL(int) RTVfsChainOpenFsStream(const char *pszSpec, PRTVFSFSSTREAM phVfsFss, uint32_t *poffError, PRTERRINFO pErrInfo); 1536 1550 RTDECL(int) RTVfsChainOpenDir(const char *pszSpec, uint32_t fOpen, PRTVFSDIR phVfsDir, uint32_t *poffError, PRTERRINFO pErrInfo); 1551 RTDECL(int) RTVfsChainOpenParentDir(const char *pszSpec, uint32_t fOpen, PRTVFSDIR phVfsDir, const char **ppszChild, 1552 uint32_t *poffError, PRTERRINFO pErrInfo); 1537 1553 RTDECL(int) RTVfsChainOpenFile(const char *pszSpec, uint64_t fOpen, PRTVFSFILE phVfsFile, uint32_t *poffError, PRTERRINFO pErrInfo); 1538 1554 RTDECL(int) RTVfsChainOpenIoStream(const char *pszSpec, uint64_t fOpen, PRTVFSIOSTREAM phVfsIos, uint32_t *poffError, PRTERRINFO pErrInfo); … … 1566 1582 1567 1583 /** 1584 * Splits the given chain spec into a final path and the preceeding spec. 1585 * 1586 * This works on plain paths too. 1587 * 1588 * @returns IPRT status code. 1589 * @param pszSpec The chain spec to split. This will be modified! 1590 * @param ppszSpec Where to return the pointer to the chain spec part. 1591 * This is set to NULL if it's a plain path or a chain 1592 * spec with only a final-path element. 1593 * @param ppszFinalPath Where to return the pointer to the final path. This 1594 * is set to NULL if no final path. 1595 * @param poffError Where to on error return an offset into @a pszSpec 1596 * of what cause the error. Optional. 1597 */ 1598 RTDECL(int) RTVfsChainSplitOffFinalPath(char *pszSpec, char **ppszSpec, char **ppszFinalPath, uint32_t *poffError); 1599 1600 /** 1568 1601 * Common code for reporting errors of a RTVfsChainOpen* API. 1569 1602 * -
trunk/include/iprt/vfslowlevel.h
r69705 r69716 566 566 * @param fFlags RTDIR_F_XXX. 567 567 * @param phVfsDir Where to return the handle to the opened directory. 568 * Optional. 568 569 * @sa RTDirOpen. 569 570 */ -
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r69705 r69716 1523 1523 *pszEntryEnd = '\0'; 1524 1524 if ( rc == VERR_PATH_NOT_FOUND 1525 || rc == VERR_FILE_NOT_FOUND 1525 1526 || rc == VERR_NOT_A_DIRECTORY 1526 1527 || rc == VERR_NOT_SYMLINK) … … 2350 2351 2351 2352 2353 RTDECL(int) RTVfsDirCreateDir(RTVFSDIR hVfsDir, const char *pszRelPath, RTFMODE fMode, uint32_t fFlags, PRTVFSDIR phVfsDir) 2354 { 2355 /* 2356 * Validate input. 2357 */ 2358 RTVFSDIRINTERNAL *pThis = hVfsDir; 2359 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 2360 AssertReturn(pThis->uMagic == RTVFSDIR_MAGIC, VERR_INVALID_HANDLE); 2361 AssertPtrReturn(pszRelPath, VERR_INVALID_POINTER); 2362 AssertPtrReturn(phVfsDir, VERR_INVALID_POINTER); 2363 AssertReturn(!(fFlags & ~RTDIRCREATE_FLAGS_VALID_MASK), VERR_INVALID_FLAGS); 2364 fMode = rtFsModeNormalize(fMode, pszRelPath, 0); 2365 AssertReturn(rtFsModeIsValidPermissions(fMode), VERR_INVALID_FMODE); 2366 if (!(fFlags & RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET)) 2367 fMode |= RTFS_DOS_NT_NOT_CONTENT_INDEXED; 2368 2369 /* 2370 * Parse the path, it's always relative to the given directory. 2371 */ 2372 PRTVFSPARSEDPATH pPath; 2373 int rc = RTVfsParsePathA(pszRelPath, NULL, &pPath); 2374 if (RT_SUCCESS(rc)) 2375 { 2376 if (pPath->cComponents > 0) 2377 { 2378 /* 2379 * Tranverse the path, resolving the parent node, not checking for symbolic 2380 * links in the final element, and ask the directory to create the subdir. 2381 */ 2382 RTVFSDIRINTERNAL *pVfsParentDir; 2383 rc = rtVfsDirTraverseToParent(pThis, pPath, 2384 fFlags & RTDIRCREATE_FLAGS_NO_SYMLINKS 2385 ? RTPATH_F_NO_SYMLINKS | RTPATH_F_ON_LINK : RTPATH_F_FOLLOW_LINK, 2386 &pVfsParentDir); 2387 if (RT_SUCCESS(rc)) 2388 { 2389 const char *pszEntryName = &pPath->szPath[pPath->aoffComponents[pPath->cComponents - 1]]; 2390 2391 RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock); 2392 rc = pVfsParentDir->pOps->pfnCreateDir(pVfsParentDir->Base.pvThis, pszEntryName, fMode, phVfsDir); 2393 RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock); 2394 2395 RTVfsDirRelease(pVfsParentDir); 2396 2397 if (RT_SUCCESS(rc) && phVfsDir) 2398 { 2399 AssertPtr(*phVfsDir); 2400 Assert((*phVfsDir)->uMagic == RTVFSDIR_MAGIC); 2401 } 2402 } 2403 } 2404 else 2405 rc = VERR_PATH_ZERO_LENGTH; 2406 RTVfsParsePathFree(pPath); 2407 } 2408 return rc; 2409 } 2410 2411 2352 2412 RTDECL(int) RTVfsDirOpenFile(RTVFSDIR hVfsDir, const char *pszPath, uint64_t fOpen, PRTVFSFILE phVfsFile) 2353 2413 { -
trunk/src/VBox/Runtime/common/vfs/vfschain.cpp
r69705 r69716 34 34 #include <iprt/asm.h> 35 35 #include <iprt/critsect.h> 36 #include <iprt/ctype.h> 36 37 #include <iprt/err.h> 37 38 #include <iprt/file.h> … … 1198 1199 1199 1200 1201 RTDECL(int) RTVfsChainOpenParentDir(const char *pszSpec, uint32_t fOpen, PRTVFSDIR phVfsDir, const char **ppszChild, 1202 uint32_t *poffError, PRTERRINFO pErrInfo) 1203 { 1204 uint32_t offErrorIgn; 1205 if (!poffError) 1206 poffError = &offErrorIgn; 1207 *poffError = 0; 1208 AssertPtrReturn(pszSpec, VERR_INVALID_POINTER); 1209 AssertReturn(*pszSpec != '\0', VERR_INVALID_PARAMETER); 1210 AssertPtrReturn(phVfsDir, VERR_INVALID_POINTER); 1211 AssertPtrReturn(ppszChild, VERR_INVALID_POINTER); 1212 *ppszChild = NULL; 1213 AssertPtrNullReturn(pErrInfo, VERR_INVALID_POINTER); 1214 1215 /* 1216 * Process the spec from the end, trying to find the child part of it. 1217 * We cannot use RTPathFilename here because we must ignore trailing slashes. 1218 */ 1219 const char * const pszEnd = RTStrEnd(pszSpec, RTSTR_MAX); 1220 const char *pszChild = pszEnd; 1221 while ( pszChild != pszSpec 1222 && RTPATH_IS_SLASH(pszChild[-1])) 1223 pszChild--; 1224 while ( pszChild != pszSpec 1225 && !RTPATH_IS_SLASH(pszChild[-1]) 1226 && !RTPATH_IS_VOLSEP(pszChild[-1])) 1227 pszChild--; 1228 size_t const cchChild = pszEnd - pszChild; 1229 *ppszChild = pszChild; 1230 1231 /* 1232 * Try for a VFS chain first, falling back on regular file system stuff if it's just a path. 1233 */ 1234 int rc; 1235 PRTVFSCHAINSPEC pSpec = NULL; 1236 if (strncmp(pszSpec, RTVFSCHAIN_SPEC_PREFIX, sizeof(RTVFSCHAIN_SPEC_PREFIX) - 1) == 0) 1237 { 1238 rc = RTVfsChainSpecParse(pszSpec, 0 /*fFlags*/, RTVFSOBJTYPE_DIR, &pSpec, poffError); 1239 if (RT_FAILURE(rc)) 1240 return rc; 1241 1242 Assert(pSpec->cElements > 0); 1243 if ( pSpec->cElements > 1 1244 || pSpec->paElements[0].enmType != RTVFSOBJTYPE_END) 1245 { 1246 /* 1247 * Check that it ends with a path-only element and that this in turn ends with 1248 * what pszChild points to. (We cannot easiy figure out the parent part of 1249 * an element that isn't path-only, so we don't bother trying try.) 1250 */ 1251 PRTVFSCHAINELEMSPEC pLast = &pSpec->paElements[pSpec->cElements - 1]; 1252 if (pLast->pszProvider == NULL) 1253 { 1254 size_t cchFinal = strlen(pLast->paArgs[0].psz); 1255 if ( cchFinal >= cchChild 1256 && memcmp(&pLast->paArgs[0].psz[cchFinal - cchChild], pszChild, cchChild + 1) == 0) 1257 { 1258 /* 1259 * Drop the child part so we have a path to the parent, then setup the chain. 1260 */ 1261 if (cchFinal > cchChild) 1262 pLast->paArgs[0].psz[cchFinal - cchChild] = '\0'; 1263 else 1264 pSpec->cElements--; 1265 1266 const char *pszFinal = NULL; 1267 RTVFSOBJ hVfsObj = NIL_RTVFSOBJ; 1268 pSpec->fOpenFile = fOpen; 1269 rc = RTVfsChainSpecCheckAndSetup(pSpec, NULL /*pReuseSpec*/, &hVfsObj, &pszFinal, poffError, pErrInfo); 1270 if (RT_SUCCESS(rc)) 1271 { 1272 if (!pszFinal) 1273 { 1274 Assert(cchFinal == cchChild); 1275 1276 /* Try convert it to a file object and we're done. */ 1277 *phVfsDir = RTVfsObjToDir(hVfsObj); 1278 if (*phVfsDir) 1279 rc = VINF_SUCCESS; 1280 else 1281 rc = VERR_VFS_CHAIN_CAST_FAILED; 1282 } 1283 else 1284 { 1285 /* 1286 * Do a file open with the final path on the returned object. 1287 */ 1288 RTVFS hVfs = RTVfsObjToVfs(hVfsObj); 1289 RTVFSDIR hVfsDir = RTVfsObjToDir(hVfsObj); 1290 RTVFSFSSTREAM hVfsFss = RTVfsObjToFsStream(hVfsObj); 1291 if (hVfs != NIL_RTVFS) 1292 rc = RTVfsDirOpen(hVfs, pszFinal, fOpen, phVfsDir); 1293 else if (hVfsDir != NIL_RTVFSDIR) 1294 rc = RTVfsDirOpenDir(hVfsDir, pszFinal, fOpen, phVfsDir); 1295 else if (hVfsFss != NIL_RTVFSFSSTREAM) 1296 rc = VERR_NOT_IMPLEMENTED; 1297 else 1298 rc = VERR_VFS_CHAIN_TYPE_MISMATCH_PATH_ONLY; 1299 RTVfsRelease(hVfs); 1300 RTVfsDirRelease(hVfsDir); 1301 RTVfsFsStrmRelease(hVfsFss); 1302 } 1303 RTVfsObjRelease(hVfsObj); 1304 } 1305 } 1306 else 1307 rc = VERR_VFS_CHAIN_TOO_SHORT_FOR_PARENT; 1308 } 1309 else 1310 rc = VERR_VFS_CHAIN_NOT_PATH_ONLY; 1311 1312 RTVfsChainSpecFree(pSpec); 1313 return rc; 1314 } 1315 1316 /* Only a path element. */ 1317 pszSpec = pSpec->paElements[0].paArgs[0].psz; 1318 } 1319 1320 /* 1321 * Path to regular file system. 1322 */ 1323 if (RTPathHasPath(pszSpec)) 1324 { 1325 char *pszCopy = RTStrDup(pszSpec); 1326 if (pszCopy) 1327 { 1328 RTPathStripFilename(pszCopy); 1329 rc = RTVfsDirOpenNormal(pszCopy, fOpen, phVfsDir); 1330 RTStrFree(pszCopy); 1331 } 1332 else 1333 rc = VERR_NO_STR_MEMORY; 1334 } 1335 else 1336 rc = RTVfsDirOpenNormal(".", fOpen, phVfsDir); 1337 1338 RTVfsChainSpecFree(pSpec); 1339 return rc; 1340 1341 } 1342 1343 1200 1344 RTDECL(int) RTVfsChainOpenFile(const char *pszSpec, uint64_t fOpen, 1201 1345 PRTVFSFILE phVfsFile, uint32_t *poffError, PRTERRINFO pErrInfo) … … 1225 1369 || pSpec->paElements[0].enmType != RTVFSOBJTYPE_END) 1226 1370 { 1227 1228 1371 const char *pszFinal = NULL; 1229 1372 RTVFSOBJ hVfsObj = NIL_RTVFSOBJ; … … 1319 1462 || pSpec->paElements[0].enmType != RTVFSOBJTYPE_END) 1320 1463 { 1321 1322 1464 const char *pszFinal = NULL; 1323 1465 RTVFSOBJ hVfsObj = NIL_RTVFSOBJ; … … 1431 1573 || pSpec->paElements[0].enmType != RTVFSOBJTYPE_END) 1432 1574 { 1433 1434 1575 const char *pszFinal = NULL; 1435 1576 RTVFSOBJ hVfsObj = NIL_RTVFSOBJ; … … 1527 1668 } 1528 1669 1670 1671 RTDECL(int) RTVfsChainSplitOffFinalPath(char *pszSpec, char **ppszSpec, char **ppszFinalPath, uint32_t *poffError) 1672 { 1673 /* Make sure we've got an error info variable. */ 1674 uint32_t offErrorIgn; 1675 if (!poffError) 1676 poffError = &offErrorIgn; 1677 *poffError = 0; 1678 1679 /* 1680 * If not chain specifier, just duplicate the input and return. 1681 */ 1682 if (strncmp(pszSpec, RTVFSCHAIN_SPEC_PREFIX, sizeof(RTVFSCHAIN_SPEC_PREFIX) - 1) != 0) 1683 { 1684 *ppszSpec = NULL; 1685 *ppszFinalPath = pszSpec; 1686 return VINF_SUCCESS; 1687 } 1688 1689 /* 1690 * Parse it and check out the last element. 1691 */ 1692 PRTVFSCHAINSPEC pSpec = NULL; 1693 int rc = RTVfsChainSpecParse(pszSpec, 0 /*fFlags*/, RTVFSOBJTYPE_BASE, &pSpec, poffError); 1694 if (RT_SUCCESS(rc)) 1695 { 1696 Assert(pSpec->cElements > 0); 1697 PCRTVFSCHAINELEMSPEC pLast = &pSpec->paElements[pSpec->cElements - 1]; 1698 if (pLast->pszProvider == NULL) 1699 { 1700 char *psz = &pszSpec[pLast->offSpec]; 1701 *ppszFinalPath = psz; 1702 if (pSpec->cElements > 1) 1703 { 1704 *ppszSpec = pszSpec; 1705 1706 /* Remove the separator and any whitespace around it. */ 1707 while ( psz != pszSpec 1708 && RT_C_IS_SPACE(psz[-1])) 1709 psz--; 1710 if ( psz != pszSpec 1711 && ( psz[-1] == ':' 1712 || psz[-1] == '|')) 1713 psz--; 1714 while ( psz != pszSpec 1715 && RT_C_IS_SPACE(psz[-1])) 1716 psz--; 1717 *psz = '\0'; 1718 } 1719 else 1720 *ppszSpec = NULL; 1721 } 1722 else 1723 { 1724 *ppszFinalPath = NULL; 1725 *ppszSpec = pszSpec; 1726 } 1727 RTVfsChainSpecFree(pSpec); 1728 } 1729 else 1730 { 1731 *ppszSpec = NULL; 1732 *ppszFinalPath = NULL; 1733 } 1734 return rc; 1735 } 1736 -
trunk/src/VBox/Runtime/common/vfs/vfsstddir.cpp
r69679 r69716 347 347 { 348 348 PRTVFSSTDDIR pThis = (PRTVFSSTDDIR)pvThis; 349 int rc = RTDirRelDirCreate(pThis->hDir, pszSubDir, fMode, 0 /* fFlags */);350 if ( RT_SUCCESS(rc)351 && phVfsDir)352 {353 /** @todo subdir open flags */349 int rc; 350 if (!phVfsDir) 351 rc = RTDirRelDirCreate(pThis->hDir, pszSubDir, fMode, 0 /* fFlags */, NULL); 352 else 353 { 354 354 PRTDIR hSubDir; 355 rc = RTDirRelDir Open(pThis->hDir, pszSubDir, &hSubDir);355 rc = RTDirRelDirCreate(pThis->hDir, pszSubDir, fMode, 0 /* fFlags */, &hSubDir); 356 356 if (RT_SUCCESS(rc)) 357 357 { 358 /** @todo subdir open flags... */ 358 359 rc = rtVfsDirFromRTDir(hSubDir, 0, false, phVfsDir); 359 360 if (RT_FAILURE(rc)) … … 361 362 } 362 363 } 364 363 365 return rc; 364 366 } -
trunk/src/VBox/Runtime/include/internal/dir.h
r69691 r69716 166 166 * @param hRelativeDir The directory @a pvNativeRelative is relative, 167 167 * ~(uintptr_t)0 if absolute. 168 * @param pvNativeRelative The native relative path. NULL if absolute. 168 * @param pvNativeRelative The native relative path. NULL if absolute or 169 * we're to use (consume) hRelativeDir. 169 170 */ 170 171 int rtDirNativeOpen(PRTDIR pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative); … … 179 180 180 181 181 DECLHIDDEN(int) rtDirOpenRelative (PRTDIR *ppDir, const char *pszRelativeAndFilter, RTDIRFILTER enmFilter, uint32_t fFlags,182 uintptr_t hRelativeDir, void *pvNativeRelative);182 DECLHIDDEN(int) rtDirOpenRelativeOrHandle(PRTDIR *ppDir, const char *pszRelativeAndFilter, RTDIRFILTER enmFilter, uint32_t fFlags, 183 uintptr_t hRelativeDir, void *pvNativeRelative); 183 184 184 185 #endif -
trunk/src/VBox/Runtime/r3/dir.cpp
r69691 r69716 512 512 * @param enmFilter The type of filter to apply. 513 513 * @param fFlags RTDIR_F_XXX. 514 * @param hRelativeDir The directory @a pvNativeRelative is relative, 515 * ~(uintptr_t)0 if absolute. 516 * @param pvNativeRelative The native relative path. NULL if absolute. 514 * @param hRelativeDir The directory @a pvNativeRelative is relative 515 * to, ~(uintptr_t)0 if absolute. 516 * @param pvNativeRelative The native relative path. NULL if absolute or 517 * we're to use (consume) hRelativeDir. 517 518 */ 518 519 static int rtDirOpenCommon(PRTDIR *ppDir, const char *pszPath, const char *pszFilter, RTDIRFILTER enmFilter, uint32_t fFlags, … … 655 656 656 657 657 DECLHIDDEN(int) rtDirOpenRelative (PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter, uint32_t fFlags,658 uintptr_t hRelativeDir, void *pvNativeRelative)658 DECLHIDDEN(int) rtDirOpenRelativeOrHandle(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter, uint32_t fFlags, 659 uintptr_t hRelativeDir, void *pvNativeRelative) 659 660 { 660 661 /* … … 704 705 RTDECL(int) RTDirOpenFiltered(PRTDIR *ppDir, const char *pszPath, RTDIRFILTER enmFilter, uint32_t fFlags) 705 706 { 706 return rtDirOpenRelative (ppDir, pszPath, enmFilter, fFlags, ~(uintptr_t)0, NULL);707 return rtDirOpenRelativeOrHandle(ppDir, pszPath, enmFilter, fFlags, ~(uintptr_t)0, NULL); 707 708 } 708 709 -
trunk/src/VBox/Runtime/r3/generic/dirrel-r3-generic.cpp
r69705 r69716 211 211 * @param fMode The mode of the new directory. 212 212 * @param fCreate Create flags, RTDIRCREATE_FLAGS_XXX. 213 * @param phSubDir Where to return the handle of the created directory. 214 * Optional. 213 215 * 214 216 * @sa RTDirCreate 215 217 */ 216 RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate) 217 { 218 PRTDIR pThis = hDir; 219 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 220 AssertReturn(pThis->u32Magic == RTDIR_MAGIC, VERR_INVALID_HANDLE); 221 222 char szPath[RTPATH_MAX]; 223 int rc = rtDirRelBuildFullPath(pThis, szPath, sizeof(szPath), pszRelPath); 224 if (RT_SUCCESS(rc)) 218 RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate, PRTDIR *phSubDir) 219 { 220 PRTDIR pThis = hDir; 221 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 222 AssertReturn(pThis->u32Magic == RTDIR_MAGIC, VERR_INVALID_HANDLE); 223 224 char szPath[RTPATH_MAX]; 225 int rc = rtDirRelBuildFullPath(pThis, szPath, sizeof(szPath), pszRelPath); 226 if (RT_SUCCESS(rc)) 227 { 225 228 rc = RTDirCreate(szPath, fMode, fCreate); 229 if (RT_SUCCESS(rc) && phSubDir) 230 rc = RTDirOpen(phSubDir, szPath); 231 } 226 232 return rc; 227 233 } -
trunk/src/VBox/Runtime/r3/nt/direnum-r3-nt.cpp
r69705 r69716 106 106 bool fObjDir = false; 107 107 #endif 108 if ( pvNativeRelative == NULL)108 if (hRelativeDir == ~(uintptr_t)0 && pvNativeRelative == NULL) 109 109 rc = RTNtPathOpenDir(pszPathBuf, 110 110 FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES | FILE_TRAVERSE | SYNCHRONIZE, … … 119 119 #endif 120 120 ); 121 else 121 else if (pvNativeRelative != NULL) 122 122 rc = RTNtPathOpenDirEx((HANDLE)hRelativeDir, 123 123 (struct _UNICODE_STRING *)pvNativeRelative, … … 134 134 135 135 ); 136 else 137 { 138 pDir->hDir = (HANDLE)hRelativeDir; 139 rc = VINF_SUCCESS; 140 } 136 141 if (RT_SUCCESS(rc)) 137 142 { -
trunk/src/VBox/Runtime/r3/nt/dirrel-r3-nt.cpp
r69705 r69716 210 210 if (RT_SUCCESS(rc)) 211 211 { 212 rc = rtDirOpenRelative (phDir, pszDirAndFilter, enmFilter, fFlags, (uintptr_t)hRoot, &NtName);212 rc = rtDirOpenRelativeOrHandle(phDir, pszDirAndFilter, enmFilter, fFlags, (uintptr_t)hRoot, &NtName); 213 213 RTNtPathFree(&NtName, NULL); 214 214 } … … 225 225 * @param fMode The mode of the new directory. 226 226 * @param fCreate Create flags, RTDIRCREATE_FLAGS_XXX. 227 * @param phSubDir Where to return the handle of the created directory. 228 * Optional. 227 229 * 228 230 * @sa RTDirCreate 229 231 */ 230 RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate) 231 { 232 PRTDIR pThis = hDir; 233 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 234 AssertReturn(pThis->u32Magic == RTDIR_MAGIC, VERR_INVALID_HANDLE); 235 236 char szPath[RTPATH_MAX]; 237 int rc = rtDirRelBuildFullPath(pThis, szPath, sizeof(szPath), pszRelPath); 238 if (RT_SUCCESS(rc)) 239 { 240 RTAssertMsg2("DBG: RTDirRelDirCreate(%s)...\n", szPath); 241 rc = RTDirCreate(szPath, fMode, fCreate); 232 RTDECL(int) RTDirRelDirCreate(PRTDIR hDir, const char *pszRelPath, RTFMODE fMode, uint32_t fCreate, PRTDIR *phSubDir) 233 { 234 PRTDIR pThis = hDir; 235 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 236 AssertReturn(pThis->u32Magic == RTDIR_MAGIC, VERR_INVALID_HANDLE); 237 AssertReturn(!(fCreate & ~RTDIRCREATE_FLAGS_VALID_MASK), VERR_INVALID_FLAGS); 238 fMode = rtFsModeNormalize(fMode, pszRelPath, 0); 239 AssertReturn(rtFsModeIsValidPermissions(fMode), VERR_INVALID_FMODE); 240 AssertPtrNullReturn(phSubDir, VERR_INVALID_POINTER); 241 242 /* 243 * Convert and normalize the path. 244 */ 245 UNICODE_STRING NtName; 246 HANDLE hRoot = pThis->hDir; 247 int rc = RTNtPathRelativeFromUtf8(&NtName, &hRoot, pszRelPath, RTDIRREL_NT_GET_ASCENT(pThis), 248 pThis->enmInfoClass == FileMaximumInformation); 249 if (RT_SUCCESS(rc)) 250 { 251 HANDLE hNewDir = RTNT_INVALID_HANDLE_VALUE; 252 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 253 OBJECT_ATTRIBUTES ObjAttr; 254 InitializeObjectAttributes(&ObjAttr, &NtName, 0 /*fAttrib*/, hRoot, NULL); 255 256 ULONG fDirAttribs = (fCreate & RTFS_DOS_MASK_NT) >> RTFS_DOS_SHIFT; 257 if (!(fCreate & RTDIRCREATE_FLAGS_NOT_CONTENT_INDEXED_DONT_SET)) 258 fDirAttribs |= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; 259 if (!fDirAttribs) 260 fDirAttribs = RTFS_DOS_NT_NORMAL; 261 262 NTSTATUS rcNt = NtCreateFile(&hNewDir, 263 phSubDir 264 ? FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES | FILE_LIST_DIRECTORY | FILE_TRAVERSE | SYNCHRONIZE 265 : SYNCHRONIZE, 266 &ObjAttr, 267 &Ios, 268 NULL /*AllocationSize*/, 269 fDirAttribs, 270 FILE_SHARE_READ | FILE_SHARE_WRITE, 271 FILE_CREATE, 272 FILE_DIRECTORY_FILE | FILE_OPEN_FOR_BACKUP_INTENT | FILE_SYNCHRONOUS_IO_NONALERT, 273 NULL /*EaBuffer*/, 274 0 /*EaLength*/); 275 if (NT_SUCCESS(rcNt)) 276 { 277 if (!phSubDir) 278 { 279 NtClose(hNewDir); 280 rc = VINF_SUCCESS; 281 } 282 else 283 { 284 rc = rtDirOpenRelativeOrHandle(phSubDir, pszRelPath, RTDIRFILTER_NONE, 0 /*fFlags*/, 285 (uintptr_t)hNewDir, NULL /*pvNativeRelative*/); 286 if (RT_FAILURE(rc)) 287 NtClose(hNewDir); 288 } 289 } 290 else 291 rc = RTErrConvertFromNtStatus(rcNt); 292 RTNtPathFree(&NtName, NULL); 242 293 } 243 294 return rc; … … 259 310 AssertPtrReturn(pThis, VERR_INVALID_HANDLE); 260 311 AssertReturn(pThis->u32Magic == RTDIR_MAGIC, VERR_INVALID_HANDLE); 312 261 313 262 314 char szPath[RTPATH_MAX]; -
trunk/src/VBox/Runtime/tools/Makefile.kmk
r69603 r69716 113 113 endif 114 114 115 # RTMkDir - our mkdir clone. 116 PROGRAMS += RTMkDir 117 RTMkDir_TEMPLATE = VBoxR3Tool 118 RTMkDir_SOURCES = RTMkDir.cpp 119 115 120 # RTShutdown - similar (but not identical) to a typical unix shutdown command. 116 121 PROGRAMS += RTShutdown
Note:
See TracChangeset
for help on using the changeset viewer.