Changeset 31337 in vbox for trunk/src/VBox
- Timestamp:
- Aug 3, 2010 2:05:05 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 64376
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r31327 r31337 65 65 # include <limits.h> 66 66 # include <stdio.h> 67 # ifdef VBOX_SOLARIS_NSL_RESOLVED 68 # include <libdevinfo.h> 69 # endif 67 # include <libdevinfo.h> 68 # include <sys/scsi/generic/inquiry.h> 70 69 # include <net/if.h> 71 70 # include <sys/socket.h> … … 85 84 # endif 86 85 # include "solaris/DynLoadLibSolaris.h" 86 87 /** 88 * Solaris DVD drive list as returned by getDVDInfoFromDevTree(). 89 */ 90 typedef struct SOLARISDVD 91 { 92 struct SOLARISDVD *pNext; 93 char szDescription[512]; 94 char szRawDiskPath[PATH_MAX]; 95 } SOLARISDVD; 96 /** Pointer to a Solaris DVD descriptor. */ 97 typedef SOLARISDVD *PSOLARISDVD; 98 87 99 #endif /* RT_OS_SOLARIS */ 88 100 … … 1724 1736 if (!getDVDInfoFromHal(list)) 1725 1737 # endif 1726 // Not all Solaris versions ship with libhal. 1727 // So use a fallback approach similar to Linux. 1728 { 1729 if (RTEnvExistEx(RTENV_DEFAULT, "VBOX_CDROM")) 1730 { 1731 char *cdromEnv = RTEnvDupEx(RTENV_DEFAULT, "VBOX_CDROM"); 1732 char *saveStr = NULL; 1733 char *cdromDrive = NULL; 1734 if (cdromEnv) 1735 cdromDrive = strtok_r(cdromEnv, ":", &saveStr); 1736 while (cdromDrive) 1737 { 1738 if (validateDevice(cdromDrive, true)) 1739 { 1740 ComObjPtr<Medium> hostDVDDriveObj; 1741 hostDVDDriveObj.createObject(); 1742 hostDVDDriveObj->init(m->pParent, DeviceType_DVD, Bstr(cdromDrive)); 1743 list.push_back(hostDVDDriveObj); 1744 } 1745 cdromDrive = strtok_r(NULL, ":", &saveStr); 1746 } 1747 RTStrFree(cdromEnv); 1748 } 1749 else 1750 { 1751 // this might work on Solaris version older than Nevada. 1752 if (validateDevice("/cdrom/cdrom0", true)) 1753 { 1754 ComObjPtr<Medium> hostDVDDriveObj; 1755 hostDVDDriveObj.createObject(); 1756 hostDVDDriveObj->init(m->pParent, DeviceType_DVD, Bstr("cdrom/cdrom0")); 1757 list.push_back(hostDVDDriveObj); 1758 } 1759 1760 // check the mounted drives 1761 parseMountTable(MNTTAB, list); 1762 } 1738 { 1739 getDVDInfoFromDevTree(list); 1763 1740 } 1764 1741 … … 1978 1955 1979 1956 #if defined(RT_OS_SOLARIS) && defined(VBOX_USE_LIBHAL) 1957 1958 /** 1959 * Helper function to get the slice number from a device path 1960 * 1961 * @param pszDevLinkPath Pointer to a device path (/dev/(r)dsk/c7d1t0d0s3 etc.) 1962 * @returns Pointer to the slice portion of the given path. 1963 */ 1964 static char *solarisGetSliceFromPath(const char *pszDevLinkPath) 1965 { 1966 char *pszFound = NULL; 1967 char *pszSlice = strrchr(pszDevLinkPath, 's'); 1968 char *pszDisk = strrchr(pszDevLinkPath, 'd'); 1969 if (pszSlice && pszSlice > pszDisk) 1970 pszFound = pszSlice; 1971 else 1972 pszFound = pszDisk; 1973 1974 if (pszFound && RT_C_IS_DIGIT(pszFound[1])) 1975 return pszFound; 1976 1977 return NULL; 1978 } 1979 1980 /** 1981 * Walk device links and returns an allocated path for the first one in the snapshot. 1982 * 1983 * @param DevLink Handle to the device link being walked. 1984 * @param pvArg Opaque data containing the pointer to the path. 1985 * @returns Pointer to an allocated device path string. 1986 */ 1987 static int solarisWalkDevLink(di_devlink_t DevLink, void *pvArg) 1988 { 1989 char **ppszPath = (char **)pvArg; 1990 *ppszPath = strdup(di_devlink_path(DevLink)); 1991 return DI_WALK_TERMINATE; 1992 } 1993 1994 /** 1995 * Walk all devices in the system and enumerate CD/DVD drives. 1996 * @param Node Handle to the current node. 1997 * @param pvArg Opaque data (holds list pointer). 1998 * @returns Solaris specific code whether to continue walking or not. 1999 */ 2000 static int solarisWalkDeviceNodeForDVD(di_node_t Node, void *pvArg) 2001 { 2002 PSOLARISDVD *ppDrives = (PSOLARISDVD *)pvArg; 2003 2004 char *pszClass = NULL; 2005 if ( di_prop_lookup_strings(DDI_DEV_T_ANY, Node, "class", &pszClass) > 0 2006 && !strcmp(pszClass, "scsi")) /* SCSI */ 2007 { 2008 int *pInt = NULL; 2009 if (di_prop_lookup_ints(DDI_DEV_T_ANY, Node, "inquiry-device-type", &pInt) > 0 2010 && ( *pInt == DTYPE_RODIRECT /* CDROM */ 2011 || *pInt == DTYPE_OPTICAL)) /* Optical Drive */ 2012 { 2013 char *pszProduct = NULL; 2014 if (di_prop_lookup_strings(DDI_DEV_T_ANY, Node, "inquiry-product-id", &pszProduct) > 0) 2015 { 2016 char *pszVendor = NULL; 2017 if (di_prop_lookup_strings(DDI_DEV_T_ANY, Node, "inquiry-vendor-id", &pszVendor) > 0) 2018 { 2019 /* 2020 * Found a DVD drive, we need to scan the minor nodes to find the correct 2021 * slice that represents the whole drive. "s2" is always the whole drive for CD/DVDs. 2022 */ 2023 di_minor_t Minor = DI_MINOR_NIL; 2024 di_devlink_handle_t DevLink = di_devlink_init(NULL /* name */, 0 /* flags */); 2025 if (DevLink) 2026 { 2027 while ((Minor = di_minor_next(Node, Minor)) != DI_MINOR_NIL) 2028 { 2029 char *pszMinorPath = di_devfs_minor_path(Minor); 2030 if (!pszMinorPath) 2031 continue; 2032 2033 char *pszDevLinkPath = NULL; 2034 di_devlink_walk(DevLink, NULL, pszMinorPath, DI_PRIMARY_LINK, &pszDevLinkPath, solarisWalkDevLink); 2035 di_devfs_path_free(pszMinorPath); 2036 2037 char *pszSlice = solarisGetSliceFromPath(pszDevLinkPath); 2038 if ( pszSlice && !strcmp(pszSlice, "s2") 2039 && !strncmp(pszDevLinkPath, "/dev/rdsk", sizeof("/dev/rdsk") - 1)) /* We want only raw disks */ 2040 { 2041 /* 2042 * We've got a fully qualified DVD drive. Add it to the list. 2043 */ 2044 PSOLARISDVD pDrive = (PSOLARISDVD)RTMemAllocZ(sizeof(SOLARISDVD)); 2045 if (RT_LIKELY(pDrive)) 2046 { 2047 RTStrPrintf(pDrive->szDescription, sizeof(pDrive->szDescription), "%s %s", pszVendor, pszProduct); 2048 RTStrCopy(pDrive->szRawDiskPath, sizeof(pDrive->szRawDiskPath), pszDevLinkPath); 2049 if (!*ppDrives) 2050 *ppDrives = pDrive; 2051 else 2052 (*ppDrives)->pNext = pDrive; 2053 } 2054 } 2055 free(pszDevLinkPath); 2056 } 2057 } 2058 } 2059 } 2060 } 2061 } 2062 return DI_WALK_CONTINUE; 2063 } 2064 2065 /** 2066 * Solaris specific function to enumerate CD/DVD drives via the device tree. 2067 * Works on Solaris 10 as well as OpenSolaris without depending on libhal. 2068 */ 2069 void Host::getDVDInfoFromDevTree(std::list<ComObjPtr<Medium> > &list) 2070 { 2071 PSOLARISDVD pDrives = NULL; 2072 di_node_t RootNode = di_init("/", DINFOCPYALL); 2073 if (RootNode != DI_NODE_NIL) 2074 di_walk_node(RootNode, DI_WALK_CLDFIRST, &pDrives, solarisWalkDeviceNodeForDVD); 2075 2076 di_fini(RootNode); 2077 2078 while (pDrives) 2079 { 2080 ComObjPtr<Medium> hostDVDDriveObj; 2081 hostDVDDriveObj.createObject(); 2082 hostDVDDriveObj->init(m->pParent, DeviceType_DVD, Bstr(pDrives->szRawDiskPath), Bstr(pDrives->szDescription)); 2083 list.push_back(hostDVDDriveObj); 2084 2085 void *pvDrive = pDrives; 2086 pDrives = pDrives->pNext; 2087 RTMemFree(pvDrive); 2088 } 2089 } 2090 1980 2091 /* Solaris hosts, loading libhal at runtime */ 1981 2092 -
trunk/src/VBox/Main/Makefile.kmk
r31135 r31337 239 239 VBoxSVC_DEFS.solaris += VBOX_USE_LIBHAL 240 240 VBoxSVC_DEFS.freebsd += VBOX_USE_LIBHAL 241 ifdef VBOX_SOLARIS_NSL_RESOLVED242 VBoxSVC_DEFS.solaris += VBOX_SOLARIS_NSL_RESOLVED243 endif244 241 245 242 VBoxSVC_CXXFLAGS = $(filter-out -Wno-unused,$(TEMPLATE_VBOXMAINEXE_CXXFLAGS)) … … 267 264 adm \ 268 265 nsl \ 266 devinfo \ 269 267 socket 270 271 ifdef VBOX_WITH_NETFLT272 ifdef VBOX_SOLARIS_NSL_RESOLVED273 VBoxSVC_LIBS.solaris += devinfo274 endif275 VBoxSVC_LIBS.solaris += socket276 endif277 ifdef VBOX_WITH_USB278 VBoxSVC_LIBS.solaris += \279 devinfo280 endif281 268 282 269 VBoxSVC_INTERMEDIATES = \ -
trunk/src/VBox/Main/include/HostImpl.h
r31296 r31337 137 137 138 138 #if defined(RT_OS_SOLARIS) 139 void getDVDInfoFromDevTree(std::list< ComObjPtr<Medium> > &list); 139 140 void parseMountTable(char *mountTable, std::list< ComObjPtr<Medium> > &list); 140 141 bool validateDevice(const char *deviceNode, bool isCDROM); -
trunk/src/VBox/Main/solaris/NetIf-solaris.cpp
r28962 r31337 41 41 #include <limits.h> 42 42 #include <stdio.h> 43 #ifdef VBOX_SOLARIS_NSL_RESOLVED 44 # include <libdevinfo.h> 45 #endif 43 #include <libdevinfo.h> 46 44 #include <net/if.h> 47 45 #include <sys/socket.h> … … 272 270 } 273 271 274 # ifdef VBOX_SOLARIS_NSL_RESOLVED275 272 static int vboxSolarisAddPhysHostIface(di_node_t Node, di_minor_t Minor, void *pvHostNetworkInterfaceList) 276 273 { … … 292 289 return DI_WALK_CONTINUE; 293 290 } 294 # endif /* VBOX_SOLARIS_NSL_RESOLVED */295 291 296 292 int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list) 297 293 { 298 299 # ifdef VBOX_SOLARIS_NSL_RESOLVED300 294 301 295 /* … … 315 309 if (VBoxSolarisLibDlpiFound()) 316 310 g_pfnLibDlpiWalk(vboxSolarisAddLinkHostIface, &list, 0); 317 318 # endif /* VBOX_SOLARIS_NSL_RESOLVED */319 311 320 312 /*
Note:
See TracChangeset
for help on using the changeset viewer.