]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.c
index f6030e0897947c96ae98b0d35046b61d001cb893..d1c878ad2e7ab3e35b2cbabf76fa5e52ae6f8395 100644 (file)
@@ -4,14 +4,9 @@
   of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy\r
   MBR, and GPT partition schemes are supported.\r
 \r
-Copyright (c) 2006 - 2017, 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
+Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -26,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
@@ -39,11 +34,10 @@ 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
-  PartitionInstallElToritoChildHandles,\r
   PartitionInstallMbrChildHandles,\r
   PartitionInstallUdfChildHandles,\r
   NULL\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
@@ -306,9 +300,9 @@ PartitionDriverBindingStart (
   if (BlockIo->Media->MediaPresent ||\r
       (BlockIo->Media->RemovableMedia && !BlockIo->Media->LogicalPartition)) {\r
     //\r
-    // Try for GPT, then El Torito, then UDF, and then legacy MBR partition\r
-    // types. If the media supports a given partition type install child handles\r
-    // to represent the partitions described by the media.\r
+    // Try for GPT, then legacy MBR partition types, and then UDF and El Torito.\r
+    // If the media supports a given partition type install child handles to\r
+    // represent the partitions described by the media.\r
     //\r
     Routine = &mPartitionDetectRoutineTable[0];\r
     while (*Routine != NULL) {\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
@@ -402,6 +396,7 @@ PartitionDriverBindingStop (
   BOOLEAN                 AllChildrenStopped;\r
   PARTITION_PRIVATE_DATA  *Private;\r
   EFI_DISK_IO_PROTOCOL    *DiskIo;\r
+  EFI_GUID                *TypeGuid;\r
 \r
   BlockIo  = NULL;\r
   BlockIo2 = NULL;\r
@@ -429,7 +424,7 @@ PartitionDriverBindingStop (
           );\r
     //\r
     // Close Parent BlockIO2 if has.\r
-    //    \r
+    //\r
     gBS->CloseProtocol (\r
            ControllerHandle,\r
            &gEfiDiskIo2ProtocolGuid,\r
@@ -466,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
@@ -494,6 +489,13 @@ PartitionDriverBindingStop (
            This->DriverBindingHandle,\r
            ChildHandleBuffer[Index]\r
            );\r
+\r
+    if (IsZeroGuid (&Private->TypeGuid)) {\r
+      TypeGuid = NULL;\r
+    } else {\r
+      TypeGuid = &Private->TypeGuid;\r
+    }\r
+\r
     //\r
     // All Software protocols have be freed from the handle so remove it.\r
     // Remove the BlockIo Protocol if has.\r
@@ -517,7 +519,7 @@ PartitionDriverBindingStop (
                          &Private->BlockIo2,\r
                          &gEfiPartitionInfoProtocolGuid,\r
                          &Private->PartitionInfo,\r
-                         Private->EspGuid,\r
+                         TypeGuid,\r
                          NULL,\r
                          NULL\r
                          );\r
@@ -531,7 +533,7 @@ PartitionDriverBindingStop (
                        &Private->BlockIo,\r
                        &gEfiPartitionInfoProtocolGuid,\r
                        &Private->PartitionInfo,\r
-                       Private->EspGuid,\r
+                       TypeGuid,\r
                        NULL,\r
                        NULL\r
                        );\r
@@ -778,11 +780,15 @@ ProbeMediaStatusEx (
   )\r
 {\r
   EFI_STATUS                 Status;\r
+  UINT8                      Buffer[1];\r
 \r
   //\r
-  // Read 1 byte from offset 0 but passing NULL as buffer pointer\r
+  // Read 1 byte from offset 0 to check if the MediaId is still valid.\r
+  // The reading operation is synchronious thus it is not worth it to\r
+  // allocate a buffer from the pool. The destination buffer for the\r
+  // data is in the stack.\r
   //\r
-  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, NULL);\r
+  Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, (VOID*)Buffer);\r
   if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {\r
     return Status;\r
   }\r
@@ -881,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
@@ -889,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
@@ -907,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
@@ -982,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
@@ -1014,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
@@ -1034,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
@@ -1101,6 +1107,7 @@ PartitionFlushBlocksEx (
   @param[in]  Start             Start Block.\r
   @param[in]  End               End Block.\r
   @param[in]  BlockSize         Child block size.\r
+  @param[in]  TypeGuid          Partition GUID Type.\r
 \r
   @retval EFI_SUCCESS       A child handle was added.\r
   @retval other             A child handle was not added.\r
@@ -1119,7 +1126,8 @@ PartitionInstallChildHandle (
   IN  EFI_PARTITION_INFO_PROTOCOL  *PartitionInfo,\r
   IN  EFI_LBA                      Start,\r
   IN  EFI_LBA                      End,\r
-  IN  UINT32                       BlockSize\r
+  IN  UINT32                       BlockSize,\r
+  IN  EFI_GUID                     *TypeGuid\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -1146,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
@@ -1166,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
@@ -1213,17 +1221,14 @@ PartitionInstallChildHandle (
   //\r
   CopyMem (&Private->PartitionInfo, PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));\r
 \r
-  if ((PartitionInfo->System == 1)) {\r
-    Private->EspGuid = &gEfiPartTypeSystemPartGuid;\r
+  if (TypeGuid != NULL) {\r
+    CopyGuid(&(Private->TypeGuid), TypeGuid);\r
   } else {\r
-    //\r
-    // If NULL InstallMultipleProtocolInterfaces will ignore it.\r
-    //\r
-    Private->EspGuid = NULL;\r
+    ZeroMem ((VOID *)&(Private->TypeGuid), sizeof (EFI_GUID));\r
   }\r
 \r
   //\r
-  // Create the new handle. \r
+  // Create the new handle.\r
   //\r
   Private->Handle = NULL;\r
   if (Private->DiskIo2 != NULL) {\r
@@ -1237,11 +1242,11 @@ PartitionInstallChildHandle (
                     &Private->BlockIo2,\r
                     &gEfiPartitionInfoProtocolGuid,\r
                     &Private->PartitionInfo,\r
-                    Private->EspGuid,\r
+                    TypeGuid,\r
                     NULL,\r
                     NULL\r
                     );\r
-  } else {    \r
+  } else {\r
     Status = gBS->InstallMultipleProtocolInterfaces (\r
                     &Private->Handle,\r
                     &gEfiDevicePathProtocolGuid,\r
@@ -1250,7 +1255,7 @@ PartitionInstallChildHandle (
                     &Private->BlockIo,\r
                     &gEfiPartitionInfoProtocolGuid,\r
                     &Private->PartitionInfo,\r
-                    Private->EspGuid,\r
+                    TypeGuid,\r
                     NULL,\r
                     NULL\r
                     );\r
@@ -1280,9 +1285,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