Skip to content

Commit

Permalink
MdeModulePkg/PartitionDxe: Add impl of Partition Information Protocol
Browse files Browse the repository at this point in the history
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Bret Barkelew <[email protected]>
Signed-off-by: Hao Wu <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>
  • Loading branch information
hwu25 committed Jul 11, 2017
1 parent bce72b5 commit 3a3d62d
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 88 deletions.
43 changes: 24 additions & 19 deletions MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
Decode an El Torito formatted CD-ROM
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<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
Expand Down Expand Up @@ -44,22 +44,23 @@ PartitionInstallElToritoChildHandles (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
UINT64 VolDescriptorOffset;
UINT32 Lba2KB;
EFI_BLOCK_IO_MEDIA *Media;
CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
ELTORITO_CATALOG *Catalog;
UINTN Check;
UINTN Index;
UINTN BootEntry;
UINTN MaxIndex;
UINT16 *CheckBuffer;
CDROM_DEVICE_PATH CdDev;
UINT32 SubBlockSize;
UINT32 SectorCount;
EFI_STATUS Found;
UINT32 VolSpaceSize;
EFI_STATUS Status;
UINT64 VolDescriptorOffset;
UINT32 Lba2KB;
EFI_BLOCK_IO_MEDIA *Media;
CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
ELTORITO_CATALOG *Catalog;
UINTN Check;
UINTN Index;
UINTN BootEntry;
UINTN MaxIndex;
UINT16 *CheckBuffer;
CDROM_DEVICE_PATH CdDev;
UINT32 SubBlockSize;
UINT32 SectorCount;
EFI_STATUS Found;
UINT32 VolSpaceSize;
EFI_PARTITION_INFO_PROTOCOL PartitionInfo;

Found = EFI_NOT_FOUND;
Media = BlockIo->Media;
Expand Down Expand Up @@ -248,6 +249,10 @@ PartitionInstallElToritoChildHandles (
);
}

ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
PartitionInfo.Type = PARTITION_TYPE_OTHER;

Status = PartitionInstallChildHandle (
This,
Handle,
Expand All @@ -257,10 +262,10 @@ PartitionInstallElToritoChildHandles (
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,
FALSE
SubBlockSize
);
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
Expand Down
55 changes: 32 additions & 23 deletions MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk
partition content and validate the GPT table and GPT entry.
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<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
Expand Down Expand Up @@ -205,19 +205,20 @@ PartitionInstallGptChildHandles (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
UINT32 BlockSize;
EFI_LBA LastBlock;
MASTER_BOOT_RECORD *ProtectiveMbr;
EFI_PARTITION_TABLE_HEADER *PrimaryHeader;
EFI_PARTITION_TABLE_HEADER *BackupHeader;
EFI_PARTITION_ENTRY *PartEntry;
EFI_PARTITION_ENTRY *Entry;
EFI_PARTITION_ENTRY_STATUS *PEntryStatus;
UINTN Index;
EFI_STATUS GptValidStatus;
HARDDRIVE_DEVICE_PATH HdDev;
UINT32 MediaId;
EFI_STATUS Status;
UINT32 BlockSize;
EFI_LBA LastBlock;
MASTER_BOOT_RECORD *ProtectiveMbr;
EFI_PARTITION_TABLE_HEADER *PrimaryHeader;
EFI_PARTITION_TABLE_HEADER *BackupHeader;
EFI_PARTITION_ENTRY *PartEntry;
EFI_PARTITION_ENTRY *Entry;
EFI_PARTITION_ENTRY_STATUS *PEntryStatus;
UINTN Index;
EFI_STATUS GptValidStatus;
HARDDRIVE_DEVICE_PATH HdDev;
UINT32 MediaId;
EFI_PARTITION_INFO_PROTOCOL PartitionInfo;

ProtectiveMbr = NULL;
PrimaryHeader = NULL;
Expand Down Expand Up @@ -380,17 +381,25 @@ PartitionInstallGptChildHandles (
}

ZeroMem (&HdDev, sizeof (HdDev));
HdDev.Header.Type = MEDIA_DEVICE_PATH;
HdDev.Header.SubType = MEDIA_HARDDRIVE_DP;
HdDev.Header.Type = MEDIA_DEVICE_PATH;
HdDev.Header.SubType = MEDIA_HARDDRIVE_DP;
SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev));

