[edk2] [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no media presents

Ruiyu Ni posted 1 patch 7 years ago
Failed in applying to current master (apply log)
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c | 41 ++++++++++++++++++++--------
1 file changed, 30 insertions(+), 11 deletions(-)
[edk2] [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no media presents
Posted by Ruiyu Ni 7 years ago
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 <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
---
 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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no media presents
Posted by Wu, Hao A 7 years ago
Reviewed-by: Hao Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu


> -----Original Message-----
> From: Ni, Ruiyu
> Sent: Thursday, December 07, 2017 5:55 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star; Wu, Hao A
> Subject: [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no
> media presents
> 
> 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 <ruiyu.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> ---
>  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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no media presents
Posted by Zeng, Star 7 years ago
Reviewed-by: Star Zeng <star.zeng@intel.com>

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ruiyu Ni
Sent: Thursday, December 7, 2017 5:55 PM
To: edk2-devel@lists.01.org
Cc: Wu, Hao A <hao.a.wu@intel.com>; Zeng, Star <star.zeng@intel.com>
Subject: [edk2] [PATCH] MdeModulePkg/ScsiDisk: Return EFI_NO_MEDIA when no media presents

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 <ruiyu.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
---
 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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel