Changeset 36958 in vbox
- Timestamp:
- May 4, 2011 2:50:32 PM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/USBGetDevices.h
r34341 r36958 75 75 RT_C_DECLS_BEGIN 76 76 77 /** List of well-known USB device tree locations */78 typedef struct USBDEVTREELOCATION79 {80 /** The root of the device tree for this location. */81 char szDevicesRoot[256];82 /** Whether this location requires device enumeration using sysfs. */83 bool fUseSysfs;84 } USBDEVTREELOCATION, *PUSBDEVTREELOCATION;85 typedef const USBDEVTREELOCATION *PCUSBDEVTREELOCATION;86 87 77 /** 88 * Get the USB device tree root89 * @param fPreferSysfs whether we wish to use sysfs over usbfs for90 * enumeration if we have the choice91 * @note 78 * Check whether a USB device tree root is usable 79 * @param pcszRoot the path to the root of the device tree 80 * @param fIsDeviceNodes whether this is a device node (or usbfs) tree 81 * @note returns a pointer into a static array so it will stay valid 92 82 */ 93 extern PCUSBDEVTREELOCATION USBProxyLinuxGetDeviceRoot(bool fPreferSysfs); 83 extern bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot, 84 bool fIsDeviceNodes); 94 85 95 86 /** … … 97 88 * @a deviceFree or something equivalent. 98 89 * @param pcszDevicesRoot the path to the root of the device tree 99 * @param fUseSysfs whether to use sysfs (or usbfs) for enumeration90 * @param fUseSysfs whether to use sysfs (or usbfs) for enumeration 100 91 */ 101 92 extern PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot, -
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 } -
trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
r36348 r36958 128 128 RTPrintf ("\n"); 129 129 } 130 PCUSBDEVTREELOCATION pcLocation = USBProxyLinuxGetDeviceRoot(false);131 if ( pcLocation && !pcLocation->fUseSysfs)130 RTPrintf("NOTE: checking for usbfs at /dev/bus/usb, not /proc/bus/usb!!!\n"); 131 if (USBProxyLinuxCheckDeviceRoot("/dev/bus/usb", false)) 132 132 { 133 PUSBDEVICE pDevice = USBProxyLinuxGetDevices( pcLocation->szDevicesRoot,133 PUSBDEVICE pDevice = USBProxyLinuxGetDevices("/dev/bus/usb", 134 134 false); 135 printDevices(pDevice, pcLocation->szDevicesRoot, "usbfs");135 printDevices(pDevice, "/dev/bus/usb", "usbfs"); 136 136 freeDevices(pDevice); 137 137 } 138 else 139 RTPrintf("-> not found\n"); 138 140 #ifdef VBOX_USB_WITH_SYSFS 139 pcLocation = USBProxyLinuxGetDeviceRoot(true);140 if ( pcLocation && pcLocation->fUseSysfs)141 RTPrintf("Testing for USB devices at /dev/vboxusb\n"); 142 if (USBProxyLinuxCheckDeviceRoot("/dev/vboxusb", true)) 141 143 { 142 PUSBDEVICE pDevice = USBProxyLinuxGetDevices( pcLocation->szDevicesRoot,144 PUSBDEVICE pDevice = USBProxyLinuxGetDevices("/dev/vboxusb", 143 145 true); 144 printDevices(pDevice, pcLocation->szDevicesRoot, "sysfs");146 printDevices(pDevice, "/dev/vboxusb", "sysfs"); 145 147 freeDevices(pDevice); 146 148 } 147 VBoxMainHotplugWaiter waiter(pcLocation->szDevicesRoot); 149 else 150 RTPrintf("-> not found\n"); 151 VBoxMainHotplugWaiter waiter("/dev/vboxusb"); 148 152 RTPrintf ("Waiting for a hotplug event for five seconds...\n"); 149 153 doHotplugEvent(&waiter, 5000); -
trunk/src/VBox/Main/testcase/tstUSBProxyLinux.cpp
r36419 r36958 62 62 } 63 63 64 static USBDEVTREELOCATION s_deviceRoot = { "", false };65 static bool s_f GetDeviceRootPreferSysfs = false;64 static const char *s_pcszDeviceRoot = ""; 65 static bool s_fIsDeviceNodes = false; 66 66 67 PCUSBDEVTREELOCATION USBProxyLinuxGetDeviceRoot(bool fPreferSysfs) 67 bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot, 68 bool fIsDeviceNodes) 68 69 { 69 s_fGetDeviceRootPreferSysfs = fPreferSysfs;70 return &s_deviceRoot;70 return ( (!strcmp(s_pcszDeviceRoot, pcszRoot)) 71 && (s_fIsDeviceNodes == fIsDeviceNodes)); 71 72 } 72 73 … … 153 154 else 154 155 RTEnvUnset("VBOX_USB_ROOT"); 155 strcpy(s_deviceRoot.szDevicesRoot, 156 s_testEnvironment[i].pcszReturnedRoot); 157 s_deviceRoot.fUseSysfs = s_testEnvironment[i].fReturnedUseSysfs; 156 s_pcszDeviceRoot = s_testEnvironment[i].pcszReturnedRoot; 157 s_fIsDeviceNodes = s_testEnvironment[i].fReturnedUseSysfs; 158 158 RTTESTI_CHECK(test.init() == S_OK); 159 159 test.getDevices(); -
trunk/src/VBox/RDP/client/vrdp/rdpusb.c
r36409 r36958 888 888 rdpusb_init(void) 889 889 { 890 PCUSBDEVTREELOCATION pcLocation = USBProxyLinuxGetDeviceRoot(false); 891 g_fUseSysfs = pcLocation->fUseSysfs; 892 g_pcszDevicesRoot = pcLocation->szDevicesRoot; 890 /** @todo re-use the proxy service code */ 891 if (USBProxyLinuxCheckDeviceRoot("/dev/vboxusb", true)) 892 { 893 g_fUseSysfs = true; 894 g_pcszDevicesRoot = "/dev/vboxusb"; 895 } 896 else 897 { 898 g_fUseSysfs = false; 899 g_pcszDevicesRoot = "/proc/bus/usb"; 900 } 893 901 rdpusb_channel = 894 902 channel_register("vrdpusb", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
Note:
See TracChangeset
for help on using the changeset viewer.