From: Jeff Brasen <[email protected]> Add the partition type GUID for every partition to the installed handle, this is required per the UEFI specification.
"The firmware must add the PartitionTypeGuid to the handle of every active GPT partition using EFI_BOOT_SERVICES.InstallProtocolInterface()." Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jeff Brasen <[email protected]> --- .../Universal/Disk/PartitionDxe/ElTorito.c | 4 ++- MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c | 4 ++- MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c | 7 +++-- .../Universal/Disk/PartitionDxe/Partition.c | 30 ++++++++++++++-------- .../Universal/Disk/PartitionDxe/Partition.h | 7 +++-- MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c | 4 ++- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c index 2084ee5..a7b5434 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c @@ -1,13 +1,14 @@ /** @file Decode an El Torito formatted CD-ROM +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR> 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. **/ @@ -258,21 +259,22 @@ PartitionInstallElToritoChildHandles ( Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &CdDev, &PartitionInfo, Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize), Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize) + CdDev.PartitionSize - 1, - SubBlockSize + SubBlockSize, + NULL ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } } } FreePool (VolDescriptor); return Found; diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c index 2cd3e15..fe26a64 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c @@ -6,20 +6,21 @@ This driver will have external input - disk partition. This external input must be validated carefully to avoid security issue like buffer overflow, integer overflow. PartitionInstallGptChildHandles() routine will read disk partition content and do basic validation before PartitionInstallChildHandle(). PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk partition content and validate the GPT table and GPT entry. +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR> 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. **/ @@ -412,21 +413,22 @@ PartitionInstallGptChildHandles ( Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, &PartitionInfo, Entry->StartingLBA, Entry->EndingLBA, - BlockSize + BlockSize, + &Entry->PartitionTypeGUID ); } DEBUG ((EFI_D_INFO, "Prepare to Free Pool\n")); Done: if (ProtectiveMbr != NULL) { FreePool (ProtectiveMbr); } if (PrimaryHeader != NULL) { diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c index 55e9d26..479745b 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c @@ -4,20 +4,21 @@ MBR - Master Boot Record is in the first sector of a partitioned hard disk. The MBR supports four partitions per disk. The MBR also contains legacy code that is not run on an EFI system. The legacy code reads the first sector of the active partition into memory and BPB - BIOS Parameter Block is in the first sector of a FAT file system. The BPB contains information about the FAT file system. The BPB is always on the first sector of a media. The first sector also contains the legacy boot strap code. +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR> Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR> 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. @@ -239,21 +240,22 @@ PartitionInstallMbrChildHandles ( Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, &PartitionInfo, HdDev.PartitionStart, HdDev.PartitionStart + HdDev.PartitionSize - 1, - MBR_SIZE + MBR_SIZE, + ((Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid: NULL) ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } } } else { // // It's an extended partition. Follow the extended partition // chain to get all the logical drives @@ -310,21 +312,22 @@ PartitionInstallMbrChildHandles ( Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &HdDev, &PartitionInfo, HdDev.PartitionStart - ParentHdDev.PartitionStart, HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1, - MBR_SIZE + MBR_SIZE, + ((Mbr->Partition[0].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid: NULL) ); if (!EFI_ERROR (Status)) { Found = EFI_SUCCESS; } if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) && (Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION) ) { break; } diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c index 46c0877..71acdcc 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c @@ -1,16 +1,17 @@ /** @file Partition driver that produces logical BlockIo devices from a physical BlockIo device. The logical BlockIo devices are based on the format of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy MBR, and GPT partition schemes are supported. +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR> 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. **/ @@ -394,20 +395,21 @@ PartitionDriverBindingStop ( IN EFI_HANDLE *ChildHandleBuffer ) { EFI_STATUS Status; UINTN Index; EFI_BLOCK_IO_PROTOCOL *BlockIo; EFI_BLOCK_IO2_PROTOCOL *BlockIo2; BOOLEAN AllChildrenStopped; PARTITION_PRIVATE_DATA *Private; EFI_DISK_IO_PROTOCOL *DiskIo; + EFI_GUID *TypeGuid; BlockIo = NULL; BlockIo2 = NULL; Private = NULL; if (NumberOfChildren == 0) { // // In the case of re-entry of the PartitionDriverBindingStop, the // NumberOfChildren may not reflect the actual number of children on the // bus driver. Hence, additional check is needed here. @@ -486,20 +488,27 @@ PartitionDriverBindingStop ( } else { Status = EFI_SUCCESS; } gBS->CloseProtocol ( ControllerHandle, &gEfiDiskIoProtocolGuid, This->DriverBindingHandle, ChildHandleBuffer[Index] ); + + if (IsZeroGuid (&Private->TypeGuid)) { + TypeGuid = NULL; + } else { + TypeGuid = &Private->TypeGuid; + } + // // All Software protocols have be freed from the handle so remove it. // Remove the BlockIo Protocol if has. // Remove the BlockIo2 Protocol if has. // if (BlockIo2 != NULL) { // // Some device drivers might re-install the BlockIO(2) protocols for a // media change condition. Therefore, if the FlushBlocksEx returned with // EFI_MEDIA_CHANGED, just let the BindingStop fail to avoid potential @@ -509,35 +518,35 @@ PartitionDriverBindingStop ( Status = gBS->UninstallMultipleProtocolInterfaces ( ChildHandleBuffer[Index], &gEfiDevicePathProtocolGuid, Private->DevicePath, &gEfiBlockIoProtocolGuid, &Private->BlockIo, &gEfiBlockIo2ProtocolGuid, &Private->BlockIo2, &gEfiPartitionInfoProtocolGuid, &Private->PartitionInfo, - Private->EspGuid, + TypeGuid, NULL, NULL ); } } else { Status = gBS->UninstallMultipleProtocolInterfaces ( ChildHandleBuffer[Index], &gEfiDevicePathProtocolGuid, Private->DevicePath, &gEfiBlockIoProtocolGuid, &Private->BlockIo, &gEfiPartitionInfoProtocolGuid, &Private->PartitionInfo, - Private->EspGuid, + TypeGuid, NULL, NULL ); } if (EFI_ERROR (Status)) { Private->InStop = FALSE; gBS->OpenProtocol ( ControllerHandle, &gEfiDiskIoProtocolGuid, @@ -1097,39 +1106,41 @@ PartitionFlushBlocksEx ( @param[in] ParentDiskIo Parent DiskIo interface. @param[in] ParentDiskIo2 Parent DiskIo2 interface. @param[in] ParentBlockIo Parent BlockIo interface. @param[in] ParentBlockIo2 Parent BlockIo2 interface. @param[in] ParentDevicePath Parent Device Path. @param[in] DevicePathNode Child Device Path node. @param[in] PartitionInfo Child Partition Information interface. @param[in] Start Start Block. @param[in] End End Block. @param[in] BlockSize Child block size. + @param[in] TypeGuid Partition GUID Type. @retval EFI_SUCCESS A child handle was added. @retval other A child handle was not added. **/ EFI_STATUS PartitionInstallChildHandle ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ParentHandle, IN EFI_DISK_IO_PROTOCOL *ParentDiskIo, IN EFI_DISK_IO2_PROTOCOL *ParentDiskIo2, IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo, IN EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_PARTITION_INFO_PROTOCOL *PartitionInfo, IN EFI_LBA Start, IN EFI_LBA End, - IN UINT32 BlockSize + IN UINT32 BlockSize, + IN EFI_GUID *TypeGuid ) { EFI_STATUS Status; PARTITION_PRIVATE_DATA *Private; Status = EFI_SUCCESS; Private = AllocateZeroPool (sizeof (PARTITION_PRIVATE_DATA)); if (Private == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1209,58 +1220,55 @@ PartitionInstallChildHandle ( if (Private->DevicePath == NULL) { FreePool (Private); return EFI_OUT_OF_RESOURCES; } // // Set the PartitionInfo into Private Data. // CopyMem (&Private->PartitionInfo, PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL)); - if (PartitionInfo->System == 1) { - Private->EspGuid = &gEfiPartTypeSystemPartGuid; + if (TypeGuid != NULL) { + CopyGuid(&(Private->TypeGuid), TypeGuid); } else { - // - // If NULL InstallMultipleProtocolInterfaces will ignore it. - // - Private->EspGuid = NULL; + ZeroMem ((VOID *)&(Private->TypeGuid), sizeof (EFI_GUID)); } // // Create the new handle. // Private->Handle = NULL; if (Private->DiskIo2 != NULL) { Status = gBS->InstallMultipleProtocolInterfaces ( &Private->Handle, &gEfiDevicePathProtocolGuid, Private->DevicePath, &gEfiBlockIoProtocolGuid, &Private->BlockIo, &gEfiBlockIo2ProtocolGuid, &Private->BlockIo2, &gEfiPartitionInfoProtocolGuid, &Private->PartitionInfo, - Private->EspGuid, + TypeGuid, NULL, NULL ); } else { Status = gBS->InstallMultipleProtocolInterfaces ( &Private->Handle, &gEfiDevicePathProtocolGuid, Private->DevicePath, &gEfiBlockIoProtocolGuid, &Private->BlockIo, &gEfiPartitionInfoProtocolGuid, &Private->PartitionInfo, - Private->EspGuid, + TypeGuid, NULL, NULL ); } if (!EFI_ERROR (Status)) { // // Open the Parent Handle for the child // Status = gBS->OpenProtocol ( diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h index c763c67..f1a0520 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h @@ -1,16 +1,17 @@ /** @file Partition driver that produces logical BlockIo devices from a physical BlockIo device. The logical BlockIo devices are based on the format of the raw block devices media. Currently "El Torito CD-ROM", UDF, Legacy MBR, and GPT partition schemes are supported. +Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR> 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. **/ @@ -58,21 +59,21 @@ typedef struct { EFI_DISK_IO_PROTOCOL *DiskIo; EFI_DISK_IO2_PROTOCOL *DiskIo2; EFI_BLOCK_IO_PROTOCOL *ParentBlockIo; EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2; UINT64 Start; UINT64 End; UINT32 BlockSize; BOOLEAN InStop; - EFI_GUID *EspGuid; + EFI_GUID TypeGuid; } PARTITION_PRIVATE_DATA; typedef struct { EFI_DISK_IO2_TOKEN DiskIo2Token; EFI_BLOCK_IO2_TOKEN *BlockIo2Token; } PARTITION_ACCESS_TASK; #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE) #define PARTITION_DEVICE_FROM_BLOCK_IO2_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo2, PARTITION_PRIVATE_DATA_SIGNATURE) @@ -320,39 +321,41 @@ PartitionComponentNameGetControllerName ( @param[in] ParentDiskIo Parent DiskIo interface. @param[in] ParentDiskIo2 Parent DiskIo2 interface. @param[in] ParentBlockIo Parent BlockIo interface. @param[in] ParentBlockIo2 Parent BlockIo2 interface. @param[in] ParentDevicePath Parent Device Path. @param[in] DevicePathNode Child Device Path node. @param[in] PartitionInfo Child Partition Information interface. @param[in] Start Start Block. @param[in] End End Block. @param[in] BlockSize Child block size. + @param[in] TypeGuid Parition Type Guid. @retval EFI_SUCCESS A child handle was added. @retval other A child handle was not added. **/ EFI_STATUS PartitionInstallChildHandle ( IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE ParentHandle, IN EFI_DISK_IO_PROTOCOL *ParentDiskIo, IN EFI_DISK_IO2_PROTOCOL *ParentDiskIo2, IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo, IN EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath, IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN EFI_PARTITION_INFO_PROTOCOL *PartitionInfo, IN EFI_LBA Start, IN EFI_LBA End, - IN UINT32 BlockSize + IN UINT32 BlockSize, + IN EFI_GUID *TypeGuid ); /** Test to see if there is any child on ControllerHandle. @param[in] ControllerHandle Handle of device to test. @retval TRUE There are children on the ControllerHandle. @retval FALSE No child is on the ControllerHandle. diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c index 5aac564..83bd174 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c @@ -1,13 +1,14 @@ /** @file Scan for an UDF file system on a formatted media. + Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (C) 2014-2017 Paulo Alcantara <[email protected]> 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. **/ @@ -746,18 +747,19 @@ PartitionInstallUdfChildHandles ( Handle, DiskIo, DiskIo2, BlockIo, BlockIo2, DevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath, &PartitionInfo, StartingLBA, EndingLBA, - Media->BlockSize + Media->BlockSize, + NULL ); if (EFI_ERROR (Status)) { return (ChildCreated ? EFI_SUCCESS : Status); } return EFI_SUCCESS; } -- 1.9.1 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

