diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c index 2289f20152..6a0a193556 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c @@ -568,6 +568,7 @@ ScsiDiskReadBlocks ( MediaChange = FALSE; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (This); + Media = ScsiDiskDevice->BlkIo.Media; if (!IS_DEVICE_FIXED(ScsiDiskDevice)) { @@ -598,14 +599,17 @@ ScsiDiskReadBlocks ( &ScsiDiskDevice->EraseBlock ); } - Status = EFI_MEDIA_CHANGED; + if (Media->MediaPresent) { + Status = EFI_MEDIA_CHANGED; + } else { + Status = EFI_NO_MEDIA; + } goto Done; } } // // Get the intrinsic block size // - Media = ScsiDiskDevice->BlkIo.Media; BlockSize = Media->BlockSize; NumberOfBlocks = BufferSize / BlockSize; @@ -700,6 +704,7 @@ ScsiDiskWriteBlocks ( MediaChange = FALSE; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO (This); + Media = ScsiDiskDevice->BlkIo.Media; if (!IS_DEVICE_FIXED(ScsiDiskDevice)) { @@ -730,14 +735,17 @@ ScsiDiskWriteBlocks ( &ScsiDiskDevice->EraseBlock ); } - Status = EFI_MEDIA_CHANGED; + if (Media->MediaPresent) { + Status = EFI_MEDIA_CHANGED; + } else { + Status = EFI_NO_MEDIA; + } goto Done; } } // // Get the intrinsic block size // - Media = ScsiDiskDevice->BlkIo.Media; BlockSize = Media->BlockSize; NumberOfBlocks = BufferSize / BlockSize; @@ -922,6 +930,7 @@ ScsiDiskReadBlocksEx ( MediaChange = FALSE; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This); + Media = ScsiDiskDevice->BlkIo.Media; if (!IS_DEVICE_FIXED(ScsiDiskDevice)) { @@ -952,14 +961,17 @@ ScsiDiskReadBlocksEx ( &ScsiDiskDevice->EraseBlock ); } - Status = EFI_MEDIA_CHANGED; + if (Media->MediaPresent) { + Status = EFI_MEDIA_CHANGED; + } else { + Status = EFI_NO_MEDIA; + } goto Done; } } // // Get the intrinsic block size // - Media = ScsiDiskDevice->BlkIo2.Media; BlockSize = Media->BlockSize; NumberOfBlocks = BufferSize / BlockSize; @@ -1081,6 +1093,7 @@ ScsiDiskWriteBlocksEx ( MediaChange = FALSE; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This); + Media = ScsiDiskDevice->BlkIo.Media; if (!IS_DEVICE_FIXED(ScsiDiskDevice)) { @@ -1111,14 +1124,17 @@ ScsiDiskWriteBlocksEx ( &ScsiDiskDevice->EraseBlock ); } - Status = EFI_MEDIA_CHANGED; + if (Media->MediaPresent) { + Status = EFI_MEDIA_CHANGED; + } else { + Status = EFI_NO_MEDIA; + } goto Done; } } // // Get the intrinsic block size // - Media = ScsiDiskDevice->BlkIo2.Media; BlockSize = Media->BlockSize; NumberOfBlocks = BufferSize / BlockSize; @@ -1230,6 +1246,7 @@ ScsiDiskFlushBlocksEx ( MediaChange = FALSE; OldTpl = gBS->RaiseTPL (TPL_CALLBACK); ScsiDiskDevice = SCSI_DISK_DEV_FROM_BLKIO2 (This); + Media = ScsiDiskDevice->BlkIo.Media; if (!IS_DEVICE_FIXED(ScsiDiskDevice)) { @@ -1260,13 +1277,15 @@ ScsiDiskFlushBlocksEx ( &ScsiDiskDevice->EraseBlock ); } - Status = EFI_MEDIA_CHANGED; + if (Media->MediaPresent) { + Status = EFI_MEDIA_CHANGED; + } else { + Status = EFI_NO_MEDIA; + } goto Done; } } - Media = ScsiDiskDevice->BlkIo2.Media; - if (!(Media->MediaPresent)) { Status = EFI_NO_MEDIA; goto Done;