VirtualBox

Ignore:
Timestamp:
Jun 8, 2011 1:57:44 PM (14 years ago)
Author:
vboxsync
Message:

Main/USB/linux: attempt to fix USB detection on CentOS/RHEL 5, fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp

    r37373 r37377  
    825825#define USBDEVICE_MAJOR 189
    826826
     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 */
     835static 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
    827847/** Calculate the device number of a USB device.  See
    828848 * drivers/usb/core/hub.c:usb_new_device as of Linux 2.6.20. */
     
    830850{
    831851    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);
    833854}
    834855
     
    842863{
    843864    const char *pcszFile = strrchr(pcszNode, '/');
     865    if (!pcszFile)
     866        return VERR_INVALID_PARAMETER;
    844867    if (strchr(pcszFile, ':'))
    845868        return VINF_SUCCESS;
    846     unsigned bus = RTLinuxSysFsReadIntFile(10, "%s/busnum", pcszNode);
     869    unsigned bus = usbGetBusFromSysfsPath(pcszNode);
     870    if (!bus)
     871        return VINF_SUCCESS;
    847872    unsigned device = RTLinuxSysFsReadIntFile(10, "%s/devnum", pcszNode);
    848873    dev_t devnum = usbMakeDevNum(bus, device);
     
    12111236    /* Fill in the simple fields */
    12121237    Dev->enmState           = USBDEVICESTATE_UNUSED;
    1213     Dev->bBus               = RTLinuxSysFsReadIntFile(10, "%s/busnum", pszSysfsPath);
     1238    Dev->bBus               = usbGetBusFromSysfsPath(pszSysfsPath);
    12141239    Dev->bDeviceClass       = RTLinuxSysFsReadIntFile(16, "%s/bDeviceClass", pszSysfsPath);
    12151240    Dev->bDeviceSubClass    = RTLinuxSysFsReadIntFile(16, "%s/bDeviceSubClass", pszSysfsPath);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette