From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Permerror (SPF Permanent Error: More than 10 MX records returned) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id F3F4821B02839 for ; Thu, 7 Dec 2017 01:50:32 -0800 (PST) Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Dec 2017 01:55:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,372,1508828400"; d="scan'208";a="791121" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.14]) by orsmga007.jf.intel.com with ESMTP; 07 Dec 2017 01:55:04 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Star Zeng , Hao A Wu Date: Thu, 7 Dec 2017 17:55:03 +0800 Message-Id: <20171207095503.20652-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.0.gvfs.1.preview.4 Subject: [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no media presents X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Dec 2017 09:50:33 -0000 Current code always return EFI_MEDIA_CHANGED no matter the media is removed from CD/DVD drive or the media is changed. It doesn't strictly follow the UEFI Spec. Update code to return EFI_NO_MEDIA when media is removed. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Star Zeng Cc: Hao A Wu --- MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c | 41 ++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 11 deletions(-) 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; -- 2.15.0.gvfs.1.preview.4