]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
Change BlockIo drivers to return EFI_NO_MEDIA or EFI_MEDIA_CHANGED even the Buffer...
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.c
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