summaryrefslogtreecommitdiffstats
path: root/FatPkg
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2021-12-05 14:53:58 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-07 17:24:28 +0000
commitbcdcc4160d7460c46c08c9395aae81be44ef23a9 (patch)
tree8e8607b86b86a1cebeaf6f614c43731a486b61a5 /FatPkg
parenta550d468a6ca577d9e9c57a0eafcf2fc9fbb8c97 (diff)
downloadedk2-bcdcc4160d7460c46c08c9395aae81be44ef23a9.tar.gz
edk2-bcdcc4160d7460c46c08c9395aae81be44ef23a9.tar.bz2
edk2-bcdcc4160d7460c46c08c9395aae81be44ef23a9.zip
FatPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the FatPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
Diffstat (limited to 'FatPkg')
-rw-r--r--FatPkg/EnhancedFatDxe/ComponentName.c33
-rw-r--r--FatPkg/EnhancedFatDxe/Data.c6
-rw-r--r--FatPkg/EnhancedFatDxe/Delete.c9
-rw-r--r--FatPkg/EnhancedFatDxe/DirectoryCache.c29
-rw-r--r--FatPkg/EnhancedFatDxe/DirectoryManage.c354
-rw-r--r--FatPkg/EnhancedFatDxe/DiskCache.c152
-rw-r--r--FatPkg/EnhancedFatDxe/Fat.c98
-rw-r--r--FatPkg/EnhancedFatDxe/Fat.h673
-rw-r--r--FatPkg/EnhancedFatDxe/FatFileSystem.h239
-rw-r--r--FatPkg/EnhancedFatDxe/FileName.c118
-rw-r--r--FatPkg/EnhancedFatDxe/FileSpace.c281
-rw-r--r--FatPkg/EnhancedFatDxe/Flush.c91
-rw-r--r--FatPkg/EnhancedFatDxe/Hash.c46
-rw-r--r--FatPkg/EnhancedFatDxe/Info.c189
-rw-r--r--FatPkg/EnhancedFatDxe/Init.c114
-rw-r--r--FatPkg/EnhancedFatDxe/Misc.c182
-rw-r--r--FatPkg/EnhancedFatDxe/Open.c67
-rw-r--r--FatPkg/EnhancedFatDxe/OpenVolume.c1
-rw-r--r--FatPkg/EnhancedFatDxe/ReadWrite.c93
-rw-r--r--FatPkg/EnhancedFatDxe/UnicodeCollation.c52
-rw-r--r--FatPkg/FatPei/Eltorito.c166
-rw-r--r--FatPkg/FatPei/FatLiteAccess.c212
-rw-r--r--FatPkg/FatPei/FatLiteApi.c246
-rw-r--r--FatPkg/FatPei/FatLiteApi.h2
-rw-r--r--FatPkg/FatPei/FatLiteFmt.h176
-rw-r--r--FatPkg/FatPei/FatLiteLib.c119
-rw-r--r--FatPkg/FatPei/FatLitePeim.h193
-rw-r--r--FatPkg/FatPei/Gpt.c210
-rw-r--r--FatPkg/FatPei/Mbr.c79
-rw-r--r--FatPkg/FatPei/Part.c16
30 files changed, 2176 insertions, 2070 deletions
diff --git a/FatPkg/EnhancedFatDxe/ComponentName.c b/FatPkg/EnhancedFatDxe/ComponentName.c
index b3cf16df56..a7460ebbf8 100644
--- a/FatPkg/EnhancedFatDxe/ComponentName.c
+++ b/FatPkg/EnhancedFatDxe/ComponentName.c
@@ -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.
@@ -130,11 +130,11 @@ FatComponentNameGetDriverName (
EFI_STATUS
EFIAPI
FatComponentNameGetControllerName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
);
//
@@ -149,13 +149,13 @@ 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,
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2 = {
+ (EFI_COMPONENT_NAME2_GET_DRIVER_NAME)FatComponentNameGetDriverName,
+ (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)FatComponentNameGetControllerName,
"en"
};
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
{
"eng;en",
L"FAT File System Driver"
@@ -166,7 +166,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
}
};
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[] = {
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[] = {
{
"eng;en",
L"FAT File System"
@@ -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.
@@ -305,11 +304,11 @@ FatComponentNameGetDriverName (
EFI_STATUS
EFIAPI
FatComponentNameGetControllerName (
- IN EFI_COMPONENT_NAME_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN EFI_HANDLE ChildHandle OPTIONAL,
- IN CHAR8 *Language,
- OUT CHAR16 **ControllerName
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
diff --git a/FatPkg/EnhancedFatDxe/Data.c b/FatPkg/EnhancedFatDxe/Data.c
index a0e1b62ce9..ba50a079db 100644
--- a/FatPkg/EnhancedFatDxe/Data.c
+++ b/FatPkg/EnhancedFatDxe/Data.c
@@ -14,14 +14,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// FatFsLock - Global lock for synchronizing all requests.
//
-EFI_LOCK FatFsLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK);
+EFI_LOCK FatFsLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK);
-EFI_LOCK FatTaskLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
+EFI_LOCK FatTaskLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
//
// Filesystem interface functions
//
-EFI_FILE_PROTOCOL FatFileInterface = {
+EFI_FILE_PROTOCOL FatFileInterface = {
EFI_FILE_PROTOCOL_REVISION,
FatOpen,
FatClose,
diff --git a/FatPkg/EnhancedFatDxe/Delete.c b/FatPkg/EnhancedFatDxe/Delete.c
index 8a437e3ee2..448d669f9d 100644
--- a/FatPkg/EnhancedFatDxe/Delete.c
+++ b/FatPkg/EnhancedFatDxe/Delete.c
@@ -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
diff --git a/FatPkg/EnhancedFatDxe/DirectoryCache.c b/FatPkg/EnhancedFatDxe/DirectoryCache.c
index 2333016d13..c8e5095771 100644
--- a/FatPkg/EnhancedFatDxe/DirectoryCache.c
+++ b/FatPkg/EnhancedFatDxe/DirectoryCache.c
@@ -19,7 +19,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
STATIC
VOID
FatFreeODir (
- IN FAT_ODIR *ODir
+ IN FAT_ODIR *ODir
)
{
FAT_DIRENT *DirEnt;
@@ -50,7 +50,7 @@ FatFreeODir (
STATIC
FAT_ODIR *
FatAllocateODir (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
FAT_ODIR *ODir;
@@ -78,14 +78,14 @@ FatAllocateODir (
**/
VOID
FatDiscardODir (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
FAT_ODIR *ODir;
FAT_VOLUME *Volume;
- Volume = OFile->Volume;
- ODir = OFile->ODir;
+ Volume = OFile->Volume;
+ ODir = OFile->ODir;
if (!OFile->DirEnt->Invalid) {
//
// If OFile does not represent a deleted file, then we will cache the directory
@@ -107,6 +107,7 @@ FatDiscardODir (
ODir = NULL;
}
}
+
//
// Release ODir Structure
//
@@ -127,14 +128,14 @@ FatDiscardODir (
**/
VOID
FatRequestODir (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
- UINTN DirCacheTag;
- FAT_VOLUME *Volume;
- FAT_ODIR *ODir;
- FAT_ODIR *CurrentODir;
- LIST_ENTRY *CurrentODirLink;
+ UINTN DirCacheTag;
+ FAT_VOLUME *Volume;
+ FAT_ODIR *ODir;
+ FAT_ODIR *CurrentODir;
+ LIST_ENTRY *CurrentODirLink;
Volume = OFile->Volume;
ODir = NULL;
@@ -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);
@@ -171,10 +173,11 @@ FatRequestODir (
**/
VOID
FatCleanupODirCache (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
FAT_ODIR *ODir;
+
while (Volume->DirCacheCount > 0) {
ODir = ODIR_FROM_DIRCACHELINK (Volume->DirCacheList.BackLink);
RemoveEntryList (&ODir->DirCacheLink);
diff --git a/FatPkg/EnhancedFatDxe/DirectoryManage.c b/FatPkg/EnhancedFatDxe/DirectoryManage.c
index 23871a4cdc..723fc35f38 100644
--- a/FatPkg/EnhancedFatDxe/DirectoryManage.c
+++ b/FatPkg/EnhancedFatDxe/DirectoryManage.c
@@ -24,14 +24,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
STATIC
EFI_STATUS
FatAccessEntry (
- IN FAT_OFILE *Parent,
- IN IO_MODE IoMode,
- IN UINTN EntryPos,
- IN OUT VOID *Entry
+ IN FAT_OFILE *Parent,
+ IN IO_MODE IoMode,
+ IN UINTN EntryPos,
+ IN OUT VOID *Entry
)
{
- UINTN Position;
- UINTN BufferSize;
+ UINTN Position;
+ UINTN BufferSize;
Position = EntryPos * sizeof (FAT_DIRECTORY_ENTRY);
if (Position >= Parent->FileSize) {
@@ -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;
}
@@ -61,17 +61,17 @@ FatAccessEntry (
**/
EFI_STATUS
FatStoreDirEnt (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
)
{
- EFI_STATUS Status;
- FAT_DIRECTORY_LFN LfnEntry;
- UINTN EntryPos;
- CHAR16 *LfnBufferPointer;
- CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
- UINT8 EntryCount;
- UINT8 LfnOrdinal;
+ EFI_STATUS Status;
+ FAT_DIRECTORY_LFN LfnEntry;
+ UINTN EntryPos;
+ CHAR16 *LfnBufferPointer;
+ CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
+ UINT8 EntryCount;
+ UINT8 LfnOrdinal;
EntryPos = DirEnt->EntryPos;
EntryCount = DirEnt->EntryCount;
@@ -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;
}
@@ -163,7 +164,7 @@ FatIsDotDirEnt (
STATIC
VOID
FatSetDirEntCluster (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
UINTN Cluster;
@@ -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;
}
/**
@@ -184,11 +185,11 @@ FatSetDirEntCluster (
**/
VOID
FatUpdateDirEntClusterSizeInfo (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
ASSERT (OFile->ODir == NULL);
- OFile->DirEnt->Entry.FileSize = (UINT32) OFile->FileSize;
+ OFile->DirEnt->Entry.FileSize = (UINT32)OFile->FileSize;
FatSetDirEntCluster (OFile);
}
@@ -202,14 +203,15 @@ FatUpdateDirEntClusterSizeInfo (
**/
VOID
FatCloneDirEnt (
- IN FAT_DIRENT *DirEnt1,
- IN FAT_DIRENT *DirEnt2
+ IN FAT_DIRENT *DirEnt1,
+ IN FAT_DIRENT *DirEnt2
)
{
- UINT8 *Entry1;
- UINT8 *Entry2;
- Entry1 = (UINT8 *) &DirEnt1->Entry;
- Entry2 = (UINT8 *) &DirEnt2->Entry;
+ UINT8 *Entry1;
+ UINT8 *Entry2;
+
+ Entry1 = (UINT8 *)&DirEnt1->Entry;
+ Entry2 = (UINT8 *)&DirEnt2->Entry;
CopyMem (
Entry1 + FAT_ENTRY_INFO_OFFSET,
Entry2 + FAT_ENTRY_INFO_OFFSET,
@@ -228,22 +230,22 @@ FatCloneDirEnt (
STATIC
VOID
FatLoadLongNameEntry (
- IN FAT_OFILE *Parent,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *Parent,
+ IN FAT_DIRENT *DirEnt
)
{
- CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
- CHAR16 *LfnBufferPointer;
- CHAR8 *File8Dot3Name;
- UINTN EntryPos;
- UINT8 LfnOrdinal;
- UINT8 LfnChecksum;
- FAT_DIRECTORY_LFN LfnEntry;
- EFI_STATUS Status;
-
- EntryPos = DirEnt->EntryPos;
- File8Dot3Name = DirEnt->Entry.FileName;
- LfnBufferPointer = LfnBuffer;
+ CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
+ CHAR16 *LfnBufferPointer;
+ CHAR8 *File8Dot3Name;
+ UINTN EntryPos;
+ UINT8 LfnOrdinal;
+ UINT8 LfnChecksum;
+ FAT_DIRECTORY_LFN LfnEntry;
+ EFI_STATUS Status;
+
+ EntryPos = DirEnt->EntryPos;
+ File8Dot3Name = DirEnt->Entry.FileName;
+ LfnBufferPointer = LfnBuffer;
//
// Computes checksum for LFN
//
@@ -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
@@ -312,13 +316,14 @@ FatLoadLongNameEntry (
STATIC
VOID
FatAddDirEnt (
- IN FAT_ODIR *ODir,
- IN FAT_DIRENT *DirEnt
+ IN FAT_ODIR *ODir,
+ IN FAT_DIRENT *DirEnt
)
{
if (DirEnt->Link.BackLink == NULL) {
DirEnt->Link.BackLink = &ODir->ChildList;
}
+
InsertTailList (DirEnt->Link.BackLink, &DirEnt->Link);
FatInsertToHashTable (ODir, DirEnt);
}
@@ -338,14 +343,14 @@ FatAddDirEnt (
STATIC
EFI_STATUS
FatLoadNextDirEnt (
- IN FAT_OFILE *OFile,
- OUT FAT_DIRENT **PtrDirEnt
+ IN FAT_OFILE *OFile,
+ OUT FAT_DIRENT **PtrDirEnt
)
{
- EFI_STATUS Status;
- FAT_DIRENT *DirEnt;
- FAT_ODIR *ODir;
- FAT_DIRECTORY_ENTRY Entry;
+ EFI_STATUS Status;
+ FAT_DIRENT *DirEnt;
+ FAT_ODIR *ODir;
+ FAT_DIRECTORY_ENTRY Entry;
ODir = OFile->ODir;
//
@@ -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
//
@@ -440,40 +446,40 @@ Done:
**/
EFI_STATUS
FatGetDirEntInfo (
- IN FAT_VOLUME *Volume,
- IN FAT_DIRENT *DirEnt,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN FAT_DIRENT *DirEnt,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
- UINTN Size;
- UINTN NameSize;
- UINTN ResultSize;
- UINTN Cluster;
- EFI_STATUS Status;
- EFI_FILE_INFO *Info;
- FAT_DIRECTORY_ENTRY *Entry;
- FAT_DATE_TIME FatLastAccess;
+ UINTN Size;
+ UINTN NameSize;
+ UINTN ResultSize;
+ UINTN Cluster;
+ EFI_STATUS Status;
+ EFI_FILE_INFO *Info;
+ FAT_DIRECTORY_ENTRY *Entry;
+ FAT_DATE_TIME FatLastAccess;
ASSERT_VOLUME_LOCKED (Volume);
- Size = SIZE_OF_EFI_FILE_INFO;
- NameSize = StrSize (DirEnt->FileString);
- ResultSize = Size + NameSize;
+ Size = SIZE_OF_EFI_FILE_INFO;
+ NameSize = StrSize (DirEnt->FileString);
+ ResultSize = Size + NameSize;
- Status = EFI_BUFFER_TOO_SMALL;
+ Status = EFI_BUFFER_TOO_SMALL;
if (*BufferSize >= ResultSize) {
- Status = EFI_SUCCESS;
- Entry = &DirEnt->Entry;
- Info = Buffer;
- Info->Size = ResultSize;
+ Status = EFI_SUCCESS;
+ Entry = &DirEnt->Entry;
+ Info = Buffer;
+ Info->Size = ResultSize;
if ((Entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) != 0) {
- Cluster = (Entry->FileClusterHigh << 16) | Entry->FileCluster;
- Info->PhysicalSize = FatPhysicalDirSize (Volume, Cluster);
- Info->FileSize = Info->PhysicalSize;
+ Cluster = (Entry->FileClusterHigh << 16) | Entry->FileCluster;
+ Info->PhysicalSize = FatPhysicalDirSize (Volume, Cluster);
+ Info->FileSize = Info->PhysicalSize;
} else {
- Info->FileSize = Entry->FileSize;
- Info->PhysicalSize = FatPhysicalFileSize (Volume, Entry->FileSize);
+ Info->FileSize = Entry->FileSize;
+ Info->PhysicalSize = FatPhysicalFileSize (Volume, Entry->FileSize);
}
ZeroMem (&FatLastAccess.Time, sizeof (FatLastAccess.Time));
@@ -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;
@@ -504,9 +510,9 @@ FatGetDirEntInfo (
STATIC
EFI_STATUS
FatSearchODir (
- IN FAT_OFILE *OFile,
- IN CHAR16 *FileNameString,
- OUT FAT_DIRENT **PtrDirEnt
+ IN FAT_OFILE *OFile,
+ IN CHAR16 *FileNameString,
+ OUT FAT_DIRENT **PtrDirEnt
)
{
BOOLEAN PossibleShortName;
@@ -525,9 +531,10 @@ FatSearchODir (
// Search the hash table first
//
DirEnt = *FatLongNameHashSearch (ODir, FileNameString);
- if (DirEnt == NULL && PossibleShortName) {
- DirEnt = *FatShortNameHashSearch (ODir, File8Dot3Name);
+ 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;
}
}
@@ -564,7 +571,7 @@ FatSearchODir (
**/
VOID
FatResetODirCursor (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
FAT_ODIR *ODir;
@@ -588,8 +595,8 @@ FatResetODirCursor (
**/
EFI_STATUS
FatGetNextDirEnt (
- IN FAT_OFILE *OFile,
- OUT FAT_DIRENT **PtrDirEnt
+ IN FAT_OFILE *OFile,
+ OUT FAT_DIRENT **PtrDirEnt
)
{
EFI_STATUS Status;
@@ -617,8 +624,8 @@ FatGetNextDirEnt (
//
// End of directory, return NULL
//
- DirEnt = NULL;
- ODir->CurrentPos = ODir->CurrentEndPos;
+ DirEnt = NULL;
+ ODir->CurrentPos = ODir->CurrentEndPos;
} else {
ODir->CurrentCursor = ODir->CurrentCursor->ForwardLink;
DirEnt = DIRENT_FROM_LINK (ODir->CurrentCursor);
@@ -640,8 +647,8 @@ FatGetNextDirEnt (
STATIC
VOID
FatSetEntryCount (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
)
{
CHAR16 *FileString;
@@ -650,9 +657,9 @@ FatSetEntryCount (
//
// Get new entry count and set the 8.3 name
//
- DirEnt->EntryCount = 1;
- FileString = DirEnt->FileString;
- File8Dot3Name = DirEnt->Entry.FileName;
+ DirEnt->EntryCount = 1;
+ FileString = DirEnt->FileString;
+ File8Dot3Name = DirEnt->Entry.FileName;
SetMem (File8Dot3Name, FAT_NAME_LEN, ' ');
if (StrCmp (FileString, L".") == 0) {
//
@@ -664,8 +671,8 @@ FatSetEntryCount (
//
// ".." entry
//
- File8Dot3Name[0] = '.';
- File8Dot3Name[1] = '.';
+ File8Dot3Name[0] = '.';
+ File8Dot3Name[1] = '.';
FatCloneDirEnt (DirEnt, OFile->Parent->DirEnt);
} else {
//
@@ -719,13 +726,13 @@ FatExpandODir (
STATIC
EFI_STATUS
FatSeekVolumeId (
- IN FAT_OFILE *Root,
- OUT FAT_DIRENT *DirEnt
+ IN FAT_OFILE *Root,
+ OUT FAT_DIRENT *DirEnt
)
{
- EFI_STATUS Status;
- UINTN EntryPos;
- FAT_DIRECTORY_ENTRY *Entry;
+ EFI_STATUS Status;
+ UINTN EntryPos;
+ FAT_DIRECTORY_ENTRY *Entry;
EntryPos = 0;
Entry = &DirEnt->Entry;
@@ -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;
}
@@ -766,19 +774,19 @@ FatSeekVolumeId (
STATIC
EFI_STATUS
FatFirstFitInsertDirEnt (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
)
{
- EFI_STATUS Status;
- FAT_ODIR *ODir;
- LIST_ENTRY *CurrentEntry;
- FAT_DIRENT *CurrentDirEnt;
- UINT32 CurrentPos;
- UINT32 LabelPos;
- UINT32 NewEntryPos;
- UINT16 EntryCount;
- FAT_DIRENT LabelDirEnt;
+ EFI_STATUS Status;
+ FAT_ODIR *ODir;
+ LIST_ENTRY *CurrentEntry;
+ FAT_DIRENT *CurrentDirEnt;
+ UINT32 CurrentPos;
+ UINT32 LabelPos;
+ UINT32 NewEntryPos;
+ UINT16 EntryCount;
+ FAT_DIRENT LabelDirEnt;
LabelPos = 0;
if (OFile->Parent == NULL) {
@@ -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;
}
@@ -839,8 +848,8 @@ Done:
STATIC
EFI_STATUS
FatNewEntryPos (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
)
{
EFI_STATUS Status;
@@ -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;
}
@@ -902,15 +914,15 @@ FatNewEntryPos (
**/
EFI_STATUS
FatGetVolumeEntry (
- IN FAT_VOLUME *Volume,
- IN CHAR16 *Name
+ IN FAT_VOLUME *Volume,
+ IN CHAR16 *Name
)
{
EFI_STATUS Status;
FAT_DIRENT LabelDirEnt;
- *Name = 0;
- Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
+ *Name = 0;
+ Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
if (!EFI_ERROR (Status)) {
if (!LabelDirEnt.Invalid) {
FatNameToStr (LabelDirEnt.Entry.FileName, FAT_NAME_LEN, FALSE, Name);
@@ -934,16 +946,16 @@ FatGetVolumeEntry (
**/
EFI_STATUS
FatSetVolumeEntry (
- IN FAT_VOLUME *Volume,
- IN CHAR16 *Name
+ IN FAT_VOLUME *Volume,
+ IN CHAR16 *Name
)
{
EFI_STATUS Status;
FAT_DIRENT LabelDirEnt;
FAT_OFILE *Root;
- Root = Volume->Root;
- Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
+ Root = Volume->Root;
+ Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
if (EFI_ERROR (Status)) {
return Status;
}
@@ -983,7 +995,7 @@ FatSetVolumeEntry (
**/
EFI_STATUS
FatCreateDotDirEnts (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
EFI_STATUS Status;
@@ -1002,6 +1014,7 @@ FatCreateDotDirEnts (
if (EFI_ERROR (Status)) {
return Status;
}
+
//
// Create ".."
//
@@ -1025,10 +1038,10 @@ FatCreateDotDirEnts (
**/
EFI_STATUS
FatCreateDirEnt (
- IN FAT_OFILE *OFile,
- IN CHAR16 *FileName,
- IN UINT8 Attributes,
- OUT FAT_DIRENT **PtrDirEnt
+ IN FAT_OFILE *OFile,
+ IN CHAR16 *FileName,
+ IN UINT8 Attributes,
+ OUT FAT_DIRENT **PtrDirEnt
)
{
FAT_DIRENT *DirEnt;
@@ -1043,12 +1056,13 @@ FatCreateDirEnt (
return EFI_OUT_OF_RESOURCES;
}
- DirEnt->Signature = FAT_DIRENT_SIGNATURE;
- DirEnt->FileString = AllocateCopyPool (StrSize (FileName), FileName);
+ DirEnt->Signature = FAT_DIRENT_SIGNATURE;
+ DirEnt->FileString = AllocateCopyPool (StrSize (FileName), FileName);
if (DirEnt->FileString == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
//
// Determine how many directory entries we need
//
@@ -1085,8 +1099,8 @@ Done:
**/
EFI_STATUS
FatRemoveDirEnt (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
)
{
FAT_ODIR *ODir;
@@ -1098,6 +1112,7 @@ FatRemoveDirEnt (
//
ODir->CurrentCursor = ODir->CurrentCursor->BackLink;
}
+
//
// Remove from directory entry list
//
@@ -1125,8 +1140,8 @@ FatRemoveDirEnt (
**/
EFI_STATUS
FatOpenDirEnt (
- IN FAT_OFILE *Parent,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *Parent,
+ IN FAT_DIRENT *DirEnt
)
{
FAT_OFILE *OFile;
@@ -1158,16 +1173,16 @@ FatOpenDirEnt (
//
// The newly created OFile is root
//
- Volume = VOLUME_FROM_ROOT_DIRENT (DirEnt);
- Volume->Root = OFile;
- OFile->FileCluster = Volume->RootCluster;
+ Volume = VOLUME_FROM_ROOT_DIRENT (DirEnt);
+ Volume->Root = OFile;
+ OFile->FileCluster = Volume->RootCluster;
if (Volume->FatType != Fat32) {
- OFile->IsFixedRootDir = TRUE;
+ OFile->IsFixedRootDir = TRUE;
}
}
- OFile->FileCurrentCluster = OFile->FileCluster;
- OFile->Volume = Volume;
+ OFile->FileCurrentCluster = OFile->FileCluster;
+ OFile->Volume = Volume;
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
OFile->FileSize = DirEnt->Entry.FileSize;
@@ -1199,15 +1214,15 @@ FatOpenDirEnt (
**/
VOID
FatCloseDirEnt (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
)
{
FAT_OFILE *OFile;
FAT_VOLUME *Volume;
- OFile = DirEnt->OFile;
+ OFile = DirEnt->OFile;
ASSERT (OFile != NULL);
- Volume = OFile->Volume;
+ Volume = OFile->Volume;
if (OFile->ODir != NULL) {
FatDiscardODir (OFile);
@@ -1251,10 +1266,10 @@ FatCloseDirEnt (
**/
EFI_STATUS
FatLocateOFile (
- IN OUT FAT_OFILE **PtrOFile,
- IN CHAR16 *FileName,
- IN UINT8 Attributes,
- OUT CHAR16 *NewFileName
+ IN OUT FAT_OFILE **PtrOFile,
+ IN CHAR16 *FileName,
+ IN UINT8 Attributes,
+ OUT CHAR16 *NewFileName
)
{
EFI_STATUS Status;
@@ -1273,13 +1288,14 @@ FatLocateOFile (
return EFI_INVALID_PARAMETER;
}
- OFile = *PtrOFile;
- Volume = OFile->Volume;
+ OFile = *PtrOFile;
+ Volume = OFile->Volume;
DirIntended = FALSE;
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
diff --git a/FatPkg/EnhancedFatDxe/DiskCache.c b/FatPkg/EnhancedFatDxe/DiskCache.c
index a488cd437d..d1a34a6a64 100644
--- a/FatPkg/EnhancedFatDxe/DiskCache.c
+++ b/FatPkg/EnhancedFatDxe/DiskCache.c
@@ -30,11 +30,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
STATIC
VOID
FatFlushDataCacheRange (
- IN FAT_VOLUME *Volume,
- IN IO_MODE IoMode,
- IN UINTN StartPageNo,
- IN UINTN EndPageNo,
- OUT UINT8 *Buffer
+ IN FAT_VOLUME *Volume,
+ IN IO_MODE IoMode,
+ IN UINTN StartPageNo,
+ IN UINTN EndPageNo,
+ OUT UINT8 *Buffer
)
{
UINTN PageNo;
@@ -53,9 +53,9 @@ FatFlushDataCacheRange (
PageSize = (UINTN)1 << PageAlignment;
for (PageNo = StartPageNo; PageNo < EndPageNo; PageNo++) {
- GroupNo = PageNo & GroupMask;
- CacheTag = &DiskCache->CacheTag[GroupNo];
- if (CacheTag->RealSize > 0 && CacheTag->PageNo == PageNo) {
+ GroupNo = PageNo & GroupMask;
+ CacheTag = &DiskCache->CacheTag[GroupNo];
+ 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
@@ -96,11 +96,11 @@ FatFlushDataCacheRange (
STATIC
EFI_STATUS
FatExchangeCachePage (
- IN FAT_VOLUME *Volume,
- IN CACHE_DATA_TYPE DataType,
- IN IO_MODE IoMode,
- IN CACHE_TAG *CacheTag,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN CACHE_DATA_TYPE DataType,
+ IN IO_MODE IoMode,
+ IN CACHE_TAG *CacheTag,
+ IN FAT_TASK *Task
)
{
EFI_STATUS Status;
@@ -122,16 +122,16 @@ FatExchangeCachePage (
EntryPos = DiskCache->BaseAddress + LShiftU64 (PageNo, PageAlignment);
RealSize = CacheTag->RealSize;
if (IoMode == ReadDisk) {
- RealSize = (UINTN)1 << PageAlignment;
- MaxSize = DiskCache->LimitAddress - EntryPos;
+ RealSize = (UINTN)1 << PageAlignment;
+ 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;
}
@@ -147,8 +147,8 @@ FatExchangeCachePage (
EntryPos += Volume->FatSize;
} while (--WriteCount > 0);
- CacheTag->Dirty = FALSE;
- CacheTag->RealSize = RealSize;
+ CacheTag->Dirty = FALSE;
+ CacheTag->RealSize = RealSize;
return EFI_SUCCESS;
}
@@ -168,17 +168,17 @@ FatExchangeCachePage (
STATIC
EFI_STATUS
FatGetCachePage (
- IN FAT_VOLUME *Volume,
- IN CACHE_DATA_TYPE CacheDataType,
- IN UINTN PageNo,
- IN CACHE_TAG *CacheTag
+ IN FAT_VOLUME *Volume,
+ IN CACHE_DATA_TYPE CacheDataType,
+ IN UINTN PageNo,
+ IN CACHE_TAG *CacheTag
)
{
EFI_STATUS Status;
UINTN OldPageNo;
OldPageNo = CacheTag->PageNo;
- if (CacheTag->RealSize > 0 && OldPageNo == PageNo) {
+ if ((CacheTag->RealSize > 0) && (OldPageNo == PageNo)) {
//
// Cache Hit occurred
//
@@ -188,17 +188,18 @@ 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;
//
- CacheTag->PageNo = PageNo;
- Status = FatExchangeCachePage (Volume, CacheDataType, ReadDisk, CacheTag, NULL);
+ CacheTag->PageNo = PageNo;
+ Status = FatExchangeCachePage (Volume, CacheDataType, ReadDisk, CacheTag, NULL);
return Status;
}
@@ -223,13 +224,13 @@ FatGetCachePage (
STATIC
EFI_STATUS
FatAccessUnalignedCachePage (
- IN FAT_VOLUME *Volume,
- IN CACHE_DATA_TYPE CacheDataType,
- IN IO_MODE IoMode,
- IN UINTN PageNo,
- IN UINTN Offset,
- IN UINTN Length,
- IN OUT VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN CACHE_DATA_TYPE CacheDataType,
+ IN IO_MODE IoMode,
+ IN UINTN PageNo,
+ IN UINTN Offset,
+ IN UINTN Length,
+ IN OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -247,10 +248,10 @@ FatAccessUnalignedCachePage (
Source = DiskCache->CacheBase + (GroupNo << DiskCache->PageAlignment) + Offset;
Destination = Buffer;
if (IoMode != ReadDisk) {
- CacheTag->Dirty = TRUE;
- DiskCache->Dirty = TRUE;
- Destination = Source;
- Source = Buffer;
+ CacheTag->Dirty = TRUE;
+ DiskCache->Dirty = TRUE;
+ Destination = Source;
+ Source = Buffer;
}
CopyMem (Destination, Source, Length);
@@ -290,13 +291,13 @@ FatAccessUnalignedCachePage (
**/
EFI_STATUS
FatAccessCache (
- IN FAT_VOLUME *Volume,
- IN CACHE_DATA_TYPE CacheDataType,
- IN IO_MODE IoMode,
- IN UINT64 Offset,
- IN UINTN BufferSize,
- IN OUT UINT8 *Buffer,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN CACHE_DATA_TYPE CacheDataType,
+ IN IO_MODE IoMode,
+ IN UINT64 Offset,
+ IN UINTN BufferSize,
+ IN OUT UINT8 *Buffer,
+ IN FAT_TASK *Task
)
{
EFI_STATUS Status;
@@ -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;
@@ -338,8 +339,8 @@ FatAccessCache (
PageNo++;
}
- AlignedPageCount = BufferSize >> PageAlignment;
- OverRunPageNo = PageNo + AlignedPageCount;
+ AlignedPageCount = BufferSize >> PageAlignment;
+ OverRunPageNo = PageNo + AlignedPageCount;
//
// The access of the Aligned data
//
@@ -355,14 +356,16 @@ FatAccessCache (
if (EFI_ERROR (Status)) {
return Status;
}
+
//
// If these access data over laps the relative cache range, these cache pages need
// to be updated.
//
FatFlushDataCacheRange (Volume, IoMode, PageNo, OverRunPageNo, Buffer);
- Buffer += AlignedSize;
- BufferSize -= AlignedSize;
+ Buffer += AlignedSize;
+ BufferSize -= AlignedSize;
}
+
//
// The access of the OverRun data
//
@@ -390,18 +393,18 @@ FatAccessCache (
**/
EFI_STATUS
FatVolumeFlushCache (
- IN FAT_VOLUME *Volume,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN FAT_TASK *Task
)
{
- EFI_STATUS Status;
- CACHE_DATA_TYPE CacheDataType;
- UINTN GroupIndex;
- UINTN GroupMask;
- DISK_CACHE *DiskCache;
- CACHE_TAG *CacheTag;
-
- for (CacheDataType = (CACHE_DATA_TYPE) 0; CacheDataType < CacheMaxType; CacheDataType++) {
+ EFI_STATUS Status;
+ CACHE_DATA_TYPE CacheDataType;
+ UINTN GroupIndex;
+ UINTN GroupMask;
+ DISK_CACHE *DiskCache;
+ CACHE_TAG *CacheTag;
+
+ 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.
//
@@ -443,7 +447,7 @@ FatVolumeFlushCache (
**/
EFI_STATUS
FatInitializeDiskCache (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
DISK_CACHE *DiskCache;
@@ -457,23 +461,23 @@ FatInitializeDiskCache (
// Configure the parameters of disk cache
//
if (Volume->FatType == Fat12) {
- FatCacheGroupCount = FAT_FATCACHE_GROUP_MIN_COUNT;
+ FatCacheGroupCount = FAT_FATCACHE_GROUP_MIN_COUNT;
DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MIN_ALIGNMENT;
DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MIN_ALIGNMENT;
} else {
- FatCacheGroupCount = FAT_FATCACHE_GROUP_MAX_COUNT;
+ FatCacheGroupCount = FAT_FATCACHE_GROUP_MAX_COUNT;
DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MAX_ALIGNMENT;
DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MAX_ALIGNMENT;
}
- DiskCache[CacheData].GroupMask = FAT_DATACACHE_GROUP_COUNT - 1;
- DiskCache[CacheData].BaseAddress = Volume->RootPos;
- DiskCache[CacheData].LimitAddress = Volume->VolumeSize;
- DiskCache[CacheFat].GroupMask = FatCacheGroupCount - 1;
- DiskCache[CacheFat].BaseAddress = Volume->FatPos;
- DiskCache[CacheFat].LimitAddress = Volume->FatPos + Volume->FatSize;
- FatCacheSize = FatCacheGroupCount << DiskCache[CacheFat].PageAlignment;
- DataCacheSize = FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment;
+ DiskCache[CacheData].GroupMask = FAT_DATACACHE_GROUP_COUNT - 1;
+ DiskCache[CacheData].BaseAddress = Volume->RootPos;
+ DiskCache[CacheData].LimitAddress = Volume->VolumeSize;
+ DiskCache[CacheFat].GroupMask = FatCacheGroupCount - 1;
+ DiskCache[CacheFat].BaseAddress = Volume->FatPos;
+ DiskCache[CacheFat].LimitAddress = Volume->FatPos + Volume->FatSize;
+ FatCacheSize = FatCacheGroupCount << DiskCache[CacheFat].PageAlignment;
+ DataCacheSize = FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment;
//
// Allocate the Fat Cache buffer
//
@@ -482,7 +486,7 @@ FatInitializeDiskCache (
return EFI_OUT_OF_RESOURCES;
}
- Volume->CacheBuffer = CacheBuffer;
+ Volume->CacheBuffer = CacheBuffer;
DiskCache[CacheFat].CacheBase = CacheBuffer;
DiskCache[CacheData].CacheBase = CacheBuffer + FatCacheSize;
return EFI_SUCCESS;
diff --git a/FatPkg/EnhancedFatDxe/Fat.c b/FatPkg/EnhancedFatDxe/Fat.c
index 77cda19539..358580b120 100644
--- a/FatPkg/EnhancedFatDxe/Fat.c
+++ b/FatPkg/EnhancedFatDxe/Fat.c
@@ -22,8 +22,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
FatEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
);
/**
@@ -39,7 +39,7 @@ FatEntryPoint (
EFI_STATUS
EFIAPI
FatUnload (
- IN EFI_HANDLE ImageHandle
+ IN EFI_HANDLE ImageHandle
);
/**
@@ -113,7 +113,7 @@ FatDriverBindingStop (
//
// DriverBinding protocol instance
//
-EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding = {
+EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding = {
FatDriverBindingSupported,
FatDriverBindingStart,
FatDriverBindingStop,
@@ -136,11 +136,11 @@ EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding = {
EFI_STATUS
EFIAPI
FatEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
+ EFI_STATUS Status;
//
// Initialize the EFI Driver Library
@@ -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
//
@@ -351,11 +360,11 @@ FatDriverBindingStart (
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
- EFI_STATUS Status;
- EFI_BLOCK_IO_PROTOCOL *BlockIo;
- EFI_DISK_IO_PROTOCOL *DiskIo;
- EFI_DISK_IO2_PROTOCOL *DiskIo2;
- BOOLEAN LockedByMe;
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_DISK_IO_PROTOCOL *DiskIo;
+ EFI_DISK_IO2_PROTOCOL *DiskIo2;
+ BOOLEAN LockedByMe;
LockedByMe = FALSE;
//
@@ -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;
}
@@ -472,16 +483,16 @@ Exit:
EFI_STATUS
EFIAPI
FatDriverBindingStop (
- IN EFI_DRIVER_BINDING_PROTOCOL *This,
- IN EFI_HANDLE ControllerHandle,
- IN UINTN NumberOfChildren,
- IN EFI_HANDLE *ChildHandleBuffer
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
)
{
- EFI_STATUS Status;
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
- FAT_VOLUME *Volume;
- EFI_DISK_IO2_PROTOCOL *DiskIo2;
+ EFI_STATUS Status;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
+ FAT_VOLUME *Volume;
+ EFI_DISK_IO2_PROTOCOL *DiskIo2;
DiskIo2 = NULL;
//
@@ -490,7 +501,7 @@ FatDriverBindingStop (
Status = gBS->OpenProtocol (
ControllerHandle,
&gEfiSimpleFileSystemProtocolGuid,
- (VOID **) &FileSystem,
+ (VOID **)&FileSystem,
This->DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -505,19 +516,20 @@ FatDriverBindingStop (
if (!EFI_ERROR (Status)) {
if (DiskIo2 != NULL) {
Status = gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDiskIo2ProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDiskIo2ProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
ASSERT_EFI_ERROR (Status);
}
+
Status = gBS->CloseProtocol (
- ControllerHandle,
- &gEfiDiskIoProtocolGuid,
- This->DriverBindingHandle,
- ControllerHandle
- );
+ ControllerHandle,
+ &gEfiDiskIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
ASSERT_EFI_ERROR (Status);
}
diff --git a/FatPkg/EnhancedFatDxe/Fat.h b/FatPkg/EnhancedFatDxe/Fat.h
index fcc25952d4..356cdbdb51 100644
--- a/FatPkg/EnhancedFatDxe/Fat.h
+++ b/FatPkg/EnhancedFatDxe/Fat.h
@@ -35,42 +35,42 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// The FAT signature
//
-#define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
-#define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
-#define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
-#define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
-#define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
-#define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
-#define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
+#define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
+#define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
+#define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
+#define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
+#define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
+#define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
+#define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
-#define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
+#define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
-#define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
+#define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
-#define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
+#define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
-#define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
+#define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
-#define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
+#define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
-#define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
+#define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
-#define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
+#define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
-#define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
+#define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
//
// Minimum sector size is 512B, Maximum sector size is 4096B
// Max sectors per cluster is 128
//
-#define MAX_BLOCK_ALIGNMENT 12
-#define MIN_BLOCK_ALIGNMENT 9
-#define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
+#define MAX_BLOCK_ALIGNMENT 12
+#define MIN_BLOCK_ALIGNMENT 9
+#define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
//
// Efi Time Definition
//
-#define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
+#define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
//
// Minimum fat page size is 8K, maximum fat page alignment is 32K
@@ -87,26 +87,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Used in 8.3 generation algorithm
//
-#define MAX_SPEC_RETRY 4
-#define SPEC_BASE_TAG_LEN 6
-#define HASH_BASE_TAG_LEN 2
-#define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
+#define MAX_SPEC_RETRY 4
+#define SPEC_BASE_TAG_LEN 6
+#define HASH_BASE_TAG_LEN 2
+#define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
//
// Path name separator is back slash
//
-#define PATH_NAME_SEPARATOR L'\\'
+#define PATH_NAME_SEPARATOR L'\\'
+#define EFI_PATH_STRING_LENGTH 260
+#define EFI_FILE_STRING_LENGTH 255
+#define FAT_MAX_ALLOCATE_SIZE 0xA00000
+#define LC_ISO_639_2_ENTRY_SIZE 3
+#define MAX_LANG_CODE_SIZE 100
-#define EFI_PATH_STRING_LENGTH 260
-#define EFI_FILE_STRING_LENGTH 255
-#define FAT_MAX_ALLOCATE_SIZE 0xA00000
-#define LC_ISO_639_2_ENTRY_SIZE 3
-#define MAX_LANG_CODE_SIZE 100
-
-#define FAT_MAX_DIR_CACHE_COUNT 8
-#define FAT_MAX_DIRENTRY_COUNT 0xFFFF
-typedef CHAR8 LC_ISO_639_2;
+#define FAT_MAX_DIR_CACHE_COUNT 8
+#define FAT_MAX_DIRENTRY_COUNT 0xFFFF
+typedef CHAR8 LC_ISO_639_2;
//
// The fat types we support
@@ -128,12 +127,12 @@ typedef enum {
// Used in FatDiskIo
//
typedef enum {
- ReadDisk = 0, // raw disk read
- WriteDisk = 1, // raw disk write
- ReadFat = 2, // read fat cache
- WriteFat = 3, // write fat cache
- ReadData = 6, // read data cache
- WriteData = 7 // write data cache
+ ReadDisk = 0, // raw disk read
+ WriteDisk = 1, // raw disk write
+ ReadFat = 2, // read fat cache
+ WriteFat = 3, // write fat cache
+ ReadData = 6, // read data cache
+ WriteData = 7 // write data cache
} IO_MODE;
#define CACHE_ENABLED(a) ((a) >= 2)
@@ -144,19 +143,19 @@ typedef enum {
// Disk cache tag
//
typedef struct {
- UINTN PageNo;
- UINTN RealSize;
- BOOLEAN Dirty;
+ UINTN PageNo;
+ UINTN RealSize;
+ BOOLEAN Dirty;
} CACHE_TAG;
typedef struct {
- UINT64 BaseAddress;
- UINT64 LimitAddress;
- UINT8 *CacheBase;
- BOOLEAN Dirty;
- UINT8 PageAlignment;
- UINTN GroupMask;
- CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
+ UINT64 BaseAddress;
+ UINT64 LimitAddress;
+ UINT8 *CacheBase;
+ BOOLEAN Dirty;
+ UINT8 PageAlignment;
+ UINTN GroupMask;
+ CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
} DISK_CACHE;
//
@@ -170,88 +169,88 @@ typedef struct {
//
typedef struct _FAT_DIRENT FAT_DIRENT;
-typedef struct _FAT_ODIR FAT_ODIR;
-typedef struct _FAT_OFILE FAT_OFILE;
+typedef struct _FAT_ODIR FAT_ODIR;
+typedef struct _FAT_OFILE FAT_OFILE;
typedef struct _FAT_VOLUME FAT_VOLUME;
struct _FAT_DIRENT {
- UINTN Signature;
- UINT16 EntryPos; // The position of this directory entry in the parent directory file
- UINT8 EntryCount; // The count of the directory entry in the parent directory file
- BOOLEAN Invalid; // Indicate whether this directory entry is valid
- CHAR16 *FileString; // The unicode long file name for this directory entry
- FAT_OFILE *OFile; // The OFile of the corresponding directory entry
- FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename
- FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename
- LIST_ENTRY Link; // Connection of every directory entry
- FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk
+ UINTN Signature;
+ UINT16 EntryPos; // The position of this directory entry in the parent directory file
+ UINT8 EntryCount; // The count of the directory entry in the parent directory file
+ BOOLEAN Invalid; // Indicate whether this directory entry is valid
+ CHAR16 *FileString; // The unicode long file name for this directory entry
+ FAT_OFILE *OFile; // The OFile of the corresponding directory entry
+ FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename
+ FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename
+ LIST_ENTRY Link; // Connection of every directory entry
+ FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk
};
struct _FAT_ODIR {
- UINTN Signature;
- UINT32 CurrentEndPos; // Current end position of the directory
- UINT32 CurrentPos; // Current position of the directory
- LIST_ENTRY *CurrentCursor; // Current directory entry pointer
- LIST_ENTRY ChildList; // List of all directory entries
- BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory
- LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded
- UINTN DirCacheTag; // The identification of the directory when in directory cache
- FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
- FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
+ UINTN Signature;
+ UINT32 CurrentEndPos; // Current end position of the directory
+ UINT32 CurrentPos; // Current position of the directory
+ LIST_ENTRY *CurrentCursor; // Current directory entry pointer
+ LIST_ENTRY ChildList; // List of all directory entries
+ BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory
+ LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded
+ UINTN DirCacheTag; // The identification of the directory when in directory cache
+ FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
+ FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
};
typedef struct {
- UINTN Signature;
- EFI_FILE_PROTOCOL Handle;
- UINT64 Position;
- BOOLEAN ReadOnly;
- FAT_OFILE *OFile;
- LIST_ENTRY Tasks; // List of all FAT_TASKs
- LIST_ENTRY Link; // Link to other IFiles
+ UINTN Signature;
+ EFI_FILE_PROTOCOL Handle;
+ UINT64 Position;
+ BOOLEAN ReadOnly;
+ FAT_OFILE *OFile;
+ LIST_ENTRY Tasks; // List of all FAT_TASKs
+ LIST_ENTRY Link; // Link to other IFiles
} FAT_IFILE;
typedef struct {
- UINTN Signature;
- EFI_FILE_IO_TOKEN *FileIoToken;
- FAT_IFILE *IFile;
- LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs
- LIST_ENTRY Link; // Link to other FAT_TASKs
+ UINTN Signature;
+ EFI_FILE_IO_TOKEN *FileIoToken;
+ FAT_IFILE *IFile;
+ LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs
+ LIST_ENTRY Link; // Link to other FAT_TASKs
} FAT_TASK;
typedef struct {
- UINTN Signature;
- EFI_DISK_IO2_TOKEN DiskIo2Token;
- FAT_TASK *Task;
- BOOLEAN Write;
- UINT64 Offset;
- VOID *Buffer;
- UINTN BufferSize;
- LIST_ENTRY Link;
+ UINTN Signature;
+ EFI_DISK_IO2_TOKEN DiskIo2Token;
+ FAT_TASK *Task;
+ BOOLEAN Write;
+ UINT64 Offset;
+ VOID *Buffer;
+ UINTN BufferSize;
+ LIST_ENTRY Link;
} FAT_SUBTASK;
//
// FAT_OFILE - Each opened file
//
struct _FAT_OFILE {
- UINTN Signature;
- FAT_VOLUME *Volume;
+ UINTN Signature;
+ FAT_VOLUME *Volume;
//
// A permanent error code to return to all accesses to
// this opened file
//
- EFI_STATUS Error;
+ EFI_STATUS Error;
//
// A list of the IFILE instances for this OFile
//
- LIST_ENTRY Opens;
+ LIST_ENTRY Opens;
//
// The dynamic information
//
- UINTN FileSize;
- UINTN FileCluster;
- UINTN FileCurrentCluster;
- UINTN FileLastCluster;
+ UINTN FileSize;
+ UINTN FileCluster;
+ UINTN FileCurrentCluster;
+ UINTN FileLastCluster;
//
// Dirty is set if there have been any updates to the
@@ -261,120 +260,120 @@ struct _FAT_OFILE {
// PreserveLastMod is set if the last modification of the
// file is specified by SetInfo API
//
- BOOLEAN Dirty;
- BOOLEAN IsFixedRootDir;
- BOOLEAN PreserveLastModification;
- BOOLEAN Archive;
+ BOOLEAN Dirty;
+ BOOLEAN IsFixedRootDir;
+ BOOLEAN PreserveLastModification;
+ BOOLEAN Archive;
//
// Set by an OFile SetPosition
//
- UINTN Position; // within file
- UINT64 PosDisk; // on the disk
- UINTN PosRem; // remaining in this disk run
+ UINTN Position; // within file
+ UINT64 PosDisk; // on the disk
+ UINTN PosRem; // remaining in this disk run
//
// The opened parent, full path length and currently opened child files
//
- FAT_OFILE *Parent;
- UINTN FullPathLen;
- LIST_ENTRY ChildHead;
- LIST_ENTRY ChildLink;
+ FAT_OFILE *Parent;
+ UINTN FullPathLen;
+ LIST_ENTRY ChildHead;
+ LIST_ENTRY ChildLink;
//
// The opened directory structure for a directory; if this
// OFile represents a file, then ODir = NULL
//
- FAT_ODIR *ODir;
+ FAT_ODIR *ODir;
//
// The directory entry for the Ofile
//
- FAT_DIRENT *DirEnt;
+ FAT_DIRENT *DirEnt;
//
// Link in Volume's reference list
//
- LIST_ENTRY CheckLink;
+ LIST_ENTRY CheckLink;
};
struct _FAT_VOLUME {
- UINTN Signature;
+ UINTN Signature;
- EFI_HANDLE Handle;
- BOOLEAN Valid;
- BOOLEAN DiskError;
+ EFI_HANDLE Handle;
+ BOOLEAN Valid;
+ BOOLEAN DiskError;
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;
//
// If opened, the parent handle and BlockIo interface
//
- EFI_BLOCK_IO_PROTOCOL *BlockIo;
- EFI_DISK_IO_PROTOCOL *DiskIo;
- EFI_DISK_IO2_PROTOCOL *DiskIo2;
- UINT32 MediaId;
- BOOLEAN ReadOnly;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_DISK_IO_PROTOCOL *DiskIo;
+ EFI_DISK_IO2_PROTOCOL *DiskIo2;
+ UINT32 MediaId;
+ BOOLEAN ReadOnly;
//
// Computed values from fat bpb info
//
- UINT64 VolumeSize;
- UINT64 FatPos; // Disk pos of fat tables
- UINT64 RootPos; // Disk pos of root directory
- UINT64 FirstClusterPos; // Disk pos of first cluster
- UINTN FatSize; // Number of bytes in each fat
- UINTN MaxCluster; // Max cluster number
- UINTN ClusterSize; // Cluster size of fat partition
- UINT8 ClusterAlignment; // Equal to log_2 (clustersize);
- FAT_VOLUME_TYPE FatType;
+ UINT64 VolumeSize;
+ UINT64 FatPos; // Disk pos of fat tables
+ UINT64 RootPos; // Disk pos of root directory
+ UINT64 FirstClusterPos; // Disk pos of first cluster
+ UINTN FatSize; // Number of bytes in each fat
+ UINTN MaxCluster; // Max cluster number
+ UINTN ClusterSize; // Cluster size of fat partition
+ UINT8 ClusterAlignment; // Equal to log_2 (clustersize);
+ FAT_VOLUME_TYPE FatType;
//
// Current part of fat table that's present
//
- UINT64 FatEntryPos; // Location of buffer
- UINTN FatEntrySize; // Size of buffer
- UINT32 FatEntryBuffer; // The buffer
- FAT_INFO_SECTOR FatInfoSector; // Free cluster info
- UINTN FreeInfoPos; // Pos with the free cluster info
- BOOLEAN FreeInfoValid; // If free cluster info is valid
+ UINT64 FatEntryPos; // Location of buffer
+ UINTN FatEntrySize; // Size of buffer
+ UINT32 FatEntryBuffer; // The buffer
+ FAT_INFO_SECTOR FatInfoSector; // Free cluster info
+ UINTN FreeInfoPos; // Pos with the free cluster info
+ BOOLEAN FreeInfoValid; // If free cluster info is valid
//
// Unpacked Fat BPB info
//
- UINTN NumFats;
- UINTN RootEntries; // < FAT32, root dir is fixed size
- UINTN RootCluster; // >= FAT32, root cluster chain head
+ UINTN NumFats;
+ UINTN RootEntries; // < FAT32, root dir is fixed size
+ UINTN RootCluster; // >= FAT32, root cluster chain head
//
// info for marking the volume dirty or not
//
- BOOLEAN FatDirty; // If fat-entries have been updated
- UINT32 DirtyValue;
- UINT32 NotDirtyValue;
+ BOOLEAN FatDirty; // If fat-entries have been updated
+ UINT32 DirtyValue;
+ UINT32 NotDirtyValue;
//
// The root directory entry and opened root file
//
- FAT_DIRENT RootDirEnt;
+ FAT_DIRENT RootDirEnt;
//
// File Name of root OFile, it is empty string
//
- CHAR16 RootFileString[1];
- FAT_OFILE *Root;
+ CHAR16 RootFileString[1];
+ FAT_OFILE *Root;
//
// New OFiles are added to this list so they
// can be cleaned up if they aren't referenced.
//
- LIST_ENTRY CheckRef;
+ LIST_ENTRY CheckRef;
//
// Directory cache List
//
- LIST_ENTRY DirCacheList;
- UINTN DirCacheCount;
+ LIST_ENTRY DirCacheList;
+ UINTN DirCacheCount;
//
// Disk Cache for this volume
//
- VOID *CacheBuffer;
- DISK_CACHE DiskCache[CacheMaxType];
+ VOID *CacheBuffer;
+ DISK_CACHE DiskCache[CacheMaxType];
};
//
@@ -403,11 +402,11 @@ struct _FAT_VOLUME {
EFI_STATUS
EFIAPI
FatOpen (
- IN EFI_FILE_PROTOCOL *FHand,
- OUT EFI_FILE_PROTOCOL **NewHandle,
- IN CHAR16 *FileName,
- IN UINT64 OpenMode,
- IN UINT64 Attributes
+ IN EFI_FILE_PROTOCOL *FHand,
+ OUT EFI_FILE_PROTOCOL **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes
)
;
@@ -433,12 +432,12 @@ FatOpen (
EFI_STATUS
EFIAPI
FatOpenEx (
- IN EFI_FILE_PROTOCOL *FHand,
- OUT EFI_FILE_PROTOCOL **NewHandle,
- IN CHAR16 *FileName,
- IN UINT64 OpenMode,
- IN UINT64 Attributes,
- IN OUT EFI_FILE_IO_TOKEN *Token
+ IN EFI_FILE_PROTOCOL *FHand,
+ OUT EFI_FILE_PROTOCOL **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes,
+ IN OUT EFI_FILE_IO_TOKEN *Token
)
;
@@ -457,8 +456,8 @@ FatOpenEx (
EFI_STATUS
EFIAPI
FatGetPosition (
- IN EFI_FILE_PROTOCOL *FHand,
- OUT UINT64 *Position
+ IN EFI_FILE_PROTOCOL *FHand,
+ OUT UINT64 *Position
)
;
@@ -478,10 +477,10 @@ FatGetPosition (
EFI_STATUS
EFIAPI
FatGetInfo (
- IN EFI_FILE_PROTOCOL *FHand,
- IN EFI_GUID *Type,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN EFI_FILE_PROTOCOL *FHand,
+ IN EFI_GUID *Type,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
;
@@ -619,9 +618,9 @@ FatSetPosition (
EFI_STATUS
EFIAPI
FatRead (
- IN EFI_FILE_PROTOCOL *FHand,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN EFI_FILE_PROTOCOL *FHand,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
;
@@ -666,9 +665,9 @@ FatReadEx (
EFI_STATUS
EFIAPI
FatWrite (
- IN EFI_FILE_PROTOCOL *FHand,
- IN OUT UINTN *BufferSize,
- IN VOID *Buffer
+ IN EFI_FILE_PROTOCOL *FHand,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
)
;
@@ -696,6 +695,7 @@ FatWriteEx (
//
// DiskCache.c
//
+
/**
Initialize the disk cache according to Volume's FatType.
@@ -708,7 +708,7 @@ FatWriteEx (
**/
EFI_STATUS
FatInitializeDiskCache (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
);
/**
@@ -742,13 +742,13 @@ FatInitializeDiskCache (
**/
EFI_STATUS
FatAccessCache (
- IN FAT_VOLUME *Volume,
- IN CACHE_DATA_TYPE CacheDataType,
- IN IO_MODE IoMode,
- IN UINT64 Offset,
- IN UINTN BufferSize,
- IN OUT UINT8 *Buffer,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN CACHE_DATA_TYPE CacheDataType,
+ IN IO_MODE IoMode,
+ IN UINT64 Offset,
+ IN UINTN BufferSize,
+ IN OUT UINT8 *Buffer,
+ IN FAT_TASK *Task
);
/**
@@ -764,13 +764,14 @@ FatAccessCache (
**/
EFI_STATUS
FatVolumeFlushCache (
- IN FAT_VOLUME *Volume,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN FAT_TASK *Task
);
//
// Flush.c
//
+
/**
Flush the data associated with an open file.
@@ -784,7 +785,7 @@ FatVolumeFlushCache (
**/
EFI_STATUS
FatOFileFlush (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -801,7 +802,7 @@ FatOFileFlush (
**/
BOOLEAN
FatCheckOFileRef (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -814,8 +815,8 @@ FatCheckOFileRef (
**/
VOID
FatSetVolumeError (
- IN FAT_OFILE *OFile,
- IN EFI_STATUS Status
+ IN FAT_OFILE *OFile,
+ IN EFI_STATUS Status
);
/**
@@ -829,7 +830,7 @@ FatSetVolumeError (
**/
EFI_STATUS
FatIFileClose (
- FAT_IFILE *IFile
+ FAT_IFILE *IFile
);
/**
@@ -850,15 +851,16 @@ FatIFileClose (
**/
EFI_STATUS
FatCleanupVolume (
- IN FAT_VOLUME *Volume,
- IN FAT_OFILE *OFile,
- IN EFI_STATUS EfiStatus,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN FAT_OFILE *OFile,
+ IN EFI_STATUS EfiStatus,
+ IN FAT_TASK *Task
);
//
// FileSpace.c
//
+
/**
Shrink the end of the open file base on the file size.
@@ -871,7 +873,7 @@ FatCleanupVolume (
**/
EFI_STATUS
FatShrinkEof (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -889,8 +891,8 @@ FatShrinkEof (
**/
EFI_STATUS
FatGrowEof (
- IN FAT_OFILE *OFile,
- IN UINT64 NewSizeInBytes
+ IN FAT_OFILE *OFile,
+ IN UINT64 NewSizeInBytes
);
/**
@@ -906,8 +908,8 @@ FatGrowEof (
**/
UINTN
FatPhysicalDirSize (
- IN FAT_VOLUME *Volume,
- IN UINTN Cluster
+ IN FAT_VOLUME *Volume,
+ IN UINTN Cluster
);
/**
@@ -922,8 +924,8 @@ FatPhysicalDirSize (
**/
UINT64
FatPhysicalFileSize (
- IN FAT_VOLUME *Volume,
- IN UINTN RealSize
+ IN FAT_VOLUME *Volume,
+ IN UINTN RealSize
);
/**
@@ -941,9 +943,9 @@ FatPhysicalFileSize (
**/
EFI_STATUS
FatOFilePosition (
- IN FAT_OFILE *OFile,
- IN UINTN Position,
- IN UINTN PosLimit
+ IN FAT_OFILE *OFile,
+ IN UINTN Position,
+ IN UINTN PosLimit
);
/**
@@ -955,12 +957,13 @@ FatOFilePosition (
**/
VOID
FatComputeFreeInfo (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
);
//
// Init.c
//
+
/**
Allocates volume structure, detects FAT file system, installs protocol,
@@ -978,10 +981,10 @@ FatComputeFreeInfo (
**/
EFI_STATUS
FatAllocateVolume (
- IN EFI_HANDLE Handle,
- IN EFI_DISK_IO_PROTOCOL *DiskIo,
- IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
- IN EFI_BLOCK_IO_PROTOCOL *BlockIo
+ IN EFI_HANDLE Handle,
+ IN EFI_DISK_IO_PROTOCOL *DiskIo,
+ IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
+ IN EFI_BLOCK_IO_PROTOCOL *BlockIo
);
/**
@@ -997,7 +1000,7 @@ FatAllocateVolume (
**/
EFI_STATUS
FatOpenDevice (
- IN OUT FAT_VOLUME *Volume
+ IN OUT FAT_VOLUME *Volume
);
/**
@@ -1012,12 +1015,13 @@ FatOpenDevice (
**/
EFI_STATUS
FatAbandonVolume (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
);
//
// Misc.c
//
+
/**
Create the task
@@ -1030,8 +1034,8 @@ FatAbandonVolume (
**/
FAT_TASK *
FatCreateTask (
- FAT_IFILE *IFile,
- EFI_FILE_IO_TOKEN *Token
+ FAT_IFILE *IFile,
+ EFI_FILE_IO_TOKEN *Token
);
/**
@@ -1043,7 +1047,7 @@ FatCreateTask (
**/
VOID
FatDestroyTask (
- FAT_TASK *Task
+ FAT_TASK *Task
);
/**
@@ -1055,7 +1059,7 @@ FatDestroyTask (
**/
VOID
FatWaitNonblockingTask (
- FAT_IFILE *IFile
+ FAT_IFILE *IFile
);
/**
@@ -1069,7 +1073,7 @@ FatWaitNonblockingTask (
**/
LIST_ENTRY *
FatDestroySubtask (
- FAT_SUBTASK *Subtask
+ FAT_SUBTASK *Subtask
);
/**
@@ -1085,8 +1089,8 @@ FatDestroySubtask (
**/
EFI_STATUS
FatQueueTask (
- IN FAT_IFILE *IFile,
- IN FAT_TASK *Task
+ IN FAT_IFILE *IFile,
+ IN FAT_TASK *Task
);
/**
@@ -1103,9 +1107,9 @@ FatQueueTask (
**/
EFI_STATUS
FatAccessVolumeDirty (
- IN FAT_VOLUME *Volume,
- IN IO_MODE IoMode,
- IN VOID *DirtyValue
+ IN FAT_VOLUME *Volume,
+ IN IO_MODE IoMode,
+ IN VOID *DirtyValue
);
/**
@@ -1126,12 +1130,12 @@ FatAccessVolumeDirty (
**/
EFI_STATUS
FatDiskIo (
- IN FAT_VOLUME *Volume,
- IN IO_MODE IoMode,
- IN UINT64 Offset,
- IN UINTN BufferSize,
- IN OUT VOID *Buffer,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN IO_MODE IoMode,
+ IN UINT64 Offset,
+ IN UINTN BufferSize,
+ IN OUT VOID *Buffer,
+ IN FAT_TASK *Task
);
/**
@@ -1178,7 +1182,7 @@ FatAcquireLockOrFail (
**/
VOID
FatFreeDirEnt (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1190,7 +1194,7 @@ FatFreeDirEnt (
**/
VOID
FatFreeVolume (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
);
/**
@@ -1203,8 +1207,8 @@ FatFreeVolume (
**/
VOID
FatEfiTimeToFatTime (
- IN EFI_TIME *ETime,
- OUT FAT_DATE_TIME *FTime
+ IN EFI_TIME *ETime,
+ OUT FAT_DATE_TIME *FTime
);
/**
@@ -1217,8 +1221,8 @@ FatEfiTimeToFatTime (
**/
VOID
FatFatTimeToEfiTime (
- IN FAT_DATE_TIME *FTime,
- OUT EFI_TIME *ETime
+ IN FAT_DATE_TIME *FTime,
+ OUT EFI_TIME *ETime
);
/**
@@ -1230,7 +1234,7 @@ FatFatTimeToEfiTime (
**/
VOID
FatGetCurrentFatTime (
- OUT FAT_DATE_TIME *FatTime
+ OUT FAT_DATE_TIME *FatTime
);
/**
@@ -1245,12 +1249,13 @@ FatGetCurrentFatTime (
**/
BOOLEAN
FatIsValidTime (
- IN EFI_TIME *Time
+ IN EFI_TIME *Time
);
//
// UnicodeCollation.c
//
+
/**
Initialize Unicode Collation support.
@@ -1266,7 +1271,7 @@ FatIsValidTime (
**/
EFI_STATUS
InitializeUnicodeCollationSupport (
- IN EFI_HANDLE AgentHandle
+ IN EFI_HANDLE AgentHandle
);
/**
@@ -1281,9 +1286,9 @@ InitializeUnicodeCollationSupport (
**/
VOID
FatFatToStr (
- IN UINTN FatSize,
- IN CHAR8 *Fat,
- OUT CHAR16 *String
+ IN UINTN FatSize,
+ IN CHAR8 *Fat,
+ OUT CHAR16 *String
);
/**
@@ -1299,9 +1304,9 @@ FatFatToStr (
**/
BOOLEAN
FatStrToFat (
- IN CHAR16 *String,
- IN UINTN FatSize,
- OUT CHAR8 *Fat
+ IN CHAR16 *String,
+ IN UINTN FatSize,
+ OUT CHAR8 *Fat
);
/**
@@ -1312,7 +1317,7 @@ FatStrToFat (
**/
VOID
FatStrLwr (
- IN CHAR16 *Str
+ IN CHAR16 *Str
);
/**
@@ -1323,7 +1328,7 @@ FatStrLwr (
**/
VOID
FatStrUpr (
- IN CHAR16 *Str
+ IN CHAR16 *Str
);
/**
@@ -1338,8 +1343,8 @@ FatStrUpr (
**/
INTN
FatStriCmp (
- IN CHAR16 *Str1,
- IN CHAR16 *Str2
+ IN CHAR16 *Str1,
+ IN CHAR16 *Str2
);
//
@@ -1370,11 +1375,11 @@ FatStriCmp (
**/
EFI_STATUS
FatOFileOpen (
- IN FAT_OFILE *OFile,
- OUT FAT_IFILE **NewIFile,
- IN CHAR16 *FileName,
- IN UINT64 OpenMode,
- IN UINT8 Attributes
+ IN FAT_OFILE *OFile,
+ OUT FAT_IFILE **NewIFile,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT8 Attributes
);
/**
@@ -1391,13 +1396,14 @@ FatOFileOpen (
**/
EFI_STATUS
FatAllocateIFile (
- IN FAT_OFILE *OFile,
- OUT FAT_IFILE **PtrIFile
+ IN FAT_OFILE *OFile,
+ OUT FAT_IFILE **PtrIFile
);
//
// OpenVolume.c
//
+
/**
Implements Simple File System Protocol interface function OpenVolume().
@@ -1413,13 +1419,14 @@ FatAllocateIFile (
EFI_STATUS
EFIAPI
FatOpenVolume (
- IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
- OUT EFI_FILE_PROTOCOL **File
+ IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
+ OUT EFI_FILE_PROTOCOL **File
);
//
// ReadWrite.c
//
+
/**
This function reads data from a file or writes data to a file.
@@ -1438,12 +1445,12 @@ FatOpenVolume (
**/
EFI_STATUS
FatAccessOFile (
- IN FAT_OFILE *OFile,
- IN IO_MODE IoMode,
- IN UINTN Position,
- IN UINTN *DataBufferSize,
- IN UINT8 *UserBuffer,
- IN FAT_TASK *Task
+ IN FAT_OFILE *OFile,
+ IN IO_MODE IoMode,
+ IN UINTN Position,
+ IN UINTN *DataBufferSize,
+ IN UINT8 *UserBuffer,
+ IN FAT_TASK *Task
);
/**
@@ -1459,8 +1466,8 @@ FatAccessOFile (
**/
EFI_STATUS
FatExpandOFile (
- IN FAT_OFILE *OFile,
- IN UINT64 ExpandedSize
+ IN FAT_OFILE *OFile,
+ IN UINT64 ExpandedSize
);
/**
@@ -1477,8 +1484,8 @@ FatExpandOFile (
**/
EFI_STATUS
FatWriteZeroPool (
- IN FAT_OFILE *OFile,
- IN UINTN WritePos
+ IN FAT_OFILE *OFile,
+ IN UINTN WritePos
);
/**
@@ -1494,13 +1501,14 @@ FatWriteZeroPool (
**/
EFI_STATUS
FatTruncateOFile (
- IN FAT_OFILE *OFile,
- IN UINTN TruncatedSize
+ IN FAT_OFILE *OFile,
+ IN UINTN TruncatedSize
);
//
// DirectoryManage.c
//
+
/**
Set the OFile's current directory cursor to the list head.
@@ -1510,7 +1518,7 @@ FatTruncateOFile (
**/
VOID
FatResetODirCursor (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -1526,8 +1534,8 @@ FatResetODirCursor (
**/
EFI_STATUS
FatGetNextDirEnt (
- IN FAT_OFILE *OFile,
- OUT FAT_DIRENT **PtrDirEnt
+ IN FAT_OFILE *OFile,
+ OUT FAT_DIRENT **PtrDirEnt
);
/**
@@ -1543,8 +1551,8 @@ FatGetNextDirEnt (
**/
EFI_STATUS
FatRemoveDirEnt (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1560,8 +1568,8 @@ FatRemoveDirEnt (
**/
EFI_STATUS
FatStoreDirEnt (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1580,10 +1588,10 @@ FatStoreDirEnt (
**/
EFI_STATUS
FatCreateDirEnt (
- IN FAT_OFILE *OFile,
- IN CHAR16 *FileName,
- IN UINT8 Attributes,
- OUT FAT_DIRENT **PtrDirEnt
+ IN FAT_OFILE *OFile,
+ IN CHAR16 *FileName,
+ IN UINT8 Attributes,
+ OUT FAT_DIRENT **PtrDirEnt
);
/**
@@ -1598,7 +1606,7 @@ FatCreateDirEnt (
**/
BOOLEAN
FatIsDotDirEnt (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1610,7 +1618,7 @@ FatIsDotDirEnt (
**/
VOID
FatUpdateDirEntClusterSizeInfo (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -1623,8 +1631,8 @@ FatUpdateDirEntClusterSizeInfo (
**/
VOID
FatCloneDirEnt (
- IN FAT_DIRENT *DirEnt1,
- IN FAT_DIRENT *DirEnt2
+ IN FAT_DIRENT *DirEnt1,
+ IN FAT_DIRENT *DirEnt2
);
/**
@@ -1642,10 +1650,10 @@ FatCloneDirEnt (
**/
EFI_STATUS
FatGetDirEntInfo (
- IN FAT_VOLUME *Volume,
- IN FAT_DIRENT *DirEnt,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN FAT_DIRENT *DirEnt,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
);
/**
@@ -1662,8 +1670,8 @@ FatGetDirEntInfo (
**/
EFI_STATUS
FatOpenDirEnt (
- IN FAT_OFILE *OFile,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *OFile,
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1678,7 +1686,7 @@ FatOpenDirEnt (
**/
EFI_STATUS
FatCreateDotDirEnts (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -1690,7 +1698,7 @@ FatCreateDotDirEnts (
**/
VOID
FatCloseDirEnt (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1715,10 +1723,10 @@ FatCloseDirEnt (
**/
EFI_STATUS
FatLocateOFile (
- IN OUT FAT_OFILE **PtrOFile,
- IN CHAR16 *FileName,
- IN UINT8 Attributes,
- OUT CHAR16 *NewFileName
+ IN OUT FAT_OFILE **PtrOFile,
+ IN CHAR16 *FileName,
+ IN UINT8 Attributes,
+ OUT CHAR16 *NewFileName
);
/**
@@ -1734,8 +1742,8 @@ FatLocateOFile (
**/
EFI_STATUS
FatGetVolumeEntry (
- IN FAT_VOLUME *Volume,
- IN CHAR16 *Name
+ IN FAT_VOLUME *Volume,
+ IN CHAR16 *Name
);
/**
@@ -1752,13 +1760,14 @@ FatGetVolumeEntry (
**/
EFI_STATUS
FatSetVolumeEntry (
- IN FAT_VOLUME *Volume,
- IN CHAR16 *Name
+ IN FAT_VOLUME *Volume,
+ IN CHAR16 *Name
);
//
// Hash.c
//
+
/**
Search the long name hash table for the directory entry.
@@ -1771,8 +1780,8 @@ FatSetVolumeEntry (
**/
FAT_DIRENT **
FatLongNameHashSearch (
- IN FAT_ODIR *ODir,
- IN CHAR16 *LongNameString
+ IN FAT_ODIR *ODir,
+ IN CHAR16 *LongNameString
);
/**
@@ -1787,8 +1796,8 @@ FatLongNameHashSearch (
**/
FAT_DIRENT **
FatShortNameHashSearch (
- IN FAT_ODIR *ODir,
- IN CHAR8 *ShortNameString
+ IN FAT_ODIR *ODir,
+ IN CHAR8 *ShortNameString
);
/**
@@ -1801,8 +1810,8 @@ FatShortNameHashSearch (
**/
VOID
FatInsertToHashTable (
- IN FAT_ODIR *ODir,
- IN FAT_DIRENT *DirEnt
+ IN FAT_ODIR *ODir,
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1815,13 +1824,14 @@ FatInsertToHashTable (
**/
VOID
FatDeleteFromHashTable (
- IN FAT_ODIR *ODir,
- IN FAT_DIRENT *DirEnt
+ IN FAT_ODIR *ODir,
+ IN FAT_DIRENT *DirEnt
);
//
// FileName.c
//
+
/**
This function checks whether the input FileName is a valid 8.3 short name.
@@ -1837,8 +1847,8 @@ FatDeleteFromHashTable (
**/
BOOLEAN
FatCheckIs8Dot3Name (
- IN CHAR16 *FileName,
- OUT CHAR8 *File8Dot3Name
+ IN CHAR16 *FileName,
+ OUT CHAR8 *File8Dot3Name
);
/**
@@ -1851,8 +1861,8 @@ FatCheckIs8Dot3Name (
**/
VOID
FatCreate8Dot3Name (
- IN FAT_OFILE *Parent,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *Parent,
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1868,10 +1878,10 @@ FatCreate8Dot3Name (
**/
VOID
FatNameToStr (
- IN CHAR8 *FatName,
- IN UINTN Len,
- IN UINTN LowerCase,
- IN CHAR16 *Str
+ IN CHAR8 *FatName,
+ IN UINTN Len,
+ IN UINTN LowerCase,
+ IN CHAR16 *Str
);
/**
@@ -1883,7 +1893,7 @@ FatNameToStr (
**/
VOID
FatSetCaseFlag (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
);
/**
@@ -1897,9 +1907,9 @@ FatSetCaseFlag (
**/
VOID
FatGetFileNameViaCaseFlag (
- IN FAT_DIRENT *DirEnt,
- IN OUT CHAR16 *FileString,
- IN UINTN FileStringMax
+ IN FAT_DIRENT *DirEnt,
+ IN OUT CHAR16 *FileString,
+ IN UINTN FileStringMax
);
/**
@@ -1913,7 +1923,7 @@ FatGetFileNameViaCaseFlag (
**/
UINT8
FatCheckSum (
- IN CHAR8 *ShortNameString
+ IN CHAR8 *ShortNameString
);
/**
@@ -1928,10 +1938,10 @@ FatCheckSum (
The position after Name in the Path
**/
-CHAR16*
+CHAR16 *
FatGetNextNameComponent (
- IN CHAR16 *Path,
- OUT CHAR16 *Name
+ IN CHAR16 *Path,
+ OUT CHAR16 *Name
);
/**
@@ -1956,6 +1966,7 @@ FatFileNameIsValid (
//
// DirectoryCache.c
//
+
/**
Discard the directory structure when an OFile will be freed.
@@ -1966,7 +1977,7 @@ FatFileNameIsValid (
**/
VOID
FatDiscardODir (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -1980,7 +1991,7 @@ FatDiscardODir (
**/
VOID
FatRequestODir (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
);
/**
@@ -1992,17 +2003,17 @@ FatRequestODir (
**/
VOID
FatCleanupODirCache (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
);
//
// Global Variables
//
-extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
-extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
-extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
-extern EFI_LOCK FatFsLock;
-extern EFI_LOCK FatTaskLock;
-extern EFI_FILE_PROTOCOL FatFileInterface;
+extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
+extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
+extern EFI_LOCK FatFsLock;
+extern EFI_LOCK FatTaskLock;
+extern EFI_FILE_PROTOCOL FatFileInterface;
#endif
diff --git a/FatPkg/EnhancedFatDxe/FatFileSystem.h b/FatPkg/EnhancedFatDxe/FatFileSystem.h
index fc24293d52..60b9c56b71 100644
--- a/FatPkg/EnhancedFatDxe/FatFileSystem.h
+++ b/FatPkg/EnhancedFatDxe/FatFileSystem.h
@@ -20,142 +20,141 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// FAT entry values
//
-#define FAT_CLUSTER_SPECIAL_EXT (MAX_UINTN & (~0xF))
-#define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
-#define FAT_CLUSTER_FREE 0
-#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
-#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
-#define FAT_CLUSTER_LAST (-1)
-#define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
-#define FAT_MIN_CLUSTER 2
-#define FAT_MAX_FAT12_CLUSTER 0xFF5
-#define FAT_MAX_FAT16_CLUSTER 0xFFF5
-#define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
-#define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
-#define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
-#define FAT_CLUSTER_MASK_FAT12 0xFFF
-#define FAT_CLUSTER_UNMASK_FAT12 0xF000
-#define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
-#define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
-#define FAT_POS_FAT12(a) ((a) * 3 / 2)
-#define FAT_POS_FAT16(a) ((a) * 2)
-#define FAT_POS_FAT32(a) ((a) * 4)
-#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
-
+#define FAT_CLUSTER_SPECIAL_EXT (MAX_UINTN & (~0xF))
+#define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
+#define FAT_CLUSTER_FREE 0
+#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
+#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
+#define FAT_CLUSTER_LAST (-1)
+#define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
+#define FAT_MIN_CLUSTER 2
+#define FAT_MAX_FAT12_CLUSTER 0xFF5
+#define FAT_MAX_FAT16_CLUSTER 0xFFF5
+#define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
+#define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
+#define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
+#define FAT_CLUSTER_MASK_FAT12 0xFFF
+#define FAT_CLUSTER_UNMASK_FAT12 0xF000
+#define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
+#define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
+#define FAT_POS_FAT12(a) ((a) * 3 / 2)
+#define FAT_POS_FAT16(a) ((a) * 2)
+#define FAT_POS_FAT32(a) ((a) * 4)
+#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
//
// FAT attribute define
//
-#define FAT_ATTRIBUTE_READ_ONLY 0x01
-#define FAT_ATTRIBUTE_HIDDEN 0x02
-#define FAT_ATTRIBUTE_SYSTEM 0x04
-#define FAT_ATTRIBUTE_VOLUME_ID 0x08
-#define FAT_ATTRIBUTE_DIRECTORY 0x10
-#define FAT_ATTRIBUTE_ARCHIVE 0x20
-#define FAT_ATTRIBUTE_DEVICE 0x40
-#define FAT_ATTRIBUTE_LFN 0x0F
+#define FAT_ATTRIBUTE_READ_ONLY 0x01
+#define FAT_ATTRIBUTE_HIDDEN 0x02
+#define FAT_ATTRIBUTE_SYSTEM 0x04
+#define FAT_ATTRIBUTE_VOLUME_ID 0x08
+#define FAT_ATTRIBUTE_DIRECTORY 0x10
+#define FAT_ATTRIBUTE_ARCHIVE 0x20
+#define FAT_ATTRIBUTE_DEVICE 0x40
+#define FAT_ATTRIBUTE_LFN 0x0F
//
// Some Long File Name definitions
//
-#define FAT_LFN_LAST 0x40 // Ordinal field
-#define MAX_LFN_ENTRIES 20
-#define LFN_CHAR1_LEN 5
-#define LFN_CHAR2_LEN 6
-#define LFN_CHAR3_LEN 2
-#define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
-#define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
+#define FAT_LFN_LAST 0x40 // Ordinal field
+#define MAX_LFN_ENTRIES 20
+#define LFN_CHAR1_LEN 5
+#define LFN_CHAR2_LEN 6
+#define LFN_CHAR3_LEN 2
+#define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
+#define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
//
// Some 8.3 File Name definitions
//
-#define FAT_MAIN_NAME_LEN 8
-#define FAT_EXTEND_NAME_LEN 3
-#define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
+#define FAT_MAIN_NAME_LEN 8
+#define FAT_EXTEND_NAME_LEN 3
+#define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
//
// Some directory entry information
//
-#define FAT_ENTRY_INFO_OFFSET 13
-#define DELETE_ENTRY_MARK 0xE5
-#define EMPTY_ENTRY_MARK 0x00
+#define FAT_ENTRY_INFO_OFFSET 13
+#define DELETE_ENTRY_MARK 0xE5
+#define EMPTY_ENTRY_MARK 0x00
//
// Volume dirty Mask
//
-#define FAT16_DIRTY_MASK 0x7fff
-#define FAT32_DIRTY_MASK 0xf7ffffff
+#define FAT16_DIRTY_MASK 0x7fff
+#define FAT32_DIRTY_MASK 0xf7ffffff
//
// internal flag
//
-#define FAT_CASE_MIXED 0x01
-#define FAT_CASE_NAME_LOWER 0x08
-#define FAT_CASE_EXT_LOWER 0x10
+#define FAT_CASE_MIXED 0x01
+#define FAT_CASE_NAME_LOWER 0x08
+#define FAT_CASE_EXT_LOWER 0x10
typedef struct {
- UINT8 Ia32Jump[3];
- CHAR8 OemId[8];
- UINT16 SectorSize;
- UINT8 SectorsPerCluster;
- UINT16 ReservedSectors;
- UINT8 NumFats;
- UINT16 RootEntries; // < FAT32, root dir is fixed size
- UINT16 Sectors;
- UINT8 Media;
- UINT16 SectorsPerFat; // < FAT32
- UINT16 SectorsPerTrack; // (ignored)
- UINT16 Heads; // (ignored)
- UINT32 HiddenSectors; // (ignored)
- UINT32 LargeSectors; // Used if Sectors==0
+ UINT8 Ia32Jump[3];
+ CHAR8 OemId[8];
+ UINT16 SectorSize;
+ UINT8 SectorsPerCluster;
+ UINT16 ReservedSectors;
+ UINT8 NumFats;
+ UINT16 RootEntries; // < FAT32, root dir is fixed size
+ UINT16 Sectors;
+ UINT8 Media;
+ UINT16 SectorsPerFat; // < FAT32
+ UINT16 SectorsPerTrack; // (ignored)
+ UINT16 Heads; // (ignored)
+ UINT32 HiddenSectors; // (ignored)
+ UINT32 LargeSectors; // Used if Sectors==0
} FAT_BOOT_SECTOR_BASIC;
typedef struct {
- UINT8 PhysicalDriveNumber; // (ignored)
- UINT8 CurrentHead; // holds boot_sector_dirty bit
- UINT8 Signature; // (ignored)
- CHAR8 Id[4];
- CHAR8 FatLabel[11];
- CHAR8 SystemId[8];
+ UINT8 PhysicalDriveNumber; // (ignored)
+ UINT8 CurrentHead; // holds boot_sector_dirty bit
+ UINT8 Signature; // (ignored)
+ CHAR8 Id[4];
+ CHAR8 FatLabel[11];
+ CHAR8 SystemId[8];
} FAT_BOOT_SECTOR_EXT;
typedef struct {
- UINT32 LargeSectorsPerFat; // FAT32
- UINT16 ExtendedFlags; // FAT32 (ignored)
- UINT16 FsVersion; // FAT32 (ignored)
- UINT32 RootDirFirstCluster; // FAT32
- UINT16 FsInfoSector; // FAT32
- UINT16 BackupBootSector; // FAT32
- UINT8 Reserved[12]; // FAT32 (ignored)
- UINT8 PhysicalDriveNumber; // (ignored)
- UINT8 CurrentHead; // holds boot_sector_dirty bit
- UINT8 Signature; // (ignored)
- CHAR8 Id[4];
- CHAR8 FatLabel[11];
- CHAR8 SystemId[8];
+ UINT32 LargeSectorsPerFat; // FAT32
+ UINT16 ExtendedFlags; // FAT32 (ignored)
+ UINT16 FsVersion; // FAT32 (ignored)
+ UINT32 RootDirFirstCluster; // FAT32
+ UINT16 FsInfoSector; // FAT32
+ UINT16 BackupBootSector; // FAT32
+ UINT8 Reserved[12]; // FAT32 (ignored)
+ UINT8 PhysicalDriveNumber; // (ignored)
+ UINT8 CurrentHead; // holds boot_sector_dirty bit
+ UINT8 Signature; // (ignored)
+ CHAR8 Id[4];
+ CHAR8 FatLabel[11];
+ CHAR8 SystemId[8];
} FAT32_BOOT_SECTOR_EXT;
typedef union {
- FAT_BOOT_SECTOR_EXT FatBse;
- FAT32_BOOT_SECTOR_EXT Fat32Bse;
- } FAT_BSE;
+ FAT_BOOT_SECTOR_EXT FatBse;
+ FAT32_BOOT_SECTOR_EXT Fat32Bse;
+} FAT_BSE;
typedef struct {
- FAT_BOOT_SECTOR_BASIC FatBsb;
- FAT_BSE FatBse;
+ FAT_BOOT_SECTOR_BASIC FatBsb;
+ FAT_BSE FatBse;
} FAT_BOOT_SECTOR;
//
// FAT Info Structure
//
typedef struct {
- UINT32 ClusterCount;
- UINT32 NextCluster;
+ UINT32 ClusterCount;
+ UINT32 NextCluster;
} FAT_FREE_INFO;
typedef struct {
- UINT32 Signature;
- UINT8 ExtraBootCode[480];
- UINT32 InfoBeginSignature;
- FAT_FREE_INFO FreeInfo;
- UINT8 Reserved[12];
- UINT32 InfoEndSignature;
+ UINT32 Signature;
+ UINT8 ExtraBootCode[480];
+ UINT32 InfoBeginSignature;
+ FAT_FREE_INFO FreeInfo;
+ UINT8 Reserved[12];
+ UINT32 InfoEndSignature;
} FAT_INFO_SECTOR;
//
@@ -163,44 +162,44 @@ typedef struct {
//
#define FAT_MAX_YEAR_FROM_1980 0x7f
typedef struct {
- UINT16 Day : 5;
- UINT16 Month : 4;
- UINT16 Year : 7; // From 1980
+ UINT16 Day : 5;
+ UINT16 Month : 4;
+ UINT16 Year : 7; // From 1980
} FAT_DATE;
typedef struct {
- UINT16 DoubleSecond : 5;
- UINT16 Minute : 6;
- UINT16 Hour : 5;
+ UINT16 DoubleSecond : 5;
+ UINT16 Minute : 6;
+ UINT16 Hour : 5;
} FAT_TIME;
typedef struct {
- FAT_TIME Time;
- FAT_DATE Date;
+ FAT_TIME Time;
+ FAT_DATE Date;
} FAT_DATE_TIME;
typedef struct {
- CHAR8 FileName[11]; // 8.3 filename
- UINT8 Attributes;
- UINT8 CaseFlag;
- UINT8 CreateMillisecond; // (creation milliseconds - ignored)
- FAT_DATE_TIME FileCreateTime;
- FAT_DATE FileLastAccess;
- UINT16 FileClusterHigh; // >= FAT32
- FAT_DATE_TIME FileModificationTime;
- UINT16 FileCluster;
- UINT32 FileSize;
+ CHAR8 FileName[11]; // 8.3 filename
+ UINT8 Attributes;
+ UINT8 CaseFlag;
+ UINT8 CreateMillisecond; // (creation milliseconds - ignored)
+ FAT_DATE_TIME FileCreateTime;
+ FAT_DATE FileLastAccess;
+ UINT16 FileClusterHigh; // >= FAT32
+ FAT_DATE_TIME FileModificationTime;
+ UINT16 FileCluster;
+ UINT32 FileSize;
} FAT_DIRECTORY_ENTRY;
typedef struct {
- UINT8 Ordinal;
- CHAR8 Name1[10]; // (Really 5 chars, but not WCHAR aligned)
- UINT8 Attributes;
- UINT8 Type;
- UINT8 Checksum;
- CHAR16 Name2[6];
- UINT16 MustBeZero;
- CHAR16 Name3[2];
+ UINT8 Ordinal;
+ CHAR8 Name1[10]; // (Really 5 chars, but not WCHAR aligned)
+ UINT8 Attributes;
+ UINT8 Type;
+ UINT8 Checksum;
+ CHAR16 Name2[6];
+ UINT16 MustBeZero;
+ CHAR16 Name3[2];
} FAT_DIRECTORY_LFN;
#pragma pack()
diff --git a/FatPkg/EnhancedFatDxe/FileName.c b/FatPkg/EnhancedFatDxe/FileName.c
index d2d1fb3117..17914ccf92 100644
--- a/FatPkg/EnhancedFatDxe/FileName.c
+++ b/FatPkg/EnhancedFatDxe/FileName.c
@@ -23,16 +23,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
FatCheckIs8Dot3Name (
- IN CHAR16 *FileName,
- OUT CHAR8 *File8Dot3Name
+ IN CHAR16 *FileName,
+ OUT CHAR8 *File8Dot3Name
)
{
- BOOLEAN PossibleShortName;
- CHAR16 *TempName;
- CHAR16 *ExtendName;
- CHAR16 *SeparateDot;
- UINTN MainNameLen;
- UINTN ExtendNameLen;
+ BOOLEAN PossibleShortName;
+ CHAR16 *TempName;
+ CHAR16 *ExtendName;
+ CHAR16 *SeparateDot;
+ UINTN MainNameLen;
+ UINTN ExtendNameLen;
PossibleShortName = TRUE;
SeparateDot = NULL;
@@ -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
//
@@ -109,8 +110,8 @@ FatCheckIs8Dot3Name (
STATIC
UINTN
FatTrimAsciiTrailingBlanks (
- IN CHAR8 *Name,
- IN UINTN Len
+ IN CHAR8 *Name,
+ IN UINTN Len
)
{
while (Len > 0 && Name[Len - 1] == ' ') {
@@ -133,10 +134,10 @@ FatTrimAsciiTrailingBlanks (
**/
VOID
FatNameToStr (
- IN CHAR8 *FatName,
- IN UINTN Len,
- IN UINTN LowerCase,
- OUT CHAR16 *Str
+ IN CHAR8 *FatName,
+ IN UINTN Len,
+ IN UINTN LowerCase,
+ OUT CHAR16 *Str
)
{
//
@@ -166,20 +167,21 @@ FatNameToStr (
**/
VOID
FatCreate8Dot3Name (
- IN FAT_OFILE *Parent,
- IN FAT_DIRENT *DirEnt
+ IN FAT_OFILE *Parent,
+ IN FAT_DIRENT *DirEnt
)
{
- CHAR8 *ShortName;
- CHAR8 *ShortNameChar;
- UINTN BaseTagLen;
- UINTN Index;
- UINTN Retry;
- UINT8 Segment;
+ CHAR8 *ShortName;
+ CHAR8 *ShortNameChar;
+ UINTN BaseTagLen;
+ UINTN Index;
+ UINTN Retry;
+ UINT8 Segment;
+
union {
- UINT32 Crc;
+ UINT32 Crc;
struct HEX_DATA {
- UINT8 Segment : HASH_VALUE_TAG_LEN;
+ UINT8 Segment : HASH_VALUE_TAG_LEN;
} Hex[HASH_VALUE_TAG_LEN];
} HashValue;
//
@@ -195,13 +197,14 @@ FatCreate8Dot3Name (
if (BaseTagLen > SPEC_BASE_TAG_LEN) {
BaseTagLen = SPEC_BASE_TAG_LEN;
}
+
//
// We first use the algorithm described by spec.
//
- ShortNameChar = ShortName + BaseTagLen;
- *ShortNameChar++ = '~';
- *ShortNameChar = '1';
- Retry = 0;
+ ShortNameChar = ShortName + BaseTagLen;
+ *ShortNameChar++ = '~';
+ *ShortNameChar = '1';
+ Retry = 0;
while (*FatShortNameHashSearch (Parent->ODir, ShortName) != NULL) {
*ShortNameChar = (CHAR8)(*ShortNameChar + 1);
if (++Retry == MAX_SPEC_RETRY) {
@@ -225,8 +228,8 @@ FatCreate8Dot3Name (
}
}
- *ShortNameChar++ = '~';
- *ShortNameChar = '1';
+ *ShortNameChar++ = '~';
+ *ShortNameChar = '1';
}
}
}
@@ -245,8 +248,8 @@ FatCreate8Dot3Name (
STATIC
UINT8
FatCheckNameCase (
- IN CHAR16 *Str,
- IN UINT8 InCaseFlag
+ IN CHAR16 *Str,
+ IN UINT8 InCaseFlag
)
{
CHAR16 Buffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];
@@ -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
@@ -287,7 +291,7 @@ FatCheckNameCase (
**/
VOID
FatSetCaseFlag (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
)
{
CHAR16 LfnBuffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];
@@ -342,14 +346,15 @@ FatSetCaseFlag (
**/
VOID
FatGetFileNameViaCaseFlag (
- IN FAT_DIRENT *DirEnt,
- IN OUT CHAR16 *FileString,
- IN UINTN FileStringMax
+ IN FAT_DIRENT *DirEnt,
+ IN OUT CHAR16 *FileString,
+ IN UINTN FileStringMax
)
{
UINT8 CaseFlag;
CHAR8 *File8Dot3Name;
CHAR16 TempExt[1 + FAT_EXTEND_NAME_LEN + 1];
+
//
// Store file extension like ".txt"
//
@@ -378,8 +383,9 @@ FatCheckSum (
IN CHAR8 *ShortNameString
)
{
- UINTN ShortNameLen;
- UINT8 Sum;
+ UINTN ShortNameLen;
+ UINT8 Sum;
+
Sum = 0;
for (ShortNameLen = FAT_NAME_LEN; ShortNameLen != 0; ShortNameLen--) {
Sum = (UINT8)((((Sum & 1) != 0) ? 0x80 : 0) + (Sum >> 1) + *ShortNameString++);
@@ -402,13 +408,14 @@ FatCheckSum (
**/
CHAR16 *
FatGetNextNameComponent (
- IN CHAR16 *Path,
- OUT CHAR16 *Name
+ IN CHAR16 *Path,
+ OUT CHAR16 *Name
)
{
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;
}
diff --git a/FatPkg/EnhancedFatDxe/FileSpace.c b/FatPkg/EnhancedFatDxe/FileSpace.c
index 7dd220f837..909d4980d2 100644
--- a/FatPkg/EnhancedFatDxe/FileSpace.c
+++ b/FatPkg/EnhancedFatDxe/FileSpace.c
@@ -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.
@@ -24,46 +23,48 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
STATIC
VOID *
FatLoadFatEntry (
- IN FAT_VOLUME *Volume,
- IN UINTN Index
+ IN FAT_VOLUME *Volume,
+ IN UINTN Index
)
{
UINTN Pos;
EFI_STATUS Status;
if (Index > (Volume->MaxCluster + 1)) {
- Volume->FatEntryBuffer = (UINT32) -1;
+ Volume->FatEntryBuffer = (UINT32)-1;
return &Volume->FatEntryBuffer;
}
+
//
// Compute buffer position needed
//
switch (Volume->FatType) {
- case Fat12:
- Pos = FAT_POS_FAT12 (Index);
- break;
+ case Fat12:
+ Pos = FAT_POS_FAT12 (Index);
+ break;
- case Fat16:
- Pos = FAT_POS_FAT16 (Index);
- break;
+ case Fat16:
+ Pos = FAT_POS_FAT16 (Index);
+ break;
- default:
- Pos = FAT_POS_FAT32 (Index);
+ default:
+ Pos = FAT_POS_FAT32 (Index);
}
+
//
// Set the position and read the buffer
//
Volume->FatEntryPos = Volume->FatPos + Pos;
- Status = FatDiskIo (
- Volume,
- ReadFat,
- Volume->FatEntryPos,
- Volume->FatEntrySize,
- &Volume->FatEntryBuffer,
- NULL
- );
+ Status = FatDiskIo (
+ Volume,
+ ReadFat,
+ Volume->FatEntryPos,
+ Volume->FatEntrySize,
+ &Volume->FatEntryBuffer,
+ NULL
+ );
if (EFI_ERROR (Status)) {
- Volume->FatEntryBuffer = (UINT32) -1;
+ Volume->FatEntryBuffer = (UINT32)-1;
}
return &Volume->FatEntryBuffer;
@@ -82,8 +83,8 @@ FatLoadFatEntry (
STATIC
UINTN
FatGetFatEntry (
- IN FAT_VOLUME *Volume,
- IN UINTN Index
+ IN FAT_VOLUME *Volume,
+ IN UINTN Index
)
{
VOID *Pos;
@@ -95,27 +96,27 @@ FatGetFatEntry (
Pos = FatLoadFatEntry (Volume, Index);
if (Index > (Volume->MaxCluster + 1)) {
- return (UINTN) -1;
+ return (UINTN)-1;
}
switch (Volume->FatType) {
- case Fat12:
- En12 = Pos;
- Accum = En12[0] | (En12[1] << 8);
- Accum = FAT_ODD_CLUSTER_FAT12 (Index) ? (Accum >> 4) : (Accum & FAT_CLUSTER_MASK_FAT12);
- Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT12) ? FAT_CLUSTER_SPECIAL_EXT : 0);
- break;
-
- case Fat16:
- En16 = Pos;
- Accum = *En16;
- Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT16) ? FAT_CLUSTER_SPECIAL_EXT : 0);
- break;
-
- default:
- En32 = Pos;
- Accum = *En32 & FAT_CLUSTER_MASK_FAT32;
- Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT32) ? FAT_CLUSTER_SPECIAL_EXT : 0);
+ case Fat12:
+ En12 = Pos;
+ Accum = En12[0] | (En12[1] << 8);
+ Accum = FAT_ODD_CLUSTER_FAT12 (Index) ? (Accum >> 4) : (Accum & FAT_CLUSTER_MASK_FAT12);
+ Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT12) ? FAT_CLUSTER_SPECIAL_EXT : 0);
+ break;
+
+ case Fat16:
+ En16 = Pos;
+ Accum = *En16;
+ Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT16) ? FAT_CLUSTER_SPECIAL_EXT : 0);
+ break;
+
+ default:
+ En32 = Pos;
+ Accum = *En32 & FAT_CLUSTER_MASK_FAT32;
+ Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT32) ? FAT_CLUSTER_SPECIAL_EXT : 0);
}
return Accum;
@@ -137,9 +138,9 @@ FatGetFatEntry (
STATIC
EFI_STATUS
FatSetFatEntry (
- IN FAT_VOLUME *Volume,
- IN UINTN Index,
- IN UINTN Value
+ IN FAT_VOLUME *Volume,
+ IN UINTN Index,
+ IN UINTN Value
)
{
VOID *Pos;
@@ -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
//
@@ -174,37 +176,39 @@ FatSetFatEntry (
// Update the value
//
switch (Volume->FatType) {
- case Fat12:
- En12 = Pos;
- Accum = En12[0] | (En12[1] << 8);
- Value = Value & FAT_CLUSTER_MASK_FAT12;
-
- if (FAT_ODD_CLUSTER_FAT12 (Index)) {
- Accum = (Value << 4) | (Accum & 0xF);
- } else {
- Accum = Value | (Accum & FAT_CLUSTER_UNMASK_FAT12);
- }
+ case Fat12:
+ En12 = Pos;
+ Accum = En12[0] | (En12[1] << 8);
+ Value = Value & FAT_CLUSTER_MASK_FAT12;
- En12[0] = (UINT8) (Accum & 0xFF);
- En12[1] = (UINT8) (Accum >> 8);
- break;
+ if (FAT_ODD_CLUSTER_FAT12 (Index)) {
+ Accum = (Value << 4) | (Accum & 0xF);
+ } else {
+ Accum = Value | (Accum & FAT_CLUSTER_UNMASK_FAT12);
+ }
- case Fat16:
- En16 = Pos;
- *En16 = (UINT16) Value;
- break;
+ En12[0] = (UINT8)(Accum & 0xFF);
+ En12[1] = (UINT8)(Accum >> 8);
+ break;
+
+ case Fat16:
+ En16 = Pos;
+ *En16 = (UINT16)Value;
+ break;
- default:
- En32 = Pos;
- *En32 = (*En32 & FAT_CLUSTER_UNMASK_FAT32) | (UINT32) (Value & FAT_CLUSTER_MASK_FAT32);
+ default:
+ En32 = Pos;
+ *En32 = (*En32 & FAT_CLUSTER_UNMASK_FAT32) | (UINT32)(Value & FAT_CLUSTER_MASK_FAT32);
}
+
//
// If the volume's dirty bit is not set, set it now
//
- if (!Volume->FatDirty && Volume->FatType != Fat12) {
+ if (!Volume->FatDirty && (Volume->FatType != Fat12)) {
Volume->FatDirty = TRUE;
FatAccessVolumeDirty (Volume, WriteFat, &Volume->DirtyValue);
}
+
//
// Write the updated fat entry value to the volume
// The fat is the first fat, and other fat will be in sync
@@ -235,15 +239,14 @@ FatSetFatEntry (
STATIC
EFI_STATUS
FatFreeClusters (
- IN FAT_VOLUME *Volume,
- IN UINTN Cluster
+ IN FAT_VOLUME *Volume,
+ IN UINTN Cluster
)
{
- UINTN LastCluster;
+ 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;
}
@@ -268,30 +271,30 @@ FatFreeClusters (
STATIC
UINTN
FatAllocateCluster (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
- UINTN Cluster;
+ UINTN Cluster;
//
// 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,13 +302,14 @@ FatAllocateCluster (
if (Cluster == FAT_CLUSTER_FREE) {
break;
}
+
//
// Try the next cluster
//
Volume->FatInfoSector.FreeInfo.NextCluster += 1;
}
- Cluster = Volume->FatInfoSector.FreeInfo.NextCluster;
+ Cluster = Volume->FatInfoSector.FreeInfo.NextCluster;
Volume->FatInfoSector.FreeInfo.NextCluster += 1;
return Cluster;
}
@@ -323,11 +327,11 @@ FatAllocateCluster (
STATIC
UINTN
FatSizeToClusters (
- IN FAT_VOLUME *Volume,
- IN UINTN Size
+ IN FAT_VOLUME *Volume,
+ IN UINTN Size
)
{
- UINTN Clusters;
+ UINTN Clusters;
Clusters = Size >> Volume->ClusterAlignment;
if ((Size & (Volume->ClusterSize - 1)) > 0) {
@@ -349,7 +353,7 @@ FatSizeToClusters (
**/
EFI_STATUS
FatShrinkEof (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
FAT_VOLUME *Volume;
@@ -358,7 +362,7 @@ FatShrinkEof (
UINTN Cluster;
UINTN LastCluster;
- Volume = OFile->Volume;
+ Volume = OFile->Volume;
ASSERT_VOLUME_LOCKED (Volume);
NewSize = FatSizeToClusters (Volume, OFile->FileSize);
@@ -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;
+ OFile->FileCluster = FAT_CLUSTER_FREE;
}
+
//
// Set CurrentCluster == FileCluster
// to force a recalculation of Position related stuffs
@@ -424,8 +427,8 @@ FatShrinkEof (
**/
EFI_STATUS
FatGrowEof (
- IN FAT_OFILE *OFile,
- IN UINT64 NewSizeInBytes
+ IN FAT_OFILE *OFile,
+ IN UINT64 NewSizeInBytes
)
{
FAT_VOLUME *Volume;
@@ -450,42 +453,41 @@ 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) {
//
// If we haven't found the files last cluster do it now
//
if ((OFile->FileCluster != 0) && (OFile->FileLastCluster == 0)) {
- Cluster = OFile->FileCluster;
- ClusterCount = 0;
+ Cluster = OFile->FileCluster;
+ 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")
+ "FatGrowEof: cluster chain corrupt\n")
);
Status = EFI_VOLUME_CORRUPTED;
goto Done;
}
ClusterCount++;
- OFile->FileLastCluster = Cluster;
- Cluster = FatGetFatEntry (Volume, Cluster);
+ OFile->FileLastCluster = Cluster;
+ Cluster = FatGetFatEntry (Volume, Cluster);
}
if (ClusterCount != CurSize) {
DEBUG (
(DEBUG_INIT | DEBUG_ERROR,
- "FatGrowEof: cluster chain size does not match file size\n")
+ "FatGrowEof: cluster chain size does not match file size\n")
);
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;
}
@@ -516,7 +518,7 @@ FatGrowEof (
}
LastCluster = NewCluster;
- CurSize += 1;
+ CurSize += 1;
//
// Terminate the cluster list
@@ -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;
@@ -558,9 +560,9 @@ Done:
**/
EFI_STATUS
FatOFilePosition (
- IN FAT_OFILE *OFile,
- IN UINTN Position,
- IN UINTN PosLimit
+ IN FAT_OFILE *OFile,
+ IN UINTN Position,
+ IN UINTN PosLimit
)
{
FAT_VOLUME *Volume;
@@ -579,8 +581,8 @@ FatOFilePosition (
// from its fixed info in the fat bpb
//
if (OFile->IsFixedRootDir) {
- OFile->PosDisk = Volume->RootPos + Position;
- Run = OFile->FileSize - Position;
+ OFile->PosDisk = Volume->RootPos + Position;
+ Run = OFile->FileSize - Position;
} else {
//
// Run the file's cluster chain to find the current position
@@ -594,30 +596,30 @@ FatOFilePosition (
// when OFile->FileCluster is updated, so make a check of this
// and invalidate the original OFile->Position in this case
//
- Cluster = OFile->FileCurrentCluster;
- StartPos = OFile->Position;
- if (Position < StartPos || OFile->FileCluster == Cluster) {
- StartPos = 0;
- Cluster = OFile->FileCluster;
+ Cluster = OFile->FileCurrentCluster;
+ StartPos = OFile->Position;
+ 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;
}
- OFile->PosDisk = Volume->FirstClusterPos +
- LShiftU64 (Cluster - FAT_MIN_CLUSTER, Volume->ClusterAlignment) +
- Position - StartPos;
+ OFile->PosDisk = Volume->FirstClusterPos +
+ LShiftU64 (Cluster - FAT_MIN_CLUSTER, Volume->ClusterAlignment) +
+ Position - StartPos;
OFile->FileCurrentCluster = Cluster;
OFile->Position = StartPos;
@@ -650,11 +652,12 @@ FatOFilePosition (
**/
UINTN
FatPhysicalDirSize (
- IN FAT_VOLUME *Volume,
- IN UINTN Cluster
+ IN FAT_VOLUME *Volume,
+ IN UINTN Cluster
)
{
- UINTN Size;
+ UINTN Size;
+
ASSERT_VOLUME_LOCKED (Volume);
//
// Run the cluster chain for the OFile
@@ -666,15 +669,15 @@ 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")
+ "FATDirSize: cluster chain corrupt\n")
);
return 0;
}
- Size += Volume->ClusterSize;
+ Size += Volume->ClusterSize;
Cluster = FatGetFatEntry (Volume, Cluster);
}
}
@@ -694,14 +697,15 @@ FatPhysicalDirSize (
**/
UINT64
FatPhysicalFileSize (
- IN FAT_VOLUME *Volume,
- IN UINTN RealSize
+ IN FAT_VOLUME *Volume,
+ IN UINTN RealSize
)
{
UINTN ClusterSizeMask;
UINT64 PhysicalSize;
+
ClusterSizeMask = Volume->ClusterSize - 1;
- PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64) ClusterSizeMask));
+ PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64)ClusterSizeMask));
return PhysicalSize;
}
@@ -714,18 +718,17 @@ FatPhysicalFileSize (
**/
VOID
FatComputeFreeInfo (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
- UINTN Index;
+ UINTN Index;
//
// If we don't have valid info, compute it now
//
if (!Volume->FreeInfoValid) {
-
- Volume->FreeInfoValid = TRUE;
- Volume->FatInfoSector.FreeInfo.ClusterCount = 0;
+ Volume->FreeInfoValid = TRUE;
+ Volume->FatInfoSector.FreeInfo.ClusterCount = 0;
for (Index = Volume->MaxCluster + 1; Index >= FAT_MIN_CLUSTER; Index--) {
if (Volume->DiskError) {
break;
@@ -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;
}
}
diff --git a/FatPkg/EnhancedFatDxe/Flush.c b/FatPkg/EnhancedFatDxe/Flush.c
index d532791075..8c6010328b 100644
--- a/FatPkg/EnhancedFatDxe/Flush.c
+++ b/FatPkg/EnhancedFatDxe/Flush.c
@@ -35,10 +35,10 @@ FatFlushEx (
EFI_STATUS Status;
FAT_TASK *Task;
- IFile = IFILE_FROM_FHAND (FHand);
- OFile = IFile->OFile;
- Volume = OFile->Volume;
- Task = NULL;
+ IFile = IFILE_FROM_FHAND (FHand);
+ OFile = IFile->OFile;
+ Volume = OFile->Volume;
+ Task = NULL;
//
// If the file has a permanent error, return it
@@ -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;
@@ -77,8 +79,8 @@ FatFlushEx (
// Flush the OFile
//
FatAcquireLock ();
- Status = FatOFileFlush (OFile);
- Status = FatCleanupVolume (OFile->Volume, OFile, Status, Task);
+ Status = FatOFileFlush (OFile);
+ Status = FatCleanupVolume (OFile->Volume, OFile, Status, Task);
FatReleaseLock ();
if (Token != NULL) {
@@ -132,9 +134,9 @@ FatClose (
FAT_OFILE *OFile;
FAT_VOLUME *Volume;
- IFile = IFILE_FROM_FHAND (FHand);
- OFile = IFile->OFile;
- Volume = OFile->Volume;
+ IFile = IFILE_FROM_FHAND (FHand);
+ OFile = IFile->OFile;
+ Volume = OFile->Volume;
//
// Lock the volume
@@ -169,14 +171,14 @@ FatClose (
**/
EFI_STATUS
FatIFileClose (
- FAT_IFILE *IFile
+ FAT_IFILE *IFile
)
{
FAT_OFILE *OFile;
FAT_VOLUME *Volume;
- OFile = IFile->OFile;
- Volume = OFile->Volume;
+ OFile = IFile->OFile;
+ Volume = OFile->Volume;
ASSERT_VOLUME_LOCKED (Volume);
@@ -193,6 +195,7 @@ FatIFileClose (
if (OFile->CheckLink.ForwardLink == NULL) {
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
}
+
//
// Done. Free the open instance structure
//
@@ -213,13 +216,13 @@ FatIFileClose (
**/
EFI_STATUS
FatOFileFlush (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
- EFI_STATUS Status;
- FAT_OFILE *Parent;
- FAT_DIRENT *DirEnt;
- FAT_DATE_TIME FatNow;
+ EFI_STATUS Status;
+ FAT_OFILE *Parent;
+ FAT_DIRENT *DirEnt;
+ FAT_DATE_TIME FatNow;
//
// Flush each entry up the tree while dirty
@@ -233,8 +236,8 @@ FatOFileFlush (
return OFile->Error;
}
- Parent = OFile->Parent;
- DirEnt = OFile->DirEnt;
+ Parent = OFile->Parent;
+ DirEnt = OFile->DirEnt;
if (OFile->Dirty) {
//
// Update the last modification time
@@ -248,12 +251,13 @@ FatOFileFlush (
OFile->PreserveLastModification = FALSE;
if (OFile->Archive) {
DirEnt->Entry.Attributes |= FAT_ATTRIBUTE_ARCHIVE;
- OFile->Archive = FALSE;
+ 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;
}
@@ -287,7 +293,7 @@ FatOFileFlush (
**/
BOOLEAN
FatCheckOFileRef (
- IN FAT_OFILE *OFile
+ IN FAT_OFILE *OFile
)
{
//
@@ -308,6 +314,7 @@ FatCheckOFileRef (
//
return FALSE;
}
+
//
// Free the Ofile
//
@@ -328,11 +335,11 @@ FatCheckOFileRef (
STATIC
VOID
FatCheckVolumeRef (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
- FAT_OFILE *OFile;
- FAT_OFILE *Parent;
+ FAT_OFILE *OFile;
+ FAT_OFILE *Parent;
//
// Check all files on the pending check list
@@ -346,8 +353,8 @@ FatCheckVolumeRef (
// Go up the tree cleaning up any un-referenced OFiles
//
while (Parent != NULL) {
- OFile = Parent;
- Parent = OFile->Parent;
+ OFile = Parent;
+ Parent = OFile->Parent;
if (!FatCheckOFileRef (OFile)) {
break;
}
@@ -373,19 +380,21 @@ FatCheckVolumeRef (
**/
EFI_STATUS
FatCleanupVolume (
- IN FAT_VOLUME *Volume,
- IN FAT_OFILE *OFile,
- IN EFI_STATUS EfiStatus,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN FAT_OFILE *OFile,
+ IN EFI_STATUS EfiStatus,
+ IN FAT_TASK *Task
)
{
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) {
- Volume->FatDirty = FALSE;
- Status = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue);
+ 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
//
@@ -445,12 +457,12 @@ FatCleanupVolume (
**/
VOID
FatSetVolumeError (
- IN FAT_OFILE *OFile,
- IN EFI_STATUS Status
+ IN FAT_OFILE *OFile,
+ IN EFI_STATUS Status
)
{
- LIST_ENTRY *Link;
- FAT_OFILE *ChildOFile;
+ LIST_ENTRY *Link;
+ FAT_OFILE *ChildOFile;
//
// If this OFile doesn't already have an error, set one
@@ -458,6 +470,7 @@ FatSetVolumeError (
if (!EFI_ERROR (OFile->Error)) {
OFile->Error = Status;
}
+
//
// Set the error on each child OFile
//
diff --git a/FatPkg/EnhancedFatDxe/Hash.c b/FatPkg/EnhancedFatDxe/Hash.c
index 3413cd6ffe..142dafe349 100644
--- a/FatPkg/EnhancedFatDxe/Hash.c
+++ b/FatPkg/EnhancedFatDxe/Hash.c
@@ -20,11 +20,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
STATIC
UINT32
FatHashLongName (
- IN CHAR16 *LongNameString
+ IN CHAR16 *LongNameString
)
{
UINT32 HashValue;
CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
+
StrnCpyS (
UpCasedLongFileName,
ARRAY_SIZE (UpCasedLongFileName),
@@ -48,10 +49,11 @@ FatHashLongName (
STATIC
UINT32
FatHashShortName (
- IN CHAR8 *ShortNameString
+ IN CHAR8 *ShortNameString
)
{
UINT32 HashValue;
+
gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);
return (HashValue & HASH_TABLE_MASK);
}
@@ -68,15 +70,17 @@ FatHashShortName (
**/
FAT_DIRENT **
FatLongNameHashSearch (
- IN FAT_ODIR *ODir,
- IN CHAR16 *LongNameString
+ IN FAT_ODIR *ODir,
+ IN CHAR16 *LongNameString
)
{
FAT_DIRENT **PreviousHashNode;
+
for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];
*PreviousHashNode != NULL;
PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink
- ) {
+ )
+ {
if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {
break;
}
@@ -97,15 +101,17 @@ FatLongNameHashSearch (
**/
FAT_DIRENT **
FatShortNameHashSearch (
- IN FAT_ODIR *ODir,
- IN CHAR8 *ShortNameString
+ IN FAT_ODIR *ODir,
+ IN CHAR8 *ShortNameString
)
{
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;
}
@@ -124,8 +130,8 @@ FatShortNameHashSearch (
**/
VOID
FatInsertToHashTable (
- IN FAT_ODIR *ODir,
- IN FAT_DIRENT *DirEnt
+ IN FAT_ODIR *ODir,
+ IN FAT_DIRENT *DirEnt
)
{
FAT_DIRENT **HashTable;
@@ -134,17 +140,17 @@ FatInsertToHashTable (
//
// Insert hash table index for short name
//
- HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);
- HashTable = ODir->ShortNameHashTable;
- DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];
- HashTable[HashTableIndex] = DirEnt;
+ HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);
+ HashTable = ODir->ShortNameHashTable;
+ DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];
+ HashTable[HashTableIndex] = DirEnt;
//
// Insert hash table index for long name
//
- HashTableIndex = FatHashLongName (DirEnt->FileString);
- HashTable = ODir->LongNameHashTable;
- DirEnt->LongNameForwardLink = HashTable[HashTableIndex];
- HashTable[HashTableIndex] = DirEnt;
+ HashTableIndex = FatHashLongName (DirEnt->FileString);
+ HashTable = ODir->LongNameHashTable;
+ DirEnt->LongNameForwardLink = HashTable[HashTableIndex];
+ HashTable[HashTableIndex] = DirEnt;
}
/**
@@ -157,8 +163,8 @@ FatInsertToHashTable (
**/
VOID
FatDeleteFromHashTable (
- IN FAT_ODIR *ODir,
- IN FAT_DIRENT *DirEnt
+ IN FAT_ODIR *ODir,
+ IN FAT_DIRENT *DirEnt
)
{
*FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;
diff --git a/FatPkg/EnhancedFatDxe/Info.c b/FatPkg/EnhancedFatDxe/Info.c
index fd4c0278f9..d17ce5b7ee 100644
--- a/FatPkg/EnhancedFatDxe/Info.c
+++ b/FatPkg/EnhancedFatDxe/Info.c
@@ -24,9 +24,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
FatGetVolumeInfo (
- IN FAT_VOLUME *Volume,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
);
/**
@@ -45,9 +45,9 @@ FatGetVolumeInfo (
**/
EFI_STATUS
FatSetVolumeInfo (
- IN FAT_VOLUME *Volume,
- IN UINTN BufferSize,
- IN VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
);
/**
@@ -66,11 +66,11 @@ FatSetVolumeInfo (
**/
EFI_STATUS
FatSetOrGetInfo (
- IN BOOLEAN IsSet,
- IN EFI_FILE_PROTOCOL *FHand,
- IN EFI_GUID *Type,
- IN OUT UINTN *BufferSize,
- IN OUT VOID *Buffer
+ IN BOOLEAN IsSet,
+ IN EFI_FILE_PROTOCOL *FHand,
+ IN EFI_GUID *Type,
+ IN OUT UINTN *BufferSize,
+ IN OUT VOID *Buffer
);
/**
@@ -87,9 +87,9 @@ FatSetOrGetInfo (
**/
EFI_STATUS
FatGetFileInfo (
- IN FAT_OFILE *OFile,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_OFILE *OFile,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
return FatGetDirEntInfo (OFile->Volume, OFile->DirEnt, BufferSize, Buffer);
@@ -109,9 +109,9 @@ FatGetFileInfo (
**/
EFI_STATUS
FatGetVolumeInfo (
- IN FAT_VOLUME *Volume,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
UINTN Size;
@@ -122,11 +122,11 @@ FatGetVolumeInfo (
EFI_FILE_SYSTEM_INFO *Info;
UINT8 ClusterAlignment;
- Size = SIZE_OF_EFI_FILE_SYSTEM_INFO;
- Status = FatGetVolumeEntry (Volume, Name);
- NameSize = StrSize (Name);
- ResultSize = Size + NameSize;
- ClusterAlignment = Volume->ClusterAlignment;
+ Size = SIZE_OF_EFI_FILE_SYSTEM_INFO;
+ Status = FatGetVolumeEntry (Volume, Name);
+ NameSize = StrSize (Name);
+ ResultSize = Size + NameSize;
+ ClusterAlignment = Volume->ClusterAlignment;
//
// If we don't have valid info, compute it now
@@ -135,20 +135,20 @@ FatGetVolumeInfo (
Status = EFI_BUFFER_TOO_SMALL;
if (*BufferSize >= ResultSize) {
- Status = EFI_SUCCESS;
+ Status = EFI_SUCCESS;
- Info = Buffer;
+ Info = Buffer;
ZeroMem (Info, SIZE_OF_EFI_FILE_SYSTEM_INFO);
- Info->Size = ResultSize;
- Info->ReadOnly = Volume->ReadOnly;
- 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);
+ Info->Size = ResultSize;
+ Info->ReadOnly = Volume->ReadOnly;
+ 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);
}
*BufferSize = ResultSize;
@@ -169,26 +169,26 @@ FatGetVolumeInfo (
**/
EFI_STATUS
FatGetVolumeLabelInfo (
- IN FAT_VOLUME *Volume,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
- UINTN Size;
- UINTN NameSize;
- UINTN ResultSize;
- CHAR16 Name[FAT_NAME_LEN + 1];
- EFI_STATUS Status;
-
- Size = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL;
- Status = FatGetVolumeEntry (Volume, Name);
- NameSize = StrSize (Name);
- ResultSize = Size + NameSize;
-
- Status = EFI_BUFFER_TOO_SMALL;
+ UINTN Size;
+ UINTN NameSize;
+ UINTN ResultSize;
+ CHAR16 Name[FAT_NAME_LEN + 1];
+ EFI_STATUS Status;
+
+ Size = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL;
+ Status = FatGetVolumeEntry (Volume, Name);
+ NameSize = StrSize (Name);
+ ResultSize = Size + NameSize;
+
+ Status = EFI_BUFFER_TOO_SMALL;
if (*BufferSize >= ResultSize) {
- Status = EFI_SUCCESS;
- CopyMem ((CHAR8 *) Buffer + Size, Name, NameSize);
+ Status = EFI_SUCCESS;
+ CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
}
*BufferSize = ResultSize;
@@ -211,16 +211,16 @@ FatGetVolumeLabelInfo (
**/
EFI_STATUS
FatSetVolumeInfo (
- IN FAT_VOLUME *Volume,
- IN UINTN BufferSize,
- IN VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
)
{
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;
}
@@ -243,14 +243,14 @@ FatSetVolumeInfo (
**/
EFI_STATUS
FatSetVolumeLabelInfo (
- IN FAT_VOLUME *Volume,
- IN UINTN BufferSize,
- IN VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
)
{
- EFI_FILE_SYSTEM_VOLUME_LABEL *Info;
+ 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;
@@ -285,38 +285,39 @@ FatSetVolumeLabelInfo (
**/
EFI_STATUS
FatSetFileInfo (
- IN FAT_VOLUME *Volume,
- IN FAT_IFILE *IFile,
- IN FAT_OFILE *OFile,
- IN UINTN BufferSize,
- IN VOID *Buffer
+ IN FAT_VOLUME *Volume,
+ IN FAT_IFILE *IFile,
+ IN FAT_OFILE *OFile,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
)
{
- EFI_STATUS Status;
- EFI_FILE_INFO *NewInfo;
- FAT_OFILE *DotOFile;
- FAT_OFILE *Parent;
- CHAR16 NewFileName[EFI_PATH_STRING_LENGTH];
- EFI_TIME ZeroTime;
- FAT_DIRENT *DirEnt;
- FAT_DIRENT *TempDirEnt;
- UINT8 NewAttribute;
- BOOLEAN ReadOnly;
+ EFI_STATUS Status;
+ EFI_FILE_INFO *NewInfo;
+ FAT_OFILE *DotOFile;
+ FAT_OFILE *Parent;
+ CHAR16 NewFileName[EFI_PATH_STRING_LENGTH];
+ EFI_TIME ZeroTime;
+ FAT_DIRENT *DirEnt;
+ FAT_DIRENT *TempDirEnt;
+ UINT8 NewAttribute;
+ BOOLEAN ReadOnly;
ZeroMem (&ZeroTime, sizeof (EFI_TIME));
- Parent = OFile->Parent;
- DirEnt = OFile->DirEnt;
+ Parent = OFile->Parent;
+ DirEnt = OFile->DirEnt;
//
// If this is the root directory, we can't make any updates
//
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)) {
@@ -490,11 +495,11 @@ FatSetOrGetInfo (
FAT_VOLUME *Volume;
EFI_STATUS Status;
- IFile = IFILE_FROM_FHAND (FHand);
- OFile = IFile->OFile;
- Volume = OFile->Volume;
+ IFile = IFILE_FROM_FHAND (FHand);
+ OFile = IFile->OFile;
+ Volume = OFile->Volume;
- Status = OFile->Error;
+ Status = OFile->Error;
if (Status == EFI_NOT_FOUND) {
return EFI_DEVICE_ERROR;
}
@@ -560,10 +565,10 @@ FatSetOrGetInfo (
EFI_STATUS
EFIAPI
FatGetInfo (
- IN EFI_FILE_PROTOCOL *FHand,
- IN EFI_GUID *Type,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN EFI_FILE_PROTOCOL *FHand,
+ IN EFI_GUID *Type,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
return FatSetOrGetInfo (FALSE, FHand, Type, BufferSize, Buffer);
diff --git a/FatPkg/EnhancedFatDxe/Init.c b/FatPkg/EnhancedFatDxe/Init.c
index fb62dc2332..208318c7ad 100644
--- a/FatPkg/EnhancedFatDxe/Init.c
+++ b/FatPkg/EnhancedFatDxe/Init.c
@@ -25,10 +25,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
FatAllocateVolume (
- IN EFI_HANDLE Handle,
- IN EFI_DISK_IO_PROTOCOL *DiskIo,
- IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
- IN EFI_BLOCK_IO_PROTOCOL *BlockIo
+ IN EFI_HANDLE Handle,
+ IN EFI_DISK_IO_PROTOCOL *DiskIo,
+ IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
+ IN EFI_BLOCK_IO_PROTOCOL *BlockIo
)
{
EFI_STATUS Status;
@@ -45,15 +45,15 @@ FatAllocateVolume (
//
// Initialize the structure
//
- Volume->Signature = FAT_VOLUME_SIGNATURE;
- Volume->Handle = Handle;
- Volume->DiskIo = DiskIo;
- Volume->DiskIo2 = DiskIo2;
- Volume->BlockIo = BlockIo;
- Volume->MediaId = BlockIo->Media->MediaId;
- Volume->ReadOnly = BlockIo->Media->ReadOnly;
- Volume->VolumeInterface.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
- Volume->VolumeInterface.OpenVolume = FatOpenVolume;
+ Volume->Signature = FAT_VOLUME_SIGNATURE;
+ Volume->Handle = Handle;
+ Volume->DiskIo = DiskIo;
+ Volume->DiskIo2 = DiskIo2;
+ Volume->BlockIo = BlockIo;
+ Volume->MediaId = BlockIo->Media->MediaId;
+ Volume->ReadOnly = BlockIo->Media->ReadOnly;
+ Volume->VolumeInterface.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
+ Volume->VolumeInterface.OpenVolume = FatOpenVolume;
InitializeListHead (&Volume->CheckRef);
InitializeListHead (&Volume->DirCacheList);
//
@@ -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
//
@@ -113,7 +116,7 @@ Done:
**/
EFI_STATUS
FatAbandonVolume (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
EFI_STATUS Status;
@@ -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
@@ -190,7 +194,7 @@ FatAbandonVolume (
**/
EFI_STATUS
FatOpenDevice (
- IN OUT FAT_VOLUME *Volume
+ IN OUT FAT_VOLUME *Volume
)
{
EFI_STATUS Status;
@@ -213,8 +217,8 @@ FatOpenDevice (
// This is the only part of FAT code that uses parent DiskIo,
// Others use FatDiskIo which utilizes a Cache.
//
- DiskIo = Volume->DiskIo;
- Status = DiskIo->ReadDisk (DiskIo, Volume->MediaId, 0, sizeof (FatBs), &FatBs);
+ DiskIo = Volume->DiskIo;
+ Status = DiskIo->ReadDisk (DiskIo, Volume->MediaId, 0, sizeof (FatBs), &FatBs);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INIT, "FatOpenDevice: read of part_lba failed %r\n", Status));
@@ -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,35 +294,36 @@ 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
//
Volume->RootCluster = FatBs.FatBse.Fat32Bse.RootDirFirstCluster;
}
- Volume->NumFats = FatBs.FatBsb.NumFats;
+ Volume->NumFats = FatBs.FatBsb.NumFats;
//
// Compute some fat locations
//
- BlockSize = FatBs.FatBsb.SectorSize;
- RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (BlockSize - 1)) / BlockSize;
+ BlockSize = FatBs.FatBsb.SectorSize;
+ RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (BlockSize - 1)) / BlockSize;
- FatLba = FatBs.FatBsb.ReservedSectors;
- RootLba = FatBs.FatBsb.NumFats * SectorsPerFat + FatLba;
- FirstClusterLba = RootLba + RootDirSectors;
+ FatLba = FatBs.FatBsb.ReservedSectors;
+ RootLba = FatBs.FatBsb.NumFats * SectorsPerFat + FatLba;
+ FirstClusterLba = RootLba + RootDirSectors;
- Volume->FatPos = FatLba * BlockSize;
- Volume->FatSize = SectorsPerFat * BlockSize;
+ Volume->FatPos = FatLba * BlockSize;
+ Volume->FatSize = SectorsPerFat * BlockSize;
- Volume->VolumeSize = LShiftU64 (Sectors, BlockAlignment);
- Volume->RootPos = LShiftU64 (RootLba, BlockAlignment);
- Volume->FirstClusterPos = LShiftU64 (FirstClusterLba, BlockAlignment);
- Volume->MaxCluster = (Sectors - FirstClusterLba) >> SectorsPerClusterAlignment;
- Volume->ClusterAlignment = (UINT8)(BlockAlignment + SectorsPerClusterAlignment);
- Volume->ClusterSize = (UINTN)1 << (Volume->ClusterAlignment);
+ Volume->VolumeSize = LShiftU64 (Sectors, BlockAlignment);
+ Volume->RootPos = LShiftU64 (RootLba, BlockAlignment);
+ Volume->FirstClusterPos = LShiftU64 (FirstClusterLba, BlockAlignment);
+ Volume->MaxCluster = (Sectors - FirstClusterLba) >> SectorsPerClusterAlignment;
+ Volume->ClusterAlignment = (UINT8)(BlockAlignment + SectorsPerClusterAlignment);
+ Volume->ClusterSize = (UINTN)1 << (Volume->ClusterAlignment);
//
// If this is not a fat32, determine if it's a fat16 or fat12
@@ -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
//
diff --git a/FatPkg/EnhancedFatDxe/Misc.c b/FatPkg/EnhancedFatDxe/Misc.c
index d488a6e9a6..68a113fcfd 100644
--- a/FatPkg/EnhancedFatDxe/Misc.c
+++ b/FatPkg/EnhancedFatDxe/Misc.c
@@ -22,11 +22,11 @@ UINT8 mMonthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
**/
FAT_TASK *
FatCreateTask (
- FAT_IFILE *IFile,
- EFI_FILE_IO_TOKEN *Token
+ FAT_IFILE *IFile,
+ EFI_FILE_IO_TOKEN *Token
)
{
- FAT_TASK *Task;
+ FAT_TASK *Task;
Task = AllocateZeroPool (sizeof (*Task));
if (Task != NULL) {
@@ -36,6 +36,7 @@ FatCreateTask (
InitializeListHead (&Task->Subtasks);
InitializeListHead (&Task->Link);
}
+
return Task;
}
@@ -48,17 +49,18 @@ FatCreateTask (
**/
VOID
FatDestroyTask (
- FAT_TASK *Task
+ FAT_TASK *Task
)
{
- LIST_ENTRY *Link;
- FAT_SUBTASK *Subtask;
+ LIST_ENTRY *Link;
+ FAT_SUBTASK *Subtask;
Link = GetFirstNode (&Task->Subtasks);
while (!IsNull (&Task->Subtasks, Link)) {
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
- Link = FatDestroySubtask (Subtask);
+ Link = FatDestroySubtask (Subtask);
}
+
FreePool (Task);
}
@@ -71,10 +73,10 @@ FatDestroyTask (
**/
VOID
FatWaitNonblockingTask (
- FAT_IFILE *IFile
+ FAT_IFILE *IFile
)
{
- BOOLEAN TaskQueueEmpty;
+ BOOLEAN TaskQueueEmpty;
do {
EfiAcquireLock (&FatTaskLock);
@@ -94,10 +96,10 @@ FatWaitNonblockingTask (
**/
LIST_ENTRY *
FatDestroySubtask (
- FAT_SUBTASK *Subtask
+ FAT_SUBTASK *Subtask
)
{
- LIST_ENTRY *Link;
+ LIST_ENTRY *Link;
gBS->CloseEvent (Subtask->DiskIo2Token.Event);
@@ -120,14 +122,14 @@ FatDestroySubtask (
**/
EFI_STATUS
FatQueueTask (
- IN FAT_IFILE *IFile,
- IN FAT_TASK *Task
+ IN FAT_IFILE *IFile,
+ IN FAT_TASK *Task
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Link;
- LIST_ENTRY *NextLink;
- FAT_SUBTASK *Subtask;
+ EFI_STATUS Status;
+ LIST_ENTRY *Link;
+ LIST_ENTRY *NextLink;
+ FAT_SUBTASK *Subtask;
//
// Sometimes the Task doesn't contain any subtasks, signal the event directly.
@@ -153,12 +155,12 @@ FatQueueTask (
// handle list elements being removed during the traverse.
//
for ( Link = GetFirstNode (&Task->Subtasks), NextLink = GetNextNode (&Task->Subtasks, Link)
- ; Link != &Task->Subtasks
- ; Link = NextLink, NextLink = Link->ForwardLink
- ) {
+ ; 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;
}
@@ -191,7 +194,7 @@ FatQueueTask (
//
while (!IsNull (&Task->Subtasks, Link)) {
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
- Link = FatDestroySubtask (Subtask);
+ Link = FatDestroySubtask (Subtask);
}
if (IsListEmpty (&Task->Subtasks)) {
@@ -225,12 +228,12 @@ FatQueueTask (
**/
EFI_STATUS
FatAccessVolumeDirty (
- IN FAT_VOLUME *Volume,
- IN IO_MODE IoMode,
- IN VOID *DirtyValue
+ IN FAT_VOLUME *Volume,
+ IN IO_MODE IoMode,
+ IN VOID *DirtyValue
)
{
- UINTN WriteCount;
+ UINTN WriteCount;
WriteCount = Volume->FatEntrySize;
return FatDiskIo (Volume, IoMode, Volume->FatPos + WriteCount, WriteCount, DirtyValue, NULL);
@@ -247,20 +250,20 @@ FatAccessVolumeDirty (
VOID
EFIAPI
FatOnAccessComplete (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
- EFI_STATUS Status;
- FAT_SUBTASK *Subtask;
- FAT_TASK *Task;
+ EFI_STATUS Status;
+ FAT_SUBTASK *Subtask;
+ FAT_TASK *Task;
//
// Avoid someone in future breaks the below assumption.
//
ASSERT (EfiGetCurrentTpl () == FatTaskLock.Tpl);
- Subtask = (FAT_SUBTASK *) Context;
+ Subtask = (FAT_SUBTASK *)Context;
Task = Subtask->Task;
Status = Subtask->DiskIo2Token.TransactionStatus;
@@ -310,12 +313,12 @@ FatOnAccessComplete (
**/
EFI_STATUS
FatDiskIo (
- IN FAT_VOLUME *Volume,
- IN IO_MODE IoMode,
- IN UINT64 Offset,
- IN UINTN BufferSize,
- IN OUT VOID *Buffer,
- IN FAT_TASK *Task
+ IN FAT_VOLUME *Volume,
+ IN IO_MODE IoMode,
+ IN UINT64 Offset,
+ IN UINTN BufferSize,
+ IN OUT VOID *Buffer,
+ IN FAT_TASK *Task
)
{
EFI_STATUS Status;
@@ -341,30 +344,30 @@ FatDiskIo (
//
// Blocking access
//
- DiskIo = Volume->DiskIo;
- IoFunction = (IoMode == ReadDisk) ? DiskIo->ReadDisk : DiskIo->WriteDisk;
- Status = IoFunction (DiskIo, Volume->MediaId, Offset, BufferSize, Buffer);
+ DiskIo = Volume->DiskIo;
+ IoFunction = (IoMode == ReadDisk) ? DiskIo->ReadDisk : DiskIo->WriteDisk;
+ Status = IoFunction (DiskIo, Volume->MediaId, Offset, BufferSize, Buffer);
} else {
//
// Non-blocking access
//
Subtask = AllocateZeroPool (sizeof (*Subtask));
if (Subtask == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
+ Status = EFI_OUT_OF_RESOURCES;
} 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;
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL,
- TPL_NOTIFY,
- FatOnAccessComplete,
- Subtask,
- &Subtask->DiskIo2Token.Event
- );
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ FatOnAccessComplete,
+ Subtask,
+ &Subtask->DiskIo2Token.Event
+ );
if (!EFI_ERROR (Status)) {
InsertTailList (&Task->Subtasks, &Subtask->Link);
} else {
@@ -436,7 +439,7 @@ FatReleaseLock (
**/
VOID
FatFreeDirEnt (
- IN FAT_DIRENT *DirEnt
+ IN FAT_DIRENT *DirEnt
)
{
if (DirEnt->FileString != NULL) {
@@ -455,7 +458,7 @@ FatFreeDirEnt (
**/
VOID
FatFreeVolume (
- IN FAT_VOLUME *Volume
+ IN FAT_VOLUME *Volume
)
{
//
@@ -464,6 +467,7 @@ FatFreeVolume (
if (Volume->CacheBuffer != NULL) {
FreePool (Volume->CacheBuffer);
}
+
//
// Free directory cache
//
@@ -481,26 +485,26 @@ FatFreeVolume (
**/
VOID
FatEfiTimeToFatTime (
- IN EFI_TIME *ETime,
- OUT FAT_DATE_TIME *FTime
+ IN EFI_TIME *ETime,
+ OUT FAT_DATE_TIME *FTime
)
{
//
// 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) {
FTime->Date.Year = FAT_MAX_YEAR_FROM_1980;
}
- FTime->Date.Month = ETime->Month;
- FTime->Date.Day = ETime->Day;
- FTime->Time.Hour = ETime->Hour;
- FTime->Time.Minute = ETime->Minute;
- FTime->Time.DoubleSecond = (UINT16) (ETime->Second / 2);
+ FTime->Date.Month = ETime->Month;
+ FTime->Date.Day = ETime->Day;
+ FTime->Time.Hour = ETime->Hour;
+ FTime->Time.Minute = ETime->Minute;
+ FTime->Time.DoubleSecond = (UINT16)(ETime->Second / 2);
}
/**
@@ -513,16 +517,16 @@ FatEfiTimeToFatTime (
**/
VOID
FatFatTimeToEfiTime (
- IN FAT_DATE_TIME *FTime,
- OUT EFI_TIME *ETime
+ IN FAT_DATE_TIME *FTime,
+ 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;
@@ -537,20 +541,20 @@ FatFatTimeToEfiTime (
**/
VOID
FatGetCurrentFatTime (
- OUT FAT_DATE_TIME *FatNow
+ OUT FAT_DATE_TIME *FatNow
)
{
- EFI_STATUS Status;
- EFI_TIME Now;
+ EFI_STATUS Status;
+ EFI_TIME Now;
Status = gRT->GetTime (&Now, NULL);
if (!EFI_ERROR (Status)) {
FatEfiTimeToFatTime (&Now, FatNow);
} else {
ZeroMem (&Now, sizeof (EFI_TIME));
- Now.Year = 1980;
+ Now.Year = 1980;
Now.Month = 1;
- Now.Day = 1;
+ Now.Day = 1;
FatEfiTimeToFatTime (&Now, FatNow);
}
}
@@ -567,11 +571,11 @@ FatGetCurrentFatTime (
**/
BOOLEAN
FatIsValidTime (
- IN EFI_TIME *Time
+ IN EFI_TIME *Time
)
{
- UINTN Day;
- BOOLEAN ValidTime;
+ UINTN Day;
+ BOOLEAN ValidTime;
ValidTime = TRUE;
@@ -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;
}
diff --git a/FatPkg/EnhancedFatDxe/Open.c b/FatPkg/EnhancedFatDxe/Open.c
index 6ec7d8e541..f3fd6566ea 100644
--- a/FatPkg/EnhancedFatDxe/Open.c
+++ b/FatPkg/EnhancedFatDxe/Open.c
@@ -22,11 +22,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
EFI_STATUS
FatAllocateIFile (
- IN FAT_OFILE *OFile,
- OUT FAT_IFILE **PtrIFile
+ IN FAT_OFILE *OFile,
+ OUT FAT_IFILE **PtrIFile
)
{
- FAT_IFILE *IFile;
+ FAT_IFILE *IFile;
ASSERT_VOLUME_LOCKED (OFile->Volume);
@@ -83,11 +83,11 @@ FatAllocateIFile (
**/
EFI_STATUS
FatOFileOpen (
- IN FAT_OFILE *OFile,
- OUT FAT_IFILE **NewIFile,
- IN CHAR16 *FileName,
- IN UINT64 OpenMode,
- IN UINT8 Attributes
+ IN FAT_OFILE *OFile,
+ OUT FAT_IFILE **NewIFile,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT8 Attributes
)
{
FAT_VOLUME *Volume;
@@ -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);
@@ -194,12 +198,12 @@ FatOFileOpen (
EFI_STATUS
EFIAPI
FatOpenEx (
- IN EFI_FILE_PROTOCOL *FHand,
- OUT EFI_FILE_PROTOCOL **NewHandle,
- IN CHAR16 *FileName,
- IN UINT64 OpenMode,
- IN UINT64 Attributes,
- IN OUT EFI_FILE_IO_TOKEN *Token
+ IN EFI_FILE_PROTOCOL *FHand,
+ OUT EFI_FILE_PROTOCOL **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes,
+ IN OUT EFI_FILE_IO_TOKEN *Token
)
{
FAT_IFILE *IFile;
@@ -214,23 +218,24 @@ FatOpenEx (
if (FileName == NULL) {
return EFI_INVALID_PARAMETER;
}
+
//
// Check for a valid mode
//
switch (OpenMode) {
- case EFI_FILE_MODE_READ:
- case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
- case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE:
- break;
+ case EFI_FILE_MODE_READ:
+ case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
+ case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE:
+ break;
- default:
- return EFI_INVALID_PARAMETER;
+ default:
+ return EFI_INVALID_PARAMETER;
}
//
// 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
//
@@ -309,11 +316,11 @@ FatOpenEx (
EFI_STATUS
EFIAPI
FatOpen (
- IN EFI_FILE_PROTOCOL *FHand,
- OUT EFI_FILE_PROTOCOL **NewHandle,
- IN CHAR16 *FileName,
- IN UINT64 OpenMode,
- IN UINT64 Attributes
+ IN EFI_FILE_PROTOCOL *FHand,
+ OUT EFI_FILE_PROTOCOL **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes
)
{
return FatOpenEx (FHand, NewHandle, FileName, OpenMode, Attributes, NULL);
diff --git a/FatPkg/EnhancedFatDxe/OpenVolume.c b/FatPkg/EnhancedFatDxe/OpenVolume.c
index 16038468a6..f347586160 100644
--- a/FatPkg/EnhancedFatDxe/OpenVolume.c
+++ b/FatPkg/EnhancedFatDxe/OpenVolume.c
@@ -41,6 +41,7 @@ FatOpenVolume (
if (EFI_ERROR (Status)) {
goto Done;
}
+
//
// Open a new instance to the root
//
diff --git a/FatPkg/EnhancedFatDxe/ReadWrite.c b/FatPkg/EnhancedFatDxe/ReadWrite.c
index 07bed70037..8f525044d1 100644
--- a/FatPkg/EnhancedFatDxe/ReadWrite.c
+++ b/FatPkg/EnhancedFatDxe/ReadWrite.c
@@ -25,12 +25,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
EFI_STATUS
EFIAPI
FatGetPosition (
- IN EFI_FILE_PROTOCOL *FHand,
- OUT UINT64 *Position
+ IN EFI_FILE_PROTOCOL *FHand,
+ OUT UINT64 *Position
)
{
- FAT_IFILE *IFile;
- FAT_OFILE *OFile;
+ FAT_IFILE *IFile;
+ FAT_OFILE *OFile;
IFile = IFILE_FROM_FHAND (FHand);
OFile = IFile->OFile;
@@ -66,8 +66,8 @@ FatSetPosition (
IN UINT64 Position
)
{
- FAT_IFILE *IFile;
- FAT_OFILE *OFile;
+ FAT_IFILE *IFile;
+ FAT_OFILE *OFile;
IFile = IFILE_FROM_FHAND (FHand);
OFile = IFile->OFile;
@@ -91,12 +91,14 @@ FatSetPosition (
FatResetODirCursor (OFile);
}
+
//
// Set the position
//
if (Position == (UINT64)-1) {
Position = OFile->FileSize;
}
+
//
// Set the position
//
@@ -118,9 +120,9 @@ FatSetPosition (
**/
EFI_STATUS
FatIFileReadDir (
- IN FAT_IFILE *IFile,
- IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ IN FAT_IFILE *IFile,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -129,9 +131,9 @@ FatIFileReadDir (
FAT_DIRENT *DirEnt;
UINT32 CurrentPos;
- OFile = IFile->OFile;
- ODir = OFile->ODir;
- CurrentPos = ((UINT32) IFile->Position) / sizeof (FAT_DIRECTORY_ENTRY);
+ OFile = IFile->OFile;
+ ODir = OFile->ODir;
+ 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:
@@ -193,11 +197,11 @@ Done:
**/
EFI_STATUS
FatIFileAccess (
- IN EFI_FILE_PROTOCOL *FHand,
- IN IO_MODE IoMode,
- IN OUT UINTN *BufferSize,
- IN OUT VOID *Buffer,
- IN EFI_FILE_IO_TOKEN *Token
+ IN EFI_FILE_PROTOCOL *FHand,
+ IN IO_MODE IoMode,
+ IN OUT UINTN *BufferSize,
+ IN OUT VOID *Buffer,
+ IN EFI_FILE_IO_TOKEN *Token
)
{
EFI_STATUS Status;
@@ -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;
@@ -269,7 +274,7 @@ FatIFileAccess (
//
ASSERT (IoMode == ReadData);
Status = FatIFileReadDir (IFile, BufferSize, Buffer);
- OFile = NULL;
+ OFile = NULL;
} else {
//
// Access a file
@@ -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;
}
}
@@ -355,7 +360,7 @@ EFIAPI
FatRead (
IN EFI_FILE_PROTOCOL *FHand,
IN OUT UINTN *BufferSize,
- OUT VOID *Buffer
+ OUT VOID *Buffer
)
{
return FatIFileAccess (FHand, ReadData, BufferSize, Buffer, NULL);
@@ -453,12 +458,12 @@ FatWriteEx (
**/
EFI_STATUS
FatAccessOFile (
- IN FAT_OFILE *OFile,
- IN IO_MODE IoMode,
- IN UINTN Position,
- IN OUT UINTN *DataBufferSize,
- IN OUT UINT8 *UserBuffer,
- IN FAT_TASK *Task
+ IN FAT_OFILE *OFile,
+ IN IO_MODE IoMode,
+ IN UINTN Position,
+ IN OUT UINTN *DataBufferSize,
+ IN OUT UINT8 *UserBuffer,
+ IN FAT_TASK *Task
)
{
FAT_VOLUME *Volume;
@@ -466,8 +471,8 @@ FatAccessOFile (
EFI_STATUS Status;
UINTN BufferSize;
- BufferSize = *DataBufferSize;
- Volume = OFile->Volume;
+ BufferSize = *DataBufferSize;
+ Volume = OFile->Volume;
ASSERT_VOLUME_LOCKED (Volume);
Status = EFI_SUCCESS;
@@ -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
//
@@ -498,14 +505,16 @@ FatAccessOFile (
UserBuffer += Len;
BufferSize -= Len;
if (IoMode == WriteData) {
- OFile->Dirty = TRUE;
- OFile->Archive = TRUE;
+ OFile->Dirty = TRUE;
+ OFile->Archive = TRUE;
}
+
//
// Make sure no outbound occurred
//
ASSERT (Position <= OFile->FileSize);
}
+
//
// Update the number of bytes accessed
//
@@ -526,15 +535,15 @@ FatAccessOFile (
**/
EFI_STATUS
FatExpandOFile (
- IN FAT_OFILE *OFile,
- IN UINT64 ExpandedSize
+ IN FAT_OFILE *OFile,
+ IN UINT64 ExpandedSize
)
{
EFI_STATUS Status;
UINTN WritePos;
- WritePos = OFile->FileSize;
- Status = FatGrowEof (OFile, ExpandedSize);
+ WritePos = OFile->FileSize;
+ Status = FatGrowEof (OFile, ExpandedSize);
if (!EFI_ERROR (Status)) {
Status = FatWriteZeroPool (OFile, WritePos);
}
@@ -566,8 +575,8 @@ FatWriteZeroPool (
UINTN BufferSize;
UINTN WriteSize;
- AppendedSize = OFile->FileSize - WritePos;
- BufferSize = AppendedSize;
+ AppendedSize = OFile->FileSize - WritePos;
+ BufferSize = AppendedSize;
if (AppendedSize > FAT_MAX_ALLOCATE_SIZE) {
//
// If the appended size is larger, maybe we can not allocate the whole
@@ -584,9 +593,9 @@ FatWriteZeroPool (
}
do {
- WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN) AppendedSize;
+ WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN)AppendedSize;
AppendedSize -= WriteSize;
- Status = FatAccessOFile (OFile, WriteData, WritePos, &WriteSize, ZeroBuffer, NULL);
+ Status = FatAccessOFile (OFile, WriteData, WritePos, &WriteSize, ZeroBuffer, NULL);
if (EFI_ERROR (Status)) {
break;
}
@@ -611,8 +620,8 @@ FatWriteZeroPool (
**/
EFI_STATUS
FatTruncateOFile (
- IN FAT_OFILE *OFile,
- IN UINTN TruncatedSize
+ IN FAT_OFILE *OFile,
+ IN UINTN TruncatedSize
)
{
OFile->FileSize = TruncatedSize;
diff --git a/FatPkg/EnhancedFatDxe/UnicodeCollation.c b/FatPkg/EnhancedFatDxe/UnicodeCollation.c
index 9b22e05bc3..813f153617 100644
--- a/FatPkg/EnhancedFatDxe/UnicodeCollation.c
+++ b/FatPkg/EnhancedFatDxe/UnicodeCollation.c
@@ -28,10 +28,10 @@ EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL;
**/
EFI_STATUS
InitializeUnicodeCollationSupportWorker (
- IN EFI_HANDLE AgentHandle,
- IN EFI_GUID *ProtocolGuid,
- IN CONST CHAR16 *VariableName,
- IN CONST CHAR8 *DefaultLanguage
+ IN EFI_HANDLE AgentHandle,
+ IN EFI_GUID *ProtocolGuid,
+ IN CONST CHAR16 *VariableName,
+ IN CONST CHAR8 *DefaultLanguage
)
{
EFI_STATUS ReturnStatus;
@@ -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
@@ -89,7 +89,7 @@ InitializeUnicodeCollationSupportWorker (
if (BestLanguage != NULL) {
FreePool (BestLanguage);
mUnicodeCollationInterface = Uci;
- ReturnStatus = EFI_SUCCESS;
+ ReturnStatus = EFI_SUCCESS;
break;
}
}
@@ -118,11 +118,10 @@ InitializeUnicodeCollationSupportWorker (
**/
EFI_STATUS
InitializeUnicodeCollationSupport (
- IN EFI_HANDLE AgentHandle
+ IN EFI_HANDLE AgentHandle
)
{
-
- EFI_STATUS Status;
+ 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.
@@ -164,8 +162,8 @@ InitializeUnicodeCollationSupport (
**/
INTN
FatStriCmp (
- IN CHAR16 *S1,
- IN CHAR16 *S2
+ IN CHAR16 *S1,
+ IN CHAR16 *S2
)
{
ASSERT (StrSize (S1) != 0);
@@ -179,7 +177,6 @@ FatStriCmp (
);
}
-
/**
Uppercase a string.
@@ -189,7 +186,7 @@ FatStriCmp (
**/
VOID
FatStrUpr (
- IN OUT CHAR16 *String
+ IN OUT CHAR16 *String
)
{
ASSERT (StrSize (String) != 0);
@@ -198,7 +195,6 @@ FatStrUpr (
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
}
-
/**
Lowercase a string
@@ -208,7 +204,7 @@ FatStrUpr (
**/
VOID
FatStrLwr (
- IN OUT CHAR16 *String
+ IN OUT CHAR16 *String
)
{
ASSERT (StrSize (String) != 0);
@@ -217,7 +213,6 @@ FatStrLwr (
mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
}
-
/**
Convert FAT string to unicode string.
@@ -230,20 +225,19 @@ FatStrLwr (
**/
VOID
FatFatToStr (
- IN UINTN FatSize,
- IN CHAR8 *Fat,
- OUT CHAR16 *String
+ IN UINTN FatSize,
+ IN CHAR8 *Fat,
+ OUT CHAR16 *String
)
{
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.
@@ -257,9 +251,9 @@ FatFatToStr (
**/
BOOLEAN
FatStrToFat (
- IN CHAR16 *String,
- IN UINTN FatSize,
- OUT CHAR8 *Fat
+ IN CHAR16 *String,
+ IN UINTN FatSize,
+ OUT CHAR8 *Fat
)
{
ASSERT (Fat != NULL);
diff --git a/FatPkg/FatPei/Eltorito.c b/FatPkg/FatPei/Eltorito.c
index 5fe0cb454e..d35768e6ef 100644
--- a/FatPkg/FatPei/Eltorito.c
+++ b/FatPkg/FatPei/Eltorito.c
@@ -25,33 +25,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
FatFindEltoritoPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
- EFI_STATUS Status;
- BOOLEAN Found;
- PEI_FAT_BLOCK_DEVICE *BlockDev;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- UINT32 VolDescriptorLba;
- UINT32 Lba;
- CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
- ELTORITO_CATALOG *Catalog;
- UINTN Check;
- UINTN Index;
- UINTN MaxIndex;
- UINT16 *CheckBuffer;
- UINT32 SubBlockSize;
- UINT32 SectorCount;
- UINT32 VolSpaceSize;
+ EFI_STATUS Status;
+ BOOLEAN Found;
+ PEI_FAT_BLOCK_DEVICE *BlockDev;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ UINT32 VolDescriptorLba;
+ UINT32 Lba;
+ CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
+ ELTORITO_CATALOG *Catalog;
+ UINTN Check;
+ UINTN Index;
+ UINTN MaxIndex;
+ UINT16 *CheckBuffer;
+ UINT32 SubBlockSize;
+ UINT32 SectorCount;
+ UINT32 VolSpaceSize;
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
return FALSE;
}
- Found = FALSE;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
- VolSpaceSize = 0;
+ Found = FALSE;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ VolSpaceSize = 0;
//
// CD_ROM has the fixed block size as 2048 bytes
@@ -60,8 +60,8 @@ FatFindEltoritoPartitions (
return FALSE;
}
- VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
- Catalog = (ELTORITO_CATALOG *) VolDescriptor;
+ VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *)PrivateData->BlockData;
+ Catalog = (ELTORITO_CATALOG *)VolDescriptor;
//
// the ISO-9660 volume descriptor starts at 32k on the media
@@ -74,7 +74,6 @@ FatFindEltoritoPartitions (
// Loop: handle one volume descriptor per time
//
while (TRUE) {
-
VolDescriptorLba += 1;
if (VolDescriptorLba > ParentBlockDev->LastBlock) {
//
@@ -84,32 +83,36 @@ FatFindEltoritoPartitions (
}
Status = FatReadBlock (
- PrivateData,
- ParentBlockDevNo,
- VolDescriptorLba,
- ParentBlockDev->BlockSize,
- VolDescriptor
- );
+ PrivateData,
+ ParentBlockDevNo,
+ VolDescriptorLba,
+ ParentBlockDev->BlockSize,
+ VolDescriptor
+ );
if (EFI_ERROR (Status)) {
break;
}
+
//
// Check for valid volume descriptor signature
//
- if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
- CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0
- ) {
+ if ((VolDescriptor->Unknown.Type == CDVOL_TYPE_END) ||
+ (CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0)
+ )
+ {
//
// end of Volume descriptor list
//
break;
}
+
//
// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
//
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
}
+
//
// Is it an El Torito volume descriptor?
//
@@ -117,9 +120,11 @@ FatFindEltoritoPartitions (
VolDescriptor->BootRecordVolume.SystemId,
CDVOL_ELTORITO_ID,
sizeof (CDVOL_ELTORITO_ID) - 1
- ) != 0) {
+ ) != 0)
+ {
continue;
}
+
//
// Read in the boot El Torito boot catalog
//
@@ -129,25 +134,26 @@ FatFindEltoritoPartitions (
}
Status = FatReadBlock (
- PrivateData,
- ParentBlockDevNo,
- Lba,
- ParentBlockDev->BlockSize,
- Catalog
- );
+ PrivateData,
+ ParentBlockDevNo,
+ Lba,
+ ParentBlockDev->BlockSize,
+ Catalog
+ );
if (EFI_ERROR (Status)) {
continue;
}
+
//
// We don't care too much about the Catalog header's contents, but we do want
// to make sure it looks like a Catalog header
//
- if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) {
+ if ((Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG) || (Catalog->Catalog.Id55AA != 0xAA55)) {
continue;
}
Check = 0;
- CheckBuffer = (UINT16 *) Catalog;
+ CheckBuffer = (UINT16 *)Catalog;
for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
Check += CheckBuffer[Index];
}
@@ -166,60 +172,59 @@ FatFindEltoritoPartitions (
//
// Check this entry
//
- if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) {
+ if ((Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE) || (Catalog->Boot.Lba == 0)) {
continue;
}
- SubBlockSize = 512;
- SectorCount = Catalog->Boot.SectorCount;
+ SubBlockSize = 512;
+ SectorCount = Catalog->Boot.SectorCount;
switch (Catalog->Boot.MediaType) {
-
- case ELTORITO_NO_EMULATION:
- SubBlockSize = ParentBlockDev->BlockSize;
- SectorCount = Catalog->Boot.SectorCount;
- break;
-
- case ELTORITO_HARD_DISK:
- break;
-
- case ELTORITO_12_DISKETTE:
- SectorCount = 0x50 * 0x02 * 0x0F;
- break;
-
- case ELTORITO_14_DISKETTE:
- SectorCount = 0x50 * 0x02 * 0x12;
- break;
-
- case ELTORITO_28_DISKETTE:
- SectorCount = 0x50 * 0x02 * 0x24;
- break;
-
- default:
- SectorCount = 0;
- SubBlockSize = ParentBlockDev->BlockSize;
- break;
+ case ELTORITO_NO_EMULATION:
+ SubBlockSize = ParentBlockDev->BlockSize;
+ SectorCount = Catalog->Boot.SectorCount;
+ break;
+
+ case ELTORITO_HARD_DISK:
+ break;
+
+ case ELTORITO_12_DISKETTE:
+ SectorCount = 0x50 * 0x02 * 0x0F;
+ break;
+
+ case ELTORITO_14_DISKETTE:
+ SectorCount = 0x50 * 0x02 * 0x12;
+ break;
+
+ case ELTORITO_28_DISKETTE:
+ SectorCount = 0x50 * 0x02 * 0x24;
+ break;
+
+ default:
+ SectorCount = 0;
+ SubBlockSize = ParentBlockDev->BlockSize;
+ break;
}
if (SectorCount < 2) {
- SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32) (ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32) (VolSpaceSize - Catalog->Boot.Lba);
+ SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32)(ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32)(VolSpaceSize - Catalog->Boot.Lba);
}
+
//
// Register this partition
//
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
+ Found = TRUE;
- Found = TRUE;
-
- BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
+ BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
- BlockDev->BlockSize = SubBlockSize;
- BlockDev->LastBlock = SectorCount - 1;
- BlockDev->IoAlign = ParentBlockDev->IoAlign;
- BlockDev->Logical = TRUE;
- BlockDev->PartitionChecked = FALSE;
- BlockDev->StartingPos = MultU64x32 (Catalog->Boot.Lba, ParentBlockDev->BlockSize);
- BlockDev->ParentDevNo = ParentBlockDevNo;
+ BlockDev->BlockSize = SubBlockSize;
+ BlockDev->LastBlock = SectorCount - 1;
+ BlockDev->IoAlign = ParentBlockDev->IoAlign;
+ BlockDev->Logical = TRUE;
+ BlockDev->PartitionChecked = FALSE;
+ BlockDev->StartingPos = MultU64x32 (Catalog->Boot.Lba, ParentBlockDev->BlockSize);
+ BlockDev->ParentDevNo = ParentBlockDevNo;
PrivateData->BlockDeviceCount++;
}
@@ -229,5 +234,4 @@ FatFindEltoritoPartitions (
ParentBlockDev->PartitionChecked = TRUE;
return Found;
-
}
diff --git a/FatPkg/FatPei/FatLiteAccess.c b/FatPkg/FatPei/FatLiteAccess.c
index a3f846dda1..10df4516b2 100644
--- a/FatPkg/FatPei/FatLiteAccess.c
+++ b/FatPkg/FatPei/FatLiteAccess.c
@@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h"
-
/**
Check if there is a valid FAT in the corresponding Block device
of the volume and if yes, fill in the relevant fields for the
@@ -49,25 +48,25 @@ FatGetBpbInfo (
// Read in the BPB
//
Status = FatReadDisk (
- PrivateData,
- Volume->BlockDeviceNo,
- 0,
- sizeof (PEI_FAT_BOOT_SECTOR_EX),
- &BpbEx
- );
+ PrivateData,
+ Volume->BlockDeviceNo,
+ 0,
+ sizeof (PEI_FAT_BOOT_SECTOR_EX),
+ &BpbEx
+ );
if (EFI_ERROR (Status)) {
return Status;
}
CopyMem (
- (UINT8 *) (&Bpb),
- (UINT8 *) (&BpbEx),
+ (UINT8 *)(&Bpb),
+ (UINT8 *)(&BpbEx),
sizeof (PEI_FAT_BOOT_SECTOR)
);
Volume->FatType = FatUnknown;
- Sectors = Bpb.Sectors;
+ Sectors = Bpb.Sectors;
if (Sectors == 0) {
Sectors = Bpb.LargeSectors;
}
@@ -77,60 +76,65 @@ FatGetBpbInfo (
SectorsPerFat = BpbEx.LargeSectorsPerFat;
Volume->FatType = Fat32;
}
+
//
// Filter out those not a FAT
//
- if (Bpb.Ia32Jump[0] != 0xe9 && Bpb.Ia32Jump[0] != 0xeb && Bpb.Ia32Jump[0] != 0x49) {
+ if ((Bpb.Ia32Jump[0] != 0xe9) && (Bpb.Ia32Jump[0] != 0xeb) && (Bpb.Ia32Jump[0] != 0x49)) {
return EFI_NOT_FOUND;
}
- if (Bpb.ReservedSectors == 0 || Bpb.NoFats == 0 || Sectors == 0) {
+ if ((Bpb.ReservedSectors == 0) || (Bpb.NoFats == 0) || (Sectors == 0)) {
return EFI_NOT_FOUND;
}
- if (Bpb.SectorsPerCluster != 1 &&
- Bpb.SectorsPerCluster != 2 &&
- Bpb.SectorsPerCluster != 4 &&
- Bpb.SectorsPerCluster != 8 &&
- Bpb.SectorsPerCluster != 16 &&
- Bpb.SectorsPerCluster != 32 &&
- Bpb.SectorsPerCluster != 64 &&
- Bpb.SectorsPerCluster != 128
- ) {
+ if ((Bpb.SectorsPerCluster != 1) &&
+ (Bpb.SectorsPerCluster != 2) &&
+ (Bpb.SectorsPerCluster != 4) &&
+ (Bpb.SectorsPerCluster != 8) &&
+ (Bpb.SectorsPerCluster != 16) &&
+ (Bpb.SectorsPerCluster != 32) &&
+ (Bpb.SectorsPerCluster != 64) &&
+ (Bpb.SectorsPerCluster != 128)
+ )
+ {
return EFI_NOT_FOUND;
}
- if (Volume->FatType == Fat32 && (SectorsPerFat == 0 || BpbEx.FsVersion != 0)) {
+ if ((Volume->FatType == Fat32) && ((SectorsPerFat == 0) || (BpbEx.FsVersion != 0))) {
return EFI_NOT_FOUND;
}
- if (Bpb.Media != 0xf0 &&
- Bpb.Media != 0xf8 &&
- Bpb.Media != 0xf9 &&
- Bpb.Media != 0xfb &&
- Bpb.Media != 0xfc &&
- Bpb.Media != 0xfd &&
- Bpb.Media != 0xfe &&
- Bpb.Media != 0xff &&
+ if ((Bpb.Media != 0xf0) &&
+ (Bpb.Media != 0xf8) &&
+ (Bpb.Media != 0xf9) &&
+ (Bpb.Media != 0xfb) &&
+ (Bpb.Media != 0xfc) &&
+ (Bpb.Media != 0xfd) &&
+ (Bpb.Media != 0xfe) &&
+ (Bpb.Media != 0xff) &&
//
// FujitsuFMR
//
- Bpb.Media != 0x00 &&
- Bpb.Media != 0x01 &&
- Bpb.Media != 0xfa
- ) {
+ (Bpb.Media != 0x00) &&
+ (Bpb.Media != 0x01) &&
+ (Bpb.Media != 0xfa)
+ )
+ {
return EFI_NOT_FOUND;
}
- if (Volume->FatType != Fat32 && Bpb.RootEntries == 0) {
+ if ((Volume->FatType != Fat32) && (Bpb.RootEntries == 0)) {
return EFI_NOT_FOUND;
}
+
//
// If this is fat32, refuse to mount mirror-disabled volumes
//
- if (Volume->FatType == Fat32 && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
+ if ((Volume->FatType == Fat32) && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
return EFI_NOT_FOUND;
}
+
//
// Fill in the volume structure fields
// (Sectors & SectorsPerFat is computed earlier already)
@@ -141,22 +145,21 @@ FatGetBpbInfo (
RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (Volume->SectorSize - 1)) / Volume->SectorSize;
- FatLba = Bpb.ReservedSectors;
- RootLba = Bpb.NoFats * SectorsPerFat + FatLba;
- FirstClusterLba = RootLba + RootDirSectors;
+ FatLba = Bpb.ReservedSectors;
+ RootLba = Bpb.NoFats * SectorsPerFat + FatLba;
+ FirstClusterLba = RootLba + RootDirSectors;
Volume->VolumeSize = MultU64x32 (Sectors, Volume->SectorSize);
Volume->FatPos = MultU64x32 (FatLba, Volume->SectorSize);
Volume->RootDirPos = MultU64x32 (RootLba, Volume->SectorSize);
Volume->FirstClusterPos = MultU64x32 (FirstClusterLba, Volume->SectorSize);
- Volume->MaxCluster = (UINT32) (Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;
+ Volume->MaxCluster = (UINT32)(Sectors - FirstClusterLba) / Bpb.SectorsPerCluster;
Volume->RootDirCluster = BpbEx.RootDirFirstCluster;
//
// If this is not a fat32, determine if it's a fat16 or fat12
//
if (Volume->FatType != Fat32) {
-
if (Volume->MaxCluster >= 65525) {
return EFI_NOT_FOUND;
}
@@ -167,7 +170,6 @@ FatGetBpbInfo (
return EFI_SUCCESS;
}
-
/**
Gets the next cluster in the cluster chain
@@ -198,7 +200,7 @@ FatGetNextCluster (
if (Volume->FatType == Fat32) {
FatEntryPos = Volume->FatPos + MultU64x32 (4, Cluster);
- Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);
+ Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);
*NextCluster &= 0x0fffffff;
//
@@ -207,11 +209,10 @@ FatGetNextCluster (
if ((*NextCluster) >= 0x0ffffff7) {
*NextCluster |= (-1 &~0xf);
}
-
} else if (Volume->FatType == Fat16) {
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
- Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
+ Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
//
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
@@ -219,17 +220,17 @@ FatGetNextCluster (
if ((*NextCluster) >= 0xfff7) {
*NextCluster |= (-1 &~0xf);
}
-
} else {
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
- Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
+ Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
if ((Cluster & 0x01) != 0) {
*NextCluster = (*NextCluster) >> 4;
} else {
*NextCluster = (*NextCluster) & 0x0fff;
}
+
//
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
//
@@ -243,10 +244,8 @@ FatGetNextCluster (
}
return EFI_SUCCESS;
-
}
-
/**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@@ -274,31 +273,29 @@ FatSetFilePos (
UINT32 PrevCluster;
if (File->IsFixedRootDir) {
-
if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {
return EFI_INVALID_PARAMETER;
}
- File->CurrentPos += Pos;
- File->StraightReadAmount = (UINT32) (MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
-
+ File->CurrentPos += Pos;
+ File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
} else {
-
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
- AlignedPos = (UINT32) File->CurrentPos - (UINT32) Offset;
+ AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;
while
(
- !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
- AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
- ) {
+ !FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
+ AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
+ )
+ {
AlignedPos += File->Volume->ClusterSize;
- Status = FatGetNextCluster (
- PrivateData,
- File->Volume,
- File->CurrentCluster,
- &File->CurrentCluster
- );
+ Status = FatGetNextCluster (
+ PrivateData,
+ File->Volume,
+ File->CurrentCluster,
+ &File->CurrentCluster
+ );
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -313,12 +310,12 @@ FatSetFilePos (
// Calculate the amount of consecutive cluster occupied by the file.
// FatReadFile() will use it to read these blocks once.
//
- File->StraightReadAmount = 0;
- Cluster = File->CurrentCluster;
+ File->StraightReadAmount = 0;
+ Cluster = File->CurrentCluster;
while (!FAT_CLUSTER_FUNCTIONAL (Cluster)) {
File->StraightReadAmount += File->Volume->ClusterSize;
- PrevCluster = Cluster;
- Status = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);
+ PrevCluster = Cluster;
+ Status = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -329,14 +326,12 @@ FatSetFilePos (
}
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
- File->StraightReadAmount -= (UINT32) Offset;
-
+ File->StraightReadAmount -= (UINT32)Offset;
}
return EFI_SUCCESS;
}
-
/**
Reads file data. Updates the file's CurrentPos.
@@ -375,53 +370,52 @@ FatReadFile (
}
Status = FatReadDisk (
- PrivateData,
- File->Volume->BlockDeviceNo,
- File->Volume->RootDirPos + File->CurrentPos,
- Size,
- Buffer
- );
- File->CurrentPos += (UINT32) Size;
+ PrivateData,
+ File->Volume->BlockDeviceNo,
+ File->Volume->RootDirPos + File->CurrentPos,
+ Size,
+ Buffer
+ );
+ File->CurrentPos += (UINT32)Size;
return Status;
-
} else {
-
if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
}
+
//
// This is a normal cluster based file
//
while (Size != 0) {
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
- PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);
+ PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);
- Amount = File->StraightReadAmount;
- Amount = Size > Amount ? Amount : Size;
+ Amount = File->StraightReadAmount;
+ Amount = Size > Amount ? Amount : Size;
Status = FatReadDisk (
- PrivateData,
- File->Volume->BlockDeviceNo,
- PhysicalAddr + Offset,
- Amount,
- BufferPtr
- );
+ PrivateData,
+ File->Volume->BlockDeviceNo,
+ PhysicalAddr + Offset,
+ Amount,
+ BufferPtr
+ );
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// Advance the file's current pos and current cluster
//
- FatSetFilePos (PrivateData, File, (UINT32) Amount);
+ FatSetFilePos (PrivateData, File, (UINT32)Amount);
BufferPtr += Amount;
- Size -= Amount;
+ Size -= Amount;
}
return EFI_SUCCESS;
}
}
-
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@@ -446,13 +440,13 @@ FatReadNextDirectoryEntry (
OUT PEI_FAT_FILE *SubFile
)
{
- EFI_STATUS Status;
- FAT_DIRECTORY_ENTRY DirEntry;
- CHAR16 *Pos;
- CHAR16 BaseName[9];
- CHAR16 Ext[4];
+ EFI_STATUS Status;
+ FAT_DIRECTORY_ENTRY DirEntry;
+ CHAR16 *Pos;
+ CHAR16 BaseName[9];
+ CHAR16 Ext[4];
- ZeroMem ((UINT8 *) SubFile, sizeof (PEI_FAT_FILE));
+ ZeroMem ((UINT8 *)SubFile, sizeof (PEI_FAT_FILE));
//
// Pick a valid directory entry
@@ -465,6 +459,7 @@ FatReadNextDirectoryEntry (
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// We only search for *FILE* in root directory
// Long file name entry is *NOT* supported
@@ -472,35 +467,38 @@ FatReadNextDirectoryEntry (
if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {
continue;
}
+
//
// if this is a terminator dir entry, just return EFI_NOT_FOUND
//
if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {
return EFI_NOT_FOUND;
}
+
//
// If this not an invalid entry neither an empty entry, this is what we want.
// otherwise we will start a new loop to continue to find something meaningful
//
- if ((UINT8) DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
+ if ((UINT8)DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
break;
}
}
+
//
// fill in the output parameter
//
EngFatToStr (8, DirEntry.FileName, BaseName);
EngFatToStr (3, DirEntry.FileName + 8, Ext);
- Pos = (UINT16 *) SubFile->FileName;
- SetMem ((UINT8 *) Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
- CopyMem ((UINT8 *) Pos, (UINT8 *) BaseName, 2 * (StrLen (BaseName) + 1));
+ Pos = (UINT16 *)SubFile->FileName;
+ SetMem ((UINT8 *)Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
+ CopyMem ((UINT8 *)Pos, (UINT8 *)BaseName, 2 * (StrLen (BaseName) + 1));
if (Ext[0] != 0) {
Pos += StrLen (BaseName);
*Pos = '.';
Pos++;
- CopyMem ((UINT8 *) Pos, (UINT8 *) Ext, 2 * (StrLen (Ext) + 1));
+ CopyMem ((UINT8 *)Pos, (UINT8 *)Ext, 2 * (StrLen (Ext) + 1));
}
SubFile->Attributes = DirEntry.Attributes;
@@ -509,10 +507,10 @@ FatReadNextDirectoryEntry (
SubFile->CurrentCluster |= DirEntry.FileClusterHigh << 16;
}
- SubFile->CurrentPos = 0;
- SubFile->FileSize = DirEntry.FileSize;
- SubFile->StartingCluster = SubFile->CurrentCluster;
- SubFile->Volume = ParentDir->Volume;
+ SubFile->CurrentPos = 0;
+ SubFile->FileSize = DirEntry.FileSize;
+ SubFile->StartingCluster = SubFile->CurrentCluster;
+ SubFile->Volume = ParentDir->Volume;
//
// in Pei phase, time parameters do not need to be filled for minimum use.
diff --git a/FatPkg/FatPei/FatLiteApi.c b/FatPkg/FatPei/FatLiteApi.c
index d07422ba93..cc48c4c66b 100644
--- a/FatPkg/FatPei/FatLiteApi.c
+++ b/FatPkg/FatPei/FatLiteApi.c
@@ -33,7 +33,6 @@ BlockIoNotifyEntry (
IN VOID *Ppi
);
-
/**
Discover all the block I/O devices to find the FAT volume.
@@ -46,23 +45,23 @@ BlockIoNotifyEntry (
**/
EFI_STATUS
UpdateBlocksAndVolumes (
- IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
- IN BOOLEAN BlockIo2
+ IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN BOOLEAN BlockIo2
)
{
- EFI_STATUS Status;
- EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
- UINTN BlockIoPpiInstance;
- EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
- EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
- UINTN NumberBlockDevices;
- UINTN Index;
- EFI_PEI_BLOCK_IO_MEDIA Media;
- EFI_PEI_BLOCK_IO2_MEDIA Media2;
- PEI_FAT_VOLUME Volume;
- EFI_PEI_SERVICES **PeiServices;
-
- PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
+ UINTN BlockIoPpiInstance;
+ EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
+ EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
+ UINTN NumberBlockDevices;
+ UINTN Index;
+ EFI_PEI_BLOCK_IO_MEDIA Media;
+ EFI_PEI_BLOCK_IO2_MEDIA Media2;
+ PEI_FAT_VOLUME Volume;
+ EFI_PEI_SERVICES **PeiServices;
+
+ PeiServices = (EFI_PEI_SERVICES **)GetPeiServicesTablePointer ();
BlockIo2Ppi = NULL;
BlockIoPpi = NULL;
//
@@ -81,19 +80,20 @@ UpdateBlocksAndVolumes (
for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_FAT_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
if (BlockIo2) {
Status = PeiServicesLocatePpi (
- &gEfiPeiVirtualBlockIo2PpiGuid,
- BlockIoPpiInstance,
- &TempPpiDescriptor,
- (VOID **) &BlockIo2Ppi
- );
+ &gEfiPeiVirtualBlockIo2PpiGuid,
+ BlockIoPpiInstance,
+ &TempPpiDescriptor,
+ (VOID **)&BlockIo2Ppi
+ );
} else {
Status = PeiServicesLocatePpi (
- &gEfiPeiVirtualBlockIoPpiGuid,
- BlockIoPpiInstance,
- &TempPpiDescriptor,
- (VOID **) &BlockIoPpi
- );
+ &gEfiPeiVirtualBlockIoPpiGuid,
+ BlockIoPpiInstance,
+ &TempPpiDescriptor,
+ (VOID **)&BlockIoPpi
+ );
}
+
if (EFI_ERROR (Status)) {
//
// Done with all Block Io Ppis
@@ -114,12 +114,12 @@ UpdateBlocksAndVolumes (
&NumberBlockDevices
);
}
+
if (EFI_ERROR (Status)) {
continue;
}
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
-
if (BlockIo2) {
Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
PeiServices,
@@ -130,10 +130,11 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media2.MediaPresent) {
continue;
}
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
+
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
} else {
Status = BlockIoPpi->GetBlockDeviceMediaInfo (
PeiServices,
@@ -144,23 +145,25 @@ UpdateBlocksAndVolumes (
if (EFI_ERROR (Status) || !Media.MediaPresent) {
continue;
}
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
+
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32)Media.BlockSize;
}
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
//
// Not used here
//
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
- PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8) Index;
+ PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8)Index;
PrivateData->BlockDeviceCount++;
}
}
+
//
// Find out all logical devices
//
@@ -171,15 +174,15 @@ UpdateBlocksAndVolumes (
//
PrivateData->VolumeCount = 0;
for (Index = 0; Index < PrivateData->BlockDeviceCount; Index++) {
- Volume.BlockDeviceNo = Index;
- Status = FatGetBpbInfo (PrivateData, &Volume);
+ Volume.BlockDeviceNo = Index;
+ Status = FatGetBpbInfo (PrivateData, &Volume);
if (Status == EFI_SUCCESS) {
//
// Add the detected volume to the volume array
//
CopyMem (
- (UINT8 *) &(PrivateData->Volume[PrivateData->VolumeCount]),
- (UINT8 *) &Volume,
+ (UINT8 *)&(PrivateData->Volume[PrivateData->VolumeCount]),
+ (UINT8 *)&Volume,
sizeof (PEI_FAT_VOLUME)
);
PrivateData->VolumeCount += 1;
@@ -192,7 +195,6 @@ UpdateBlocksAndVolumes (
return EFI_SUCCESS;
}
-
/**
BlockIo installation notification function. Find out all the current BlockIO
PPIs in the system and add them into private data. Assume there is
@@ -220,10 +222,10 @@ BlockIoNotifyEntry (
} else {
UpdateBlocksAndVolumes (mPrivateData, FALSE);
}
+
return EFI_SUCCESS;
}
-
/**
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
installation notification
@@ -241,8 +243,8 @@ BlockIoNotifyEntry (
EFI_STATUS
EFIAPI
FatPeimEntry (
- IN EFI_PEI_FILE_HANDLE FileHandle,
- IN CONST EFI_PEI_SERVICES **PeiServices
+ IN EFI_PEI_FILE_HANDLE FileHandle,
+ IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
@@ -255,38 +257,39 @@ FatPeimEntry (
}
Status = PeiServicesAllocatePages (
- EfiBootServicesCode,
- (sizeof (PEI_FAT_PRIVATE_DATA) - 1) / PEI_FAT_MEMORY_PAGE_SIZE + 1,
- &Address
- );
+ EfiBootServicesCode,
+ (sizeof (PEI_FAT_PRIVATE_DATA) - 1) / PEI_FAT_MEMORY_PAGE_SIZE + 1,
+ &Address
+ );
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
- PrivateData = (PEI_FAT_PRIVATE_DATA *) (UINTN) Address;
+ PrivateData = (PEI_FAT_PRIVATE_DATA *)(UINTN)Address;
//
// Initialize Private Data (to zero, as is required by subsequent operations)
//
- ZeroMem ((UINT8 *) PrivateData, sizeof (PEI_FAT_PRIVATE_DATA));
+ ZeroMem ((UINT8 *)PrivateData, sizeof (PEI_FAT_PRIVATE_DATA));
PrivateData->Signature = PEI_FAT_PRIVATE_DATA_SIGNATURE;
//
// Installs Ppi
//
- PrivateData->DeviceRecoveryPpi.GetNumberRecoveryCapsules = GetNumberRecoveryCapsules;
- PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo = GetRecoveryCapsuleInfo;
- PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule = LoadRecoveryCapsule;
+ PrivateData->DeviceRecoveryPpi.GetNumberRecoveryCapsules = GetNumberRecoveryCapsules;
+ PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo = GetRecoveryCapsuleInfo;
+ PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule = LoadRecoveryCapsule;
- PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
- PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
- PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
+ PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
+ PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
+ PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
Status = PeiServicesInstallPpi (&PrivateData->PpiDescriptor);
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
+
//
// Other initializations
//
@@ -305,21 +308,20 @@ FatPeimEntry (
//
PrivateData->NotifyDescriptor[0].Flags =
(
- EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
+ EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
);
- PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
- PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
+ PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
+ PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
PrivateData->NotifyDescriptor[1].Flags =
(
- EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
- EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
+ EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
+ EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
- PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
- PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
+ PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
+ PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
}
-
/**
Returns the number of DXE capsules residing on the device.
@@ -346,9 +348,9 @@ FatPeimEntry (
EFI_STATUS
EFIAPI
GetNumberRecoveryCapsules (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- OUT UINTN *NumberRecoveryCapsules
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ OUT UINTN *NumberRecoveryCapsules
)
{
EFI_STATUS Status;
@@ -364,7 +366,7 @@ GetNumberRecoveryCapsules (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
@@ -381,7 +383,6 @@ GetNumberRecoveryCapsules (
return EFI_SUCCESS;
}
-
/**
Returns the size and type of the requested recovery capsule.
@@ -410,11 +411,11 @@ GetNumberRecoveryCapsules (
EFI_STATUS
EFIAPI
GetRecoveryCapsuleInfo (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT UINTN *Size,
- OUT EFI_GUID *CapsuleType
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT UINTN *Size,
+ OUT EFI_GUID *CapsuleType
)
{
EFI_STATUS Status;
@@ -442,7 +443,7 @@ GetRecoveryCapsuleInfo (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
@@ -452,7 +453,7 @@ GetRecoveryCapsuleInfo (
//
// Get file size
//
- *Size = (UINTN) (((PEI_FAT_FILE *) Handle)->FileSize);
+ *Size = (UINTN)(((PEI_FAT_FILE *)Handle)->FileSize);
//
// Find corresponding physical block device
@@ -461,45 +462,47 @@ GetRecoveryCapsuleInfo (
while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) {
BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo;
}
+
//
// Fill in the Capsule Type GUID according to the block device type
//
if (BlockDeviceNo < PrivateData->BlockDeviceCount) {
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo2 != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].InterfaceType) {
- case MSG_ATAPI_DP:
- CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
- break;
+ case MSG_ATAPI_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
+ break;
- case MSG_USB_DP:
- CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
- break;
+ case MSG_USB_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
+ break;
- case MSG_NVME_NAMESPACE_DP:
- CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
- break;
+ case MSG_NVME_NAMESPACE_DP:
+ CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
+ break;
- default:
- break;
+ default:
+ break;
}
}
+
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
- case LegacyFloppy:
- CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
- break;
+ case LegacyFloppy:
+ CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
+ break;
- case IdeCDROM:
- case IdeLS120:
- CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
- break;
+ case IdeCDROM:
+ case IdeLS120:
+ CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
+ break;
- case UsbMassStorage:
- CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
- break;
+ case UsbMassStorage:
+ CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
+ break;
- default:
- break;
+ default:
+ break;
}
}
}
@@ -513,7 +516,6 @@ GetRecoveryCapsuleInfo (
return EFI_NOT_FOUND;
}
-
/**
Loads a DXE capsule from some media into memory.
@@ -536,10 +538,10 @@ GetRecoveryCapsuleInfo (
EFI_STATUS
EFIAPI
LoadRecoveryCapsule (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT VOID *Buffer
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -566,19 +568,18 @@ LoadRecoveryCapsule (
//
RecoveryCapsuleCount = 0;
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
- Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr(PcdRecoveryFileName), &Handle);
+ Status = FindRecoveryFile (PrivateData, Index, (CHAR16 *)PcdGetPtr (PcdRecoveryFileName), &Handle);
if (EFI_ERROR (Status)) {
continue;
}
if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
-
Status = FatReadFile (
- PrivateData,
- Handle,
- (UINTN) (((PEI_FAT_FILE *) Handle)->FileSize),
- Buffer
- );
+ PrivateData,
+ Handle,
+ (UINTN)(((PEI_FAT_FILE *)Handle)->FileSize),
+ Buffer
+ );
return Status;
}
@@ -588,7 +589,6 @@ LoadRecoveryCapsule (
return EFI_NOT_FOUND;
}
-
/**
Finds the recovery file on a FAT volume.
This function finds the recovery file named FileName on a specified FAT volume and returns
@@ -631,17 +631,18 @@ FindRecoveryFile (
// Construct root directory file
//
ZeroMem (&Parent, sizeof (PEI_FAT_FILE));
- Parent.IsFixedRootDir = (BOOLEAN) ((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
- Parent.Attributes = FAT_ATTR_DIRECTORY;
- Parent.CurrentPos = 0;
- Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
- Parent.StartingCluster = Parent.CurrentCluster;
- Parent.Volume = &PrivateData->Volume[VolumeIndex];
-
- Status = FatSetFilePos (PrivateData, &Parent, 0);
+ Parent.IsFixedRootDir = (BOOLEAN)((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
+ Parent.Attributes = FAT_ATTR_DIRECTORY;
+ Parent.CurrentPos = 0;
+ Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
+ Parent.StartingCluster = Parent.CurrentCluster;
+ Parent.Volume = &PrivateData->Volume[VolumeIndex];
+
+ Status = FatSetFilePos (PrivateData, &Parent, 0);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
+
//
// Search for recovery capsule in root directory
//
@@ -671,5 +672,4 @@ FindRecoveryFile (
*Handle = File;
return EFI_SUCCESS;
-
}
diff --git a/FatPkg/FatPei/FatLiteApi.h b/FatPkg/FatPei/FatLiteApi.h
index 2d03fe17e2..a9025633a0 100644
--- a/FatPkg/FatPei/FatLiteApi.h
+++ b/FatPkg/FatPei/FatLiteApi.h
@@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// API data structures
//
-typedef VOID *PEI_FILE_HANDLE;
+typedef VOID *PEI_FILE_HANDLE;
typedef enum {
Fat12,
diff --git a/FatPkg/FatPei/FatLiteFmt.h b/FatPkg/FatPei/FatLiteFmt.h
index 876874d6b3..fef70fe1de 100644
--- a/FatPkg/FatPei/FatLiteFmt.h
+++ b/FatPkg/FatPei/FatLiteFmt.h
@@ -13,25 +13,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
//
// Definitions
//
-#define FAT_ATTR_READ_ONLY 0x01
-#define FAT_ATTR_HIDDEN 0x02
-#define FAT_ATTR_SYSTEM 0x04
-#define FAT_ATTR_VOLUME_ID 0x08
-#define FAT_ATTR_DIRECTORY 0x10
-#define FAT_ATTR_ARCHIVE 0x20
-#define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
-
-#define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
-#define FAT_CLUSTER_FREE 0
-#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
-#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
-#define FAT_CLUSTER_LAST (-1)
-
-#define DELETE_ENTRY_MARK 0xE5
-#define EMPTY_ENTRY_MARK 0x00
-
-#define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
-#define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
+#define FAT_ATTR_READ_ONLY 0x01
+#define FAT_ATTR_HIDDEN 0x02
+#define FAT_ATTR_SYSTEM 0x04
+#define FAT_ATTR_VOLUME_ID 0x08
+#define FAT_ATTR_DIRECTORY 0x10
+#define FAT_ATTR_ARCHIVE 0x20
+#define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
+
+#define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
+#define FAT_CLUSTER_FREE 0
+#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
+#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
+#define FAT_CLUSTER_LAST (-1)
+
+#define DELETE_ENTRY_MARK 0xE5
+#define EMPTY_ENTRY_MARK 0x00
+
+#define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
+#define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
//
// Directory Entry
@@ -39,33 +39,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#pragma pack(1)
typedef struct {
- UINT16 Day : 5;
- UINT16 Month : 4;
- UINT16 Year : 7; // From 1980
+ UINT16 Day : 5;
+ UINT16 Month : 4;
+ UINT16 Year : 7; // From 1980
} FAT_DATE;
typedef struct {
- UINT16 DoubleSecond : 5;
- UINT16 Minute : 6;
- UINT16 Hour : 5;
+ UINT16 DoubleSecond : 5;
+ UINT16 Minute : 6;
+ UINT16 Hour : 5;
} FAT_TIME;
typedef struct {
- FAT_TIME Time;
- FAT_DATE Date;
+ FAT_TIME Time;
+ FAT_DATE Date;
} FAT_DATE_TIME;
typedef struct {
- CHAR8 FileName[11]; // 8.3 filename
- UINT8 Attributes;
- UINT8 CaseFlag;
- UINT8 CreateMillisecond; // (creation milliseconds - ignored)
- FAT_DATE_TIME FileCreateTime;
- FAT_DATE FileLastAccess;
- UINT16 FileClusterHigh; // >= FAT32
- FAT_DATE_TIME FileModificationTime;
- UINT16 FileCluster;
- UINT32 FileSize;
+ CHAR8 FileName[11]; // 8.3 filename
+ UINT8 Attributes;
+ UINT8 CaseFlag;
+ UINT8 CreateMillisecond; // (creation milliseconds - ignored)
+ FAT_DATE_TIME FileCreateTime;
+ FAT_DATE FileLastAccess;
+ UINT16 FileClusterHigh; // >= FAT32
+ FAT_DATE_TIME FileModificationTime;
+ UINT16 FileCluster;
+ UINT32 FileSize;
} FAT_DIRECTORY_ENTRY;
#pragma pack()
@@ -75,62 +75,58 @@ typedef struct {
#pragma pack(1)
typedef struct {
-
- UINT8 Ia32Jump[3];
- CHAR8 OemId[8];
-
- UINT16 SectorSize;
- UINT8 SectorsPerCluster;
- UINT16 ReservedSectors;
- UINT8 NoFats;
- UINT16 RootEntries; // < FAT32, root dir is fixed size
- UINT16 Sectors;
- UINT8 Media; // (ignored)
- UINT16 SectorsPerFat; // < FAT32
- UINT16 SectorsPerTrack; // (ignored)
- UINT16 Heads; // (ignored)
- UINT32 HiddenSectors; // (ignored)
- UINT32 LargeSectors; // => FAT32
- UINT8 PhysicalDriveNumber; // (ignored)
- UINT8 CurrentHead; // holds boot_sector_dirty bit
- UINT8 Signature; // (ignored)
- CHAR8 Id[4];
- CHAR8 FatLabel[11];
- CHAR8 SystemId[8];
-
+ UINT8 Ia32Jump[3];
+ CHAR8 OemId[8];
+
+ UINT16 SectorSize;
+ UINT8 SectorsPerCluster;
+ UINT16 ReservedSectors;
+ UINT8 NoFats;
+ UINT16 RootEntries; // < FAT32, root dir is fixed size
+ UINT16 Sectors;
+ UINT8 Media; // (ignored)
+ UINT16 SectorsPerFat; // < FAT32
+ UINT16 SectorsPerTrack; // (ignored)
+ UINT16 Heads; // (ignored)
+ UINT32 HiddenSectors; // (ignored)
+ UINT32 LargeSectors; // => FAT32
+ UINT8 PhysicalDriveNumber; // (ignored)
+ UINT8 CurrentHead; // holds boot_sector_dirty bit
+ UINT8 Signature; // (ignored)
+ CHAR8 Id[4];
+ CHAR8 FatLabel[11];
+ CHAR8 SystemId[8];
} PEI_FAT_BOOT_SECTOR;
typedef struct {
-
- UINT8 Ia32Jump[3];
- CHAR8 OemId[8];
-
- UINT16 SectorSize;
- UINT8 SectorsPerCluster;
- UINT16 ReservedSectors;
- UINT8 NoFats;
- UINT16 RootEntries; // < FAT32, root dir is fixed size
- UINT16 Sectors;
- UINT8 Media; // (ignored)
- UINT16 SectorsPerFat; // < FAT32
- UINT16 SectorsPerTrack; // (ignored)
- UINT16 Heads; // (ignored)
- UINT32 HiddenSectors; // (ignored)
- UINT32 LargeSectors; // Used if Sectors==0
- UINT32 LargeSectorsPerFat; // FAT32
- UINT16 ExtendedFlags; // FAT32 (ignored)
- UINT16 FsVersion; // FAT32 (ignored)
- UINT32 RootDirFirstCluster; // FAT32
- UINT16 FsInfoSector; // FAT32
- UINT16 BackupBootSector; // FAT32
- UINT8 Reserved[12]; // FAT32 (ignored)
- UINT8 PhysicalDriveNumber; // (ignored)
- UINT8 CurrentHead; // holds boot_sector_dirty bit
- UINT8 Signature; // (ignored)
- CHAR8 Id[4];
- CHAR8 FatLabel[11];
- CHAR8 SystemId[8];
-
+ UINT8 Ia32Jump[3];
+ CHAR8 OemId[8];
+
+ UINT16 SectorSize;
+ UINT8 SectorsPerCluster;
+ UINT16 ReservedSectors;
+ UINT8 NoFats;
+ UINT16 RootEntries; // < FAT32, root dir is fixed size
+ UINT16 Sectors;
+ UINT8 Media; // (ignored)
+ UINT16 SectorsPerFat; // < FAT32
+ UINT16 SectorsPerTrack; // (ignored)
+ UINT16 Heads; // (ignored)
+ UINT32 HiddenSectors; // (ignored)
+ UINT32 LargeSectors; // Used if Sectors==0
+ UINT32 LargeSectorsPerFat; // FAT32
+ UINT16 ExtendedFlags; // FAT32 (ignored)
+ UINT16 FsVersion; // FAT32 (ignored)
+ UINT32 RootDirFirstCluster; // FAT32
+ UINT16 FsInfoSector; // FAT32
+ UINT16 BackupBootSector; // FAT32
+ UINT8 Reserved[12]; // FAT32 (ignored)
+ UINT8 PhysicalDriveNumber; // (ignored)
+ UINT8 CurrentHead; // holds boot_sector_dirty bit
+ UINT8 Signature; // (ignored)
+ CHAR8 Id[4];
+ CHAR8 FatLabel[11];
+ CHAR8 SystemId[8];
} PEI_FAT_BOOT_SECTOR_EX;
#pragma pack()
diff --git a/FatPkg/FatPei/FatLiteLib.c b/FatPkg/FatPei/FatLiteLib.c
index 3d43e0b877..ef71fe907e 100644
--- a/FatPkg/FatPei/FatLiteLib.c
+++ b/FatPkg/FatPei/FatLiteLib.c
@@ -9,10 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "FatLitePeim.h"
-
#define CHAR_FAT_VALID 0x01
-
/**
Converts a union code character to upper case.
This functions converts a unicode character to upper case.
@@ -26,17 +24,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
CHAR16
ToUpper (
- IN CHAR16 Letter
+ IN CHAR16 Letter
)
{
- if ('a' <= Letter && Letter <= 'z') {
- Letter = (CHAR16) (Letter - 0x20);
+ if (('a' <= Letter) && (Letter <= 'z')) {
+ Letter = (CHAR16)(Letter - 0x20);
}
return Letter;
}
-
/**
Reads a block of data from the block device by calling
underlying Block I/O service.
@@ -55,11 +52,11 @@ ToUpper (
**/
EFI_STATUS
FatReadBlock (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN BlockDeviceNo,
- IN EFI_PEI_LBA Lba,
- IN UINTN BufferSize,
- OUT VOID *Buffer
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN BlockDeviceNo,
+ IN EFI_PEI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
)
{
EFI_STATUS Status;
@@ -69,8 +66,8 @@ FatReadBlock (
return EFI_DEVICE_ERROR;
}
- Status = EFI_SUCCESS;
- BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);
+ Status = EFI_SUCCESS;
+ BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);
if (BufferSize > MultU64x32 (BlockDev->LastBlock - Lba + 1, BlockDev->BlockSize)) {
return EFI_DEVICE_ERROR;
@@ -83,38 +80,36 @@ FatReadBlock (
//
if (BlockDev->BlockIo2 != NULL) {
Status = BlockDev->BlockIo2->ReadBlocks (
- (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
- BlockDev->BlockIo2,
+ (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
+ BlockDev->BlockIo2,
+ BlockDev->PhysicalDevNo,
+ Lba,
+ BufferSize,
+ Buffer
+ );
+ } else {
+ Status = BlockDev->BlockIo->ReadBlocks (
+ (EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
+ BlockDev->BlockIo,
BlockDev->PhysicalDevNo,
Lba,
BufferSize,
Buffer
);
- } else {
- Status = BlockDev->BlockIo->ReadBlocks (
- (EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
- BlockDev->BlockIo,
- BlockDev->PhysicalDevNo,
- Lba,
- BufferSize,
- Buffer
- );
}
-
} else {
Status = FatReadDisk (
- PrivateData,
- BlockDev->ParentDevNo,
- BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),
- BufferSize,
- Buffer
- );
+ PrivateData,
+ BlockDev->ParentDevNo,
+ BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),
+ BufferSize,
+ Buffer
+ );
}
return Status;
}
-
/**
Find a cache block designated to specific Block device and Lba.
If not found, invalidate an oldest one and use it. (LRU cache)
@@ -150,15 +145,16 @@ FatGetCacheBlock (
//
for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
- if (CacheBuffer->Valid && CacheBuffer->BlockDeviceNo == BlockDeviceNo && CacheBuffer->Lba == Lba) {
+ if (CacheBuffer->Valid && (CacheBuffer->BlockDeviceNo == BlockDeviceNo) && (CacheBuffer->Lba == Lba)) {
break;
}
}
if (Index < PEI_FAT_CACHE_SIZE) {
- *CachePtr = (CHAR8 *) CacheBuffer->Buffer;
+ *CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return EFI_SUCCESS;
}
+
//
// We have to find an invalid cache buffer
//
@@ -167,6 +163,7 @@ FatGetCacheBlock (
break;
}
}
+
//
// Use the cache buffer
//
@@ -181,33 +178,32 @@ FatGetCacheBlock (
return EFI_DEVICE_ERROR;
}
- CacheBuffer = &(PrivateData->CacheBuffer[Index]);
+ CacheBuffer = &(PrivateData->CacheBuffer[Index]);
- CacheBuffer->BlockDeviceNo = BlockDeviceNo;
- CacheBuffer->Lba = Lba;
- CacheBuffer->Size = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;
+ CacheBuffer->BlockDeviceNo = BlockDeviceNo;
+ CacheBuffer->Lba = Lba;
+ CacheBuffer->Size = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;
//
// Read in the data
//
Status = FatReadBlock (
- PrivateData,
- BlockDeviceNo,
- Lba,
- CacheBuffer->Size,
- CacheBuffer->Buffer
- );
+ PrivateData,
+ BlockDeviceNo,
+ Lba,
+ CacheBuffer->Size,
+ CacheBuffer->Buffer
+ );
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
- CacheBuffer->Valid = TRUE;
- *CachePtr = (CHAR8 *) CacheBuffer->Buffer;
+ CacheBuffer->Valid = TRUE;
+ *CachePtr = (CHAR8 *)CacheBuffer->Buffer;
return Status;
}
-
/**
Disk reading.
@@ -246,8 +242,8 @@ FatReadDisk (
//
// Read underrun
//
- Lba = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);
- Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);
+ Lba = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);
+ Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
}
@@ -259,17 +255,17 @@ FatReadDisk (
return EFI_SUCCESS;
}
- Size -= Amount;
- BufferPtr += Amount;
+ Size -= Amount;
+ BufferPtr += Amount;
StartingAddress += Amount;
- Lba += 1;
+ Lba += 1;
//
// Read aligned parts
//
OverRunLba = Lba + DivU64x32Remainder (Size, BlockSize, &Offset);
- Size -= Offset;
+ Size -= Offset;
Status = FatReadBlock (PrivateData, BlockDeviceNo, Lba, Size, BufferPtr);
if (EFI_ERROR (Status)) {
return EFI_DEVICE_ERROR;
@@ -292,7 +288,6 @@ FatReadDisk (
return Status;
}
-
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@@ -310,9 +305,9 @@ FatReadDisk (
**/
VOID
EngFatToStr (
- IN UINTN FatSize,
- IN CHAR8 *Fat,
- OUT CHAR16 *Str
+ IN UINTN FatSize,
+ IN CHAR8 *Fat,
+ OUT CHAR16 *Str
)
{
CHAR16 *String;
@@ -325,16 +320,16 @@ EngFatToStr (
if (*Fat == ' ') {
break;
}
- *String = *Fat;
- String += 1;
- Fat += 1;
+
+ *String = *Fat;
+ String += 1;
+ Fat += 1;
FatSize -= 1;
}
*String = 0;
}
-
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@@ -366,5 +361,5 @@ EngStriColl (
UpperS2 = ToUpper (*Str2);
}
- return (BOOLEAN) ((*Str2 != 0) ? FALSE : TRUE);
+ return (BOOLEAN)((*Str2 != 0) ? FALSE : TRUE);
}
diff --git a/FatPkg/FatPei/FatLitePeim.h b/FatPkg/FatPei/FatLitePeim.h
index 0c3c69853c..1f90ef885d 100644
--- a/FatPkg/FatPei/FatLitePeim.h
+++ b/FatPkg/FatPei/FatLitePeim.h
@@ -33,14 +33,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Definitions
//
-#define PEI_FAT_CACHE_SIZE 4
-#define PEI_FAT_MAX_BLOCK_SIZE 8192
-#define FAT_MAX_FILE_NAME_LENGTH 128
-#define PEI_FAT_MAX_BLOCK_DEVICE 64
-#define PEI_FAT_MAX_BLOCK_IO_PPI 32
-#define PEI_FAT_MAX_VOLUME 64
+#define PEI_FAT_CACHE_SIZE 4
+#define PEI_FAT_MAX_BLOCK_SIZE 8192
+#define FAT_MAX_FILE_NAME_LENGTH 128
+#define PEI_FAT_MAX_BLOCK_DEVICE 64
+#define PEI_FAT_MAX_BLOCK_IO_PPI 32
+#define PEI_FAT_MAX_VOLUME 64
-#define PEI_FAT_MEMORY_PAGE_SIZE 0x1000
+#define PEI_FAT_MEMORY_PAGE_SIZE 0x1000
//
// Data Structures
@@ -49,86 +49,79 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// The block device
//
typedef struct {
-
- UINT32 BlockSize;
- UINT64 LastBlock;
- UINT32 IoAlign;
- BOOLEAN Logical;
- BOOLEAN PartitionChecked;
+ UINT32 BlockSize;
+ UINT64 LastBlock;
+ UINT32 IoAlign;
+ BOOLEAN Logical;
+ BOOLEAN PartitionChecked;
//
// Following fields only valid for logical device
//
- CHAR8 PartitionFlag[8];
- UINT64 StartingPos;
- UINTN ParentDevNo;
+ CHAR8 PartitionFlag[8];
+ UINT64 StartingPos;
+ UINTN ParentDevNo;
//
// Following fields only valid for physical device
//
- EFI_PEI_BLOCK_DEVICE_TYPE DevType;
- UINT8 InterfaceType;
+ EFI_PEI_BLOCK_DEVICE_TYPE DevType;
+ UINT8 InterfaceType;
//
// EFI_PEI_READ_BLOCKS ReadFunc;
//
- EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
- EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
- UINT8 PhysicalDevNo;
+ EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
+ EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
+ UINT8 PhysicalDevNo;
} PEI_FAT_BLOCK_DEVICE;
//
// the Volume structure
//
typedef struct {
-
- UINTN BlockDeviceNo;
- UINTN VolumeNo;
- UINT64 VolumeSize;
- UINTN MaxCluster;
- CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
- PEI_FAT_TYPE FatType;
- UINT64 FatPos;
- UINT32 SectorSize;
- UINT32 ClusterSize;
- UINT64 FirstClusterPos;
- UINT64 RootDirPos;
- UINT32 RootEntries;
- UINT32 RootDirCluster;
-
+ UINTN BlockDeviceNo;
+ UINTN VolumeNo;
+ UINT64 VolumeSize;
+ UINTN MaxCluster;
+ CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
+ PEI_FAT_TYPE FatType;
+ UINT64 FatPos;
+ UINT32 SectorSize;
+ UINT32 ClusterSize;
+ UINT64 FirstClusterPos;
+ UINT64 RootDirPos;
+ UINT32 RootEntries;
+ UINT32 RootDirCluster;
} PEI_FAT_VOLUME;
//
// File instance
//
typedef struct {
+ PEI_FAT_VOLUME *Volume;
+ CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
- PEI_FAT_VOLUME *Volume;
- CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
-
- BOOLEAN IsFixedRootDir;
+ BOOLEAN IsFixedRootDir;
- UINT32 StartingCluster;
- UINT32 CurrentPos;
- UINT32 StraightReadAmount;
- UINT32 CurrentCluster;
-
- UINT8 Attributes;
- UINT32 FileSize;
+ UINT32 StartingCluster;
+ UINT32 CurrentPos;
+ UINT32 StraightReadAmount;
+ UINT32 CurrentCluster;
+ UINT8 Attributes;
+ UINT32 FileSize;
} PEI_FAT_FILE;
//
// Cache Buffer
//
typedef struct {
-
- BOOLEAN Valid;
- UINTN BlockDeviceNo;
- UINT64 Lba;
- UINT32 Lru;
- UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
- UINTN Size;
-
+ BOOLEAN Valid;
+ UINTN BlockDeviceNo;
+ UINT64 Lba;
+ UINT32 Lru;
+ UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
+ UINTN Size;
} PEI_FAT_CACHE_BUFFER;
//
@@ -142,25 +135,23 @@ typedef struct {
#define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
typedef struct {
-
- UINTN Signature;
- EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
- EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
- EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
-
- UINT8 UnicodeCaseMap[0x300];
- CHAR8 *EngUpperMap;
- CHAR8 *EngLowerMap;
- CHAR8 *EngInfoMap;
-
- UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
- UINTN BlockDeviceCount;
- PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
- UINTN VolumeCount;
- PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
- PEI_FAT_FILE File;
- PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
-
+ UINTN Signature;
+ EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
+ EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
+ EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
+
+ UINT8 UnicodeCaseMap[0x300];
+ CHAR8 *EngUpperMap;
+ CHAR8 *EngLowerMap;
+ CHAR8 *EngInfoMap;
+
+ UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
+ UINTN BlockDeviceCount;
+ PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
+ UINTN VolumeCount;
+ PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
+ PEI_FAT_FILE File;
+ PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
} PEI_FAT_PRIVATE_DATA;
#define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
@@ -178,7 +169,6 @@ typedef struct {
#define UNPACK_UINT32(a) \
(UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
-
//
// API functions
//
@@ -209,7 +199,6 @@ FindRecoveryFile (
OUT PEI_FILE_HANDLE *Handle
);
-
/**
Returns the number of DXE capsules residing on the device.
This function, by whatever mechanism, searches for DXE capsules from the associated device and
@@ -231,12 +220,11 @@ FindRecoveryFile (
EFI_STATUS
EFIAPI
GetNumberRecoveryCapsules (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- OUT UINTN *NumberRecoveryCapsules
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ OUT UINTN *NumberRecoveryCapsules
);
-
/**
Returns the size and type of the requested recovery capsule.
This function returns the size and type of the capsule specified by CapsuleInstance.
@@ -267,14 +255,13 @@ GetNumberRecoveryCapsules (
EFI_STATUS
EFIAPI
GetRecoveryCapsuleInfo (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT UINTN *Size,
- OUT EFI_GUID *CapsuleType
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT UINTN *Size,
+ OUT EFI_GUID *CapsuleType
);
-
/**
Loads a DXE capsule from some media into memory.
@@ -297,13 +284,12 @@ GetRecoveryCapsuleInfo (
EFI_STATUS
EFIAPI
LoadRecoveryCapsule (
- IN EFI_PEI_SERVICES **PeiServices,
- IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
- IN UINTN CapsuleInstance,
- OUT VOID *Buffer
+ IN EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
+ IN UINTN CapsuleInstance,
+ OUT VOID *Buffer
);
-
/**
This version is different from the version in Unicode collation
protocol in that this version strips off trailing blanks.
@@ -321,12 +307,11 @@ LoadRecoveryCapsule (
**/
VOID
EngFatToStr (
- IN UINTN FatSize,
- IN CHAR8 *Fat,
- OUT CHAR16 *Str
+ IN UINTN FatSize,
+ IN CHAR8 *Fat,
+ OUT CHAR16 *Str
);
-
/**
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
@@ -342,7 +327,6 @@ EngStriColl (
IN CHAR16 *Str2
);
-
/**
Reads a block of data from the block device by calling
underlying Block I/O service.
@@ -361,14 +345,13 @@ EngStriColl (
**/
EFI_STATUS
FatReadBlock (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN BlockDeviceNo,
- IN EFI_PEI_LBA Lba,
- IN UINTN BufferSize,
- OUT VOID *Buffer
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN BlockDeviceNo,
+ IN EFI_PEI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
);
-
/**
Check if there is a valid FAT in the corresponding Block device
of the volume and if yes, fill in the relevant fields for the
@@ -394,7 +377,6 @@ FatGetBpbInfo (
IN OUT PEI_FAT_VOLUME *Volume
);
-
/**
Gets the next cluster in the cluster chain.
@@ -416,7 +398,6 @@ FatGetNextCluster (
OUT UINT32 *NextCluster
);
-
/**
Disk reading.
@@ -439,7 +420,6 @@ FatReadDisk (
OUT VOID *Buffer
);
-
/**
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
@@ -460,7 +440,6 @@ FatSetFilePos (
IN UINT32 Pos
);
-
/**
Reads file data. Updates the file's CurrentPos.
@@ -482,7 +461,6 @@ FatReadFile (
OUT VOID *Buffer
);
-
/**
This function reads the next item in the parent directory and
initializes the output parameter SubFile (CurrentPos is initialized to 0).
@@ -507,7 +485,6 @@ FatReadNextDirectoryEntry (
OUT PEI_FAT_FILE *SubFile
);
-
/**
This function finds partitions (logical devices) in physical block devices.
diff --git a/FatPkg/FatPei/Gpt.c b/FatPkg/FatPei/Gpt.c
index 4028c535f3..0a1a25ceef 100644
--- a/FatPkg/FatPei/Gpt.c
+++ b/FatPkg/FatPei/Gpt.c
@@ -23,9 +23,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// GPT Partition Entry Status
//
typedef struct {
- BOOLEAN OutOfRange;
- BOOLEAN Overlap;
- BOOLEAN OsSpecific;
+ BOOLEAN OutOfRange;
+ BOOLEAN Overlap;
+ BOOLEAN OsSpecific;
} EFI_PARTITION_ENTRY_STATUS;
/**
@@ -42,8 +42,8 @@ PartitionCheckGptHeaderCRC (
IN EFI_PARTITION_TABLE_HEADER *PartHeader
)
{
- UINT32 GptHdrCrc;
- UINT32 Crc;
+ UINT32 GptHdrCrc;
+ UINT32 Crc;
GptHdrCrc = PartHeader->Header.CRC32;
@@ -62,7 +62,6 @@ PartitionCheckGptHeaderCRC (
return (GptHdrCrc == Crc);
}
-
/**
Check if the CRC field in the Partition table header is valid
for Partition entry array.
@@ -76,17 +75,17 @@ PartitionCheckGptHeaderCRC (
**/
BOOLEAN
PartitionCheckGptEntryArrayCRC (
- IN EFI_PARTITION_TABLE_HEADER *PartHeader,
- IN EFI_PARTITION_ENTRY *PartEntry
+ IN EFI_PARTITION_TABLE_HEADER *PartHeader,
+ IN EFI_PARTITION_ENTRY *PartEntry
)
{
- UINT32 Crc;
- UINTN Size;
+ UINT32 Crc;
+ UINTN Size;
- Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
+ Size = (UINTN)MultU64x32 (PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
Crc = CalculateCrc32 (PartEntry, Size);
- return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
+ return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc);
}
/**
@@ -109,14 +108,14 @@ PartitionCheckGptHeader (
IN EFI_PARTITION_TABLE_HEADER *PartHdr
)
{
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- EFI_PEI_LBA Lba;
- EFI_PEI_LBA AlternateLba;
- EFI_PEI_LBA EntryArrayLastLba;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ EFI_PEI_LBA Lba;
+ EFI_PEI_LBA AlternateLba;
+ EFI_PEI_LBA EntryArrayLastLba;
- UINT64 PartitionEntryArraySize;
- UINT64 PartitionEntryBlockNumb;
- UINT32 EntryArraySizeRemainder;
+ UINT64 PartitionEntryArraySize;
+ UINT64 PartitionEntryBlockNumb;
+ UINT32 EntryArraySizeRemainder;
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
@@ -128,13 +127,14 @@ PartitionCheckGptHeader (
AlternateLba = PRIMARY_PART_HEADER_LBA;
}
- if ( (PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
- (PartHdr->Header.Revision != 0x00010000) ||
- (PartHdr->Header.HeaderSize < 92) ||
- (PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
- (!PartitionCheckGptHeaderCRC (PartHdr)) ||
- (PartHdr->Header.Reserved != 0)
- ) {
+ if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
+ (PartHdr->Header.Revision != 0x00010000) ||
+ (PartHdr->Header.HeaderSize < 92) ||
+ (PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
+ (!PartitionCheckGptHeaderCRC (PartHdr)) ||
+ (PartHdr->Header.Reserved != 0)
+ )
+ {
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@@ -150,17 +150,18 @@ PartitionCheckGptHeader (
// 5. Must be remain 128*128 bytes for backup entry array.
// 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
//
- if ( (PartHdr->MyLBA != Lba) ||
- (PartHdr->AlternateLBA != AlternateLba) ||
- (PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
- (PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
- (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
- (PartHdr->PartitionEntryLBA < 2) ||
- (PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
- (PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA && PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA) ||
- (PartHdr->SizeOfPartitionEntry%128 != 0) ||
- (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
- ) {
+ if ((PartHdr->MyLBA != Lba) ||
+ (PartHdr->AlternateLBA != AlternateLba) ||
+ (PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
+ (PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
+ (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
+ (PartHdr->PartitionEntryLBA < 2) ||
+ (PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
+ ((PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA) && (PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA)) ||
+ (PartHdr->SizeOfPartitionEntry%128 != 0) ||
+ (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
+ )
+ {
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
return FALSE;
}
@@ -219,30 +220,30 @@ PartitionCheckGptEntryArray (
IN EFI_PARTITION_TABLE_HEADER *PartHdr
)
{
- EFI_STATUS Status;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
+ EFI_STATUS Status;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
- UINT64 PartitionEntryArraySize;
- UINT64 PartitionEntryBlockNumb;
- UINT32 EntryArraySizeRemainder;
+ UINT64 PartitionEntryArraySize;
+ UINT64 PartitionEntryBlockNumb;
+ UINT32 EntryArraySizeRemainder;
- EFI_PARTITION_ENTRY *PartitionEntryBuffer;
- EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
+ EFI_PARTITION_ENTRY *PartitionEntryBuffer;
+ EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
- BOOLEAN Found;
- EFI_LBA StartingLBA;
- EFI_LBA EndingLBA;
- UINTN Index;
- UINTN Index1;
- UINTN Index2;
- EFI_PARTITION_ENTRY *Entry;
+ BOOLEAN Found;
+ EFI_LBA StartingLBA;
+ EFI_LBA EndingLBA;
+ UINTN Index;
+ UINTN Index1;
+ UINTN Index2;
+ EFI_PARTITION_ENTRY *Entry;
PartitionEntryBuffer = NULL;
PartitionEntryStatus = NULL;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
- Found = FALSE;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ Found = FALSE;
PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
EntryArraySizeRemainder = 0;
@@ -250,19 +251,21 @@ PartitionCheckGptEntryArray (
if (EntryArraySizeRemainder != 0) {
PartitionEntryBlockNumb++;
}
+
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
- PartitionEntryBuffer = (EFI_PARTITION_ENTRY *) AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
+ PartitionEntryBuffer = (EFI_PARTITION_ENTRY *)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
if (PartitionEntryBuffer == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
- PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *) AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
+ PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *)AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
if (PartitionEntryStatus == NULL) {
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
goto EXIT;
}
+
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
Status = FatReadBlock (
@@ -283,19 +286,20 @@ PartitionCheckGptEntryArray (
}
for (Index1 = 0; Index1 < PartHdr->NumberOfPartitionEntries; Index1++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
StartingLBA = Entry->StartingLBA;
EndingLBA = Entry->EndingLBA;
- if (StartingLBA > EndingLBA ||
- StartingLBA < PartHdr->FirstUsableLBA ||
- StartingLBA > PartHdr->LastUsableLBA ||
- EndingLBA < PartHdr->FirstUsableLBA ||
- EndingLBA > PartHdr->LastUsableLBA
- ) {
+ if ((StartingLBA > EndingLBA) ||
+ (StartingLBA < PartHdr->FirstUsableLBA) ||
+ (StartingLBA > PartHdr->LastUsableLBA) ||
+ (EndingLBA < PartHdr->FirstUsableLBA) ||
+ (EndingLBA > PartHdr->LastUsableLBA)
+ )
+ {
PartitionEntryStatus[Index1].OutOfRange = TRUE;
continue;
}
@@ -308,27 +312,28 @@ PartitionCheckGptEntryArray (
}
for (Index2 = Index1 + 1; Index2 < PartHdr->NumberOfPartitionEntries; Index2++) {
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
continue;
}
- if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {
+ if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
- PartitionEntryStatus[Index1].Overlap = TRUE;
- PartitionEntryStatus[Index2].Overlap = TRUE;
+ PartitionEntryStatus[Index1].Overlap = TRUE;
+ PartitionEntryStatus[Index2].Overlap = TRUE;
continue;
}
}
}
for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
- if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)||
+ if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
PartitionEntryStatus[Index].OutOfRange ||
PartitionEntryStatus[Index].Overlap ||
- PartitionEntryStatus[Index].OsSpecific) {
+ PartitionEntryStatus[Index].OsSpecific)
+ {
//
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
// partition Entries
@@ -340,8 +345,8 @@ PartitionCheckGptEntryArray (
break;
}
- Found = TRUE;
- BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
+ Found = TRUE;
+ BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
BlockDevPtr->BlockSize = ParentBlockDev->BlockSize;
BlockDevPtr->LastBlock = PartitionEntryBuffer[Index].EndingLBA;
@@ -352,13 +357,13 @@ PartitionCheckGptEntryArray (
PartitionEntryBuffer[Index].StartingLBA,
ParentBlockDev->BlockSize
);
- BlockDevPtr->ParentDevNo = ParentBlockDevNo;
+ BlockDevPtr->ParentDevNo = ParentBlockDevNo;
PrivateData->BlockDeviceCount++;
- DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
+ DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
DEBUG ((DEBUG_INFO, ", 0x%lx]\n", BlockDevPtr->LastBlock));
- DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
+ DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
}
EXIT:
@@ -390,18 +395,18 @@ EXIT:
**/
BOOLEAN
PartitionCheckGptStructure (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo,
- IN BOOLEAN IsPrimary
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo,
+ IN BOOLEAN IsPrimary
)
{
- EFI_STATUS Status;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- EFI_PARTITION_TABLE_HEADER *PartHdr;
- EFI_PEI_LBA GptHeaderLBA;
+ EFI_STATUS Status;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ EFI_PARTITION_TABLE_HEADER *PartHdr;
+ EFI_PEI_LBA GptHeaderLBA;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
- PartHdr = (EFI_PARTITION_TABLE_HEADER *) PrivateData->BlockData;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ PartHdr = (EFI_PARTITION_TABLE_HEADER *)PrivateData->BlockData;
if (IsPrimary) {
GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
@@ -442,18 +447,18 @@ PartitionCheckGptStructure (
**/
BOOLEAN
PartitionCheckProtectiveMbr (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
- EFI_STATUS Status;
- MASTER_BOOT_RECORD *ProtectiveMbr;
- MBR_PARTITION_RECORD *MbrPartition;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
- UINTN Index;
+ EFI_STATUS Status;
+ MASTER_BOOT_RECORD *ProtectiveMbr;
+ MBR_PARTITION_RECORD *MbrPartition;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ UINTN Index;
- ProtectiveMbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ ProtectiveMbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
//
// Read Protective MBR
@@ -482,11 +487,12 @@ PartitionCheckProtectiveMbr (
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
- if (MbrPartition->BootIndicator == 0x00 &&
- MbrPartition->StartSector == 0x02 &&
- MbrPartition->OSIndicator == PMBR_GPT_PARTITION &&
- UNPACK_UINT32 (MbrPartition->StartingLBA) == 1
- ) {
+ if ((MbrPartition->BootIndicator == 0x00) &&
+ (MbrPartition->StartSector == 0x02) &&
+ (MbrPartition->OSIndicator == PMBR_GPT_PARTITION) &&
+ (UNPACK_UINT32 (MbrPartition->StartingLBA) == 1)
+ )
+ {
return TRUE;
}
}
@@ -510,18 +516,18 @@ PartitionCheckProtectiveMbr (
**/
BOOLEAN
FatFindGptPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
- BOOLEAN Found;
- PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
+ BOOLEAN Found;
+ PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
return FALSE;
}
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceed FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
return FALSE;
diff --git a/FatPkg/FatPei/Mbr.c b/FatPkg/FatPei/Mbr.c
index 78e73fb811..0a6f1f505c 100644
--- a/FatPkg/FatPei/Mbr.c
+++ b/FatPkg/FatPei/Mbr.c
@@ -23,26 +23,27 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
PartitionValidMbr (
- IN MASTER_BOOT_RECORD *Mbr,
- IN EFI_PEI_LBA LastLba
+ IN MASTER_BOOT_RECORD *Mbr,
+ IN EFI_PEI_LBA LastLba
)
{
- UINT32 StartingLBA;
- UINT32 EndingLBA;
- UINT32 NewEndingLBA;
- INTN Index1;
- INTN Index2;
- BOOLEAN MbrValid;
+ UINT32 StartingLBA;
+ UINT32 EndingLBA;
+ UINT32 NewEndingLBA;
+ INTN Index1;
+ INTN Index2;
+ BOOLEAN MbrValid;
if (Mbr->Signature != MBR_SIGNATURE) {
return FALSE;
}
+
//
// The BPB also has this signature, so it can not be used alone.
//
MbrValid = FALSE;
for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) {
- if (Mbr->Partition[Index1].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index1].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0)) {
continue;
}
@@ -65,12 +66,12 @@ PartitionValidMbr (
}
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {
- if (Mbr->Partition[Index2].OSIndicator == 0x00 || UNPACK_INT32 (Mbr->Partition[Index2].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index2].OSIndicator == 0x00) || (UNPACK_INT32 (Mbr->Partition[Index2].SizeInLBA) == 0)) {
continue;
}
NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1;
- if (NewEndingLBA >= StartingLBA && UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA) {
+ if ((NewEndingLBA >= StartingLBA) && (UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
@@ -78,6 +79,7 @@ PartitionValidMbr (
}
}
}
+
//
// Non of the regions overlapped so MBR is O.K.
//
@@ -98,8 +100,8 @@ PartitionValidMbr (
**/
BOOLEAN
FatFindMbrPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
)
{
EFI_STATUS Status;
@@ -113,55 +115,56 @@ FatFindMbrPartitions (
return FALSE;
}
- ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
+ ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
- DEBUG((DEBUG_ERROR, "Device BlockSize %x exceeds FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
+ DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceeds FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
return FALSE;
}
- Found = FALSE;
- Mbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
+ Found = FALSE;
+ Mbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
Status = FatReadBlock (
- PrivateData,
- ParentBlockDevNo,
- 0,
- ParentBlockDev->BlockSize,
- Mbr
- );
+ PrivateData,
+ ParentBlockDevNo,
+ 0,
+ ParentBlockDev->BlockSize,
+ Mbr
+ );
if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev->LastBlock)) {
goto Done;
}
+
//
// We have a valid mbr - add each partition
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
- if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index].OSIndicator == 0x00) || (UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) == 0)) {
//
// Don't use null MBR entries
//
continue;
}
+
//
// Register this partition
//
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
-
- Found = TRUE;
-
- BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
-
- BlockDev->BlockSize = MBR_SIZE;
- BlockDev->LastBlock = UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) - 1;
- BlockDev->IoAlign = ParentBlockDev->IoAlign;
- BlockDev->Logical = TRUE;
- BlockDev->PartitionChecked = FALSE;
- BlockDev->StartingPos = MultU64x32 (
- UNPACK_INT32 (Mbr->Partition[Index].StartingLBA),
- ParentBlockDev->BlockSize
- );
+ Found = TRUE;
+
+ BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
+
+ BlockDev->BlockSize = MBR_SIZE;
+ BlockDev->LastBlock = UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) - 1;
+ BlockDev->IoAlign = ParentBlockDev->IoAlign;
+ BlockDev->Logical = TRUE;
+ BlockDev->PartitionChecked = FALSE;
+ BlockDev->StartingPos = MultU64x32 (
+ UNPACK_INT32 (Mbr->Partition[Index].StartingLBA),
+ ParentBlockDev->BlockSize
+ );
BlockDev->ParentDevNo = ParentBlockDevNo;
PrivateData->BlockDeviceCount++;
diff --git a/FatPkg/FatPei/Part.c b/FatPkg/FatPei/Part.c
index 3e2ded31cc..10d51f9397 100644
--- a/FatPkg/FatPei/Part.c
+++ b/FatPkg/FatPei/Part.c
@@ -24,8 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
FatFindEltoritoPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
);
/**
@@ -42,8 +42,8 @@ FatFindEltoritoPartitions (
**/
BOOLEAN
FatFindMbrPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
);
/**
@@ -61,8 +61,8 @@ FatFindMbrPartitions (
**/
BOOLEAN
FatFindGptPartitions (
- IN PEI_FAT_PRIVATE_DATA *PrivateData,
- IN UINTN ParentBlockDevNo
+ IN PEI_FAT_PRIVATE_DATA *PrivateData,
+ IN UINTN ParentBlockDevNo
);
/**
@@ -76,8 +76,8 @@ FatFindPartitions (
IN PEI_FAT_PRIVATE_DATA *PrivateData
)
{
- BOOLEAN Found;
- UINTN Index;
+ BOOLEAN Found;
+ UINTN Index;
do {
Found = FALSE;