From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.126; helo=mga18.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6DDDC21959CB2 for ; Thu, 24 Jan 2019 21:08:10 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2019 21:08:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,519,1539673200"; d="scan'208";a="313369815" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga006.fm.intel.com with ESMTP; 24 Jan 2019 21:08:09 -0800 Received: from fmsmsx115.amr.corp.intel.com (10.18.116.19) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 24 Jan 2019 21:08:09 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx115.amr.corp.intel.com (10.18.116.19) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 24 Jan 2019 21:08:09 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.194]) with mapi id 14.03.0415.000; Fri, 25 Jan 2019 13:08:07 +0800 From: "Wu, Hao A" To: "Chen, Chen A" , "edk2-devel@lists.01.org" CC: "Ni, Ray" , "Zhang, Chao B" Thread-Topic: [edk2] [PATCH 1/2] FatPkg: Break down Part.c file. Thread-Index: AQHUrgjGlB1lJxEG6Ei5OBVIjlwCPaW/exsA Date: Fri, 25 Jan 2019 05:08:06 +0000 Message-ID: References: <20190117020242.5960-1-chen.a.chen@intel.com> In-Reply-To: <20190117020242.5960-1-chen.a.chen@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 1/2] FatPkg: Break down Part.c file. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jan 2019 05:08:10 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Chen A Chen > Sent: Thursday, January 17, 2019 10:03 AM > To: edk2-devel@lists.01.org > Cc: Ni, Ray; Zhang, Chao B > Subject: [edk2] [PATCH 1/2] FatPkg: Break down Part.c file. >=20 > BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1470 > Break down partition parsing logic to 2 parts, Eltorito and MBR. >=20 > Cc: Ruiyu Ni > Cc: Zhang Chao B > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Chen A Chen > --- > FatPkg/FatPei/Eltorito.c | 239 +++++++++++++++++++++++++++++ > FatPkg/FatPei/FatPei.inf | 2 + > FatPkg/FatPei/Mbr.c | 182 ++++++++++++++++++++++ > FatPkg/FatPei/Part.c | 385 +----------------------------------------= ------ > 4 files changed, 424 insertions(+), 384 deletions(-) > create mode 100644 FatPkg/FatPei/Eltorito.c > create mode 100644 FatPkg/FatPei/Mbr.c >=20 > diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c > new file mode 100644 > index 0000000000..ffaef51860 > --- /dev/null > +++ b/FatPkg/FatPei/Eltorito.c > @@ -0,0 +1,239 @@ > +/** @file > + Routines supporting partition discovery and > + logical device reading > + > +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> + > +This program and the accompanying materials are licensed and made > available > +under the terms and conditions of the BSD License which accompanies this > +distribution. The full text of the license may be found at > +http://opensource.org/licenses/bsd-license.php > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include > +#include "FatLitePeim.h" > + > +/** > + This function finds Eltorito partitions. Main algorithm > + is ported from DXE partition driver. > + > + @param PrivateData The global memory map > + @param ParentBlockDevNo The parent block device > + > + @retval TRUE New partitions are detected and logical bloc= k devices > + are added to block device array > + @retval FALSE No New partitions are added; > + > +**/ > +BOOLEAN > +FatFindEltoritoPartitions ( > + IN PEI_FAT_PRIVATE_DATA *PrivateData, > + IN UINTN ParentBlockDevNo > + ) > +{ > + EFI_STATUS Status; > + BOOLEAN Found; > + PEI_FAT_BLOCK_DEVICE *BlockDev; > + PEI_FAT_BLOCK_DEVICE *ParentBlockDev; > + UINT32 VolDescriptorLba; > + UINT32 Lba; > + CDROM_VOLUME_DESCRIPTOR *VolDescriptor; > + ELTORITO_CATALOG *Catalog; > + UINTN Check; > + UINTN Index; > + UINTN MaxIndex; > + UINT16 *CheckBuffer; > + UINT32 SubBlockSize; > + UINT32 SectorCount; > + UINT32 VolSpaceSize; > + > + if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) { > + return FALSE; > + } > + > + Found =3D FALSE; > + ParentBlockDev =3D &(PrivateData->BlockDevice[ParentBlockDevNo]); > + VolSpaceSize =3D 0; > + > + // > + // CD_ROM has the fixed block size as 2048 bytes > + // > + if (ParentBlockDev->BlockSize !=3D 2048) { > + return FALSE; > + } > + > + VolDescriptor =3D (CDROM_VOLUME_DESCRIPTOR *) PrivateData- > >BlockData; > + Catalog =3D (ELTORITO_CATALOG *) VolDescriptor; > + > + // > + // the ISO-9660 volume descriptor starts at 32k on the media > + // and CD_ROM has the fixed block size as 2048 bytes, so... > + // > + VolDescriptorLba =3D 15; > + // > + // ((16*2048) / Media->BlockSize) - 1; > + // > + // Loop: handle one volume descriptor per time > + // > + while (TRUE) { > + > + VolDescriptorLba +=3D 1; > + if (VolDescriptorLba > ParentBlockDev->LastBlock) { > + // > + // We are pointing past the end of the device so exit > + // > + break; > + } > + > + Status =3D FatReadBlock ( > + PrivateData, > + ParentBlockDevNo, > + VolDescriptorLba, > + ParentBlockDev->BlockSize, > + VolDescriptor > + ); > + if (EFI_ERROR (Status)) { > + break; > + } > + // > + // Check for valid volume descriptor signature > + // > + if (VolDescriptor->Unknown.Type =3D=3D CDVOL_TYPE_END || > + CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof > (VolDescriptor->Unknown.Id)) !=3D 0 > + ) { > + // > + // end of Volume descriptor list > + // > + break; > + } > + // > + // Read the Volume Space Size from Primary Volume Descriptor 81-88 > byte > + // > + if (VolDescriptor->Unknown.Type =3D=3D CDVOL_TYPE_CODED) { > + VolSpaceSize =3D VolDescriptor->PrimaryVolume.VolSpaceSize[1]; > + } > + // > + // Is it an El Torito volume descriptor? > + // > + if (CompareMem ( > + VolDescriptor->BootRecordVolume.SystemId, > + CDVOL_ELTORITO_ID, > + sizeof (CDVOL_ELTORITO_ID) - 1 > + ) !=3D 0) { > + continue; > + } > + // > + // Read in the boot El Torito boot catalog > + // > + Lba =3D UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog); > + if (Lba > ParentBlockDev->LastBlock) { > + continue; > + } > + > + Status =3D FatReadBlock ( > + PrivateData, > + ParentBlockDevNo, > + Lba, > + ParentBlockDev->BlockSize, > + Catalog > + ); > + if (EFI_ERROR (Status)) { > + continue; > + } > + // > + // We don't care too much about the Catalog header's contents, but w= e > do want > + // to make sure it looks like a Catalog header > + // > + if (Catalog->Catalog.Indicator !=3D ELTORITO_ID_CATALOG || Catalog- > >Catalog.Id55AA !=3D 0xAA55) { > + continue; > + } > + > + Check =3D 0; > + CheckBuffer =3D (UINT16 *) Catalog; > + for (Index =3D 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16= ); > Index +=3D 1) { > + Check +=3D CheckBuffer[Index]; > + } > + > + if ((Check & 0xFFFF) !=3D 0) { > + continue; > + } > + > + MaxIndex =3D ParentBlockDev->BlockSize / sizeof (ELTORITO_CATALOG); > + for (Index =3D 1; Index < MaxIndex; Index +=3D 1) { > + // > + // Next entry > + // > + Catalog +=3D 1; > + > + // > + // Check this entry > + // > + if (Catalog->Boot.Indicator !=3D ELTORITO_ID_SECTION_BOOTABLE || > Catalog->Boot.Lba =3D=3D 0) { > + continue; > + } > + > + SubBlockSize =3D 512; > + SectorCount =3D Catalog->Boot.SectorCount; > + > + switch (Catalog->Boot.MediaType) { > + > + case ELTORITO_NO_EMULATION: > + SubBlockSize =3D ParentBlockDev->BlockSize; > + SectorCount =3D Catalog->Boot.SectorCount; > + break; > + > + case ELTORITO_HARD_DISK: > + break; > + > + case ELTORITO_12_DISKETTE: > + SectorCount =3D 0x50 * 0x02 * 0x0F; > + break; > + > + case ELTORITO_14_DISKETTE: > + SectorCount =3D 0x50 * 0x02 * 0x12; > + break; > + > + case ELTORITO_28_DISKETTE: > + SectorCount =3D 0x50 * 0x02 * 0x24; > + break; > + > + default: > + SectorCount =3D 0; > + SubBlockSize =3D ParentBlockDev->BlockSize; > + break; > + } > + > + if (SectorCount < 2) { > + SectorCount =3D (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? > (UINT32) (ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32) > (VolSpaceSize - Catalog->Boot.Lba); > + } > + // > + // Register this partition > + // > + if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) { > + > + Found =3D TRUE; > + > + BlockDev =3D &(PrivateData->BlockDevice[Priva= teData- > >BlockDeviceCount]); > + > + BlockDev->BlockSize =3D SubBlockSize; > + BlockDev->LastBlock =3D SectorCount - 1; > + BlockDev->IoAlign =3D ParentBlockDev->IoAlign; > + BlockDev->Logical =3D TRUE; > + BlockDev->PartitionChecked =3D FALSE; > + BlockDev->StartingPos =3D MultU64x32 (Catalog->Boot.Lba, > ParentBlockDev->BlockSize); > + BlockDev->ParentDevNo =3D ParentBlockDevNo; > + > + PrivateData->BlockDeviceCount++; > + } > + } > + } > + > + ParentBlockDev->PartitionChecked =3D TRUE; > + > + return Found; > + > +} > \ No newline at end of file > diff --git a/FatPkg/FatPei/FatPei.inf b/FatPkg/FatPei/FatPei.inf > index fc8d612283..829e87fe92 100644 > --- a/FatPkg/FatPei/FatPei.inf > +++ b/FatPkg/FatPei/FatPei.inf > @@ -30,6 +30,8 @@ > # >=20 > [Sources] > + Mbr.c > + Eltorito.c > Part.c > FatLiteApi.c > FatLiteLib.c > diff --git a/FatPkg/FatPei/Mbr.c b/FatPkg/FatPei/Mbr.c > new file mode 100644 > index 0000000000..41688e8ee3 > --- /dev/null > +++ b/FatPkg/FatPei/Mbr.c > @@ -0,0 +1,182 @@ > +/** @file > + Routines supporting partition discovery and > + logical device reading > + > +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> + > +This program and the accompanying materials are licensed and made > available > +under the terms and conditions of the BSD License which accompanies this > +distribution. The full text of the license may be found at > +http://opensource.org/licenses/bsd-license.php > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include > +#include "FatLitePeim.h" > + > +/** > + Test to see if the Mbr buffer is a valid MBR > + > + @param Mbr Parent Handle > + @param LastLba Last Lba address on the device. > + > + @retval TRUE Mbr is a Valid MBR > + @retval FALSE Mbr is not a Valid MBR > + > +**/ > +BOOLEAN > +PartitionValidMbr ( > + IN MASTER_BOOT_RECORD *Mbr, > + IN EFI_PEI_LBA LastLba > + ) > +{ > + UINT32 StartingLBA; > + UINT32 EndingLBA; > + UINT32 NewEndingLBA; > + INTN Index1; > + INTN Index2; > + BOOLEAN MbrValid; > + > + if (Mbr->Signature !=3D MBR_SIGNATURE) { > + return FALSE; > + } > + // > + // The BPB also has this signature, so it can not be used alone. > + // > + MbrValid =3D FALSE; > + for (Index1 =3D 0; Index1 < MAX_MBR_PARTITIONS; Index1++) { > + if (Mbr->Partition[Index1].OSIndicator =3D=3D 0x00 || UNPACK_UINT32 = (Mbr- > >Partition[Index1].SizeInLBA) =3D=3D 0) { > + continue; > + } > + > + MbrValid =3D TRUE; > + StartingLBA =3D UNPACK_UINT32 (Mbr->Partition[Index1].StartingLBA); > + EndingLBA =3D StartingLBA + UNPACK_UINT32 (Mbr- > >Partition[Index1].SizeInLBA) - 1; > + if (EndingLBA > LastLba) { > + // > + // Compatability Errata: > + // Some systems try to hide drive space with thier INT 13h driver > + // This does not hide space from the OS driver. This means the MB= R > + // that gets created from DOS is smaller than the MBR created fro= m > + // a real OS (NT & Win98). This leads to BlockIo->LastBlock being > + // wrong on some systems FDISKed by the OS. > + // > + // return FALSE Because no block devices on a system are implemen= ted > + // with INT 13h > + // > + return FALSE; > + } > + > + for (Index2 =3D Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) { > + if (Mbr->Partition[Index2].OSIndicator =3D=3D 0x00 || UNPACK_INT32= (Mbr- > >Partition[Index2].SizeInLBA) =3D=3D 0) { > + continue; > + } > + > + NewEndingLBA =3D UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA= ) > + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1; > + if (NewEndingLBA >=3D StartingLBA && UNPACK_UINT32 (Mbr- > >Partition[Index2].StartingLBA) <=3D EndingLBA) { > + // > + // This region overlaps with the Index1'th region > + // > + return FALSE; > + } > + } > + } > + // > + // Non of the regions overlapped so MBR is O.K. > + // > + return MbrValid; > +} > + > + > +/** > + This function finds Mbr partitions. Main algorithm > + is ported from DXE partition driver. > + > + @param PrivateData The global memory map > + @param ParentBlockDevNo The parent block device > + > + @retval TRUE New partitions are detected and logical bloc= k devices > + are added to block device array > + @retval FALSE No New partitions are added; > + > +**/ > +BOOLEAN > +FatFindMbrPartitions ( > + IN PEI_FAT_PRIVATE_DATA *PrivateData, > + IN UINTN ParentBlockDevNo > + ) > +{ > + EFI_STATUS Status; > + MASTER_BOOT_RECORD *Mbr; > + UINTN Index; > + BOOLEAN Found; > + PEI_FAT_BLOCK_DEVICE *ParentBlockDev; > + PEI_FAT_BLOCK_DEVICE *BlockDev; > + > + if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) { > + return FALSE; > + } > + > + ParentBlockDev =3D &(PrivateData->BlockDevice[ParentBlockDevNo]); > + > + if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) { > + DEBUG((DEBUG_ERROR, "Device BlockSize %x exeed exeed -> exceeds with this handled, Reviewed-by: Hao Wu Best Regards, Hao Wu > FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize)); > + return FALSE; > + } > + > + Found =3D FALSE; > + Mbr =3D (MASTER_BOOT_RECORD *) PrivateData->BlockData; > + > + Status =3D FatReadBlock ( > + PrivateData, > + ParentBlockDevNo, > + 0, > + ParentBlockDev->BlockSize, > + Mbr > + ); > + > + if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev- > >LastBlock)) { > + goto Done; > + } > + // > + // We have a valid mbr - add each partition > + // > + for (Index =3D 0; Index < MAX_MBR_PARTITIONS; Index++) { > + if (Mbr->Partition[Index].OSIndicator =3D=3D 0x00 || UNPACK_INT32 (M= br- > >Partition[Index].SizeInLBA) =3D=3D 0) { > + // > + // Don't use null MBR entries > + // > + continue; > + } > + // > + // Register this partition > + // > + if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) { > + > + Found =3D TRUE; > + > + BlockDev =3D &(PrivateData->BlockDevice[Private= Data- > >BlockDeviceCount]); > + > + BlockDev->BlockSize =3D MBR_SIZE; > + BlockDev->LastBlock =3D UNPACK_INT32 (Mbr- > >Partition[Index].SizeInLBA) - 1; > + BlockDev->IoAlign =3D ParentBlockDev->IoAlign; > + BlockDev->Logical =3D TRUE; > + BlockDev->PartitionChecked =3D FALSE; > + BlockDev->StartingPos =3D MultU64x32 ( > + UNPACK_INT32 (Mbr->Partition[Index].Star= tingLBA), > + ParentBlockDev->BlockSize > + ); > + BlockDev->ParentDevNo =3D ParentBlockDevNo; > + > + PrivateData->BlockDeviceCount++; > + } > + } > + > +Done: > + > + ParentBlockDev->PartitionChecked =3D TRUE; > + return Found; > +} > diff --git a/FatPkg/FatPei/Part.c b/FatPkg/FatPei/Part.c > index be185460f3..1cf5f11b27 100644 > --- a/FatPkg/FatPei/Part.c > +++ b/FatPkg/FatPei/Part.c > @@ -2,7 +2,7 @@ > Routines supporting partition discovery and > logical device reading >=20 > -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
> +Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>=20 > This program and the accompanying materials are licensed and made > available > under the terms and conditions of the BSD License which accompanies this > @@ -14,8 +14,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. >=20 > **/ >=20 > -#include > -#include > #include "FatLitePeim.h" >=20 > /** > @@ -83,384 +81,3 @@ FatFindPartitions ( > } while (Found && PrivateData->BlockDeviceCount <=3D > PEI_FAT_MAX_BLOCK_DEVICE); > } >=20 > - > -/** > - This function finds Eltorito partitions. Main algorithm > - is ported from DXE partition driver. > - > - @param PrivateData The global memory map > - @param ParentBlockDevNo The parent block device > - > - @retval TRUE New partitions are detected and logical bloc= k devices > - are added to block device array > - @retval FALSE No New partitions are added; > - > -**/ > -BOOLEAN > -FatFindEltoritoPartitions ( > - IN PEI_FAT_PRIVATE_DATA *PrivateData, > - IN UINTN ParentBlockDevNo > - ) > -{ > - EFI_STATUS Status; > - BOOLEAN Found; > - PEI_FAT_BLOCK_DEVICE *BlockDev; > - PEI_FAT_BLOCK_DEVICE *ParentBlockDev; > - UINT32 VolDescriptorLba; > - UINT32 Lba; > - CDROM_VOLUME_DESCRIPTOR *VolDescriptor; > - ELTORITO_CATALOG *Catalog; > - UINTN Check; > - UINTN Index; > - UINTN MaxIndex; > - UINT16 *CheckBuffer; > - UINT32 SubBlockSize; > - UINT32 SectorCount; > - UINT32 VolSpaceSize; > - > - if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) { > - return FALSE; > - } > - > - Found =3D FALSE; > - ParentBlockDev =3D &(PrivateData->BlockDevice[ParentBlockDevNo]); > - VolSpaceSize =3D 0; > - > - // > - // CD_ROM has the fixed block size as 2048 bytes > - // > - if (ParentBlockDev->BlockSize !=3D 2048) { > - return FALSE; > - } > - > - VolDescriptor =3D (CDROM_VOLUME_DESCRIPTOR *) PrivateData- > >BlockData; > - Catalog =3D (ELTORITO_CATALOG *) VolDescriptor; > - > - // > - // the ISO-9660 volume descriptor starts at 32k on the media > - // and CD_ROM has the fixed block size as 2048 bytes, so... > - // > - VolDescriptorLba =3D 15; > - // > - // ((16*2048) / Media->BlockSize) - 1; > - // > - // Loop: handle one volume descriptor per time > - // > - while (TRUE) { > - > - VolDescriptorLba +=3D 1; > - if (VolDescriptorLba > ParentBlockDev->LastBlock) { > - // > - // We are pointing past the end of the device so exit > - // > - break; > - } > - > - Status =3D FatReadBlock ( > - PrivateData, > - ParentBlockDevNo, > - VolDescriptorLba, > - ParentBlockDev->BlockSize, > - VolDescriptor > - ); > - if (EFI_ERROR (Status)) { > - break; > - } > - // > - // Check for valid volume descriptor signature > - // > - if (VolDescriptor->Unknown.Type =3D=3D CDVOL_TYPE_END || > - CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof > (VolDescriptor->Unknown.Id)) !=3D 0 > - ) { > - // > - // end of Volume descriptor list > - // > - break; > - } > - // > - // Read the Volume Space Size from Primary Volume Descriptor 81-88 > byte > - // > - if (VolDescriptor->Unknown.Type =3D=3D CDVOL_TYPE_CODED) { > - VolSpaceSize =3D VolDescriptor->PrimaryVolume.VolSpaceSize[1]; > - } > - // > - // Is it an El Torito volume descriptor? > - // > - if (CompareMem ( > - VolDescriptor->BootRecordVolume.SystemId, > - CDVOL_ELTORITO_ID, > - sizeof (CDVOL_ELTORITO_ID) - 1 > - ) !=3D 0) { > - continue; > - } > - // > - // Read in the boot El Torito boot catalog > - // > - Lba =3D UNPACK_INT32 (VolDescriptor->BootRecordVolume.EltCatalog); > - if (Lba > ParentBlockDev->LastBlock) { > - continue; > - } > - > - Status =3D FatReadBlock ( > - PrivateData, > - ParentBlockDevNo, > - Lba, > - ParentBlockDev->BlockSize, > - Catalog > - ); > - if (EFI_ERROR (Status)) { > - continue; > - } > - // > - // We don't care too much about the Catalog header's contents, but w= e > do want > - // to make sure it looks like a Catalog header > - // > - if (Catalog->Catalog.Indicator !=3D ELTORITO_ID_CATALOG || Catalog- > >Catalog.Id55AA !=3D 0xAA55) { > - continue; > - } > - > - Check =3D 0; > - CheckBuffer =3D (UINT16 *) Catalog; > - for (Index =3D 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16= ); > Index +=3D 1) { > - Check +=3D CheckBuffer[Index]; > - } > - > - if ((Check & 0xFFFF) !=3D 0) { > - continue; > - } > - > - MaxIndex =3D ParentBlockDev->BlockSize / sizeof (ELTORITO_CATALOG); > - for (Index =3D 1; Index < MaxIndex; Index +=3D 1) { > - // > - // Next entry > - // > - Catalog +=3D 1; > - > - // > - // Check this entry > - // > - if (Catalog->Boot.Indicator !=3D ELTORITO_ID_SECTION_BOOTABLE || > Catalog->Boot.Lba =3D=3D 0) { > - continue; > - } > - > - SubBlockSize =3D 512; > - SectorCount =3D Catalog->Boot.SectorCount; > - > - switch (Catalog->Boot.MediaType) { > - > - case ELTORITO_NO_EMULATION: > - SubBlockSize =3D ParentBlockDev->BlockSize; > - SectorCount =3D Catalog->Boot.SectorCount; > - break; > - > - case ELTORITO_HARD_DISK: > - break; > - > - case ELTORITO_12_DISKETTE: > - SectorCount =3D 0x50 * 0x02 * 0x0F; > - break; > - > - case ELTORITO_14_DISKETTE: > - SectorCount =3D 0x50 * 0x02 * 0x12; > - break; > - > - case ELTORITO_28_DISKETTE: > - SectorCount =3D 0x50 * 0x02 * 0x24; > - break; > - > - default: > - SectorCount =3D 0; > - SubBlockSize =3D ParentBlockDev->BlockSize; > - break; > - } > - > - if (SectorCount < 2) { > - SectorCount =3D (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? > (UINT32) (ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32) > (VolSpaceSize - Catalog->Boot.Lba); > - } > - // > - // Register this partition > - // > - if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) { > - > - Found =3D TRUE; > - > - BlockDev =3D &(PrivateData->BlockDevice[Priva= teData- > >BlockDeviceCount]); > - > - BlockDev->BlockSize =3D SubBlockSize; > - BlockDev->LastBlock =3D SectorCount - 1; > - BlockDev->IoAlign =3D ParentBlockDev->IoAlign; > - BlockDev->Logical =3D TRUE; > - BlockDev->PartitionChecked =3D FALSE; > - BlockDev->StartingPos =3D MultU64x32 (Catalog->Boot.Lba, > ParentBlockDev->BlockSize); > - BlockDev->ParentDevNo =3D ParentBlockDevNo; > - > - PrivateData->BlockDeviceCount++; > - } > - } > - } > - > - ParentBlockDev->PartitionChecked =3D TRUE; > - > - return Found; > - > -} > - > - > -/** > - Test to see if the Mbr buffer is a valid MBR > - > - @param Mbr Parent Handle > - @param LastLba Last Lba address on the device. > - > - @retval TRUE Mbr is a Valid MBR > - @retval FALSE Mbr is not a Valid MBR > - > -**/ > -BOOLEAN > -PartitionValidMbr ( > - IN MASTER_BOOT_RECORD *Mbr, > - IN EFI_PEI_LBA LastLba > - ) > -{ > - UINT32 StartingLBA; > - UINT32 EndingLBA; > - UINT32 NewEndingLBA; > - INTN Index1; > - INTN Index2; > - BOOLEAN MbrValid; > - > - if (Mbr->Signature !=3D MBR_SIGNATURE) { > - return FALSE; > - } > - // > - // The BPB also has this signature, so it can not be used alone. > - // > - MbrValid =3D FALSE; > - for (Index1 =3D 0; Index1 < MAX_MBR_PARTITIONS; Index1++) { > - if (Mbr->Partition[Index1].OSIndicator =3D=3D 0x00 || UNPACK_UINT32 = (Mbr- > >Partition[Index1].SizeInLBA) =3D=3D 0) { > - continue; > - } > - > - MbrValid =3D TRUE; > - StartingLBA =3D UNPACK_UINT32 (Mbr->Partition[Index1].StartingLBA); > - EndingLBA =3D StartingLBA + UNPACK_UINT32 (Mbr- > >Partition[Index1].SizeInLBA) - 1; > - if (EndingLBA > LastLba) { > - // > - // Compatability Errata: > - // Some systems try to hide drive space with thier INT 13h driver > - // This does not hide space from the OS driver. This means the MB= R > - // that gets created from DOS is smaller than the MBR created fro= m > - // a real OS (NT & Win98). This leads to BlockIo->LastBlock being > - // wrong on some systems FDISKed by the OS. > - // > - // return FALSE Because no block devices on a system are implemen= ted > - // with INT 13h > - // > - return FALSE; > - } > - > - for (Index2 =3D Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) { > - if (Mbr->Partition[Index2].OSIndicator =3D=3D 0x00 || UNPACK_INT32= (Mbr- > >Partition[Index2].SizeInLBA) =3D=3D 0) { > - continue; > - } > - > - NewEndingLBA =3D UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA= ) > + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1; > - if (NewEndingLBA >=3D StartingLBA && UNPACK_UINT32 (Mbr- > >Partition[Index2].StartingLBA) <=3D EndingLBA) { > - // > - // This region overlaps with the Index1'th region > - // > - return FALSE; > - } > - } > - } > - // > - // Non of the regions overlapped so MBR is O.K. > - // > - return MbrValid; > -} > - > - > -/** > - This function finds Mbr partitions. Main algorithm > - is ported from DXE partition driver. > - > - @param PrivateData The global memory map > - @param ParentBlockDevNo The parent block device > - > - @retval TRUE New partitions are detected and logical bloc= k devices > - are added to block device array > - @retval FALSE No New partitions are added; > - > -**/ > -BOOLEAN > -FatFindMbrPartitions ( > - IN PEI_FAT_PRIVATE_DATA *PrivateData, > - IN UINTN ParentBlockDevNo > - ) > -{ > - EFI_STATUS Status; > - MASTER_BOOT_RECORD *Mbr; > - UINTN Index; > - BOOLEAN Found; > - PEI_FAT_BLOCK_DEVICE *ParentBlockDev; > - PEI_FAT_BLOCK_DEVICE *BlockDev; > - > - if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) { > - return FALSE; > - } > - > - ParentBlockDev =3D &(PrivateData->BlockDevice[ParentBlockDevNo]); > - > - Found =3D FALSE; > - Mbr =3D (MASTER_BOOT_RECORD *) PrivateData->BlockData; > - > - Status =3D FatReadBlock ( > - PrivateData, > - ParentBlockDevNo, > - 0, > - ParentBlockDev->BlockSize, > - Mbr > - ); > - > - if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev- > >LastBlock)) { > - goto Done; > - } > - // > - // We have a valid mbr - add each partition > - // > - for (Index =3D 0; Index < MAX_MBR_PARTITIONS; Index++) { > - if (Mbr->Partition[Index].OSIndicator =3D=3D 0x00 || UNPACK_INT32 (M= br- > >Partition[Index].SizeInLBA) =3D=3D 0) { > - // > - // Don't use null MBR entries > - // > - continue; > - } > - // > - // Register this partition > - // > - if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) { > - > - Found =3D TRUE; > - > - BlockDev =3D &(PrivateData->BlockDevice[Private= Data- > >BlockDeviceCount]); > - > - BlockDev->BlockSize =3D MBR_SIZE; > - BlockDev->LastBlock =3D UNPACK_INT32 (Mbr- > >Partition[Index].SizeInLBA) - 1; > - BlockDev->IoAlign =3D ParentBlockDev->IoAlign; > - BlockDev->Logical =3D TRUE; > - BlockDev->PartitionChecked =3D FALSE; > - BlockDev->StartingPos =3D MultU64x32 ( > - UNPACK_INT32 (Mbr->Partition[Index].Star= tingLBA), > - ParentBlockDev->BlockSize > - ); > - BlockDev->ParentDevNo =3D ParentBlockDevNo; > - > - PrivateData->BlockDeviceCount++; > - } > - } > - > -Done: > - > - ParentBlockDev->PartitionChecked =3D TRUE; > - return Found; > -} > -- > 2.16.2.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel