Changeset 100317 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- Jun 28, 2023 10:34:21 AM (23 months ago)
- svn:sync-xref-src-repo-rev:
- 158032
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp
r99828 r100317 55 55 #include <iprt/sort.h> 56 56 #include <iprt/string.h> 57 #include <iprt/system.h> 57 58 #include <VBox/err.h> 58 59 #include <VBox/VBoxGuestLib.h> … … 68 69 # include <os2emx.h> 69 70 #else 71 # include <alloca.h> 70 72 # include <errno.h> 71 73 # include <grp.h> … … 387 389 if (RT_SUCCESS(rc)) 388 390 { 391 uint32_t cbOpts = RTSystemGetPageSize(); 392 char *pszOpts = (char *)alloca(cbOpts); 393 RT_BZERO(pszOpts, cbOpts); 394 389 395 # ifdef RT_OS_SOLARIS 390 396 int const fFlags = MS_OPTIONSTR; 391 char szOptBuf[MAX_MNTOPT_STR] = { '\0', }; 392 RTStrPrintf(szOptBuf, sizeof(szOptBuf), "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", grp_vboxsf->gr_gid); 397 RTStrPrintf(pszOptBuf, sizeof(szOptBuf), "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", grp_vboxsf->gr_gid); 393 398 int r = mount(pszShareName, 394 399 pszMountPoint, … … 397 402 NULL, /* char *dataptr */ 398 403 0, /* int datalen */ 399 szOptBuf,400 sizeof(szOptBuf));404 pszOpts, 405 cbOpts); 401 406 if (r == 0) 402 407 VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", pszShareName, pszMountPoint); … … 410 415 411 416 unsigned long const fFlags = MS_NODEV; 412 char szOpts[MAX_MNTOPT_STR] = { '\0' }; 413 ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts), "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", 417 ssize_t cchOpts = RTStrPrintf2(pszOpts, cbOpts, "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000", 414 418 grp_vboxsf->gr_gid); 415 419 if (cchOpts > 0 && RTStrVersionCompare(uts.release, "2.6.0") < 0) 416 cchOpts = RTStrPrintf2(& szOpts[cchOpts], sizeof(szOpts)- cchOpts, ",sf_name=%s", pszShareName);420 cchOpts = RTStrPrintf2(&pszOpts[cchOpts], cbOpts - cchOpts, ",sf_name=%s", pszShareName); 417 421 if (cchOpts <= 0) 418 422 { 419 VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd (share %s)\n", cchOpts, pszShareName);423 VGSvcError("vbsvcAutomounterMountIt: pszOpts overflow! %zd (share %s)\n", cchOpts, pszShareName); 420 424 return VERR_BUFFER_OVERFLOW; 421 425 } … … 425 429 "vboxsf", 426 430 fFlags, 427 szOpts);431 pszOpts); 428 432 if (r == 0) 429 433 { 430 434 VGSvcVerbose(0, "vbsvcAutoMountWorker: Shared folder '%s' was mounted to '%s'\n", pszShareName, pszMountPoint); 431 435 432 r = vbsfmount_complete(pszShareName, pszMountPoint, fFlags, szOpts);436 r = vbsfmount_complete(pszShareName, pszMountPoint, fFlags, pszOpts); 433 437 switch (r) 434 438 { … … 1465 1469 } 1466 1470 1471 /* 1472 * Allocate options string buffer which is limited to a page on most systems. 1473 */ 1474 uint32_t cbOpts = RTSystemGetPageSize(); 1475 char *pszOpts = (char *)alloca(cbOpts); 1476 1467 1477 # if defined(RT_OS_LINUX) 1468 1478 /* … … 1474 1484 /* Built mount option string. Need st_name for pre 2.6.0 kernels. */ 1475 1485 unsigned long const fFlags = MS_NODEV; 1476 char szOpts[MAX_MNTOPT_STR] = { '\0' }; 1477 ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts), 1486 ssize_t cchOpts = RTStrPrintf2(pszOpts, cbOpts, 1478 1487 "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000,tag=%s", gidMount, g_szTag); 1479 1488 if (RTStrVersionCompare(uts.release, "2.6.0") < 0 && cchOpts > 0) 1480 cchOpts += RTStrPrintf2(& szOpts[cchOpts], sizeof(szOpts)- cchOpts, ",sf_name=%s", pEntry->pszName);1489 cchOpts += RTStrPrintf2(&pszOpts[cchOpts], cbOpts - cchOpts, ",sf_name=%s", pEntry->pszName); 1481 1490 if (cchOpts <= 0) 1482 1491 { 1483 VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd\n", cchOpts);1492 VGSvcError("vbsvcAutomounterMountIt: pszOpts overflow! %zd\n", cchOpts); 1484 1493 return VERR_BUFFER_OVERFLOW; 1485 1494 } … … 1488 1497 which lagged a lot behind when it first appeared in 5.6. */ 1489 1498 errno = 0; 1490 rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, szOpts);1499 rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, pszOpts); 1491 1500 if (rc != 0 && errno == EINVAL && RTStrVersionCompare(uts.release, "5.6.0") >= 0) 1492 1501 { 1493 1502 VGSvcVerbose(2, "vbsvcAutomounterMountIt: mount returned EINVAL, retrying without the tag.\n"); 1494 *strstr( szOpts, ",tag=") = '\0';1503 *strstr(pszOpts, ",tag=") = '\0'; 1495 1504 errno = 0; 1496 rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, szOpts);1505 rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, "vboxsf", fFlags, pszOpts); 1497 1506 if (rc == 0) 1498 1507 VGSvcVerbose(0, "vbsvcAutomounterMountIt: Running outdated vboxsf module without support for the 'tag' option?\n"); … … 1504 1513 1505 1514 errno = 0; 1506 rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, szOpts);1515 rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, pszOpts); 1507 1516 if (rc != 0) /* Ignorable. /etc/mtab is probably a link to /proc/mounts. */ 1508 1517 VGSvcVerbose(1, "vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n", … … 1529 1538 * with EOVERFLOW in vfs_buildoptionstr() during domount() otherwise. 1530 1539 */ 1531 char szOpts[MAX_MNTOPT_STR] = { '\0', }; 1532 ssize_t cchOpts = RTStrPrintf2(szOpts, sizeof(szOpts), 1540 ssize_t cchOpts = RTStrPrintf2(pszOpts, cbOpts, 1533 1541 "uid=0,gid=%d,dmode=0770,fmode=0770,dmask=0000,fmask=0000,tag=%s", gidMount, g_szTag); 1534 1542 if (cchOpts <= 0) 1535 1543 { 1536 VGSvcError("vbsvcAutomounterMountIt: szOpts overflow! %zd\n", cchOpts);1544 VGSvcError("vbsvcAutomounterMountIt: pszOpts overflow! %zd\n", cchOpts); 1537 1545 return VERR_BUFFER_OVERFLOW; 1538 1546 } 1539 1547 1540 1548 rc = mount(pEntry->pszName, pEntry->pszActualMountPoint, MS_OPTIONSTR, "vboxfs", 1541 NULL /*dataptr*/, 0 /* datalen */, szOpts, MAX_MNTOPT_STR);1549 NULL /*dataptr*/, 0 /* datalen */, pszOpts, MAX_MNTOPT_STR); 1542 1550 if (rc == 0) 1543 1551 { … … 1548 1556 1549 1557 rc = errno; 1550 VGSvcError("vbsvcAutomounterMountIt: mount failed for '%s' on '%s' ( szOpts=%s): %s (%d)\n",1551 pEntry->pszName, pEntry->pszActualMountPoint, szOpts, strerror(rc), rc);1558 VGSvcError("vbsvcAutomounterMountIt: mount failed for '%s' on '%s' (pszOpts=%s): %s (%d)\n", 1559 pEntry->pszName, pEntry->pszActualMountPoint, pszOpts, strerror(rc), rc); 1552 1560 return VERR_OPEN_FAILED; 1553 1561
Note:
See TracChangeset
for help on using the changeset viewer.