VirtualBox

Changeset 31337 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 3, 2010 2:05:05 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64376
Message:

Main/Solaris: New DVD drive enumeration, works on Solaris 10 & Nevada. Removed now obsolete NSL_RESOLVED stuff on Solaris.

Location:
trunk/src/VBox/Main
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HostImpl.cpp

    r31327 r31337  
    6565# include <limits.h>
    6666# 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>
    7069# include <net/if.h>
    7170# include <sys/socket.h>
     
    8584# endif
    8685# include "solaris/DynLoadLibSolaris.h"
     86
     87/**
     88 * Solaris DVD drive list as returned by getDVDInfoFromDevTree().
     89 */
     90typedef 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. */
     97typedef SOLARISDVD *PSOLARISDVD;
     98
    8799#endif /* RT_OS_SOLARIS */
    88100
     
    17241736        if (!getDVDInfoFromHal(list))
    17251737# 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);
    17631740        }
    17641741
     
    19781955
    19791956#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 */
     1964static 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 */
     1987static 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 */
     2000static 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 */
     2069void 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
    19802091/* Solaris hosts, loading libhal at runtime */
    19812092
  • trunk/src/VBox/Main/Makefile.kmk

    r31135 r31337  
    239239VBoxSVC_DEFS.solaris += VBOX_USE_LIBHAL
    240240VBoxSVC_DEFS.freebsd += VBOX_USE_LIBHAL
    241 ifdef VBOX_SOLARIS_NSL_RESOLVED
    242  VBoxSVC_DEFS.solaris += VBOX_SOLARIS_NSL_RESOLVED
    243 endif
    244241
    245242VBoxSVC_CXXFLAGS = $(filter-out -Wno-unused,$(TEMPLATE_VBOXMAINEXE_CXXFLAGS))
     
    267264        adm \
    268265        nsl \
     266        devinfo \
    269267        socket
    270 
    271 ifdef VBOX_WITH_NETFLT
    272  ifdef VBOX_SOLARIS_NSL_RESOLVED
    273   VBoxSVC_LIBS.solaris += devinfo
    274  endif
    275  VBoxSVC_LIBS.solaris += socket
    276 endif
    277 ifdef VBOX_WITH_USB
    278  VBoxSVC_LIBS.solaris += \
    279         devinfo
    280 endif
    281268
    282269VBoxSVC_INTERMEDIATES = \
  • trunk/src/VBox/Main/include/HostImpl.h

    r31296 r31337  
    137137
    138138#if defined(RT_OS_SOLARIS)
     139    void getDVDInfoFromDevTree(std::list< ComObjPtr<Medium> > &list);
    139140    void parseMountTable(char *mountTable, std::list< ComObjPtr<Medium> > &list);
    140141    bool validateDevice(const char *deviceNode, bool isCDROM);
  • trunk/src/VBox/Main/solaris/NetIf-solaris.cpp

    r28962 r31337  
    4141#include <limits.h>
    4242#include <stdio.h>
    43 #ifdef VBOX_SOLARIS_NSL_RESOLVED
    44 # include <libdevinfo.h>
    45 #endif
     43#include <libdevinfo.h>
    4644#include <net/if.h>
    4745#include <sys/socket.h>
     
    272270}
    273271
    274 # ifdef VBOX_SOLARIS_NSL_RESOLVED
    275272static int vboxSolarisAddPhysHostIface(di_node_t Node, di_minor_t Minor, void *pvHostNetworkInterfaceList)
    276273{
     
    292289    return DI_WALK_CONTINUE;
    293290}
    294 # endif /* VBOX_SOLARIS_NSL_RESOLVED */
    295291
    296292int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
    297293{
    298 
    299 #  ifdef VBOX_SOLARIS_NSL_RESOLVED
    300294
    301295    /*
     
    315309    if (VBoxSolarisLibDlpiFound())
    316310        g_pfnLibDlpiWalk(vboxSolarisAddLinkHostIface, &list, 0);
    317 
    318 #  endif    /* VBOX_SOLARIS_NSL_RESOLVED */
    319311
    320312    /*
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