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 // EFI Component Name Functions
// //
/** /**
Retrieves a Unicode string that is the user readable name of the driver. Retrieves a Unicode string that is the user readable name of the driver.
@ -58,7 +59,6 @@ FatComponentNameGetDriverName (
OUT CHAR16 **DriverName OUT CHAR16 **DriverName
); );
/** /**
Retrieves a Unicode string that is the user readable name of the controller Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver. 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. Retrieves a Unicode string that is the user readable name of the driver.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -220,7 +220,7 @@ FatSetVolumeInfo (
Info = (EFI_FILE_SYSTEM_INFO *)Buffer; 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; return EFI_BAD_BUFFER_SIZE;
} }
@ -312,11 +312,12 @@ FatSetFileInfo (
if (Parent == NULL) { if (Parent == NULL) {
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
// //
// Make sure there's a valid input buffer // Make sure there's a valid input buffer
// //
NewInfo = 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; return EFI_BAD_BUFFER_SIZE;
} }
@ -357,6 +358,7 @@ FatSetFileInfo (
if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) { if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) {
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
// //
// Set the current attributes even if the IFile->ReadOnly is TRUE // 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 // File was not found. We do not allow rename of the current directory if
// there are open files below the current directory // there are open files below the current directory
// //
if (!IsListEmpty (&OFile->ChildHead) || Parent == OFile) { if (!IsListEmpty (&OFile->ChildHead) || (Parent == OFile)) {
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
@ -386,6 +388,7 @@ FatSetFileInfo (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return Status; return Status;
} }
// //
// Create new dirent // Create new dirent
// //
@ -413,7 +416,7 @@ FatSetFileInfo (
ASSERT (OFile->Parent != NULL); ASSERT (OFile->Parent != NULL);
for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) { for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) {
Status = FatGetNextDirEnt (OFile, &DirEnt); Status = FatGetNextDirEnt (OFile, &DirEnt);
if (EFI_ERROR (Status) || DirEnt == NULL || !FatIsDotDirEnt (DirEnt)) { if (EFI_ERROR (Status) || (DirEnt == NULL) || !FatIsDotDirEnt (DirEnt)) {
return EFI_VOLUME_CORRUPTED; return EFI_VOLUME_CORRUPTED;
} }
@ -424,6 +427,7 @@ FatSetFileInfo (
} }
} }
} }
// //
// If the file is renamed, we should append the ARCHIVE attribute // If the file is renamed, we should append the ARCHIVE attribute
// //
@ -434,11 +438,12 @@ FatSetFileInfo (
// //
return EFI_ACCESS_DENIED; return EFI_ACCESS_DENIED;
} }
// //
// If the file size has changed, apply it // If the file size has changed, apply it
// //
if (NewInfo->FileSize != OFile->FileSize) { 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 // 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)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
// //
// Initialize cache // Initialize cache
// //
@ -75,6 +76,7 @@ FatAllocateVolume (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
// //
// Install our protocol interfaces on the device's handle // Install our protocol interfaces on the device's handle
// //
@ -87,6 +89,7 @@ FatAllocateVolume (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
// //
// Volume installed // Volume installed
// //
@ -146,6 +149,7 @@ FatAbandonVolume (
if (!EFI_ERROR (Status)) { if (!EFI_ERROR (Status)) {
LockedByMe = TRUE; LockedByMe = TRUE;
} }
// //
// The volume is still being used. Hence, set error flag for all OFiles still in // 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 // 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; SectorsPerFat = FatBs.FatBse.Fat32Bse.LargeSectorsPerFat;
FatType = Fat32; FatType = Fat32;
} }
// //
// Is boot sector a fat sector? // Is boot sector a fat sector?
// (Note that so far we only know if the sector is FAT32 or not, we don't // (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 // know if the sector is Fat16 or Fat12 until later when we can compute
// the volume size) // 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; return EFI_UNSUPPORTED;
} }
@ -251,7 +256,7 @@ FatOpenDevice (
} }
BlockAlignment = (UINT8)HighBitSet32 (FatBs.FatBsb.SectorSize); 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; return EFI_UNSUPPORTED;
} }
@ -264,13 +269,15 @@ FatOpenDevice (
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
if (FatBs.FatBsb.Media <= 0xf7 && if ((FatBs.FatBsb.Media <= 0xf7) &&
FatBs.FatBsb.Media != 0xf0 && (FatBs.FatBsb.Media != 0xf0) &&
FatBs.FatBsb.Media != 0x00 && (FatBs.FatBsb.Media != 0x00) &&
FatBs.FatBsb.Media != 0x01 (FatBs.FatBsb.Media != 0x01)
) { )
{
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Initialize fields the volume information for this FatType // Initialize fields the volume information for this FatType
// //
@ -278,6 +285,7 @@ FatOpenDevice (
if (FatBs.FatBsb.RootEntries == 0) { if (FatBs.FatBsb.RootEntries == 0) {
return EFI_UNSUPPORTED; return EFI_UNSUPPORTED;
} }
// //
// Unpack fat12, fat16 info // Unpack fat12, fat16 info
// //
@ -286,9 +294,10 @@ FatOpenDevice (
// //
// If this is fat32, refuse to mount mirror-disabled volumes // 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; return EFI_UNSUPPORTED;
} }
// //
// Unpack fat32 info // Unpack fat32 info
// //
@ -334,12 +343,14 @@ FatOpenDevice (
if (Volume->MaxCluster < FAT_MAX_FAT16_CLUSTER) { if (Volume->MaxCluster < FAT_MAX_FAT16_CLUSTER) {
return EFI_VOLUME_CORRUPTED; return EFI_VOLUME_CORRUPTED;
} }
// //
// fat32 fat-entries are 4 bytes // fat32 fat-entries are 4 bytes
// //
Volume->FatEntrySize = sizeof (UINT32); Volume->FatEntrySize = sizeof (UINT32);
DirtyMask = FAT32_DIRTY_MASK; DirtyMask = FAT32_DIRTY_MASK;
} }
// //
// Get the DirtyValue and NotDirtyValue // Get the DirtyValue and NotDirtyValue
// We should keep the initial value as the NotDirtyValue // We should keep the initial value as the NotDirtyValue
@ -353,6 +364,7 @@ FatOpenDevice (
Volume->DirtyValue = Volume->NotDirtyValue & DirtyMask; Volume->DirtyValue = Volume->NotDirtyValue & DirtyMask;
} }
// //
// If present, read the fat hint info // If present, read the fat hint info
// //
@ -360,23 +372,27 @@ FatOpenDevice (
Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize; Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize;
if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) { if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) {
FatDiskIo (Volume, ReadDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, NULL); FatDiskIo (Volume, ReadDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, NULL);
if (Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE && if ((Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE) &&
Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE && (Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE) &&
Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE && (Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE) &&
Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster (Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster)
) { )
{
Volume->FreeInfoValid = TRUE; Volume->FreeInfoValid = TRUE;
} }
} }
} }
// //
// Just make up a FreeInfo.NextCluster for use by allocate cluster // Just make up a FreeInfo.NextCluster for use by allocate cluster
// //
if (FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster || if ((FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster) ||
Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1 (Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1)
) { )
{
Volume->FatInfoSector.FreeInfo.NextCluster = FAT_MIN_CLUSTER; Volume->FatInfoSector.FreeInfo.NextCluster = FAT_MIN_CLUSTER;
} }
// //
// We are now defining FAT Type // We are now defining FAT Type
// //

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -74,7 +74,6 @@ FatFindEltoritoPartitions (
// Loop: handle one volume descriptor per time // Loop: handle one volume descriptor per time
// //
while (TRUE) { while (TRUE) {
VolDescriptorLba += 1; VolDescriptorLba += 1;
if (VolDescriptorLba > ParentBlockDev->LastBlock) { if (VolDescriptorLba > ParentBlockDev->LastBlock) {
// //
@ -93,23 +92,27 @@ FatFindEltoritoPartitions (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
break; break;
} }
// //
// Check for valid volume descriptor signature // Check for valid volume descriptor signature
// //
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END || if ((VolDescriptor->Unknown.Type == CDVOL_TYPE_END) ||
CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0 (CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0)
) { )
{
// //
// end of Volume descriptor list // end of Volume descriptor list
// //
break; break;
} }
// //
// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte // Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
// //
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) { if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1]; VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
} }
// //
// Is it an El Torito volume descriptor? // Is it an El Torito volume descriptor?
// //
@ -117,9 +120,11 @@ FatFindEltoritoPartitions (
VolDescriptor->BootRecordVolume.SystemId, VolDescriptor->BootRecordVolume.SystemId,
CDVOL_ELTORITO_ID, CDVOL_ELTORITO_ID,
sizeof (CDVOL_ELTORITO_ID) - 1 sizeof (CDVOL_ELTORITO_ID) - 1
) != 0) { ) != 0)
{
continue; continue;
} }
// //
// Read in the boot El Torito boot catalog // Read in the boot El Torito boot catalog
// //
@ -138,11 +143,12 @@ FatFindEltoritoPartitions (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
// //
// We don't care too much about the Catalog header's contents, but we do want // 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 // 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; continue;
} }
@ -166,7 +172,7 @@ FatFindEltoritoPartitions (
// //
// Check this entry // 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; continue;
} }
@ -174,7 +180,6 @@ FatFindEltoritoPartitions (
SectorCount = Catalog->Boot.SectorCount; SectorCount = Catalog->Boot.SectorCount;
switch (Catalog->Boot.MediaType) { switch (Catalog->Boot.MediaType) {
case ELTORITO_NO_EMULATION: case ELTORITO_NO_EMULATION:
SubBlockSize = ParentBlockDev->BlockSize; SubBlockSize = ParentBlockDev->BlockSize;
SectorCount = Catalog->Boot.SectorCount; SectorCount = Catalog->Boot.SectorCount;
@ -204,11 +209,11 @@ FatFindEltoritoPartitions (
if (SectorCount < 2) { 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 // Register this partition
// //
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) { if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
Found = TRUE; Found = TRUE;
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]); BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
@ -229,5 +234,4 @@ FatFindEltoritoPartitions (
ParentBlockDev->PartitionChecked = TRUE; ParentBlockDev->PartitionChecked = TRUE;
return Found; return Found;
} }

View File

@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h" #include "FatLitePeim.h"
/** /**
Check if there is a valid FAT in the corresponding Block device 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 of the volume and if yes, fill in the relevant fields for the
@ -77,60 +76,65 @@ FatGetBpbInfo (
SectorsPerFat = BpbEx.LargeSectorsPerFat; SectorsPerFat = BpbEx.LargeSectorsPerFat;
Volume->FatType = Fat32; Volume->FatType = Fat32;
} }
// //
// Filter out those not a FAT // 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; 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; return EFI_NOT_FOUND;
} }
if (Bpb.SectorsPerCluster != 1 && if ((Bpb.SectorsPerCluster != 1) &&
Bpb.SectorsPerCluster != 2 && (Bpb.SectorsPerCluster != 2) &&
Bpb.SectorsPerCluster != 4 && (Bpb.SectorsPerCluster != 4) &&
Bpb.SectorsPerCluster != 8 && (Bpb.SectorsPerCluster != 8) &&
Bpb.SectorsPerCluster != 16 && (Bpb.SectorsPerCluster != 16) &&
Bpb.SectorsPerCluster != 32 && (Bpb.SectorsPerCluster != 32) &&
Bpb.SectorsPerCluster != 64 && (Bpb.SectorsPerCluster != 64) &&
Bpb.SectorsPerCluster != 128 (Bpb.SectorsPerCluster != 128)
) { )
{
return EFI_NOT_FOUND; 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; return EFI_NOT_FOUND;
} }
if (Bpb.Media != 0xf0 && if ((Bpb.Media != 0xf0) &&
Bpb.Media != 0xf8 && (Bpb.Media != 0xf8) &&
Bpb.Media != 0xf9 && (Bpb.Media != 0xf9) &&
Bpb.Media != 0xfb && (Bpb.Media != 0xfb) &&
Bpb.Media != 0xfc && (Bpb.Media != 0xfc) &&
Bpb.Media != 0xfd && (Bpb.Media != 0xfd) &&
Bpb.Media != 0xfe && (Bpb.Media != 0xfe) &&
Bpb.Media != 0xff && (Bpb.Media != 0xff) &&
// //
// FujitsuFMR // FujitsuFMR
// //
Bpb.Media != 0x00 && (Bpb.Media != 0x00) &&
Bpb.Media != 0x01 && (Bpb.Media != 0x01) &&
Bpb.Media != 0xfa (Bpb.Media != 0xfa)
) { )
{
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
if (Volume->FatType != Fat32 && Bpb.RootEntries == 0) { if ((Volume->FatType != Fat32) && (Bpb.RootEntries == 0)) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// If this is fat32, refuse to mount mirror-disabled volumes // 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; return EFI_NOT_FOUND;
} }
// //
// Fill in the volume structure fields // Fill in the volume structure fields
// (Sectors & SectorsPerFat is computed earlier already) // (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 this is not a fat32, determine if it's a fat16 or fat12
// //
if (Volume->FatType != Fat32) { if (Volume->FatType != Fat32) {
if (Volume->MaxCluster >= 65525) { if (Volume->MaxCluster >= 65525) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
@ -167,7 +170,6 @@ FatGetBpbInfo (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Gets the next cluster in the cluster chain Gets the next cluster in the cluster chain
@ -207,7 +209,6 @@ FatGetNextCluster (
if ((*NextCluster) >= 0x0ffffff7) { if ((*NextCluster) >= 0x0ffffff7) {
*NextCluster |= (-1 &~0xf); *NextCluster |= (-1 &~0xf);
} }
} else if (Volume->FatType == Fat16) { } else if (Volume->FatType == Fat16) {
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster); FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
@ -219,7 +220,6 @@ FatGetNextCluster (
if ((*NextCluster) >= 0xfff7) { if ((*NextCluster) >= 0xfff7) {
*NextCluster |= (-1 &~0xf); *NextCluster |= (-1 &~0xf);
} }
} else { } else {
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy); FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
@ -230,6 +230,7 @@ FatGetNextCluster (
} else { } else {
*NextCluster = (*NextCluster) & 0x0fff; *NextCluster = (*NextCluster) & 0x0fff;
} }
// //
// Pad high bits for our FAT_CLUSTER_... macro definitions to work // Pad high bits for our FAT_CLUSTER_... macro definitions to work
// //
@ -243,10 +244,8 @@ FatGetNextCluster (
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount. Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@ -274,16 +273,13 @@ FatSetFilePos (
UINT32 PrevCluster; UINT32 PrevCluster;
if (File->IsFixedRootDir) { if (File->IsFixedRootDir) {
if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) { if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {
return EFI_INVALID_PARAMETER; return EFI_INVALID_PARAMETER;
} }
File->CurrentPos += Pos; File->CurrentPos += Pos;
File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos); File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
} else { } else {
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset); DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset; AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;
@ -291,7 +287,8 @@ FatSetFilePos (
( (
!FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) && !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
) { )
{
AlignedPos += File->Volume->ClusterSize; AlignedPos += File->Volume->ClusterSize;
Status = FatGetNextCluster ( Status = FatGetNextCluster (
PrivateData, PrivateData,
@ -330,13 +327,11 @@ FatSetFilePos (
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset); DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
File->StraightReadAmount -= (UINT32)Offset; File->StraightReadAmount -= (UINT32)Offset;
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Reads file data. Updates the file's CurrentPos. Reads file data. Updates the file's CurrentPos.
@ -383,12 +378,11 @@ FatReadFile (
); );
File->CurrentPos += (UINT32)Size; File->CurrentPos += (UINT32)Size;
return Status; return Status;
} else { } else {
if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) { if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos); Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
} }
// //
// This is a normal cluster based file // This is a normal cluster based file
// //
@ -408,6 +402,7 @@ FatReadFile (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Advance the file's current pos and current cluster // 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 This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0). initializes the output parameter SubFile (CurrentPos is initialized to 0).
@ -465,6 +459,7 @@ FatReadNextDirectoryEntry (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// We only search for *FILE* in root directory // We only search for *FILE* in root directory
// Long file name entry is *NOT* supported // 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)) { if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {
continue; continue;
} }
// //
// if this is a terminator dir entry, just return EFI_NOT_FOUND // if this is a terminator dir entry, just return EFI_NOT_FOUND
// //
if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) { if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
// //
// If this not an invalid entry neither an empty entry, this is what we want. // 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 // otherwise we will start a new loop to continue to find something meaningful
@ -486,6 +483,7 @@ FatReadNextDirectoryEntry (
break; break;
} }
} }
// //
// fill in the output parameter // fill in the output parameter
// //

View File

@ -33,7 +33,6 @@ BlockIoNotifyEntry (
IN VOID *Ppi IN VOID *Ppi
); );
/** /**
Discover all the block I/O devices to find the FAT volume. Discover all the block I/O devices to find the FAT volume.
@ -94,6 +93,7 @@ UpdateBlocksAndVolumes (
(VOID **)&BlockIoPpi (VOID **)&BlockIoPpi
); );
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
// //
// Done with all Block Io Ppis // Done with all Block Io Ppis
@ -114,12 +114,12 @@ UpdateBlocksAndVolumes (
&NumberBlockDevices &NumberBlockDevices
); );
} }
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
continue; continue;
} }
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) { for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
if (BlockIo2) { if (BlockIo2) {
Status = BlockIo2Ppi->GetBlockDeviceMediaInfo ( Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
PeiServices, PeiServices,
@ -130,6 +130,7 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media2.MediaPresent) { if (EFI_ERROR (Status) || !Media2.MediaPresent) {
continue; continue;
} }
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi; PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType; PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock; PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
@ -144,6 +145,7 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media.MediaPresent) { if (EFI_ERROR (Status) || !Media.MediaPresent) {
continue; continue;
} }
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi; PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType; PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock; PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
@ -161,6 +163,7 @@ UpdateBlocksAndVolumes (
PrivateData->BlockDeviceCount++; PrivateData->BlockDeviceCount++;
} }
} }
// //
// Find out all logical devices // Find out all logical devices
// //
@ -192,7 +195,6 @@ UpdateBlocksAndVolumes (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
BlockIo installation notification function. Find out all the current BlockIO BlockIo installation notification function. Find out all the current BlockIO
PPIs in the system and add them into private data. Assume there is PPIs in the system and add them into private data. Assume there is
@ -220,10 +222,10 @@ BlockIoNotifyEntry (
} else { } else {
UpdateBlocksAndVolumes (mPrivateData, FALSE); UpdateBlocksAndVolumes (mPrivateData, FALSE);
} }
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
installation notification installation notification
@ -287,6 +289,7 @@ FatPeimEntry (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
// //
// Other initializations // Other initializations
// //
@ -319,7 +322,6 @@ FatPeimEntry (
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]); return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
} }
/** /**
Returns the number of DXE capsules residing on the device. Returns the number of DXE capsules residing on the device.
@ -381,7 +383,6 @@ GetNumberRecoveryCapsules (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
/** /**
Returns the size and type of the requested recovery capsule. Returns the size and type of the requested recovery capsule.
@ -461,6 +462,7 @@ GetRecoveryCapsuleInfo (
while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) { while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) {
BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo; BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo;
} }
// //
// Fill in the Capsule Type GUID according to the block device type // Fill in the Capsule Type GUID according to the block device type
// //
@ -483,6 +485,7 @@ GetRecoveryCapsuleInfo (
break; break;
} }
} }
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) { if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) { switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
case LegacyFloppy: case LegacyFloppy:
@ -513,7 +516,6 @@ GetRecoveryCapsuleInfo (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Loads a DXE capsule from some media into memory. Loads a DXE capsule from some media into memory.
@ -572,7 +574,6 @@ LoadRecoveryCapsule (
} }
if (CapsuleInstance - 1 == RecoveryCapsuleCount) { if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
Status = FatReadFile ( Status = FatReadFile (
PrivateData, PrivateData,
Handle, Handle,
@ -588,7 +589,6 @@ LoadRecoveryCapsule (
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
/** /**
Finds the recovery file on a FAT volume. Finds the recovery file on a FAT volume.
This function finds the recovery file named FileName on a specified FAT volume and returns This function finds the recovery file named FileName on a specified FAT volume and returns
@ -642,6 +642,7 @@ FindRecoveryFile (
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR; return EFI_DEVICE_ERROR;
} }
// //
// Search for recovery capsule in root directory // Search for recovery capsule in root directory
// //
@ -671,5 +672,4 @@ FindRecoveryFile (
*Handle = File; *Handle = File;
return EFI_SUCCESS; return EFI_SUCCESS;
} }

View File

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

View File

@ -9,10 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h" #include "FatLitePeim.h"
#define CHAR_FAT_VALID 0x01 #define CHAR_FAT_VALID 0x01
/** /**
Converts a union code character to upper case. Converts a union code character to upper case.
This functions converts a unicode character to upper case. This functions converts a unicode character to upper case.
@ -29,14 +27,13 @@ ToUpper (
IN CHAR16 Letter IN CHAR16 Letter
) )
{ {
if ('a' <= Letter && Letter <= 'z') { if (('a' <= Letter) && (Letter <= 'z')) {
Letter = (CHAR16)(Letter - 0x20); Letter = (CHAR16)(Letter - 0x20);
} }
return Letter; return Letter;
} }
/** /**
Reads a block of data from the block device by calling Reads a block of data from the block device by calling
underlying Block I/O service. underlying Block I/O service.
@ -100,7 +97,6 @@ FatReadBlock (
Buffer Buffer
); );
} }
} else { } else {
Status = FatReadDisk ( Status = FatReadDisk (
PrivateData, PrivateData,
@ -114,7 +110,6 @@ FatReadBlock (
return Status; return Status;
} }
/** /**
Find a cache block designated to specific Block device and Lba. Find a cache block designated to specific Block device and Lba.
If not found, invalidate an oldest one and use it. (LRU cache) 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++) { for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {
CacheBuffer = &(PrivateData->CacheBuffer[Index]); CacheBuffer = &(PrivateData->CacheBuffer[Index]);
if (CacheBuffer->Valid && CacheBuffer->BlockDeviceNo == BlockDeviceNo && CacheBuffer->Lba == Lba) { if (CacheBuffer->Valid && (CacheBuffer->BlockDeviceNo == BlockDeviceNo) && (CacheBuffer->Lba == Lba)) {
break; break;
} }
} }
@ -159,6 +154,7 @@ FatGetCacheBlock (
*CachePtr = (CHAR8 *)CacheBuffer->Buffer; *CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return EFI_SUCCESS; return EFI_SUCCESS;
} }
// //
// We have to find an invalid cache buffer // We have to find an invalid cache buffer
// //
@ -167,6 +163,7 @@ FatGetCacheBlock (
break; break;
} }
} }
// //
// Use the cache buffer // Use the cache buffer
// //
@ -207,7 +204,6 @@ FatGetCacheBlock (
return Status; return Status;
} }
/** /**
Disk reading. Disk reading.
@ -292,7 +288,6 @@ FatReadDisk (
return Status; return Status;
} }
/** /**
This version is different from the version in Unicode collation This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks. protocol in that this version strips off trailing blanks.
@ -325,6 +320,7 @@ EngFatToStr (
if (*Fat == ' ') { if (*Fat == ' ') {
break; break;
} }
*String = *Fat; *String = *Fat;
String += 1; String += 1;
Fat += 1; Fat += 1;
@ -334,7 +330,6 @@ EngFatToStr (
*String = 0; *String = 0;
} }
/** /**
Performs a case-insensitive comparison of two Null-terminated Unicode strings. 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 // The block device
// //
typedef struct { typedef struct {
UINT32 BlockSize; UINT32 BlockSize;
UINT64 LastBlock; UINT64 LastBlock;
UINT32 IoAlign; UINT32 IoAlign;
@ -80,7 +79,6 @@ typedef struct {
// the Volume structure // the Volume structure
// //
typedef struct { typedef struct {
UINTN BlockDeviceNo; UINTN BlockDeviceNo;
UINTN VolumeNo; UINTN VolumeNo;
UINT64 VolumeSize; UINT64 VolumeSize;
@ -94,14 +92,12 @@ typedef struct {
UINT64 RootDirPos; UINT64 RootDirPos;
UINT32 RootEntries; UINT32 RootEntries;
UINT32 RootDirCluster; UINT32 RootDirCluster;
} PEI_FAT_VOLUME; } PEI_FAT_VOLUME;
// //
// File instance // File instance
// //
typedef struct { typedef struct {
PEI_FAT_VOLUME *Volume; PEI_FAT_VOLUME *Volume;
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH]; CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
@ -114,21 +110,18 @@ typedef struct {
UINT8 Attributes; UINT8 Attributes;
UINT32 FileSize; UINT32 FileSize;
} PEI_FAT_FILE; } PEI_FAT_FILE;
// //
// Cache Buffer // Cache Buffer
// //
typedef struct { typedef struct {
BOOLEAN Valid; BOOLEAN Valid;
UINTN BlockDeviceNo; UINTN BlockDeviceNo;
UINT64 Lba; UINT64 Lba;
UINT32 Lru; UINT32 Lru;
UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8]; UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
UINTN Size; UINTN Size;
} PEI_FAT_CACHE_BUFFER; } PEI_FAT_CACHE_BUFFER;
// //
@ -142,7 +135,6 @@ typedef struct {
#define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't') #define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
typedef struct { typedef struct {
UINTN Signature; UINTN Signature;
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi; EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
EFI_PEI_PPI_DESCRIPTOR PpiDescriptor; EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
@ -160,7 +152,6 @@ typedef struct {
PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME]; PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
PEI_FAT_FILE File; PEI_FAT_FILE File;
PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE]; PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
} PEI_FAT_PRIVATE_DATA; } PEI_FAT_PRIVATE_DATA;
#define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \ #define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
@ -178,7 +169,6 @@ typedef struct {
#define UNPACK_UINT32(a) \ #define UNPACK_UINT32(a) \
(UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24)) (UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
// //
// API functions // API functions
// //
@ -209,7 +199,6 @@ FindRecoveryFile (
OUT PEI_FILE_HANDLE *Handle OUT PEI_FILE_HANDLE *Handle
); );
/** /**
Returns the number of DXE capsules residing on the device. Returns the number of DXE capsules residing on the device.
This function, by whatever mechanism, searches for DXE capsules from the associated device and This function, by whatever mechanism, searches for DXE capsules from the associated device and
@ -236,7 +225,6 @@ GetNumberRecoveryCapsules (
OUT UINTN *NumberRecoveryCapsules OUT UINTN *NumberRecoveryCapsules
); );
/** /**
Returns the size and type of the requested recovery capsule. Returns the size and type of the requested recovery capsule.
This function returns the size and type of the capsule specified by CapsuleInstance. This function returns the size and type of the capsule specified by CapsuleInstance.
@ -274,7 +262,6 @@ GetRecoveryCapsuleInfo (
OUT EFI_GUID *CapsuleType OUT EFI_GUID *CapsuleType
); );
/** /**
Loads a DXE capsule from some media into memory. Loads a DXE capsule from some media into memory.
@ -303,7 +290,6 @@ LoadRecoveryCapsule (
OUT VOID *Buffer OUT VOID *Buffer
); );
/** /**
This version is different from the version in Unicode collation This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks. protocol in that this version strips off trailing blanks.
@ -326,7 +312,6 @@ EngFatToStr (
OUT CHAR16 *Str OUT CHAR16 *Str
); );
/** /**
Performs a case-insensitive comparison of two Null-terminated Unicode strings. Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@ -342,7 +327,6 @@ EngStriColl (
IN CHAR16 *Str2 IN CHAR16 *Str2
); );
/** /**
Reads a block of data from the block device by calling Reads a block of data from the block device by calling
underlying Block I/O service. underlying Block I/O service.
@ -368,7 +352,6 @@ FatReadBlock (
OUT VOID *Buffer OUT VOID *Buffer
); );
/** /**
Check if there is a valid FAT in the corresponding Block device 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 of the volume and if yes, fill in the relevant fields for the
@ -394,7 +377,6 @@ FatGetBpbInfo (
IN OUT PEI_FAT_VOLUME *Volume IN OUT PEI_FAT_VOLUME *Volume
); );
/** /**
Gets the next cluster in the cluster chain. Gets the next cluster in the cluster chain.
@ -416,7 +398,6 @@ FatGetNextCluster (
OUT UINT32 *NextCluster OUT UINT32 *NextCluster
); );
/** /**
Disk reading. Disk reading.
@ -439,7 +420,6 @@ FatReadDisk (
OUT VOID *Buffer OUT VOID *Buffer
); );
/** /**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount. Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@ -460,7 +440,6 @@ FatSetFilePos (
IN UINT32 Pos IN UINT32 Pos
); );
/** /**
Reads file data. Updates the file's CurrentPos. Reads file data. Updates the file's CurrentPos.
@ -482,7 +461,6 @@ FatReadFile (
OUT VOID *Buffer OUT VOID *Buffer
); );
/** /**
This function reads the next item in the parent directory and This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0). initializes the output parameter SubFile (CurrentPos is initialized to 0).
@ -507,7 +485,6 @@ FatReadNextDirectoryEntry (
OUT PEI_FAT_FILE *SubFile OUT PEI_FAT_FILE *SubFile
); );
/** /**
This function finds partitions (logical devices) in physical block devices. This function finds partitions (logical devices) in physical block devices.

View File

@ -62,7 +62,6 @@ PartitionCheckGptHeaderCRC (
return (GptHdrCrc == Crc); return (GptHdrCrc == Crc);
} }
/** /**
Check if the CRC field in the Partition table header is valid Check if the CRC field in the Partition table header is valid
for Partition entry array. for Partition entry array.
@ -134,7 +133,8 @@ PartitionCheckGptHeader (
(PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) || (PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
(!PartitionCheckGptHeaderCRC (PartHdr)) || (!PartitionCheckGptHeaderCRC (PartHdr)) ||
(PartHdr->Header.Reserved != 0) (PartHdr->Header.Reserved != 0)
) { )
{
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n")); DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE; return FALSE;
} }
@ -157,10 +157,11 @@ PartitionCheckGptHeader (
(PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) || (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
(PartHdr->PartitionEntryLBA < 2) || (PartHdr->PartitionEntryLBA < 2) ||
(PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) || (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%128 != 0) ||
(PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY)) (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
) { )
{
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n")); DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE; return FALSE;
} }
@ -250,6 +251,7 @@ PartitionCheckGptEntryArray (
if (EntryArraySizeRemainder != 0) { if (EntryArraySizeRemainder != 0) {
PartitionEntryBlockNumb++; PartitionEntryBlockNumb++;
} }
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize); 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));
@ -263,6 +265,7 @@ PartitionCheckGptEntryArray (
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n")); DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT; goto EXIT;
} }
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)); ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
Status = FatReadBlock ( Status = FatReadBlock (
@ -290,12 +293,13 @@ PartitionCheckGptEntryArray (
StartingLBA = Entry->StartingLBA; StartingLBA = Entry->StartingLBA;
EndingLBA = Entry->EndingLBA; EndingLBA = Entry->EndingLBA;
if (StartingLBA > EndingLBA || if ((StartingLBA > EndingLBA) ||
StartingLBA < PartHdr->FirstUsableLBA || (StartingLBA < PartHdr->FirstUsableLBA) ||
StartingLBA > PartHdr->LastUsableLBA || (StartingLBA > PartHdr->LastUsableLBA) ||
EndingLBA < PartHdr->FirstUsableLBA || (EndingLBA < PartHdr->FirstUsableLBA) ||
EndingLBA > PartHdr->LastUsableLBA (EndingLBA > PartHdr->LastUsableLBA)
) { )
{
PartitionEntryStatus[Index1].OutOfRange = TRUE; PartitionEntryStatus[Index1].OutOfRange = TRUE;
continue; continue;
} }
@ -313,7 +317,7 @@ PartitionCheckGptEntryArray (
continue; continue;
} }
if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) { if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
// //
// This region overlaps with the Index1'th region // This region overlaps with the Index1'th region
// //
@ -328,7 +332,8 @@ PartitionCheckGptEntryArray (
if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) || if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
PartitionEntryStatus[Index].OutOfRange || PartitionEntryStatus[Index].OutOfRange ||
PartitionEntryStatus[Index].Overlap || PartitionEntryStatus[Index].Overlap ||
PartitionEntryStatus[Index].OsSpecific) { PartitionEntryStatus[Index].OsSpecific)
{
// //
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
// partition Entries // partition Entries
@ -482,11 +487,12 @@ PartitionCheckProtectiveMbr (
// //
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) { for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index]; MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
if (MbrPartition->BootIndicator == 0x00 && if ((MbrPartition->BootIndicator == 0x00) &&
MbrPartition->StartSector == 0x02 && (MbrPartition->StartSector == 0x02) &&
MbrPartition->OSIndicator == PMBR_GPT_PARTITION && (MbrPartition->OSIndicator == PMBR_GPT_PARTITION) &&
UNPACK_UINT32 (MbrPartition->StartingLBA) == 1 (UNPACK_UINT32 (MbrPartition->StartingLBA) == 1)
) { )
{
return TRUE; return TRUE;
} }
} }

View File

@ -37,12 +37,13 @@ PartitionValidMbr (
if (Mbr->Signature != MBR_SIGNATURE) { if (Mbr->Signature != MBR_SIGNATURE) {
return FALSE; return FALSE;
} }
// //
// The BPB also has this signature, so it can not be used alone. // The BPB also has this signature, so it can not be used alone.
// //
MbrValid = FALSE; MbrValid = FALSE;
for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) { 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; continue;
} }
@ -65,12 +66,12 @@ PartitionValidMbr (
} }
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) { 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; continue;
} }
NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1; 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 // This region overlaps with the Index1'th region
// //
@ -78,6 +79,7 @@ PartitionValidMbr (
} }
} }
} }
// //
// Non of the regions overlapped so MBR is O.K. // Non of the regions overlapped so MBR is O.K.
// //
@ -134,21 +136,22 @@ FatFindMbrPartitions (
if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev->LastBlock)) { if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev->LastBlock)) {
goto Done; goto Done;
} }
// //
// We have a valid mbr - add each partition // We have a valid mbr - add each partition
// //
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) { 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 // Don't use null MBR entries
// //
continue; continue;
} }
// //
// Register this partition // Register this partition
// //
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) { if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
Found = TRUE; Found = TRUE;
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]); BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);