]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Change BlockIo drivers to return EFI_NO_MEDIA or EFI_MEDIA_CHANGED even the Buffer...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 25 Apr 2011 09:31:57 +0000 (09:31 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 25 Apr 2011 09:31:57 +0000 (09:31 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11584 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c
MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c

index 6b8257e1b6d42961ec674aa176c26b7cda67882d..a3c0670c98c744df6332279cb358095e913c43ef 100644 (file)
@@ -842,6 +842,11 @@ BlockIoReadWrite (
   //\r
   // Check parameters.\r
   //\r
+  Media = This->Media;\r
+  if (MediaId != Media->MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
   if (Buffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -850,11 +855,6 @@ BlockIoReadWrite (
     return EFI_SUCCESS;\r
   }\r
 \r
-  Media = This->Media;\r
-  if (MediaId != Media->MediaId) {\r
-    return EFI_MEDIA_CHANGED;\r
-  }\r
-\r
   BlockSize = Media->BlockSize;\r
   if ((BufferSize % BlockSize) != 0) {\r
     return EFI_BAD_BUFFER_SIZE;\r
index 3f6963ef198e41543158df291175c8677e0acfc2..fd63857a5e29db96b90ec27c9527edfedc5ad55c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   SCSI disk driver that layers on every SCSI IO protocol in the system.\r
 \r
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -454,17 +454,8 @@ ScsiDiskReadBlocks (
   BOOLEAN             MediaChange;\r
   EFI_TPL             OldTpl;\r
 \r
-  MediaChange = FALSE;\r
-  if (Buffer == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (BufferSize == 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-\r
+  MediaChange    = FALSE;\r
+  OldTpl         = gBS->RaiseTPL (TPL_CALLBACK);\r
   ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);\r
 \r
   if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
@@ -502,6 +493,16 @@ ScsiDiskReadBlocks (
     goto Done;\r
   }\r
 \r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  }\r
+\r
+  if (BufferSize == 0) {\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
   if (BufferSize % BlockSize != 0) {\r
     Status = EFI_BAD_BUFFER_SIZE;\r
     goto Done;\r
@@ -569,17 +570,8 @@ ScsiDiskWriteBlocks (
   BOOLEAN             MediaChange;\r
   EFI_TPL             OldTpl;\r
 \r
-  MediaChange = FALSE;\r
-  if (Buffer == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (BufferSize == 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-\r
+  MediaChange    = FALSE;\r
+  OldTpl         = gBS->RaiseTPL (TPL_CALLBACK);\r
   ScsiDiskDevice = SCSI_DISK_DEV_FROM_THIS (This);\r
 \r
   if (!IS_DEVICE_FIXED(ScsiDiskDevice)) {\r
@@ -617,6 +609,16 @@ ScsiDiskWriteBlocks (
     goto Done;\r
   }\r
 \r
+  if (BufferSize == 0) {\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  }\r
+\r
   if (BufferSize % BlockSize != 0) {\r
     Status = EFI_BAD_BUFFER_SIZE;\r
     goto Done;\r
index f440e9fd7c5f78820afbce67ed165630a94a26c3..107eb8b4e4ba9d93e3a3ca1027eafd861b0ea27a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   USB Mass Storage Driver that manages USB Mass Storage Device and produces Block I/O Protocol.\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -113,13 +113,6 @@ UsbMassReadBlocks (
   EFI_TPL             OldTpl;\r
   UINTN               TotalBlock;\r
 \r
-  //\r
-  // First, validate the parameters\r
-  //\r
-  if ((Buffer == NULL) || (BufferSize == 0)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
   //\r
   // Raise TPL to TPL_NOTIFY to serialize all its operations\r
   // to protect shared data structures.\r
@@ -140,6 +133,26 @@ UsbMassReadBlocks (
     }\r
   }\r
 \r
+  if (!(Media->MediaPresent)) {\r
+    Status = EFI_NO_MEDIA;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (MediaId != Media->MediaId) {\r
+    Status = EFI_MEDIA_CHANGED;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (BufferSize == 0) {\r
+    Status = EFI_SUCCESS;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto ON_EXIT;\r
+  }\r
+\r
   //\r
   // BufferSize must be a multiple of the intrinsic block size of the device.\r
   //\r
@@ -158,16 +171,6 @@ UsbMassReadBlocks (
     goto ON_EXIT;\r
   }\r
 \r
-  if (!(Media->MediaPresent)) {\r
-    Status = EFI_NO_MEDIA;\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  if (MediaId != Media->MediaId) {\r
-    Status = EFI_MEDIA_CHANGED;\r
-    goto ON_EXIT;\r
-  }\r
-\r
   Status = UsbBootReadBlocks (UsbMass, (UINT32) Lba, TotalBlock, Buffer);\r
   if (EFI_ERROR (Status)) {\r
     DEBUG ((EFI_D_ERROR, "UsbMassReadBlocks: UsbBootReadBlocks (%r) -> Reset\n", Status));\r
@@ -221,13 +224,6 @@ UsbMassWriteBlocks (
   EFI_TPL             OldTpl;\r
   UINTN               TotalBlock;\r
 \r
-  //\r
-  // First, validate the parameters\r
-  //\r
-  if ((Buffer == NULL) || (BufferSize == 0)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
   //\r
   // Raise TPL to TPL_NOTIFY to serialize all its operations\r
   // to protect shared data structures.\r
@@ -248,6 +244,26 @@ UsbMassWriteBlocks (
     }\r
   }\r
 \r
+  if (!(Media->MediaPresent)) {\r
+    Status = EFI_NO_MEDIA;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (MediaId != Media->MediaId) {\r
+    Status = EFI_MEDIA_CHANGED;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (BufferSize == 0) {\r
+    Status = EFI_SUCCESS;\r
+    goto ON_EXIT;\r
+  }\r
+\r
+  if (Buffer == NULL) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto ON_EXIT;\r
+  }\r
+\r
   //\r
   // BufferSize must be a multiple of the intrinsic block size of the device.\r
   //\r
@@ -266,16 +282,6 @@ UsbMassWriteBlocks (
     goto ON_EXIT;\r
   }\r
 \r
-  if (!(Media->MediaPresent)) {\r
-    Status = EFI_NO_MEDIA;\r
-    goto ON_EXIT;\r
-  }\r
-\r
-  if (MediaId != Media->MediaId) {\r
-    Status = EFI_MEDIA_CHANGED;\r
-    goto ON_EXIT;\r
-  }\r
-\r
   //\r
   // Try to write the data even the device is marked as ReadOnly,\r
   // and clear the status should the write succeed.\r
index 0a5d3d28f0cc7a580574661a7bbf83c625c064dc..3596a3bfc1c6cdf59109a0f3a17ed179dc68db85 100644 (file)
@@ -465,6 +465,37 @@ PartitionReset (
                                   );\r
 }\r
 \r
+/**\r
+  Probe the media status and return EFI_NO_MEDIA or EFI_MEDIA_CHANGED\r
+  for no media or media change case. Otherwise DefaultStatus is returned.\r
+\r
+  @param DiskIo             Pointer to the DiskIo instance.\r
+  @param MediaId            Id of the media, changes every time the media is replaced.\r
+  @param DefaultStatus      The default status to return when it's not the no media\r
+                            or media change case.\r
+\r
+  @retval EFI_NO_MEDIA      There is no media.\r
+  @retval EFI_MEDIA_CHANGED The media was changed.\r
+  @retval others            The default status to return.\r
+**/\r
+EFI_STATUS\r
+ProbeMediaStatus (\r
+  IN EFI_DISK_IO_PROTOCOL    *DiskIo,\r
+  IN UINT32                  MediaId,\r
+  IN EFI_STATUS              DefaultStatus\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+\r
+  //\r
+  // Read 1 byte from offset 0 but passing NULL as buffer pointer\r
+  //\r
+  Status = DiskIo->ReadDisk (DiskIo, MediaId, 0, 1, NULL);\r
+  if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {\r
+    return Status;\r
+  }\r
+  return DefaultStatus;\r
+}\r
 \r
 /**\r
   Read by using the Disk IO protocol on the parent device. Lba addresses\r
@@ -501,12 +532,12 @@ PartitionReadBlocks (
   Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r
 \r
   if (BufferSize % Private->BlockSize != 0) {\r
-    return EFI_BAD_BUFFER_SIZE;\r
+    return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_BAD_BUFFER_SIZE);\r
   }\r
 \r
   Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r
   if (Offset + BufferSize > Private->End) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
   //\r
   // Because some kinds of partition have different block size from their parent\r
@@ -552,12 +583,12 @@ PartitionWriteBlocks (
   Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r
 \r
   if (BufferSize % Private->BlockSize != 0) {\r
-    return EFI_BAD_BUFFER_SIZE;\r
+    return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_BAD_BUFFER_SIZE);\r
   }\r
 \r
   Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r
   if (Offset + BufferSize > Private->End) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
   //\r
   // Because some kinds of partition have different block size from their parent\r