summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/Disk/PartitionDxe
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Universal/Disk/PartitionDxe')
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c21
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c119
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c177
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c111
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c365
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h84
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c399
7 files changed, 666 insertions, 610 deletions
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c
index 7d1031f35c..fd27a84b81 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/ComponentName.c
@@ -20,9 +20,9 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentNa
//
// EFI Component Name 2 Protocol
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2 = {
- (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) PartitionComponentNameGetDriverName,
- (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) PartitionComponentNameGetControllerName,
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2 = {
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)PartitionComponentNameGetDriverName,
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)PartitionComponentNameGetControllerName,
"en"
};
@@ -30,7 +30,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentNa
// Driver name table for Partition module.
// It is shared by the implementation of ComponentName & ComponentName2 Protocol.
//
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPartitionDriverNameTable[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPartitionDriverNameTable[] = {
{
"eng;en",
L"Partition Driver(MBR/GPT/El Torito)"
@@ -41,8 +41,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mPartitionDriverNameTable
}
};
-
-
/**
Retrieves a Unicode string that is the user readable name of the driver.
@@ -99,7 +97,6 @@ PartitionComponentNameGetDriverName (
);
}
-
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
@@ -171,11 +168,11 @@ PartitionComponentNameGetDriverName (
EFI_STATUS
EFIAPI
PartitionComponentNameGetControllerName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
)
{
return EFI_UNSUPPORTED;
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
index e2b028f733..977ded851e 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/ElTorito.c
@@ -7,10 +7,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-
#include "Partition.h"
-
/**
Install child handles if the Handle supports El Torito format.
@@ -57,10 +55,10 @@ PartitionInstallElToritoChildHandles (
UINT32 VolSpaceSize;
EFI_PARTITION_INFO_PROTOCOL PartitionInfo;
- Found = EFI_NOT_FOUND;
- Media = BlockIo->Media;
+ Found = EFI_NOT_FOUND;
+ Media = BlockIo->Media;
- VolSpaceSize = 0;
+ VolSpaceSize = 0;
//
// CD_ROM has the fixed block size as 2048 bytes (SIZE_2KB)
@@ -79,7 +77,7 @@ PartitionInstallElToritoChildHandles (
return EFI_NOT_FOUND;
}
- Catalog = (ELTORITO_CATALOG *) VolDescriptor;
+ Catalog = (ELTORITO_CATALOG *)VolDescriptor;
//
// Loop: handle one volume descriptor per time
@@ -87,7 +85,8 @@ PartitionInstallElToritoChildHandles (
//
for (VolDescriptorOffset = SIZE_32KB;
VolDescriptorOffset <= MultU64x32 (Media->LastBlock, Media->BlockSize);
- VolDescriptorOffset += SIZE_2KB) {
+ VolDescriptorOffset += SIZE_2KB)
+ {
Status = DiskIo->ReadDisk (
DiskIo,
Media->MediaId,
@@ -99,17 +98,20 @@ PartitionInstallElToritoChildHandles (
Found = Status;
break;
}
+
//
// Check for valid volume descriptor signature
//
- if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
- CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0
- ) {
+ if ((VolDescriptor->Unknown.Type == CDVOL_TYPE_END) ||
+ (CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0)
+ )
+ {
//
// end of Volume descriptor list
//
break;
}
+
//
// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte,
// the 32-bit numerical values is stored in Both-byte orders
@@ -117,12 +119,14 @@ PartitionInstallElToritoChildHandles (
if (VolDescriptor->PrimaryVolume.Type == CDVOL_TYPE_CODED) {
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[0];
}
+
//
// Is it an El Torito volume descriptor?
//
if (CompareMem (VolDescriptor->BootRecordVolume.SystemId, CDVOL_ELTORITO_ID, sizeof (CDVOL_ELTORITO_ID) - 1) != 0) {
continue;
}
+
//
// Read in the boot El Torito boot catalog
// The LBA unit used by El Torito boot catalog is 2KB unit
@@ -144,17 +148,18 @@ PartitionInstallElToritoChildHandles (
DEBUG ((DEBUG_ERROR, "EltCheckDevice: error reading catalog %r\n", Status));
continue;
}
+
//
// We don't care too much about the Catalog header's contents, but we do want
// to make sure it looks like a Catalog header
//
- if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) {
+ if ((Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG) || (Catalog->Catalog.Id55AA != 0xAA55)) {
DEBUG ((DEBUG_ERROR, "EltCheckBootCatalog: El Torito boot catalog header IDs not correct\n"));
continue;
}
Check = 0;
- CheckBuffer = (UINT16 *) Catalog;
+ CheckBuffer = (UINT16 *)Catalog;
for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
Check += CheckBuffer[Index];
}
@@ -174,45 +179,45 @@ PartitionInstallElToritoChildHandles (
//
// Check this entry
//
- if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) {
+ if ((Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE) || (Catalog->Boot.Lba == 0)) {
continue;
}
- SubBlockSize = 512;
- SectorCount = Catalog->Boot.SectorCount;
+ SubBlockSize = 512;
+ SectorCount = Catalog->Boot.SectorCount;
switch (Catalog->Boot.MediaType) {
-
- case ELTORITO_NO_EMULATION:
- SubBlockSize = Media->BlockSize;
- break;
-
- case ELTORITO_HARD_DISK:
- break;
-
- case ELTORITO_12_DISKETTE:
- SectorCount = 0x50 * 0x02 * 0x0F;
- break;
-
- case ELTORITO_14_DISKETTE:
- SectorCount = 0x50 * 0x02 * 0x12;
- break;
-
- case ELTORITO_28_DISKETTE:
- SectorCount = 0x50 * 0x02 * 0x24;
- break;
-
- default:
- DEBUG ((DEBUG_INIT, "EltCheckDevice: unsupported El Torito boot media type %x\n", Catalog->Boot.MediaType));
- SectorCount = 0;
- SubBlockSize = Media->BlockSize;
- break;
+ case ELTORITO_NO_EMULATION:
+ SubBlockSize = Media->BlockSize;
+ break;
+
+ case ELTORITO_HARD_DISK:
+ break;
+
+ case ELTORITO_12_DISKETTE:
+ SectorCount = 0x50 * 0x02 * 0x0F;
+ break;
+
+ case ELTORITO_14_DISKETTE:
+ SectorCount = 0x50 * 0x02 * 0x12;
+ break;
+
+ case ELTORITO_28_DISKETTE:
+ SectorCount = 0x50 * 0x02 * 0x24;
+ break;
+
+ default:
+ DEBUG ((DEBUG_INIT, "EltCheckDevice: unsupported El Torito boot media type %x\n", Catalog->Boot.MediaType));
+ SectorCount = 0;
+ SubBlockSize = Media->BlockSize;
+ break;
}
+
//
// Create child device handle
//
- CdDev.Header.Type = MEDIA_DEVICE_PATH;
- CdDev.Header.SubType = MEDIA_CDROM_DP;
+ CdDev.Header.Type = MEDIA_DEVICE_PATH;
+ CdDev.Header.SubType = MEDIA_CDROM_DP;
SetDevicePathNodeLength (&CdDev.Header, sizeof (CdDev));
if (Index == 1) {
@@ -222,7 +227,7 @@ PartitionInstallElToritoChildHandles (
BootEntry = 0;
}
- CdDev.BootEntry = (UINT32) BootEntry;
+ CdDev.BootEntry = (UINT32)BootEntry;
BootEntry++;
CdDev.PartitionStart = Catalog->Boot.Lba * (SIZE_2KB / Media->BlockSize);
if (SectorCount < 2) {
@@ -249,20 +254,20 @@ PartitionInstallElToritoChildHandles (
PartitionInfo.Type = PARTITION_TYPE_OTHER;
Status = PartitionInstallChildHandle (
- This,
- 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,
- NULL
- );
+ This,
+ 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,
+ NULL
+ );
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
}
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
index e985bd2c44..5bcf94d587 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Gpt.c
@@ -19,7 +19,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-
#include "Partition.h"
/**
@@ -65,7 +64,6 @@ PartitionCheckGptEntryArrayCRC (
IN EFI_PARTITION_TABLE_HEADER *PartHeader
);
-
/**
Restore Partition Table to its alternate place
(Primary -> Backup or Backup -> Primary).
@@ -85,7 +83,6 @@ PartitionRestoreGptTable (
IN EFI_PARTITION_TABLE_HEADER *PartHeader
);
-
/**
This routine will check GPT partition entry and return entry status.
@@ -106,7 +103,6 @@ PartitionCheckGptEntry (
OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus
);
-
/**
Checks the CRC32 value in the table header.
@@ -125,7 +121,6 @@ PartitionCheckCrcAltSize (
IN OUT EFI_TABLE_HEADER *Hdr
);
-
/**
Checks the CRC32 value in the table header.
@@ -142,7 +137,6 @@ PartitionCheckCrc (
IN OUT EFI_TABLE_HEADER *Hdr
);
-
/**
Updates the CRC32 value in the table header.
@@ -156,7 +150,6 @@ PartitionSetCrcAltSize (
IN OUT EFI_TABLE_HEADER *Hdr
);
-
/**
Updates the CRC32 value in the table header.
@@ -165,7 +158,7 @@ PartitionSetCrcAltSize (
**/
VOID
PartitionSetCrc (
- IN OUT EFI_TABLE_HEADER *Hdr
+ IN OUT EFI_TABLE_HEADER *Hdr
);
/**
@@ -221,9 +214,9 @@ PartitionInstallGptChildHandles (
PartEntry = NULL;
PEntryStatus = NULL;
- BlockSize = BlockIo->Media->BlockSize;
- LastBlock = BlockIo->Media->LastBlock;
- MediaId = BlockIo->Media->MediaId;
+ BlockSize = BlockIo->Media->BlockSize;
+ LastBlock = BlockIo->Media->LastBlock;
+ MediaId = BlockIo->Media->MediaId;
DEBUG ((DEBUG_INFO, " BlockSize : %d \n", BlockSize));
DEBUG ((DEBUG_INFO, " LastBlock : %lx \n", LastBlock));
@@ -264,12 +257,14 @@ PartitionInstallGptChildHandles (
// Verify that the Protective MBR is valid
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
- if (ProtectiveMbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION &&
- UNPACK_UINT32 (ProtectiveMbr->Partition[Index].StartingLBA) == 1
- ) {
+ if ((ProtectiveMbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION) &&
+ (UNPACK_UINT32 (ProtectiveMbr->Partition[Index].StartingLBA) == 1)
+ )
+ {
break;
}
}
+
if (Index == MAX_MBR_PARTITIONS) {
goto Done;
}
@@ -317,7 +312,6 @@ PartitionInstallGptChildHandles (
if (PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) {
DEBUG ((DEBUG_INFO, " Restore backup partition table success\n"));
}
-
}
DEBUG ((DEBUG_INFO, " Valid primary and Valid backup partition table\n"));
@@ -334,7 +328,7 @@ PartitionInstallGptChildHandles (
Status = DiskIo->ReadDisk (
DiskIo,
MediaId,
- MultU64x32(PrimaryHeader->PartitionEntryLBA, BlockSize),
+ MultU64x32 (PrimaryHeader->PartitionEntryLBA, BlockSize),
PrimaryHeader->NumberOfPartitionEntries * (PrimaryHeader->SizeOfPartitionEntry),
PartEntry
);
@@ -368,12 +362,13 @@ PartitionInstallGptChildHandles (
// Create child device handles
//
for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index * PrimaryHeader->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index * PrimaryHeader->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
PEntryStatus[Index].OutOfRange ||
PEntryStatus[Index].Overlap ||
PEntryStatus[Index].OsSpecific
- ) {
+ )
+ {
//
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
// partition Entries
@@ -382,15 +377,15 @@ 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));
@@ -399,12 +394,13 @@ PartitionInstallGptChildHandles (
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)) {
PartitionInfo.System = 1;
}
+
CopyMem (&PartitionInfo.Info.Gpt, Entry, sizeof (EFI_PARTITION_ENTRY));
- DEBUG ((DEBUG_INFO, " Index : %d\n", (UINT32) Index));
- DEBUG ((DEBUG_INFO, " Start LBA : %lx\n", (UINT64) HdDev.PartitionStart));
- DEBUG ((DEBUG_INFO, " End LBA : %lx\n", (UINT64) Entry->EndingLBA));
- DEBUG ((DEBUG_INFO, " Partition size: %lx\n", (UINT64) HdDev.PartitionSize));
+ DEBUG ((DEBUG_INFO, " Index : %d\n", (UINT32)Index));
+ DEBUG ((DEBUG_INFO, " Start LBA : %lx\n", (UINT64)HdDev.PartitionStart));
+ DEBUG ((DEBUG_INFO, " End LBA : %lx\n", (UINT64)Entry->EndingLBA));
+ DEBUG ((DEBUG_INFO, " Partition size: %lx\n", (UINT64)HdDev.PartitionSize));
DEBUG ((DEBUG_INFO, " Start : %lx", MultU64x32 (Entry->StartingLBA, BlockSize)));
DEBUG ((DEBUG_INFO, " End : %lx\n", MultU64x32 (Entry->EndingLBA, BlockSize)));
@@ -416,7 +412,7 @@ PartitionInstallGptChildHandles (
BlockIo,
BlockIo2,
DevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
+ (EFI_DEVICE_PATH_PROTOCOL *)&HdDev,
&PartitionInfo,
Entry->StartingLBA,
Entry->EndingLBA,
@@ -431,15 +427,19 @@ Done:
if (ProtectiveMbr != NULL) {
FreePool (ProtectiveMbr);
}
+
if (PrimaryHeader != NULL) {
FreePool (PrimaryHeader);
}
+
if (BackupHeader != NULL) {
FreePool (BackupHeader);
}
+
if (PartEntry != NULL) {
FreePool (PartEntry);
}
+
if (PEntryStatus != NULL) {
FreePool (PEntryStatus);
}
@@ -484,6 +484,7 @@ PartitionValidGptTable (
DEBUG ((DEBUG_ERROR, "Allocate pool error\n"));
return FALSE;
}
+
//
// Read the EFI Partition Table Header
//
@@ -501,9 +502,10 @@ PartitionValidGptTable (
if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
!PartitionCheckCrc (BlockSize, &PartHdr->Header) ||
- PartHdr->MyLBA != Lba ||
+ (PartHdr->MyLBA != Lba) ||
(PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY))
- ) {
+ )
+ {
DEBUG ((DEBUG_INFO, "Invalid efi partition table header\n"));
FreePool (PartHdr);
return FALSE;
@@ -562,20 +564,20 @@ PartitionCheckGptEntryArrayCRC (
}
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- MultU64x32(PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize),
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
- Ptr
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ MultU64x32 (PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize),
+ PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
+ Ptr
+ );
if (EFI_ERROR (Status)) {
FreePool (Ptr);
return FALSE;
}
- Size = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry;
+ Size = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry;
- Status = gBS->CalculateCrc32 (Ptr, Size, &Crc);
+ Status = gBS->CalculateCrc32 (Ptr, Size, &Crc);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "CheckPEntryArrayCRC: Crc calculation failed\n"));
FreePool (Ptr);
@@ -584,10 +586,9 @@ PartitionCheckGptEntryArrayCRC (
FreePool (Ptr);
- return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+ return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc);
}
-
/**
Restore Partition Table to its alternate place
(Primary -> Backup or Backup -> Primary).
@@ -614,13 +615,13 @@ PartitionRestoreGptTable (
UINT8 *Ptr;
UINT32 MediaId;
- PartHdr = NULL;
- Ptr = NULL;
+ PartHdr = NULL;
+ Ptr = NULL;
BlockSize = BlockIo->Media->BlockSize;
MediaId = BlockIo->Media->MediaId;
- PartHdr = AllocateZeroPool (BlockSize);
+ PartHdr = AllocateZeroPool (BlockSize);
if (PartHdr == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate pool error\n"));
@@ -628,20 +629,20 @@ PartitionRestoreGptTable (
}
PEntryLBA = (PartHeader->MyLBA == PRIMARY_PART_HEADER_LBA) ? \
- (PartHeader->LastUsableLBA + 1) : \
- (PRIMARY_PART_HEADER_LBA + 1);
+ (PartHeader->LastUsableLBA + 1) : \
+ (PRIMARY_PART_HEADER_LBA + 1);
CopyMem (PartHdr, PartHeader, sizeof (EFI_PARTITION_TABLE_HEADER));
- PartHdr->MyLBA = PartHeader->AlternateLBA;
- PartHdr->AlternateLBA = PartHeader->MyLBA;
- PartHdr->PartitionEntryLBA = PEntryLBA;
- PartitionSetCrc ((EFI_TABLE_HEADER *) PartHdr);
+ PartHdr->MyLBA = PartHeader->AlternateLBA;
+ PartHdr->AlternateLBA = PartHeader->MyLBA;
+ PartHdr->PartitionEntryLBA = PEntryLBA;
+ PartitionSetCrc ((EFI_TABLE_HEADER *)PartHdr);
Status = DiskIo->WriteDisk (
DiskIo,
MediaId,
- MultU64x32 (PartHdr->MyLBA, (UINT32) BlockSize),
+ MultU64x32 (PartHdr->MyLBA, (UINT32)BlockSize),
BlockSize,
PartHdr
);
@@ -657,23 +658,23 @@ PartitionRestoreGptTable (
}
Status = DiskIo->ReadDisk (
- DiskIo,
- MediaId,
- MultU64x32(PartHeader->PartitionEntryLBA, (UINT32) BlockSize),
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
- Ptr
- );
+ DiskIo,
+ MediaId,
+ MultU64x32 (PartHeader->PartitionEntryLBA, (UINT32)BlockSize),
+ PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
+ Ptr
+ );
if (EFI_ERROR (Status)) {
goto Done;
}
Status = DiskIo->WriteDisk (
- DiskIo,
- MediaId,
- MultU64x32(PEntryLBA, (UINT32) BlockSize),
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
- Ptr
- );
+ DiskIo,
+ MediaId,
+ MultU64x32 (PEntryLBA, (UINT32)BlockSize),
+ PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
+ Ptr
+ );
Done:
FreePool (PartHdr);
@@ -717,19 +718,20 @@ PartitionCheckGptEntry (
DEBUG ((DEBUG_INFO, " start check partition entries\n"));
for (Index1 = 0; Index1 < PartHeader->NumberOfPartitionEntries; Index1++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index1 * PartHeader->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index1 * PartHeader->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
StartingLBA = Entry->StartingLBA;
EndingLBA = Entry->EndingLBA;
- if (StartingLBA > EndingLBA ||
- StartingLBA < PartHeader->FirstUsableLBA ||
- StartingLBA > PartHeader->LastUsableLBA ||
- EndingLBA < PartHeader->FirstUsableLBA ||
- EndingLBA > PartHeader->LastUsableLBA
- ) {
+ if ((StartingLBA > EndingLBA) ||
+ (StartingLBA < PartHeader->FirstUsableLBA) ||
+ (StartingLBA > PartHeader->LastUsableLBA) ||
+ (EndingLBA < PartHeader->FirstUsableLBA) ||
+ (EndingLBA > PartHeader->LastUsableLBA)
+ )
+ {
PEntryStatus[Index1].OutOfRange = TRUE;
continue;
}
@@ -742,17 +744,17 @@ PartitionCheckGptEntry (
}
for (Index2 = Index1 + 1; Index2 < PartHeader->NumberOfPartitionEntries; Index2++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index2 * PartHeader->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index2 * PartHeader->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
- if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {
+ if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
- PEntryStatus[Index1].Overlap = TRUE;
- PEntryStatus[Index2].Overlap = TRUE;
+ PEntryStatus[Index1].Overlap = TRUE;
+ PEntryStatus[Index2].Overlap = TRUE;
continue;
}
}
@@ -761,7 +763,6 @@ PartitionCheckGptEntry (
DEBUG ((DEBUG_INFO, " End check partition entries\n"));
}
-
/**
Updates the CRC32 value in the table header.
@@ -770,13 +771,12 @@ PartitionCheckGptEntry (
**/
VOID
PartitionSetCrc (
- IN OUT EFI_TABLE_HEADER *Hdr
+ IN OUT EFI_TABLE_HEADER *Hdr
)
{
PartitionSetCrcAltSize (Hdr->HeaderSize, Hdr);
}
-
/**
Updates the CRC32 value in the table header.
@@ -793,11 +793,10 @@ PartitionSetCrcAltSize (
UINT32 Crc;
Hdr->CRC32 = 0;
- gBS->CalculateCrc32 ((UINT8 *) Hdr, Size, &Crc);
+ gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc);
Hdr->CRC32 = Crc;
}
-
/**
Checks the CRC32 value in the table header.
@@ -817,7 +816,6 @@ PartitionCheckCrc (
return PartitionCheckCrcAltSize (MaxSize, Hdr->HeaderSize, Hdr);
}
-
/**
Checks the CRC32 value in the table header.
@@ -853,17 +851,19 @@ PartitionCheckCrcAltSize (
DEBUG ((DEBUG_ERROR, "CheckCrc32: Size > MaxSize\n"));
return FALSE;
}
+
//
// clear old crc from header
//
- OrgCrc = Hdr->CRC32;
- Hdr->CRC32 = 0;
+ OrgCrc = Hdr->CRC32;
+ Hdr->CRC32 = 0;
- Status = gBS->CalculateCrc32 ((UINT8 *) Hdr, Size, &Crc);
+ Status = gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc calculation failed\n"));
return FALSE;
}
+
//
// set results
//
@@ -873,10 +873,11 @@ PartitionCheckCrcAltSize (
// return status
//
DEBUG_CODE_BEGIN ();
- if (OrgCrc != Crc) {
- DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc check failed\n"));
- }
+ if (OrgCrc != Crc) {
+ DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc check failed\n"));
+ }
+
DEBUG_CODE_END ();
- return (BOOLEAN) (OrgCrc == Crc);
+ return (BOOLEAN)(OrgCrc == Crc);
}
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
index df25a93f85..0f8dc54865 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
@@ -32,26 +32,27 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
PartitionValidMbr (
- IN MASTER_BOOT_RECORD *Mbr,
- IN EFI_LBA LastLba
+ IN MASTER_BOOT_RECORD *Mbr,
+ IN EFI_LBA LastLba
)
{
- UINT32 StartingLBA;
- UINT32 EndingLBA;
- UINT32 NewEndingLBA;
- INTN Index1;
- INTN Index2;
- BOOLEAN MbrValid;
+ UINT32 StartingLBA;
+ UINT32 EndingLBA;
+ UINT32 NewEndingLBA;
+ INTN Index1;
+ INTN Index2;
+ BOOLEAN MbrValid;
if (Mbr->Signature != MBR_SIGNATURE) {
return FALSE;
}
+
//
// The BPB also has this signature, so it can not be used alone.
//
MbrValid = FALSE;
for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) {
- if (Mbr->Partition[Index1].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index1].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0)) {
continue;
}
@@ -71,18 +72,18 @@ PartitionValidMbr (
// with INT 13h
//
- DEBUG((DEBUG_INFO, "PartitionValidMbr: Bad MBR partition size EndingLBA(%1x) > LastLBA(%1x)\n", EndingLBA, LastLba));
+ DEBUG ((DEBUG_INFO, "PartitionValidMbr: Bad MBR partition size EndingLBA(%1x) > LastLBA(%1x)\n", EndingLBA, LastLba));
return FALSE;
}
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {
- if (Mbr->Partition[Index2].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index2].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) == 0)) {
continue;
}
NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1;
- if (NewEndingLBA >= StartingLBA && UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA) {
+ if ((NewEndingLBA >= StartingLBA) && (UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
@@ -90,13 +91,13 @@ PartitionValidMbr (
}
}
}
+
//
// None of the regions overlapped so MBR is O.K.
//
return MbrValid;
}
-
/**
Install child handles if the Handle supports MBR format.
@@ -138,14 +139,14 @@ PartitionInstallMbrChildHandles (
EFI_LBA LastSector;
EFI_PARTITION_INFO_PROTOCOL PartitionInfo;
- Found = EFI_NOT_FOUND;
+ Found = EFI_NOT_FOUND;
- BlockSize = BlockIo->Media->BlockSize;
- MediaId = BlockIo->Media->MediaId;
- LastSector = DivU64x32 (
- MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize),
- MBR_SIZE
- ) - 1;
+ BlockSize = BlockIo->Media->BlockSize;
+ MediaId = BlockIo->Media->MediaId;
+ LastSector = DivU64x32 (
+ MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize),
+ MBR_SIZE
+ ) - 1;
//
// Ensure the block size can hold the MBR
@@ -170,9 +171,11 @@ PartitionInstallMbrChildHandles (
Found = Status;
goto Done;
}
+
if (!PartitionValidMbr (Mbr, LastSector)) {
goto Done;
}
+
//
// We have a valid mbr - add each partition
//
@@ -183,14 +186,15 @@ PartitionInstallMbrChildHandles (
ZeroMem (&ParentHdDev, sizeof (ParentHdDev));
DevicePathNode = DevicePath;
while (!IsDevicePathEnd (DevicePathNode)) {
- LastDevicePathNode = DevicePathNode;
- DevicePathNode = NextDevicePathNode (DevicePathNode);
+ LastDevicePathNode = DevicePathNode;
+ DevicePathNode = NextDevicePathNode (DevicePathNode);
}
if (LastDevicePathNode != NULL) {
- if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH &&
- DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP
- ) {
+ if ((DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP)
+ )
+ {
CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));
} else {
LastDevicePathNode = NULL;
@@ -198,18 +202,18 @@ PartitionInstallMbrChildHandles (
}
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.MBRType = MBR_TYPE_PCAT;
- HdDev.SignatureType = SIGNATURE_TYPE_MBR;
+ HdDev.MBRType = MBR_TYPE_PCAT;
+ HdDev.SignatureType = SIGNATURE_TYPE_MBR;
if (LastDevicePathNode == NULL) {
//
// This is a MBR, add each partition
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
- if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA) == 0)) {
//
// Don't use null MBR entries
//
@@ -237,23 +241,24 @@ PartitionInstallMbrChildHandles (
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,
- DiskIo,
- DiskIo2,
- BlockIo,
- BlockIo2,
- DevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
- &PartitionInfo,
- HdDev.PartitionStart,
- HdDev.PartitionStart + HdDev.PartitionSize - 1,
- MBR_SIZE,
- ((Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid: NULL)
- );
+ This,
+ Handle,
+ DiskIo,
+ DiskIo2,
+ BlockIo,
+ BlockIo2,
+ DevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)&HdDev,
+ &PartitionInfo,
+ HdDev.PartitionStart,
+ HdDev.PartitionStart + HdDev.PartitionSize - 1,
+ MBR_SIZE,
+ ((Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid : NULL)
+ );
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
@@ -268,7 +273,6 @@ PartitionInstallMbrChildHandles (
ExtMbrStartingLba = 0;
do {
-
Status = DiskIo->ReadDisk (
DiskIo,
MediaId,
@@ -286,22 +290,25 @@ PartitionInstallMbrChildHandles (
}
if ((Mbr->Partition[0].OSIndicator == EXTENDED_DOS_PARTITION) ||
- (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION)) {
+ (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION))
+ {
ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA);
continue;
}
+
HdDev.PartitionNumber = ++Index;
HdDev.PartitionStart = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart;
HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA);
if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) ||
- (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) {
+ (HdDev.PartitionStart <= ParentHdDev.PartitionStart))
+ {
break;
}
//
// The signature in EBR(Extended Boot Record) should always be 0.
//
- *((UINT32 *) &HdDev.Signature[0]) = 0;
+ *((UINT32 *)&HdDev.Signature[0]) = 0;
ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
@@ -309,6 +316,7 @@ PartitionInstallMbrChildHandles (
if (Mbr->Partition[0].OSIndicator == EFI_PARTITION) {
PartitionInfo.System = 1;
}
+
CopyMem (&PartitionInfo.Info.Mbr, &Mbr->Partition[0], sizeof (MBR_PARTITION_RECORD));
Status = PartitionInstallChildHandle (
@@ -319,12 +327,12 @@ PartitionInstallMbrChildHandles (
BlockIo,
BlockIo2,
DevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
+ (EFI_DEVICE_PATH_PROTOCOL *)&HdDev,
&PartitionInfo,
HdDev.PartitionStart - ParentHdDev.PartitionStart,
HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1,
MBR_SIZE,
- ((Mbr->Partition[0].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid: NULL)
+ ((Mbr->Partition[0].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid : NULL)
);
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
@@ -332,7 +340,8 @@ PartitionInstallMbrChildHandles (
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 aebc8a1dac..bc89559727 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.c
@@ -10,13 +10,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-
#include "Partition.h"
//
// Partition Driver Global Variables.
//
-EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
+EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
PartitionDriverBindingSupported,
PartitionDriverBindingStart,
PartitionDriverBindingStop,
@@ -44,7 +43,7 @@ EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {
// Note: UDF is using a same method as booting from CD-ROM, so put it along
// with CD-ROM check.
//
-PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {
+PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {
PartitionInstallGptChildHandles,
PartitionInstallUdfChildHandles,
PartitionInstallMbrChildHandles,
@@ -92,10 +91,11 @@ PartitionDriverBindingSupported (
// If RemainingDevicePath isn't the End of Device Path Node,
// check its validation
//
- Node = (EFI_DEV_PATH *) RemainingDevicePath;
- if (Node->DevPath.Type != MEDIA_DEVICE_PATH ||
- Node->DevPath.SubType != MEDIA_HARDDRIVE_DP ||
- DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)) {
+ Node = (EFI_DEV_PATH *)RemainingDevicePath;
+ if ((Node->DevPath.Type != MEDIA_DEVICE_PATH) ||
+ (Node->DevPath.SubType != MEDIA_HARDDRIVE_DP) ||
+ (DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)))
+ {
return EFI_UNSUPPORTED;
}
}
@@ -107,7 +107,7 @@ PartitionDriverBindingSupported (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,
- (VOID **) &DiskIo,
+ (VOID **)&DiskIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -115,9 +115,11 @@ PartitionDriverBindingSupported (
if (Status == EFI_ALREADY_STARTED) {
return EFI_SUCCESS;
}
+
if (EFI_ERROR (Status)) {
return Status;
}
+
//
// Close the I/O Abstraction(s) used to perform the supported test
//
@@ -134,7 +136,7 @@ PartitionDriverBindingSupported (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
- (VOID **) &ParentDevicePath,
+ (VOID **)&ParentDevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
@@ -151,11 +153,11 @@ PartitionDriverBindingSupported (
// Close protocol, don't use device path protocol in the Support() function
//
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDevicePathProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
//
// Open the IO Abstraction(s) needed to perform the supported test
@@ -207,7 +209,7 @@ PartitionDriverBindingStart (
EFI_TPL OldTpl;
BlockIo2 = NULL;
- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
//
// Check RemainingDevicePath validation
//
@@ -229,7 +231,7 @@ PartitionDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
- (VOID **) &BlockIo,
+ (VOID **)&BlockIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -241,7 +243,7 @@ PartitionDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIo2ProtocolGuid,
- (VOID **) &BlockIo2,
+ (VOID **)&BlockIo2,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -256,12 +258,12 @@ PartitionDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDevicePathProtocolGuid,
- (VOID **) &ParentDevicePath,
+ (VOID **)&ParentDevicePath,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
- if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
goto Exit;
}
@@ -271,18 +273,18 @@ PartitionDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,
- (VOID **) &DiskIo,
+ (VOID **)&DiskIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
- if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDevicePathProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
goto Exit;
}
@@ -291,12 +293,12 @@ PartitionDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIo2ProtocolGuid,
- (VOID **) &DiskIo2,
+ (VOID **)&DiskIo2,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
- if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ if (EFI_ERROR (Status) && (Status != EFI_ALREADY_STARTED)) {
DiskIo2 = NULL;
}
@@ -306,7 +308,8 @@ PartitionDriverBindingStart (
Status = EFI_UNSUPPORTED;
MediaPresent = BlockIo->Media->MediaPresent;
if (BlockIo->Media->MediaPresent ||
- (BlockIo->Media->RemovableMedia && !BlockIo->Media->LogicalPartition)) {
+ (BlockIo->Media->RemovableMedia && !BlockIo->Media->LogicalPartition))
+ {
//
// Try for GPT, then legacy MBR partition types, and then UDF and El Torito.
// If the media supports a given partition type install child handles to
@@ -314,21 +317,23 @@ PartitionDriverBindingStart (
//
Routine = &mPartitionDetectRoutineTable[0];
while (*Routine != NULL) {
- Status = (*Routine) (
- This,
- ControllerHandle,
- DiskIo,
- DiskIo2,
- BlockIo,
- BlockIo2,
- ParentDevicePath
- );
- if (!EFI_ERROR (Status) || Status == EFI_MEDIA_CHANGED || Status == EFI_NO_MEDIA) {
+ Status = (*Routine)(
+ This,
+ ControllerHandle,
+ DiskIo,
+ DiskIo2,
+ BlockIo,
+ BlockIo2,
+ ParentDevicePath
+ );
+ if (!EFI_ERROR (Status) || (Status == EFI_MEDIA_CHANGED) || (Status == EFI_NO_MEDIA)) {
break;
}
+
Routine++;
}
}
+
//
// In the case that the driver is already started (OpenStatus == EFI_ALREADY_STARTED),
// the DevicePathProtocol and the DiskIoProtocol are not actually opened by the
@@ -343,14 +348,15 @@ PartitionDriverBindingStart (
//
if (EFI_ERROR (Status) &&
!EFI_ERROR (OpenStatus) &&
- Status != EFI_MEDIA_CHANGED &&
- !(MediaPresent && Status == EFI_NO_MEDIA)) {
+ (Status != EFI_MEDIA_CHANGED) &&
+ !(MediaPresent && (Status == EFI_NO_MEDIA)))
+ {
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDiskIoProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDiskIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
//
// Close Parent DiskIo2 if has.
//
@@ -362,11 +368,11 @@ PartitionDriverBindingStart (
);
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDevicePathProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
}
Exit:
@@ -391,10 +397,10 @@ Exit:
EFI_STATUS
EFIAPI
PartitionDriverBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
@@ -408,7 +414,7 @@ PartitionDriverBindingStop (
BlockIo = NULL;
BlockIo2 = NULL;
- Private = NULL;
+ Private = NULL;
if (NumberOfChildren == 0) {
//
@@ -417,7 +423,7 @@ PartitionDriverBindingStop (
// bus driver. Hence, additional check is needed here.
//
if (HasChildren (ControllerHandle)) {
- DEBUG((DEBUG_ERROR, "PartitionDriverBindingStop: Still has child.\n"));
+ DEBUG ((DEBUG_ERROR, "PartitionDriverBindingStop: Still has child.\n"));
return EFI_DEVICE_ERROR;
}
@@ -425,11 +431,11 @@ PartitionDriverBindingStop (
// Close the bus driver
//
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDiskIoProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDiskIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
//
// Close Parent BlockIO2 if has.
//
@@ -441,11 +447,11 @@ PartitionDriverBindingStop (
);
gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDevicePathProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
return EFI_SUCCESS;
}
@@ -454,7 +460,7 @@ PartitionDriverBindingStop (
gBS->OpenProtocol (
ChildHandleBuffer[Index],
&gEfiBlockIoProtocolGuid,
- (VOID **) &BlockIo,
+ (VOID **)&BlockIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -465,13 +471,12 @@ PartitionDriverBindingStop (
gBS->OpenProtocol (
ChildHandleBuffer[Index],
&gEfiBlockIo2ProtocolGuid,
- (VOID **) &BlockIo2,
+ (VOID **)&BlockIo2,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
-
Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);
if (Private->InStop) {
//
@@ -480,13 +485,14 @@ PartitionDriverBindingStop (
//
break;
}
+
Private->InStop = TRUE;
BlockIo->FlushBlocks (BlockIo);
if (BlockIo2 != NULL) {
Status = BlockIo2->FlushBlocksEx (BlockIo2, NULL);
- DEBUG((DEBUG_ERROR, "PartitionDriverBindingStop: FlushBlocksEx returned with %r\n", Status));
+ DEBUG ((DEBUG_ERROR, "PartitionDriverBindingStop: FlushBlocksEx returned with %r\n", Status));
} else {
Status = EFI_SUCCESS;
}
@@ -518,33 +524,33 @@ PartitionDriverBindingStop (
//
if (Status != EFI_MEDIA_CHANGED) {
Status = gBS->UninstallMultipleProtocolInterfaces (
- ChildHandleBuffer[Index],
- &gEfiDevicePathProtocolGuid,
- Private->DevicePath,
- &gEfiBlockIoProtocolGuid,
- &Private->BlockIo,
- &gEfiBlockIo2ProtocolGuid,
- &Private->BlockIo2,
- &gEfiPartitionInfoProtocolGuid,
- &Private->PartitionInfo,
- TypeGuid,
- NULL,
- NULL
- );
+ ChildHandleBuffer[Index],
+ &gEfiDevicePathProtocolGuid,
+ Private->DevicePath,
+ &gEfiBlockIoProtocolGuid,
+ &Private->BlockIo,
+ &gEfiBlockIo2ProtocolGuid,
+ &Private->BlockIo2,
+ &gEfiPartitionInfoProtocolGuid,
+ &Private->PartitionInfo,
+ TypeGuid,
+ NULL,
+ NULL
+ );
}
} else {
Status = gBS->UninstallMultipleProtocolInterfaces (
- ChildHandleBuffer[Index],
- &gEfiDevicePathProtocolGuid,
- Private->DevicePath,
- &gEfiBlockIoProtocolGuid,
- &Private->BlockIo,
- &gEfiPartitionInfoProtocolGuid,
- &Private->PartitionInfo,
- TypeGuid,
- NULL,
- NULL
- );
+ ChildHandleBuffer[Index],
+ &gEfiDevicePathProtocolGuid,
+ Private->DevicePath,
+ &gEfiBlockIoProtocolGuid,
+ &Private->BlockIo,
+ &gEfiPartitionInfoProtocolGuid,
+ &Private->PartitionInfo,
+ TypeGuid,
+ NULL,
+ NULL
+ );
}
if (EFI_ERROR (Status)) {
@@ -552,7 +558,7 @@ PartitionDriverBindingStop (
gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,
- (VOID **) &DiskIo,
+ (VOID **)&DiskIo,
This->DriverBindingHandle,
ChildHandleBuffer[Index],
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -577,7 +583,6 @@ PartitionDriverBindingStop (
return EFI_SUCCESS;
}
-
/**
Reset the Block Device.
@@ -601,9 +606,9 @@ PartitionReset (
Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);
return Private->ParentBlockIo->Reset (
- Private->ParentBlockIo,
- ExtendedVerification
- );
+ Private->ParentBlockIo,
+ ExtendedVerification
+ );
}
/**
@@ -621,13 +626,13 @@ PartitionReset (
**/
EFI_STATUS
ProbeMediaStatus (
- IN EFI_DISK_IO_PROTOCOL *DiskIo,
- IN UINT32 MediaId,
- IN EFI_STATUS DefaultStatus
+ IN EFI_DISK_IO_PROTOCOL *DiskIo,
+ IN UINT32 MediaId,
+ IN EFI_STATUS DefaultStatus
)
{
- EFI_STATUS Status;
- UINT8 Buffer[1];
+ EFI_STATUS Status;
+ UINT8 Buffer[1];
//
// Read 1 byte from offset 0 to check if the MediaId is still valid.
@@ -635,10 +640,11 @@ ProbeMediaStatus (
// allocate a buffer from the pool. The destination buffer for the
// data is in the stack.
//
- Status = DiskIo->ReadDisk (DiskIo, MediaId, 0, 1, (VOID*)Buffer);
+ Status = DiskIo->ReadDisk (DiskIo, MediaId, 0, 1, (VOID *)Buffer);
if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {
return Status;
}
+
return DefaultStatus;
}
@@ -684,6 +690,7 @@ PartitionReadBlocks (
if (Offset + BufferSize > Private->End) {
return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);
}
+
//
// Because some kinds of partition have different block size from their parent
// device, we call the Disk IO protocol on the parent device, not the Block IO
@@ -719,7 +726,7 @@ PartitionWriteBlocks (
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
- IN VOID *Buffer
+ IN VOID *Buffer
)
{
PARTITION_PRIVATE_DATA *Private;
@@ -735,6 +742,7 @@ PartitionWriteBlocks (
if (Offset + BufferSize > Private->End) {
return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);
}
+
//
// Because some kinds of partition have different block size from their parent
// device, we call the Disk IO protocol on the parent device, not the Block IO
@@ -743,7 +751,6 @@ PartitionWriteBlocks (
return Private->DiskIo->WriteDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);
}
-
/**
Flush the parent Block Device.
@@ -782,13 +789,13 @@ PartitionFlushBlocks (
**/
EFI_STATUS
ProbeMediaStatusEx (
- IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
- IN UINT32 MediaId,
- IN EFI_STATUS DefaultStatus
+ IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
+ IN UINT32 MediaId,
+ IN EFI_STATUS DefaultStatus
)
{
- EFI_STATUS Status;
- UINT8 Buffer[1];
+ EFI_STATUS Status;
+ UINT8 Buffer[1];
//
// Read 1 byte from offset 0 to check if the MediaId is still valid.
@@ -796,10 +803,11 @@ ProbeMediaStatusEx (
// allocate a buffer from the pool. The destination buffer for the
// data is in the stack.
//
- Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, (VOID*)Buffer);
+ Status = DiskIo2->ReadDiskEx (DiskIo2, MediaId, 0, NULL, 1, (VOID *)Buffer);
if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {
return Status;
}
+
return DefaultStatus;
}
@@ -817,8 +825,8 @@ ProbeMediaStatusEx (
EFI_STATUS
EFIAPI
PartitionResetEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN BOOLEAN ExtendedVerification
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
)
{
PARTITION_PRIVATE_DATA *Private;
@@ -840,13 +848,13 @@ PartitionResetEx (
VOID
EFIAPI
PartitionOnAccessComplete (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- PARTITION_ACCESS_TASK *Task;
+ PARTITION_ACCESS_TASK *Task;
- Task = (PARTITION_ACCESS_TASK *) Context;
+ Task = (PARTITION_ACCESS_TASK *)Context;
gBS->CloseEvent (Event);
@@ -865,11 +873,11 @@ PartitionOnAccessComplete (
**/
PARTITION_ACCESS_TASK *
PartitionCreateAccessTask (
- IN EFI_BLOCK_IO2_TOKEN *Token
+ IN EFI_BLOCK_IO2_TOKEN *Token
)
{
- EFI_STATUS Status;
- PARTITION_ACCESS_TASK *Task;
+ EFI_STATUS Status;
+ PARTITION_ACCESS_TASK *Task;
Task = AllocatePool (sizeof (*Task));
if (Task == NULL) {
@@ -929,12 +937,12 @@ PartitionCreateAccessTask (
EFI_STATUS
EFIAPI
PartitionReadBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token,
- IN UINTN BufferSize,
- OUT VOID *Buffer
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -1005,12 +1013,12 @@ PartitionReadBlocksEx (
EFI_STATUS
EFIAPI
PartitionWriteBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN UINT32 MediaId,
- IN EFI_LBA Lba,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token,
- IN UINTN BufferSize,
- IN VOID *Buffer
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
)
{
EFI_STATUS Status;
@@ -1043,6 +1051,7 @@ PartitionWriteBlocksEx (
} else {
Status = Private->DiskIo2->WriteDiskEx (Private->DiskIo2, MediaId, Offset, NULL, BufferSize, Buffer);
}
+
return Status;
}
@@ -1071,8 +1080,8 @@ PartitionWriteBlocksEx (
EFI_STATUS
EFIAPI
PartitionFlushBlocksEx (
- IN EFI_BLOCK_IO2_PROTOCOL *This,
- IN OUT EFI_BLOCK_IO2_TOKEN *Token
+ IN EFI_BLOCK_IO2_PROTOCOL *This,
+ IN OUT EFI_BLOCK_IO2_TOKEN *Token
)
{
EFI_STATUS Status;
@@ -1095,10 +1104,10 @@ PartitionFlushBlocksEx (
} else {
Status = Private->DiskIo2->FlushDiskEx (Private->DiskIo2, NULL);
}
+
return Status;
}
-
/**
Create a child handle for a logical block device that represents the
bytes Start to End of the Parent Block IO device.
@@ -1147,60 +1156,60 @@ PartitionInstallChildHandle (
return EFI_OUT_OF_RESOURCES;
}
- Private->Signature = PARTITION_PRIVATE_DATA_SIGNATURE;
+ Private->Signature = PARTITION_PRIVATE_DATA_SIGNATURE;
- Private->Start = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);
- Private->End = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);
+ Private->Start = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);
+ Private->End = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);
- Private->BlockSize = BlockSize;
- Private->ParentBlockIo = ParentBlockIo;
- Private->ParentBlockIo2 = ParentBlockIo2;
- Private->DiskIo = ParentDiskIo;
- Private->DiskIo2 = ParentDiskIo2;
+ Private->BlockSize = BlockSize;
+ Private->ParentBlockIo = ParentBlockIo;
+ Private->ParentBlockIo2 = ParentBlockIo2;
+ Private->DiskIo = ParentDiskIo;
+ Private->DiskIo2 = ParentDiskIo2;
//
// Set the BlockIO into Private Data.
//
Private->BlockIo.Revision = ParentBlockIo->Revision;
- Private->BlockIo.Media = &Private->Media;
+ Private->BlockIo.Media = &Private->Media;
CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));
- Private->BlockIo.Reset = PartitionReset;
- Private->BlockIo.ReadBlocks = PartitionReadBlocks;
- Private->BlockIo.WriteBlocks = PartitionWriteBlocks;
- Private->BlockIo.FlushBlocks = PartitionFlushBlocks;
+ Private->BlockIo.Reset = PartitionReset;
+ Private->BlockIo.ReadBlocks = PartitionReadBlocks;
+ Private->BlockIo.WriteBlocks = PartitionWriteBlocks;
+ Private->BlockIo.FlushBlocks = PartitionFlushBlocks;
//
// Set the BlockIO2 into Private Data.
//
if (Private->DiskIo2 != NULL) {
ASSERT (Private->ParentBlockIo2 != NULL);
- Private->BlockIo2.Media = &Private->Media2;
+ Private->BlockIo2.Media = &Private->Media2;
CopyMem (Private->BlockIo2.Media, ParentBlockIo2->Media, sizeof (EFI_BLOCK_IO_MEDIA));
- Private->BlockIo2.Reset = PartitionResetEx;
- Private->BlockIo2.ReadBlocksEx = PartitionReadBlocksEx;
- Private->BlockIo2.WriteBlocksEx = PartitionWriteBlocksEx;
- Private->BlockIo2.FlushBlocksEx = PartitionFlushBlocksEx;
+ Private->BlockIo2.Reset = PartitionResetEx;
+ Private->BlockIo2.ReadBlocksEx = PartitionReadBlocksEx;
+ Private->BlockIo2.WriteBlocksEx = PartitionWriteBlocksEx;
+ Private->BlockIo2.FlushBlocksEx = PartitionFlushBlocksEx;
}
- Private->Media.IoAlign = 0;
+ Private->Media.IoAlign = 0;
Private->Media.LogicalPartition = TRUE;
- Private->Media.LastBlock = DivU64x32 (
- MultU64x32 (
- End - Start + 1,
- ParentBlockIo->Media->BlockSize
- ),
- BlockSize
- ) - 1;
+ Private->Media.LastBlock = DivU64x32 (
+ MultU64x32 (
+ End - Start + 1,
+ ParentBlockIo->Media->BlockSize
+ ),
+ BlockSize
+ ) - 1;
- Private->Media.BlockSize = (UINT32) BlockSize;
+ Private->Media.BlockSize = (UINT32)BlockSize;
- Private->Media2.IoAlign = 0;
+ Private->Media2.IoAlign = 0;
Private->Media2.LogicalPartition = TRUE;
- Private->Media2.LastBlock = Private->Media.LastBlock;
- Private->Media2.BlockSize = (UINT32) BlockSize;
+ Private->Media2.LastBlock = Private->Media.LastBlock;
+ Private->Media2.BlockSize = (UINT32)BlockSize;
//
// Per UEFI Spec, LowestAlignedLba, LogicalBlocksPerPhysicalBlock and OptimalTransferLengthGranularity must be 0
@@ -1217,7 +1226,7 @@ PartitionInstallChildHandle (
}
}
- Private->DevicePath = AppendDevicePathNode (ParentDevicePath, DevicePathNode);
+ Private->DevicePath = AppendDevicePathNode (ParentDevicePath, DevicePathNode);
if (Private->DevicePath == NULL) {
FreePool (Private);
@@ -1230,7 +1239,7 @@ PartitionInstallChildHandle (
CopyMem (&Private->PartitionInfo, PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
if (TypeGuid != NULL) {
- CopyGuid(&(Private->TypeGuid), TypeGuid);
+ CopyGuid (&(Private->TypeGuid), TypeGuid);
} else {
ZeroMem ((VOID *)&(Private->TypeGuid), sizeof (EFI_GUID));
}
@@ -1276,7 +1285,7 @@ PartitionInstallChildHandle (
Status = gBS->OpenProtocol (
ParentHandle,
&gEfiDiskIoProtocolGuid,
- (VOID **) &ParentDiskIo,
+ (VOID **)&ParentDiskIo,
This->DriverBindingHandle,
Private->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
@@ -1298,7 +1307,6 @@ PartitionInstallChildHandle (
return Status;
}
-
/**
The user Entry Point for module Partition. The user code starts with this function.
@@ -1312,11 +1320,11 @@ PartitionInstallChildHandle (
EFI_STATUS
EFIAPI
InitializePartition (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Install driver model protocol(s).
@@ -1331,11 +1339,9 @@ InitializePartition (
);
ASSERT_EFI_ERROR (Status);
-
return Status;
}
-
/**
Test to see if there is any child on ControllerHandle.
@@ -1347,7 +1353,7 @@ InitializePartition (
**/
BOOLEAN
HasChildren (
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE ControllerHandle
)
{
EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
@@ -1368,7 +1374,8 @@ HasChildren (
break;
}
}
+
FreePool (OpenInfoBuffer);
- return (BOOLEAN) (Index < EntryCount);
+ return (BOOLEAN)(Index < EntryCount);
}
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
index a633950bec..100aa4c310 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
@@ -41,36 +41,35 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
#define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
typedef struct {
- UINT64 Signature;
-
- EFI_HANDLE Handle;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_BLOCK_IO_PROTOCOL BlockIo;
- EFI_BLOCK_IO2_PROTOCOL BlockIo2;
- EFI_BLOCK_IO_MEDIA Media;
- EFI_BLOCK_IO_MEDIA Media2;//For BlockIO2
- EFI_PARTITION_INFO_PROTOCOL PartitionInfo;
-
- 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 TypeGuid;
-
+ UINT64 Signature;
+
+ EFI_HANDLE Handle;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_BLOCK_IO_PROTOCOL BlockIo;
+ EFI_BLOCK_IO2_PROTOCOL BlockIo2;
+ EFI_BLOCK_IO_MEDIA Media;
+ EFI_BLOCK_IO_MEDIA Media2;// For BlockIO2
+ EFI_PARTITION_INFO_PROTOCOL PartitionInfo;
+
+ 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 TypeGuid;
} PARTITION_PRIVATE_DATA;
typedef struct {
- EFI_DISK_IO2_TOKEN DiskIo2Token;
- EFI_BLOCK_IO2_TOKEN *BlockIo2Token;
+ 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)
+#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)
//
// Global Variables
@@ -82,7 +81,7 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2;
//
// Extract INT32 from char array
//
-#define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
+#define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
(((UINT8 *) a)[1] << 8) | \
(((UINT8 *) a)[2] << 16) | \
(((UINT8 *) a)[3] << 24) )
@@ -90,24 +89,24 @@ extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2;
//
// Extract UINT32 from char array
//
-#define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
+#define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
(((UINT8 *) a)[1] << 8) | \
(((UINT8 *) a)[2] << 16) | \
(((UINT8 *) a)[3] << 24) )
-
//
// GPT Partition Entry Status
//
typedef struct {
- BOOLEAN OutOfRange;
- BOOLEAN Overlap;
- BOOLEAN OsSpecific;
+ BOOLEAN OutOfRange;
+ BOOLEAN Overlap;
+ BOOLEAN OsSpecific;
} EFI_PARTITION_ENTRY_STATUS;
//
// Function Prototypes
//
+
/**
Test to see if this driver supports ControllerHandle. Any ControllerHandle
than contains a BlockIo and DiskIo protocol can be supported.
@@ -170,15 +169,16 @@ PartitionDriverBindingStart (
EFI_STATUS
EFIAPI
PartitionDriverBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
);
//
// EFI Component Name Functions
//
+
/**
Retrieves a Unicode string that is the user readable name of the driver.
@@ -226,7 +226,6 @@ PartitionComponentNameGetDriverName (
OUT CHAR16 **DriverName
);
-
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
@@ -298,14 +297,13 @@ PartitionComponentNameGetDriverName (
EFI_STATUS
EFIAPI
PartitionComponentNameGetControllerName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
);
-
/**
Create a child handle for a logical block device that represents the
bytes Start to End of the Parent Block IO device.
@@ -356,7 +354,7 @@ PartitionInstallChildHandle (
**/
BOOLEAN
HasChildren (
- IN EFI_HANDLE ControllerHandle
+ IN EFI_HANDLE ControllerHandle
);
/**
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
index 3bf89a1873..098e4fec66 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Udf.c
@@ -18,7 +18,7 @@
#include "Partition.h"
-#define MAX_CORRECTION_BLOCKS_NUM 512u
+#define MAX_CORRECTION_BLOCKS_NUM 512u
//
// C5BD4D42-1A76-4996-8956-73CDA326CD0A
@@ -29,25 +29,27 @@
}
typedef struct {
- VENDOR_DEVICE_PATH DevicePath;
- EFI_DEVICE_PATH_PROTOCOL End;
+ VENDOR_DEVICE_PATH DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL End;
} UDF_DEVICE_PATH;
//
// Vendor-Defined Device Path GUID for UDF file system
//
-EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;
+EFI_GUID gUdfDevPathGuid = EFI_UDF_DEVICE_PATH_GUID;
//
// Vendor-Defined Media Device Path for UDF file system
//
-UDF_DEVICE_PATH gUdfDevicePath = {
- { { MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP,
- { sizeof (VENDOR_DEVICE_PATH), 0 } },
+UDF_DEVICE_PATH gUdfDevicePath = {
+ {
+ { MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP,
+ { sizeof (VENDOR_DEVICE_PATH), 0 }
+ },
EFI_UDF_DEVICE_PATH_GUID
},
- { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
- { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
+ { END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
}
};
@@ -99,10 +101,10 @@ FindAnchorVolumeDescriptorPointer (
// That said, we define a magic number of 512 blocks to be used as correction
// when attempting to find AVDP and define last block number.
//
- BlockSize = BlockIo->Media->BlockSize;
- EndLBA = BlockIo->Media->LastBlock;
+ BlockSize = BlockIo->Media->BlockSize;
+ EndLBA = BlockIo->Media->LastBlock;
*LastRecordedBlock = EndLBA;
- AvdpsCount = 0;
+ AvdpsCount = 0;
//
// Check if the block size of the underlying media can hold the data of an
@@ -122,12 +124,12 @@ FindAnchorVolumeDescriptorPointer (
// Find AVDP at block 256
//
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- MultU64x32 (256, BlockSize),
- sizeof (*AnchorPoint),
- AnchorPoint
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ MultU64x32 (256, BlockSize),
+ sizeof (*AnchorPoint),
+ AnchorPoint
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -146,12 +148,12 @@ FindAnchorVolumeDescriptorPointer (
// Find AVDP at block N - 256
//
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- MultU64x32 ((UINT64)EndLBA - 256, BlockSize),
- sizeof (*AnchorPoint),
- AnchorPoint
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ MultU64x32 ((UINT64)EndLBA - 256, BlockSize),
+ sizeof (*AnchorPoint),
+ AnchorPoint
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -159,10 +161,15 @@ FindAnchorVolumeDescriptorPointer (
//
// Check if read block is a valid AVDP descriptor
//
- if (DescriptorTag->TagIdentifier == UdfAnchorVolumeDescriptorPointer &&
- ++AvdpsCount == 2) {
- DEBUG ((DEBUG_INFO, "%a: found AVDP at block %Ld\n", __FUNCTION__,
- EndLBA - 256));
+ if ((DescriptorTag->TagIdentifier == UdfAnchorVolumeDescriptorPointer) &&
+ (++AvdpsCount == 2))
+ {
+ DEBUG ((
+ DEBUG_INFO,
+ "%a: found AVDP at block %Ld\n",
+ __FUNCTION__,
+ EndLBA - 256
+ ));
return EFI_SUCCESS;
}
@@ -177,12 +184,12 @@ FindAnchorVolumeDescriptorPointer (
// Find AVDP at block N
//
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- MultU64x32 ((UINT64)EndLBA, BlockSize),
- sizeof (*AnchorPoint),
- AnchorPoint
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ MultU64x32 ((UINT64)EndLBA, BlockSize),
+ sizeof (*AnchorPoint),
+ AnchorPoint
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -213,12 +220,12 @@ FindAnchorVolumeDescriptorPointer (
// Read consecutive MAX_CORRECTION_BLOCKS_NUM disk blocks
//
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- MultU64x32 ((UINT64)EndLBA - MAX_CORRECTION_BLOCKS_NUM, BlockSize),
- Size,
- AnchorPoints
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ MultU64x32 ((UINT64)EndLBA - MAX_CORRECTION_BLOCKS_NUM, BlockSize),
+ Size,
+ AnchorPoints
+ );
if (EFI_ERROR (Status)) {
goto Out_Free;
}
@@ -241,10 +248,19 @@ FindAnchorVolumeDescriptorPointer (
// Calculate last recorded block number
//
LastAvdpBlockNum = EndLBA - (MAX_CORRECTION_BLOCKS_NUM - Index);
- DEBUG ((DEBUG_WARN, "%a: found AVDP at block %Ld\n", __FUNCTION__,
- LastAvdpBlockNum));
- DEBUG ((DEBUG_WARN, "%a: correcting last block from %Ld to %Ld\n",
- __FUNCTION__, EndLBA, LastAvdpBlockNum));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: found AVDP at block %Ld\n",
+ __FUNCTION__,
+ LastAvdpBlockNum
+ ));
+ DEBUG ((
+ DEBUG_WARN,
+ "%a: correcting last block from %Ld to %Ld\n",
+ __FUNCTION__,
+ EndLBA,
+ LastAvdpBlockNum
+ ));
//
// Save read AVDP from last block
//
@@ -253,7 +269,7 @@ FindAnchorVolumeDescriptorPointer (
// Set last recorded block number
//
*LastRecordedBlock = LastAvdpBlockNum;
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
break;
}
}
@@ -280,49 +296,60 @@ FindUdfVolumeIdentifiers (
IN EFI_DISK_IO_PROTOCOL *DiskIo
)
{
- EFI_STATUS Status;
- UINT64 Offset;
- UINT64 EndDiskOffset;
- CDROM_VOLUME_DESCRIPTOR VolDescriptor;
- CDROM_VOLUME_DESCRIPTOR TerminatingVolDescriptor;
+ EFI_STATUS Status;
+ UINT64 Offset;
+ UINT64 EndDiskOffset;
+ CDROM_VOLUME_DESCRIPTOR VolDescriptor;
+ CDROM_VOLUME_DESCRIPTOR TerminatingVolDescriptor;
ZeroMem ((VOID *)&TerminatingVolDescriptor, sizeof (CDROM_VOLUME_DESCRIPTOR));
//
// Start Volume Recognition Sequence
//
- EndDiskOffset = MultU64x32 (BlockIo->Media->LastBlock,
- BlockIo->Media->BlockSize);
+ EndDiskOffset = MultU64x32 (
+ BlockIo->Media->LastBlock,
+ BlockIo->Media->BlockSize
+ );
for (Offset = UDF_VRS_START_OFFSET; Offset < EndDiskOffset;
- Offset += UDF_LOGICAL_SECTOR_SIZE) {
+ Offset += UDF_LOGICAL_SECTOR_SIZE)
+ {
//
// Check if block device has a Volume Structure Descriptor and an Extended
// Area.
//
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- Offset,
- sizeof (CDROM_VOLUME_DESCRIPTOR),
- (VOID *)&VolDescriptor
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ Offset,
+ sizeof (CDROM_VOLUME_DESCRIPTOR),
+ (VOID *)&VolDescriptor
+ );
if (EFI_ERROR (Status)) {
return Status;
}
- if (CompareMem ((VOID *)VolDescriptor.Unknown.Id,
- (VOID *)UDF_BEA_IDENTIFIER,
- sizeof (VolDescriptor.Unknown.Id)) == 0) {
+ if (CompareMem (
+ (VOID *)VolDescriptor.Unknown.Id,
+ (VOID *)UDF_BEA_IDENTIFIER,
+ sizeof (VolDescriptor.Unknown.Id)
+ ) == 0)
+ {
break;
}
- if ((CompareMem ((VOID *)VolDescriptor.Unknown.Id,
- (VOID *)CDVOL_ID,
- sizeof (VolDescriptor.Unknown.Id)) != 0) ||
- (CompareMem ((VOID *)&VolDescriptor,
- (VOID *)&TerminatingVolDescriptor,
- sizeof (CDROM_VOLUME_DESCRIPTOR)) == 0)) {
+ if ((CompareMem (
+ (VOID *)VolDescriptor.Unknown.Id,
+ (VOID *)CDVOL_ID,
+ sizeof (VolDescriptor.Unknown.Id)
+ ) != 0) ||
+ (CompareMem (
+ (VOID *)&VolDescriptor,
+ (VOID *)&TerminatingVolDescriptor,
+ sizeof (CDROM_VOLUME_DESCRIPTOR)
+ ) == 0))
+ {
return EFI_NOT_FOUND;
}
}
@@ -336,22 +363,27 @@ FindUdfVolumeIdentifiers (
}
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- Offset,
- sizeof (CDROM_VOLUME_DESCRIPTOR),
- (VOID *)&VolDescriptor
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ Offset,
+ sizeof (CDROM_VOLUME_DESCRIPTOR),
+ (VOID *)&VolDescriptor
+ );
if (EFI_ERROR (Status)) {
return Status;
}
- if ((CompareMem ((VOID *)VolDescriptor.Unknown.Id,
- (VOID *)UDF_NSR2_IDENTIFIER,
- sizeof (VolDescriptor.Unknown.Id)) != 0) &&
- (CompareMem ((VOID *)VolDescriptor.Unknown.Id,
- (VOID *)UDF_NSR3_IDENTIFIER,
- sizeof (VolDescriptor.Unknown.Id)) != 0)) {
+ if ((CompareMem (
+ (VOID *)VolDescriptor.Unknown.Id,
+ (VOID *)UDF_NSR2_IDENTIFIER,
+ sizeof (VolDescriptor.Unknown.Id)
+ ) != 0) &&
+ (CompareMem (
+ (VOID *)VolDescriptor.Unknown.Id,
+ (VOID *)UDF_NSR3_IDENTIFIER,
+ sizeof (VolDescriptor.Unknown.Id)
+ ) != 0))
+ {
return EFI_NOT_FOUND;
}
@@ -364,19 +396,22 @@ FindUdfVolumeIdentifiers (
}
Status = DiskIo->ReadDisk (
- DiskIo,
- BlockIo->Media->MediaId,
- Offset,
- sizeof (CDROM_VOLUME_DESCRIPTOR),
- (VOID *)&VolDescriptor
- );
+ DiskIo,
+ BlockIo->Media->MediaId,
+ Offset,
+ sizeof (CDROM_VOLUME_DESCRIPTOR),
+ (VOID *)&VolDescriptor
+ );
if (EFI_ERROR (Status)) {
return Status;
}
- if (CompareMem ((VOID *)VolDescriptor.Unknown.Id,
- (VOID *)UDF_TEA_IDENTIFIER,
- sizeof (VolDescriptor.Unknown.Id)) != 0) {
+ if (CompareMem (
+ (VOID *)VolDescriptor.Unknown.Id,
+ (VOID *)UDF_TEA_IDENTIFIER,
+ sizeof (VolDescriptor.Unknown.Id)
+ ) != 0)
+ {
return EFI_NOT_FOUND;
}
@@ -395,22 +430,22 @@ FindUdfVolumeIdentifiers (
**/
BOOLEAN
IsLogicalVolumeDescriptorSupported (
- UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc
+ UDF_LOGICAL_VOLUME_DESCRIPTOR *LogicalVolDesc
)
{
//
// Check for a valid UDF revision range
//
switch (LogicalVolDesc->DomainIdentifier.Suffix.Domain.UdfRevision) {
- case 0x0102:
- case 0x0150:
- case 0x0200:
- case 0x0201:
- case 0x0250:
- case 0x0260:
- break;
- default:
- return FALSE;
+ case 0x0102:
+ case 0x0150:
+ case 0x0200:
+ case 0x0201:
+ case 0x0250:
+ case 0x0260:
+ break;
+ default:
+ return FALSE;
}
//
@@ -419,6 +454,7 @@ IsLogicalVolumeDescriptorSupported (
if (LogicalVolDesc->NumberOfPartitionMaps > 1) {
return FALSE;
}
+
//
// UDF 1.02 revision supports only Type 1 (Physical) partitions, but
// let's check it any way.
@@ -426,8 +462,9 @@ IsLogicalVolumeDescriptorSupported (
// PartitionMap[0] -> type
// PartitionMap[1] -> length (in bytes)
//
- if (LogicalVolDesc->PartitionMaps[0] != 1 ||
- LogicalVolDesc->PartitionMaps[1] != 6) {
+ if ((LogicalVolDesc->PartitionMaps[0] != 1) ||
+ (LogicalVolDesc->PartitionMaps[1] != 6))
+ {
return FALSE;
}
@@ -475,7 +512,7 @@ FindLogicalVolumeLocation (
UDF_DESCRIPTOR_TAG *DescriptorTag;
BlockSize = BlockIo->Media->BlockSize;
- ExtentAd = &AnchorPoint->MainVolumeDescriptorSequenceExtent;
+ ExtentAd = &AnchorPoint->MainVolumeDescriptorSequenceExtent;
//
// UDF 2.60, 2.2.3.1 struct MainVolumeDescriptorSequenceExtent
@@ -486,7 +523,7 @@ FindLogicalVolumeLocation (
// Also make sure it does not exceed maximum number of blocks in the disk.
//
SeqBlocksNum = DivU64x32 ((UINT64)ExtentAd->ExtentLength, BlockSize);
- if (SeqBlocksNum < 16 || (EFI_LBA)SeqBlocksNum > LastRecordedBlock + 1) {
+ if ((SeqBlocksNum < 16) || ((EFI_LBA)SeqBlocksNum > LastRecordedBlock + 1)) {
return EFI_VOLUME_CORRUPTED;
}
@@ -494,8 +531,9 @@ FindLogicalVolumeLocation (
// Check for valid Volume Descriptor Sequence starting block number
//
SeqStartBlock = (UINT64)ExtentAd->ExtentLocation;
- if (SeqStartBlock > LastRecordedBlock ||
- SeqStartBlock + SeqBlocksNum - 1 > LastRecordedBlock) {
+ if ((SeqStartBlock > LastRecordedBlock) ||
+ (SeqStartBlock + SeqBlocksNum - 1 > LastRecordedBlock))
+ {
return EFI_VOLUME_CORRUPTED;
}
@@ -509,24 +547,24 @@ FindLogicalVolumeLocation (
return EFI_OUT_OF_RESOURCES;
}
- SeqEndBlock = SeqStartBlock + SeqBlocksNum;
+ SeqEndBlock = SeqStartBlock + SeqBlocksNum;
StopSequence = FALSE;
- LvdsCount = 0;
- Status = EFI_VOLUME_CORRUPTED;
+ LvdsCount = 0;
+ Status = EFI_VOLUME_CORRUPTED;
//
// Start Main Volume Descriptor Sequence
//
- for (; SeqStartBlock < SeqEndBlock && !StopSequence; SeqStartBlock++) {
+ for ( ; SeqStartBlock < SeqEndBlock && !StopSequence; SeqStartBlock++) {
//
// Read disk block
//
Status = BlockIo->ReadBlocks (
- BlockIo,
- BlockIo->Media->MediaId,
- SeqStartBlock,
- BlockSize,
- Buffer
- );
+ BlockIo,
+ BlockIo->Media->MediaId,
+ SeqStartBlock,
+ BlockSize,
+ Buffer
+ );
if (EFI_ERROR (Status)) {
goto Out_Free;
}
@@ -548,50 +586,51 @@ FindLogicalVolumeLocation (
// Space Descriptors.
//
switch (DescriptorTag->TagIdentifier) {
- case UdfPrimaryVolumeDescriptor:
- case UdfImplemenationUseVolumeDescriptor:
- case UdfPartitionDescriptor:
- case UdfUnallocatedSpaceDescriptor:
- break;
-
- case UdfLogicalVolumeDescriptor:
- LogicalVolDesc = Buffer;
-
- //
- // Check for existence of a single LVD and whether it is supported by
- // current EDK2 UDF file system implementation.
- //
- if (++LvdsCount > 1 ||
- !IsLogicalVolumeDescriptorSupported (LogicalVolDesc)) {
- Status = EFI_UNSUPPORTED;
+ case UdfPrimaryVolumeDescriptor:
+ case UdfImplemenationUseVolumeDescriptor:
+ case UdfPartitionDescriptor:
+ case UdfUnallocatedSpaceDescriptor:
+ break;
+
+ case UdfLogicalVolumeDescriptor:
+ LogicalVolDesc = Buffer;
+
+ //
+ // Check for existence of a single LVD and whether it is supported by
+ // current EDK2 UDF file system implementation.
+ //
+ if ((++LvdsCount > 1) ||
+ !IsLogicalVolumeDescriptorSupported (LogicalVolDesc))
+ {
+ Status = EFI_UNSUPPORTED;
+ StopSequence = TRUE;
+ }
+
+ break;
+
+ case UdfTerminatingDescriptor:
+ //
+ // Stop the sequence when we find a Terminating Descriptor
+ // (aka Unallocated Sector), se we don't have to walk all the unallocated
+ // area unnecessarily.
+ //
StopSequence = TRUE;
- }
-
- break;
-
- case UdfTerminatingDescriptor:
- //
- // Stop the sequence when we find a Terminating Descriptor
- // (aka Unallocated Sector), se we don't have to walk all the unallocated
- // area unnecessarily.
- //
- StopSequence = TRUE;
- break;
-
- default:
- //
- // An invalid Volume Descriptor has been found in the sequece. Volume is
- // corrupted.
- //
- Status = EFI_VOLUME_CORRUPTED;
- goto Out_Free;
+ break;
+
+ default:
+ //
+ // An invalid Volume Descriptor has been found in the sequece. Volume is
+ // corrupted.
+ //
+ Status = EFI_VOLUME_CORRUPTED;
+ goto Out_Free;
}
}
//
// Check if LVD was found
//
- if (!EFI_ERROR (Status) && LvdsCount == 1) {
+ if (!EFI_ERROR (Status) && (LvdsCount == 1)) {
*MainVdsStartBlock = GuardMainVdsStartBlock;
//
// We do not need to read either LVD or PD descriptors to know the last
@@ -654,11 +693,11 @@ FindUdfFileSystem (
// Find Anchor Volume Descriptor Pointer
//
Status = FindAnchorVolumeDescriptorPointer (
- BlockIo,
- DiskIo,
- &AnchorPoint,
- &LastRecordedBlock
- );
+ BlockIo,
+ DiskIo,
+ &AnchorPoint,
+ &LastRecordedBlock
+ );
if (EFI_ERROR (Status)) {
return Status;
}
@@ -667,13 +706,13 @@ FindUdfFileSystem (
// Find Logical Volume location
//
Status = FindLogicalVolumeLocation (
- BlockIo,
- DiskIo,
- &AnchorPoint,
- LastRecordedBlock,
- (UINT64 *)StartingLBA,
- (UINT64 *)EndingLBA
- );
+ BlockIo,
+ DiskIo,
+ &AnchorPoint,
+ LastRecordedBlock,
+ (UINT64 *)StartingLBA,
+ (UINT64 *)EndingLBA
+ );
return Status;
}
@@ -714,7 +753,7 @@ PartitionInstallUdfChildHandles (
EFI_LBA EndingLBA;
BOOLEAN ChildCreated;
- Media = BlockIo->Media;
+ Media = BlockIo->Media;
ChildCreated = FALSE;
//
@@ -760,26 +799,26 @@ PartitionInstallUdfChildHandles (
//
ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
- PartitionInfo.Type = PARTITION_TYPE_OTHER;
+ PartitionInfo.Type = PARTITION_TYPE_OTHER;
//
// Install partition child handle for UDF file system
//
Status = PartitionInstallChildHandle (
- This,
- Handle,
- DiskIo,
- DiskIo2,
- BlockIo,
- BlockIo2,
- DevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath,
- &PartitionInfo,
- StartingLBA,
- EndingLBA,
- Media->BlockSize,
- NULL
- );
+ This,
+ Handle,
+ DiskIo,
+ DiskIo2,
+ BlockIo,
+ BlockIo2,
+ DevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)&gUdfDevicePath,
+ &PartitionInfo,
+ StartingLBA,
+ EndingLBA,
+ Media->BlockSize,
+ NULL
+ );
if (EFI_ERROR (Status)) {
return (ChildCreated ? EFI_SUCCESS : Status);
}