]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
MdeModulePkg/PartitionDxe: Add partition type guid to installed handle
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / ElTorito.c
index 3d7cf2dc6cdd8e2fa2c29e4cc21dba80cad2492a..a7b5434a08e7cf844b05e8d197f5d9e795c2fc39 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Decode an El Torito formatted CD-ROM\r
 \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.\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
@@ -44,22 +45,23 @@ PartitionInstallElToritoChildHandles (
   IN  EFI_DEVICE_PATH_PROTOCOL     *DevicePath\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
-  UINT32                  VolDescriptorLba;\r
-  UINT32                  Lba;\r
-  EFI_BLOCK_IO_MEDIA      *Media;\r
-  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;\r
-  ELTORITO_CATALOG        *Catalog;\r
-  UINTN                   Check;\r
-  UINTN                   Index;\r
-  UINTN                   BootEntry;\r
-  UINTN                   MaxIndex;\r
-  UINT16                  *CheckBuffer;\r
-  CDROM_DEVICE_PATH       CdDev;\r
-  UINT32                  SubBlockSize;\r
-  UINT32                  SectorCount;\r
-  EFI_STATUS              Found;\r
-  UINT32                  VolSpaceSize;\r
+  EFI_STATUS                   Status;\r
+  UINT64                       VolDescriptorOffset;\r
+  UINT32                       Lba2KB;\r
+  EFI_BLOCK_IO_MEDIA           *Media;\r
+  CDROM_VOLUME_DESCRIPTOR      *VolDescriptor;\r
+  ELTORITO_CATALOG             *Catalog;\r
+  UINTN                        Check;\r
+  UINTN                        Index;\r
+  UINTN                        BootEntry;\r
+  UINTN                        MaxIndex;\r
+  UINT16                       *CheckBuffer;\r
+  CDROM_DEVICE_PATH            CdDev;\r
+  UINT32                       SubBlockSize;\r
+  UINT32                       SectorCount;\r
+  EFI_STATUS                   Found;\r
+  UINT32                       VolSpaceSize;\r
+  EFI_PARTITION_INFO_PROTOCOL  PartitionInfo;\r
 \r
   Found         = EFI_NOT_FOUND;\r
   Media         = BlockIo->Media;\r
@@ -67,13 +69,17 @@ PartitionInstallElToritoChildHandles (
   VolSpaceSize  = 0;\r
 \r
   //\r
-  // CD_ROM has the fixed block size as 2048 bytes\r
+  // CD_ROM has the fixed block size as 2048 bytes (SIZE_2KB)\r
   //\r
-  if (Media->BlockSize != 2048) {\r
+\r
+  // If the ISO image has been copied onto a different storage media\r
+  // then the block size might be different (eg: USB).\r
+  // Ensure 2048 (SIZE_2KB) is a multiple of block size\r
+  if (((SIZE_2KB % Media->BlockSize) != 0) || (Media->BlockSize > SIZE_2KB)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
-  VolDescriptor = AllocatePool ((UINTN) Media->BlockSize);\r
+  VolDescriptor = AllocatePool ((UINTN)SIZE_2KB);\r
 \r
   if (VolDescriptor == NULL) {\r
     return EFI_NOT_FOUND;\r
@@ -81,32 +87,18 @@ PartitionInstallElToritoChildHandles (
 \r
   Catalog = (ELTORITO_CATALOG *) VolDescriptor;\r
 \r
-  //\r
-  // the ISO-9660 volume descriptor starts at 32k on the media\r
-  // and CD_ROM has the fixed block size as 2048 bytes, so...\r
-  //\r
-  //\r
-  // ((16*2048) / Media->BlockSize) - 1;\r
-  //\r
-  VolDescriptorLba = 15;\r
   //\r
   // Loop: handle one volume descriptor per time\r
+  //       The ISO-9660 volume descriptor starts at 32k on the media\r
   //\r
-  while (TRUE) {\r
-\r
-    VolDescriptorLba += 1;\r
-    if (VolDescriptorLba > Media->LastBlock) {\r
-      //\r
-      // We are pointing past the end of the device so exit\r
-      //\r
-      break;\r
-    }\r
-\r
+  for (VolDescriptorOffset = SIZE_32KB;\r
+       VolDescriptorOffset <= MultU64x32 (Media->LastBlock, Media->BlockSize);\r
+       VolDescriptorOffset += SIZE_2KB) {\r
     Status = DiskIo->ReadDisk (\r
                        DiskIo,\r
                        Media->MediaId,\r
-                       MultU64x32 (VolDescriptorLba, Media->BlockSize),\r
-                       Media->BlockSize,\r
+                       VolDescriptorOffset,\r
+                       SIZE_2KB,\r
                        VolDescriptor\r
                        );\r
     if (EFI_ERROR (Status)) {\r
@@ -139,17 +131,19 @@ PartitionInstallElToritoChildHandles (
     }\r
     //\r
     // Read in the boot El Torito boot catalog\r
+    // The LBA unit used by El Torito boot catalog is 2KB unit\r
     //\r
-    Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog);\r
-    if (Lba > Media->LastBlock) {\r
+    Lba2KB = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog);\r
+    // Ensure the LBA (in 2KB unit) fits into our media\r
+    if (Lba2KB * (SIZE_2KB / Media->BlockSize) > Media->LastBlock) {\r
       continue;\r
     }\r
 \r
     Status = DiskIo->ReadDisk (\r
                        DiskIo,\r
                        Media->MediaId,\r
-                       MultU64x32 (Lba, Media->BlockSize),\r
-                       Media->BlockSize,\r
+                       MultU64x32 (Lba2KB, SIZE_2KB),\r
+                       SIZE_2KB,\r
                        Catalog\r
                        );\r
     if (EFI_ERROR (Status)) {\r
@@ -236,26 +230,30 @@ PartitionInstallElToritoChildHandles (
 \r
       CdDev.BootEntry = (UINT32) BootEntry;\r
       BootEntry++;\r
-      CdDev.PartitionStart = Catalog->Boot.Lba;\r
+      CdDev.PartitionStart = Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize);\r
       if (SectorCount < 2) {\r
         //\r
         // When the SectorCount < 2, set the Partition as the whole CD.\r
         //\r
-        if (VolSpaceSize > (Media->LastBlock + 1)) {\r
-          CdDev.PartitionSize = (UINT32)(Media->LastBlock - Catalog->Boot.Lba + 1);\r
+        if (VolSpaceSize * (SIZE_2KB / Media->BlockSize) > (Media->LastBlock + 1)) {\r
+          CdDev.PartitionSize = (UINT32)(Media->LastBlock - Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize) + 1);\r
         } else {\r
-          CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba);\r
+          CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba) * (SIZE_2KB / Media->BlockSize);\r
         }\r
       } else {\r
         CdDev.PartitionSize = DivU64x32 (\r
                                 MultU64x32 (\r
-                                  SectorCount,\r
+                                  SectorCount * (SIZE_2KB / Media->BlockSize),\r
                                   SubBlockSize\r
                                   ) + Media->BlockSize - 1,\r
                                 Media->BlockSize\r
                                 );\r
       }\r
 \r
+      ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));\r
+      PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;\r
+      PartitionInfo.Type     = PARTITION_TYPE_OTHER;\r
+\r
       Status = PartitionInstallChildHandle (\r
                 This,\r
                 Handle,\r
@@ -265,10 +263,11 @@ PartitionInstallElToritoChildHandles (
                 BlockIo2,\r
                 DevicePath,\r
                 (EFI_DEVICE_PATH_PROTOCOL *) &CdDev,\r
-                Catalog->Boot.Lba,\r
-                Catalog->Boot.Lba + CdDev.PartitionSize - 1,\r
+                &PartitionInfo,\r
+                Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize),\r
+                Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize) + CdDev.PartitionSize - 1,\r
                 SubBlockSize,\r
-                FALSE\r
+                NULL\r
                 );\r
       if (!EFI_ERROR (Status)) {\r
         Found = EFI_SUCCESS;\r