VirtualBox

Changeset 39566 in vbox


Ignore:
Timestamp:
Dec 9, 2011 1:27:31 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75320
Message:

SCSI: Add support for readonly disks

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/scsi.h

    r38680 r39566  
    185185#define SCSI_ASC_LOGICAL_BLOCK_OOR                          0x21
    186186#define SCSI_ASC_INV_FIELD_IN_CMD_PACKET                    0x24
     187#define SCSI_ASC_WRITE_PROTECTED                            0x27
    187188#define SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED                    0x28
    188189#define SCSI_ASC_MEDIUM_NOT_PRESENT                         0x3a
  • trunk/include/VBox/vscsi.h

    r38878 r39566  
    9999/** The LUN has a non rotational medium. */
    100100#define VSCSI_LUN_FEATURE_NON_ROTATIONAL RT_BIT(1)
     101/** The medium of the LUN is readonly. */
     102#define VSCSI_LUN_FEATURE_READONLY       RT_BIT(2)
    101103
    102104/**
  • trunk/src/VBox/Devices/Storage/DrvSCSI.cpp

    r39550 r39566  
    107107    /** Mark the drive as having a non-rotational medium (i.e. as a SSD). */
    108108    bool                    fNonRotational;
     109    /** Medium is readonly */
     110    bool                    fReadonly;
    109111} DRVSCSI, *PDRVSCSI;
    110112
     
    422424        *pfFeatures |= VSCSI_LUN_FEATURE_NON_ROTATIONAL;
    423425
     426    if (pThis->fReadonly)
     427        *pfFeatures |= VSCSI_LUN_FEATURE_READONLY;
     428
    424429    return VINF_SUCCESS;
    425430}
     
    825830     * Validate and read configuration.
    826831     */
    827     if (!CFGMR3AreValuesValid(pCfg, "NonRotationalMedium\0"))
     832    if (!CFGMR3AreValuesValid(pCfg, "NonRotationalMedium\0Readonly\0"))
    828833        return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    829834                                N_("SCSI configuration error: unknown option specified"));
     
    833838        return PDMDRV_SET_ERROR(pDrvIns, rc,
    834839                    N_("SCSI configuration error: failed to read \"NonRotationalMedium\" as boolean"));
     840
     841    rc = CFGMR3QueryBoolDef(pCfg, "Readonly", &pThis->fReadonly, false);
     842    if (RT_FAILURE(rc))
     843        return PDMDRV_SET_ERROR(pDrvIns, rc,
     844                                N_("SCSI configuration error: failed to read \"Readonly\" as boolean"));
    835845
    836846    /*
  • trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunSbc.cpp

    r38878 r39566  
    260260            aReply[3] = 0; /* Block descriptor length. */
    261261
     262            if (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_READONLY)
     263                aReply[2] |= RT_BIT(7); /* Set write protect bit */
     264
    262265            pu8ReplyPos = aReply + 4;
    263266
     
    509512        {
    510513            /* Enqueue new I/O request */
    511             rc = vscsiIoReqTransferEnqueue(pVScsiLun, pVScsiReq, enmTxDir,
    512                                            uLbaStart * 512, cSectorTransfer * 512);
     514            if (   (   enmTxDir == VSCSIIOREQTXDIR_WRITE
     515                    || enmTxDir == VSCSIIOREQTXDIR_FLUSH)
     516                && (pVScsiLun->fFeatures & VSCSI_LUN_FEATURE_READONLY))
     517                rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_DATA_PROTECT, SCSI_ASC_WRITE_PROTECTED, 0x00);
     518            else
     519                rc = vscsiIoReqTransferEnqueue(pVScsiLun, pVScsiReq, enmTxDir,
     520                                               uLbaStart * 512, cSectorTransfer * 512);
    513521        }
    514522    }
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