VirtualBox

Changeset 50783 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Mar 14, 2014 9:57:47 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
92804
Message:

Main and Runtime/Linux: rip out all code for recursively walking /dev, as it is not needed on modern Linux systems and partly visibly broken.

Location:
trunk/src/VBox/Main/src-server/linux
Files:
2 edited

Legend:

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

    r48424 r50783  
    8686static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList,
    8787                               bool isDVD, bool *pfSuccess);
    88 static int getDriveInfoFromDev(DriveInfoList *pList, bool isDVD,
    89                                bool *pfSuccess);
    9088static int getDriveInfoFromSysfs(DriveInfoList *pList, bool isDVD,
    9189                                 bool *pfSuccess);
     
    469467            rc = getDriveInfoFromSysfs(&mDVDList, true /* isDVD */, &success);
    470468        }
    471         /* Walk through the /dev subtree if nothing else has helped. */
    472         if (RT_SUCCESS(rc) && (!success | testing()))
    473             rc = getDriveInfoFromDev(&mDVDList, true /* isDVD */, &success);
    474469    }
    475470    catch(std::bad_alloc &e)
     
    501496            rc = getDriveInfoFromSysfs(&mFloppyList, false /* isDVD */, &success);
    502497        }
    503         /* Walk through the /dev subtree if nothing else has helped. */
    504         if (   RT_SUCCESS(rc) && (!success || testing()))
    505             rc = getDriveInfoFromDev(&mFloppyList, false /* isDVD */,
    506                                      &success);
    507498    }
    508499    catch(std::bad_alloc &e)
     
    622613            return false;
    623614        }
    624         if (RTLinuxFindDevicePath(dev, RTFS_TYPE_DEV_BLOCK, mszNode,
    625                                   sizeof(mszNode), "%s", mpcszName) < 0)
     615        if (RTLinuxCheckDevicePath(dev, RTFS_TYPE_DEV_BLOCK, mszNode,
     616                                   sizeof(mszNode), "%s", mpcszName) < 0)
    626617            return false;
    627618        return true;
     
    809800
    810801
    811 /** Structure for holding information about a drive we have found */
    812 struct deviceNodeInfo
    813 {
    814     /** The device number */
    815     dev_t Device;
    816     /** The device node path */
    817     char szPath[RTPATH_MAX];
    818     /** The device description */
    819     char szDesc[256];
    820     /** The device UDI */
    821     char szUdi[256];
    822 };
    823 
    824 /** The maximum number of devices we will search for. */
    825 enum { MAX_DEVICE_NODES = 8 };
    826 /** An array of MAX_DEVICE_NODES devices */
    827 typedef struct deviceNodeInfo deviceNodeArray[MAX_DEVICE_NODES];
    828 
    829 /**
    830  * Recursive worker function to walk the /dev tree looking for DVD or floppy
    831  * devices.
    832  * @returns true if we have already found MAX_DEVICE_NODES devices, false
    833  *          otherwise
    834  * @param   pszPath   the path to start recursing.  The function can modify
    835  *                    this string at and after the terminating zero
    836  * @param   cchPath   the size of the buffer (not the string!) in @a pszPath
    837  * @param   aDevices  where to fill in information about devices that we have
    838  *                    found
    839  * @param   wantDVD   are we looking for DVD devices (or floppies)?
    840  */
    841 static bool devFindDeviceRecursive(char *pszPath, size_t cchPath,
    842                                    deviceNodeArray aDevices, bool wantDVD)
    843 {
    844     /*
    845      * Check assumptions made by the code below.
    846      */
    847     size_t const cchBasePath = strlen(pszPath);
    848     AssertReturn(cchBasePath < RTPATH_MAX - 10U, false);
    849     AssertReturn(pszPath[cchBasePath - 1] != '/', false);
    850 
    851     PRTDIR  pDir;
    852     if (RT_FAILURE(RTDirOpen(&pDir, pszPath)))
    853         return false;
    854     for (;;)
    855     {
    856         RTDIRENTRY Entry;
    857         RTFSOBJINFO ObjInfo;
    858         int rc = RTDirRead(pDir, &Entry, NULL);
    859         if (RT_FAILURE(rc))
    860             break;
    861         if (Entry.enmType == RTDIRENTRYTYPE_UNKNOWN)
    862         {
    863             if (RT_FAILURE(RTPathQueryInfo(pszPath, &ObjInfo,
    864                            RTFSOBJATTRADD_UNIX)))
    865                 continue;
    866             if (RTFS_IS_SYMLINK(ObjInfo.Attr.fMode))
    867                 continue;
    868         }
    869 
    870         if (Entry.enmType == RTDIRENTRYTYPE_SYMLINK)
    871             continue;
    872         pszPath[cchBasePath] = '\0';
    873         if (RT_FAILURE(RTPathAppend(pszPath, cchPath, Entry.szName)))
    874             break;
    875 
    876         /* Do the matching. */
    877         dev_t DevNode;
    878         char szDesc[256], szUdi[256];
    879         if (!devValidateDevice(pszPath, wantDVD, &DevNode, szDesc,
    880                                sizeof(szDesc), szUdi, sizeof(szUdi)))
    881             continue;
    882         unsigned i;
    883         for (i = 0; i < MAX_DEVICE_NODES; ++i)
    884             if (!aDevices[i].Device || (aDevices[i].Device == DevNode))
    885                 break;
    886         AssertBreak(i < MAX_DEVICE_NODES);
    887         if (aDevices[i].Device)
    888             continue;
    889         aDevices[i].Device = DevNode;
    890         RTStrPrintf(aDevices[i].szPath, sizeof(aDevices[i].szPath),
    891                     "%s", pszPath);
    892         AssertCompile(sizeof(aDevices[i].szDesc) == sizeof(szDesc));
    893         strcpy(aDevices[i].szDesc, szDesc);
    894         AssertCompile(sizeof(aDevices[i].szUdi) == sizeof(szUdi));
    895         strcpy(aDevices[i].szUdi, szUdi);
    896         if (i == MAX_DEVICE_NODES - 1)
    897             break;
    898         continue;
    899 
    900         /* Recurse into subdirectories. */
    901         if (   (Entry.enmType == RTDIRENTRYTYPE_UNKNOWN)
    902             && !RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode))
    903             continue;
    904         if (Entry.enmType != RTDIRENTRYTYPE_DIRECTORY)
    905             continue;
    906         if (Entry.szName[0] == '.')
    907             continue;
    908 
    909         if (devFindDeviceRecursive(pszPath, cchPath, aDevices, wantDVD))
    910             break;
    911     }
    912     RTDirClose(pDir);
    913     return aDevices[MAX_DEVICE_NODES - 1].Device ? true : false;
    914 }
    915 
    916 
    917 /**
    918  * Recursively walk through the /dev tree and add any DVD or floppy drives we
    919  * find and can access to our list.  (If we can't access them we can't check
    920  * whether or not they are really DVD or floppy drives).
    921  * @note  this is rather slow (a couple of seconds) for DVD probing on
    922  *        systems with a static /dev tree, as the current code tries to open
    923  *        any device node with a major/minor combination that could belong to
    924  *        a CD-ROM device, and opening a non-existent device can take a non.
    925  *        negligible time on Linux.  If it is ever necessary to improve this
    926  *        (static /dev trees are no longer very fashionable these days, and
    927  *        sysfs looks like it will be with us for a while), we could further
    928  *        reduce the number of device nodes we open by checking whether the
    929  *        driver is actually loaded in /proc/devices, and by counting the
    930  *        of currently attached SCSI CD-ROM devices in /proc/scsi/scsi (yes,
    931  *        there is a race, but it is probably not important for us).
    932  * @returns iprt status code
    933  * @param   pList      the list to append the drives found to
    934  * @param   isDVD      are we looking for DVD drives or for floppies?
    935  * @param   pfSuccess  this will be set to true if we found at least one drive
    936  *                     and to false otherwise.  Optional.
    937  */
    938 /* static */
    939 int getDriveInfoFromDev(DriveInfoList *pList, bool isDVD, bool *pfSuccess)
    940 {
    941     AssertPtrReturn(pList, VERR_INVALID_POINTER);
    942     AssertPtrNullReturn(pfSuccess, VERR_INVALID_POINTER);
    943     LogFlowFunc(("pList=%p, isDVD=%d, pfSuccess=%p\n", pList, isDVD,
    944                  pfSuccess));
    945     int rc = VINF_SUCCESS;
    946     bool success = false;
    947 
    948     char szPath[RTPATH_MAX] = "/dev";
    949     deviceNodeArray aDevices;
    950     RT_ZERO(aDevices);
    951     devFindDeviceRecursive(szPath, sizeof(szPath), aDevices, isDVD);
    952     try
    953     {
    954         for (unsigned i = 0; i < MAX_DEVICE_NODES; ++i)
    955         {
    956             if (aDevices[i].Device)
    957             {
    958                 pList->push_back(DriveInfo(aDevices[i].szPath,
    959                                  aDevices[i].szUdi, aDevices[i].szDesc));
    960                 success = true;
    961             }
    962         }
    963         if (pfSuccess != NULL)
    964             *pfSuccess = success;
    965     }
    966     catch(std::bad_alloc &e)
    967     {
    968         rc = VERR_NO_MEMORY;
    969     }
    970     LogFlowFunc (("rc=%Rrc, success=%d\n", rc, success));
    971     return rc;
    972 }
    973 
    974 
    975802/** Helper for readFilePathsFromDir().  Adds a path to the vector if it is not
    976803 * NULL and not a dotfile (".", "..", ".*"). */
  • trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp

    r48955 r50783  
    882882    char szDevPath[RTPATH_MAX];
    883883    ssize_t cchDevPath;
    884     cchDevPath = RTLinuxFindDevicePath(devnum, RTFS_TYPE_DEV_CHAR,
    885                                        szDevPath, sizeof(szDevPath),
    886                                        "%s/%.3d/%.3d",
    887                                        pcszDevicesRoot, bus, device);
     884    cchDevPath = RTLinuxCheckDevicePath(devnum, RTFS_TYPE_DEV_CHAR,
     885                                        szDevPath, sizeof(szDevPath),
     886                                        "%s/%.3d/%.3d",
     887                                        pcszDevicesRoot, bus, device);
    888888    if (cchDevPath < 0)
    889889        return VINF_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

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