HdDev.PartitionNumber = (UINT32) Index + 1;
HdDev.MBRType = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;
HdDev.SignatureType = SIGNATURE_TYPE_GUID;
HdDev.PartitionStart = Entry->StartingLBA;
HdDev.PartitionSize = Entry->EndingLBA - Entry->StartingLBA + 1;
HdDev.PartitionNumber = (UINT32) Index + 1;
HdDev.MBRType = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;
HdDev.SignatureType = SIGNATURE_TYPE_GUID;
HdDev.PartitionStart = Entry->StartingLBA;
HdDev.PartitionSize = Entry->EndingLBA - Entry->StartingLBA + 1;
CopyMem (HdDev.Signature, &Entry->UniquePartitionGUID, sizeof (EFI_GUID));

ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
PartitionInfo.Type = PARTITION_TYPE_GPT;
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)) {
PartitionInfo.System = 1;
}
CopyMem (&PartitionInfo.Info.Gpt, Entry, sizeof (EFI_PARTITION_ENTRY));

DEBUG ((EFI_D_INFO, " Index : %d\n", (UINT32) Index));
DEBUG ((EFI_D_INFO, " Start LBA : %lx\n", (UINT64) HdDev.PartitionStart));
DEBUG ((EFI_D_INFO, " End LBA : %lx\n", (UINT64) Entry->EndingLBA));
Expand All @@ -407,10 +416,10 @@ PartitionInstallGptChildHandles (
BlockIo2,
DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
&PartitionInfo,
Entry->StartingLBA,
Entry->EndingLBA,
BlockSize,
CompareGuid(&Entry->PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)
BlockSize
);
}

