Changeset 36958 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- May 4, 2011 2:50:32 PM (14 years ago)
- Location:
- trunk/src/VBox/Main/src-server/linux
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r36417 r36958 93 93 { "s", 1, 1000, 0 }, 94 94 { "", 0, 0, 0 } /* term */ 95 };96 97 /**98 * List of well-known USB device tree locations.99 */100 static const USBDEVTREELOCATION s_aTreeLocations[] =101 {102 { "/dev/vboxusb", true },103 { "/proc/bus/usb", false },104 95 }; 105 96 … … 1401 1392 /** Is inotify available and working on this system? This is a requirement 1402 1393 * for using USB with sysfs */ 1403 /** @todo test the "inotify in glibc but not in the kernel" case. */1404 1394 static bool inotifyAvailable(void) 1405 1395 { … … 1416 1406 } 1417 1407 1418 PCUSBDEVTREELOCATION USBProxyLinuxGetDeviceRoot(bool fPreferSysfs) 1419 { 1420 PCUSBDEVTREELOCATION pcBestUsbfs = NULL; 1421 PCUSBDEVTREELOCATION pcBestSysfs = NULL; 1422 1423 bool fHaveInotify = inotifyAvailable(); 1424 for (unsigned i = 0; i < RT_ELEMENTS(s_aTreeLocations); ++i) 1425 if (!s_aTreeLocations[i].fUseSysfs) 1426 { 1427 if (!pcBestUsbfs) 1428 { 1429 PUSBDEVICE pDevices; 1430 1431 pDevices = getDevicesFromUsbfs(s_aTreeLocations[i].szDevicesRoot, 1432 true); 1433 if (pDevices) 1434 { 1435 pcBestUsbfs = &s_aTreeLocations[i]; 1436 deviceListFree(&pDevices); 1437 } 1438 } 1439 } 1440 else 1441 { 1442 if ( fHaveInotify 1443 && !pcBestSysfs 1444 && RTPathExists(s_aTreeLocations[i].szDevicesRoot)) 1445 pcBestSysfs = &s_aTreeLocations[i]; 1446 } 1447 if (pcBestUsbfs && !fPreferSysfs) 1448 return pcBestUsbfs; 1449 return pcBestSysfs; 1408 bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot, bool fIsDeviceNodes) 1409 { 1410 bool fOK = false; 1411 if (!fIsDeviceNodes) /* usbfs */ 1412 { 1413 PUSBDEVICE pDevices; 1414 1415 pDevices = getDevicesFromUsbfs(pcszRoot, true); 1416 if (pDevices) 1417 { 1418 PUSBDEVICE pDevice; 1419 1420 fOK = true; 1421 for (pDevice = pDevices; pDevice && fOK; pDevice = pDevice->pNext) 1422 if (access(pDevice->pszAddress, R_OK | W_OK)) 1423 fOK = false; 1424 deviceListFree(&pDevices); 1425 } 1426 } 1427 else /* device nodes */ 1428 if (inotifyAvailable() && !access(pcszRoot, R_OK | X_OK)) 1429 fOK = true; 1430 return fOK; 1450 1431 } 1451 1432 -
trunk/src/VBox/Main/src-server/linux/USBProxyServiceLinux.cpp
r36727 r36958 32 32 #include <iprt/assert.h> 33 33 #include <iprt/ctype.h> 34 #include <iprt/dir.h> 34 35 #include <iprt/env.h> 35 36 #include <iprt/file.h> … … 82 83 /* 83 84 * We have two methods available for getting host USB device data - using 84 * USBFS and using sysfs /hal. The default choice depends on build-time85 * USBFS and using sysfs. The default choice depends on build-time 85 86 * settings and an environment variable; if the default is not available 86 87 * we fall back to the second. … … 88 89 * will be presented to the user. 89 90 */ 90 #ifdef VBOX_WITH_SYSFS_BY_DEFAULT 91 bool fUseSysfs = true; 92 #else 93 bool fUseSysfs = false; 94 #endif 91 bool fUseSysfs; 95 92 const char *pcszUsbFromEnv = RTEnvGet("VBOX_USB"); 96 93 const char *pcszUsbRoot = NULL; … … 121 118 if (!pcszUsbRoot) 122 119 { 123 PCUSBDEVTREELOCATION pLocation; 124 pLocation = USBProxyLinuxGetDeviceRoot(fUseSysfs); 125 if (pLocation) 126 { 127 pcszUsbRoot = pLocation->szDevicesRoot; 128 fUseSysfs = pLocation->fUseSysfs; 120 if (USBProxyLinuxCheckDeviceRoot("/dev/vboxusb", true)) 121 { 122 fUseSysfs = true; 123 pcszUsbRoot = "/dev/vboxusb"; 124 } 125 else if (USBProxyLinuxCheckDeviceRoot("/proc/bus/usb", false)) 126 { 127 fUseSysfs = false; 128 pcszUsbRoot = "/proc/bus/usb"; 129 129 } 130 130 } … … 141 141 } 142 142 else 143 mLastError = VERR_NOT_FOUND; 143 /** @todo fix this, preferably in the next fifteen minutes. */ 144 mLastError = RTDirExists("/dev/vboxusb") ? VERR_PERMISSION_DENIED 145 : RTFileExists("/proc/bus/usb/devices") ? VERR_VUSB_USBFS_PERMISSION 146 : VERR_NOT_FOUND; 144 147 return S_OK; 145 148 }
Note:
See TracChangeset
for help on using the changeset viewer.