]> git.proxmox.com Git - mirror_edk2.git/commitdiff
The patch enhances the Partition driver to return the media status (EFI_NO_MEDIA...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 19 Sep 2011 06:24:50 +0000 (06:24 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 19 Sep 2011 06:24:50 +0000 (06:24 +0000)
Signed-off-by: niruiyu
Reviewed-by: erictian
Reviewed-by: qianouyang
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12378 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c

index ed564e5cf3bfcd432dbd49958bff1d005ca9d619..4ebff473e4fe1db053bdc4cd8cd84c6f79a93754 100644 (file)
@@ -712,6 +712,45 @@ PartitionFlushBlocks (
   return Private->ParentBlockIo->FlushBlocks (Private->ParentBlockIo);\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 BlockIo2           Pointer to the BlockIo2 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
+ProbeMediaStatusEx (\r
+  IN EFI_BLOCK_IO2_PROTOCOL  *BlockIo2,\r
+  IN UINT32                  MediaId,\r
+  IN EFI_STATUS              DefaultStatus\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+\r
+  //\r
+  // Read from LBA 0 but passing NULL as buffer pointer to detect the media status.\r
+  //\r
+  Status = BlockIo2->ReadBlocksEx (\r
+                       BlockIo2,\r
+                       MediaId,\r
+                       0,\r
+                       NULL,\r
+                       0,\r
+                       NULL\r
+                       );\r
+  if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {\r
+    return Status;\r
+  }\r
+  return DefaultStatus;\r
+}\r
+\r
 /**\r
   Reset the Block Device throught Block I/O2 protocol.\r
 \r
@@ -788,18 +827,19 @@ PartitionReadBlocksEx (
   UINT64                  Offset;\r
   UINT32                  UnderRun;\r
 \r
+  Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
+\r
   if (Token == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
 \r
-  Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
   if (BufferSize % Private->BlockSize != 0) {\r
-    return EFI_BAD_BUFFER_SIZE;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, 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 ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
 \r
   //\r
@@ -809,7 +849,7 @@ PartitionReadBlocksEx (
   //\r
   Lba = DivU64x32Remainder (Offset, Private->BlockSize, &UnderRun);\r
   if (UnderRun != 0) {\r
-    return EFI_UNSUPPORTED;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
   }\r
 \r
   //\r
@@ -817,7 +857,7 @@ PartitionReadBlocksEx (
   // device, in that case the Block I/O2 couldn't be called.\r
   //\r
   if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r
-    return EFI_UNSUPPORTED;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
   }\r
 \r
   return Private->ParentBlockIo2->ReadBlocksEx (Private->ParentBlockIo2, MediaId, Lba, Token, BufferSize, Buffer);\r
@@ -869,18 +909,19 @@ PartitionWriteBlocksEx (
   UINT64                  Offset;\r
   UINT32                  UnderRun;\r
 \r
+  Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
+\r
   if (Token == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
 \r
-  Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r
   if (BufferSize % Private->BlockSize != 0) {\r
-    return EFI_BAD_BUFFER_SIZE;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, 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 ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
 \r
   //\r
@@ -890,7 +931,7 @@ PartitionWriteBlocksEx (
   //\r
   Lba = DivU64x32Remainder (Offset, Private->BlockSize, &UnderRun);\r
   if (UnderRun != 0) {\r
-    return EFI_UNSUPPORTED;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
   }\r
 \r
   //\r
@@ -898,7 +939,7 @@ PartitionWriteBlocksEx (
   // in that case it couldn't call parent Block I/O2. \r
   //\r
   if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r
-    return EFI_UNSUPPORTED;\r
+    return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r
   }\r
 \r
   return Private->ParentBlockIo2->WriteBlocksEx (Private->ParentBlockIo2, MediaId, Lba, Token, BufferSize, Buffer);\r