Expand Down
51 changes: 34 additions & 17 deletions MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
the legacy boot strap code.
Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<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
Expand Down Expand Up @@ -129,18 +129,19 @@ PartitionInstallMbrChildHandles (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
EFI_STATUS Status;
MASTER_BOOT_RECORD *Mbr;
UINT32 ExtMbrStartingLba;
UINT32 Index;
HARDDRIVE_DEVICE_PATH HdDev;
HARDDRIVE_DEVICE_PATH ParentHdDev;
EFI_STATUS Found;
EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode;
UINT32 BlockSize;
UINT32 MediaId;
EFI_LBA LastBlock;
EFI_STATUS Status;
MASTER_BOOT_RECORD *Mbr;
UINT32 ExtMbrStartingLba;
UINT32 Index;
HARDDRIVE_DEVICE_PATH HdDev;
HARDDRIVE_DEVICE_PATH ParentHdDev;
EFI_STATUS Found;
EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
EFI_DEVICE_PATH_PROTOCOL *LastDevicePathNode;
UINT32 BlockSize;
UINT32 MediaId;
EFI_LBA LastBlock;
EFI_PARTITION_INFO_PROTOCOL PartitionInfo;

Found = EFI_NOT_FOUND;

Expand Down Expand Up @@ -225,6 +226,14 @@ PartitionInstallMbrChildHandles (
HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA);
CopyMem (HdDev.Signature, &(Mbr->UniqueMbrSignature[0]), sizeof (Mbr->UniqueMbrSignature));

ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
PartitionInfo.Type = PARTITION_TYPE_MBR;
if (Mbr->Partition[Index].OSIndicator == EFI_PARTITION) {
PartitionInfo.System = 1;
}
CopyMem (&PartitionInfo.Info.Mbr, &Mbr->Partition[Index], sizeof (MBR_PARTITION_RECORD));

Status = PartitionInstallChildHandle (
This,
Handle,
Expand All @@ -234,10 +243,10 @@ PartitionInstallMbrChildHandles (
BlockIo2,
DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
&PartitionInfo,
HdDev.PartitionStart,
HdDev.PartitionStart + HdDev.PartitionSize - 1,
MBR_SIZE,
(BOOLEAN) (Mbr->Partition[Index].OSIndicator == EFI_PARTITION)
MBR_SIZE
);

if (!EFI_ERROR (Status)) {
Expand Down Expand Up @@ -288,6 +297,14 @@ PartitionInstallMbrChildHandles (
//
*((UINT32 *) &HdDev.Signature[0]) = 0;

ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
PartitionInfo.Type = PARTITION_TYPE_MBR;
if (Mbr->Partition[0].OSIndicator == EFI_PARTITION) {
PartitionInfo.System = 1;
}
CopyMem (&PartitionInfo.Info.Mbr, &Mbr->Partition[0], sizeof (MBR_PARTITION_RECORD));

Status = PartitionInstallChildHandle (
This,
Handle,
Expand All @@ -297,10 +314,10 @@ PartitionInstallMbrChildHandles (
BlockIo2,
DevicePath,
(EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
&PartitionInfo,
HdDev.PartitionStart - ParentHdDev.PartitionStart,
HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1,
MBR_SIZE,
(BOOLEAN) (Mbr->Partition[0].OSIndicator == EFI_PARTITION)
MBR_SIZE
);
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
Expand Down
23 changes: 18 additions & 5 deletions MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
of the raw block devices media. Currently "El Torito CD-ROM", Legacy
MBR, and GPT partition schemes are supported.
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<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
Expand Down Expand Up @@ -514,6 +514,8 @@ PartitionDriverBindingStop (
&Private->BlockIo,
&gEfiBlockIo2ProtocolGuid,
&Private->BlockIo2,
&gEfiPartitionInfoProtocolGuid,
&Private->PartitionInfo,
Private->EspGuid,
NULL,
NULL
Expand All @@ -526,6 +528,8 @@ PartitionDriverBindingStop (
Private->DevicePath,
&gEfiBlockIoProtocolGuid,
&Private->BlockIo,
&gEfiPartitionInfoProtocolGuid,
&Private->PartitionInfo,
Private->EspGuid,
NULL,
NULL
Expand Down Expand Up @@ -1092,10 +1096,10 @@ PartitionFlushBlocksEx (
@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] InstallEspGuid Flag to install EFI System Partition GUID on handle.
@retval EFI_SUCCESS A child handle was added.
@retval other A child handle was not added.
Expand All @@ -1111,10 +1115,10 @@ PartitionInstallChildHandle (
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 BOOLEAN InstallEspGuid
IN UINT32 BlockSize
)
{
EFI_STATUS Status;
Expand Down Expand Up @@ -1203,7 +1207,12 @@ PartitionInstallChildHandle (
return EFI_OUT_OF_RESOURCES;
}

if (InstallEspGuid) {
//
// Set the PartitionInfo into Private Data.
//
CopyMem (&Private->PartitionInfo, PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));

if ((PartitionInfo->System == 1)) {
Private->EspGuid = &gEfiPartTypeSystemPartGuid;
} else {
//
Expand All @@ -1225,6 +1234,8 @@ PartitionInstallChildHandle (
&Private->BlockIo,
&gEfiBlockIo2ProtocolGuid,
&Private->BlockIo2,
&gEfiPartitionInfoProtocolGuid,
&Private->PartitionInfo,
Private->EspGuid,
NULL,
NULL
Expand All @@ -1236,6 +1247,8 @@ PartitionInstallChildHandle (
Private->DevicePath,
&gEfiBlockIoProtocolGuid,
&Private->BlockIo,
&gEfiPartitionInfoProtocolGuid,
&Private->PartitionInfo,
Private->EspGuid,
NULL,
NULL
Expand Down
Loading

0 comments on commit 3a3d62d

Please sign in to comment.