VirtualBox

Changeset 5212 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Oct 9, 2007 6:43:56 PM (17 years ago)
Author:
vboxsync
Message:

Solaris.

Location:
trunk/src/VBox/Devices/Storage
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvHostBase.cpp

    r5184 r5212  
     1/* $Id$ */
    12/** @file
    2  *
    3  * VBox storage devices:
    4  * Host base drive access driver
     3 * DrvHostBase - Host base drive access driver.
    54 */
    65
     
    4645# include <errno.h>
    4746# include <stropts.h>
     47# include <malloc.h>
    4848# include <sys/dkio.h>
     49extern "C" char *getfullblkname(char *);
    4950
    5051#elif defined(RT_OS_WINDOWS)
     
    734735
    735736
     737#ifndef RT_OS_SOLARIS
    736738/**
    737739 * Wrapper for open / RTFileOpen / IOKit.
     
    920922    return rc;
    921923
    922 #elif defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
     924#elif defined(RT_OS_LINUX)
    923925    /** @todo we've got RTFILE_O_NON_BLOCK now. Change the code to use RTFileOpen. */
    924926    int FileDevice = open(pThis->pszDeviceOpen, (pThis->fReadOnlyConfig ? O_RDONLY : O_RDWR) | O_NONBLOCK);
     
    934936}
    935937
     938#else   /* RT_OS_SOLARIS */
     939
     940/**
     941 * Solaris wrapper for RTFileOpen.
     942 *
     943 * Solaris has to deal with two filehandles, a block and a raw one. Rather than messing
     944 * with drvHostBaseOpen's function signature & body, having a seperate one is better.
     945 *
     946 * @returns VBox status code.
     947 */
     948static int drvHostBaseOpen(PDRVHOSTBASE pThis, PRTFILE pBlockFileDevice, PRTFILE pFileRawDevice, bool fReadOnly)
     949{
     950    unsigned fFlags = (pThis->fReadOnlyConfig ? RTFILE_O_READ : RTFILE_O_READWRITE) | RTFILE_O_NON_BLOCK;
     951    int rc = RTFileOpen(pBlockFileDevice, pThis->pszDeviceOpen, fFlags);
     952    if (RT_SUCCESS(rc))
     953    {
     954        rc = RTFileOpen(pFileRawDevice, pThis->pszRawDeviceOpen, fFlags);
     955        if (RT_FAILURE(rc))
     956            RTFileClose(BlockFileDevice);
     957    }
     958    return rc;
     959}
     960#endif  /* RT_OS_SOLARIS */
     961
    936962
    937963/**
     
    951977
    952978    RTFILE FileDevice;
     979#ifdef RT_OS_SOLARIS
     980    RTFILE FileRawDevice;
     981    int rc = drvHostBaseOpen(pThis, &FileDevice, &FileRawDevice, pThis->fReadOnlyConfig);
     982#else
    953983    int rc = drvHostBaseOpen(pThis, &FileDevice, pThis->fReadOnlyConfig);
     984#endif
    954985    if (VBOX_FAILURE(rc))
    955986    {
     
    957988        {
    958989            LogFlow(("%s-%d: drvHostBaseReopen: '%s' - retry readonly (%Vrc)\n", pThis->pDrvIns->pDrvReg->szDriverName, pThis->pDrvIns->iInstance, pThis->pszDeviceOpen, rc));
     990#ifdef RT_OS_SOLARIS
     991            rc = drvHostBaseOpen(pThis, &FileDevice, &FileRawDevice, false);
     992#else
    959993            rc = drvHostBaseOpen(pThis, &FileDevice, false);
     994#endif
    960995        }
    961996        if (VBOX_FAILURE(rc))
     
    9691004    else
    9701005        pThis->fReadOnly = pThis->fReadOnlyConfig;
     1006
     1007#ifdef RT_OS_SOLARIS
     1008    if (pThis->FileRawDevice != NIL_RTFILE)
     1009        RTFileClose(pThis->FileRawDevice);
     1010    pThis->FileRawDevice = FileRawDevice;
     1011#endif
    9711012
    9721013    if (pThis->FileDevice != NIL_RTFILE)
     
    10231064     */
    10241065    struct dk_minfo MediaInfo;
    1025     if (ioctl(pThis->FileDevice, DKIOCGMEDIAINFO, &MediaInfo) == 0)
     1066    if (ioctl(pThis->FileRawDevice, DKIOCGMEDIAINFO, &MediaInfo) == 0)
    10261067    {
    10271068        *pcb = MediaInfo.dki_capacity * (uint64_t)MediaInfo.dki_lbsize;
     
    15621603#endif
    15631604
     1605#ifdef RT_OS_SOLARIS
     1606    if (pThis->FileRawDevice != NIL_RTFILE)
     1607    {
     1608        int rc = RTFileClose(pThis->FileRawDevice);
     1609        AssertRC(rc);
     1610        pThis->FileRawDevice = NIL_RTFILE;
     1611    }
     1612
     1613    if (pThis->pszRawDeviceOpen)
     1614    {
     1615        RTStrFree(pThis->pszRawDeviceOpen);
     1616        pThis->pszRawDeviceOpen = NULL;
     1617    }
     1618#endif
     1619
    15641620    if (pThis->pszDevice)
    15651621    {
     
    16191675    pThis->FileDevice                       = NIL_RTFILE;
    16201676#endif
     1677#ifdef RT_OS_SOLARIS
     1678    pThis->FileRawDevice                    = NIL_RTFILE;
     1679#endif
    16211680    pThis->enmType                          = enmType;
    16221681    //pThis->cErrors                          = 0;
     
    17581817    pThis->fUnitMask = 1 << iBit;
    17591818    RTStrAPrintf(&pThis->pszDeviceOpen, "\\\\.\\%s", pThis->pszDevice);
     1819
     1820#elif defined(RT_OS_SOLARIS)
     1821    char *pszBlockDevName = getfullblkname(pThis->pszDevice);
     1822    if (!pszBlockDevName)
     1823        return VERR_NO_MEMORY;
     1824    pThis->pszDeviceOpen = RTStrDup(pszBlockDevName);  /* for RTStrFree() */
     1825    free(pszBlockDevName);
     1826    pThis->pszRawDeviceOpen = RTStrDup(pThis->pszDevice);
     1827
    17601828#else
    17611829    pThis->pszDeviceOpen = RTStrDup(pThis->pszDevice);
    17621830#endif
     1831
    17631832    if (!pThis->pszDeviceOpen)
    17641833        return VERR_NO_MEMORY;
     
    18591928        pThis->FileDevice = NIL_RTFILE;
    18601929#endif
    1861         /* Disable CD/DVD passthrough in case it was enabled. Would cause
     1930#ifdef RT_OS_SOLARIS
     1931        pThis->FileRawDevice = NIL_RTFILE;
     1932#endif
     1933
     1934        /*
     1935         * Disable CD/DVD passthrough in case it was enabled. Would cause
    18621936         * weird failures later when the guest issues commands. These would
    18631937         * all fail because of the invalid file handle. So use the normal
    18641938         * virtual CD/DVD code, which deals more gracefully with unavailable
    1865          * "media" - actually a complete drive in this case. */
     1939         * "media" - actually a complete drive in this case.
     1940         */
    18661941        pThis->IBlock.pfnSendCmd = NULL;
    18671942        AssertMsgFailed(("Could not open host device %s, rc=%Vrc\n", pszDevice, rc));
  • trunk/src/VBox/Devices/Storage/DrvHostBase.h

    r4071 r5212  
     1/* $Id$ */
    12/** @file
    2  *
    3  * VBox storage devices:
    4  * Host base drive access driver
     3 * DrvHostBase - Host base drive access driver.
    54 */
    65
     
    5352    /** Device name to open (RTStrFree). */
    5453    char                   *pszDeviceOpen;
     54#ifdef RT_OS_SOLARIS
     55    /** Device name of raw device (RTStrFree). */
     56    char                   *pszRawDeviceOpen;
     57#endif
    5558    /** Uuid of the drive. */
    5659    RTUUID                  Uuid;
     
    7780    /** The filehandle of the device. */
    7881    RTFILE                  FileDevice;
     82#endif
     83#ifdef RT_OS_SOLARIS
     84    /** The raw filehandle of the device. */
     85    RTFILE                  FileRawDevice;
    7986#endif
    8087
  • trunk/src/VBox/Devices/Storage/DrvHostDVD.cpp

    r5184 r5212  
     1/* $Id$ */
    12/** @file
    2  *
    3  * VBox storage devices:
    4  * Host DVD block driver
     3 * DrvHostDVD - Host DVD block driver.
    54 */
    65
     
    132131
    133132#elif defined(RT_OS_SOLARIS)
    134         rc = ioctl(pThis->FileDevice, DKIOCEJECT, 0);
     133        rc = ioctl(pThis->FileRawDevice, DKIOCEJECT, 0);
    135134        if (rc < 0)
    136135        {
     
    221220
    222221#elif defined(RT_OS_SOLARIS)
    223     int rc = ioctl(pThis->FileDevice, fLock ? DKIOCLOCK : DKIOCUNLOCK, 0);
     222    int rc = ioctl(pThis->FileRawDevice, fLock ? DKIOCLOCK : DKIOCUNLOCK, 0);
    224223    if (rc < 0)
    225224    {
     
    326325    /* Need to pass the previous state and DKIO_NONE for the first time. */
    327326    static dkio_state DeviceState = DKIO_NONE;
    328     int rc2 = ioctl(pThis->FileDevice, DKIOCSTATE, &DeviceState);
     327    int rc2 = ioctl(pThis->FileRawDevice, DKIOCSTATE, &DeviceState);
    329328    if (rc2 == 0)
    330329    {
     
    509508
    510509    /* We need root privileges for user-SCSI under Solaris. */
    511     rc = ioctl(pThis->FileDevice, USCSICMD, &usc);
     510    rc = ioctl(pThis->FileRawDevice, USCSICMD, &usc);
    512511    if (rc < 0)
    513512    {
     
    625624    if (*pEffUserID == 0)
    626625        return VINF_SUCCESS;
     626    else
     627    {
     628        if (seteuid(0) == 0)
     629        {
     630            *pEffUserID = 0;
     631            return VINF_SUCCESS;
     632        }
     633        else
     634            return VERR_PERMISSION_DENIED;
     635    }
     636}
     637
     638/**
     639 * Setuid wrapper to relinquish root access.
     640 *
     641 * @returns VBox error code.
     642 * @param   pUserID        Pointer to user ID.
     643 * @param   pEffUserID     Pointer to effective user ID.
     644 */
     645static int solarisExitRootMode(uid_t *pUserID, uid_t *pEffUserID)
     646{
     647    /* Get back to user mode. */
     648    if (*pEffUserID == 0)
     649    {
     650        if (seteuid(*pUserID) == 0)
     651        {
     652            *pEffUserID = *pUserID;
     653            return VINF_SUCCESS;
     654        }
     655        else
     656            return VERR_PERMISSION_DENIED;
     657    }
     658    return VINF_SUCCESS;
     659}
     660
     661/**
     662 * Setuid wrapper to gain root access.
     663 *
     664 * @returns VBox error code.
     665 * @param   pUserID        Pointer to user ID.
     666 * @param   pEffUserID     Pointer to effective user ID.
     667 */
     668static int solarisEnterRootMode(uid_t *pUserID, uid_t *pEffUserID)
     669{
     670    /* Increase privilege if required */
     671    if (*pEffUserID == 0)
     672        return VINF_SUCCESS;
    627673    if (seteuid(0) == 0)
    628674    {
     
    720766        rc = DRVHostBaseInitFinish(pThis);
    721767    }
    722 
    723768    if (VBOX_FAILURE(rc))
    724769    {
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