Index: /trunk/include/VBox/vscsi.h
===================================================================
--- /trunk/include/VBox/vscsi.h	(revision 43639)
+++ /trunk/include/VBox/vscsi.h	(revision 43640)
@@ -271,4 +271,20 @@
 
 /**
+ * Notify virtual SCSI LUN of medium being mounted.
+ *
+ * @returns VBox status code.
+ * @param   hVScsiLun               The virtual SCSI LUN handle to destroy.
+ */
+VBOXDDU_DECL(int) VSCSILunMountNotify(VSCSILUN hVScsiLun);
+
+/**
+ * Notify virtual SCSI LUN of medium being unmounted.
+ *
+ * @returns VBox status code.
+ * @param   hVScsiLun               The virtual SCSI LUN handle to destroy.
+ */
+VBOXDDU_DECL(int) VSCSILunUnmountNotify(VSCSILUN hVScsiLun);
+
+/**
  * Notify a that a I/O request completed.
  *
Index: /trunk/src/VBox/Devices/Storage/DrvSCSI.cpp
===================================================================
--- /trunk/src/VBox/Devices/Storage/DrvSCSI.cpp	(revision 43639)
+++ /trunk/src/VBox/Devices/Storage/DrvSCSI.cpp	(revision 43640)
@@ -668,5 +668,6 @@
         return;
 
-    //@todo: Notify of media change? Update media size? 
+    /* Let the LUN know that a medium was mounted. */
+    VSCSILunMountNotify(pThis->hVScsiLun);
 }
 
@@ -681,5 +682,6 @@
     LogFlowFunc(("unmounting LUN#%p\n", pThis->hVScsiLun));
 
-    //@todo: Notify of media change? Report that no media is present?
+    /* Let the LUN know that the medium was unmounted. */
+    VSCSILunUnmountNotify(pThis->hVScsiLun);
 }
 
@@ -854,4 +856,5 @@
     PDRVSCSI pThis = PDMINS_2_DATA(pDrvIns, PDRVSCSI);
     LogFlowFunc(("pDrvIns=%#p pCfg=%#p\n", pDrvIns, pCfg));
+LogRelFunc(("pDrvIns=%#p pCfg=%#p\n", pDrvIns, pCfg));
     PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
 
@@ -966,4 +969,20 @@
     rc = VSCSIDeviceLunAttach(pThis->hVScsiDevice, pThis->hVScsiLun, 0);
     AssertMsgReturn(RT_SUCCESS(rc), ("Failed to attached the LUN to the SCSI device\n"), rc);
+
+    //@todo: This is a very hacky way of telling the LUN whether a medium was mounted.
+    // The mount/unmount interface doesn't work in a very sensible manner!
+    if (pThis->pDrvMount)
+    {
+        if (pThis->pDrvBlock->pfnGetSize(pThis->pDrvBlock))
+        {
+            rc = VINF_SUCCESS; VSCSILunMountNotify(pThis->hVScsiLun);
+            AssertMsgReturn(RT_SUCCESS(rc), ("Failed to notify the LUN of media being mounted\n"), rc);
+        }
+        else
+        {
+            rc = VINF_SUCCESS; VSCSILunUnmountNotify(pThis->hVScsiLun);
+            AssertMsgReturn(RT_SUCCESS(rc), ("Failed to notify the LUN of media being unmounted\n"), rc);
+        }
+    }
 
     /* Register statistics counter. */
@@ -1054,3 +1073,2 @@
     PDM_DRVREG_VERSION
 };
-
Index: /trunk/src/VBox/Devices/Storage/VSCSI/VSCSIDevice.cpp
===================================================================
--- /trunk/src/VBox/Devices/Storage/VSCSI/VSCSIDevice.cpp	(revision 43639)
+++ /trunk/src/VBox/Devices/Storage/VSCSI/VSCSIDevice.cpp	(revision 43640)
@@ -102,5 +102,8 @@
         case SCSI_TEST_UNIT_READY:
         {
-            *prcReq = vscsiReqSenseOkSet(&pVScsiDevice->VScsiSense, pVScsiReq);
+            if (pVScsiDevice->papVScsiLun[pVScsiReq->iLun]->fReady)
+                *prcReq = vscsiReqSenseOkSet(&pVScsiDevice->VScsiSense, pVScsiReq);
+            else
+                fProcessed = false; /* The LUN will provide details. */
             break;
         }
@@ -344,3 +347,2 @@
     return VINF_SUCCESS;
 }
-
Index: /trunk/src/VBox/Devices/Storage/VSCSI/VSCSIInternal.h
===================================================================
--- /trunk/src/VBox/Devices/Storage/VSCSI/VSCSIInternal.h	(revision 43639)
+++ /trunk/src/VBox/Devices/Storage/VSCSI/VSCSIInternal.h	(revision 43640)
@@ -86,4 +86,8 @@
     /** Pointer to the LUN type descriptor. */
     PVSCSILUNDESC        pVScsiLunDesc;
