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>
This commit is contained in:
Michael Kubacki
2021-12-05 14:53:58 -08:00
committed by mergify[bot]
parent a550d468a6
commit bcdcc4160d
30 changed files with 2153 additions and 2047 deletions

View File

@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
@ -58,7 +59,6 @@ FatComponentNameGetDriverName (
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
@ -177,7 +177,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[]
}
};
/**
Retrieves a Unicode string that is the user readable name of the driver.

View File

@ -48,6 +48,7 @@ FatDelete (
Status = EFI_WRITE_PROTECTED;
goto Done;
}
//
// If the file is the root dir, then don't delete it
//
@ -55,6 +56,7 @@ FatDelete (
Status = EFI_ACCESS_DENIED;
goto Done;
}
//
// If the file has a permanent error, skip the delete
//
@ -72,14 +74,16 @@ FatDelete (
for (Round = 0; Round < 3; Round++) {
Status = FatGetNextDirEnt (OFile, &DirEnt);
if ((EFI_ERROR (Status)) ||
((Round < 2) && (DirEnt == NULL || !FatIsDotDirEnt (DirEnt))) ||
((Round < 2) && ((DirEnt == NULL) || !FatIsDotDirEnt (DirEnt))) ||
((Round == 2) && (DirEnt != NULL))
) {
)
{
Status = EFI_ACCESS_DENIED;
goto Done;
}
}
}
//
// Return the file's space by setting its size to 0
//
@ -91,6 +95,7 @@ FatDelete (
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Set a permanent error for this OFile in case there
// are still opened IFiles attached

View File

@ -107,6 +107,7 @@ FatDiscardODir (
ODir = NULL;
}
}
//
// Release ODir Structure
//
@ -142,7 +143,8 @@ FatRequestODir (
for (CurrentODirLink = Volume->DirCacheList.ForwardLink;
CurrentODirLink != &Volume->DirCacheList;
CurrentODirLink = CurrentODirLink->ForwardLink
) {
)
{
CurrentODir = ODIR_FROM_DIRCACHELINK (CurrentODirLink);
if (CurrentODir->DirCacheTag == DirCacheTag) {
RemoveEntryList (&CurrentODir->DirCacheLink);
@ -175,6 +177,7 @@ FatCleanupODirCache (
)
{
FAT_ODIR *ODir;
while (Volume->DirCacheCount > 0) {
ODir = ODIR_FROM_DIRCACHELINK (Volume->DirCacheList.BackLink);
RemoveEntryList (&ODir->DirCacheLink);

View File

@ -145,8 +145,9 @@ FatIsDotDirEnt (
)
{
CHAR16 *FileString;
FileString = DirEnt->FileString;
if (StrCmp (FileString, L".") == 0 || StrCmp (FileString, L"..") == 0) {
if ((StrCmp (FileString, L".") == 0) || (StrCmp (FileString, L"..") == 0)) {
return TRUE;
}
@ -208,6 +209,7 @@ FatCloneDirEnt (
{
UINT8 *Entry1;
UINT8 *Entry2;
Entry1 = (UINT8 *)&DirEnt1->Entry;
Entry2 = (UINT8 *)&DirEnt2->Entry;
CopyMem (
@ -258,12 +260,13 @@ FatLoadLongNameEntry (
EntryPos--;
Status = FatAccessEntry (Parent, ReadData, EntryPos, &LfnEntry);
if (EFI_ERROR (Status) ||
LfnEntry.Attributes != FAT_ATTRIBUTE_LFN ||
LfnEntry.MustBeZero != 0 ||
LfnEntry.Checksum != LfnChecksum ||
(LfnEntry.Ordinal & (~FAT_LFN_LAST)) != LfnOrdinal ||
LfnOrdinal > MAX_LFN_ENTRIES
) {
(LfnEntry.Attributes != FAT_ATTRIBUTE_LFN) ||
(LfnEntry.MustBeZero != 0) ||
(LfnEntry.Checksum != LfnChecksum) ||
((LfnEntry.Ordinal & (~FAT_LFN_LAST)) != LfnOrdinal) ||
(LfnOrdinal > MAX_LFN_ENTRIES)
)
{
//
// The directory entry does not have a long file name or
// some error occurs when loading long file name for a directory entry,
@ -281,6 +284,7 @@ FatLoadLongNameEntry (
LfnBufferPointer += LFN_CHAR3_LEN;
LfnOrdinal++;
} while ((LfnEntry.Ordinal & FAT_LFN_LAST) == 0);
DirEnt->EntryCount = LfnOrdinal;
//
// Terminate current Lfnbuffer
@ -319,6 +323,7 @@ FatAddDirEnt (
if (DirEnt->Link.BackLink == NULL) {
DirEnt->Link.BackLink = &ODir->ChildList;
}
InsertTailList (DirEnt->Link.BackLink, &DirEnt->Link);
FatInsertToHashTable (ODir, DirEnt);
}
@ -367,7 +372,7 @@ FatLoadNextDirEnt (
return Status;
}
if (((UINT8) Entry.FileName[0] != DELETE_ENTRY_MARK) && (Entry.Attributes & FAT_ATTRIBUTE_VOLUME_ID) == 0) {
if (((UINT8)Entry.FileName[0] != DELETE_ENTRY_MARK) && ((Entry.Attributes & FAT_ATTRIBUTE_VOLUME_ID) == 0)) {
//
// We get a valid directory entry, then handle it
//
@ -405,6 +410,7 @@ FatLoadNextDirEnt (
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
//
// Add this directory entry to directory
//
@ -525,9 +531,10 @@ FatSearchODir (
// Search the hash table first
//
DirEnt = *FatLongNameHashSearch (ODir, FileNameString);
if (DirEnt == NULL && PossibleShortName) {
if ((DirEnt == NULL) && PossibleShortName) {
DirEnt = *FatShortNameHashSearch (ODir, File8Dot3Name);
}
if (DirEnt == NULL) {
//
// We fail to get the directory entry from hash table; we then
@ -544,7 +551,7 @@ FatSearchODir (
break;
}
if (PossibleShortName && CompareMem (File8Dot3Name, DirEnt->Entry.FileName, FAT_NAME_LEN) == 0) {
if (PossibleShortName && (CompareMem (File8Dot3Name, DirEnt->Entry.FileName, FAT_NAME_LEN) == 0)) {
break;
}
}
@ -745,6 +752,7 @@ FatSeekVolumeId (
EntryPos++;
} while (Entry->FileName[0] != EMPTY_ENTRY_MARK);
return EFI_SUCCESS;
}
@ -799,10 +807,11 @@ FatFirstFitInsertDirEnt (
for (CurrentEntry = ODir->ChildList.ForwardLink;
CurrentEntry != &ODir->ChildList;
CurrentEntry = CurrentEntry->ForwardLink
) {
)
{
CurrentDirEnt = DIRENT_FROM_LINK (CurrentEntry);
if (NewEntryPos + CurrentDirEnt->EntryCount <= CurrentDirEnt->EntryPos) {
if (LabelPos > NewEntryPos || LabelPos <= CurrentPos) {
if ((LabelPos > NewEntryPos) || (LabelPos <= CurrentPos)) {
//
// first fit succeeded
//
@ -859,6 +868,7 @@ FatNewEntryPos (
return Status;
}
}
//
// We will append this entry to the end of directory
//
@ -873,6 +883,7 @@ FatNewEntryPos (
//
return FatFirstFitInsertDirEnt (OFile, DirEnt);
}
//
// We should allocate a new cluster for this directory
//
@ -881,6 +892,7 @@ FatNewEntryPos (
return Status;
}
}
//
// We append our directory entry at the end of directory file
//
@ -1002,6 +1014,7 @@ FatCreateDotDirEnts (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Create ".."
//
@ -1049,6 +1062,7 @@ FatCreateDirEnt (
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
//
// Determine how many directory entries we need
//
@ -1098,6 +1112,7 @@ FatRemoveDirEnt (
//
ODir->CurrentCursor = ODir->CurrentCursor->BackLink;
}
//
// Remove from directory entry list
//
@ -1280,6 +1295,7 @@ FatLocateOFile (
if (FileName[FileNameLen - 1] == PATH_NAME_SEPARATOR) {
DirIntended = TRUE;
}
//
// If name starts with path name separator, then move to root OFile
//
@ -1288,6 +1304,7 @@ FatLocateOFile (
FileName++;
FileNameLen--;
}
//
// Per FAT Spec the file name should meet the following criteria:
// C1. Length (FileLongName) <= 255
@ -1300,6 +1317,7 @@ FatLocateOFile (
//
return EFI_INVALID_PARAMETER;
}
//
// Start at current location
//
@ -1315,19 +1333,21 @@ FatLocateOFile (
// If end of the file name, we're done
//
if (ComponentName[0] == 0) {
if (DirIntended && OFile->ODir == NULL) {
if (DirIntended && (OFile->ODir == NULL)) {
return EFI_NOT_FOUND;
}
NewFileName[0] = 0;
break;
}
//
// If "dot", then current
//
if (StrCmp (ComponentName, L".") == 0) {
continue;
}
//
// If "dot dot", then parent
//
@ -1335,6 +1355,7 @@ FatLocateOFile (
if (OFile->Parent == NULL) {
return EFI_INVALID_PARAMETER;
}
OFile = OFile->Parent;
continue;
}
@ -1342,6 +1363,7 @@ FatLocateOFile (
if (!FatFileNameIsValid (ComponentName, NewFileName)) {
return EFI_INVALID_PARAMETER;
}
//
// We have a component name, try to open it
//
@ -1351,6 +1373,7 @@ FatLocateOFile (
//
return EFI_NOT_FOUND;
}
//
// Search the compName in the directory
//
@ -1367,9 +1390,10 @@ FatLocateOFile (
return EFI_NOT_FOUND;
}
if (DirIntended && (Attributes & FAT_ATTRIBUTE_DIRECTORY) == 0) {
if (DirIntended && ((Attributes & FAT_ATTRIBUTE_DIRECTORY) == 0)) {
return EFI_INVALID_PARAMETER;
}
//
// It's the last component name - return with the open
// path and the remaining name

View File

@ -55,7 +55,7 @@ FatFlushDataCacheRange (
for (PageNo = StartPageNo; PageNo < EndPageNo; PageNo++) {
GroupNo = PageNo & GroupMask;
CacheTag = &DiskCache->CacheTag[GroupNo];
if (CacheTag->RealSize > 0 && CacheTag->PageNo == PageNo) {
if ((CacheTag->RealSize > 0) && (CacheTag->PageNo == PageNo)) {
//
// When reading data form disk directly, if some dirty data
// in cache is in this rang, this data in the Buffer need to
@ -131,7 +131,7 @@ FatExchangeCachePage (
}
WriteCount = 1;
if (DataType == CacheFat && IoMode == WriteDisk) {
if ((DataType == CacheFat) && (IoMode == WriteDisk)) {
WriteCount = Volume->NumFats;
}
@ -178,7 +178,7 @@ FatGetCachePage (
UINTN OldPageNo;
OldPageNo = CacheTag->PageNo;
if (CacheTag->RealSize > 0 && OldPageNo == PageNo) {
if ((CacheTag->RealSize > 0) && (OldPageNo == PageNo)) {
//
// Cache Hit occurred
//
@ -188,12 +188,13 @@ FatGetCachePage (
//
// Write dirty cache page back to disk
//
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {
if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, NULL);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Load new data from disk;
//
@ -355,6 +356,7 @@ FatAccessCache (
if (EFI_ERROR (Status)) {
return Status;
}
//
// If these access data over laps the relative cache range, these cache pages need
// to be updated.
@ -363,6 +365,7 @@ FatAccessCache (
Buffer += AlignedSize;
BufferSize -= AlignedSize;
}
//
// The access of the OverRun data
//
@ -410,7 +413,7 @@ FatVolumeFlushCache (
GroupMask = DiskCache->GroupMask;
for (GroupIndex = 0; GroupIndex <= GroupMask; GroupIndex++) {
CacheTag = &DiskCache->CacheTag[GroupIndex];
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {
if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
//
// Write back all Dirty Data Cache Page to disk
//
@ -424,6 +427,7 @@ FatVolumeFlushCache (
DiskCache->Dirty = FALSE;
}
}
//
// Flush the block device.
//

View File

@ -224,14 +224,17 @@ FatUnload (
if (ComponentName2 == NULL) {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
NULL
);
} else {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiComponentName2ProtocolGuid, ComponentName2,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
&gEfiComponentName2ProtocolGuid,
ComponentName2,
NULL
);
}
@ -239,16 +242,21 @@ FatUnload (
if (ComponentName2 == NULL) {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiComponentNameProtocolGuid, ComponentName,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
&gEfiComponentNameProtocolGuid,
ComponentName,
NULL
);
} else {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiComponentNameProtocolGuid, ComponentName,
&gEfiComponentName2ProtocolGuid, ComponentName2,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
&gEfiComponentNameProtocolGuid,
ComponentName,
&gEfiComponentName2ProtocolGuid,
ComponentName2,
NULL
);
}
@ -302,6 +310,7 @@ FatDriverBindingSupported (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
@ -371,6 +380,7 @@ FatDriverBindingStart (
if (EFI_ERROR (Status)) {
goto Exit;
}
//
// Open our required BlockIo and DiskIo
//
@ -453,6 +463,7 @@ Exit:
if (LockedByMe) {
FatReleaseLock ();
}
return Status;
}
@ -512,6 +523,7 @@ FatDriverBindingStop (
);
ASSERT_EFI_ERROR (Status);
}
Status = gBS->CloseProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,

View File

@ -97,7 +97,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
#define PATH_NAME_SEPARATOR L'\\'
#define EFI_PATH_STRING_LENGTH 260
#define EFI_FILE_STRING_LENGTH 255
#define FAT_MAX_ALLOCATE_SIZE 0xA00000
@ -696,6 +695,7 @@ FatWriteEx (
//
// DiskCache.c
//
/**
Initialize the disk cache according to Volume's FatType.
@ -771,6 +771,7 @@ FatVolumeFlushCache (
//
// Flush.c
//
/**
Flush the data associated with an open file.
@ -859,6 +860,7 @@ FatCleanupVolume (
//
// FileSpace.c
//
/**
Shrink the end of the open file base on the file size.
@ -961,6 +963,7 @@ FatComputeFreeInfo (
//
// Init.c
//
/**
Allocates volume structure, detects FAT file system, installs protocol,
@ -1018,6 +1021,7 @@ FatAbandonVolume (
//
// Misc.c
//
/**
Create the task
@ -1251,6 +1255,7 @@ FatIsValidTime (
//
// UnicodeCollation.c
//
/**
Initialize Unicode Collation support.
@ -1398,6 +1403,7 @@ FatAllocateIFile (
//
// OpenVolume.c
//
/**
Implements Simple File System Protocol interface function OpenVolume().
@ -1420,6 +1426,7 @@ FatOpenVolume (
//
// ReadWrite.c
//
/**
This function reads data from a file or writes data to a file.
@ -1501,6 +1508,7 @@ FatTruncateOFile (
//
// DirectoryManage.c
//
/**
Set the OFile's current directory cursor to the list head.
@ -1759,6 +1767,7 @@ FatSetVolumeEntry (
//
// Hash.c
//
/**
Search the long name hash table for the directory entry.
@ -1822,6 +1831,7 @@ FatDeleteFromHashTable (
//
// FileName.c
//
/**
This function checks whether the input FileName is a valid 8.3 short name.
@ -1956,6 +1966,7 @@ FatFileNameIsValid (
//
// DirectoryCache.c
//
/**
Discard the directory structure when an OFile will be freed.

View File

@ -42,7 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define FAT_POS_FAT32(a) ((a) * 4)
#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
//
// FAT attribute define
//

View File

@ -58,12 +58,13 @@ FatCheckIs8Dot3Name (
ExtendName = SeparateDot + 1;
ExtendNameLen = TempName - ExtendName;
}
//
// We scan the filename for the second time
// to check if there exists any extra blanks and dots
//
while (--TempName >= FileName) {
if ((*TempName == L'.' || *TempName == L' ') && (TempName != SeparateDot)) {
if (((*TempName == L'.') || (*TempName == L' ')) && (TempName != SeparateDot)) {
//
// There exist extra blanks and dots
//
@ -176,6 +177,7 @@ FatCreate8Dot3Name (
UINTN Index;
UINTN Retry;
UINT8 Segment;
union {
UINT32 Crc;
struct HEX_DATA {
@ -195,6 +197,7 @@ FatCreate8Dot3Name (
if (BaseTagLen > SPEC_BASE_TAG_LEN) {
BaseTagLen = SPEC_BASE_TAG_LEN;
}
//
// We first use the algorithm described by spec.
//
@ -265,6 +268,7 @@ FatCheckNameCase (
if (StrCmp (Str, Buffer) == 0) {
OutCaseFlag = InCaseFlag;
}
//
// Upper case a copy of the string, if it matches the
// original then the string is upper case
@ -350,6 +354,7 @@ FatGetFileNameViaCaseFlag (
UINT8 CaseFlag;
CHAR8 *File8Dot3Name;
CHAR16 TempExt[1 + FAT_EXTEND_NAME_LEN + 1];
//
// Store file extension like ".txt"
//
@ -380,6 +385,7 @@ FatCheckSum (
{
UINTN ShortNameLen;
UINT8 Sum;
Sum = 0;
for (ShortNameLen = FAT_NAME_LEN; ShortNameLen != 0; ShortNameLen--) {
Sum = (UINT8)((((Sum & 1) != 0) ? 0x80 : 0) + (Sum >> 1) + *ShortNameString++);
@ -409,6 +415,7 @@ FatGetNextNameComponent (
while (*Path != 0 && *Path != PATH_NAME_SEPARATOR) {
*Name++ = *Path++;
}
*Name = 0;
//
// Get off of trailing path name separator
@ -441,6 +448,7 @@ FatFileNameIsValid (
{
CHAR16 *TempNamePointer;
CHAR16 TempChar;
//
// Trim Leading blanks
//
@ -452,12 +460,13 @@ FatFileNameIsValid (
while (*InputFileName != 0) {
*TempNamePointer++ = *InputFileName++;
}
//
// Trim Trailing blanks and dots
//
while (TempNamePointer > OutputFileName) {
TempChar = *(TempNamePointer - 1);
if (TempChar != L' ' && TempChar != L'.') {
if ((TempChar != L' ') && (TempChar != L'.')) {
break;
}
@ -475,25 +484,28 @@ FatFileNameIsValid (
if (TempNamePointer - OutputFileName > EFI_FILE_STRING_LENGTH) {
return FALSE;
}
//
// See if there is any illegal characters within the name
//
do {
if (*OutputFileName < 0x20 ||
*OutputFileName == '\"' ||
*OutputFileName == '*' ||
*OutputFileName == '/' ||
*OutputFileName == ':' ||
*OutputFileName == '<' ||
*OutputFileName == '>' ||
*OutputFileName == '?' ||
*OutputFileName == '\\' ||
*OutputFileName == '|'
) {
if ((*OutputFileName < 0x20) ||
(*OutputFileName == '\"') ||
(*OutputFileName == '*') ||
(*OutputFileName == '/') ||
(*OutputFileName == ':') ||
(*OutputFileName == '<') ||
(*OutputFileName == '>') ||
(*OutputFileName == '?') ||
(*OutputFileName == '\\') ||
(*OutputFileName == '|')
)
{
return FALSE;
}
OutputFileName++;
} while (*OutputFileName != 0);
return TRUE;
}

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Fat.h"
/**
Get the FAT entry of the volume, which is identified with the Index.
@ -35,6 +34,7 @@ FatLoadFatEntry (
Volume->FatEntryBuffer = (UINT32)-1;
return &Volume->FatEntryBuffer;
}
//
// Compute buffer position needed
//
@ -50,6 +50,7 @@ FatLoadFatEntry (
default:
Pos = FAT_POS_FAT32 (Index);
}
//
// Set the position and read the buffer
//
@ -155,16 +156,17 @@ FatSetFatEntry (
}
OriginalVal = FatGetFatEntry (Volume, Index);
if (Value == FAT_CLUSTER_FREE && OriginalVal != FAT_CLUSTER_FREE) {
if ((Value == FAT_CLUSTER_FREE) && (OriginalVal != FAT_CLUSTER_FREE)) {
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
if (Index < Volume->FatInfoSector.FreeInfo.NextCluster) {
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32)Index;
}
} else if (Value != FAT_CLUSTER_FREE && OriginalVal == FAT_CLUSTER_FREE) {
} else if ((Value != FAT_CLUSTER_FREE) && (OriginalVal == FAT_CLUSTER_FREE)) {
if (Volume->FatInfoSector.FreeInfo.ClusterCount != 0) {
Volume->FatInfoSector.FreeInfo.ClusterCount -= 1;
}
}
//
// Make sure the entry is in memory
//
@ -198,13 +200,15 @@ FatSetFatEntry (
En32 = Pos;
*En32 = (*En32 & FAT_CLUSTER_UNMASK_FAT32) | (UINT32)(Value & FAT_CLUSTER_MASK_FAT32);
}
//
// If the volume's dirty bit is not set, set it now
//
if (!Volume->FatDirty && Volume->FatType != Fat12) {
if (!Volume->FatDirty && (Volume->FatType != Fat12)) {
Volume->FatDirty = TRUE;
FatAccessVolumeDirty (Volume, WriteFat, &Volume->DirtyValue);
}
//
// Write the updated fat entry value to the volume
// The fat is the first fat, and other fat will be in sync
@ -242,8 +246,7 @@ FatFreeClusters (
UINTN LastCluster;
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
return EFI_VOLUME_CORRUPTED;
}
@ -285,7 +288,7 @@ FatAllocateCluster (
// If the end of the list, return no available cluster
//
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
if (Volume->FreeInfoValid && 0 < (INT32) (Volume->FatInfoSector.FreeInfo.ClusterCount)) {
if (Volume->FreeInfoValid && (0 < (INT32)(Volume->FatInfoSector.FreeInfo.ClusterCount))) {
Volume->FreeInfoValid = FALSE;
}
@ -299,6 +302,7 @@ FatAllocateCluster (
if (Cluster == FAT_CLUSTER_FREE) {
break;
}
//
// Try the next cluster
//
@ -370,10 +374,8 @@ FatShrinkEof (
LastCluster = FAT_CLUSTER_FREE;
if (NewSize != 0) {
for (CurSize = 0; CurSize < NewSize; CurSize++) {
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
return EFI_VOLUME_CORRUPTED;
}
@ -383,7 +385,6 @@ FatShrinkEof (
}
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
} else {
//
// Check to see if the file is already completely truncated
@ -391,11 +392,13 @@ FatShrinkEof (
if (Cluster == FAT_CLUSTER_FREE) {
return EFI_SUCCESS;
}
//
// The file is being completely truncated.
//
OFile->FileCluster = FAT_CLUSTER_FREE;
}
//
// Set CurrentCluster == FileCluster
// to force a recalculation of Position related stuffs
@ -461,8 +464,7 @@ FatGrowEof (
ClusterCount = 0;
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
if ((Cluster < FAT_MIN_CLUSTER) || (Cluster > Volume->MaxCluster + 1)) {
DEBUG (
(DEBUG_INIT | DEBUG_ERROR,
"FatGrowEof: cluster chain corrupt\n")
@ -484,8 +486,8 @@ FatGrowEof (
Status = EFI_VOLUME_CORRUPTED;
goto Done;
}
}
//
// Loop until we've allocated enough space
//
@ -503,7 +505,7 @@ FatGrowEof (
goto Done;
}
if (NewCluster < FAT_MIN_CLUSTER || NewCluster > Volume->MaxCluster + 1) {
if ((NewCluster < FAT_MIN_CLUSTER) || (NewCluster > Volume->MaxCluster + 1)) {
Status = EFI_VOLUME_CORRUPTED;
goto Done;
}
@ -596,14 +598,14 @@ FatOFilePosition (
//
Cluster = OFile->FileCurrentCluster;
StartPos = OFile->Position;
if (Position < StartPos || OFile->FileCluster == Cluster) {
if ((Position < StartPos) || (OFile->FileCluster == Cluster)) {
StartPos = 0;
Cluster = OFile->FileCluster;
}
while (StartPos + ClusterSize <= Position) {
StartPos += ClusterSize;
if (Cluster == FAT_CLUSTER_FREE || (Cluster >= FAT_CLUSTER_SPECIAL)) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatOFilePosition:" " cluster chain corrupt\n"));
return EFI_VOLUME_CORRUPTED;
}
@ -611,7 +613,7 @@ FatOFilePosition (
Cluster = FatGetFatEntry (Volume, Cluster);
}
if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
if ((Cluster < FAT_MIN_CLUSTER) || (Cluster > Volume->MaxCluster + 1)) {
return EFI_VOLUME_CORRUPTED;
}
@ -655,6 +657,7 @@ FatPhysicalDirSize (
)
{
UINTN Size;
ASSERT_VOLUME_LOCKED (Volume);
//
// Run the cluster chain for the OFile
@ -666,7 +669,7 @@ FatPhysicalDirSize (
//
if (Cluster != 0) {
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG (
(DEBUG_INIT | DEBUG_ERROR,
"FATDirSize: cluster chain corrupt\n")
@ -700,6 +703,7 @@ FatPhysicalFileSize (
{
UINTN ClusterSizeMask;
UINT64 PhysicalSize;
ClusterSizeMask = Volume->ClusterSize - 1;
PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64)ClusterSizeMask));
return PhysicalSize;
@ -723,7 +727,6 @@ FatComputeFreeInfo (
// If we don't have valid info, compute it now
//
if (!Volume->FreeInfoValid) {
Volume->FreeInfoValid = TRUE;
Volume->FatInfoSector.FreeInfo.ClusterCount = 0;
for (Index = Volume->MaxCluster + 1; Index >= FAT_MIN_CLUSTER; Index--) {

View File

@ -50,6 +50,7 @@ FatFlushEx (
if (Volume->ReadOnly) {
return EFI_WRITE_PROTECTED;
}
//
// If read only, return error
//
@ -67,6 +68,7 @@ FatFlushEx (
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
return EFI_UNSUPPORTED;
}
Task = FatCreateTask (IFile, Token);
if (Task == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -193,6 +195,7 @@ FatIFileClose (
if (OFile->CheckLink.ForwardLink == NULL) {
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
}
//
// Done. Free the open instance structure
//
@ -250,10 +253,11 @@ FatOFileFlush (
DirEnt->Entry.Attributes |= FAT_ATTRIBUTE_ARCHIVE;
OFile->Archive = FALSE;
}
//
// Write the directory entry
//
if (Parent != NULL && !DirEnt->Invalid) {
if ((Parent != NULL) && !DirEnt->Invalid) {
//
// Write the OFile's directory entry
//
@ -265,11 +269,13 @@ FatOFileFlush (
OFile->Dirty = FALSE;
}
//
// Check the parent
//
OFile = Parent;
} while (OFile != NULL);
return EFI_SUCCESS;
}
@ -308,6 +314,7 @@ FatCheckOFileRef (
//
return FALSE;
}
//
// Free the Ofile
//
@ -380,12 +387,14 @@ FatCleanupVolume (
)
{
EFI_STATUS Status;
//
// Flag the OFile
//
if (OFile != NULL) {
FatSetVolumeError (OFile, EfiStatus);
}
//
// Clean up any dangling OFiles that don't have IFiles
// we don't check return status here because we want the
@ -403,16 +412,18 @@ FatCleanupVolume (
return Status;
}
}
//
// Update that the volume is not dirty
//
if (Volume->FatDirty && Volume->FatType != Fat12) {
if (Volume->FatDirty && (Volume->FatType != Fat12)) {
Volume->FatDirty = FALSE;
Status = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Flush all dirty cache entries to disk
//
@ -421,11 +432,12 @@ FatCleanupVolume (
return Status;
}
}
//
// If the volume is cleared , remove it.
// The only time volume be invalidated is in DriverBindingStop.
//
if (Volume->Root == NULL && !Volume->Valid) {
if ((Volume->Root == NULL) && !Volume->Valid) {
//
// Free the volume structure
//
@ -458,6 +470,7 @@ FatSetVolumeError (
if (!EFI_ERROR (OFile->Error)) {
OFile->Error = Status;
}
//
// Set the error on each child OFile
//

View File

@ -25,6 +25,7 @@ FatHashLongName (
{
UINT32 HashValue;
CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
StrnCpyS (
UpCasedLongFileName,
ARRAY_SIZE (UpCasedLongFileName),
@ -52,6 +53,7 @@ FatHashShortName (
)
{
UINT32 HashValue;
gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);
return (HashValue & HASH_TABLE_MASK);
}
@ -73,10 +75,12 @@ FatLongNameHashSearch (
)
{
FAT_DIRENT **PreviousHashNode;
for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];
*PreviousHashNode != NULL;
PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink
) {
)
{
if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {
break;
}
@ -102,10 +106,12 @@ FatShortNameHashSearch (
)
{
FAT_DIRENT **PreviousHashNode;
for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];
*PreviousHashNode != NULL;
PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink
) {
)
{
if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {
break;
}

View File

@ -220,7 +220,7 @@ FatSetVolumeInfo (
Info = (EFI_FILE_SYSTEM_INFO *)Buffer;
if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + 2 || Info->Size > BufferSize) {
if ((BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + 2) || (Info->Size > BufferSize)) {
return EFI_BAD_BUFFER_SIZE;
}
@ -312,11 +312,12 @@ FatSetFileInfo (
if (Parent == NULL) {
return EFI_ACCESS_DENIED;
}
//
// Make sure there's a valid input buffer
//
NewInfo = Buffer;
if (BufferSize < SIZE_OF_EFI_FILE_INFO + 2 || NewInfo->Size > BufferSize) {
if ((BufferSize < SIZE_OF_EFI_FILE_INFO + 2) || (NewInfo->Size > BufferSize)) {
return EFI_BAD_BUFFER_SIZE;
}
@ -357,6 +358,7 @@ FatSetFileInfo (
if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) {
return EFI_ACCESS_DENIED;
}
//
// Set the current attributes even if the IFile->ReadOnly is TRUE
//
@ -374,7 +376,7 @@ FatSetFileInfo (
// File was not found. We do not allow rename of the current directory if
// there are open files below the current directory
//
if (!IsListEmpty (&OFile->ChildHead) || Parent == OFile) {
if (!IsListEmpty (&OFile->ChildHead) || (Parent == OFile)) {
return EFI_ACCESS_DENIED;
}
@ -386,6 +388,7 @@ FatSetFileInfo (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Create new dirent
//
@ -413,7 +416,7 @@ FatSetFileInfo (
ASSERT (OFile->Parent != NULL);
for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) {
Status = FatGetNextDirEnt (OFile, &DirEnt);
if (EFI_ERROR (Status) || DirEnt == NULL || !FatIsDotDirEnt (DirEnt)) {
if (EFI_ERROR (Status) || (DirEnt == NULL) || !FatIsDotDirEnt (DirEnt)) {
return EFI_VOLUME_CORRUPTED;
}
@ -424,6 +427,7 @@ FatSetFileInfo (
}
}
}
//
// If the file is renamed, we should append the ARCHIVE attribute
//
@ -434,11 +438,12 @@ FatSetFileInfo (
//
return EFI_ACCESS_DENIED;
}
//
// If the file size has changed, apply it
//
if (NewInfo->FileSize != OFile->FileSize) {
if (OFile->ODir != NULL || ReadOnly) {
if ((OFile->ODir != NULL) || ReadOnly) {
//
// If this is a directory or the file is read only, we can't change the file size
//

View File

@ -68,6 +68,7 @@ FatAllocateVolume (
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Initialize cache
//
@ -75,6 +76,7 @@ FatAllocateVolume (
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Install our protocol interfaces on the device's handle
//
@ -87,6 +89,7 @@ FatAllocateVolume (
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Volume installed
//
@ -146,6 +149,7 @@ FatAbandonVolume (
if (!EFI_ERROR (Status)) {
LockedByMe = TRUE;
}
//
// The volume is still being used. Hence, set error flag for all OFiles still in
// use. In two cases, we could get here. One is EFI_MEDIA_CHANGED, the other is
@ -236,13 +240,14 @@ FatOpenDevice (
SectorsPerFat = FatBs.FatBse.Fat32Bse.LargeSectorsPerFat;
FatType = Fat32;
}
//
// Is boot sector a fat sector?
// (Note that so far we only know if the sector is FAT32 or not, we don't
// know if the sector is Fat16 or Fat12 until later when we can compute
// the volume size)
//
if (FatBs.FatBsb.ReservedSectors == 0 || FatBs.FatBsb.NumFats == 0 || Sectors == 0) {
if ((FatBs.FatBsb.ReservedSectors == 0) || (FatBs.FatBsb.NumFats == 0) || (Sectors == 0)) {
return EFI_UNSUPPORTED;
}
@ -251,7 +256,7 @@ FatOpenDevice (
}
BlockAlignment = (UINT8)HighBitSet32 (FatBs.FatBsb.SectorSize);
if (BlockAlignment > MAX_BLOCK_ALIGNMENT || BlockAlignment < MIN_BLOCK_ALIGNMENT) {
if ((BlockAlignment > MAX_BLOCK_ALIGNMENT) || (BlockAlignment < MIN_BLOCK_ALIGNMENT)) {
return EFI_UNSUPPORTED;
}
@ -264,13 +269,15 @@ FatOpenDevice (
return EFI_UNSUPPORTED;
}
if (FatBs.FatBsb.Media <= 0xf7 &&
FatBs.FatBsb.Media != 0xf0 &&
FatBs.FatBsb.Media != 0x00 &&
FatBs.FatBsb.Media != 0x01
) {
if ((FatBs.FatBsb.Media <= 0xf7) &&
(FatBs.FatBsb.Media != 0xf0) &&
(FatBs.FatBsb.Media != 0x00) &&
(FatBs.FatBsb.Media != 0x01)
)
{
return EFI_UNSUPPORTED;
}
//
// Initialize fields the volume information for this FatType
//
@ -278,6 +285,7 @@ FatOpenDevice (
if (FatBs.FatBsb.RootEntries == 0) {
return EFI_UNSUPPORTED;
}
//
// Unpack fat12, fat16 info
//
@ -286,9 +294,10 @@ FatOpenDevice (
//
// If this is fat32, refuse to mount mirror-disabled volumes
//
if ((SectorsPerFat == 0 || FatBs.FatBse.Fat32Bse.FsVersion != 0) || (FatBs.FatBse.Fat32Bse.ExtendedFlags & 0x80)) {
if (((SectorsPerFat == 0) || (FatBs.FatBse.Fat32Bse.FsVersion != 0)) || (FatBs.FatBse.Fat32Bse.ExtendedFlags & 0x80)) {
return EFI_UNSUPPORTED;
}
//
// Unpack fat32 info
//
@ -334,12 +343,14 @@ FatOpenDevice (
if (Volume->MaxCluster < FAT_MAX_FAT16_CLUSTER) {
return EFI_VOLUME_CORRUPTED;
}
//
// fat32 fat-entries are 4 bytes
//
Volume->FatEntrySize = sizeof (UINT32);
DirtyMask = FAT32_DIRTY_MASK;
}
//
// Get the DirtyValue and NotDirtyValue
// We should keep the initial value as the NotDirtyValue
@ -353,6 +364,7 @@ FatOpenDevice (
Volume->DirtyValue = Volume->NotDirtyValue & DirtyMask;
}
//
// If present, read the fat hint info
//
@ -360,23 +372,27 @@ FatOpenDevice (
Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize;
if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) {
FatDiskIo (Volume, ReadDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, NULL);
if (Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE &&
Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE &&
Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE &&
Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster
) {
if ((Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE) &&
(Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE) &&
(Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE) &&
(Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster)
)
{
Volume->FreeInfoValid = TRUE;
}
}
}
//
// Just make up a FreeInfo.NextCluster for use by allocate cluster
//
if (FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster ||
Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1
) {
if ((FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster) ||
(Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1)
)
{
Volume->FatInfoSector.FreeInfo.NextCluster = FAT_MIN_CLUSTER;
}
//
// We are now defining FAT Type
//

View File

@ -36,6 +36,7 @@ FatCreateTask (
InitializeListHead (&Task->Subtasks);
InitializeListHead (&Task->Link);
}
return Task;
}
@ -59,6 +60,7 @@ FatDestroyTask (
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
Link = FatDestroySubtask (Subtask);
}
FreePool (Task);
}
@ -155,10 +157,10 @@ FatQueueTask (
for ( Link = GetFirstNode (&Task->Subtasks), NextLink = GetNextNode (&Task->Subtasks, Link)
; Link != &Task->Subtasks
; Link = NextLink, NextLink = Link->ForwardLink
) {
)
{
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
if (Subtask->Write) {
Status = IFile->OFile->Volume->DiskIo2->WriteDiskEx (
IFile->OFile->Volume->DiskIo2,
IFile->OFile->Volume->MediaId,
@ -177,6 +179,7 @@ FatQueueTask (
Subtask->Buffer
);
}
if (EFI_ERROR (Status)) {
break;
}
@ -464,6 +467,7 @@ FatFreeVolume (
if (Volume->CacheBuffer != NULL) {
FreePool (Volume->CacheBuffer);
}
//
// Free directory cache
//
@ -579,30 +583,30 @@ FatIsValidTime (
// Check the fields for range problems
// Fat can only support from 1980
//
if (Time->Year < 1980 ||
Time->Month < 1 ||
Time->Month > 12 ||
Time->Day < 1 ||
Time->Day > 31 ||
Time->Hour > 23 ||
Time->Minute > 59 ||
Time->Second > 59 ||
Time->Nanosecond > 999999999
) {
if ((Time->Year < 1980) ||
(Time->Month < 1) ||
(Time->Month > 12) ||
(Time->Day < 1) ||
(Time->Day > 31) ||
(Time->Hour > 23) ||
(Time->Minute > 59) ||
(Time->Second > 59) ||
(Time->Nanosecond > 999999999)
)
{
ValidTime = FALSE;
} else {
//
// Perform a more specific check of the day of the month
//
Day = mMonthDays[Time->Month - 1];
if (Time->Month == 2 && IS_LEAP_YEAR (Time->Year)) {
if ((Time->Month == 2) && IS_LEAP_YEAR (Time->Year)) {
Day += 1;
//
// 1 extra day this month
//
}
if (Time->Day > Day) {
ValidTime = FALSE;
}

View File

@ -104,6 +104,7 @@ FatOFileOpen (
if (Volume->ReadOnly && WriteMode) {
return EFI_WRITE_PROTECTED;
}
//
// Verify the source file handle isn't in an error state
//
@ -111,6 +112,7 @@ FatOFileOpen (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get new OFile for the file
//
@ -150,14 +152,16 @@ FatOFileOpen (
}
}
}
//
// If the file's attribute is read only, and the open is for
// read-write, then the access is denied.
//
FileAttributes = OFile->DirEnt->Entry.Attributes;
if ((FileAttributes & EFI_FILE_READ_ONLY) != 0 && (FileAttributes & FAT_ATTRIBUTE_DIRECTORY) == 0 && WriteMode) {
if (((FileAttributes & EFI_FILE_READ_ONLY) != 0) && ((FileAttributes & FAT_ATTRIBUTE_DIRECTORY) == 0) && WriteMode) {
return EFI_ACCESS_DENIED;
}
//
// Create an open instance of the OFile
//
@ -214,6 +218,7 @@ FatOpenEx (
if (FileName == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Check for a valid mode
//
@ -230,7 +235,7 @@ FatOpenEx (
//
// Check for valid Attributes for file creation case.
//
if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && (Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0) {
if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && ((Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0)) {
return EFI_INVALID_PARAMETER;
}
@ -248,6 +253,7 @@ FatOpenEx (
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
return EFI_UNSUPPORTED;
}
Task = FatCreateTask (IFile, Token);
if (Task == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -270,6 +276,7 @@ FatOpenEx (
if (!EFI_ERROR (Status)) {
*NewHandle = &NewIFile->Handle;
}
//
// Unlock
//

View File

@ -41,6 +41,7 @@ FatOpenVolume (
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Open a new instance to the root
//

View File

@ -91,12 +91,14 @@ FatSetPosition (
FatResetODirCursor (OFile);
}
//
// Set the position
//
if (Position == (UINT64)-1) {
Position = OFile->FileSize;
}
//
// Set the position
//
@ -142,12 +144,13 @@ FatIFileReadDir (
//
FatResetODirCursor (OFile);
}
//
// We seek the next directory entry's position
//
do {
Status = FatGetNextDirEnt (OFile, &DirEnt);
if (EFI_ERROR (Status) || DirEnt == NULL) {
if (EFI_ERROR (Status) || (DirEnt == NULL)) {
//
// Something error occurred or reach the end of directory,
// return 0 buffersize
@ -156,6 +159,7 @@ FatIFileReadDir (
goto Done;
}
} while (ODir->CurrentPos <= CurrentPos);
Status = FatGetDirEntInfo (OFile->Volume, DirEnt, BufferSize, Buffer);
Done:
@ -253,6 +257,7 @@ FatIFileAccess (
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
return EFI_UNSUPPORTED;
}
Task = FatCreateTask (IFile, Token);
if (Task == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -479,6 +484,7 @@ FatAccessOFile (
if (EFI_ERROR (Status)) {
break;
}
//
// Clip length to block run
//
@ -491,6 +497,7 @@ FatAccessOFile (
if (EFI_ERROR (Status)) {
break;
}
//
// Data was successfully accessed
//
@ -501,11 +508,13 @@ FatAccessOFile (
OFile->Dirty = TRUE;
OFile->Archive = TRUE;
}
//
// Make sure no outbound occurred
//
ASSERT (Position <= OFile->FileSize);
}
//
// Update the number of bytes accessed
//

View File

@ -121,7 +121,6 @@ InitializeUnicodeCollationSupport (
IN EFI_HANDLE AgentHandle
)
{
EFI_STATUS Status;
Status = EFI_UNSUPPORTED;
@ -151,7 +150,6 @@ InitializeUnicodeCollationSupport (
return Status;
}
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@ -179,7 +177,6 @@ FatStriCmp (
);
}
/**
Uppercase a string.
@ -198,7 +195,6 @@ FatStrUpr (
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
}
/**
Lowercase a string
@ -217,7 +213,6 @@ FatStrLwr (
mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
}
/**
Convert FAT string to unicode string.
@ -243,7 +238,6 @@ FatFatToStr (
mUnicodeCollationInterface->FatToStr (mUnicodeCollationInterface, FatSize, Fat, String);
}
/**
Convert unicode string to Fat string.

View File

@ -74,7 +74,6 @@ FatFindEltoritoPartitions (
// Loop: handle one volume descriptor per time
//
while (TRUE) {
VolDescriptorLba += 1;
if (VolDescriptorLba > ParentBlockDev->LastBlock) {
//
@ -93,23 +92,27 @@ FatFindEltoritoPartitions (
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
//
@ -138,11 +143,12 @@ FatFindEltoritoPartitions (
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;
}
@ -166,7 +172,7 @@ 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;
}
@ -174,7 +180,6 @@ FatFindEltoritoPartitions (
SectorCount = Catalog->Boot.SectorCount;
switch (Catalog->Boot.MediaType) {
case ELTORITO_NO_EMULATION:
SubBlockSize = ParentBlockDev->BlockSize;
SectorCount = Catalog->Boot.SectorCount;
@ -204,11 +209,11 @@ FatFindEltoritoPartitions (
if (SectorCount < 2) {
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;
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
@ -229,5 +234,4 @@ FatFindEltoritoPartitions (
ParentBlockDev->PartitionChecked = TRUE;
return Found;
}

View File

@ -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
@ -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)
@ -156,7 +160,6 @@ FatGetBpbInfo (
// 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
@ -207,7 +209,6 @@ FatGetNextCluster (
if ((*NextCluster) >= 0x0ffffff7) {
*NextCluster |= (-1 &~0xf);
}
} else if (Volume->FatType == Fat16) {
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
@ -219,7 +220,6 @@ FatGetNextCluster (
if ((*NextCluster) >= 0xfff7) {
*NextCluster |= (-1 &~0xf);
}
} else {
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
@ -230,6 +230,7 @@ FatGetNextCluster (
} 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,16 +273,13 @@ 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);
} else {
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;
@ -291,7 +287,8 @@ FatSetFilePos (
(
!FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
) {
)
{
AlignedPos += File->Volume->ClusterSize;
Status = FatGetNextCluster (
PrivateData,
@ -330,13 +327,11 @@ FatSetFilePos (
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
File->StraightReadAmount -= (UINT32)Offset;
}
return EFI_SUCCESS;
}
/**
Reads file data. Updates the file's CurrentPos.
@ -383,12 +378,11 @@ FatReadFile (
);
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
//
@ -408,6 +402,7 @@ FatReadFile (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
//
// Advance the file's current pos and current cluster
//
@ -421,7 +416,6 @@ FatReadFile (
}
}
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@ -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,12 +467,14 @@ 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
@ -486,6 +483,7 @@ FatReadNextDirectoryEntry (
break;
}
}
//
// fill in the output parameter
//

View File

@ -33,7 +33,6 @@ BlockIoNotifyEntry (
IN VOID *Ppi
);
/**
Discover all the block I/O devices to find the FAT volume.
@ -94,6 +93,7 @@ UpdateBlocksAndVolumes (
(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,6 +130,7 @@ 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;
@ -144,6 +145,7 @@ 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;
@ -161,6 +163,7 @@ UpdateBlocksAndVolumes (
PrivateData->BlockDeviceCount++;
}
}
//
// Find out all logical devices
//
@ -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
@ -287,6 +289,7 @@ FatPeimEntry (
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Other initializations
//
@ -319,7 +322,6 @@ FatPeimEntry (
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
}
/**
Returns the number of DXE capsules residing on the device.
@ -381,7 +383,6 @@ GetNumberRecoveryCapsules (
return EFI_SUCCESS;
}
/**
Returns the size and type of the requested recovery capsule.
@ -461,6 +462,7 @@ 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
//
@ -483,6 +485,7 @@ GetRecoveryCapsuleInfo (
break;
}
}
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
case LegacyFloppy:
@ -513,7 +516,6 @@ GetRecoveryCapsuleInfo (
return EFI_NOT_FOUND;
}
/**
Loads a DXE capsule from some media into memory.
@ -572,7 +574,6 @@ LoadRecoveryCapsule (
}
if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
Status = FatReadFile (
PrivateData,
Handle,
@ -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
@ -642,6 +642,7 @@ FindRecoveryFile (
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;
}

View File

@ -75,7 +75,6 @@ typedef struct {
#pragma pack(1)
typedef struct {
UINT8 Ia32Jump[3];
CHAR8 OemId[8];
@ -97,11 +96,9 @@ typedef struct {
CHAR8 Id[4];
CHAR8 FatLabel[11];
CHAR8 SystemId[8];
} PEI_FAT_BOOT_SECTOR;
typedef struct {
UINT8 Ia32Jump[3];
CHAR8 OemId[8];
@ -130,7 +127,6 @@ typedef struct {
CHAR8 Id[4];
CHAR8 FatLabel[11];
CHAR8 SystemId[8];
} PEI_FAT_BOOT_SECTOR_EX;
#pragma pack()

View File

@ -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.
@ -29,14 +27,13 @@ ToUpper (
IN CHAR16 Letter
)
{
if ('a' <= Letter && Letter <= 'z') {
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.
@ -100,7 +97,6 @@ FatReadBlock (
Buffer
);
}
} else {
Status = FatReadDisk (
PrivateData,
@ -114,7 +110,6 @@ FatReadBlock (
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,7 +145,7 @@ 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;
}
}
@ -159,6 +154,7 @@ FatGetCacheBlock (
*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
//
@ -207,7 +204,6 @@ FatGetCacheBlock (
return Status;
}
/**
Disk reading.
@ -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.
@ -325,6 +320,7 @@ EngFatToStr (
if (*Fat == ' ') {
break;
}
*String = *Fat;
String += 1;
Fat += 1;
@ -334,7 +330,6 @@ EngFatToStr (
*String = 0;
}
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.

View File

@ -49,7 +49,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// The block device
//
typedef struct {
UINT32 BlockSize;
UINT64 LastBlock;
UINT32 IoAlign;
@ -80,7 +79,6 @@ typedef struct {
// the Volume structure
//
typedef struct {
UINTN BlockDeviceNo;
UINTN VolumeNo;
UINT64 VolumeSize;
@ -94,14 +92,12 @@ typedef struct {
UINT64 RootDirPos;
UINT32 RootEntries;
UINT32 RootDirCluster;
} PEI_FAT_VOLUME;
//
// File instance
//
typedef struct {
PEI_FAT_VOLUME *Volume;
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
@ -114,21 +110,18 @@ typedef struct {
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;
} PEI_FAT_CACHE_BUFFER;
//
@ -142,7 +135,6 @@ 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;
@ -160,7 +152,6 @@ typedef struct {
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
@ -236,7 +225,6 @@ GetNumberRecoveryCapsules (
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.
@ -274,7 +262,6 @@ GetRecoveryCapsuleInfo (
OUT EFI_GUID *CapsuleType
);
/**
Loads a DXE capsule from some media into memory.
@ -303,7 +290,6 @@ LoadRecoveryCapsule (
OUT VOID *Buffer
);
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@ -326,7 +312,6 @@ EngFatToStr (
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.
@ -368,7 +352,6 @@ FatReadBlock (
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.

View File

@ -62,7 +62,6 @@ PartitionCheckGptHeaderCRC (
return (GptHdrCrc == Crc);
}
/**
Check if the CRC field in the Partition table header is valid
for Partition entry array.
@ -134,7 +133,8 @@ PartitionCheckGptHeader (
(PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
(!PartitionCheckGptHeaderCRC (PartHdr)) ||
(PartHdr->Header.Reserved != 0)
) {
)
{
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@ -157,10 +157,11 @@ PartitionCheckGptHeader (
(PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
(PartHdr->PartitionEntryLBA < 2) ||
(PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
(PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA && PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA) ||
((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;
}
@ -250,6 +251,7 @@ PartitionCheckGptEntryArray (
if (EntryArraySizeRemainder != 0) {
PartitionEntryBlockNumb++;
}
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
PartitionEntryBuffer = (EFI_PARTITION_ENTRY *)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
@ -263,6 +265,7 @@ PartitionCheckGptEntryArray (
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
Status = FatReadBlock (
@ -290,12 +293,13 @@ PartitionCheckGptEntryArray (
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;
}
@ -313,7 +317,7 @@ PartitionCheckGptEntryArray (
continue;
}
if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {
if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
@ -328,7 +332,8 @@ PartitionCheckGptEntryArray (
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
@ -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;
}
}

View File

@ -37,12 +37,13 @@ PartitionValidMbr (
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.
//
@ -134,21 +136,22 @@ FatFindMbrPartitions (
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]);