VirtualBox

Changeset 28779 in vbox for trunk/src/VBox/Main/linux


Ignore:
Timestamp:
Apr 26, 2010 8:18:24 PM (15 years ago)
Author:
vboxsync
Message:

Main/HostHardwareLinux: cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/linux/HostHardwareLinux.cpp

    r28741 r28779  
    172172    {
    173173        int rcIoCtl;
    174         /** @todo The next line can produce a warning, as the ioctl request
    175          * field is defined as signed, but the Linux ioctl definition macros
    176          * produce unsigned constants. */
    177174        rc = RTFileIoCtl(File, FDGETDRVTYP, pszName, 0, &rcIoCtl);
    178175        RTFileClose(File);
     
    15911588
    15921589
     1590#define USBDEVICE_MAJOR 189
     1591
     1592/** Deduce the bus that a USB device is plugged into from the device node
     1593 * number.  See drivers/usb/core/hub.c:usb_new_device as of Linux 2.6.20. */
     1594static unsigned usbBusFromDevNum(dev_t devNum)
     1595{
     1596    AssertReturn(devNum, 0);
     1597    AssertReturn(major(devNum) == USBDEVICE_MAJOR, 0);
     1598    return (minor(devNum) >> 7) + 1;
     1599}
     1600
     1601
     1602/** Deduce the device number of a USB device on the bus from the device node
     1603 * number.  See drivers/usb/core/hub.c:usb_new_device as of Linux 2.6.20. */
     1604static unsigned usbDeviceFromDevNum(dev_t devNum)
     1605{
     1606    AssertReturn(devNum, 0);
     1607    AssertReturn(major(devNum) == USBDEVICE_MAJOR, 0);
     1608    return (minor(devNum) & 127) + 1;
     1609}
     1610
     1611
    15931612/**
    15941613 * Tell whether a file in /sys/bus/usb/devices is a device rather than an
     
    16071626            return true;
    16081627        dev_t devnum = RTLinuxSysFsReadDevNumFile("%s/dev", pcszNode);
     1628        /* Sanity test of our static helpers */
     1629        Assert(usbBusFromDevNum(makedev(USBDEVICE_MAJOR, 517)) == 5);
     1630        Assert(usbDeviceFromDevNum(makedev(USBDEVICE_MAJOR, 517)) == 6);
    16091631        AssertReturn (devnum, true);
    16101632        char szDevPath[RTPATH_MAX];
     
    16131635                                           szDevPath, sizeof(szDevPath),
    16141636                                           "/dev/bus/usb/%.3d/%.3d",
    1615                                            RTLinuxSysFsReadIntFile(10, "%s/busnum", pcszNode),
    1616                                            RTLinuxSysFsReadIntFile(10, "%s/devnum", pcszNode));
     1637                                           usbBusFromDevNum(devnum),
     1638                                           usbDeviceFromDevNum(devnum));
    16171639        if (cchDevPath < 0)
    16181640            return true;
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