diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
index 3d7cf2dc6c..2af38429dd 100644
|
a
|
b
|
|
| 1 | 1 | /** @file |
| 2 | 2 | Decode an El Torito formatted CD-ROM |
| 3 | 3 | |
| 4 | | Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> |
| | 4 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR> |
| 5 | 5 | This program and the accompanying materials |
| 6 | 6 | are licensed and made available under the terms and conditions of the BSD License |
| 7 | 7 | which accompanies this distribution. The full text of the license may be found at |
| … |
… |
PartitionInstallElToritoChildHandles (
|
| 45 | 45 | ) |
| 46 | 46 | { |
| 47 | 47 | EFI_STATUS Status; |
| 48 | | UINT32 VolDescriptorLba; |
| 49 | | UINT32 Lba; |
| | 48 | UINT64 VolDescriptorOffset; |
| | 49 | UINT32 Lba2KB; |
| 50 | 50 | EFI_BLOCK_IO_MEDIA *Media; |
| 51 | 51 | CDROM_VOLUME_DESCRIPTOR *VolDescriptor; |
| 52 | 52 | ELTORITO_CATALOG *Catalog; |
| … |
… |
PartitionInstallElToritoChildHandles (
|
| 67 | 67 | VolSpaceSize = 0; |
| 68 | 68 | |
| 69 | 69 | // |
| 70 | | // CD_ROM has the fixed block size as 2048 bytes |
| | 70 | // CD_ROM has the fixed block size as 2048 bytes (SIZE_2KB) |
| 71 | 71 | // |
| 72 | | if (Media->BlockSize != 2048) { |
| | 72 | |
| | 73 | // If the ISO image has been copied onto a different storage media |
| | 74 | // then the block size might be different (eg: USB). |
| | 75 | // Ensure 2048 (SIZE_2KB) is a multiple of block size |
| | 76 | if (((SIZE_2KB % Media->BlockSize) != 0) || (Media->BlockSize > SIZE_2KB)) { |
| 73 | 77 | return EFI_NOT_FOUND; |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | | VolDescriptor = AllocatePool ((UINTN) Media->BlockSize); |
| | 80 | VolDescriptor = AllocatePool ((UINTN)SIZE_2KB); |
| 77 | 81 | |
| 78 | 82 | if (VolDescriptor == NULL) { |
| 79 | 83 | return EFI_NOT_FOUND; |
| … |
… |
PartitionInstallElToritoChildHandles (
|
| 81 | 85 | |
| 82 | 86 | Catalog = (ELTORITO_CATALOG *) VolDescriptor; |
| 83 | 87 | |
| 84 | | // |
| 85 | | // the ISO-9660 volume descriptor starts at 32k on the media |
| 86 | | // and CD_ROM has the fixed block size as 2048 bytes, so... |
| 87 | | // |
| 88 | | // |
| 89 | | // ((16*2048) / Media->BlockSize) - 1; |
| 90 | | // |
| 91 | | VolDescriptorLba = 15; |
| 92 | 88 | // |
| 93 | 89 | // Loop: handle one volume descriptor per time |
| | 90 | // The ISO-9660 volume descriptor starts at 32k on the media |
| 94 | 91 | // |
| 95 | | while (TRUE) { |
| 96 | | |
| 97 | | VolDescriptorLba += 1; |
| 98 | | if (VolDescriptorLba > Media->LastBlock) { |
| 99 | | // |
| 100 | | // We are pointing past the end of the device so exit |
| 101 | | // |
| 102 | | break; |
| 103 | | } |
| 104 | | |
| | 92 | for (VolDescriptorOffset = SIZE_32KB; |
| | 93 | VolDescriptorOffset <= MultU64x32 (Media->LastBlock, Media->BlockSize); |
| | 94 | VolDescriptorOffset += SIZE_2KB) { |
| 105 | 95 | Status = DiskIo->ReadDisk ( |
| 106 | 96 | DiskIo, |
| 107 | 97 | Media->MediaId, |
| 108 | | MultU64x32 (VolDescriptorLba, Media->BlockSize), |
| 109 | | Media->BlockSize, |
| | 98 | VolDescriptorOffset, |
| | 99 | SIZE_2KB, |
| 110 | 100 | VolDescriptor |
| 111 | 101 | ); |
| 112 | 102 | if (EFI_ERROR (Status)) { |
| … |
… |
PartitionInstallElToritoChildHandles (
|
| 139 | 129 | } |
| 140 | 130 | // |
| 141 | 131 | // Read in the boot El Torito boot catalog |
| | 132 | // The LBA unit used by El Torito boot catalog is 2KB unit |
| 142 | 133 | // |
| 143 | | Lba = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog); |
| 144 | | if (Lba > Media->LastBlock) { |
| | 134 | Lba2KB = UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog); |
| | 135 | // Ensure the LBA (in 2KB unit) fits into our media |
| | 136 | if (Lba2KB * (SIZE_2KB / Media->BlockSize) > Media->LastBlock) { |
| 145 | 137 | continue; |
| 146 | 138 | } |
| 147 | 139 | |
| 148 | 140 | Status = DiskIo->ReadDisk ( |
| 149 | 141 | DiskIo, |
| 150 | 142 | Media->MediaId, |
| 151 | | MultU64x32 (Lba, Media->BlockSize), |
| 152 | | Media->BlockSize, |
| | 143 | MultU64x32 (Lba2KB, SIZE_2KB), |
| | 144 | SIZE_2KB, |
| 153 | 145 | Catalog |
| 154 | 146 | ); |
| 155 | 147 | if (EFI_ERROR (Status)) { |
| … |
… |
PartitionInstallElToritoChildHandles (
|
| 236 | 228 | |
| 237 | 229 | CdDev.BootEntry = (UINT32) BootEntry; |
| 238 | 230 | BootEntry++; |
| 239 | | CdDev.PartitionStart = Catalog->Boot.Lba; |
| | 231 | CdDev.PartitionStart = Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize); |
| 240 | 232 | if (SectorCount < 2) { |
| 241 | 233 | // |
| 242 | 234 | // When the SectorCount < 2, set the Partition as the whole CD. |
| 243 | 235 | // |
| 244 | | if (VolSpaceSize > (Media->LastBlock + 1)) { |
| 245 | | CdDev.PartitionSize = (UINT32)(Media->LastBlock - Catalog->Boot.Lba + 1); |
| | 236 | if (VolSpaceSize * (SIZE_2KB / Media->BlockSize) > (Media->LastBlock + 1)) { |
| | 237 | CdDev.PartitionSize = (UINT32)(Media->LastBlock - Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize) + 1); |
| 246 | 238 | } else { |
| 247 | | CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba); |
| | 239 | CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba) * (SIZE_2KB / Media->BlockSize); |
| 248 | 240 | } |
| 249 | 241 | } else { |
| 250 | 242 | CdDev.PartitionSize = DivU64x32 ( |
| 251 | 243 | MultU64x32 ( |
| 252 | | SectorCount, |
| | 244 | SectorCount * (SIZE_2KB / Media->BlockSize), |
| 253 | 245 | SubBlockSize |
| 254 | 246 | ) + Media->BlockSize - 1, |
| 255 | 247 | Media->BlockSize |
| … |
… |
PartitionInstallElToritoChildHandles (
|
| 265 | 257 | BlockIo2, |
| 266 | 258 | DevicePath, |
| 267 | 259 | (EFI_DEVICE_PATH_PROTOCOL *) &CdDev, |
| 268 | | Catalog->Boot.Lba, |
| 269 | | Catalog->Boot.Lba + CdDev.PartitionSize - 1, |
| | 260 | Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize), |
| | 261 | Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize) + CdDev.PartitionSize - 1, |
| 270 | 262 | SubBlockSize, |
| 271 | 263 | FALSE |
| 272 | 264 | ); |