VirtualBox

Ignore:
Timestamp:
Oct 19, 2016 11:59:42 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
111389
Message:

Devices/Storage/DrvHost*: Move host dependent members of DRVHOSTBASE into a private struct for each host to keep including host dependent headers in one file for each host

File:
1 edited

Legend:

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

    r64278 r64316  
    3333
    3434#include <iprt/file.h>
     35
     36/**
     37 * Host backend specific data.
     38 */
     39typedef struct DRVHOSTBASEOS
     40{
     41    /** The filehandle of the device. */
     42    RTFILE                  hFileDevice;
     43    /** The raw filehandle of the device. */
     44    RTFILE                  hFileRawDevice;
     45    /** Device name of raw device (RTStrFree). */
     46    char                   *pszRawDeviceOpen;
     47} DRVHOSTBASEOS;
     48/** Pointer to the host backend specific data. */
     49typedef DRVHOSTBASEOS *PDRVHOSBASEOS;
     50AssertCompile(sizeof(DRVHOSTBASEOS) <= 64);
     51
     52#define DRVHOSTBASE_OS_INT_DECLARED
    3553#include "DrvHostBase.h"
    3654
     
    4058 * return the value. BUT... this might be prohibitively slow.
    4159 */
     60
     61/**
     62 * Checks if the current user is authorized using Solaris' role-based access control.
     63 * Made as a separate function with so that it need not be invoked each time we need
     64 * to gain root access.
     65 *
     66 * @returns VBox error code.
     67 */
     68static int solarisCheckUserAuth()
     69{
     70    /* Uses Solaris' role-based access control (RBAC).*/
     71    struct passwd *pPass = getpwuid(getuid());
     72    if (pPass == NULL || chkauthattr("solaris.device.cdrw", pPass->pw_name) == 0)
     73        return VERR_PERMISSION_DENIED;
     74
     75    return VINF_SUCCESS;
     76}
    4277
    4378/**
     
    148183    solarisEnterRootMode(&effUserID); /** @todo check return code when this really works. */
    149184#endif
    150     rc = ioctl(RTFileToNative(pThis->hFileRawDevice), USCSICMD, &usc);
     185    rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), USCSICMD, &usc);
    151186#ifdef VBOX_WITH_SUID_WRAPPER
    152187    solarisExitRootMode(&effUserID);
     
    175210     */
    176211    struct dk_minfo MediaInfo;
    177     if (ioctl(RTFileToNative(pThis->hFileRawDevice), DKIOCGMEDIAINFO, &MediaInfo) == 0)
     212    if (ioctl(RTFileToNative(pThis->Os.hFileRawDevice), DKIOCGMEDIAINFO, &MediaInfo) == 0)
    178213    {
    179214        *pcb = MediaInfo.dki_capacity * (uint64_t)MediaInfo.dki_lbsize;
    180215        return VINF_SUCCESS;
    181216    }
    182     return RTFileSeek(pThis->hFileDevice, 0, RTFILE_SEEK_END, pcb);
     217    return RTFileSeek(pThis->Os.hFileDevice, 0, RTFILE_SEEK_END, pcb);
    183218}
    184219
     
    186221DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
    187222{
    188     return RTFileReadAt(pThis->hFileDevice, off, pvBuf, cbRead, NULL);
     223    return RTFileReadAt(pThis->Os.hFileDevice, off, pvBuf, cbRead, NULL);
    189224}
    190225
     
    192227DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
    193228{
    194     return RTFileWriteAt(pThis->hFileDevice, off, pvBuf, cbWrite, NULL);
     229    return RTFileWriteAt(pThis->Os.hFileDevice, off, pvBuf, cbWrite, NULL);
    195230}
    196231
     
    198233DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
    199234{
    200     return RTFileFlush(pThis->hFileDevice);
     235    return RTFileFlush(pThis->Os.hFileDevice);
    201236}
    202237
     
    204239DECLHIDDEN(int) drvHostBaseDoLockOs(PDRVHOSTBASE pThis, bool fLock)
    205240{
    206     int rc = ioctl(RTFileToNative(pThis->hFileRawDevice), fLock ? DKIOCLOCK : DKIOCUNLOCK, 0);
     241    int rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), fLock ? DKIOCLOCK : DKIOCUNLOCK, 0);
    207242    if (rc < 0)
    208243    {
     
    221256DECLHIDDEN(int) drvHostBaseEjectOs(PDRVHOSTBASE pThis)
    222257{
    223     int rc = ioctl(RTFileToNative(pThis->hFileRawDevice), DKIOCEJECT, 0);
     258    int rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), DKIOCEJECT, 0);
    224259    if (rc < 0)
    225260    {
     
    246281    static dkio_state s_DeviceState = DKIO_NONE;
    247282    dkio_state PreviousState = s_DeviceState;
    248     int rc = ioctl(RTFileToNative(pThis->hFileRawDevice), DKIOCSTATE, &s_DeviceState);
     283    int rc = ioctl(RTFileToNative(pThis->Os.hFileRawDevice), DKIOCSTATE, &s_DeviceState);
    249284    if (rc == 0)
    250285    {
     
    258293
    259294
    260 DECLHIDDEN(int) drvHostBasePollerWakeupOs(PDRVHOSTBASE pThis)
    261 {
    262     return RTSemEventSignal(pThis->EventPoller);
     295DECLHIDDEN(void) drvHostBaseInitOs(PDRVHOSTBASE pThis)
     296{
     297    pThis->Os.hFileDevice      = NIL_RTFILE;
     298    pThis->Os.hFileRawDevice   = NIL_RTFILE;
     299    pThis->Os.pszRawDeviceOpen = NULL;
     300}
     301
     302
     303DECLHIDDEN(int) drvHostBaseOpenOs(PDRVHOSTBASE pThis, bool fReadOnly)
     304{
     305#ifdef VBOX_WITH_SUID_WRAPPER  /* Solaris setuid for Passthrough mode. */
     306    if (   (pThis->enmType == PDMMEDIATYPE_CDROM || pThis->enmType == PDMMEDIATYPE_DVD)
     307        && pThis->IMedia.pfnSendCmd)
     308    {
     309        rc = solarisCheckUserAuth();
     310        if (RT_FAILURE(rc))
     311        {
     312            Log(("DVD: solarisCheckUserAuth failed. Permission denied!\n"));
     313            return rc;
     314        }
     315    }
     316#endif /* VBOX_WITH_SUID_WRAPPER */
     317
     318    char *pszBlockDevName = getfullblkname(pThis->pszDevice);
     319    if (!pszBlockDevName)
     320        return VERR_NO_MEMORY;
     321    pThis->pszDeviceOpen = RTStrDup(pszBlockDevName);  /* for RTStrFree() */
     322    free(pszBlockDevName);
     323    pThis->Os.pszRawDeviceOpen = RTStrDup(pThis->pszDevice);
     324    if (!pThis->pszDeviceOpen || !pThis->Os.pszRawDeviceOpen);
     325        return VERR_NO_MEMORY;
     326
     327    unsigned fFlags = (fReadOnly ? RTFILE_O_READ : RTFILE_O_READWRITE)
     328                    | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_NON_BLOCK;
     329    int rc = RTFileOpen(&pThis->Os.hFileDevice, pThis->pszDeviceOpen, fFlags);
     330    if (RT_SUCCESS(rc))
     331    {
     332        rc = RTFileOpen(&pThis->Os.hFileRawDevice, pThis->Os.pszRawDeviceOpen, fFlags);
     333        if (RT_SUCCESS(rc))
     334            return rc;
     335
     336        LogRel(("DVD: failed to open device %s rc=%Rrc\n", pThis->Os.pszRawDeviceOpen, rc));
     337        RTFileClose(pThis->Os.hFileDevice);
     338    }
     339    else
     340        LogRel(("DVD: failed to open device %s rc=%Rrc\n", pThis->pszDeviceOpen, rc));
     341    return rc;
     342}
     343
     344
     345DECLHIDDEN(int) drvHostBaseMediaRefreshOs(PDRVHOSTBASE pThis)
     346{
     347    RT_NOREF(pThis);
     348    return VINF_SUCCESS;
     349}
     350
     351
     352DECLHIDDEN(bool) drvHostBaseIsMediaPollingRequiredOs(PDRVHOSTBASE pThis)
     353{
     354    if (pThis->enmType == PDMMEDIATYPE_CDROM || pThis->enmType == PDMMEDIATYPE_DVD)
     355        return true;
     356
     357    AssertMsgFailed(("Solaris supports only CD/DVD host drive access\n"));
     358    return false;
    263359}
    264360
     
    266362DECLHIDDEN(void) drvHostBaseDestructOs(PDRVHOSTBASE pThis)
    267363{
    268     if (pThis->EventPoller != NULL)
    269     {
    270         RTSemEventDestroy(pThis->EventPoller);
    271         pThis->EventPoller = NULL;
    272     }
    273 
    274     if (pThis->hFileDevice != NIL_RTFILE)
    275     {
    276         int rc = RTFileClose(pThis->hFileDevice);
     364    /*
     365     * Unlock the drive if we've locked it or we're in passthru mode.
     366     */
     367    if (    pThis->fLocked
     368        &&  pThis->Os.hFileDevice != NIL_RTFILE
     369        &&  pThis->pfnDoLock)
     370    {
     371        int rc = pThis->pfnDoLock(pThis, false);
     372        if (RT_SUCCESS(rc))
     373            pThis->fLocked = false;
     374    }
     375
     376    if (pThis->Os.hFileDevice != NIL_RTFILE)
     377    {
     378        int rc = RTFileClose(pThis->Os.hFileDevice);
    277379        AssertRC(rc);
    278         pThis->hFileDevice = NIL_RTFILE;
    279     }
    280 
    281     if (pThis->hFileRawDevice != NIL_RTFILE)
    282     {
    283         int rc = RTFileClose(pThis->hFileRawDevice);
     380        pThis->Os.hFileDevice = NIL_RTFILE;
     381    }
     382
     383    if (pThis->Os.hFileRawDevice != NIL_RTFILE)
     384    {
     385        int rc = RTFileClose(pThis->Os.hFileRawDevice);
    284386        AssertRC(rc);
    285         pThis->hFileRawDevice = NIL_RTFILE;
    286     }
    287 
    288     if (pThis->pszRawDeviceOpen)
    289     {
    290         RTStrFree(pThis->pszRawDeviceOpen);
    291         pThis->pszRawDeviceOpen = NULL;
    292     }
    293 }
    294 
     387        pThis->Os.hFileRawDevice = NIL_RTFILE;
     388    }
     389
     390    if (pThis->Os.pszRawDeviceOpen)
     391    {
     392        RTStrFree(pThis->Os.pszRawDeviceOpen);
     393        pThis->Os.pszRawDeviceOpen = NULL;
     394    }
     395}
     396
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