Changeset 75433 in vbox
- Timestamp:
- Nov 13, 2018 10:34:39 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 126586
- Location:
- trunk/src/VBox/Additions
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp
r75415 r75433 169 169 /** The attachment tag we use to identify attchments that belongs to us. */ 170 170 static char const g_szTag[] = "VBoxAutomounter"; 171 #elif defined(RT_OS_LINUX) 172 /** Tag option value that lets us identify mounts that belongs to us. */ 173 static char const g_szTag[] = "VBoxAutomounter"; 171 174 #elif defined(RT_OS_SOLARIS) 172 175 /** Dummy mount option that lets us identify mounts that belongs to us. */ … … 433 436 mntinf.dmask = Opts.dmask; 434 437 mntinf.fmask = Opts.fmask; 438 mntinf.tag[0] = '\0'; 435 439 436 440 strcpy(mntinf.name, pszShareName); … … 958 962 * but later we may use the same approach as on solaris. 959 963 */ 960 char szMountPrefix[RTPATH_MAX]; 961 rc = vbsvcAutomounterQueryMountDirAndPrefix(szMountPrefix, sizeof(szMountPrefix)); 962 AssertRCReturn(rc, rc); 963 size_t const cchMountPrefix = strlen(szMountPrefix); 964 965 FILE *pFile = setmntent(_PATH_MOUNTED, "r"); 964 FILE *pFile = setmntent("/proc/mounts", "r"); 965 if (!pFile) 966 pFile = setmntent("/etc/mtab", "r"); 966 967 if (pFile) 967 968 { … … 970 971 while ((pEntry = getmntent(pFile)) != NULL) 971 972 if (strcmp(pEntry->mnt_type, "vboxsf") == 0) 972 { 973 /** @todo add mount option for tagging a mount, make kernel show it by 974 * implementing super_operations::show_options. */ 975 if (strncmp(pEntry->mnt_dir, szMountPrefix, cchMountPrefix) == 0) 973 if (strstr(pEntry->mnt_opts, g_szTag) != NULL) 976 974 { 977 975 rc = vbsvcAutomounterAddEntry(pMountTable, pEntry->mnt_fsname, pEntry->mnt_dir); … … 982 980 } 983 981 } 984 }985 982 endmntent(pFile); 986 983 } … … 988 985 VGSvcError("vbsvcAutomounterQueryMountPoint: Could not open mount tab '%s' (errno=%d) or '/proc/mounts' (errno=%d)\n", 989 986 _PATH_MOUNTED, errno); 990 return rc;991 987 992 988 #elif defined(RT_OS_SOLARIS) … … 1159 1155 if (RTStrICmp(pszMountedName, pszName) == 0) 1160 1156 { 1161 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",1157 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n", 1162 1158 pszMountPoint, pszName); 1163 1159 rc = VINF_SUCCESS; … … 1223 1219 if (RTStrICmp(pszMountedName, pszName) == 0) 1224 1220 { 1225 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",1221 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n", 1226 1222 pszMountPoint, pszName); 1227 1223 rc = VINF_SUCCESS; … … 1255 1251 * match file system and device/share. 1256 1252 */ 1257 FILE *pFile = setmntent( _PATH_MOUNTED, "r");1253 FILE *pFile = setmntent("/proc/mounts", "r"); 1258 1254 int rc = errno; 1259 1255 if (!pFile) 1260 pFile = setmntent( "/proc/mounts", "r");1256 pFile = setmntent(_PATH_MOUNTED, "r"); 1261 1257 if (pFile) 1262 1258 { … … 1270 1266 if (RTStrICmp(pEntry->mnt_fsname, pszName) == 0) 1271 1267 { 1272 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",1268 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n", 1273 1269 pszMountPoint, pszName); 1274 1270 rc = VINF_SUCCESS; … … 1293 1289 else 1294 1290 { 1295 VGSvcError("vbsvcAutomounterQueryMountPoint: Could not open mount tab ' %s' (errno=%d) or '/proc/mounts' (errno=%d)\n",1296 _PATH_MOUNTED, rc, errno);1291 VGSvcError("vbsvcAutomounterQueryMountPoint: Could not open mount tab '/proc/mounts' (errno=%d) or '%s' (errno=%d)\n", 1292 rc, _PATH_MOUNTED, errno); 1297 1293 rc = VERR_ACCESS_DENIED; 1298 1294 } … … 1316 1312 if (RTStrICmp(Entry.mnt_special, pszName) == 0) 1317 1313 { 1318 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s' as expected.\n",1314 VGSvcVerbose(3, "vbsvcAutomounterQueryMountPoint: Found shared folder '%s' at '%s'.\n", 1319 1315 pszMountPoint, pszName); 1320 1316 rc = VINF_SUCCESS; … … 1478 1474 MntInfo.dmask = MntOpts.dmask = 0000; 1479 1475 MntInfo.fmask = MntOpts.fmask = 0000; 1476 memcpy(MntInfo.tag, g_szTag, sizeof(g_szTag)); AssertCompile(sizeof(MntInfo.tag) >= sizeof(g_szTag)); 1480 1477 rc = RTStrCopy(MntInfo.name, sizeof(MntInfo.name), pEntry->pszName); 1481 1478 if (RT_FAILURE(rc)) … … 1495 1492 errno = 0; 1496 1493 rc = vbsfmount_complete(pEntry->pszName, pEntry->pszActualMountPoint, fFlags, &MntOpts); 1497 if (rc == 0) 1498 return VINF_SUCCESS; 1499 1500 VGSvcError("vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n", 1501 rc == 1 ? "open_memstream" : rc == 2 ? "setmntent" : rc == 3 ? "addmntent" : "unknown", rc, errno); 1494 if (rc != 0) /* Ignorable. /etc/mtab is probably a link to /proc/mounts. */ 1495 VGSvcVerbose(1, "vbsvcAutomounterMountIt: vbsfmount_complete failed: %s (%d/%d)\n", 1496 rc == 1 ? "open_memstream" : rc == 2 ? "setmntent" : rc == 3 ? "addmntent" : "unknown", rc, errno); 1497 return VINF_SUCCESS; 1502 1498 } 1503 1499 else if (errno == EINVAL) … … 1630 1626 * Path based #2: Mount dir + prefix + share. 1631 1627 */ 1632 /* Mount base directory: */ 1633 szActualMountPoint[0] = '\0'; 1634 char *pszProp; 1635 rc = VbglR3SharedFolderGetMountDir(&pszProp); 1628 rc = vbsvcAutomounterQueryMountDirAndPrefix(szActualMountPoint, sizeof(szActualMountPoint)); 1636 1629 if (RT_SUCCESS(rc)) 1637 1630 { 1638 if (*pszProp == '/') 1639 rc = RTPathAbs(pszProp, szActualMountPoint, sizeof(szActualMountPoint)); 1640 else 1641 VGSvcError("vbsvcAutomounterMountNewEntry: Invalid mount directory: '%s'\n", pszProp); 1642 RTStrFree(pszProp); 1643 } 1644 if (RT_FAILURE(rc) || szActualMountPoint[0] != '/') 1645 memcpy(szActualMountPoint, VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR, sizeof(VBOXSERVICE_AUTOMOUNT_DEFAULT_DIR)); 1646 1647 /* Add prefix: */ 1648 rc = VbglR3SharedFolderGetMountPrefix(&pszProp); 1649 if (RT_SUCCESS(rc)) 1650 { 1651 if ( strchr(pszProp, '/') == NULL 1652 && strchr(pszProp, '\\') == NULL 1653 && strcmp(pszProp, "..") != 0) 1654 rc = RTPathAppend(szActualMountPoint, sizeof(szActualMountPoint), pszProp); 1655 else 1656 VGSvcError("vbsvcAutomounterMountNewEntry: Invalid mount prefix: '%s'\n", pszProp); 1657 RTStrFree(pszProp); 1658 } 1659 else 1660 rc = RTPathEnsureTrailingSeparator(szActualMountPoint, sizeof(szActualMountPoint)) != 0 1661 ? VINF_SUCCESS : VERR_BUFFER_OVERFLOW; 1662 if (RT_SUCCESS(rc)) 1663 { 1664 /* Add sanitized share name: */ 1631 /* Append a sanitized share name: */ 1665 1632 size_t const offShare = strlen(szActualMountPoint); 1666 1633 size_t offDst = offShare; … … 1824 1791 int rc2 = umount(pszMountPoint); 1825 1792 if (rc2 == 0) 1793 { 1794 /* Remove the mount directory if not directly under the root dir. */ 1795 RTPATHPARSED Parsed = { 0 }; 1796 RTPathParse(pszMountPoint, &Parsed, sizeof(Parsed), RTPATH_STR_F_STYLE_HOST); 1797 if (Parsed.cComps >= 3) 1798 RTDirRemove(pszMountPoint); 1799 1826 1800 return VINF_SUCCESS; 1801 } 1827 1802 rc2 = errno; 1828 1803 VGSvcVerbose(2, "vbsvcAutomounterUnmount: umount failed on '%s' ('%s'): %d\n", pszMountPoint, pszName, rc2); … … 1865 1840 Assert(iTable < pTable->cEntries); 1866 1841 PVBSVCAUTOMOUNTERENTRY pEntry = pTable->papEntries[iTable]; 1867 VGSvcVerbose( 3, "vbsvcAutomounterUnmountEntry: #%u: '%s' at '%s' (reason: %s)\n",1868 iTable, pEntry->pszName, pEntry->psz MountPoint, pszReason);1842 VGSvcVerbose(2, "vbsvcAutomounterUnmountEntry: #%u: '%s' at '%s' (reason: %s)\n", 1843 iTable, pEntry->pszName, pEntry->pszActualMountPoint, pszReason); 1869 1844 1870 1845 /* … … 1876 1851 if (rc == VERR_TRY_AGAIN) 1877 1852 { 1878 VGSvcVerbose( 2, "vbsvcAutomounterUnmountEntry: Keeping '%s' -> '%s' (VERR_TRY_AGAIN)\n",1853 VGSvcVerbose(1, "vbsvcAutomounterUnmountEntry: Keeping '%s' -> '%s' (VERR_TRY_AGAIN)\n", 1879 1854 pEntry->pszActualMountPoint, pEntry->pszName); 1880 1855 return iTable + 1; -
trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c
r69500 r75433 402 402 mntinf.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2; 403 403 mntinf.length = sizeof(mntinf); 404 mntinf.tag[0] = '\0'; 404 405 405 406 if (getuid()) -
trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.h
r72627 r75433 59 59 int dmask; /* umask applied to directories */ 60 60 int fmask; /* umask applied to regular files */ 61 char tag[32]; /**< Mount tag for VBoxService automounter. @since 6.0 */ 61 62 }; 62 63 -
trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.c
r75407 r75433 156 156 sf_g->gid = info->gid; 157 157 158 if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) {158 if ((unsigned)info->length >= RT_UOFFSETOF(struct vbsf_mount_info_new, tag)) { 159 159 /* new fields */ 160 160 sf_g->dmode = info->dmode; … … 165 165 sf_g->dmode = ~0; 166 166 sf_g->fmode = ~0; 167 } 168 169 if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) { 170 AssertCompile(sizeof(sf_g->tag) >= sizeof(info->tag)); 171 memcpy(sf_g->tag, info->tag, sizeof(info->tag)); 172 sf_g->tag[sizeof(sf_g->tag) - 1] = '\0'; 173 } else { 174 sf_g->tag[0] = '\0'; 167 175 } 168 176 … … 457 465 sf_g->gid = info->gid; 458 466 sf_g->ttl = info->ttl; 459 sf_g->dmode = info->dmode; 460 sf_g->fmode = info->fmode; 461 sf_g->dmask = info->dmask; 462 sf_g->fmask = info->fmask; 467 if ((unsigned)info->length >= RT_UOFFSETOF(struct vbsf_mount_info_new, tag)) { 468 sf_g->dmode = info->dmode; 469 sf_g->fmode = info->fmode; 470 sf_g->dmask = info->dmask; 471 sf_g->fmask = info->fmask; 472 } else { 473 sf_g->dmode = ~0; 474 sf_g->fmode = ~0; 475 } 476 if ((unsigned)info->length >= sizeof(struct vbsf_mount_info_new)) { 477 AssertCompile(sizeof(sf_g->tag) >= sizeof(info->tag)); 478 memcpy(sf_g->tag, info->tag, sizeof(info->tag)); 479 sf_g->tag[sizeof(sf_g->tag) - 1] = '\0'; 480 } else { 481 sf_g->tag[0] = '\0'; 482 } 463 483 } 464 484 } … … 479 499 } 480 500 501 /** Show mount options. */ 502 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) 503 static int sf_show_options(struct seq_file *m, struct vfsmount *mnt) 504 #else 505 static int sf_show_options(struct seq_file *m, struct dentry *root) 506 #endif 507 { 508 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) 509 struct super_block *sb = mnt->mnt_sb; 510 #else 511 struct super_block *sb = root->d_sb; 512 #endif 513 struct sf_glob_info *sf_g = GET_GLOB_INFO(sb); 514 if (sf_g) { 515 seq_printf(m, ",uid=%u,gid=%u,ttl=%u,dmode=0%o,fmode=0%o,dmask=0%o,fmask=0%o", 516 sf_g->uid, sf_g->gid, sf_g->ttl, sf_g->dmode, sf_g->fmode, sf_g->dmask, sf_g->fmask); 517 if (sf_g->tag[0] != '\0') { 518 seq_puts(m, ",tag="); 519 seq_escape(m, sf_g->tag, " \t\n\\"); 520 } 521 } 522 523 return 0; 524 } 525 481 526 /** @todo Implement show_options (forever) or maybe set s_options (2.6.25+). 482 527 * Necessary for the automounter tagging. */ … … 492 537 .put_super = sf_put_super, 493 538 .statfs = sf_statfs, 494 .remount_fs = sf_remount_fs 539 .remount_fs = sf_remount_fs, 540 .show_options = sf_show_options 495 541 }; 496 542 -
trunk/src/VBox/Additions/linux/sharedfolders/vfsmod.h
r72627 r75433 58 58 struct backing_dev_info bdi; 59 59 #endif 60 char tag[32]; /**< Mount tag for VBoxService automounter. @since 6.0 */ 60 61 }; 61 62
Note:
See TracChangeset
for help on using the changeset viewer.