summaryrefslogtreecommitdiffstats
path: root/FatPkg/FatPei
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2021-12-05 14:53:58 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-07 17:24:28 +0000
commitbcdcc4160d7460c46c08c9395aae81be44ef23a9 (patch)
tree8e8607b86b86a1cebeaf6f614c43731a486b61a5 /FatPkg/FatPei
parenta550d468a6ca577d9e9c57a0eafcf2fc9fbb8c97 (diff)
downloadedk2-bcdcc4160d7460c46c08c9395aae81be44ef23a9.tar.gz
edk2-bcdcc4160d7460c46c08c9395aae81be44ef23a9.tar.bz2
edk2-bcdcc4160d7460c46c08c9395aae81be44ef23a9.zip
FatPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the FatPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
Diffstat (limited to 'FatPkg/FatPei')
-rw-r--r--FatPkg/FatPei/Eltorito.c166
-rw-r--r--FatPkg/FatPei/FatLiteAccess.c212
-rw-r--r--FatPkg/FatPei/FatLiteApi.c246
-rw-r--r--FatPkg/FatPei/FatLiteApi.h2
-rw-r--r--FatPkg/FatPei/FatLiteFmt.h176
-rw-r--r--FatPkg/FatPei/FatLiteLib.c119
-rw-r--r--FatPkg/FatPei/FatLitePeim.h193
-rw-r--r--FatPkg/FatPei/Gpt.c210
-rw-r--r--FatPkg/FatPei/Mbr.c79
-rw-r--r--FatPkg/FatPei/Part.c16
10 files changed, 699 insertions, 720 deletions
diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c
index 5fe0cb454e..d35768e6ef 100644
--- a/FatPkg/FatPei/Eltorito.c
+++ b/FatPkg/FatPei/Eltorito.c
@@ -25,33 +25,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
FatFindEltoritoPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
- EFI_STATUS Status;
- BOOLEAN Found;
- PEI_FAT_BLOCK_DEVICE *BlockDev;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- UINT32 VolDescriptorLba;
- UINT32 Lba;
- CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
- ELTORITO_CATALOG *Catalog;
- UINTN Check;
- UINTN Index;
- UINTN MaxIndex;
- UINT16 *CheckBuffer;
- UINT32 SubBlockSize;
- UINT32 SectorCount;
- UINT32 VolSpaceSize;
+ EFI_STATUS Status;
+ BOOLEAN Found;
+ PEI_FAT_BLOCK_DEVICE *BlockDev;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ UINT32 VolDescriptorLba;
+ UINT32 Lba;
+ CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
+ ELTORITO_CATALOG *Catalog;
+ UINTN Check;
+ UINTN Index;
+ UINTN MaxIndex;
+ UINT16 *CheckBuffer;
+ UINT32 SubBlockSize;
+ UINT32 SectorCount;
+ UINT32 VolSpaceSize;
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
return FALSE;
}
- Found = FALSE;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
- VolSpaceSize = 0;
+ Found = FALSE;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ VolSpaceSize = 0;
//
// CD_ROM has the fixed block size as 2048 bytes
@@ -60,8 +60,8 @@ FatFindEltoritoPartitions (
return FALSE;
}
- VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
- Catalog = (ELTORITO_CATALOG *) VolDescriptor;
+ VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *)PrivateData->BlockData;
+ Catalog = (ELTORITO_CATALOG *)VolDescriptor;
//
// the ISO-9660 volume descriptor starts at 32k on the media
@@ -74,7 +74,6 @@ FatFindEltoritoPartitions (
// Loop: handle one volume descriptor per time
//
while (TRUE) {
-
VolDescriptorLba += 1;
if (VolDescriptorLba > ParentBlockDev->LastBlock) {
//
@@ -84,32 +83,36 @@ FatFindEltoritoPartitions (
}
Status = FatReadBlock (
- PrivateData,
- ParentBlockDevNo,
- VolDescriptorLba,
- ParentBlockDev->BlockSize,
- VolDescriptor
- );
+ PrivateData,
+ ParentBlockDevNo,
+ VolDescriptorLba,
+ ParentBlockDev->BlockSize,
+ VolDescriptor
+ );
if (EFI_ERROR (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
//
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
}
+
//
// Is it an El Torito volume descriptor?
//
@@ -117,9 +120,11 @@ FatFindEltoritoPartitions (
VolDescriptor->BootRecordVolume.SystemId,
CDVOL_ELTORITO_ID,
sizeof (CDVOL_ELTORITO_ID) - 1
- ) != 0) {
+ ) != 0)
+ {
continue;
}
+
//
// Read in the boot El Torito boot catalog
//
@@ -129,25 +134,26 @@ FatFindEltoritoPartitions (
}
Status = FatReadBlock (
- PrivateData,
- ParentBlockDevNo,
- Lba,
- ParentBlockDev->BlockSize,
- Catalog
- );
+ PrivateData,
+ ParentBlockDevNo,
+ Lba,
+ ParentBlockDev->BlockSize,
+ Catalog
+ );
if (EFI_ERROR (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)) {
continue;
}
Check = 0;
- CheckBuffer = (UINT16 *) Catalog;
+ CheckBuffer = (UINT16 *)Catalog;
for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
Check += CheckBuffer[Index];
}
@@ -166,60 +172,59 @@ FatFindEltoritoPartitions (
//
// 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 = ParentBlockDev->BlockSize;
- SectorCount = Catalog->Boot.SectorCount;
- 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:
- SectorCount = 0;
- SubBlockSize = ParentBlockDev->BlockSize;
- break;
+ case ELTORITO_NO_EMULATION:
+ SubBlockSize = ParentBlockDev->BlockSize;
+ SectorCount = Catalog->Boot.SectorCount;
+ 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:
+ SectorCount = 0;
+ SubBlockSize = ParentBlockDev->BlockSize;
+ break;
}
if (SectorCount < 2) {
- SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32) (ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32) (VolSpaceSize - Catalog->Boot.Lba);
+ SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32)(ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32)(VolSpaceSize - Catalog->Boot.Lba);
}
+
//
// Register this partition
//
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
+ Found = TRUE;
- Found = TRUE;
-
- BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
+ BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
- BlockDev->BlockSize = SubBlockSize;
- BlockDev->LastBlock = SectorCount - 1;
- BlockDev->IoAlign = ParentBlockDev->IoAlign;
- BlockDev->Logical = TRUE;
- BlockDev->PartitionChecked = FALSE;
- BlockDev->StartingPos = MultU64x32 (Catalog->Boot.Lba, ParentBlockDev->BlockSize);
- BlockDev->ParentDevNo = ParentBlockDevNo;
+ BlockDev->BlockSize = SubBlockSize;
+ BlockDev->LastBlock = SectorCount - 1;
+ BlockDev->IoAlign = ParentBlockDev->IoAlign;
+ BlockDev->Logical = TRUE;
+ BlockDev->PartitionChecked = FALSE;
+ BlockDev->StartingPos = MultU64x32 (Catalog->Boot.Lba, ParentBlockDev->BlockSize);
+ BlockDev->ParentDevNo = ParentBlockDevNo;
PrivateData->BlockDeviceCount++;
}
@@ -229,5 +234,4 @@ FatFindEltoritoPartitions (
ParentBlockDev->PartitionChecked = TRUE;
return Found;
-
}
diff --git a/FatPkg/FatPei/FatLiteAccess.c b/FatPkg/FatPei/FatLiteAccess.c
index a3f846dda1..10df4516b2 100644
--- a/FatPkg/FatPei/FatLiteAccess.c
+++ b/FatPkg/FatPei/FatLiteAccess.c
@@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h"
-
/**
Check if there is a valid FAT in the corresponding Block device
of the volume and if yes, fill in the relevant fields for the
@@ -49,25 +48,25 @@ FatGetBpbInfo (
// Read in the BPB
//
Status = FatReadDisk (
- PrivateData,
- Volume->BlockDeviceNo,
- 0,
- sizeof (PEI_FAT_BOOT_SECTOR_EX),
- &BpbEx
- );
+ PrivateData,
+ Volume->BlockDeviceNo,
+ 0,
+ sizeof (PEI_FAT_BOOT_SECTOR_EX),
+ &BpbEx
+ );
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem (
- (UINT8 *) (&Bpb),
- (UINT8 *) (&BpbEx),
+ (UINT8 *)(&Bpb),
+ (UINT8 *)(&BpbEx),
sizeof (PEI_FAT_BOOT_SECTOR)
);
Volume->FatType = FatUnknown;
- Sectors = Bpb.Sectors;
+ Sectors = Bpb.Sectors;
if (Sectors == 0) {
Sectors = Bpb.LargeSectors;
}
@@ -77,60 +76,65 @@ FatGetBpbInfo (
SectorsPerFat = BpbEx.LargeSectorsPerFat;
Volume->FatType = Fat32;
}
+
//
// Filter out those not a FAT
//
- if (Bpb.Ia32Jump[0] != 0xe9 && Bpb.Ia32Jump[0] != 0xeb && Bpb.Ia32Jump[0] != 0x49) {
+ if ((Bpb.Ia32Jump[0] != 0xe9) && (Bpb.Ia32Jump[0] != 0xeb) && (Bpb.Ia32Jump[0] != 0x49)) {
return EFI_NOT_FOUND;
}
- if (Bpb.ReservedSectors == 0 || Bpb.NoFats == 0 || Sectors == 0) {
+ if ((Bpb.ReservedSectors == 0) || (Bpb.NoFats == 0) || (Sectors == 0)) {
return EFI_NOT_FOUND;
}
- if (Bpb.SectorsPerCluster != 1 &&
- Bpb.SectorsPerCluster != 2 &&
- Bpb.SectorsPerCluster != 4 &&
- Bpb.SectorsPerCluster != 8 &&
- Bpb.SectorsPerCluster != 16 &&
- Bpb.SectorsPerCluster != 32 &&
- Bpb.SectorsPerCluster != 64 &&
- Bpb.SectorsPerCluster != 128
- ) {
+ if ((Bpb.SectorsPerCluster != 1) &&
+ (Bpb.SectorsPerCluster != 2) &&
+ (Bpb.SectorsPerCluster != 4) &&
+ (Bpb.SectorsPerCluster != 8) &&
+ (Bpb.SectorsPerCluster != 16) &&
+ (Bpb.SectorsPerCluster != 32) &&
+ (Bpb.SectorsPerCluster != 64) &&
+ (Bpb.SectorsPerCluster != 128)
+ )
+ {
return EFI_NOT_FOUND;
}
- if (Volume->FatType == Fat32 && (SectorsPerFat == 0 || BpbEx.FsVersion != 0)) {
+ if ((Volume->FatType == Fat32) && ((SectorsPerFat == 0) || (BpbEx.FsVersion != 0))) {
return EFI_NOT_FOUND;
}
- if (Bpb.Media != 0xf0 &&
- Bpb.Media != 0xf8 &&
- Bpb.Media != 0xf9 &&
- Bpb.Media != 0xfb &&
- Bpb.Media != 0xfc &&
- Bpb.Media != 0xfd &&
- Bpb.Media != 0xfe &&
- Bpb.Media != 0xff &&
+ if ((Bpb.Media != 0xf0) &&
+ (Bpb.Media != 0xf8) &&
+ (Bpb.Media != 0xf9) &&
+ (Bpb.Media != 0xfb) &&
+ (Bpb.Media != 0xfc) &&
+ (Bpb.Media != 0xfd) &&
+ (Bpb.Media != 0xfe) &&
+ (Bpb.Media != 0xff) &&
//
// FujitsuFMR
//
- Bpb.Media != 0x00 &&
- Bpb.Media != 0x01 &&
- Bpb.Media != 0xfa
- ) {
+ (Bpb.Media != 0x00) &&
+ (Bpb.Media != 0x01) &&
+ (Bpb.Media != 0xfa)
+ )
+ {
return EFI_NOT_FOUND;
}
- if (Volume->FatType != Fat32 && Bpb.RootEntries == 0) {
+ if ((Volume->FatType != Fat32) && (Bpb.RootEntries == 0)) {
return EFI_NOT_FOUND;
}
+
//
// If this is fat32, refuse to mount mirror-disabled volumes
//
- if (Volume->FatType == Fat32 && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
+ if ((Volume->FatType == Fat32) && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
return EFI_NOT_FOUND;
}
+
//
// Fill in the volume structure fields
// (Sectors & SectorsPerFat is computed earlier already)
@@ -141,22 +145,21 @@ FatGetBpbInfo (
RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (Volume->SectorSize - 1)) / Volume->SectorSize;
- FatLba = Bpb.ReservedSectors;
- RootLba = Bpb.NoFats * SectorsPerFat + FatLba;
- FirstClusterLba = RootLba + RootDirSectors;
+ FatLba = Bpb.ReservedSectors;
+ RootLba = Bpb.NoFats * SectorsPerFat + FatLba;
+ FirstClusterLba = RootLba + RootDirSectors;
Volume->VolumeSize = MultU64x32 (Sectors, Volume->SectorSize);
Volume->FatPos = MultU64x32 (FatLba, Volume->SectorSize);
Volume->RootDirPos = MultU64x32 (RootLba, Volume->SectorSize);
Volume->FirstClusterPos = MultU64x32 (FirstClusterLba, Volume->SectorSize);
- Volume->MaxCluster = (UINT32) (Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;
+ Volume->MaxCluster = (UINT32)(Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;
Volume->RootDirCluster = BpbEx.RootDirFirstCluster;
//
// If this is not a fat32, determine if it's a fat16 or fat12
//
if (Volume->FatType != Fat32) {
-
if (Volume->MaxCluster >= 65525) {
return EFI_NOT_FOUND;
}
@@ -167,7 +170,6 @@ FatGetBpbInfo (
return EFI_SUCCESS;
}
-
/**
Gets the next cluster in the cluster chain
@@ -198,7 +200,7 @@ FatGetNextCluster (
if (Volume->FatType == Fat32) {
FatEntryPos = Volume->FatPos + MultU64x32 (4, Cluster);
- Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);
+ Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);
*NextCluster &= 0x0fffffff;
//
@@ -207,11 +209,10 @@ FatGetNextCluster (
if ((*NextCluster) >= 0x0ffffff7) {
*NextCluster |= (-1 &~0xf);
}
-
} else if (Volume->FatType == Fat16) {
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
- Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
+ Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
//
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
@@ -219,17 +220,17 @@ FatGetNextCluster (
if ((*NextCluster) >= 0xfff7) {
*NextCluster |= (-1 &~0xf);
}
-
} else {
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
- Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
+ Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
if ((Cluster & 0x01) != 0) {
*NextCluster = (*NextCluster) >> 4;
} else {
*NextCluster = (*NextCluster) & 0x0fff;
}
+
//
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
//
@@ -243,10 +244,8 @@ FatGetNextCluster (
}
return EFI_SUCCESS;
-
}
-
/**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@@ -274,31 +273,29 @@ FatSetFilePos (
UINT32 PrevCluster;
if (File->IsFixedRootDir) {
-
if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {
return EFI_INVALID_PARAMETER;
}
- File->CurrentPos += Pos;
- File->StraightReadAmount = (UINT32) (MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
-
+ File->CurrentPos += Pos;
+ File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
} else {
-
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
- AlignedPos = (UINT32) File->CurrentPos - (UINT32) Offset;
+ AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;
while
(
- !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
- AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
- ) {
+ !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
+ AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
+ )
+ {
AlignedPos += File->Volume->ClusterSize;
- Status = FatGetNextCluster (
- PrivateData,
- File->Volume,
- File->CurrentCluster,
- &File->CurrentCluster
- );
+ Status = FatGetNextCluster (
+ PrivateData,
+ File->Volume,
+ File->CurrentCluster,
+ &File->CurrentCluster
+ );
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -313,12 +310,12 @@ FatSetFilePos (
// Calculate the amount of consecutive cluster occupied by the file.
// FatReadFile() will use it to read these blocks once.
//
- File->StraightReadAmount = 0;
- Cluster = File->CurrentCluster;
+ File->StraightReadAmount = 0;
+ Cluster = File->CurrentCluster;
while (!FAT_CLUSTER_FUNCTIONAL (Cluster)) {
File->StraightReadAmount += File->Volume->ClusterSize;
- PrevCluster = Cluster;
- Status = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);
+ PrevCluster = Cluster;
+ Status = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -329,14 +326,12 @@ FatSetFilePos (
}
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
- File->StraightReadAmount -= (UINT32) Offset;
-
+ File->StraightReadAmount -= (UINT32)Offset;
}
return EFI_SUCCESS;
}
-
/**
Reads file data. Updates the file's CurrentPos.
@@ -375,53 +370,52 @@ FatReadFile (
}
Status = FatReadDisk (
- PrivateData,
- File->Volume->BlockDeviceNo,
- File->Volume->RootDirPos + File->CurrentPos,
- Size,
- Buffer
- );
- File->CurrentPos += (UINT32) Size;
+ PrivateData,
+ File->Volume->BlockDeviceNo,
+ File->Volume->RootDirPos + File->CurrentPos,
+ Size,
+ Buffer
+ );
+ File->CurrentPos += (UINT32)Size;
return Status;
-
} else {
-
if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
}
+
//
// This is a normal cluster based file
//
while (Size != 0) {
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
- PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);
+ PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);
- Amount = File->StraightReadAmount;
- Amount = Size > Amount ? Amount : Size;
+ Amount = File->StraightReadAmount;
+ Amount = Size > Amount ? Amount : Size;
Status = FatReadDisk (
- PrivateData,
- File->Volume->BlockDeviceNo,
- PhysicalAddr + Offset,
- Amount,
- BufferPtr
- );
+ PrivateData,
+ File->Volume->BlockDeviceNo,
+ PhysicalAddr + Offset,
+ Amount,
+ BufferPtr
+ );
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// Advance the file's current pos and current cluster
//
- FatSetFilePos (PrivateData, File, (UINT32) Amount);
+ FatSetFilePos (PrivateData, File, (UINT32)Amount);
BufferPtr += Amount;
- Size -= Amount;
+ Size -= Amount;
}
return EFI_SUCCESS;
}
}
-
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@@ -446,13 +440,13 @@ FatReadNextDirectoryEntry (
OUT PEI_FAT_FILE *SubFile
)
{
- EFI_STATUS Status;
- FAT_DIRECTORY_ENTRY DirEntry;
- CHAR16 *Pos;
- CHAR16 BaseName[9];
- CHAR16 Ext[4];
+ EFI_STATUS Status;
+ FAT_DIRECTORY_ENTRY DirEntry;
+ CHAR16 *Pos;
+ CHAR16 BaseName[9];
+ CHAR16 Ext[4];
- ZeroMem ((UINT8 *) SubFile, sizeof (PEI_FAT_FILE));
+ ZeroMem ((UINT8 *)SubFile, sizeof (PEI_FAT_FILE));
//
// Pick a valid directory entry
@@ -465,6 +459,7 @@ FatReadNextDirectoryEntry (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// We only search for *FILE* in root directory
// Long file name entry is *NOT* supported
@@ -472,35 +467,38 @@ FatReadNextDirectoryEntry (
if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {
continue;
}
+
//
// if this is a terminator dir entry, just return EFI_NOT_FOUND
//
if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {
return EFI_NOT_FOUND;
}
+
//
// If this not an invalid entry neither an empty entry, this is what we want.
// otherwise we will start a new loop to continue to find something meaningful
//
- if ((UINT8) DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
+ if ((UINT8)DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
break;
}
}
+
//
// fill in the output parameter
//
EngFatToStr (8, DirEntry.FileName, BaseName);
EngFatToStr (3, DirEntry.FileName + 8, Ext);
- Pos = (UINT16 *) SubFile->FileName;
- SetMem ((UINT8 *) Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
- CopyMem ((UINT8 *) Pos, (UINT8 *) BaseName, 2 * (StrLen (BaseName) + 1));
+ Pos = (UINT16 *)SubFile->FileName;
+ SetMem ((UINT8 *)Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
+ CopyMem ((UINT8 *)Pos, (UINT8 *)BaseName, 2 * (StrLen (BaseName) + 1));
if (Ext[0] != 0) {
Pos += StrLen (BaseName);
*Pos = '.';
Pos++;
- CopyMem ((UINT8 *) Pos, (UINT8 *) Ext, 2 * (StrLen (Ext) + 1));
+ CopyMem ((UINT8 *)Pos, (UINT8 *)Ext, 2 * (StrLen (Ext) + 1));
}
SubFile->Attributes = DirEntry.Attributes;
@@ -509,10 +507,10 @@ FatReadNextDirectoryEntry (
SubFile->CurrentCluster |= DirEntry.FileClusterHigh << 16;
}
- SubFile->CurrentPos = 0;
- SubFile->FileSize = DirEntry.FileSize;
- SubFile->StartingCluster = SubFile->CurrentCluster;
- SubFile->Volume = ParentDir->Volume;
+ SubFile->CurrentPos = 0;
+ SubFile->FileSize = DirEntry.FileSize;
+ SubFile->StartingCluster = SubFile->CurrentCluster;
+ SubFile->Volume = ParentDir->Volume;
//
// in Pei phase, time parameters do not need to be filled for minimum use.
diff --git a/FatPkg/FatPei/FatLiteApi.c b/FatPkg/FatPei/FatLiteApi.c
index d07422ba93..cc48c4c66b 100644
--- a/FatPkg/FatPei/FatLiteApi.c
+++ b/FatPkg/FatPei/FatLiteApi.c
@@ -33,7 +33,6 @@ BlockIoNotifyEntry (
IN VOID *Ppi
);
-
/**
Discover all the block I/O devices to find the FAT volume.
@@ -46,23 +45,23 @@ BlockIoNotifyEntry (
**/
EFI_STATUS
UpdateBlocksAndVolumes (
- IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
- IN BOOLEAN BlockIo2
+ IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN BOOLEAN BlockIo2
)
{
- EFI_STATUS Status;
- EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
- UINTN BlockIoPpiInstance;
- EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
- EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
- UINTN NumberBlockDevices;
- UINTN Index;
- EFI_PEI_BLOCK_IO_MEDIA Media;
- EFI_PEI_BLOCK_IO2_MEDIA Media2;
- PEI_FAT_VOLUME Volume;
- EFI_PEI_SERVICES **PeiServices;
-
- PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
+ UINTN BlockIoPpiInstance;
+ EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
+ EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
+ UINTN NumberBlockDevices;
+ UINTN Index;
+ EFI_PEI_BLOCK_IO_MEDIA Media;
+ EFI_PEI_BLOCK_IO2_MEDIA Media2;
+ PEI_FAT_VOLUME Volume;
+ EFI_PEI_SERVICES **PeiServices;
+
+ PeiServices = (EFI_PEI_SERVICES **)GetPeiServicesTablePointer ();
BlockIo2Ppi = NULL;
BlockIoPpi = NULL;
//
@@ -81,19 +80,20 @@ UpdateBlocksAndVolumes (
for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_FAT_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
if (BlockIo2) {
Status = PeiServicesLocatePpi (
- &gEfiPeiVirtualBlockIo2PpiGuid,
- BlockIoPpiInstance,
- &TempPpiDescriptor,
- (VOID **) &BlockIo2Ppi
- );
+ &gEfiPeiVirtualBlockIo2PpiGuid,
+ BlockIoPpiInstance,
+ &TempPpiDescriptor,
+ (VOID **)&BlockIo2Ppi
+ );
} else {
Status = PeiServicesLocatePpi (
- &gEfiPeiVirtualBlockIoPpiGuid,
- BlockIoPpiInstance,
- &TempPpiDescriptor,
- (VOID **) &BlockIoPpi
- );
+ &gEfiPeiVirtualBlockIoPpiGuid,
+ BlockIoPpiInstance,
+ &TempPpiDescriptor,
+ (VOID **)&BlockIoPpi
+ );
}
+
if (EFI_ERROR (Status)) {
//
// Done with all Block Io Ppis
@@ -114,12 +114,12 @@ UpdateBlocksAndVolumes (
&NumberBlockDevices
);
}
+
if (EFI_ERROR (Status)) {
continue;
}
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
-
if (BlockIo2) {
Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
PeiServices,
@@ -130,10 +130,11 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media2.MediaPresent) {
continue;
}
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
+
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
} else {
Status = BlockIoPpi->GetBlockDeviceMediaInfo (
PeiServices,
@@ -144,23 +145,25 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media.MediaPresent) {
continue;
}
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
+
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32)Media.BlockSize;
}
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
//
// Not used here
//
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8) Index;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8)Index;
PrivateData->BlockDeviceCount++;
}
}
+
//
// Find out all logical devices
//
@@ -171,15 +174,15 @@ UpdateBlocksAndVolumes (
//
PrivateData->VolumeCount = 0;
for (Index = 0; Index < PrivateData->BlockDeviceCount; Index++) {
- Volume.BlockDeviceNo = Index;
- Status = FatGetBpbInfo (PrivateData, &Volume);
+ Volume.BlockDeviceNo = Index;
+ Status = FatGetBpbInfo (PrivateData, &Volume);
if (Status == EFI_SUCCESS) {
//
// Add the detected volume to the volume array
//
CopyMem (
- (UINT8 *) &(PrivateData->Volume[PrivateData->VolumeCount]),
- (UINT8 *) &Volume,
+ (UINT8 *)&(PrivateData->Volume[PrivateData->VolumeCount]),
+ (UINT8 *)&Volume,
sizeof (PEI_FAT_VOLUME)
);
PrivateData->VolumeCount += 1;
@@ -192,7 +195,6 @@ UpdateBlocksAndVolumes (
return EFI_SUCCESS;
}
-
/**
BlockIo installation notification function. Find out all the current BlockIO
PPIs in the system and add them into private data. Assume there is
@@ -220,10 +222,10 @@ BlockIoNotifyEntry (
} else {
UpdateBlocksAndVolumes (mPrivateData, FALSE);
}
+
return EFI_SUCCESS;
}
-
/**
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
installation notification
@@ -241,8 +243,8 @@ BlockIoNotifyEntry (
EFI_STATUS
EFIAPI
FatPeimEntry (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
@@ -255,38 +257,39 @@ FatPeimEntry (
}
Status = PeiServicesAllocatePages (
- EfiBootServicesCode,
- (sizeof (PEI_FAT_PRIVATE_DATA) - 1) / PEI_FAT_MEMORY_PAGE_SIZE + 1,
- &Address
- );
+ EfiBootServicesCode,
+ (sizeof (PEI_FAT_PRIVATE_DATA) - 1) / PEI_FAT_MEMORY_PAGE_SIZE + 1,
+ &Address
+ );
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
- PrivateData = (PEI_FAT_PRIVATE_DATA *) (UINTN) Address;
+ PrivateData = (PEI_FAT_PRIVATE_DATA *)(UINTN)Address;
//
// Initialize Private Data (to zero, as is required by subsequent operations)
//
- ZeroMem ((UINT8 *) PrivateData, sizeof (PEI_FAT_PRIVATE_DATA));
+ ZeroMem ((UINT8 *)PrivateData, sizeof (PEI_FAT_PRIVATE_DATA));
PrivateData->Signature = PEI_FAT_PRIVATE_DATA_SIGNATURE;
//
// Installs Ppi
//
- PrivateData->DeviceRecoveryPpi.GetNumberRecoveryCapsules = GetNumberRecoveryCapsules;
- PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo = GetRecoveryCapsuleInfo;
- PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule = LoadRecoveryCapsule;
+ PrivateData->DeviceRecoveryPpi.GetNumberRecoveryCapsules = GetNumberRecoveryCapsules;
+ PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo = GetRecoveryCapsuleInfo;
+ PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule = LoadRecoveryCapsule;
- PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
- PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
- PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
+ PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
+ PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
+ PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
Status = PeiServicesInstallPpi (&PrivateData->PpiDescriptor);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// Other initializations
//
@@ -305,21 +308,20 @@ FatPeimEntry (
//
PrivateData->NotifyDescriptor[0].Flags =
(
- EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
+ EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
);
- PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
- PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
+ PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
+ PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
PrivateData->NotifyDescriptor[1].Flags =
(
- EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
- EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
+ EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
+ EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
- PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
- PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
+ PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
+ PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
}
-
/**
Returns the number of DXE capsules residing on the device.
@@ -346,9 +348,9 @@ FatPeimEntry (
EFI_STATUS
EFIAPI
GetNumberRecoveryCapsules (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- OUT UINTN *NumberRecoveryCapsules
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ OUT UINTN *NumberRecoveryCapsules
)
{
EFI_STATUS Status;
@@ -364,7 +366,7 @@ GetNumberRecoveryCapsules (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
@@ -381,7 +383,6 @@ GetNumberRecoveryCapsules (
return EFI_SUCCESS;
}
-
/**
Returns the size and type of the requested recovery capsule.
@@ -410,11 +411,11 @@ GetNumberRecoveryCapsules (
EFI_STATUS
EFIAPI
GetRecoveryCapsuleInfo (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT UINTN *Size,
- OUT EFI_GUID *CapsuleType
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT UINTN *Size,
+ OUT EFI_GUID *CapsuleType
)
{
EFI_STATUS Status;
@@ -442,7 +443,7 @@ GetRecoveryCapsuleInfo (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
@@ -452,7 +453,7 @@ GetRecoveryCapsuleInfo (
//
// Get file size
//
- *Size = (UINTN) (((PEI_FAT_FILE *) Handle)->FileSize);
+ *Size = (UINTN)(((PEI_FAT_FILE *)Handle)->FileSize);
//
// Find corresponding physical block device
@@ -461,45 +462,47 @@ GetRecoveryCapsuleInfo (
while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) {
BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo;
}
+
//
// Fill in the Capsule Type GUID according to the block device type
//
if (BlockDeviceNo < PrivateData->BlockDeviceCount) {
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo2 != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].InterfaceType) {
- case MSG_ATAPI_DP:
- CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
- break;
+ case MSG_ATAPI_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
+ break;
- case MSG_USB_DP:
- CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
- break;
+ case MSG_USB_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
+ break;
- case MSG_NVME_NAMESPACE_DP:
- CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
- break;
+ case MSG_NVME_NAMESPACE_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
+ break;
- default:
- break;
+ default:
+ break;
}
}
+
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
- case LegacyFloppy:
- CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
- break;
+ case LegacyFloppy:
+ CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
+ break;
- case IdeCDROM:
- case IdeLS120:
- CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
- break;
+ case IdeCDROM:
+ case IdeLS120:
+ CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
+ break;
- case UsbMassStorage:
- CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
- break;
+ case UsbMassStorage:
+ CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
+ break;
- default:
- break;
+ default:
+ break;
}
}
}
@@ -513,7 +516,6 @@ GetRecoveryCapsuleInfo (
return EFI_NOT_FOUND;
}
-
/**
Loads a DXE capsule from some media into memory.
@@ -536,10 +538,10 @@ GetRecoveryCapsuleInfo (
EFI_STATUS
EFIAPI
LoadRecoveryCapsule (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT VOID *Buffer
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -566,19 +568,18 @@ LoadRecoveryCapsule (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
-
Status = FatReadFile (
- PrivateData,
- Handle,
- (UINTN) (((PEI_FAT_FILE *) Handle)->FileSize),
- Buffer
- );
+ PrivateData,
+ Handle,
+ (UINTN)(((PEI_FAT_FILE *)Handle)->FileSize),
+ Buffer
+ );
return Status;
}
@@ -588,7 +589,6 @@ LoadRecoveryCapsule (
return EFI_NOT_FOUND;
}
-
/**
Finds the recovery file on a FAT volume.
This function finds the recovery file named FileName on a specified FAT volume and returns
@@ -631,17 +631,18 @@ FindRecoveryFile (
// Construct root directory file
//
ZeroMem (&Parent, sizeof (PEI_FAT_FILE));
- Parent.IsFixedRootDir = (BOOLEAN) ((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
- Parent.Attributes = FAT_ATTR_DIRECTORY;
- Parent.CurrentPos = 0;
- Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
- Parent.StartingCluster = Parent.CurrentCluster;
- Parent.Volume = &PrivateData->Volume[VolumeIndex];
-
- Status = FatSetFilePos (PrivateData, &Parent, 0);
+ Parent.IsFixedRootDir = (BOOLEAN)((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
+ Parent.Attributes = FAT_ATTR_DIRECTORY;
+ Parent.CurrentPos = 0;
+ Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
+ Parent.StartingCluster = Parent.CurrentCluster;
+ Parent.Volume = &PrivateData->Volume[VolumeIndex];
+
+ Status = FatSetFilePos (PrivateData, &Parent, 0);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// Search for recovery capsule in root directory
//
@@ -671,5 +672,4 @@ FindRecoveryFile (
*Handle = File;
return EFI_SUCCESS;
-
}
diff --git a/FatPkg/FatPei/FatLiteApi.h b/FatPkg/FatPei/FatLiteApi.h
index 2d03fe17e2..a9025633a0 100644
--- a/FatPkg/FatPei/FatLiteApi.h
+++ b/FatPkg/FatPei/FatLiteApi.h
@@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// API data structures
//
-typedef VOID *PEI_FILE_HANDLE;
+typedef VOID *PEI_FILE_HANDLE;
typedef enum {
Fat12,
diff --git a/FatPkg/FatPei/FatLiteFmt.h b/FatPkg/FatPei/FatLiteFmt.h
index 876874d6b3..fef70fe1de 100644
--- a/FatPkg/FatPei/FatLiteFmt.h
+++ b/FatPkg/FatPei/FatLiteFmt.h
@@ -13,25 +13,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Definitions
//
-#define FAT_ATTR_READ_ONLY 0x01
-#define FAT_ATTR_HIDDEN 0x02
-#define FAT_ATTR_SYSTEM 0x04
-#define FAT_ATTR_VOLUME_ID 0x08
-#define FAT_ATTR_DIRECTORY 0x10
-#define FAT_ATTR_ARCHIVE 0x20
-#define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
-
-#define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
-#define FAT_CLUSTER_FREE 0
-#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
-#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
-#define FAT_CLUSTER_LAST (-1)
-
-#define DELETE_ENTRY_MARK 0xE5
-#define EMPTY_ENTRY_MARK 0x00
-
-#define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
-#define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
+#define FAT_ATTR_READ_ONLY 0x01
+#define FAT_ATTR_HIDDEN 0x02
+#define FAT_ATTR_SYSTEM 0x04
+#define FAT_ATTR_VOLUME_ID 0x08
+#define FAT_ATTR_DIRECTORY 0x10
+#define FAT_ATTR_ARCHIVE 0x20
+#define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
+
+#define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
+#define FAT_CLUSTER_FREE 0
+#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
+#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
+#define FAT_CLUSTER_LAST (-1)
+
+#define DELETE_ENTRY_MARK 0xE5
+#define EMPTY_ENTRY_MARK 0x00
+
+#define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
+#define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
//
// Directory Entry
@@ -39,33 +39,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#pragma pack(1)
typedef struct {
- UINT16 Day : 5;
- UINT16 Month : 4;
- UINT16 Year : 7; // From 1980
+ UINT16 Day : 5;
+ UINT16 Month : 4;
+ UINT16 Year : 7; // From 1980
} FAT_DATE;
typedef struct {
- UINT16 DoubleSecond : 5;
- UINT16 Minute : 6;
- UINT16 Hour : 5;
+ UINT16 DoubleSecond : 5;
+ UINT16 Minute : 6;
+ UINT16 Hour : 5;
} FAT_TIME;
typedef struct {
- FAT_TIME Time;
- FAT_DATE Date;
+ FAT_TIME Time;
+ FAT_DATE Date;
} FAT_DATE_TIME;
typedef struct {
- CHAR8 FileName[11]; // 8.3 filename
- UINT8 Attributes;
- UINT8 CaseFlag;
- UINT8 CreateMillisecond; // (creation milliseconds - ignored)
- FAT_DATE_TIME FileCreateTime;
- FAT_DATE FileLastAccess;
- UINT16 FileClusterHigh; // >= FAT32
- FAT_DATE_TIME FileModificationTime;
- UINT16 FileCluster;
- UINT32 FileSize;
+ CHAR8 FileName[11]; // 8.3 filename
+ UINT8 Attributes;
+ UINT8 CaseFlag;
+ UINT8 CreateMillisecond; // (creation milliseconds - ignored)
+ FAT_DATE_TIME FileCreateTime;
+ FAT_DATE FileLastAccess;
+ UINT16 FileClusterHigh; // >= FAT32
+ FAT_DATE_TIME FileModificationTime;
+ UINT16 FileCluster;
+ UINT32 FileSize;
} FAT_DIRECTORY_ENTRY;
#pragma pack()
@@ -75,62 +75,58 @@ typedef struct {
#pragma pack(1)
typedef struct {
-
- UINT8 Ia32Jump[3];
- CHAR8 OemId[8];
-
- UINT16 SectorSize;
- UINT8 SectorsPerCluster;
- UINT16 ReservedSectors;
- UINT8 NoFats;
- UINT16 RootEntries; // < FAT32, root dir is fixed size
- UINT16 Sectors;
- UINT8 Media; // (ignored)
- UINT16 SectorsPerFat; // < FAT32
- UINT16 SectorsPerTrack; // (ignored)
- UINT16 Heads; // (ignored)
- UINT32 HiddenSectors; // (ignored)
- UINT32 LargeSectors; // => FAT32
- UINT8 PhysicalDriveNumber; // (ignored)
- UINT8 CurrentHead; // holds boot_sector_dirty bit
- UINT8 Signature; // (ignored)
- CHAR8 Id[4];
- CHAR8 FatLabel[11];
- CHAR8 SystemId[8];
-
+ UINT8 Ia32Jump[3];
+ CHAR8 OemId[8];
+
+ UINT16 SectorSize;
+ UINT8 SectorsPerCluster;
+ UINT16 ReservedSectors;
+ UINT8 NoFats;
+ UINT16 RootEntries; // < FAT32, root dir is fixed size
+ UINT16 Sectors;
+ UINT8 Media; // (ignored)
+ UINT16 SectorsPerFat; // < FAT32
+ UINT16 SectorsPerTrack; // (ignored)
+ UINT16 Heads; // (ignored)
+ UINT32 HiddenSectors; // (ignored)
+ UINT32 LargeSectors; // => FAT32
+ UINT8 PhysicalDriveNumber; // (ignored)
+ UINT8 CurrentHead; // holds boot_sector_dirty bit
+ UINT8 Signature; // (ignored)
+ CHAR8 Id[4];
+ CHAR8 FatLabel[11];
+ CHAR8 SystemId[8];
} PEI_FAT_BOOT_SECTOR;
typedef struct {
-
- UINT8 Ia32Jump[3];
- CHAR8 OemId[8];
-
- UINT16 SectorSize;
- UINT8 SectorsPerCluster;
- UINT16 ReservedSectors;
- UINT8 NoFats;
- UINT16 RootEntries; // < FAT32, root dir is fixed size
- UINT16 Sectors;
- UINT8 Media; // (ignored)
- UINT16 SectorsPerFat; // < FAT32
- UINT16 SectorsPerTrack; // (ignored)
- UINT16 Heads; // (ignored)
- UINT32 HiddenSectors; // (ignored)
- UINT32 LargeSectors; // Used if Sectors==0
- UINT32 LargeSectorsPerFat; // FAT32
- UINT16 ExtendedFlags; // FAT32 (ignored)
- UINT16 FsVersion; // FAT32 (ignored)
- UINT32 RootDirFirstCluster; // FAT32
- UINT16 FsInfoSector; // FAT32
- UINT16 BackupBootSector; // FAT32
- UINT8 Reserved[12]; // FAT32 (ignored)
- UINT8 PhysicalDriveNumber; // (ignored)
- UINT8 CurrentHead; // holds boot_sector_dirty bit
- UINT8 Signature; // (ignored)
- CHAR8 Id[4];
- CHAR8 FatLabel[11];
- CHAR8 SystemId[8];
-
+ UINT8 Ia32Jump[3];
+ CHAR8 OemId[8];
+
+ UINT16 SectorSize;
+ UINT8 SectorsPerCluster;
+ UINT16 ReservedSectors;
+ UINT8 NoFats;
+ UINT16 RootEntries; // < FAT32, root dir is fixed size
+ UINT16 Sectors;
+ UINT8 Media; // (ignored)
+ UINT16 SectorsPerFat; // < FAT32
+ UINT16 SectorsPerTrack; // (ignored)
+ UINT16 Heads; // (ignored)
+ UINT32 HiddenSectors; // (ignored)
+ UINT32 LargeSectors; // Used if Sectors==0
+ UINT32 LargeSectorsPerFat; // FAT32
+ UINT16 ExtendedFlags; // FAT32 (ignored)
+ UINT16 FsVersion; // FAT32 (ignored)
+ UINT32 RootDirFirstCluster; // FAT32
+ UINT16 FsInfoSector; // FAT32
+ UINT16 BackupBootSector; // FAT32
+ UINT8 Reserved[12]; // FAT32 (ignored)
+ UINT8 PhysicalDriveNumber; // (ignored)
+ UINT8 CurrentHead; // holds boot_sector_dirty bit
+ UINT8 Signature; // (ignored)
+ CHAR8 Id[4];
+ CHAR8 FatLabel[11];
+ CHAR8 SystemId[8];
} PEI_FAT_BOOT_SECTOR_EX;
#pragma pack()
diff --git a/FatPkg/FatPei/FatLiteLib.c b/FatPkg/FatPei/FatLiteLib.c
index 3d43e0b877..ef71fe907e 100644
--- a/FatPkg/FatPei/FatLiteLib.c
+++ b/FatPkg/FatPei/FatLiteLib.c
@@ -9,10 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h"
-
#define CHAR_FAT_VALID 0x01
-
/**
Converts a union code character to upper case.
This functions converts a unicode character to upper case.
@@ -26,17 +24,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
CHAR16
ToUpper (
- IN CHAR16 Letter
+ IN CHAR16 Letter
)
{
- if ('a' <= Letter && Letter <= 'z') {
- Letter = (CHAR16) (Letter - 0x20);
+ if (('a' <= Letter) && (Letter <= 'z')) {
+ Letter = (CHAR16)(Letter - 0x20);
}
return Letter;
}
-
/**
Reads a block of data from the block device by calling
underlying Block I/O service.
@@ -55,11 +52,11 @@ ToUpper (
**/
EFI_STATUS
FatReadBlock (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN BlockDeviceNo,
- IN EFI_PEI_LBA Lba,
- IN UINTN BufferSize,
- OUT VOID *Buffer
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN BlockDeviceNo,
+ IN EFI_PEI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -69,8 +66,8 @@ FatReadBlock (
return EFI_DEVICE_ERROR;
}
- Status = EFI_SUCCESS;
- BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);
+ Status = EFI_SUCCESS;
+ BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);
if (BufferSize > MultU64x32 (BlockDev->LastBlock - Lba + 1, BlockDev->BlockSize)) {
return EFI_DEVICE_ERROR;
@@ -83,38 +80,36 @@ FatReadBlock (
//
if (BlockDev->BlockIo2 != NULL) {
Status = BlockDev->BlockIo2->ReadBlocks (
- (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
- BlockDev->BlockIo2,
+ (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
+ BlockDev->BlockIo2,
+ BlockDev->PhysicalDevNo,
+ Lba,
+ BufferSize,
+ Buffer
+ );
+ } else {
+ Status = BlockDev->BlockIo->ReadBlocks (
+ (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
+ BlockDev->BlockIo,
BlockDev->PhysicalDevNo,
Lba,
BufferSize,
Buffer
);
- } else {
- Status = BlockDev->BlockIo->ReadBlocks (
- (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
- BlockDev->BlockIo,
- BlockDev->PhysicalDevNo,
- Lba,
- BufferSize,
- Buffer
- );
}
-
} else {
Status = FatReadDisk (
- PrivateData,
- BlockDev->ParentDevNo,
- BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),
- BufferSize,
- Buffer
- );
+ PrivateData,
+ BlockDev->ParentDevNo,
+ BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),
+ BufferSize,
+ Buffer
+ );
}
return Status;
}
-
/**
Find a cache block designated to specific Block device and Lba.
If not found, invalidate an oldest one and use it. (LRU cache)
@@ -150,15 +145,16 @@ FatGetCacheBlock (
//
for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
- if (CacheBuffer->Valid && CacheBuffer->BlockDeviceNo == BlockDeviceNo && CacheBuffer->Lba == Lba) {
+ if (CacheBuffer->Valid && (CacheBuffer->BlockDeviceNo == BlockDeviceNo) && (CacheBuffer->Lba == Lba)) {
break;
}
}
if (Index < PEI_FAT_CACHE_SIZE) {
- *CachePtr = (CHAR8 *) CacheBuffer->Buffer;
+ *CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return EFI_SUCCESS;
}
+
//
// We have to find an invalid cache buffer
//
@@ -167,6 +163,7 @@ FatGetCacheBlock (
break;
}
}
+
//
// Use the cache buffer
//
@@ -181,33 +178,32 @@ FatGetCacheBlock (
return EFI_DEVICE_ERROR;
}
- CacheBuffer = &(PrivateData->CacheBuffer[Index]);
+ CacheBuffer = &(PrivateData->CacheBuffer[Index]);
- CacheBuffer->BlockDeviceNo = BlockDeviceNo;
- CacheBuffer->Lba = Lba;
- CacheBuffer->Size = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;
+ CacheBuffer->BlockDeviceNo = BlockDeviceNo;
+ CacheBuffer->Lba = Lba;
+ CacheBuffer->Size = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;
//
// Read in the data
//
Status = FatReadBlock (
- PrivateData,
- BlockDeviceNo,
- Lba,
- CacheBuffer->Size,
- CacheBuffer->Buffer
- );
+ PrivateData,
+ BlockDeviceNo,
+ Lba,
+ CacheBuffer->Size,
+ CacheBuffer->Buffer
+ );
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
- CacheBuffer->Valid = TRUE;
- *CachePtr = (CHAR8 *) CacheBuffer->Buffer;
+ CacheBuffer->Valid = TRUE;
+ *CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return Status;
}
-
/**
Disk reading.
@@ -246,8 +242,8 @@ FatReadDisk (
//
// Read underrun
//
- Lba = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);
- Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);
+ Lba = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);
+ Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -259,17 +255,17 @@ FatReadDisk (
return EFI_SUCCESS;
}
- Size -= Amount;
- BufferPtr += Amount;
+ Size -= Amount;
+ BufferPtr += Amount;
StartingAddress += Amount;
- Lba += 1;
+ Lba += 1;
//
// Read aligned parts
//
OverRunLba = Lba + DivU64x32Remainder (Size, BlockSize, &Offset);
- Size -= Offset;
+ Size -= Offset;
Status = FatReadBlock (PrivateData, BlockDeviceNo, Lba, Size, BufferPtr);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
@@ -292,7 +288,6 @@ FatReadDisk (
return Status;
}
-
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@@ -310,9 +305,9 @@ FatReadDisk (
**/
VOID
EngFatToStr (
- IN UINTN FatSize,
- IN CHAR8 *Fat,
- OUT CHAR16 *Str
+ IN UINTN FatSize,
+ IN CHAR8 *Fat,
+ OUT CHAR16 *Str
)
{
CHAR16 *String;
@@ -325,16 +320,16 @@ EngFatToStr (
if (*Fat == ' ') {
break;
}
- *String = *Fat;
- String += 1;
- Fat += 1;
+
+ *String = *Fat;
+ String += 1;
+ Fat += 1;
FatSize -= 1;
}
*String = 0;
}
-
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@@ -366,5 +361,5 @@ EngStriColl (
UpperS2 = ToUpper (*Str2);
}
- return (BOOLEAN) ((*Str2 != 0) ? FALSE : TRUE);
+ return (BOOLEAN)((*Str2 != 0) ? FALSE : TRUE);
}
diff --git a/FatPkg/FatPei/FatLitePeim.h b/FatPkg/FatPei/FatLitePeim.h
index 0c3c69853c..1f90ef885d 100644
--- a/FatPkg/FatPei/FatLitePeim.h
+++ b/FatPkg/FatPei/FatLitePeim.h
@@ -33,14 +33,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Definitions
//
-#define PEI_FAT_CACHE_SIZE 4
-#define PEI_FAT_MAX_BLOCK_SIZE 8192
-#define FAT_MAX_FILE_NAME_LENGTH 128
-#define PEI_FAT_MAX_BLOCK_DEVICE 64
-#define PEI_FAT_MAX_BLOCK_IO_PPI 32
-#define PEI_FAT_MAX_VOLUME 64
+#define PEI_FAT_CACHE_SIZE 4
+#define PEI_FAT_MAX_BLOCK_SIZE 8192
+#define FAT_MAX_FILE_NAME_LENGTH 128
+#define PEI_FAT_MAX_BLOCK_DEVICE 64
+#define PEI_FAT_MAX_BLOCK_IO_PPI 32
+#define PEI_FAT_MAX_VOLUME 64
-#define PEI_FAT_MEMORY_PAGE_SIZE 0x1000
+#define PEI_FAT_MEMORY_PAGE_SIZE 0x1000
//
// Data Structures
@@ -49,86 +49,79 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// The block device
//
typedef struct {
-
- UINT32 BlockSize;
- UINT64 LastBlock;
- UINT32 IoAlign;
- BOOLEAN Logical;
- BOOLEAN PartitionChecked;
+ UINT32 BlockSize;
+ UINT64 LastBlock;
+ UINT32 IoAlign;
+ BOOLEAN Logical;
+ BOOLEAN PartitionChecked;
//
// Following fields only valid for logical device
//
- CHAR8 PartitionFlag[8];
- UINT64 StartingPos;
- UINTN ParentDevNo;
+ CHAR8 PartitionFlag[8];
+ UINT64 StartingPos;
+ UINTN ParentDevNo;
//
// Following fields only valid for physical device
//
- EFI_PEI_BLOCK_DEVICE_TYPE DevType;
- UINT8 InterfaceType;
+ EFI_PEI_BLOCK_DEVICE_TYPE DevType;
+ UINT8 InterfaceType;
//
// EFI_PEI_READ_BLOCKS ReadFunc;
//
- EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
- EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
- UINT8 PhysicalDevNo;
+ EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
+ EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
+ UINT8 PhysicalDevNo;
} PEI_FAT_BLOCK_DEVICE;
//
// the Volume structure
//
typedef struct {
-
- UINTN BlockDeviceNo;
- UINTN VolumeNo;
- UINT64 VolumeSize;
- UINTN MaxCluster;
- CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
- PEI_FAT_TYPE FatType;
- UINT64 FatPos;
- UINT32 SectorSize;
- UINT32 ClusterSize;
- UINT64 FirstClusterPos;
- UINT64 RootDirPos;
- UINT32 RootEntries;
- UINT32 RootDirCluster;
-
+ UINTN BlockDeviceNo;
+ UINTN VolumeNo;
+ UINT64 VolumeSize;
+ UINTN MaxCluster;
+ CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
+ PEI_FAT_TYPE FatType;
+ UINT64 FatPos;
+ UINT32 SectorSize;
+ UINT32 ClusterSize;
+ UINT64 FirstClusterPos;
+ UINT64 RootDirPos;
+ UINT32 RootEntries;
+ UINT32 RootDirCluster;
} PEI_FAT_VOLUME;
//
// File instance
//
typedef struct {
+ PEI_FAT_VOLUME *Volume;
+ CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
- PEI_FAT_VOLUME *Volume;
- CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
-
- BOOLEAN IsFixedRootDir;
+ BOOLEAN IsFixedRootDir;
- UINT32 StartingCluster;
- UINT32 CurrentPos;
- UINT32 StraightReadAmount;
- UINT32 CurrentCluster;
-
- UINT8 Attributes;
- UINT32 FileSize;
+ UINT32 StartingCluster;
+ UINT32 CurrentPos;
+ UINT32 StraightReadAmount;
+ UINT32 CurrentCluster;
+ UINT8 Attributes;
+ UINT32 FileSize;
} PEI_FAT_FILE;
//
// Cache Buffer
//
typedef struct {
-
- BOOLEAN Valid;
- UINTN BlockDeviceNo;
- UINT64 Lba;
- UINT32 Lru;
- UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
- UINTN Size;
-
+ BOOLEAN Valid;
+ UINTN BlockDeviceNo;
+ UINT64 Lba;
+ UINT32 Lru;
+ UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
+ UINTN Size;
} PEI_FAT_CACHE_BUFFER;
//
@@ -142,25 +135,23 @@ typedef struct {
#define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
typedef struct {
-
- UINTN Signature;
- EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
- EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
- EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
-
- UINT8 UnicodeCaseMap[0x300];
- CHAR8 *EngUpperMap;
- CHAR8 *EngLowerMap;
- CHAR8 *EngInfoMap;
-
- UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
- UINTN BlockDeviceCount;
- PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
- UINTN VolumeCount;
- PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
- PEI_FAT_FILE File;
- PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
-
+ UINTN Signature;
+ EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
+ EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
+ EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
+
+ UINT8 UnicodeCaseMap[0x300];
+ CHAR8 *EngUpperMap;
+ CHAR8 *EngLowerMap;
+ CHAR8 *EngInfoMap;
+
+ UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
+ UINTN BlockDeviceCount;
+ PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
+ UINTN VolumeCount;
+ PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
+ PEI_FAT_FILE File;
+ PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
} PEI_FAT_PRIVATE_DATA;
#define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
@@ -178,7 +169,6 @@ typedef struct {
#define UNPACK_UINT32(a) \
(UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
-
//
// API functions
//
@@ -209,7 +199,6 @@ FindRecoveryFile (
OUT PEI_FILE_HANDLE *Handle
);
-
/**
Returns the number of DXE capsules residing on the device.
This function, by whatever mechanism, searches for DXE capsules from the associated device and
@@ -231,12 +220,11 @@ FindRecoveryFile (
EFI_STATUS
EFIAPI
GetNumberRecoveryCapsules (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- OUT UINTN *NumberRecoveryCapsules
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ OUT UINTN *NumberRecoveryCapsules
);
-
/**
Returns the size and type of the requested recovery capsule.
This function returns the size and type of the capsule specified by CapsuleInstance.
@@ -267,14 +255,13 @@ GetNumberRecoveryCapsules (
EFI_STATUS
EFIAPI
GetRecoveryCapsuleInfo (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT UINTN *Size,
- OUT EFI_GUID *CapsuleType
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT UINTN *Size,
+ OUT EFI_GUID *CapsuleType
);
-
/**
Loads a DXE capsule from some media into memory.
@@ -297,13 +284,12 @@ GetRecoveryCapsuleInfo (
EFI_STATUS
EFIAPI
LoadRecoveryCapsule (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT VOID *Buffer
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT VOID *Buffer
);
-
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@@ -321,12 +307,11 @@ LoadRecoveryCapsule (
**/
VOID
EngFatToStr (
- IN UINTN FatSize,
- IN CHAR8 *Fat,
- OUT CHAR16 *Str
+ IN UINTN FatSize,
+ IN CHAR8 *Fat,
+ OUT CHAR16 *Str
);
-
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@@ -342,7 +327,6 @@ EngStriColl (
IN CHAR16 *Str2
);
-
/**
Reads a block of data from the block device by calling
underlying Block I/O service.
@@ -361,14 +345,13 @@ EngStriColl (
**/
EFI_STATUS
FatReadBlock (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN BlockDeviceNo,
- IN EFI_PEI_LBA Lba,
- IN UINTN BufferSize,
- OUT VOID *Buffer
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN BlockDeviceNo,
+ IN EFI_PEI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
);
-
/**
Check if there is a valid FAT in the corresponding Block device
of the volume and if yes, fill in the relevant fields for the
@@ -394,7 +377,6 @@ FatGetBpbInfo (
IN OUT PEI_FAT_VOLUME *Volume
);
-
/**
Gets the next cluster in the cluster chain.
@@ -416,7 +398,6 @@ FatGetNextCluster (
OUT UINT32 *NextCluster
);
-
/**
Disk reading.
@@ -439,7 +420,6 @@ FatReadDisk (
OUT VOID *Buffer
);
-
/**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@@ -460,7 +440,6 @@ FatSetFilePos (
IN UINT32 Pos
);
-
/**
Reads file data. Updates the file's CurrentPos.
@@ -482,7 +461,6 @@ FatReadFile (
OUT VOID *Buffer
);
-
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@@ -507,7 +485,6 @@ FatReadNextDirectoryEntry (
OUT PEI_FAT_FILE *SubFile
);
-
/**
This function finds partitions (logical devices) in physical block devices.
diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
index 4028c535f3..0a1a25ceef 100644
--- a/FatPkg/FatPei/Gpt.c
+++ b/FatPkg/FatPei/Gpt.c
@@ -23,9 +23,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// GPT Partition Entry Status
//
typedef struct {
- BOOLEAN OutOfRange;
- BOOLEAN Overlap;
- BOOLEAN OsSpecific;
+ BOOLEAN OutOfRange;
+ BOOLEAN Overlap;
+ BOOLEAN OsSpecific;
} EFI_PARTITION_ENTRY_STATUS;
/**
@@ -42,8 +42,8 @@ PartitionCheckGptHeaderCRC (
IN EFI_PARTITION_TABLE_HEADER *PartHeader
)
{
- UINT32 GptHdrCrc;
- UINT32 Crc;
+ UINT32 GptHdrCrc;
+ UINT32 Crc;
GptHdrCrc = PartHeader->Header.CRC32;
@@ -62,7 +62,6 @@ PartitionCheckGptHeaderCRC (
return (GptHdrCrc == Crc);
}
-
/**
Check if the CRC field in the Partition table header is valid
for Partition entry array.
@@ -76,17 +75,17 @@ PartitionCheckGptHeaderCRC (
**/
BOOLEAN
PartitionCheckGptEntryArrayCRC (
- IN EFI_PARTITION_TABLE_HEADER *PartHeader,
- IN EFI_PARTITION_ENTRY *PartEntry
+ IN EFI_PARTITION_TABLE_HEADER *PartHeader,
+ IN EFI_PARTITION_ENTRY *PartEntry
)
{
- UINT32 Crc;
- UINTN Size;
+ UINT32 Crc;
+ UINTN Size;
- Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
+ Size = (UINTN)MultU64x32 (PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
Crc = CalculateCrc32 (PartEntry, Size);
- return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+ return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc);
}
/**
@@ -109,14 +108,14 @@ PartitionCheckGptHeader (
IN EFI_PARTITION_TABLE_HEADER *PartHdr
)
{
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- EFI_PEI_LBA Lba;
- EFI_PEI_LBA AlternateLba;
- EFI_PEI_LBA EntryArrayLastLba;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ EFI_PEI_LBA Lba;
+ EFI_PEI_LBA AlternateLba;
+ EFI_PEI_LBA EntryArrayLastLba;
- UINT64 PartitionEntryArraySize;
- UINT64 PartitionEntryBlockNumb;
- UINT32 EntryArraySizeRemainder;
+ UINT64 PartitionEntryArraySize;
+ UINT64 PartitionEntryBlockNumb;
+ UINT32 EntryArraySizeRemainder;
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
@@ -128,13 +127,14 @@ PartitionCheckGptHeader (
AlternateLba = PRIMARY_PART_HEADER_LBA;
}
- if ( (PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
- (PartHdr->Header.Revision != 0x00010000) ||
- (PartHdr->Header.HeaderSize < 92) ||
- (PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
- (!PartitionCheckGptHeaderCRC (PartHdr)) ||
- (PartHdr->Header.Reserved != 0)
- ) {
+ if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
+ (PartHdr->Header.Revision != 0x00010000) ||
+ (PartHdr->Header.HeaderSize < 92) ||
+ (PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
+ (!PartitionCheckGptHeaderCRC (PartHdr)) ||
+ (PartHdr->Header.Reserved != 0)
+ )
+ {
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@@ -150,17 +150,18 @@ PartitionCheckGptHeader (
// 5. Must be remain 128*128 bytes for backup entry array.
// 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
//
- if ( (PartHdr->MyLBA != Lba) ||
- (PartHdr->AlternateLBA != AlternateLba) ||
- (PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
- (PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
- (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
- (PartHdr->PartitionEntryLBA < 2) ||
- (PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
- (PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA && PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA) ||
- (PartHdr->SizeOfPartitionEntry%128 != 0) ||
- (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
- ) {
+ if ((PartHdr->MyLBA != Lba) ||
+ (PartHdr->AlternateLBA != AlternateLba) ||
+ (PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
+ (PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
+ (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
+ (PartHdr->PartitionEntryLBA < 2) ||
+ (PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
+ ((PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA) && (PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA)) ||
+ (PartHdr->SizeOfPartitionEntry%128 != 0) ||
+ (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
+ )
+ {
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@@ -219,30 +220,30 @@ PartitionCheckGptEntryArray (
IN EFI_PARTITION_TABLE_HEADER *PartHdr
)
{
- EFI_STATUS Status;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
+ EFI_STATUS Status;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
- UINT64 PartitionEntryArraySize;
- UINT64 PartitionEntryBlockNumb;
- UINT32 EntryArraySizeRemainder;
+ UINT64 PartitionEntryArraySize;
+ UINT64 PartitionEntryBlockNumb;
+ UINT32 EntryArraySizeRemainder;
- EFI_PARTITION_ENTRY *PartitionEntryBuffer;
- EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
+ EFI_PARTITION_ENTRY *PartitionEntryBuffer;
+ EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
- BOOLEAN Found;
- EFI_LBA StartingLBA;
- EFI_LBA EndingLBA;
- UINTN Index;
- UINTN Index1;
- UINTN Index2;
- EFI_PARTITION_ENTRY *Entry;
+ BOOLEAN Found;
+ EFI_LBA StartingLBA;
+ EFI_LBA EndingLBA;
+ UINTN Index;
+ UINTN Index1;
+ UINTN Index2;
+ EFI_PARTITION_ENTRY *Entry;
PartitionEntryBuffer = NULL;
PartitionEntryStatus = NULL;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
- Found = FALSE;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ Found = FALSE;
PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
EntryArraySizeRemainder = 0;
@@ -250,19 +251,21 @@ PartitionCheckGptEntryArray (
if (EntryArraySizeRemainder != 0) {
PartitionEntryBlockNumb++;
}
+
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
- PartitionEntryBuffer = (EFI_PARTITION_ENTRY *) AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
+ PartitionEntryBuffer = (EFI_PARTITION_ENTRY *)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
if (PartitionEntryBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
- PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *) AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
+ PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *)AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
if (PartitionEntryStatus == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
+
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
Status = FatReadBlock (
@@ -283,19 +286,20 @@ PartitionCheckGptEntryArray (
}
for (Index1 = 0; Index1 < PartHdr->NumberOfPartitionEntries; Index1++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
StartingLBA = Entry->StartingLBA;
EndingLBA = Entry->EndingLBA;
- if (StartingLBA > EndingLBA ||
- StartingLBA < PartHdr->FirstUsableLBA ||
- StartingLBA > PartHdr->LastUsableLBA ||
- EndingLBA < PartHdr->FirstUsableLBA ||
- EndingLBA > PartHdr->LastUsableLBA
- ) {
+ if ((StartingLBA > EndingLBA) ||
+ (StartingLBA < PartHdr->FirstUsableLBA) ||
+ (StartingLBA > PartHdr->LastUsableLBA) ||
+ (EndingLBA < PartHdr->FirstUsableLBA) ||
+ (EndingLBA > PartHdr->LastUsableLBA)
+ )
+ {
PartitionEntryStatus[Index1].OutOfRange = TRUE;
continue;
}
@@ -308,27 +312,28 @@ PartitionCheckGptEntryArray (
}
for (Index2 = Index1 + 1; Index2 < PartHdr->NumberOfPartitionEntries; Index2++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index2 * PartHdr->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
//
- PartitionEntryStatus[Index1].Overlap = TRUE;
- PartitionEntryStatus[Index2].Overlap = TRUE;
+ PartitionEntryStatus[Index1].Overlap = TRUE;
+ PartitionEntryStatus[Index2].Overlap = TRUE;
continue;
}
}
}
for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
- if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)||
+ if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
PartitionEntryStatus[Index].OutOfRange ||
PartitionEntryStatus[Index].Overlap ||
- PartitionEntryStatus[Index].OsSpecific) {
+ PartitionEntryStatus[Index].OsSpecific)
+ {
//
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
// partition Entries
@@ -340,8 +345,8 @@ PartitionCheckGptEntryArray (
break;
}
- Found = TRUE;
- BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
+ Found = TRUE;
+ BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
BlockDevPtr->BlockSize = ParentBlockDev->BlockSize;
BlockDevPtr->LastBlock = PartitionEntryBuffer[Index].EndingLBA;
@@ -352,13 +357,13 @@ PartitionCheckGptEntryArray (
PartitionEntryBuffer[Index].StartingLBA,
ParentBlockDev->BlockSize
);
- BlockDevPtr->ParentDevNo = ParentBlockDevNo;
+ BlockDevPtr->ParentDevNo = ParentBlockDevNo;
PrivateData->BlockDeviceCount++;
- DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
+ DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
DEBUG ((DEBUG_INFO, ", 0x%lx]\n", BlockDevPtr->LastBlock));
- DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
+ DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
}
EXIT:
@@ -390,18 +395,18 @@ EXIT:
**/
BOOLEAN
PartitionCheckGptStructure (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo,
- IN BOOLEAN IsPrimary
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo,
+ IN BOOLEAN IsPrimary
)
{
- EFI_STATUS Status;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- EFI_PARTITION_TABLE_HEADER *PartHdr;
- EFI_PEI_LBA GptHeaderLBA;
+ EFI_STATUS Status;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ EFI_PARTITION_TABLE_HEADER *PartHdr;
+ EFI_PEI_LBA GptHeaderLBA;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
- PartHdr = (EFI_PARTITION_TABLE_HEADER *) PrivateData->BlockData;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ PartHdr = (EFI_PARTITION_TABLE_HEADER *)PrivateData->BlockData;
if (IsPrimary) {
GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
@@ -442,18 +447,18 @@ PartitionCheckGptStructure (
**/
BOOLEAN
PartitionCheckProtectiveMbr (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
- EFI_STATUS Status;
- MASTER_BOOT_RECORD *ProtectiveMbr;
- MBR_PARTITION_RECORD *MbrPartition;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- UINTN Index;
+ EFI_STATUS Status;
+ MASTER_BOOT_RECORD *ProtectiveMbr;
+ MBR_PARTITION_RECORD *MbrPartition;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ UINTN Index;
- ProtectiveMbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ ProtectiveMbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
//
// Read Protective MBR
@@ -482,11 +487,12 @@ PartitionCheckProtectiveMbr (
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
- if (MbrPartition->BootIndicator == 0x00 &&
- MbrPartition->StartSector == 0x02 &&
- MbrPartition->OSIndicator == PMBR_GPT_PARTITION &&
- UNPACK_UINT32 (MbrPartition->StartingLBA) == 1
- ) {
+ if ((MbrPartition->BootIndicator == 0x00) &&
+ (MbrPartition->StartSector == 0x02) &&
+ (MbrPartition->OSIndicator == PMBR_GPT_PARTITION) &&
+ (UNPACK_UINT32 (MbrPartition->StartingLBA) == 1)
+ )
+ {
return TRUE;
}
}
@@ -510,18 +516,18 @@ PartitionCheckProtectiveMbr (
**/
BOOLEAN
FatFindGptPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
- BOOLEAN Found;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ BOOLEAN Found;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
return FALSE;
}
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceed FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
return FALSE;
diff --git a/FatPkg/FatPei/Mbr.c b/FatPkg/FatPei/Mbr.c
index 78e73fb811..0a6f1f505c 100644
--- a/FatPkg/FatPei/Mbr.c
+++ b/FatPkg/FatPei/Mbr.c
@@ -23,26 +23,27 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
PartitionValidMbr (
- IN MASTER_BOOT_RECORD *Mbr,
- IN EFI_PEI_LBA LastLba
+ IN MASTER_BOOT_RECORD *Mbr,
+ IN EFI_PEI_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;
}
@@ -65,12 +66,12 @@ PartitionValidMbr (
}
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {
- if (Mbr->Partition[Index2].OSIndicator == 0x00 || UNPACK_INT32 (Mbr->Partition[Index2].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index2].OSIndicator == 0x00) || (UNPACK_INT32 (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
//
@@ -78,6 +79,7 @@ PartitionValidMbr (
}
}
}
+
//
// Non of the regions overlapped so MBR is O.K.
//
@@ -98,8 +100,8 @@ PartitionValidMbr (
**/
BOOLEAN
FatFindMbrPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
EFI_STATUS Status;
@@ -113,55 +115,56 @@ FatFindMbrPartitions (
return FALSE;
}
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
- DEBUG((DEBUG_ERROR, "Device BlockSize %x exceeds FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
+ DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceeds FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
return FALSE;
}
- Found = FALSE;
- Mbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
+ Found = FALSE;
+ Mbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
Status = FatReadBlock (
- PrivateData,
- ParentBlockDevNo,
- 0,
- ParentBlockDev->BlockSize,
- Mbr
- );
+ PrivateData,
+ ParentBlockDevNo,
+ 0,
+ ParentBlockDev->BlockSize,
+ Mbr
+ );
if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev->LastBlock)) {
goto Done;
}
+
//
// We have a valid mbr - add each partition
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
- if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index].OSIndicator == 0x00) || (UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) == 0)) {
//
// Don't use null MBR entries
//
continue;
}
+
//
// Register this partition
//
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
-
- Found = TRUE;
-
- BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
-
- BlockDev->BlockSize = MBR_SIZE;
- BlockDev->LastBlock = UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) - 1;
- BlockDev->IoAlign = ParentBlockDev->IoAlign;
- BlockDev->Logical = TRUE;
- BlockDev->PartitionChecked = FALSE;
- BlockDev->StartingPos = MultU64x32 (
- UNPACK_INT32 (Mbr->Partition[Index].StartingLBA),
- ParentBlockDev->BlockSize
- );
+ Found = TRUE;
+
+ BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
+
+ BlockDev->BlockSize = MBR_SIZE;
+ BlockDev->LastBlock = UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) - 1;
+ BlockDev->IoAlign = ParentBlockDev->IoAlign;
+ BlockDev->Logical = TRUE;
+ BlockDev->PartitionChecked = FALSE;
+ BlockDev->StartingPos = MultU64x32 (
+ UNPACK_INT32 (Mbr->Partition[Index].StartingLBA),
+ ParentBlockDev->BlockSize
+ );
BlockDev->ParentDevNo = ParentBlockDevNo;
PrivateData->BlockDeviceCount++;
diff --git a/FatPkg/FatPei/Part.c b/FatPkg/FatPei/Part.c
index 3e2ded31cc..10d51f9397 100644
--- a/FatPkg/FatPei/Part.c
+++ b/FatPkg/FatPei/Part.c
@@ -24,8 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
FatFindEltoritoPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
);
/**
@@ -42,8 +42,8 @@ FatFindEltoritoPartitions (
**/
BOOLEAN
FatFindMbrPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
);
/**
@@ -61,8 +61,8 @@ FatFindMbrPartitions (
**/
BOOLEAN
FatFindGptPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
);
/**
@@ -76,8 +76,8 @@ FatFindPartitions (
IN PEI_FAT_PRIVATE_DATA *PrivateData
)
{
- BOOLEAN Found;
- UINTN Index;
+ BOOLEAN Found;
+ UINTN Index;
do {
Found = FALSE;