Changeset 37377 in vbox for trunk/src/VBox/Main/src-server/linux
- Timestamp:
- Jun 8, 2011 1:57:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r37373 r37377 825 825 #define USBDEVICE_MAJOR 189 826 826 827 /** Calculate the bus (a.k.a root hub) number of a USB device from it's sysfs 828 * path. sysfs nodes representing root hubs have file names of the form 829 * usb<n>, where n is the bus number; other devices start with that number. 830 * See [http://www.linux-usb.org/FAQ.html#i6] and 831 * [http://www.kernel.org/doc/Documentation/usb/proc_usb_info.txt] for 832 * equivalent information about usbfs. 833 * @returns a bus number greater than 0 on success or 0 on failure. 834 */ 835 static unsigned usbGetBusFromSysfsPath(const char *pcszPath) 836 { 837 const char *pcszFile = strrchr(pcszPath, '/'); 838 if (!pcszFile) 839 return 0; 840 unsigned bus = RTStrToUInt32(pcszFile + 1); 841 if ( !bus 842 && pcszFile[1] == 'u' && pcszFile[2] == 's' && pcszFile[3] == 'b') 843 bus = RTStrToUInt32(pcszFile + 4); 844 return bus; 845 } 846 827 847 /** Calculate the device number of a USB device. See 828 848 * drivers/usb/core/hub.c:usb_new_device as of Linux 2.6.20. */ … … 830 850 { 831 851 AssertReturn(((device - 1) & ~127) == 0, 0); 832 return makedev(USBDEVICE_MAJOR, ((bus + 1) << 7) + device + 1); 852 AssertReturn(device > 0, 0); 853 return makedev(USBDEVICE_MAJOR, ((bus - 1) << 7) + device - 1); 833 854 } 834 855 … … 842 863 { 843 864 const char *pcszFile = strrchr(pcszNode, '/'); 865 if (!pcszFile) 866 return VERR_INVALID_PARAMETER; 844 867 if (strchr(pcszFile, ':')) 845 868 return VINF_SUCCESS; 846 unsigned bus = RTLinuxSysFsReadIntFile(10, "%s/busnum", pcszNode); 869 unsigned bus = usbGetBusFromSysfsPath(pcszNode); 870 if (!bus) 871 return VINF_SUCCESS; 847 872 unsigned device = RTLinuxSysFsReadIntFile(10, "%s/devnum", pcszNode); 848 873 dev_t devnum = usbMakeDevNum(bus, device); … … 1211 1236 /* Fill in the simple fields */ 1212 1237 Dev->enmState = USBDEVICESTATE_UNUSED; 1213 Dev->bBus = RTLinuxSysFsReadIntFile(10, "%s/busnum",pszSysfsPath);1238 Dev->bBus = usbGetBusFromSysfsPath(pszSysfsPath); 1214 1239 Dev->bDeviceClass = RTLinuxSysFsReadIntFile(16, "%s/bDeviceClass", pszSysfsPath); 1215 1240 Dev->bDeviceSubClass = RTLinuxSysFsReadIntFile(16, "%s/bDeviceSubClass", pszSysfsPath);
Note:
See TracChangeset
for help on using the changeset viewer.