FatPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the FatPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:53:58 -08:00
committed by mergify[bot]
parent a550d468a6
commit bcdcc4160d
30 changed files with 2153 additions and 2047 deletions

View File

@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// EFI Component Name Functions
//
/**
Retrieves a Unicode string that is the user readable name of the driver.
@ -58,7 +59,6 @@ FatComponentNameGetDriverName (
OUT CHAR16 **DriverName
);
/**
Retrieves a Unicode string that is the user readable name of the controller
that is being managed by a driver.
@ -150,8 +150,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gFatComponentName = {
// EFI Component Name 2 Protocol
//
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) FatComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) FatComponentNameGetControllerName,
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)FatComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)FatComponentNameGetControllerName,
"en"
};
@ -177,7 +177,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[]
}
};
/**
Retrieves a Unicode string that is the user readable name of the driver.

View File

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

View File

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

View File

@ -39,8 +39,8 @@ FatAccessEntry (
// End of directory
//
ASSERT (IoMode == ReadData);
((FAT_DIRECTORY_ENTRY *) Entry)->FileName[0] = EMPTY_ENTRY_MARK;
((FAT_DIRECTORY_ENTRY *) Entry)->Attributes = 0;
((FAT_DIRECTORY_ENTRY *)Entry)->FileName[0] = EMPTY_ENTRY_MARK;
((FAT_DIRECTORY_ENTRY *)Entry)->Attributes = 0;
return EFI_SUCCESS;
}
@ -145,8 +145,9 @@ FatIsDotDirEnt (
)
{
CHAR16 *FileString;
FileString = DirEnt->FileString;
if (StrCmp (FileString, L".") == 0 || StrCmp (FileString, L"..") == 0) {
if ((StrCmp (FileString, L".") == 0) || (StrCmp (FileString, L"..") == 0)) {
return TRUE;
}
@ -171,8 +172,8 @@ FatSetDirEntCluster (
DirEnt = OFile->DirEnt;
Cluster = OFile->FileCluster;
DirEnt->Entry.FileClusterHigh = (UINT16) (Cluster >> 16);
DirEnt->Entry.FileCluster = (UINT16) Cluster;
DirEnt->Entry.FileClusterHigh = (UINT16)(Cluster >> 16);
DirEnt->Entry.FileCluster = (UINT16)Cluster;
}
/**
@ -188,7 +189,7 @@ FatUpdateDirEntClusterSizeInfo (
)
{
ASSERT (OFile->ODir == NULL);
OFile->DirEnt->Entry.FileSize = (UINT32) OFile->FileSize;
OFile->DirEnt->Entry.FileSize = (UINT32)OFile->FileSize;
FatSetDirEntCluster (OFile);
}
@ -208,8 +209,9 @@ FatCloneDirEnt (
{
UINT8 *Entry1;
UINT8 *Entry2;
Entry1 = (UINT8 *) &DirEnt1->Entry;
Entry2 = (UINT8 *) &DirEnt2->Entry;
Entry1 = (UINT8 *)&DirEnt1->Entry;
Entry2 = (UINT8 *)&DirEnt2->Entry;
CopyMem (
Entry1 + FAT_ENTRY_INFO_OFFSET,
Entry2 + FAT_ENTRY_INFO_OFFSET,
@ -258,12 +260,13 @@ FatLoadLongNameEntry (
EntryPos--;
Status = FatAccessEntry (Parent, ReadData, EntryPos, &LfnEntry);
if (EFI_ERROR (Status) ||
LfnEntry.Attributes != FAT_ATTRIBUTE_LFN ||
LfnEntry.MustBeZero != 0 ||
LfnEntry.Checksum != LfnChecksum ||
(LfnEntry.Ordinal & (~FAT_LFN_LAST)) != LfnOrdinal ||
LfnOrdinal > MAX_LFN_ENTRIES
) {
(LfnEntry.Attributes != FAT_ATTRIBUTE_LFN) ||
(LfnEntry.MustBeZero != 0) ||
(LfnEntry.Checksum != LfnChecksum) ||
((LfnEntry.Ordinal & (~FAT_LFN_LAST)) != LfnOrdinal) ||
(LfnOrdinal > MAX_LFN_ENTRIES)
)
{
//
// The directory entry does not have a long file name or
// some error occurs when loading long file name for a directory entry,
@ -281,6 +284,7 @@ FatLoadLongNameEntry (
LfnBufferPointer += LFN_CHAR3_LEN;
LfnOrdinal++;
} while ((LfnEntry.Ordinal & FAT_LFN_LAST) == 0);
DirEnt->EntryCount = LfnOrdinal;
//
// Terminate current Lfnbuffer
@ -319,6 +323,7 @@ FatAddDirEnt (
if (DirEnt->Link.BackLink == NULL) {
DirEnt->Link.BackLink = &ODir->ChildList;
}
InsertTailList (DirEnt->Link.BackLink, &DirEnt->Link);
FatInsertToHashTable (ODir, DirEnt);
}
@ -358,7 +363,7 @@ FatLoadNextDirEnt (
ASSERT (!ODir->EndOfDir);
DirEnt = NULL;
for (;;) {
for ( ; ;) {
//
// Read the next directory entry until we find a valid directory entry (excluding lfn entry)
//
@ -367,7 +372,7 @@ FatLoadNextDirEnt (
return Status;
}
if (((UINT8) Entry.FileName[0] != DELETE_ENTRY_MARK) && (Entry.Attributes & FAT_ATTRIBUTE_VOLUME_ID) == 0) {
if (((UINT8)Entry.FileName[0] != DELETE_ENTRY_MARK) && ((Entry.Attributes & FAT_ATTRIBUTE_VOLUME_ID) == 0)) {
//
// We get a valid directory entry, then handle it
//
@ -398,13 +403,14 @@ FatLoadNextDirEnt (
//
// Remember the directory's entry position on disk
//
DirEnt->EntryPos = (UINT16) ODir->CurrentEndPos;
DirEnt->EntryPos = (UINT16)ODir->CurrentEndPos;
CopyMem (&DirEnt->Entry, &Entry, sizeof (FAT_DIRECTORY_ENTRY));
FatLoadLongNameEntry (OFile, DirEnt);
if (DirEnt->FileString == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
//
// Add this directory entry to directory
//
@ -482,7 +488,7 @@ FatGetDirEntInfo (
FatFatTimeToEfiTime (&Entry->FileCreateTime, &Info->CreateTime);
FatFatTimeToEfiTime (&Entry->FileModificationTime, &Info->ModificationTime);
Info->Attribute = Entry->Attributes & EFI_FILE_VALID_ATTR;
CopyMem ((CHAR8 *) Buffer + Size, DirEnt->FileString, NameSize);
CopyMem ((CHAR8 *)Buffer + Size, DirEnt->FileString, NameSize);
}
*BufferSize = ResultSize;
@ -525,9 +531,10 @@ FatSearchODir (
// Search the hash table first
//
DirEnt = *FatLongNameHashSearch (ODir, FileNameString);
if (DirEnt == NULL && PossibleShortName) {
if ((DirEnt == NULL) && PossibleShortName) {
DirEnt = *FatShortNameHashSearch (ODir, File8Dot3Name);
}
if (DirEnt == NULL) {
//
// We fail to get the directory entry from hash table; we then
@ -544,7 +551,7 @@ FatSearchODir (
break;
}
if (PossibleShortName && CompareMem (File8Dot3Name, DirEnt->Entry.FileName, FAT_NAME_LEN) == 0) {
if (PossibleShortName && (CompareMem (File8Dot3Name, DirEnt->Entry.FileName, FAT_NAME_LEN) == 0)) {
break;
}
}
@ -736,8 +743,8 @@ FatSeekVolumeId (
return Status;
}
if (((UINT8) Entry->FileName[0] != DELETE_ENTRY_MARK) && (((Entry->Attributes) & (~FAT_ATTRIBUTE_ARCHIVE)) == FAT_ATTRIBUTE_VOLUME_ID)) {
DirEnt->EntryPos = (UINT16) EntryPos;
if (((UINT8)Entry->FileName[0] != DELETE_ENTRY_MARK) && (((Entry->Attributes) & (~FAT_ATTRIBUTE_ARCHIVE)) == FAT_ATTRIBUTE_VOLUME_ID)) {
DirEnt->EntryPos = (UINT16)EntryPos;
DirEnt->EntryCount = 1;
DirEnt->Invalid = FALSE;
break;
@ -745,6 +752,7 @@ FatSeekVolumeId (
EntryPos++;
} while (Entry->FileName[0] != EMPTY_ENTRY_MARK);
return EFI_SUCCESS;
}
@ -799,10 +807,11 @@ FatFirstFitInsertDirEnt (
for (CurrentEntry = ODir->ChildList.ForwardLink;
CurrentEntry != &ODir->ChildList;
CurrentEntry = CurrentEntry->ForwardLink
) {
)
{
CurrentDirEnt = DIRENT_FROM_LINK (CurrentEntry);
if (NewEntryPos + CurrentDirEnt->EntryCount <= CurrentDirEnt->EntryPos) {
if (LabelPos > NewEntryPos || LabelPos <= CurrentPos) {
if ((LabelPos > NewEntryPos) || (LabelPos <= CurrentPos)) {
//
// first fit succeeded
//
@ -819,7 +828,7 @@ FatFirstFitInsertDirEnt (
}
Done:
DirEnt->EntryPos = (UINT16) NewEntryPos;
DirEnt->EntryPos = (UINT16)NewEntryPos;
DirEnt->Link.BackLink = CurrentEntry;
return EFI_SUCCESS;
}
@ -859,6 +868,7 @@ FatNewEntryPos (
return Status;
}
}
//
// We will append this entry to the end of directory
//
@ -873,6 +883,7 @@ FatNewEntryPos (
//
return FatFirstFitInsertDirEnt (OFile, DirEnt);
}
//
// We should allocate a new cluster for this directory
//
@ -881,11 +892,12 @@ FatNewEntryPos (
return Status;
}
}
//
// We append our directory entry at the end of directory file
//
ODir->CurrentEndPos = NewEndPos;
DirEnt->EntryPos = (UINT16) (ODir->CurrentEndPos - 1);
DirEnt->EntryPos = (UINT16)(ODir->CurrentEndPos - 1);
return EFI_SUCCESS;
}
@ -1002,6 +1014,7 @@ FatCreateDotDirEnts (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Create ".."
//
@ -1049,6 +1062,7 @@ FatCreateDirEnt (
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
//
// Determine how many directory entries we need
//
@ -1098,6 +1112,7 @@ FatRemoveDirEnt (
//
ODir->CurrentCursor = ODir->CurrentCursor->BackLink;
}
//
// Remove from directory entry list
//
@ -1280,6 +1295,7 @@ FatLocateOFile (
if (FileName[FileNameLen - 1] == PATH_NAME_SEPARATOR) {
DirIntended = TRUE;
}
//
// If name starts with path name separator, then move to root OFile
//
@ -1288,6 +1304,7 @@ FatLocateOFile (
FileName++;
FileNameLen--;
}
//
// Per FAT Spec the file name should meet the following criteria:
// C1. Length (FileLongName) <= 255
@ -1300,11 +1317,12 @@ FatLocateOFile (
//
return EFI_INVALID_PARAMETER;
}
//
// Start at current location
//
Next = FileName;
for (;;) {
for ( ; ;) {
//
// Get the next component name
//
@ -1315,19 +1333,21 @@ FatLocateOFile (
// If end of the file name, we're done
//
if (ComponentName[0] == 0) {
if (DirIntended && OFile->ODir == NULL) {
if (DirIntended && (OFile->ODir == NULL)) {
return EFI_NOT_FOUND;
}
NewFileName[0] = 0;
break;
}
//
// If "dot", then current
//
if (StrCmp (ComponentName, L".") == 0) {
continue;
}
//
// If "dot dot", then parent
//
@ -1335,6 +1355,7 @@ FatLocateOFile (
if (OFile->Parent == NULL) {
return EFI_INVALID_PARAMETER;
}
OFile = OFile->Parent;
continue;
}
@ -1342,6 +1363,7 @@ FatLocateOFile (
if (!FatFileNameIsValid (ComponentName, NewFileName)) {
return EFI_INVALID_PARAMETER;
}
//
// We have a component name, try to open it
//
@ -1351,6 +1373,7 @@ FatLocateOFile (
//
return EFI_NOT_FOUND;
}
//
// Search the compName in the directory
//
@ -1367,9 +1390,10 @@ FatLocateOFile (
return EFI_NOT_FOUND;
}
if (DirIntended && (Attributes & FAT_ATTRIBUTE_DIRECTORY) == 0) {
if (DirIntended && ((Attributes & FAT_ATTRIBUTE_DIRECTORY) == 0)) {
return EFI_INVALID_PARAMETER;
}
//
// It's the last component name - return with the open
// path and the remaining name

View File

@ -55,7 +55,7 @@ FatFlushDataCacheRange (
for (PageNo = StartPageNo; PageNo < EndPageNo; PageNo++) {
GroupNo = PageNo & GroupMask;
CacheTag = &DiskCache->CacheTag[GroupNo];
if (CacheTag->RealSize > 0 && CacheTag->PageNo == PageNo) {
if ((CacheTag->RealSize > 0) && (CacheTag->PageNo == PageNo)) {
//
// When reading data form disk directly, if some dirty data
// in cache is in this rang, this data in the Buffer need to
@ -126,12 +126,12 @@ FatExchangeCachePage (
MaxSize = DiskCache->LimitAddress - EntryPos;
if (MaxSize < RealSize) {
DEBUG ((DEBUG_INFO, "FatDiskIo: Cache Page OutBound occurred! \n"));
RealSize = (UINTN) MaxSize;
RealSize = (UINTN)MaxSize;
}
}
WriteCount = 1;
if (DataType == CacheFat && IoMode == WriteDisk) {
if ((DataType == CacheFat) && (IoMode == WriteDisk)) {
WriteCount = Volume->NumFats;
}
@ -178,7 +178,7 @@ FatGetCachePage (
UINTN OldPageNo;
OldPageNo = CacheTag->PageNo;
if (CacheTag->RealSize > 0 && OldPageNo == PageNo) {
if ((CacheTag->RealSize > 0) && (OldPageNo == PageNo)) {
//
// Cache Hit occurred
//
@ -188,12 +188,13 @@ FatGetCachePage (
//
// Write dirty cache page back to disk
//
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {
if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, NULL);
if (EFI_ERROR (Status)) {
return Status;
}
}
//
// Load new data from disk;
//
@ -319,8 +320,8 @@ FatAccessCache (
EntryPos = Offset - DiskCache->BaseAddress;
PageAlignment = DiskCache->PageAlignment;
PageSize = (UINTN)1 << PageAlignment;
PageNo = (UINTN) RShiftU64 (EntryPos, PageAlignment);
UnderRun = ((UINTN) EntryPos) & (PageSize - 1);
PageNo = (UINTN)RShiftU64 (EntryPos, PageAlignment);
UnderRun = ((UINTN)EntryPos) & (PageSize - 1);
if (UnderRun > 0) {
Length = PageSize - UnderRun;
@ -355,6 +356,7 @@ FatAccessCache (
if (EFI_ERROR (Status)) {
return Status;
}
//
// If these access data over laps the relative cache range, these cache pages need
// to be updated.
@ -363,6 +365,7 @@ FatAccessCache (
Buffer += AlignedSize;
BufferSize -= AlignedSize;
}
//
// The access of the OverRun data
//
@ -401,7 +404,7 @@ FatVolumeFlushCache (
DISK_CACHE *DiskCache;
CACHE_TAG *CacheTag;
for (CacheDataType = (CACHE_DATA_TYPE) 0; CacheDataType < CacheMaxType; CacheDataType++) {
for (CacheDataType = (CACHE_DATA_TYPE)0; CacheDataType < CacheMaxType; CacheDataType++) {
DiskCache = &Volume->DiskCache[CacheDataType];
if (DiskCache->Dirty) {
//
@ -410,7 +413,7 @@ FatVolumeFlushCache (
GroupMask = DiskCache->GroupMask;
for (GroupIndex = 0; GroupIndex <= GroupMask; GroupIndex++) {
CacheTag = &DiskCache->CacheTag[GroupIndex];
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {
if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
//
// Write back all Dirty Data Cache Page to disk
//
@ -424,6 +427,7 @@ FatVolumeFlushCache (
DiskCache->Dirty = FALSE;
}
}
//
// Flush the block device.
//

View File

@ -224,14 +224,17 @@ FatUnload (
if (ComponentName2 == NULL) {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
NULL
);
} else {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiComponentName2ProtocolGuid, ComponentName2,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
&gEfiComponentName2ProtocolGuid,
ComponentName2,
NULL
);
}
@ -239,16 +242,21 @@ FatUnload (
if (ComponentName2 == NULL) {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiComponentNameProtocolGuid, ComponentName,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
&gEfiComponentNameProtocolGuid,
ComponentName,
NULL
);
} else {
Status = gBS->UninstallMultipleProtocolInterfaces (
ImageHandle,
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
&gEfiComponentNameProtocolGuid, ComponentName,
&gEfiComponentName2ProtocolGuid, ComponentName2,
&gEfiDriverBindingProtocolGuid,
&gFatDriverBinding,
&gEfiComponentNameProtocolGuid,
ComponentName,
&gEfiComponentName2ProtocolGuid,
ComponentName2,
NULL
);
}
@ -293,7 +301,7 @@ FatDriverBindingSupported (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,
(VOID **) &DiskIo,
(VOID **)&DiskIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
@ -302,6 +310,7 @@ FatDriverBindingSupported (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Close the I/O Abstraction(s) used to perform the supported test
//
@ -371,13 +380,14 @@ FatDriverBindingStart (
if (EFI_ERROR (Status)) {
goto Exit;
}
//
// Open our required BlockIo and DiskIo
//
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiBlockIoProtocolGuid,
(VOID **) &BlockIo,
(VOID **)&BlockIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -389,7 +399,7 @@ FatDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,
(VOID **) &DiskIo,
(VOID **)&DiskIo,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
@ -401,7 +411,7 @@ FatDriverBindingStart (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiDiskIo2ProtocolGuid,
(VOID **) &DiskIo2,
(VOID **)&DiskIo2,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
@ -453,6 +463,7 @@ Exit:
if (LockedByMe) {
FatReleaseLock ();
}
return Status;
}
@ -490,7 +501,7 @@ FatDriverBindingStop (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID **) &FileSystem,
(VOID **)&FileSystem,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -512,6 +523,7 @@ FatDriverBindingStop (
);
ASSERT_EFI_ERROR (Status);
}
Status = gBS->CloseProtocol (
ControllerHandle,
&gEfiDiskIoProtocolGuid,

View File

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

View File

@ -42,7 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define FAT_POS_FAT32(a) ((a) * 4)
#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
//
// FAT attribute define
//
@ -134,7 +133,7 @@ typedef struct {
typedef union {
FAT_BOOT_SECTOR_EXT FatBse;
FAT32_BOOT_SECTOR_EXT Fat32Bse;
} FAT_BSE;
} FAT_BSE;
typedef struct {
FAT_BOOT_SECTOR_BASIC FatBsb;

View File

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

View File

@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "Fat.h"
/**
Get the FAT entry of the volume, which is identified with the Index.
@ -32,9 +31,10 @@ FatLoadFatEntry (
EFI_STATUS Status;
if (Index > (Volume->MaxCluster + 1)) {
Volume->FatEntryBuffer = (UINT32) -1;
Volume->FatEntryBuffer = (UINT32)-1;
return &Volume->FatEntryBuffer;
}
//
// Compute buffer position needed
//
@ -50,6 +50,7 @@ FatLoadFatEntry (
default:
Pos = FAT_POS_FAT32 (Index);
}
//
// Set the position and read the buffer
//
@ -63,7 +64,7 @@ FatLoadFatEntry (
NULL
);
if (EFI_ERROR (Status)) {
Volume->FatEntryBuffer = (UINT32) -1;
Volume->FatEntryBuffer = (UINT32)-1;
}
return &Volume->FatEntryBuffer;
@ -95,7 +96,7 @@ FatGetFatEntry (
Pos = FatLoadFatEntry (Volume, Index);
if (Index > (Volume->MaxCluster + 1)) {
return (UINTN) -1;
return (UINTN)-1;
}
switch (Volume->FatType) {
@ -155,16 +156,17 @@ FatSetFatEntry (
}
OriginalVal = FatGetFatEntry (Volume, Index);
if (Value == FAT_CLUSTER_FREE && OriginalVal != FAT_CLUSTER_FREE) {
if ((Value == FAT_CLUSTER_FREE) && (OriginalVal != FAT_CLUSTER_FREE)) {
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
if (Index < Volume->FatInfoSector.FreeInfo.NextCluster) {
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32) Index;
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32)Index;
}
} else if (Value != FAT_CLUSTER_FREE && OriginalVal == FAT_CLUSTER_FREE) {
} else if ((Value != FAT_CLUSTER_FREE) && (OriginalVal == FAT_CLUSTER_FREE)) {
if (Volume->FatInfoSector.FreeInfo.ClusterCount != 0) {
Volume->FatInfoSector.FreeInfo.ClusterCount -= 1;
}
}
//
// Make sure the entry is in memory
//
@ -185,26 +187,28 @@ FatSetFatEntry (
Accum = Value | (Accum & FAT_CLUSTER_UNMASK_FAT12);
}
En12[0] = (UINT8) (Accum & 0xFF);
En12[1] = (UINT8) (Accum >> 8);
En12[0] = (UINT8)(Accum & 0xFF);
En12[1] = (UINT8)(Accum >> 8);
break;
case Fat16:
En16 = Pos;
*En16 = (UINT16) Value;
*En16 = (UINT16)Value;
break;
default:
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 (!Volume->FatDirty && Volume->FatType != Fat12) {
if (!Volume->FatDirty && (Volume->FatType != Fat12)) {
Volume->FatDirty = TRUE;
FatAccessVolumeDirty (Volume, WriteFat, &Volume->DirtyValue);
}
//
// Write the updated fat entry value to the volume
// The fat is the first fat, and other fat will be in sync
@ -242,8 +246,7 @@ FatFreeClusters (
UINTN LastCluster;
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
return EFI_VOLUME_CORRUPTED;
}
@ -277,21 +280,21 @@ FatAllocateCluster (
// Start looking at FatFreePos for the next unallocated cluster
//
if (Volume->DiskError) {
return (UINTN) FAT_CLUSTER_LAST;
return (UINTN)FAT_CLUSTER_LAST;
}
for (;;) {
for ( ; ;) {
//
// If the end of the list, return no available cluster
//
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
if (Volume->FreeInfoValid && 0 < (INT32) (Volume->FatInfoSector.FreeInfo.ClusterCount)) {
if (Volume->FreeInfoValid && (0 < (INT32)(Volume->FatInfoSector.FreeInfo.ClusterCount))) {
Volume->FreeInfoValid = FALSE;
}
FatComputeFreeInfo (Volume);
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
return (UINTN) FAT_CLUSTER_LAST;
return (UINTN)FAT_CLUSTER_LAST;
}
}
@ -299,6 +302,7 @@ FatAllocateCluster (
if (Cluster == FAT_CLUSTER_FREE) {
break;
}
//
// Try the next cluster
//
@ -370,10 +374,8 @@ FatShrinkEof (
LastCluster = FAT_CLUSTER_FREE;
if (NewSize != 0) {
for (CurSize = 0; CurSize < NewSize; CurSize++) {
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
return EFI_VOLUME_CORRUPTED;
}
@ -382,8 +384,7 @@ FatShrinkEof (
Cluster = FatGetFatEntry (Volume, Cluster);
}
FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
} else {
//
// Check to see if the file is already completely truncated
@ -391,11 +392,13 @@ FatShrinkEof (
if (Cluster == FAT_CLUSTER_FREE) {
return EFI_SUCCESS;
}
//
// The file is being completely truncated.
//
OFile->FileCluster = FAT_CLUSTER_FREE;
}
//
// Set CurrentCluster == FileCluster
// to force a recalculation of Position related stuffs
@ -450,7 +453,7 @@ FatGrowEof (
// If the file is already large enough, do nothing
//
CurSize = FatSizeToClusters (Volume, OFile->FileSize);
NewSize = FatSizeToClusters (Volume, (UINTN) NewSizeInBytes);
NewSize = FatSizeToClusters (Volume, (UINTN)NewSizeInBytes);
if (CurSize < NewSize) {
//
@ -461,8 +464,7 @@ FatGrowEof (
ClusterCount = 0;
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
if ((Cluster < FAT_MIN_CLUSTER) || (Cluster > Volume->MaxCluster + 1)) {
DEBUG (
(DEBUG_INIT | DEBUG_ERROR,
"FatGrowEof: cluster chain corrupt\n")
@ -484,8 +486,8 @@ FatGrowEof (
Status = EFI_VOLUME_CORRUPTED;
goto Done;
}
}
//
// Loop until we've allocated enough space
//
@ -495,7 +497,7 @@ FatGrowEof (
NewCluster = FatAllocateCluster (Volume);
if (FAT_END_OF_FAT_CHAIN (NewCluster)) {
if (LastCluster != FAT_CLUSTER_FREE) {
FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
OFile->FileLastCluster = LastCluster;
}
@ -503,7 +505,7 @@ FatGrowEof (
goto Done;
}
if (NewCluster < FAT_MIN_CLUSTER || NewCluster > Volume->MaxCluster + 1) {
if ((NewCluster < FAT_MIN_CLUSTER) || (NewCluster > Volume->MaxCluster + 1)) {
Status = EFI_VOLUME_CORRUPTED;
goto Done;
}
@ -529,12 +531,12 @@ FatGrowEof (
// a second time. There are other, less predictable scenarios
// where this could happen, as well.
//
FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
OFile->FileLastCluster = LastCluster;
}
}
OFile->FileSize = (UINTN) NewSizeInBytes;
OFile->FileSize = (UINTN)NewSizeInBytes;
OFile->Dirty = TRUE;
return EFI_SUCCESS;
@ -596,22 +598,22 @@ FatOFilePosition (
//
Cluster = OFile->FileCurrentCluster;
StartPos = OFile->Position;
if (Position < StartPos || OFile->FileCluster == Cluster) {
if ((Position < StartPos) || (OFile->FileCluster == Cluster)) {
StartPos = 0;
Cluster = OFile->FileCluster;
}
while (StartPos + ClusterSize <= Position) {
StartPos += ClusterSize;
if (Cluster == FAT_CLUSTER_FREE || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatOFilePosition:"" cluster chain corrupt\n"));
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatOFilePosition:" " cluster chain corrupt\n"));
return EFI_VOLUME_CORRUPTED;
}
Cluster = FatGetFatEntry (Volume, Cluster);
}
if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
if ((Cluster < FAT_MIN_CLUSTER) || (Cluster > Volume->MaxCluster + 1)) {
return EFI_VOLUME_CORRUPTED;
}
@ -655,6 +657,7 @@ FatPhysicalDirSize (
)
{
UINTN Size;
ASSERT_VOLUME_LOCKED (Volume);
//
// Run the cluster chain for the OFile
@ -666,7 +669,7 @@ FatPhysicalDirSize (
//
if (Cluster != 0) {
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
DEBUG (
(DEBUG_INIT | DEBUG_ERROR,
"FATDirSize: cluster chain corrupt\n")
@ -700,8 +703,9 @@ FatPhysicalFileSize (
{
UINTN ClusterSizeMask;
UINT64 PhysicalSize;
ClusterSizeMask = Volume->ClusterSize - 1;
PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64) ClusterSizeMask));
PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64)ClusterSizeMask));
return PhysicalSize;
}
@ -723,7 +727,6 @@ FatComputeFreeInfo (
// If we don't have valid info, compute it now
//
if (!Volume->FreeInfoValid) {
Volume->FreeInfoValid = TRUE;
Volume->FatInfoSector.FreeInfo.ClusterCount = 0;
for (Index = Volume->MaxCluster + 1; Index >= FAT_MIN_CLUSTER; Index--) {
@ -733,7 +736,7 @@ FatComputeFreeInfo (
if (FatGetFatEntry (Volume, Index) == FAT_CLUSTER_FREE) {
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32) Index;
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32)Index;
}
}

View File

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

View File

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

View File

@ -142,13 +142,13 @@ FatGetVolumeInfo (
Info->Size = ResultSize;
Info->ReadOnly = Volume->ReadOnly;
Info->BlockSize = (UINT32) Volume->ClusterSize;
Info->BlockSize = (UINT32)Volume->ClusterSize;
Info->VolumeSize = LShiftU64 (Volume->MaxCluster, ClusterAlignment);
Info->FreeSpace = LShiftU64 (
Volume->FatInfoSector.FreeInfo.ClusterCount,
ClusterAlignment
);
CopyMem ((CHAR8 *) Buffer + Size, Name, NameSize);
CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
}
*BufferSize = ResultSize;
@ -188,7 +188,7 @@ FatGetVolumeLabelInfo (
Status = EFI_BUFFER_TOO_SMALL;
if (*BufferSize >= ResultSize) {
Status = EFI_SUCCESS;
CopyMem ((CHAR8 *) Buffer + Size, Name, NameSize);
CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
}
*BufferSize = ResultSize;
@ -218,9 +218,9 @@ FatSetVolumeInfo (
{
EFI_FILE_SYSTEM_INFO *Info;
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;
}
@ -250,7 +250,7 @@ FatSetVolumeLabelInfo (
{
EFI_FILE_SYSTEM_VOLUME_LABEL *Info;
Info = (EFI_FILE_SYSTEM_VOLUME_LABEL *) Buffer;
Info = (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer;
if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL + 2) {
return EFI_BAD_BUFFER_SIZE;
@ -312,11 +312,12 @@ FatSetFileInfo (
if (Parent == NULL) {
return EFI_ACCESS_DENIED;
}
//
// Make sure there's a valid input buffer
//
NewInfo = Buffer;
if (BufferSize < SIZE_OF_EFI_FILE_INFO + 2 || NewInfo->Size > BufferSize) {
if ((BufferSize < SIZE_OF_EFI_FILE_INFO + 2) || (NewInfo->Size > BufferSize)) {
return EFI_BAD_BUFFER_SIZE;
}
@ -350,17 +351,18 @@ FatSetFileInfo (
return EFI_INVALID_PARAMETER;
}
NewAttribute = (UINT8) NewInfo->Attribute;
NewAttribute = (UINT8)NewInfo->Attribute;
//
// Can not change the directory attribute bit
//
if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) {
return EFI_ACCESS_DENIED;
}
//
// Set the current attributes even if the IFile->ReadOnly is TRUE
//
DirEnt->Entry.Attributes = (UINT8) ((DirEnt->Entry.Attributes &~EFI_FILE_VALID_ATTR) | NewAttribute);
DirEnt->Entry.Attributes = (UINT8)((DirEnt->Entry.Attributes &~EFI_FILE_VALID_ATTR) | NewAttribute);
//
// Open the filename and see if it refers to an existing file
//
@ -374,7 +376,7 @@ FatSetFileInfo (
// File was not found. We do not allow rename of the current directory if
// there are open files below the current directory
//
if (!IsListEmpty (&OFile->ChildHead) || Parent == OFile) {
if (!IsListEmpty (&OFile->ChildHead) || (Parent == OFile)) {
return EFI_ACCESS_DENIED;
}
@ -386,6 +388,7 @@ FatSetFileInfo (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Create new dirent
//
@ -413,7 +416,7 @@ FatSetFileInfo (
ASSERT (OFile->Parent != NULL);
for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) {
Status = FatGetNextDirEnt (OFile, &DirEnt);
if (EFI_ERROR (Status) || DirEnt == NULL || !FatIsDotDirEnt (DirEnt)) {
if (EFI_ERROR (Status) || (DirEnt == NULL) || !FatIsDotDirEnt (DirEnt)) {
return EFI_VOLUME_CORRUPTED;
}
@ -424,6 +427,7 @@ FatSetFileInfo (
}
}
}
//
// If the file is renamed, we should append the ARCHIVE attribute
//
@ -434,11 +438,12 @@ FatSetFileInfo (
//
return EFI_ACCESS_DENIED;
}
//
// If the file size has changed, apply it
//
if (NewInfo->FileSize != OFile->FileSize) {
if (OFile->ODir != NULL || ReadOnly) {
if ((OFile->ODir != NULL) || ReadOnly) {
//
// If this is a directory or the file is read only, we can't change the file size
//
@ -448,7 +453,7 @@ FatSetFileInfo (
if (NewInfo->FileSize > OFile->FileSize) {
Status = FatExpandOFile (OFile, NewInfo->FileSize);
} else {
Status = FatTruncateOFile (OFile, (UINTN) NewInfo->FileSize);
Status = FatTruncateOFile (OFile, (UINTN)NewInfo->FileSize);
}
if (EFI_ERROR (Status)) {

View File

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

View File

@ -36,6 +36,7 @@ FatCreateTask (
InitializeListHead (&Task->Subtasks);
InitializeListHead (&Task->Link);
}
return Task;
}
@ -59,6 +60,7 @@ FatDestroyTask (
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
Link = FatDestroySubtask (Subtask);
}
FreePool (Task);
}
@ -155,10 +157,10 @@ FatQueueTask (
for ( Link = GetFirstNode (&Task->Subtasks), NextLink = GetNextNode (&Task->Subtasks, Link)
; Link != &Task->Subtasks
; Link = NextLink, NextLink = Link->ForwardLink
) {
)
{
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
if (Subtask->Write) {
Status = IFile->OFile->Volume->DiskIo2->WriteDiskEx (
IFile->OFile->Volume->DiskIo2,
IFile->OFile->Volume->MediaId,
@ -177,6 +179,7 @@ FatQueueTask (
Subtask->Buffer
);
}
if (EFI_ERROR (Status)) {
break;
}
@ -260,7 +263,7 @@ FatOnAccessComplete (
//
ASSERT (EfiGetCurrentTpl () == FatTaskLock.Tpl);
Subtask = (FAT_SUBTASK *) Context;
Subtask = (FAT_SUBTASK *)Context;
Task = Subtask->Task;
Status = Subtask->DiskIo2Token.TransactionStatus;
@ -354,7 +357,7 @@ FatDiskIo (
} else {
Subtask->Signature = FAT_SUBTASK_SIGNATURE;
Subtask->Task = Task;
Subtask->Write = (BOOLEAN) (IoMode == WriteDisk);
Subtask->Write = (BOOLEAN)(IoMode == WriteDisk);
Subtask->Offset = Offset;
Subtask->Buffer = Buffer;
Subtask->BufferSize = BufferSize;
@ -464,6 +467,7 @@ FatFreeVolume (
if (Volume->CacheBuffer != NULL) {
FreePool (Volume->CacheBuffer);
}
//
// Free directory cache
//
@ -489,7 +493,7 @@ FatEfiTimeToFatTime (
// ignores timezone info in source ETime
//
if (ETime->Year > 1980) {
FTime->Date.Year = (UINT16) (ETime->Year - 1980);
FTime->Date.Year = (UINT16)(ETime->Year - 1980);
}
if (ETime->Year >= 1980 + FAT_MAX_YEAR_FROM_1980) {
@ -500,7 +504,7 @@ FatEfiTimeToFatTime (
FTime->Date.Day = ETime->Day;
FTime->Time.Hour = ETime->Hour;
FTime->Time.Minute = ETime->Minute;
FTime->Time.DoubleSecond = (UINT16) (ETime->Second / 2);
FTime->Time.DoubleSecond = (UINT16)(ETime->Second / 2);
}
/**
@ -517,12 +521,12 @@ FatFatTimeToEfiTime (
OUT EFI_TIME *ETime
)
{
ETime->Year = (UINT16) (FTime->Date.Year + 1980);
ETime->Month = (UINT8) FTime->Date.Month;
ETime->Day = (UINT8) FTime->Date.Day;
ETime->Hour = (UINT8) FTime->Time.Hour;
ETime->Minute = (UINT8) FTime->Time.Minute;
ETime->Second = (UINT8) (FTime->Time.DoubleSecond * 2);
ETime->Year = (UINT16)(FTime->Date.Year + 1980);
ETime->Month = (UINT8)FTime->Date.Month;
ETime->Day = (UINT8)FTime->Date.Day;
ETime->Hour = (UINT8)FTime->Time.Hour;
ETime->Minute = (UINT8)FTime->Time.Minute;
ETime->Second = (UINT8)(FTime->Time.DoubleSecond * 2);
ETime->Nanosecond = 0;
ETime->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
ETime->Daylight = 0;
@ -579,30 +583,30 @@ FatIsValidTime (
// Check the fields for range problems
// Fat can only support from 1980
//
if (Time->Year < 1980 ||
Time->Month < 1 ||
Time->Month > 12 ||
Time->Day < 1 ||
Time->Day > 31 ||
Time->Hour > 23 ||
Time->Minute > 59 ||
Time->Second > 59 ||
Time->Nanosecond > 999999999
) {
if ((Time->Year < 1980) ||
(Time->Month < 1) ||
(Time->Month > 12) ||
(Time->Day < 1) ||
(Time->Day > 31) ||
(Time->Hour > 23) ||
(Time->Minute > 59) ||
(Time->Second > 59) ||
(Time->Nanosecond > 999999999)
)
{
ValidTime = FALSE;
} else {
//
// Perform a more specific check of the day of the month
//
Day = mMonthDays[Time->Month - 1];
if (Time->Month == 2 && IS_LEAP_YEAR (Time->Year)) {
if ((Time->Month == 2) && IS_LEAP_YEAR (Time->Year)) {
Day += 1;
//
// 1 extra day this month
//
}
if (Time->Day > Day) {
ValidTime = FALSE;
}

View File

@ -100,10 +100,11 @@ FatOFileOpen (
DirEnt = NULL;
Volume = OFile->Volume;
ASSERT_VOLUME_LOCKED (Volume);
WriteMode = (BOOLEAN) (OpenMode & EFI_FILE_MODE_WRITE);
WriteMode = (BOOLEAN)(OpenMode & EFI_FILE_MODE_WRITE);
if (Volume->ReadOnly && WriteMode) {
return EFI_WRITE_PROTECTED;
}
//
// Verify the source file handle isn't in an error state
//
@ -111,6 +112,7 @@ FatOFileOpen (
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get new OFile for the file
//
@ -150,14 +152,16 @@ FatOFileOpen (
}
}
}
//
// If the file's attribute is read only, and the open is for
// read-write, then the access is denied.
//
FileAttributes = OFile->DirEnt->Entry.Attributes;
if ((FileAttributes & EFI_FILE_READ_ONLY) != 0 && (FileAttributes & FAT_ATTRIBUTE_DIRECTORY) == 0 && WriteMode) {
if (((FileAttributes & EFI_FILE_READ_ONLY) != 0) && ((FileAttributes & FAT_ATTRIBUTE_DIRECTORY) == 0) && WriteMode) {
return EFI_ACCESS_DENIED;
}
//
// Create an open instance of the OFile
//
@ -166,7 +170,7 @@ FatOFileOpen (
return Status;
}
(*NewIFile)->ReadOnly = (BOOLEAN)!WriteMode;
(*NewIFile)->ReadOnly = (BOOLEAN) !WriteMode;
DEBUG ((DEBUG_INFO, "FSOpen: Open '%S' %r\n", FileName, Status));
return FatOFileFlush (OFile);
@ -214,6 +218,7 @@ FatOpenEx (
if (FileName == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Check for a valid mode
//
@ -230,7 +235,7 @@ FatOpenEx (
//
// Check for valid Attributes for file creation case.
//
if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && (Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0) {
if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && ((Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0)) {
return EFI_INVALID_PARAMETER;
}
@ -248,6 +253,7 @@ FatOpenEx (
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
return EFI_UNSUPPORTED;
}
Task = FatCreateTask (IFile, Token);
if (Task == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -262,7 +268,7 @@ FatOpenEx (
//
// Open the file
//
Status = FatOFileOpen (OFile, &NewIFile, FileName, OpenMode, (UINT8) Attributes);
Status = FatOFileOpen (OFile, &NewIFile, FileName, OpenMode, (UINT8)Attributes);
//
// If the file was opened, return the handle to the caller
@ -270,6 +276,7 @@ FatOpenEx (
if (!EFI_ERROR (Status)) {
*NewHandle = &NewIFile->Handle;
}
//
// Unlock
//

View File

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

View File

@ -91,12 +91,14 @@ FatSetPosition (
FatResetODirCursor (OFile);
}
//
// Set the position
//
if (Position == (UINT64)-1) {
Position = OFile->FileSize;
}
//
// Set the position
//
@ -131,7 +133,7 @@ FatIFileReadDir (
OFile = IFile->OFile;
ODir = OFile->ODir;
CurrentPos = ((UINT32) IFile->Position) / sizeof (FAT_DIRECTORY_ENTRY);
CurrentPos = ((UINT32)IFile->Position) / sizeof (FAT_DIRECTORY_ENTRY);
//
// We need to relocate the directory
@ -142,12 +144,13 @@ FatIFileReadDir (
//
FatResetODirCursor (OFile);
}
//
// We seek the next directory entry's position
//
do {
Status = FatGetNextDirEnt (OFile, &DirEnt);
if (EFI_ERROR (Status) || DirEnt == NULL) {
if (EFI_ERROR (Status) || (DirEnt == NULL)) {
//
// Something error occurred or reach the end of directory,
// return 0 buffersize
@ -156,6 +159,7 @@ FatIFileReadDir (
goto Done;
}
} while (ODir->CurrentPos <= CurrentPos);
Status = FatGetDirEntInfo (OFile->Volume, DirEnt, BufferSize, Buffer);
Done:
@ -253,6 +257,7 @@ FatIFileAccess (
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
return EFI_UNSUPPORTED;
}
Task = FatCreateTask (IFile, Token);
if (Task == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -283,7 +288,7 @@ FatIFileAccess (
//
// Adjust the actual size read
//
*BufferSize -= (UINTN) EndPosition - OFile->FileSize;
*BufferSize -= (UINTN)EndPosition - OFile->FileSize;
} else {
//
// We expand the file size of OFile
@ -304,7 +309,7 @@ FatIFileAccess (
}
}
Status = FatAccessOFile (OFile, IoMode, (UINTN) IFile->Position, BufferSize, Buffer, Task);
Status = FatAccessOFile (OFile, IoMode, (UINTN)IFile->Position, BufferSize, Buffer, Task);
IFile->Position += *BufferSize;
}
}
@ -479,6 +484,7 @@ FatAccessOFile (
if (EFI_ERROR (Status)) {
break;
}
//
// Clip length to block run
//
@ -491,6 +497,7 @@ FatAccessOFile (
if (EFI_ERROR (Status)) {
break;
}
//
// Data was successfully accessed
//
@ -501,11 +508,13 @@ FatAccessOFile (
OFile->Dirty = TRUE;
OFile->Archive = TRUE;
}
//
// Make sure no outbound occurred
//
ASSERT (Position <= OFile->FileSize);
}
//
// Update the number of bytes accessed
//
@ -584,7 +593,7 @@ FatWriteZeroPool (
}
do {
WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN) AppendedSize;
WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN)AppendedSize;
AppendedSize -= WriteSize;
Status = FatAccessOFile (OFile, WriteData, WritePos, &WriteSize, ZeroBuffer, NULL);
if (EFI_ERROR (Status)) {

View File

@ -55,8 +55,8 @@ InitializeUnicodeCollationSupportWorker (
return Status;
}
Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL);
Iso639Language = (BOOLEAN)(ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
GetEfiGlobalVariable2 (VariableName, (VOID **)&Language, NULL);
ReturnStatus = EFI_UNSUPPORTED;
for (Index = 0; Index < NumHandles; Index++) {
@ -66,7 +66,7 @@ InitializeUnicodeCollationSupportWorker (
Status = gBS->OpenProtocol (
Handles[Index],
ProtocolGuid,
(VOID **) &Uci,
(VOID **)&Uci,
AgentHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@ -121,7 +121,6 @@ InitializeUnicodeCollationSupport (
IN EFI_HANDLE AgentHandle
)
{
EFI_STATUS Status;
Status = EFI_UNSUPPORTED;
@ -133,7 +132,7 @@ InitializeUnicodeCollationSupport (
AgentHandle,
&gEfiUnicodeCollation2ProtocolGuid,
L"PlatformLang",
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
(CONST CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
);
//
// If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
@ -144,14 +143,13 @@ InitializeUnicodeCollationSupport (
AgentHandle,
&gEfiUnicodeCollationProtocolGuid,
L"Lang",
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang)
(CONST CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLang)
);
}
return Status;
}
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@ -179,7 +177,6 @@ FatStriCmp (
);
}
/**
Uppercase a string.
@ -198,7 +195,6 @@ FatStrUpr (
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
}
/**
Lowercase a string
@ -217,7 +213,6 @@ FatStrLwr (
mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
}
/**
Convert FAT string to unicode string.
@ -237,13 +232,12 @@ FatFatToStr (
{
ASSERT (Fat != NULL);
ASSERT (String != NULL);
ASSERT (((UINTN) String & 0x01) == 0);
ASSERT (((UINTN)String & 0x01) == 0);
ASSERT (mUnicodeCollationInterface != NULL);
mUnicodeCollationInterface->FatToStr (mUnicodeCollationInterface, FatSize, Fat, String);
}
/**
Convert unicode string to Fat string.

View File

@ -60,8 +60,8 @@ FatFindEltoritoPartitions (
return FALSE;
}
VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
Catalog = (ELTORITO_CATALOG *) VolDescriptor;
VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *)PrivateData->BlockData;
Catalog = (ELTORITO_CATALOG *)VolDescriptor;
//
// the ISO-9660 volume descriptor starts at 32k on the media
@ -74,7 +74,6 @@ FatFindEltoritoPartitions (
// Loop: handle one volume descriptor per time
//
while (TRUE) {
VolDescriptorLba += 1;
if (VolDescriptorLba > ParentBlockDev->LastBlock) {
//
@ -93,23 +92,27 @@ FatFindEltoritoPartitions (
if (EFI_ERROR (Status)) {
break;
}
//
// Check for valid volume descriptor signature
//
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0
) {
if ((VolDescriptor->Unknown.Type == CDVOL_TYPE_END) ||
(CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0)
)
{
//
// end of Volume descriptor list
//
break;
}
//
// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
//
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
}
//
// Is it an El Torito volume descriptor?
//
@ -117,9 +120,11 @@ FatFindEltoritoPartitions (
VolDescriptor->BootRecordVolume.SystemId,
CDVOL_ELTORITO_ID,
sizeof (CDVOL_ELTORITO_ID) - 1
) != 0) {
) != 0)
{
continue;
}
//
// Read in the boot El Torito boot catalog
//
@ -138,16 +143,17 @@ FatFindEltoritoPartitions (
if (EFI_ERROR (Status)) {
continue;
}
//
// We don't care too much about the Catalog header's contents, but we do want
// to make sure it looks like a Catalog header
//
if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) {
if ((Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG) || (Catalog->Catalog.Id55AA != 0xAA55)) {
continue;
}
Check = 0;
CheckBuffer = (UINT16 *) Catalog;
CheckBuffer = (UINT16 *)Catalog;
for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
Check += CheckBuffer[Index];
}
@ -166,7 +172,7 @@ FatFindEltoritoPartitions (
//
// Check this entry
//
if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) {
if ((Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE) || (Catalog->Boot.Lba == 0)) {
continue;
}
@ -174,7 +180,6 @@ FatFindEltoritoPartitions (
SectorCount = Catalog->Boot.SectorCount;
switch (Catalog->Boot.MediaType) {
case ELTORITO_NO_EMULATION:
SubBlockSize = ParentBlockDev->BlockSize;
SectorCount = Catalog->Boot.SectorCount;
@ -202,13 +207,13 @@ FatFindEltoritoPartitions (
}
if (SectorCount < 2) {
SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32) (ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32) (VolSpaceSize - Catalog->Boot.Lba);
SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32)(ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32)(VolSpaceSize - Catalog->Boot.Lba);
}
//
// Register this partition
//
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
Found = TRUE;
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
@ -229,5 +234,4 @@ FatFindEltoritoPartitions (
ParentBlockDev->PartitionChecked = TRUE;
return Found;
}

View File

@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h"
/**
Check if there is a valid FAT in the corresponding Block device
of the volume and if yes, fill in the relevant fields for the
@ -60,8 +59,8 @@ FatGetBpbInfo (
}
CopyMem (
(UINT8 *) (&Bpb),
(UINT8 *) (&BpbEx),
(UINT8 *)(&Bpb),
(UINT8 *)(&BpbEx),
sizeof (PEI_FAT_BOOT_SECTOR)
);
@ -77,60 +76,65 @@ FatGetBpbInfo (
SectorsPerFat = BpbEx.LargeSectorsPerFat;
Volume->FatType = Fat32;
}
//
// Filter out those not a FAT
//
if (Bpb.Ia32Jump[0] != 0xe9 && Bpb.Ia32Jump[0] != 0xeb && Bpb.Ia32Jump[0] != 0x49) {
if ((Bpb.Ia32Jump[0] != 0xe9) && (Bpb.Ia32Jump[0] != 0xeb) && (Bpb.Ia32Jump[0] != 0x49)) {
return EFI_NOT_FOUND;
}
if (Bpb.ReservedSectors == 0 || Bpb.NoFats == 0 || Sectors == 0) {
if ((Bpb.ReservedSectors == 0) || (Bpb.NoFats == 0) || (Sectors == 0)) {
return EFI_NOT_FOUND;
}
if (Bpb.SectorsPerCluster != 1 &&
Bpb.SectorsPerCluster != 2 &&
Bpb.SectorsPerCluster != 4 &&
Bpb.SectorsPerCluster != 8 &&
Bpb.SectorsPerCluster != 16 &&
Bpb.SectorsPerCluster != 32 &&
Bpb.SectorsPerCluster != 64 &&
Bpb.SectorsPerCluster != 128
) {
if ((Bpb.SectorsPerCluster != 1) &&
(Bpb.SectorsPerCluster != 2) &&
(Bpb.SectorsPerCluster != 4) &&
(Bpb.SectorsPerCluster != 8) &&
(Bpb.SectorsPerCluster != 16) &&
(Bpb.SectorsPerCluster != 32) &&
(Bpb.SectorsPerCluster != 64) &&
(Bpb.SectorsPerCluster != 128)
)
{
return EFI_NOT_FOUND;
}
if (Volume->FatType == Fat32 && (SectorsPerFat == 0 || BpbEx.FsVersion != 0)) {
if ((Volume->FatType == Fat32) && ((SectorsPerFat == 0) || (BpbEx.FsVersion != 0))) {
return EFI_NOT_FOUND;
}
if (Bpb.Media != 0xf0 &&
Bpb.Media != 0xf8 &&
Bpb.Media != 0xf9 &&
Bpb.Media != 0xfb &&
Bpb.Media != 0xfc &&
Bpb.Media != 0xfd &&
Bpb.Media != 0xfe &&
Bpb.Media != 0xff &&
if ((Bpb.Media != 0xf0) &&
(Bpb.Media != 0xf8) &&
(Bpb.Media != 0xf9) &&
(Bpb.Media != 0xfb) &&
(Bpb.Media != 0xfc) &&
(Bpb.Media != 0xfd) &&
(Bpb.Media != 0xfe) &&
(Bpb.Media != 0xff) &&
//
// FujitsuFMR
//
Bpb.Media != 0x00 &&
Bpb.Media != 0x01 &&
Bpb.Media != 0xfa
) {
(Bpb.Media != 0x00) &&
(Bpb.Media != 0x01) &&
(Bpb.Media != 0xfa)
)
{
return EFI_NOT_FOUND;
}
if (Volume->FatType != Fat32 && Bpb.RootEntries == 0) {
if ((Volume->FatType != Fat32) && (Bpb.RootEntries == 0)) {
return EFI_NOT_FOUND;
}
//
// If this is fat32, refuse to mount mirror-disabled volumes
//
if (Volume->FatType == Fat32 && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
if ((Volume->FatType == Fat32) && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
return EFI_NOT_FOUND;
}
//
// Fill in the volume structure fields
// (Sectors & SectorsPerFat is computed earlier already)
@ -149,14 +153,13 @@ FatGetBpbInfo (
Volume->FatPos = MultU64x32 (FatLba, Volume->SectorSize);
Volume->RootDirPos = MultU64x32 (RootLba, Volume->SectorSize);
Volume->FirstClusterPos = MultU64x32 (FirstClusterLba, Volume->SectorSize);
Volume->MaxCluster = (UINT32) (Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;
Volume->MaxCluster = (UINT32)(Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;
Volume->RootDirCluster = BpbEx.RootDirFirstCluster;
//
// If this is not a fat32, determine if it's a fat16 or fat12
//
if (Volume->FatType != Fat32) {
if (Volume->MaxCluster >= 65525) {
return EFI_NOT_FOUND;
}
@ -167,7 +170,6 @@ FatGetBpbInfo (
return EFI_SUCCESS;
}
/**
Gets the next cluster in the cluster chain
@ -207,7 +209,6 @@ FatGetNextCluster (
if ((*NextCluster) >= 0x0ffffff7) {
*NextCluster |= (-1 &~0xf);
}
} else if (Volume->FatType == Fat16) {
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
@ -219,7 +220,6 @@ FatGetNextCluster (
if ((*NextCluster) >= 0xfff7) {
*NextCluster |= (-1 &~0xf);
}
} else {
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
@ -230,6 +230,7 @@ FatGetNextCluster (
} else {
*NextCluster = (*NextCluster) & 0x0fff;
}
//
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
//
@ -243,10 +244,8 @@ FatGetNextCluster (
}
return EFI_SUCCESS;
}
/**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@ -274,24 +273,22 @@ FatSetFilePos (
UINT32 PrevCluster;
if (File->IsFixedRootDir) {
if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {
return EFI_INVALID_PARAMETER;
}
File->CurrentPos += Pos;
File->StraightReadAmount = (UINT32) (MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
} else {
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
AlignedPos = (UINT32) File->CurrentPos - (UINT32) Offset;
AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;
while
(
!FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
) {
)
{
AlignedPos += File->Volume->ClusterSize;
Status = FatGetNextCluster (
PrivateData,
@ -329,14 +326,12 @@ FatSetFilePos (
}
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
File->StraightReadAmount -= (UINT32) Offset;
File->StraightReadAmount -= (UINT32)Offset;
}
return EFI_SUCCESS;
}
/**
Reads file data. Updates the file's CurrentPos.
@ -381,14 +376,13 @@ FatReadFile (
Size,
Buffer
);
File->CurrentPos += (UINT32) Size;
File->CurrentPos += (UINT32)Size;
return Status;
} else {
if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
}
//
// This is a normal cluster based file
//
@ -408,10 +402,11 @@ FatReadFile (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
//
// Advance the file's current pos and current cluster
//
FatSetFilePos (PrivateData, File, (UINT32) Amount);
FatSetFilePos (PrivateData, File, (UINT32)Amount);
BufferPtr += Amount;
Size -= Amount;
@ -421,7 +416,6 @@ FatReadFile (
}
}
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@ -452,7 +446,7 @@ FatReadNextDirectoryEntry (
CHAR16 BaseName[9];
CHAR16 Ext[4];
ZeroMem ((UINT8 *) SubFile, sizeof (PEI_FAT_FILE));
ZeroMem ((UINT8 *)SubFile, sizeof (PEI_FAT_FILE));
//
// Pick a valid directory entry
@ -465,6 +459,7 @@ FatReadNextDirectoryEntry (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
//
// We only search for *FILE* in root directory
// Long file name entry is *NOT* supported
@ -472,35 +467,38 @@ FatReadNextDirectoryEntry (
if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {
continue;
}
//
// if this is a terminator dir entry, just return EFI_NOT_FOUND
//
if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {
return EFI_NOT_FOUND;
}
//
// If this not an invalid entry neither an empty entry, this is what we want.
// otherwise we will start a new loop to continue to find something meaningful
//
if ((UINT8) DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
if ((UINT8)DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
break;
}
}
//
// fill in the output parameter
//
EngFatToStr (8, DirEntry.FileName, BaseName);
EngFatToStr (3, DirEntry.FileName + 8, Ext);
Pos = (UINT16 *) SubFile->FileName;
SetMem ((UINT8 *) Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
CopyMem ((UINT8 *) Pos, (UINT8 *) BaseName, 2 * (StrLen (BaseName) + 1));
Pos = (UINT16 *)SubFile->FileName;
SetMem ((UINT8 *)Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
CopyMem ((UINT8 *)Pos, (UINT8 *)BaseName, 2 * (StrLen (BaseName) + 1));
if (Ext[0] != 0) {
Pos += StrLen (BaseName);
*Pos = '.';
Pos++;
CopyMem ((UINT8 *) Pos, (UINT8 *) Ext, 2 * (StrLen (Ext) + 1));
CopyMem ((UINT8 *)Pos, (UINT8 *)Ext, 2 * (StrLen (Ext) + 1));
}
SubFile->Attributes = DirEntry.Attributes;

View File

@ -33,7 +33,6 @@ BlockIoNotifyEntry (
IN VOID *Ppi
);
/**
Discover all the block I/O devices to find the FAT volume.
@ -62,7 +61,7 @@ UpdateBlocksAndVolumes (
PEI_FAT_VOLUME Volume;
EFI_PEI_SERVICES **PeiServices;
PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
PeiServices = (EFI_PEI_SERVICES **)GetPeiServicesTablePointer ();
BlockIo2Ppi = NULL;
BlockIoPpi = NULL;
//
@ -84,16 +83,17 @@ UpdateBlocksAndVolumes (
&gEfiPeiVirtualBlockIo2PpiGuid,
BlockIoPpiInstance,
&TempPpiDescriptor,
(VOID **) &BlockIo2Ppi
(VOID **)&BlockIo2Ppi
);
} else {
Status = PeiServicesLocatePpi (
&gEfiPeiVirtualBlockIoPpiGuid,
BlockIoPpiInstance,
&TempPpiDescriptor,
(VOID **) &BlockIoPpi
(VOID **)&BlockIoPpi
);
}
if (EFI_ERROR (Status)) {
//
// Done with all Block Io Ppis
@ -114,12 +114,12 @@ UpdateBlocksAndVolumes (
&NumberBlockDevices
);
}
if (EFI_ERROR (Status)) {
continue;
}
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
if (BlockIo2) {
Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
PeiServices,
@ -130,6 +130,7 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media2.MediaPresent) {
continue;
}
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
@ -144,10 +145,11 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media.MediaPresent) {
continue;
}
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32)Media.BlockSize;
}
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
@ -157,10 +159,11 @@ UpdateBlocksAndVolumes (
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8) Index;
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8)Index;
PrivateData->BlockDeviceCount++;
}
}
//
// Find out all logical devices
//
@ -178,8 +181,8 @@ UpdateBlocksAndVolumes (
// Add the detected volume to the volume array
//
CopyMem (
(UINT8 *) &(PrivateData->Volume[PrivateData->VolumeCount]),
(UINT8 *) &Volume,
(UINT8 *)&(PrivateData->Volume[PrivateData->VolumeCount]),
(UINT8 *)&Volume,
sizeof (PEI_FAT_VOLUME)
);
PrivateData->VolumeCount += 1;
@ -192,7 +195,6 @@ UpdateBlocksAndVolumes (
return EFI_SUCCESS;
}
/**
BlockIo installation notification function. Find out all the current BlockIO
PPIs in the system and add them into private data. Assume there is
@ -220,10 +222,10 @@ BlockIoNotifyEntry (
} else {
UpdateBlocksAndVolumes (mPrivateData, FALSE);
}
return EFI_SUCCESS;
}
/**
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
installation notification
@ -263,12 +265,12 @@ FatPeimEntry (
return EFI_OUT_OF_RESOURCES;
}
PrivateData = (PEI_FAT_PRIVATE_DATA *) (UINTN) Address;
PrivateData = (PEI_FAT_PRIVATE_DATA *)(UINTN)Address;
//
// Initialize Private Data (to zero, as is required by subsequent operations)
//
ZeroMem ((UINT8 *) PrivateData, sizeof (PEI_FAT_PRIVATE_DATA));
ZeroMem ((UINT8 *)PrivateData, sizeof (PEI_FAT_PRIVATE_DATA));
PrivateData->Signature = PEI_FAT_PRIVATE_DATA_SIGNATURE;
@ -287,6 +289,7 @@ FatPeimEntry (
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
//
// Other initializations
//
@ -319,7 +322,6 @@ FatPeimEntry (
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
}
/**
Returns the number of DXE capsules residing on the device.
@ -364,7 +366,7 @@ GetNumberRecoveryCapsules (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
@ -381,7 +383,6 @@ GetNumberRecoveryCapsules (
return EFI_SUCCESS;
}
/**
Returns the size and type of the requested recovery capsule.
@ -442,7 +443,7 @@ GetRecoveryCapsuleInfo (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
@ -452,7 +453,7 @@ GetRecoveryCapsuleInfo (
//
// Get file size
//
*Size = (UINTN) (((PEI_FAT_FILE *) Handle)->FileSize);
*Size = (UINTN)(((PEI_FAT_FILE *)Handle)->FileSize);
//
// Find corresponding physical block device
@ -461,6 +462,7 @@ GetRecoveryCapsuleInfo (
while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) {
BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo;
}
//
// Fill in the Capsule Type GUID according to the block device type
//
@ -483,6 +485,7 @@ GetRecoveryCapsuleInfo (
break;
}
}
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
case LegacyFloppy:
@ -513,7 +516,6 @@ GetRecoveryCapsuleInfo (
return EFI_NOT_FOUND;
}
/**
Loads a DXE capsule from some media into memory.
@ -566,17 +568,16 @@ LoadRecoveryCapsule (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
Status = FatReadFile (
PrivateData,
Handle,
(UINTN) (((PEI_FAT_FILE *) Handle)->FileSize),
(UINTN)(((PEI_FAT_FILE *)Handle)->FileSize),
Buffer
);
return Status;
@ -588,7 +589,6 @@ LoadRecoveryCapsule (
return EFI_NOT_FOUND;
}
/**
Finds the recovery file on a FAT volume.
This function finds the recovery file named FileName on a specified FAT volume and returns
@ -631,7 +631,7 @@ FindRecoveryFile (
// Construct root directory file
//
ZeroMem (&Parent, sizeof (PEI_FAT_FILE));
Parent.IsFixedRootDir = (BOOLEAN) ((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
Parent.IsFixedRootDir = (BOOLEAN)((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
Parent.Attributes = FAT_ATTR_DIRECTORY;
Parent.CurrentPos = 0;
Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
@ -642,6 +642,7 @@ FindRecoveryFile (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
//
// Search for recovery capsule in root directory
//
@ -671,5 +672,4 @@ FindRecoveryFile (
*Handle = File;
return EFI_SUCCESS;
}

View File

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

View File

@ -9,10 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h"
#define CHAR_FAT_VALID 0x01
/**
Converts a union code character to upper case.
This functions converts a unicode character to upper case.
@ -29,14 +27,13 @@ ToUpper (
IN CHAR16 Letter
)
{
if ('a' <= Letter && Letter <= 'z') {
Letter = (CHAR16) (Letter - 0x20);
if (('a' <= Letter) && (Letter <= 'z')) {
Letter = (CHAR16)(Letter - 0x20);
}
return Letter;
}
/**
Reads a block of data from the block device by calling
underlying Block I/O service.
@ -83,7 +80,7 @@ FatReadBlock (
//
if (BlockDev->BlockIo2 != NULL) {
Status = BlockDev->BlockIo2->ReadBlocks (
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
(EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
BlockDev->BlockIo2,
BlockDev->PhysicalDevNo,
Lba,
@ -92,7 +89,7 @@ FatReadBlock (
);
} else {
Status = BlockDev->BlockIo->ReadBlocks (
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
(EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
BlockDev->BlockIo,
BlockDev->PhysicalDevNo,
Lba,
@ -100,7 +97,6 @@ FatReadBlock (
Buffer
);
}
} else {
Status = FatReadDisk (
PrivateData,
@ -114,7 +110,6 @@ FatReadBlock (
return Status;
}
/**
Find a cache block designated to specific Block device and Lba.
If not found, invalidate an oldest one and use it. (LRU cache)
@ -150,15 +145,16 @@ FatGetCacheBlock (
//
for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
if (CacheBuffer->Valid && CacheBuffer->BlockDeviceNo == BlockDeviceNo && CacheBuffer->Lba == Lba) {
if (CacheBuffer->Valid && (CacheBuffer->BlockDeviceNo == BlockDeviceNo) && (CacheBuffer->Lba == Lba)) {
break;
}
}
if (Index < PEI_FAT_CACHE_SIZE) {
*CachePtr = (CHAR8 *) CacheBuffer->Buffer;
*CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return EFI_SUCCESS;
}
//
// We have to find an invalid cache buffer
//
@ -167,6 +163,7 @@ FatGetCacheBlock (
break;
}
}
//
// Use the cache buffer
//
@ -202,12 +199,11 @@ FatGetCacheBlock (
}
CacheBuffer->Valid = TRUE;
*CachePtr = (CHAR8 *) CacheBuffer->Buffer;
*CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return Status;
}
/**
Disk reading.
@ -292,7 +288,6 @@ FatReadDisk (
return Status;
}
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@ -325,6 +320,7 @@ EngFatToStr (
if (*Fat == ' ') {
break;
}
*String = *Fat;
String += 1;
Fat += 1;
@ -334,7 +330,6 @@ EngFatToStr (
*String = 0;
}
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@ -366,5 +361,5 @@ EngStriColl (
UpperS2 = ToUpper (*Str2);
}
return (BOOLEAN) ((*Str2 != 0) ? FALSE : TRUE);
return (BOOLEAN)((*Str2 != 0) ? FALSE : TRUE);
}

View File

@ -49,7 +49,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// The block device
//
typedef struct {
UINT32 BlockSize;
UINT64 LastBlock;
UINT32 IoAlign;
@ -80,7 +79,6 @@ typedef struct {
// the Volume structure
//
typedef struct {
UINTN BlockDeviceNo;
UINTN VolumeNo;
UINT64 VolumeSize;
@ -94,14 +92,12 @@ typedef struct {
UINT64 RootDirPos;
UINT32 RootEntries;
UINT32 RootDirCluster;
} PEI_FAT_VOLUME;
//
// File instance
//
typedef struct {
PEI_FAT_VOLUME *Volume;
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
@ -114,21 +110,18 @@ typedef struct {
UINT8 Attributes;
UINT32 FileSize;
} PEI_FAT_FILE;
//
// Cache Buffer
//
typedef struct {
BOOLEAN Valid;
UINTN BlockDeviceNo;
UINT64 Lba;
UINT32 Lru;
UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
UINTN Size;
} PEI_FAT_CACHE_BUFFER;
//
@ -142,7 +135,6 @@ typedef struct {
#define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
typedef struct {
UINTN Signature;
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
@ -160,7 +152,6 @@ typedef struct {
PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
PEI_FAT_FILE File;
PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
} PEI_FAT_PRIVATE_DATA;
#define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
@ -178,7 +169,6 @@ typedef struct {
#define UNPACK_UINT32(a) \
(UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
//
// API functions
//
@ -209,7 +199,6 @@ FindRecoveryFile (
OUT PEI_FILE_HANDLE *Handle
);
/**
Returns the number of DXE capsules residing on the device.
This function, by whatever mechanism, searches for DXE capsules from the associated device and
@ -236,7 +225,6 @@ GetNumberRecoveryCapsules (
OUT UINTN *NumberRecoveryCapsules
);
/**
Returns the size and type of the requested recovery capsule.
This function returns the size and type of the capsule specified by CapsuleInstance.
@ -274,7 +262,6 @@ GetRecoveryCapsuleInfo (
OUT EFI_GUID *CapsuleType
);
/**
Loads a DXE capsule from some media into memory.
@ -303,7 +290,6 @@ LoadRecoveryCapsule (
OUT VOID *Buffer
);
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@ -326,7 +312,6 @@ EngFatToStr (
OUT CHAR16 *Str
);
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@ -342,7 +327,6 @@ EngStriColl (
IN CHAR16 *Str2
);
/**
Reads a block of data from the block device by calling
underlying Block I/O service.
@ -368,7 +352,6 @@ FatReadBlock (
OUT VOID *Buffer
);
/**
Check if there is a valid FAT in the corresponding Block device
of the volume and if yes, fill in the relevant fields for the
@ -394,7 +377,6 @@ FatGetBpbInfo (
IN OUT PEI_FAT_VOLUME *Volume
);
/**
Gets the next cluster in the cluster chain.
@ -416,7 +398,6 @@ FatGetNextCluster (
OUT UINT32 *NextCluster
);
/**
Disk reading.
@ -439,7 +420,6 @@ FatReadDisk (
OUT VOID *Buffer
);
/**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@ -460,7 +440,6 @@ FatSetFilePos (
IN UINT32 Pos
);
/**
Reads file data. Updates the file's CurrentPos.
@ -482,7 +461,6 @@ FatReadFile (
OUT VOID *Buffer
);
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@ -507,7 +485,6 @@ FatReadNextDirectoryEntry (
OUT PEI_FAT_FILE *SubFile
);
/**
This function finds partitions (logical devices) in physical block devices.

View File

@ -62,7 +62,6 @@ PartitionCheckGptHeaderCRC (
return (GptHdrCrc == Crc);
}
/**
Check if the CRC field in the Partition table header is valid
for Partition entry array.
@ -83,10 +82,10 @@ PartitionCheckGptEntryArrayCRC (
UINT32 Crc;
UINTN Size;
Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
Size = (UINTN)MultU64x32 (PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
Crc = CalculateCrc32 (PartEntry, Size);
return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc);
}
/**
@ -128,13 +127,14 @@ PartitionCheckGptHeader (
AlternateLba = PRIMARY_PART_HEADER_LBA;
}
if ( (PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
(PartHdr->Header.Revision != 0x00010000) ||
(PartHdr->Header.HeaderSize < 92) ||
(PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
(!PartitionCheckGptHeaderCRC (PartHdr)) ||
(PartHdr->Header.Reserved != 0)
) {
)
{
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@ -150,17 +150,18 @@ PartitionCheckGptHeader (
// 5. Must be remain 128*128 bytes for backup entry array.
// 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
//
if ( (PartHdr->MyLBA != Lba) ||
if ((PartHdr->MyLBA != Lba) ||
(PartHdr->AlternateLBA != AlternateLba) ||
(PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
(PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
(PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
(PartHdr->PartitionEntryLBA < 2) ||
(PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
(PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA && PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA) ||
((PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA) && (PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA)) ||
(PartHdr->SizeOfPartitionEntry%128 != 0) ||
(PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
) {
)
{
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@ -250,19 +251,21 @@ PartitionCheckGptEntryArray (
if (EntryArraySizeRemainder != 0) {
PartitionEntryBlockNumb++;
}
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
PartitionEntryBuffer = (EFI_PARTITION_ENTRY *) AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
PartitionEntryBuffer = (EFI_PARTITION_ENTRY *)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
if (PartitionEntryBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *) AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *)AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
if (PartitionEntryStatus == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
Status = FatReadBlock (
@ -283,19 +286,20 @@ PartitionCheckGptEntryArray (
}
for (Index1 = 0; Index1 < PartHdr->NumberOfPartitionEntries; Index1++) {
Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
StartingLBA = Entry->StartingLBA;
EndingLBA = Entry->EndingLBA;
if (StartingLBA > EndingLBA ||
StartingLBA < PartHdr->FirstUsableLBA ||
StartingLBA > PartHdr->LastUsableLBA ||
EndingLBA < PartHdr->FirstUsableLBA ||
EndingLBA > PartHdr->LastUsableLBA
) {
if ((StartingLBA > EndingLBA) ||
(StartingLBA < PartHdr->FirstUsableLBA) ||
(StartingLBA > PartHdr->LastUsableLBA) ||
(EndingLBA < PartHdr->FirstUsableLBA) ||
(EndingLBA > PartHdr->LastUsableLBA)
)
{
PartitionEntryStatus[Index1].OutOfRange = TRUE;
continue;
}
@ -308,12 +312,12 @@ PartitionCheckGptEntryArray (
}
for (Index2 = Index1 + 1; Index2 < PartHdr->NumberOfPartitionEntries; Index2++) {
Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {
if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
@ -325,10 +329,11 @@ PartitionCheckGptEntryArray (
}
for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)||
if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
PartitionEntryStatus[Index].OutOfRange ||
PartitionEntryStatus[Index].Overlap ||
PartitionEntryStatus[Index].OsSpecific) {
PartitionEntryStatus[Index].OsSpecific)
{
//
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
// partition Entries
@ -401,7 +406,7 @@ PartitionCheckGptStructure (
EFI_PEI_LBA GptHeaderLBA;
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
PartHdr = (EFI_PARTITION_TABLE_HEADER *) PrivateData->BlockData;
PartHdr = (EFI_PARTITION_TABLE_HEADER *)PrivateData->BlockData;
if (IsPrimary) {
GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
@ -452,7 +457,7 @@ PartitionCheckProtectiveMbr (
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
UINTN Index;
ProtectiveMbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
ProtectiveMbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
//
@ -482,11 +487,12 @@ PartitionCheckProtectiveMbr (
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
if (MbrPartition->BootIndicator == 0x00 &&
MbrPartition->StartSector == 0x02 &&
MbrPartition->OSIndicator == PMBR_GPT_PARTITION &&
UNPACK_UINT32 (MbrPartition->StartingLBA) == 1
) {
if ((MbrPartition->BootIndicator == 0x00) &&
(MbrPartition->StartSector == 0x02) &&
(MbrPartition->OSIndicator == PMBR_GPT_PARTITION) &&
(UNPACK_UINT32 (MbrPartition->StartingLBA) == 1)
)
{
return TRUE;
}
}

View File

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