]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
MdeModulePkg/PartitionDxe: Add already start check for child hanldes
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.c
index 71acdcc8985140e4883288a42925a7662b4f1fd5..6a43c3cafb23c15130beefd85c41915b20943eab 100644 (file)
@@ -6,13 +6,7 @@
 \r
 Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.\r
 Copyright (c) 2006 - 2018, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -27,8 +21,8 @@ EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
   PartitionDriverBindingStart,\r
   PartitionDriverBindingStop,\r
   //\r
-  // Grub4Dos copies the BPB of the first partition to the MBR. If the \r
-  // DriverBindingStart() of the Fat driver gets run before that of Partition \r
+  // Grub4Dos copies the BPB of the first partition to the MBR. If the\r
+  // DriverBindingStart() of the Fat driver gets run before that of Partition\r
   // driver only the first partition can be recognized.\r
   // Let the driver binding version of Partition driver be higher than that of\r
   // Fat driver to make sure the DriverBindingStart() of the Partition driver\r
@@ -40,7 +34,7 @@ EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
 };\r
 \r
 //\r
-// Prioritized function list to detect partition table. \r
+// Prioritized function list to detect partition table.\r
 //\r
 PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {\r
   PartitionInstallGptChildHandles,\r
@@ -82,7 +76,7 @@ PartitionDriverBindingSupported (
   //\r
   if (RemainingDevicePath != NULL) {\r
     //\r
-    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // Check if RemainingDevicePath is the End of Device Path Node,\r
     // if yes, go on checking other conditions\r
     //\r
     if (!IsDevicePathEnd (RemainingDevicePath)) {\r
@@ -205,13 +199,13 @@ PartitionDriverBindingStart (
   EFI_TPL                   OldTpl;\r
 \r
   BlockIo2 = NULL;\r
-  OldTpl = gBS->RaiseTPL (TPL_CALLBACK); \r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
   //\r
   // Check RemainingDevicePath validation\r
   //\r
   if (RemainingDevicePath != NULL) {\r
     //\r
-    // Check if RemainingDevicePath is the End of Device Path Node, \r
+    // Check if RemainingDevicePath is the End of Device Path Node,\r
     // if yes, return EFI_SUCCESS\r
     //\r
     if (IsDevicePathEnd (RemainingDevicePath)) {\r
@@ -333,12 +327,12 @@ PartitionDriverBindingStart (
   // driver. So don't try to close them. Otherwise, we will break the dependency\r
   // between the controller and the driver set up before.\r
   //\r
-  // In the case that when the media changes on a device it will Reinstall the \r
+  // In the case that when the media changes on a device it will Reinstall the\r
   // BlockIo interaface. This will cause a call to our Stop(), and a subsequent\r
   // reentrant call to our Start() successfully. We should leave the device open\r
   // when this happen. The "media change" case includes either the status is\r
-  // EFI_MEDIA_CHANGED or it is a "media" to "no media" change. \r
-  //  \r
+  // EFI_MEDIA_CHANGED or it is a "media" to "no media" change.\r
+  //\r
   if (EFI_ERROR (Status)          &&\r
       !EFI_ERROR (OpenStatus)     &&\r
       Status != EFI_MEDIA_CHANGED &&\r
@@ -351,7 +345,7 @@ PartitionDriverBindingStart (
           );\r
     //\r
     // Close Parent DiskIo2 if has.\r
-    //    \r
+    //\r
     gBS->CloseProtocol (\r
            ControllerHandle,\r
            &gEfiDiskIo2ProtocolGuid,\r
@@ -430,7 +424,7 @@ PartitionDriverBindingStop (
           );\r
     //\r
     // Close Parent BlockIO2 if has.\r
-    //    \r
+    //\r
     gBS->CloseProtocol (\r
            ControllerHandle,\r
            &gEfiDiskIo2ProtocolGuid,\r
@@ -467,7 +461,7 @@ PartitionDriverBindingStop (
            This->DriverBindingHandle,\r
            ControllerHandle,\r
            EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-           ); \r
+           );\r
 \r
 \r
     Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);\r
@@ -893,7 +887,7 @@ PartitionCreateAccessTask (
 \r
 /**\r
   Read BufferSize bytes from Lba into Buffer.\r
-  \r
+\r
   This function reads the requested number of blocks from the device. All the\r
   blocks are read, or an error is returned.\r
   If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and\r
@@ -901,13 +895,13 @@ PartitionCreateAccessTask (
   not be signaled.\r
 \r
   @param[in]       This       Indicates a pointer to the calling context.\r
-  @param[in]       MediaId    Id of the media, changes every time the media is \r
+  @param[in]       MediaId    Id of the media, changes every time the media is\r
                               replaced.\r
   @param[in]       Lba        The starting Logical Block Address to read from.\r
-  @param[in, out]  Token           A pointer to the token associated with the transaction.\r
-  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.  \r
-  @param[out]      Buffer     A pointer to the destination buffer for the data. The \r
-                              caller is responsible for either having implicit or \r
+  @param[in, out]  Token      A pointer to the token associated with the transaction.\r
+  @param[in]       BufferSize Size of Buffer, must be a multiple of device block size.\r
+  @param[out]      Buffer     A pointer to the destination buffer for the data. The\r
+                              caller is responsible for either having implicit or\r
                               explicit ownership of the buffer.\r
 \r
   @retval EFI_SUCCESS           The read request was queued if Token->Event is\r
@@ -919,7 +913,7 @@ PartitionCreateAccessTask (
   @retval EFI_MEDIA_CHANGED     The MediaId is not for the current media.\r
   @retval EFI_BAD_BUFFER_SIZE   The BufferSize parameter is not a multiple of the\r
                                 intrinsic block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
                                 of resources.\r
@@ -994,7 +988,7 @@ PartitionReadBlocksEx (
   @retval EFI_MEDIA_CHNAGED     The MediaId does not matched the current device.\r
   @retval EFI_DEVICE_ERROR      The device reported an error while performing the write.\r
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block size of the device.\r
-  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
+  @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
                                 or the buffer is not on proper alignment.\r
   @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack\r
                                 of resources.\r
@@ -1026,7 +1020,7 @@ PartitionWriteBlocksEx (
   if (Offset + BufferSize > Private->End) {\r
     return ProbeMediaStatusEx (Private->DiskIo2, MediaId, EFI_INVALID_PARAMETER);\r
   }\r
-  \r
+\r
   if ((Token != NULL) && (Token->Event != NULL)) {\r
     Task = PartitionCreateAccessTask (Token);\r
     if (Task == NULL) {\r
@@ -1046,10 +1040,10 @@ PartitionWriteBlocksEx (
 \r
 /**\r
   Flush the Block Device.\r
\r
+\r
   If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED\r
   is returned and non-blocking I/O is being used, the Event associated with\r
-  this request will not be signaled.  \r
+  this request will not be signaled.\r
 \r
   @param[in]      This     Indicates a pointer to the calling context.\r
   @param[in, out] Token    A pointer to the token associated with the transaction\r
@@ -1160,7 +1154,7 @@ PartitionInstallChildHandle (
   // Set the BlockIO into Private Data.\r
   //\r
   Private->BlockIo.Revision = ParentBlockIo->Revision;\r
-  \r
+\r
   Private->BlockIo.Media    = &Private->Media;\r
   CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r
 \r
@@ -1180,7 +1174,7 @@ PartitionInstallChildHandle (
     Private->BlockIo2.Reset          = PartitionResetEx;\r
     Private->BlockIo2.ReadBlocksEx   = PartitionReadBlocksEx;\r
     Private->BlockIo2.WriteBlocksEx  = PartitionWriteBlocksEx;\r
-    Private->BlockIo2.FlushBlocksEx  = PartitionFlushBlocksEx; \r
+    Private->BlockIo2.FlushBlocksEx  = PartitionFlushBlocksEx;\r
   }\r
 \r
   Private->Media.IoAlign   = 0;\r
@@ -1234,7 +1228,7 @@ PartitionInstallChildHandle (
   }\r
 \r
   //\r
-  // Create the new handle. \r
+  // Create the new handle.\r
   //\r
   Private->Handle = NULL;\r
   if (Private->DiskIo2 != NULL) {\r
@@ -1252,7 +1246,7 @@ PartitionInstallChildHandle (
                     NULL,\r
                     NULL\r
                     );\r
-  } else {    \r
+  } else {\r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                     &Private->Handle,\r
                     &gEfiDevicePathProtocolGuid,\r
@@ -1282,6 +1276,15 @@ PartitionInstallChildHandle (
   } else {\r
     FreePool (Private->DevicePath);\r
     FreePool (Private);\r
+\r
+    //\r
+    // if the Status == EFI_ALREADY_STARTED, it means the child handles\r
+    // are already installed. So return EFI_SUCCESS to avoid do the next\r
+    // partition type check.\r
+    //\r
+    if (Status == EFI_ALREADY_STARTED) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -1291,9 +1294,9 @@ PartitionInstallChildHandle (
 /**\r
   The user Entry Point for module Partition. The user code starts with this function.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.\r
   @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS       The entry point is executed successfully.\r
   @retval other             Some error occurs when executing this entry point.\r
 \r