VirtualBox

Ticket #18039: eltorito2014vs2017.diff

File eltorito2014vs2017.diff, 5.8 KB (added by nickel, 6 years ago)

EFI Partition driver partial diff

  • MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c

    diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
    index 3d7cf2dc6c..2af38429dd 100644
    a b  
    11/** @file
    22  Decode an El Torito formatted CD-ROM
    33
    4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
     4Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
    55This program and the accompanying materials
    66are licensed and made available under the terms and conditions of the BSD License
    77which accompanies this distribution.  The full text of the license may be found at
    PartitionInstallElToritoChildHandles (  
    4545  )
    4646{
    4747  EFI_STATUS              Status;
    48   UINT32                  VolDescriptorLba;
    49   UINT32                  Lba;
     48  UINT64                  VolDescriptorOffset;
     49  UINT32                  Lba2KB;
    5050  EFI_BLOCK_IO_MEDIA      *Media;
    5151  CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
    5252  ELTORITO_CATALOG        *Catalog;
    PartitionInstallElToritoChildHandles (  
    6767  VolSpaceSize  = 0;
    6868
    6969  //
    70   // CD_ROM has the fixed block size as 2048 bytes
     70  // CD_ROM has the fixed block size as 2048 bytes (SIZE_2KB)
    7171  //
    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)) {
    7377    return EFI_NOT_FOUND;
    7478  }
    7579
    76   VolDescriptor = AllocatePool ((UINTN) Media->BlockSize);
     80  VolDescriptor = AllocatePool ((UINTN)SIZE_2KB);
    7781
    7882  if (VolDescriptor == NULL) {
    7983    return EFI_NOT_FOUND;
    PartitionInstallElToritoChildHandles (  
    8185
    8286  Catalog = (ELTORITO_CATALOG *) VolDescriptor;
    8387
    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;
    9288  //
    9389  // Loop: handle one volume descriptor per time
     90  //       The ISO-9660 volume descriptor starts at 32k on the media
    9491  //
    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) {
    10595    Status = DiskIo->ReadDisk (
    10696                       DiskIo,
    10797                       Media->MediaId,
    108                        MultU64x32 (VolDescriptorLba, Media->BlockSize),
    109                        Media->BlockSize,
     98                       VolDescriptorOffset,
     99                       SIZE_2KB,
    110100                       VolDescriptor
    111101                       );
    112102    if (EFI_ERROR (Status)) {
    PartitionInstallElToritoChildHandles (  
    139129    }
    140130    //
    141131    // Read in the boot El Torito boot catalog
     132    // The LBA unit used by El Torito boot catalog is 2KB unit
    142133    //
    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) {
    145137      continue;
    146138    }
    147139
    148140    Status = DiskIo->ReadDisk (
    149141                       DiskIo,
    150142                       Media->MediaId,
    151                        MultU64x32 (Lba, Media->BlockSize),
    152                        Media->BlockSize,
     143                       MultU64x32 (Lba2KB, SIZE_2KB),
     144                       SIZE_2KB,
    153145                       Catalog
    154146                       );
    155147    if (EFI_ERROR (Status)) {
    PartitionInstallElToritoChildHandles (  
    236228
    237229      CdDev.BootEntry = (UINT32) BootEntry;
    238230      BootEntry++;
    239       CdDev.PartitionStart = Catalog->Boot.Lba;
     231      CdDev.PartitionStart = Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize);
    240232      if (SectorCount < 2) {
    241233        //
    242234        // When the SectorCount < 2, set the Partition as the whole CD.
    243235        //
    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);
    246238        } else {
    247           CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba);
     239          CdDev.PartitionSize = (UINT32)(VolSpaceSize - Catalog->Boot.Lba) * (SIZE_2KB / Media->BlockSize);
    248240        }
    249241      } else {
    250242        CdDev.PartitionSize = DivU64x32 (
    251243                                MultU64x32 (
    252                                   SectorCount,
     244                                  SectorCount * (SIZE_2KB / Media->BlockSize),
    253245                                  SubBlockSize
    254246                                  ) + Media->BlockSize - 1,
    255247                                Media->BlockSize
    PartitionInstallElToritoChildHandles (  
    265257                BlockIo2,
    266258                DevicePath,
    267259                (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,
    270262                SubBlockSize,
    271263                FALSE
    272264                );

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy