Changeset 34716 in vbox
- Timestamp:
- Dec 3, 2010 11:33:04 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 68519
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/USBGetDevices.cpp
r34456 r34716 48 48 49 49 #include <dirent.h> 50 #include <dlfcn.h> 50 51 #include <errno.h> 51 52 #include <fcntl.h> … … 473 474 474 475 /** Just a worker for USBProxyServiceLinux::getDevices that avoids some code duplication. */ 475 static int addDeviceToChain(PUSBDEVICE pDev, PUSBDEVICE *ppFirst, PUSBDEVICE **pppNext, const char *pcszUsbfsRoot, int rc)476 static int addDeviceToChain(PUSBDEVICE pDev, PUSBDEVICE *ppFirst, PUSBDEVICE **pppNext, const char *pcszUsbfsRoot, bool testfs, int rc) 476 477 { 477 478 /* usbDeterminState requires the address. */ … … 483 484 { 484 485 pDevNew->enmState = usbDeterminState(pDevNew); 485 if (pDevNew->enmState != USBDEVICESTATE_UNSUPPORTED )486 if (pDevNew->enmState != USBDEVICESTATE_UNSUPPORTED || testfs) 486 487 { 487 488 if (*pppNext) … … 526 527 527 528 /** 528 * USBProxyService::getDevices() implementation for usbfs. 529 */ 530 static PUSBDEVICE getDevicesFromUsbfs(const char *pcszUsbfsRoot) 529 * USBProxyService::getDevices() implementation for usbfs. The @a testfs flag 530 * tells the function to return information about unsupported devices as well. 531 * This is used as a sanity test to check that a devices file is really what 532 * we expect. 533 */ 534 static PUSBDEVICE getDevicesFromUsbfs(const char *pcszUsbfsRoot, bool testfs) 531 535 { 532 536 PUSBDEVICE pFirst = NULL; … … 593 597 AssertMsg(cHits >= 3 || cHits == 0, ("cHits=%d\n", cHits)); 594 598 if (cHits >= 3) 595 rc = addDeviceToChain(&Dev, &pFirst, &ppNext, pcszUsbfsRoot, rc);599 rc = addDeviceToChain(&Dev, &pFirst, &ppNext, pcszUsbfsRoot, testfs, rc); 596 600 else 597 601 deviceFreeMembers(&Dev); … … 786 790 AssertMsg(cHits >= 3 || cHits == 0, ("cHits=%d\n", cHits)); 787 791 if (cHits >= 3) 788 rc = addDeviceToChain(&Dev, &pFirst, &ppNext, pcszUsbfsRoot, rc);792 rc = addDeviceToChain(&Dev, &pFirst, &ppNext, pcszUsbfsRoot, testfs, rc); 789 793 790 794 /* … … 1343 1347 * USBProxyService::getDevices() implementation for sysfs. 1344 1348 */ 1345 static PUSBDEVICE getDevicesFromSysfs(const char *pcszDevicesRoot )1349 static PUSBDEVICE getDevicesFromSysfs(const char *pcszDevicesRoot, bool testfs) 1346 1350 { 1347 1351 #ifdef VBOX_USB_WITH_SYSFS … … 1367 1371 } 1368 1372 if ( RT_SUCCESS(rc) 1369 && Dev->enmState != USBDEVICESTATE_UNSUPPORTED 1373 && ( Dev->enmState != USBDEVICESTATE_UNSUPPORTED 1374 || testfs) 1370 1375 && Dev->pszAddress != NULL 1371 1376 ) … … 1394 1399 } 1395 1400 1401 /** Is inotify available and working on this system? This is a requirement 1402 * for using USB with sysfs */ 1403 /** @todo test the "inotify in glibc but not in the kernel" case. */ 1404 static bool inotifyAvailable(void) 1405 { 1406 int (*inotify_init)(void); 1407 1408 *(void **)(&inotify_init) = dlsym(RTLD_DEFAULT, "inotify_init"); 1409 if (!inotify_init) 1410 return false; 1411 int fd = inotify_init(); 1412 if (fd == -1) 1413 return false; 1414 close(fd); 1415 return true; 1416 } 1417 1396 1418 PCUSBDEVTREELOCATION USBProxyLinuxGetDeviceRoot(bool fPreferSysfs) 1397 1419 { … … 1399 1421 PCUSBDEVTREELOCATION pcBestSysfs = NULL; 1400 1422 1423 bool fHaveInotify = inotifyAvailable(); 1401 1424 for (unsigned i = 0; i < RT_ELEMENTS(s_aTreeLocations); ++i) 1402 1425 if (!s_aTreeLocations[i].fUseSysfs) … … 1406 1429 PUSBDEVICE pDevices; 1407 1430 1408 pDevices = getDevicesFromUsbfs(s_aTreeLocations[i].szDevicesRoot); 1431 pDevices = getDevicesFromUsbfs(s_aTreeLocations[i].szDevicesRoot, 1432 true); 1409 1433 if (pDevices) 1410 1434 { … … 1416 1440 else 1417 1441 { 1418 if ( !pcBestSysfs 1442 if ( fHaveInotify 1443 && !pcBestSysfs 1419 1444 && RTPathExists(s_aTreeLocations[i].szDevicesRoot)) 1420 pcBestSysfs = &s_aTreeLocations[i]; 1445 { 1446 PUSBDEVICE pDevices; 1447 1448 pDevices = getDevicesFromSysfs(s_aTreeLocations[i].szDevicesRoot, 1449 true); 1450 if (pDevices) 1451 { 1452 pcBestSysfs = &s_aTreeLocations[i]; 1453 deviceListFree(&pDevices); 1454 } 1455 } 1421 1456 } 1422 1457 if (pcBestUsbfs && !fPreferSysfs) … … 1430 1465 { 1431 1466 if (!fUseSysfs) 1432 return getDevicesFromUsbfs(pcszDevicesRoot );1467 return getDevicesFromUsbfs(pcszDevicesRoot, false); 1433 1468 else 1434 return getDevicesFromSysfs(pcszDevicesRoot );1435 } 1469 return getDevicesFromSysfs(pcszDevicesRoot, false); 1470 }
Note:
See TracChangeset
for help on using the changeset viewer.