Changeset 50783 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Mar 14, 2014 9:57:47 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92804
- 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 86 86 static int getDriveInfoFromEnv(const char *pcszVar, DriveInfoList *pList, 87 87 bool isDVD, bool *pfSuccess); 88 static int getDriveInfoFromDev(DriveInfoList *pList, bool isDVD,89 bool *pfSuccess);90 88 static int getDriveInfoFromSysfs(DriveInfoList *pList, bool isDVD, 91 89 bool *pfSuccess); … … 469 467 rc = getDriveInfoFromSysfs(&mDVDList, true /* isDVD */, &success); 470 468 } 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);474 469 } 475 470 catch(std::bad_alloc &e) … … 501 496 rc = getDriveInfoFromSysfs(&mFloppyList, false /* isDVD */, &success); 502 497 } 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);507 498 } 508 499 catch(std::bad_alloc &e) … … 622 613 return false; 623 614 } 624 if (RTLinux FindDevicePath(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) 626 617 return false; 627 618 return true; … … 809 800 810 801 811 /** Structure for holding information about a drive we have found */812 struct deviceNodeInfo813 {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 floppy831 * devices.832 * @returns true if we have already found MAX_DEVICE_NODES devices, false833 * otherwise834 * @param pszPath the path to start recursing. The function can modify835 * this string at and after the terminating zero836 * @param cchPath the size of the buffer (not the string!) in @a pszPath837 * @param aDevices where to fill in information about devices that we have838 * found839 * @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 we919 * find and can access to our list. (If we can't access them we can't check920 * whether or not they are really DVD or floppy drives).921 * @note this is rather slow (a couple of seconds) for DVD probing on922 * systems with a static /dev tree, as the current code tries to open923 * any device node with a major/minor combination that could belong to924 * 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 this926 * (static /dev trees are no longer very fashionable these days, and927 * sysfs looks like it will be with us for a while), we could further928 * reduce the number of device nodes we open by checking whether the929 * driver is actually loaded in /proc/devices, and by counting the930 * 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 code933 * @param pList the list to append the drives found to934 * @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 drive936 * 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 try953 {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 975 802 /** Helper for readFilePathsFromDir(). Adds a path to the vector if it is not 976 803 * NULL and not a dotfile (".", "..", ".*"). */ -
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r48955 r50783 882 882 char szDevPath[RTPATH_MAX]; 883 883 ssize_t cchDevPath; 884 cchDevPath = RTLinux FindDevicePath(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); 888 888 if (cchDevPath < 0) 889 889 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.