+    /** Flag indicating whether LUN is ready. */
+    bool                 fReady;
+    /** Flag indicating media presence in LUN. */
+    bool                 fMediaPresent;
     /** Flags of supported features. */
     uint64_t             fFeatures;
Index: /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILun.cpp
===================================================================
--- /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILun.cpp	(revision 43639)
+++ /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILun.cpp	(revision 43640)
@@ -116,2 +116,44 @@
 }
 
+/**
+ * Notify virtual SCSI LUN of media being mounted.
+ *
+ * @returns VBox status code.
+ * @param   hVScsiLun               The virtual SCSI LUN 
+ *                                  mounting the medium.
+ */
+VBOXDDU_DECL(int) VSCSILunMountNotify(VSCSILUN hVScsiLun)
+{
+    PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
+
+    LogFlowFunc(("hVScsiLun=%p\n", hVScsiLun));
+    AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
+    AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
+
+    /* Mark the LUN as not ready so that LUN specific code can do its job. */
+    pVScsiLun->fReady        = false;
+    pVScsiLun->fMediaPresent = true;
+
+    return VINF_SUCCESS;
+}
+
+/**
+ * Notify virtual SCSI LUN of media being unmounted.
+ *
+ * @returns VBox status code.
+ * @param   hVScsiLun               The virtual SCSI LUN 
+ *                                  mounting the medium.
+ */
+VBOXDDU_DECL(int) VSCSILunUnmountNotify(VSCSILUN hVScsiLun)
+{
+    PVSCSILUNINT pVScsiLun = (PVSCSILUNINT)hVScsiLun;
+
+    LogFlowFunc(("hVScsiLun=%p\n", hVScsiLun));
+    AssertPtrReturn(pVScsiLun, VERR_INVALID_HANDLE);
+    AssertReturn(vscsiIoReqOutstandingCountGet(pVScsiLun) == 0, VERR_VSCSI_LUN_BUSY);
+
+    pVScsiLun->fReady        = false;
+    pVScsiLun->fMediaPresent = false;
+
+    return VINF_SUCCESS;
+}
Index: /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunMmc.cpp
===================================================================
--- /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunMmc.cpp	(revision 43639)
+++ /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunMmc.cpp	(revision 43640)
@@ -153,7 +153,38 @@
     int             rc = VINF_SUCCESS;
     int             rcReq = SCSI_STATUS_OK;
-
-    switch(pVScsiReq->pbCDB[0])
-    {
+    unsigned        uCmd = pVScsiReq->pbCDB[0];
+
+    /* 
+     * GET CONFIGURATION, GET EVENT/STATUS NOTIFICATION, INQUIRY, and REQUEST SENSE commands
+     * operate even when a unit attention condition exists for initiator; every other command
+     * needs to report CHECK CONDITION in that case.
+     */
+    if (!pVScsiLunMmc->Core.fReady && uCmd != SCSI_INQUIRY)
+    {
+        /*
+         * A note on media changes: As long as a medium is not present, the unit remains in 
+         * the 'not ready' state. Technically the unit becomes 'ready' soon after a medium 
+         * is inserted; however, we internally keep the 'not ready' state until we've had 
+         * a chance to report the UNIT ATTENTION status indicating a media change.
+         */
+        if (pVScsiLunMmc->Core.fMediaPresent)
+        {
+            rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_UNIT_ATTENTION,
+                                             SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED, 0x00);
+            pVScsiLunMmc->Core.fReady = true;
+        }
+        else 
+            rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_NOT_READY,
+                                             SCSI_ASC_MEDIUM_NOT_PRESENT, 0x00);
+    }
+    else
+    {
+        switch (uCmd)
+        {
+        case SCSI_TEST_UNIT_READY:
+            Assert(!pVScsiLunMmc->Core.fReady); /* Only should get here if LUN isn't ready. */
+            rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_NOT_READY, SCSI_ASC_MEDIUM_NOT_PRESENT, 0x00);
+            break;
+
         case SCSI_INQUIRY:
         {
@@ -373,4 +404,5 @@
             //AssertMsgFailed(("Command %#x [%s] not implemented\n", pVScsiReq->pbCDB[0], SCSICmdText(pVScsiReq->pbCDB[0])));
             rcReq = vscsiLunReqSenseErrorSet(pVScsiLun, pVScsiReq, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_ILLEGAL_OPCODE, 0x00);
+        }
     }
 
Index: /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunSbc.cpp
===================================================================
--- /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunSbc.cpp	(revision 43639)
+++ /trunk/src/VBox/Devices/Storage/VSCSI/VSCSILunSbc.cpp	(revision 43640)
@@ -168,4 +168,7 @@
     }
 
+    /* For SBC LUNs, there will be no ready state transitions. */
+    pVScsiLunSbc->Core.fReady = true;
+
     return rc;
 }
@@ -446,5 +449,5 @@
                     && cbList >= 8)
                 {
-                    size_t cBlkDesc = vscsiBE2HU16(&abHdr[2]) / 16;
+                    uint32_t    cBlkDesc = vscsiBE2HU16(&abHdr[2]) / 16;
 
                     if (cBlkDesc)
