- Timestamp:
- Nov 24, 2010 8:14:36 PM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostHardwareLinux.h
r33540 r34341 136 136 public: 137 137 /** Constructor. Responsible for selecting the implementation. */ 138 VBoxMainHotplugWaiter (void);138 VBoxMainHotplugWaiter(const char *pcszDevicesRoot); 139 139 /** Destructor. */ 140 140 ~VBoxMainHotplugWaiter (void) -
trunk/src/VBox/Main/include/USBGetDevices.h
r32469 r34341 75 75 RT_C_DECLS_BEGIN 76 76 77 /** List of well-known USB device tree locations */ 78 typedef struct USBDEVTREELOCATION 79 { 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 77 87 /** 78 * Check whether @a pcszDevices is a valid usbfs devices file for checking 79 * whether usbfs is supported or not. 80 * @returns VINF_SUCCESS if it is 81 * @returns VERR_NOT_FOUND if it isn't 82 * @returns iprt status code if an error occurred 83 * @todo test whether USB with sysfs/dev is supported 88 * Get the USB device tree root 89 * @param fPreferSysfs whether we wish to use sysfs over usbfs for 90 * enumeration if we have the choice 91 * @note returns a pointer into a static array so it will stay valid 84 92 */ 85 extern int USBProxyLinuxCheckForUsbfs(const char *pcszDevices);93 extern PCUSBDEVTREELOCATION USBProxyLinuxGetDeviceRoot(bool fPreferSysfs); 86 94 87 95 /** 88 96 * Get the list of USB devices supported by the system. Should be freed using 89 97 * @a deviceFree or something equivalent. 90 * @param pcszUsbfsRoot the path to usbfs, or NULL to use sysfs 98 * @param pcszDevicesRoot the path to the root of the device tree 99 * @param fUseSysfs whether to use sysfs (or usbfs) for enumeration 91 100 */ 92 extern PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszUsbfsRoot); 101 extern PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot, 102 bool fUseSysfs); 93 103 94 104 RT_C_DECLS_END -
trunk/src/VBox/Main/include/USBProxyService.h
r32301 r34341 204 204 { 205 205 public: 206 USBProxyServiceLinux(Host *aHost, 207 const char *aUsbfsRoot = "/proc/bus/usb"); 206 USBProxyServiceLinux(Host *aHost); 208 207 HRESULT init(void); 209 208 ~USBProxyServiceLinux(); … … 234 233 RTFILE mWakeupPipeW; 235 234 /** The root of usbfs. */ 236 Utf8Str m UsbfsRoot;235 Utf8Str mDevicesRoot; 237 236 /** Whether we're using <mUsbfsRoot>/devices or /sys/whatever. */ 238 237 bool mUsingUsbfsDevices; … … 241 240 # ifdef VBOX_USB_WITH_SYSFS 242 241 /** Object used for polling for hotplug events from hal. */ 243 VBoxMainHotplugWaiter mWaiter;242 VBoxMainHotplugWaiter *mpWaiter; 244 243 # endif 245 244 }; -
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r33540 r34341 1054 1054 { 1055 1055 public: 1056 hotplugNullImpl (void) {}1056 hotplugNullImpl(const char *) {} 1057 1057 virtual ~hotplugNullImpl (void) {} 1058 1058 /** @copydoc VBoxMainHotplugWaiter::Wait */ … … 1155 1155 } 1156 1156 1157 # define SYSFS_USB_DEVICE_PATH "/dev/bus/usb"1158 1157 # define SYSFS_WAKEUP_STRING "Wake up!" 1159 1158 … … 1169 1168 * ensure that it isn't called multiple times in parallel. */ 1170 1169 volatile uint32_t mfWaiting; 1170 /** The root of the USB devices tree. */ 1171 const char *mpcszDevicesRoot; 1171 1172 /** iprt result code from object initialisation. Should be AssertReturn-ed 1172 1173 * on at the start of all methods. I went this way because I didn't want … … 1192 1193 int drainWakeupPipe(void); 1193 1194 public: 1194 hotplugInotifyImpl( void);1195 hotplugInotifyImpl(const char *pcszDevicesRoot); 1195 1196 virtual ~hotplugInotifyImpl(void) 1196 1197 { … … 1202 1203 #endif 1203 1204 } 1204 /** Are sysfs and inotify availableon this system? If so we expect that1205 /** Is inotify available and working on this system? If so we expect that 1205 1206 * this implementation will be usable. */ 1207 /** @todo test the "inotify in glibc but not in the kernel" case. */ 1206 1208 static bool Available(void) 1207 1209 { 1208 return ( RTDirExists(SYSFS_USB_DEVICE_PATH) 1209 && dlsym(RTLD_DEFAULT, "inotify_init") != NULL); 1210 int (*inotify_init)(void); 1211 1212 *(void **)(&inotify_init) = dlsym(RTLD_DEFAULT, "inotify_init"); 1213 if (!inotify_init) 1214 return false; 1215 int fd = inotify_init(); 1216 if (fd == -1) 1217 return false; 1218 close(fd); 1219 return true; 1210 1220 } 1211 1221 … … 1252 1262 } 1253 1263 1254 hotplugInotifyImpl::hotplugInotifyImpl( void) :1264 hotplugInotifyImpl::hotplugInotifyImpl(const char *pcszDevicesRoot) : 1255 1265 mhWakeupPipeR(-1), mhWakeupPipeW(-1), mfWaiting(0), 1256 m Status(VERR_WRONG_ORDER)1266 mpcszDevicesRoot(pcszDevicesRoot), mStatus(VERR_WRONG_ORDER) 1257 1267 { 1258 1268 # ifdef DEBUG … … 1269 1279 if (RT_FAILURE(rc = iwInit(&mWatches))) 1270 1280 break; 1271 if (RT_FAILURE(rc = iwAddWatch(&mWatches, SYSFS_USB_DEVICE_PATH)))1281 if (RT_FAILURE(rc = iwAddWatch(&mWatches, mpcszDevicesRoot))) 1272 1282 break; 1273 1283 if (RT_FAILURE(rc = pipeCreateSimple(&mhWakeupPipeR, &mhWakeupPipeW))) … … 1338 1348 struct pollfd pollFD[MAX_POLLID]; 1339 1349 1340 rc = readFilePaths( SYSFS_USB_DEVICE_PATH, &vecpchDevs, false);1350 rc = readFilePaths(mpcszDevicesRoot, &vecpchDevs, false); 1341 1351 if (RT_SUCCESS(rc)) 1342 1352 VEC_FOR_EACH(&vecpchDevs, char *, ppszEntry) … … 1392 1402 #endif /* VBOX_USB_WTH_SYSFS */ 1393 1403 1394 VBoxMainHotplugWaiter::VBoxMainHotplugWaiter( void)1404 VBoxMainHotplugWaiter::VBoxMainHotplugWaiter(const char *pcszDevicesRoot) 1395 1405 { 1396 1406 try … … 1400 1410 if (hotplugInotifyImpl::Available()) 1401 1411 { 1402 mImpl = new hotplugInotifyImpl ;1412 mImpl = new hotplugInotifyImpl(pcszDevicesRoot); 1403 1413 return; 1404 1414 } 1405 1415 # endif /* VBOX_USB_WITH_INOTIFY */ 1406 1416 #endif /* VBOX_USB_WITH_SYSFS */ 1407 mImpl = new hotplugNullImpl ;1417 mImpl = new hotplugNullImpl(pcszDevicesRoot); 1408 1418 } 1409 1419 catch(std::bad_alloc &e) -
trunk/src/VBox/Main/linux/USBGetDevices.cpp
r34165 r34341 34 34 #include <iprt/mem.h> 35 35 #include <iprt/param.h> 36 #include <iprt/path.h> 36 37 #include <iprt/string.h> 37 38 #include "vector.h" … … 93 94 }; 94 95 95 96 int USBProxyLinuxCheckForUsbfs(const char *pcszDevices) 97 { 98 int fd, rc = VINF_SUCCESS; 99 100 fd = open(pcszDevices, O_RDONLY, 00600); 101 if (fd >= 0) 102 { 103 /* 104 * Check that we're actually on the usbfs. 105 */ 106 struct statfs StFS; 107 if (!fstatfs(fd, &StFS)) 108 { 109 if (StFS.f_type != USBDEVICE_SUPER_MAGIC) 110 rc = VERR_NOT_FOUND; 111 } 112 else 113 rc = RTErrConvertFromErrno(errno); 114 close(fd); 115 } 116 else 117 rc = RTErrConvertFromErrno(errno); 118 return rc; 119 } 96 /** 97 * List of well-known USB device tree locations. 98 */ 99 static const USBDEVTREELOCATION s_aTreeLocations[] = 100 { 101 { "/proc/bus/usb", false }, 102 { "/dev/bus/usb", false }, 103 { "/dev/bus/usb", true }, 104 }; 120 105 121 106 … … 870 855 * interface add an element for the device to @a pvecDevInfo. 871 856 */ 872 static int addIfDevice(const char *pcszNode, 857 static int addIfDevice(const char *pcszDevicesRoot, 858 const char *pcszNode, 873 859 VECTOR_OBJ(USBDeviceInfo) *pvecDevInfo) 874 860 { … … 886 872 cchDevPath = RTLinuxFindDevicePath(devnum, RTFS_TYPE_DEV_CHAR, 887 873 szDevPath, sizeof(szDevPath), 888 "/dev/bus/usb/%.3d/%.3d", 874 "%s/%.3d/%.3d", 875 pcszDevicesRoot, 889 876 usbBusFromDevNum(devnum), 890 877 usbDeviceFromDevNum(devnum)); … … 1025 1012 * @param pvecDevInfo vector of device information structures to add device 1026 1013 * information to 1027 * @param pvecpchDevs empty scratch vector which will be freed by the caller 1028 */ 1029 static int doSysfsEnumerateHostDevices(VECTOR_OBJ(USBDeviceInfo) *pvecDevInfo, 1030 VECTOR_PTR(char *) *pvecpchDevs) 1014 * @param pvecpchDevs empty scratch vector which will be freed by the caller, 1015 * to simplify exit logic 1016 */ 1017 static int doSysfsEnumerateHostDevices(const char *pcszDevicesRoot, 1018 VECTOR_OBJ(USBDeviceInfo) *pvecDevInfo, 1019 VECTOR_PTR(char *) *pvecpchDevs) 1031 1020 { 1032 1021 char **ppszEntry; … … 1041 1030 return rc; 1042 1031 VEC_FOR_EACH(pvecpchDevs, char *, ppszEntry) 1043 if (RT_FAILURE(rc = addIfDevice(*ppszEntry, pvecDevInfo))) 1032 if (RT_FAILURE(rc = addIfDevice(pcszDevicesRoot, *ppszEntry, 1033 pvecDevInfo))) 1044 1034 return rc; 1045 1035 VEC_FOR_EACH(pvecDevInfo, USBDeviceInfo, pInfo) … … 1050 1040 } 1051 1041 1052 static int USBSysfsEnumerateHostDevices(VECTOR_OBJ(USBDeviceInfo) *pvecDevInfo) 1042 static int USBSysfsEnumerateHostDevices(const char *pcszDevicesRoot, 1043 VECTOR_OBJ(USBDeviceInfo) *pvecDevInfo) 1053 1044 { 1054 1045 VECTOR_PTR(char *) vecpchDevs; … … 1058 1049 LogFlowFunc(("entered\n")); 1059 1050 VEC_INIT_PTR(&vecpchDevs, char *, RTStrFree); 1060 rc = doSysfsEnumerateHostDevices(pvecDevInfo, &vecpchDevs); 1051 rc = doSysfsEnumerateHostDevices(pcszDevicesRoot, pvecDevInfo, 1052 &vecpchDevs); 1061 1053 VEC_CLEANUP_PTR(&vecpchDevs); 1062 1054 LogFlowFunc(("rc=%Rrc\n", rc)); … … 1350 1342 * USBProxyService::getDevices() implementation for sysfs. 1351 1343 */ 1352 static PUSBDEVICE getDevicesFromSysfs( void)1344 static PUSBDEVICE getDevicesFromSysfs(const char *pcszDevicesRoot) 1353 1345 { 1354 1346 #ifdef VBOX_USB_WITH_SYSFS … … 1361 1353 1362 1354 VEC_INIT_OBJ(&vecDevInfo, USBDeviceInfo, USBDevInfoCleanup); 1363 rc = USBSysfsEnumerateHostDevices( &vecDevInfo);1355 rc = USBSysfsEnumerateHostDevices(pcszDevicesRoot, &vecDevInfo); 1364 1356 if (RT_FAILURE(rc)) 1365 1357 return NULL; … … 1401 1393 } 1402 1394 1403 PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszUsbfsRoot) 1404 { 1405 if (pcszUsbfsRoot) 1406 return getDevicesFromUsbfs(pcszUsbfsRoot); 1395 PCUSBDEVTREELOCATION USBProxyLinuxGetDeviceRoot(bool fPreferSysfs) 1396 { 1397 PCUSBDEVTREELOCATION pcBestUsbfs = NULL; 1398 PCUSBDEVTREELOCATION pcBestSysfs = NULL; 1399 1400 for (unsigned i = 0; i < RT_ELEMENTS(s_aTreeLocations); ++i) 1401 if (!s_aTreeLocations[i].fUseSysfs) 1402 { 1403 if (!pcBestUsbfs) 1404 { 1405 PUSBDEVICE pDevices; 1406 1407 pDevices = getDevicesFromUsbfs(s_aTreeLocations[i].szDevicesRoot); 1408 if (pDevices) 1409 { 1410 pcBestUsbfs = &s_aTreeLocations[i]; 1411 deviceListFree(&pDevices); 1412 } 1413 } 1414 } 1415 else 1416 { 1417 if ( !pcBestSysfs 1418 && RTPathExists(s_aTreeLocations[i].szDevicesRoot)) 1419 pcBestSysfs = &s_aTreeLocations[i]; 1420 } 1421 if (pcBestUsbfs && !fPreferSysfs) 1422 return pcBestUsbfs; 1423 return pcBestSysfs; 1424 } 1425 1426 1427 PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot, 1428 bool fUseSysfs) 1429 { 1430 if (!fUseSysfs) 1431 return getDevicesFromUsbfs(pcszDevicesRoot); 1407 1432 else 1408 return getDevicesFromSysfs( );1409 } 1433 return getDevicesFromSysfs(pcszDevicesRoot); 1434 } -
trunk/src/VBox/Main/linux/USBProxyServiceLinux.cpp
r33540 r34341 55 55 56 56 57 /*******************************************************************************58 * Structures and Typedefs *59 *******************************************************************************/60 /** Suffix translation. */61 typedef struct USBSUFF62 {63 char szSuff[4];64 unsigned cchSuff;65 unsigned uMul;66 unsigned uDiv;67 } USBSUFF, *PUSBSUFF;68 typedef const USBSUFF *PCUSBSUFF;69 70 71 /*******************************************************************************72 * Global Variables *73 *******************************************************************************/74 /**75 * Suffixes for the endpoint polling interval.76 */77 static const USBSUFF s_aIntervalSuff[] =78 {79 { "ms", 2, 1, 0 },80 { "us", 2, 1, 1000 },81 { "ns", 2, 1, 1000000 },82 { "s", 1, 1000, 0 },83 { "", 0, 0, 0 } /* term */84 };85 86 87 57 /** 88 58 * Initialize data members. 89 59 */ 90 USBProxyServiceLinux::USBProxyServiceLinux(Host *aHost , const char *aUsbfsRoot /* = "/proc/bus/usb" */)60 USBProxyServiceLinux::USBProxyServiceLinux(Host *aHost) 91 61 : USBProxyService(aHost), mFile(NIL_RTFILE), mWakeupPipeR(NIL_RTFILE), 92 mWakeupPipeW(NIL_RTFILE), mUsbfsRoot(aUsbfsRoot), mUsingUsbfsDevices(true /* see init */), mUdevPolls(0) 93 { 94 LogFlowThisFunc(("aHost=%p aUsbfsRoot=%p:{%s}\n", aHost, aUsbfsRoot, aUsbfsRoot)); 62 mWakeupPipeW(NIL_RTFILE), mUsingUsbfsDevices(true /* see init */), 63 mUdevPolls(0), mpWaiter(NULL) 64 { 65 LogFlowThisFunc(("aHost=%p:{%s}\n", aHost)); 95 66 } 96 67 … … 118 89 */ 119 90 #ifdef VBOX_WITH_SYSFS_BY_DEFAULT 120 mUsingUsbfsDevices = false;91 bool fUseSysfs = true; 121 92 #else 122 mUsingUsbfsDevices = true;93 bool fUseSysfs = false; 123 94 #endif 124 95 const char *pszUsbFromEnv = RTEnvGet("VBOX_USB"); … … 128 99 { 129 100 LogRel(("Default USB access method set to \"usbfs\" from environment\n")); 130 mUsingUsbfsDevices = true;101 fUseSysfs = false; 131 102 } 132 103 else if (!RTStrICmp(pszUsbFromEnv, "SYSFS")) 133 104 { 134 105 LogRel(("Default USB method set to \"sysfs\" from environment\n")); 135 mUsingUsbfsDevices = false;106 fUseSysfs = true; 136 107 } 137 108 else … … 139 110 pszUsbFromEnv)); 140 111 } 141 int rc = mUsingUsbfsDevices ? initUsbfs() : initSysfs(); 142 if (RT_FAILURE(rc)) 143 { 112 PCUSBDEVTREELOCATION pcLocation = USBProxyLinuxGetDeviceRoot(fUseSysfs); 113 if (pcLocation) 114 { 115 mUsingUsbfsDevices = !pcLocation->fUseSysfs; 116 mDevicesRoot = pcLocation->szDevicesRoot; 117 int rc = mUsingUsbfsDevices ? initUsbfs() : initSysfs(); 144 118 /* For the day when we have VBoxSVC release logging... */ 145 LogRel(("Failed to initialise host USB using %s\n", 119 LogRel((RT_SUCCESS(rc) ? "Successfully initialised host USB using %s\n" 120 : "Failed to initialise host USB using %s\n", 146 121 mUsingUsbfsDevices ? "USBFS" : "sysfs/hal")); 147 mUsingUsbfsDevices = !mUsingUsbfsDevices; 148 rc = mUsingUsbfsDevices ? initUsbfs() : initSysfs(); 149 } 150 LogRel((RT_SUCCESS(rc) ? "Successfully initialised host USB using %s\n" 151 : "Failed to initialise host USB using %s\n", 152 mUsingUsbfsDevices ? "USBFS" : "sysfs/hal")); 153 mLastError = rc; 122 mLastError = rc; 123 } 124 else 125 mLastError = VERR_NOT_FOUND; 154 126 return S_OK; 155 127 } … … 169 141 */ 170 142 int rc; 171 char *pszDevices = RTPathJoinA(m UsbfsRoot.c_str(), "devices");143 char *pszDevices = RTPathJoinA(mDevicesRoot.c_str(), "devices"); 172 144 if (pszDevices) 173 145 { 174 rc = USBProxyLinuxCheckForUsbfs(pszDevices);146 rc = RTFileOpen(&mFile, pszDevices, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE); 175 147 if (RT_SUCCESS(rc)) 176 148 { 177 rc = RTFileOpen(&mFile, pszDevices, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);178 if ( RT_SUCCESS(rc))149 int pipes[2]; 150 if (!pipe(pipes)) 179 151 { 180 int pipes[2]; 181 if (!pipe(pipes)) 152 /* Set close on exec (race here!) */ 153 if ( fcntl(pipes[0], F_SETFD, FD_CLOEXEC) >= 0 154 && fcntl(pipes[1], F_SETFD, FD_CLOEXEC) >= 0) 182 155 { 183 /* Set close on exec (race here!) */ 184 if ( fcntl(pipes[0], F_SETFD, FD_CLOEXEC) >= 0 185 && fcntl(pipes[1], F_SETFD, FD_CLOEXEC) >= 0) 156 mWakeupPipeR = pipes[0]; 157 mWakeupPipeW = pipes[1]; 158 /* 159 * Start the poller thread. 160 */ 161 rc = start(); 162 if (RT_SUCCESS(rc)) 186 163 { 187 mWakeupPipeR = pipes[0]; 188 mWakeupPipeW = pipes[1]; 189 /* 190 * Start the poller thread. 191 */ 192 rc = start(); 193 if (RT_SUCCESS(rc)) 194 { 195 RTStrFree(pszDevices); 196 LogFlowThisFunc(("returns successfully - mWakeupPipeR/W=%d/%d\n", 197 mWakeupPipeR, mWakeupPipeW)); 198 return VINF_SUCCESS; 199 } 200 201 RTFileClose(mWakeupPipeR); 202 RTFileClose(mWakeupPipeW); 203 mWakeupPipeW = mWakeupPipeR = NIL_RTFILE; 164 RTStrFree(pszDevices); 165 LogFlowThisFunc(("returns successfully - mWakeupPipeR/W=%d/%d\n", 166 mWakeupPipeR, mWakeupPipeW)); 167 return VINF_SUCCESS; 204 168 } 205 else 206 { 207 rc = RTErrConvertFromErrno(errno); 208 Log(("USBProxyServiceLinux::USBProxyServiceLinux: fcntl failed, errno=%d\n", errno)); 209 close(pipes[0]); 210 close(pipes[1]); 211 } 169 170 RTFileClose(mWakeupPipeR); 171 RTFileClose(mWakeupPipeW); 172 mWakeupPipeW = mWakeupPipeR = NIL_RTFILE; 212 173 } 213 174 else 214 175 { 215 176 rc = RTErrConvertFromErrno(errno); 216 Log(("USBProxyServiceLinux::USBProxyServiceLinux: pipe failed, errno=%d\n", errno)); 177 Log(("USBProxyServiceLinux::USBProxyServiceLinux: fcntl failed, errno=%d\n", errno)); 178 close(pipes[0]); 179 close(pipes[1]); 217 180 } 218 RTFileClose(mFile);219 181 } 220 182 else 183 { 184 rc = RTErrConvertFromErrno(errno); 185 Log(("USBProxyServiceLinux::USBProxyServiceLinux: pipe failed, errno=%d\n", errno)); 186 } 187 RTFileClose(mFile); 221 188 } 189 222 190 RTStrFree(pszDevices); 223 191 } … … 243 211 244 212 #ifdef VBOX_USB_WITH_SYSFS 245 int rc = mWaiter.getStatus(); 213 try 214 { 215 mpWaiter = new VBoxMainHotplugWaiter(mDevicesRoot.c_str()); 216 } 217 catch(std::bad_alloc &e) 218 { 219 return VERR_NO_MEMORY; 220 } 221 int rc = mpWaiter->getStatus(); 246 222 if (RT_SUCCESS(rc) || rc == VERR_TIMEOUT || rc == VERR_TRY_AGAIN) 247 223 rc = start(); … … 275 251 */ 276 252 doUsbfsCleanupAsNeeded(); 277 278 /* (No extra work for !mUsingUsbfsDevices.) */ 253 #ifdef VBOX_USB_WITH_SYSFS 254 if (mpWaiter) 255 delete mpWaiter; 256 #endif 279 257 } 280 258 … … 417 395 { 418 396 #ifdef VBOX_USB_WITH_SYSFS 419 int rc = m Waiter.Wait(aMillies);397 int rc = mpWaiter->Wait(aMillies); 420 398 if (rc == VERR_TRY_AGAIN) 421 399 { … … 436 414 if (!mUsingUsbfsDevices) 437 415 { 438 m Waiter.Interrupt();416 mpWaiter->Interrupt(); 439 417 LogFlowFunc(("Returning VINF_SUCCESS\n")); 440 418 return VINF_SUCCESS; … … 451 429 PUSBDEVICE USBProxyServiceLinux::getDevices(void) 452 430 { 453 if (mUsingUsbfsDevices) 454 return USBProxyLinuxGetDevices(mUsbfsRoot.c_str()); 455 else 456 return USBProxyLinuxGetDevices(NULL); 457 } 458 431 return USBProxyLinuxGetDevices(mDevicesRoot.c_str(), !mUsingUsbfsDevices); 432 } -
trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
r32324 r34341 55 55 } 56 56 57 void printDevices(PUSBDEVICE pDevices, const char *pcszAccess) 57 void printDevices(PUSBDEVICE pDevices, 58 const char *pcszDevices, 59 const char *pcszMethod) 58 60 { 59 61 PUSBDEVICE pDevice = pDevices; 60 62 61 RTPrintf("Enumerating usb devices using %s \n", pcszAccess);63 RTPrintf("Enumerating usb devices using %s at %s\n", pcszMethod, pcszDevices); 62 64 while (pDevice) 63 65 { … … 118 120 RTPrintf ("\n"); 119 121 } 120 #ifdef VBOX_USB_WITH_SYSFS 121 PUSBDEVICE pDevice = USBProxyLinuxGetDevices(NULL); 122 printDevices(pDevice, "sysfs"); 123 freeDevices(pDevice); 124 if (USBProxyLinuxCheckForUsbfs("/proc/bus/usb/devices")) 122 PCUSBDEVTREELOCATION pcLocation = USBProxyLinuxGetDeviceRoot(false); 123 if (pcLocation && !pcLocation->fUseSysfs) 125 124 { 126 pDevice = USBProxyLinuxGetDevices("/proc/bus/usb"); 127 printDevices(pDevice, "/proc/bus/usb"); 125 PUSBDEVICE pDevice = USBProxyLinuxGetDevices(pcLocation->szDevicesRoot, 126 false); 127 printDevices(pDevice, pcLocation->szDevicesRoot, "usbfs"); 128 128 freeDevices(pDevice); 129 129 } 130 if (USBProxyLinuxCheckForUsbfs("/dev/bus/usb/devices")) 130 #ifdef VBOX_USB_WITH_SYSFS 131 pcLocation = USBProxyLinuxGetDeviceRoot(true); 132 if (pcLocation && pcLocation->fUseSysfs) 131 133 { 132 pDevice = USBProxyLinuxGetDevices("/dev/bus/usb"); 133 printDevices(pDevice, "/dev/bus/usb"); 134 PUSBDEVICE pDevice = USBProxyLinuxGetDevices(pcLocation->szDevicesRoot, 135 true); 136 printDevices(pDevice, pcLocation->szDevicesRoot, "sysfs"); 134 137 freeDevices(pDevice); 135 138 } 136 VBoxMainHotplugWaiter waiter ;139 VBoxMainHotplugWaiter waiter(pcLocation->szDevicesRoot); 137 140 RTPrintf ("Waiting for a hotplug event for five seconds...\n"); 138 141 doHotplugEvent(&waiter, 5000); -
trunk/src/VBox/RDP/client/vrdp/rdpusb.c
r32472 r34341 63 63 }; 64 64 65 /** Location at which the Linux Usbfs filesystem was found. NULL means not 66 * found, in which case USB devices will be accessed through /dev and sysfs. */ 67 static const char *g_pcszUsbfsRoot = NULL; 65 /** Location at which the USB device tree was found. NULL means not 66 * found. */ 67 static const char *g_pcszDevicesRoot = NULL; 68 static bool g_fUseSysfs = false; 68 69 69 70 static PUSBDEVICE g_pUsbDevices = NULL; … … 252 253 if (g_pUsbDevices) 253 254 deviceListFree(&g_pUsbDevices); 254 g_pUsbDevices = USBProxyLinuxGetDevices(g_pcsz UsbfsRoot);255 g_pUsbDevices = USBProxyLinuxGetDevices(g_pcszDevicesRoot, g_fUseSysfs); 255 256 if (!g_pUsbDevices) 256 257 return NULL; … … 852 853 853 854 854 /** Check for the Linux Usbfs filesystem in a couple of common locations. */855 static void checkUsbfsRoot(void)856 {857 unsigned i;858 for (i = 0; i < RT_ELEMENTS(g_usbfsPaths); ++i)859 if (RT_SUCCESS(USBProxyLinuxCheckForUsbfs(g_usbfsPaths[i].pcszDevices)))860 {861 g_pcszUsbfsRoot = g_usbfsPaths[i].pcszRoot;862 break;863 }864 }865 866 867 855 RD_BOOL 868 856 rdpusb_init(void) 869 857 { 870 checkUsbfsRoot(); 858 PCUSBDEVTREELOCATION pcLocation = USBProxyLinuxGetDeviceRoot(false); 859 g_fUseSysfs = pcLocation->fUseSysfs; 860 g_pcszDevicesRoot = pcLocation->szDevicesRoot; 871 861 rdpusb_channel = 872 862 channel_register("vrdpusb", CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP,
Note:
See TracChangeset
for help on using the changeset viewer.