FatPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the FatPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
committed by
mergify[bot]
parent
a550d468a6
commit
bcdcc4160d
@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
//
|
//
|
||||||
// EFI Component Name Functions
|
// EFI Component Name Functions
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrieves a Unicode string that is the user readable name of the driver.
|
Retrieves a Unicode string that is the user readable name of the driver.
|
||||||
|
|
||||||
@ -58,7 +59,6 @@ FatComponentNameGetDriverName (
|
|||||||
OUT CHAR16 **DriverName
|
OUT CHAR16 **DriverName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrieves a Unicode string that is the user readable name of the controller
|
Retrieves a Unicode string that is the user readable name of the controller
|
||||||
that is being managed by a driver.
|
that is being managed by a driver.
|
||||||
@ -150,8 +150,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gFatComponentName = {
|
|||||||
// EFI Component Name 2 Protocol
|
// EFI Component Name 2 Protocol
|
||||||
//
|
//
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2 = {
|
GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2 = {
|
||||||
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME) FatComponentNameGetDriverName,
|
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)FatComponentNameGetDriverName,
|
||||||
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) FatComponentNameGetControllerName,
|
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)FatComponentNameGetControllerName,
|
||||||
"en"
|
"en"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -177,7 +177,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[]
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrieves a Unicode string that is the user readable name of the driver.
|
Retrieves a Unicode string that is the user readable name of the driver.
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ FatDelete (
|
|||||||
Status = EFI_WRITE_PROTECTED;
|
Status = EFI_WRITE_PROTECTED;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the file is the root dir, then don't delete it
|
// If the file is the root dir, then don't delete it
|
||||||
//
|
//
|
||||||
@ -55,6 +56,7 @@ FatDelete (
|
|||||||
Status = EFI_ACCESS_DENIED;
|
Status = EFI_ACCESS_DENIED;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the file has a permanent error, skip the delete
|
// If the file has a permanent error, skip the delete
|
||||||
//
|
//
|
||||||
@ -72,14 +74,16 @@ FatDelete (
|
|||||||
for (Round = 0; Round < 3; Round++) {
|
for (Round = 0; Round < 3; Round++) {
|
||||||
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
||||||
if ((EFI_ERROR (Status)) ||
|
if ((EFI_ERROR (Status)) ||
|
||||||
((Round < 2) && (DirEnt == NULL || !FatIsDotDirEnt (DirEnt))) ||
|
((Round < 2) && ((DirEnt == NULL) || !FatIsDotDirEnt (DirEnt))) ||
|
||||||
((Round == 2) && (DirEnt != NULL))
|
((Round == 2) && (DirEnt != NULL))
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
Status = EFI_ACCESS_DENIED;
|
Status = EFI_ACCESS_DENIED;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Return the file's space by setting its size to 0
|
// Return the file's space by setting its size to 0
|
||||||
//
|
//
|
||||||
@ -91,6 +95,7 @@ FatDelete (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set a permanent error for this OFile in case there
|
// Set a permanent error for this OFile in case there
|
||||||
// are still opened IFiles attached
|
// are still opened IFiles attached
|
||||||
|
@ -107,6 +107,7 @@ FatDiscardODir (
|
|||||||
ODir = NULL;
|
ODir = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Release ODir Structure
|
// Release ODir Structure
|
||||||
//
|
//
|
||||||
@ -142,7 +143,8 @@ FatRequestODir (
|
|||||||
for (CurrentODirLink = Volume->DirCacheList.ForwardLink;
|
for (CurrentODirLink = Volume->DirCacheList.ForwardLink;
|
||||||
CurrentODirLink != &Volume->DirCacheList;
|
CurrentODirLink != &Volume->DirCacheList;
|
||||||
CurrentODirLink = CurrentODirLink->ForwardLink
|
CurrentODirLink = CurrentODirLink->ForwardLink
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
CurrentODir = ODIR_FROM_DIRCACHELINK (CurrentODirLink);
|
CurrentODir = ODIR_FROM_DIRCACHELINK (CurrentODirLink);
|
||||||
if (CurrentODir->DirCacheTag == DirCacheTag) {
|
if (CurrentODir->DirCacheTag == DirCacheTag) {
|
||||||
RemoveEntryList (&CurrentODir->DirCacheLink);
|
RemoveEntryList (&CurrentODir->DirCacheLink);
|
||||||
@ -175,6 +177,7 @@ FatCleanupODirCache (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
|
|
||||||
while (Volume->DirCacheCount > 0) {
|
while (Volume->DirCacheCount > 0) {
|
||||||
ODir = ODIR_FROM_DIRCACHELINK (Volume->DirCacheList.BackLink);
|
ODir = ODIR_FROM_DIRCACHELINK (Volume->DirCacheList.BackLink);
|
||||||
RemoveEntryList (&ODir->DirCacheLink);
|
RemoveEntryList (&ODir->DirCacheLink);
|
||||||
|
@ -39,8 +39,8 @@ FatAccessEntry (
|
|||||||
// End of directory
|
// End of directory
|
||||||
//
|
//
|
||||||
ASSERT (IoMode == ReadData);
|
ASSERT (IoMode == ReadData);
|
||||||
((FAT_DIRECTORY_ENTRY *) Entry)->FileName[0] = EMPTY_ENTRY_MARK;
|
((FAT_DIRECTORY_ENTRY *)Entry)->FileName[0] = EMPTY_ENTRY_MARK;
|
||||||
((FAT_DIRECTORY_ENTRY *) Entry)->Attributes = 0;
|
((FAT_DIRECTORY_ENTRY *)Entry)->Attributes = 0;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +145,9 @@ FatIsDotDirEnt (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 *FileString;
|
CHAR16 *FileString;
|
||||||
|
|
||||||
FileString = DirEnt->FileString;
|
FileString = DirEnt->FileString;
|
||||||
if (StrCmp (FileString, L".") == 0 || StrCmp (FileString, L"..") == 0) {
|
if ((StrCmp (FileString, L".") == 0) || (StrCmp (FileString, L"..") == 0)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,8 +172,8 @@ FatSetDirEntCluster (
|
|||||||
|
|
||||||
DirEnt = OFile->DirEnt;
|
DirEnt = OFile->DirEnt;
|
||||||
Cluster = OFile->FileCluster;
|
Cluster = OFile->FileCluster;
|
||||||
DirEnt->Entry.FileClusterHigh = (UINT16) (Cluster >> 16);
|
DirEnt->Entry.FileClusterHigh = (UINT16)(Cluster >> 16);
|
||||||
DirEnt->Entry.FileCluster = (UINT16) Cluster;
|
DirEnt->Entry.FileCluster = (UINT16)Cluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,7 +189,7 @@ FatUpdateDirEntClusterSizeInfo (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT (OFile->ODir == NULL);
|
ASSERT (OFile->ODir == NULL);
|
||||||
OFile->DirEnt->Entry.FileSize = (UINT32) OFile->FileSize;
|
OFile->DirEnt->Entry.FileSize = (UINT32)OFile->FileSize;
|
||||||
FatSetDirEntCluster (OFile);
|
FatSetDirEntCluster (OFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +209,9 @@ FatCloneDirEnt (
|
|||||||
{
|
{
|
||||||
UINT8 *Entry1;
|
UINT8 *Entry1;
|
||||||
UINT8 *Entry2;
|
UINT8 *Entry2;
|
||||||
Entry1 = (UINT8 *) &DirEnt1->Entry;
|
|
||||||
Entry2 = (UINT8 *) &DirEnt2->Entry;
|
Entry1 = (UINT8 *)&DirEnt1->Entry;
|
||||||
|
Entry2 = (UINT8 *)&DirEnt2->Entry;
|
||||||
CopyMem (
|
CopyMem (
|
||||||
Entry1 + FAT_ENTRY_INFO_OFFSET,
|
Entry1 + FAT_ENTRY_INFO_OFFSET,
|
||||||
Entry2 + FAT_ENTRY_INFO_OFFSET,
|
Entry2 + FAT_ENTRY_INFO_OFFSET,
|
||||||
@ -258,12 +260,13 @@ FatLoadLongNameEntry (
|
|||||||
EntryPos--;
|
EntryPos--;
|
||||||
Status = FatAccessEntry (Parent, ReadData, EntryPos, &LfnEntry);
|
Status = FatAccessEntry (Parent, ReadData, EntryPos, &LfnEntry);
|
||||||
if (EFI_ERROR (Status) ||
|
if (EFI_ERROR (Status) ||
|
||||||
LfnEntry.Attributes != FAT_ATTRIBUTE_LFN ||
|
(LfnEntry.Attributes != FAT_ATTRIBUTE_LFN) ||
|
||||||
LfnEntry.MustBeZero != 0 ||
|
(LfnEntry.MustBeZero != 0) ||
|
||||||
LfnEntry.Checksum != LfnChecksum ||
|
(LfnEntry.Checksum != LfnChecksum) ||
|
||||||
(LfnEntry.Ordinal & (~FAT_LFN_LAST)) != LfnOrdinal ||
|
((LfnEntry.Ordinal & (~FAT_LFN_LAST)) != LfnOrdinal) ||
|
||||||
LfnOrdinal > MAX_LFN_ENTRIES
|
(LfnOrdinal > MAX_LFN_ENTRIES)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// The directory entry does not have a long file name or
|
// The directory entry does not have a long file name or
|
||||||
// some error occurs when loading long file name for a directory entry,
|
// some error occurs when loading long file name for a directory entry,
|
||||||
@ -281,6 +284,7 @@ FatLoadLongNameEntry (
|
|||||||
LfnBufferPointer += LFN_CHAR3_LEN;
|
LfnBufferPointer += LFN_CHAR3_LEN;
|
||||||
LfnOrdinal++;
|
LfnOrdinal++;
|
||||||
} while ((LfnEntry.Ordinal & FAT_LFN_LAST) == 0);
|
} while ((LfnEntry.Ordinal & FAT_LFN_LAST) == 0);
|
||||||
|
|
||||||
DirEnt->EntryCount = LfnOrdinal;
|
DirEnt->EntryCount = LfnOrdinal;
|
||||||
//
|
//
|
||||||
// Terminate current Lfnbuffer
|
// Terminate current Lfnbuffer
|
||||||
@ -319,6 +323,7 @@ FatAddDirEnt (
|
|||||||
if (DirEnt->Link.BackLink == NULL) {
|
if (DirEnt->Link.BackLink == NULL) {
|
||||||
DirEnt->Link.BackLink = &ODir->ChildList;
|
DirEnt->Link.BackLink = &ODir->ChildList;
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertTailList (DirEnt->Link.BackLink, &DirEnt->Link);
|
InsertTailList (DirEnt->Link.BackLink, &DirEnt->Link);
|
||||||
FatInsertToHashTable (ODir, DirEnt);
|
FatInsertToHashTable (ODir, DirEnt);
|
||||||
}
|
}
|
||||||
@ -358,7 +363,7 @@ FatLoadNextDirEnt (
|
|||||||
ASSERT (!ODir->EndOfDir);
|
ASSERT (!ODir->EndOfDir);
|
||||||
DirEnt = NULL;
|
DirEnt = NULL;
|
||||||
|
|
||||||
for (;;) {
|
for ( ; ;) {
|
||||||
//
|
//
|
||||||
// Read the next directory entry until we find a valid directory entry (excluding lfn entry)
|
// Read the next directory entry until we find a valid directory entry (excluding lfn entry)
|
||||||
//
|
//
|
||||||
@ -367,7 +372,7 @@ FatLoadNextDirEnt (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((UINT8) Entry.FileName[0] != DELETE_ENTRY_MARK) && (Entry.Attributes & FAT_ATTRIBUTE_VOLUME_ID) == 0) {
|
if (((UINT8)Entry.FileName[0] != DELETE_ENTRY_MARK) && ((Entry.Attributes & FAT_ATTRIBUTE_VOLUME_ID) == 0)) {
|
||||||
//
|
//
|
||||||
// We get a valid directory entry, then handle it
|
// We get a valid directory entry, then handle it
|
||||||
//
|
//
|
||||||
@ -398,13 +403,14 @@ FatLoadNextDirEnt (
|
|||||||
//
|
//
|
||||||
// Remember the directory's entry position on disk
|
// 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));
|
CopyMem (&DirEnt->Entry, &Entry, sizeof (FAT_DIRECTORY_ENTRY));
|
||||||
FatLoadLongNameEntry (OFile, DirEnt);
|
FatLoadLongNameEntry (OFile, DirEnt);
|
||||||
if (DirEnt->FileString == NULL) {
|
if (DirEnt->FileString == NULL) {
|
||||||
Status = EFI_OUT_OF_RESOURCES;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add this directory entry to directory
|
// Add this directory entry to directory
|
||||||
//
|
//
|
||||||
@ -482,7 +488,7 @@ FatGetDirEntInfo (
|
|||||||
FatFatTimeToEfiTime (&Entry->FileCreateTime, &Info->CreateTime);
|
FatFatTimeToEfiTime (&Entry->FileCreateTime, &Info->CreateTime);
|
||||||
FatFatTimeToEfiTime (&Entry->FileModificationTime, &Info->ModificationTime);
|
FatFatTimeToEfiTime (&Entry->FileModificationTime, &Info->ModificationTime);
|
||||||
Info->Attribute = Entry->Attributes & EFI_FILE_VALID_ATTR;
|
Info->Attribute = Entry->Attributes & EFI_FILE_VALID_ATTR;
|
||||||
CopyMem ((CHAR8 *) Buffer + Size, DirEnt->FileString, NameSize);
|
CopyMem ((CHAR8 *)Buffer + Size, DirEnt->FileString, NameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
*BufferSize = ResultSize;
|
*BufferSize = ResultSize;
|
||||||
@ -525,9 +531,10 @@ FatSearchODir (
|
|||||||
// Search the hash table first
|
// Search the hash table first
|
||||||
//
|
//
|
||||||
DirEnt = *FatLongNameHashSearch (ODir, FileNameString);
|
DirEnt = *FatLongNameHashSearch (ODir, FileNameString);
|
||||||
if (DirEnt == NULL && PossibleShortName) {
|
if ((DirEnt == NULL) && PossibleShortName) {
|
||||||
DirEnt = *FatShortNameHashSearch (ODir, File8Dot3Name);
|
DirEnt = *FatShortNameHashSearch (ODir, File8Dot3Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DirEnt == NULL) {
|
if (DirEnt == NULL) {
|
||||||
//
|
//
|
||||||
// We fail to get the directory entry from hash table; we then
|
// We fail to get the directory entry from hash table; we then
|
||||||
@ -544,7 +551,7 @@ FatSearchODir (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PossibleShortName && CompareMem (File8Dot3Name, DirEnt->Entry.FileName, FAT_NAME_LEN) == 0) {
|
if (PossibleShortName && (CompareMem (File8Dot3Name, DirEnt->Entry.FileName, FAT_NAME_LEN) == 0)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -736,8 +743,8 @@ FatSeekVolumeId (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((UINT8) Entry->FileName[0] != DELETE_ENTRY_MARK) && (((Entry->Attributes) & (~FAT_ATTRIBUTE_ARCHIVE)) == FAT_ATTRIBUTE_VOLUME_ID)) {
|
if (((UINT8)Entry->FileName[0] != DELETE_ENTRY_MARK) && (((Entry->Attributes) & (~FAT_ATTRIBUTE_ARCHIVE)) == FAT_ATTRIBUTE_VOLUME_ID)) {
|
||||||
DirEnt->EntryPos = (UINT16) EntryPos;
|
DirEnt->EntryPos = (UINT16)EntryPos;
|
||||||
DirEnt->EntryCount = 1;
|
DirEnt->EntryCount = 1;
|
||||||
DirEnt->Invalid = FALSE;
|
DirEnt->Invalid = FALSE;
|
||||||
break;
|
break;
|
||||||
@ -745,6 +752,7 @@ FatSeekVolumeId (
|
|||||||
|
|
||||||
EntryPos++;
|
EntryPos++;
|
||||||
} while (Entry->FileName[0] != EMPTY_ENTRY_MARK);
|
} while (Entry->FileName[0] != EMPTY_ENTRY_MARK);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,10 +807,11 @@ FatFirstFitInsertDirEnt (
|
|||||||
for (CurrentEntry = ODir->ChildList.ForwardLink;
|
for (CurrentEntry = ODir->ChildList.ForwardLink;
|
||||||
CurrentEntry != &ODir->ChildList;
|
CurrentEntry != &ODir->ChildList;
|
||||||
CurrentEntry = CurrentEntry->ForwardLink
|
CurrentEntry = CurrentEntry->ForwardLink
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
CurrentDirEnt = DIRENT_FROM_LINK (CurrentEntry);
|
CurrentDirEnt = DIRENT_FROM_LINK (CurrentEntry);
|
||||||
if (NewEntryPos + CurrentDirEnt->EntryCount <= CurrentDirEnt->EntryPos) {
|
if (NewEntryPos + CurrentDirEnt->EntryCount <= CurrentDirEnt->EntryPos) {
|
||||||
if (LabelPos > NewEntryPos || LabelPos <= CurrentPos) {
|
if ((LabelPos > NewEntryPos) || (LabelPos <= CurrentPos)) {
|
||||||
//
|
//
|
||||||
// first fit succeeded
|
// first fit succeeded
|
||||||
//
|
//
|
||||||
@ -819,7 +828,7 @@ FatFirstFitInsertDirEnt (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
DirEnt->EntryPos = (UINT16) NewEntryPos;
|
DirEnt->EntryPos = (UINT16)NewEntryPos;
|
||||||
DirEnt->Link.BackLink = CurrentEntry;
|
DirEnt->Link.BackLink = CurrentEntry;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
@ -859,6 +868,7 @@ FatNewEntryPos (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We will append this entry to the end of directory
|
// We will append this entry to the end of directory
|
||||||
//
|
//
|
||||||
@ -873,6 +883,7 @@ FatNewEntryPos (
|
|||||||
//
|
//
|
||||||
return FatFirstFitInsertDirEnt (OFile, DirEnt);
|
return FatFirstFitInsertDirEnt (OFile, DirEnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We should allocate a new cluster for this directory
|
// We should allocate a new cluster for this directory
|
||||||
//
|
//
|
||||||
@ -881,11 +892,12 @@ FatNewEntryPos (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We append our directory entry at the end of directory file
|
// We append our directory entry at the end of directory file
|
||||||
//
|
//
|
||||||
ODir->CurrentEndPos = NewEndPos;
|
ODir->CurrentEndPos = NewEndPos;
|
||||||
DirEnt->EntryPos = (UINT16) (ODir->CurrentEndPos - 1);
|
DirEnt->EntryPos = (UINT16)(ODir->CurrentEndPos - 1);
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,6 +1014,7 @@ FatCreateDotDirEnts (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create ".."
|
// Create ".."
|
||||||
//
|
//
|
||||||
@ -1049,6 +1062,7 @@ FatCreateDirEnt (
|
|||||||
Status = EFI_OUT_OF_RESOURCES;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Determine how many directory entries we need
|
// Determine how many directory entries we need
|
||||||
//
|
//
|
||||||
@ -1098,6 +1112,7 @@ FatRemoveDirEnt (
|
|||||||
//
|
//
|
||||||
ODir->CurrentCursor = ODir->CurrentCursor->BackLink;
|
ODir->CurrentCursor = ODir->CurrentCursor->BackLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Remove from directory entry list
|
// Remove from directory entry list
|
||||||
//
|
//
|
||||||
@ -1280,6 +1295,7 @@ FatLocateOFile (
|
|||||||
if (FileName[FileNameLen - 1] == PATH_NAME_SEPARATOR) {
|
if (FileName[FileNameLen - 1] == PATH_NAME_SEPARATOR) {
|
||||||
DirIntended = TRUE;
|
DirIntended = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If name starts with path name separator, then move to root OFile
|
// If name starts with path name separator, then move to root OFile
|
||||||
//
|
//
|
||||||
@ -1288,6 +1304,7 @@ FatLocateOFile (
|
|||||||
FileName++;
|
FileName++;
|
||||||
FileNameLen--;
|
FileNameLen--;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Per FAT Spec the file name should meet the following criteria:
|
// Per FAT Spec the file name should meet the following criteria:
|
||||||
// C1. Length (FileLongName) <= 255
|
// C1. Length (FileLongName) <= 255
|
||||||
@ -1300,11 +1317,12 @@ FatLocateOFile (
|
|||||||
//
|
//
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Start at current location
|
// Start at current location
|
||||||
//
|
//
|
||||||
Next = FileName;
|
Next = FileName;
|
||||||
for (;;) {
|
for ( ; ;) {
|
||||||
//
|
//
|
||||||
// Get the next component name
|
// Get the next component name
|
||||||
//
|
//
|
||||||
@ -1315,19 +1333,21 @@ FatLocateOFile (
|
|||||||
// If end of the file name, we're done
|
// If end of the file name, we're done
|
||||||
//
|
//
|
||||||
if (ComponentName[0] == 0) {
|
if (ComponentName[0] == 0) {
|
||||||
if (DirIntended && OFile->ODir == NULL) {
|
if (DirIntended && (OFile->ODir == NULL)) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewFileName[0] = 0;
|
NewFileName[0] = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If "dot", then current
|
// If "dot", then current
|
||||||
//
|
//
|
||||||
if (StrCmp (ComponentName, L".") == 0) {
|
if (StrCmp (ComponentName, L".") == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If "dot dot", then parent
|
// If "dot dot", then parent
|
||||||
//
|
//
|
||||||
@ -1335,6 +1355,7 @@ FatLocateOFile (
|
|||||||
if (OFile->Parent == NULL) {
|
if (OFile->Parent == NULL) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
OFile = OFile->Parent;
|
OFile = OFile->Parent;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1342,6 +1363,7 @@ FatLocateOFile (
|
|||||||
if (!FatFileNameIsValid (ComponentName, NewFileName)) {
|
if (!FatFileNameIsValid (ComponentName, NewFileName)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We have a component name, try to open it
|
// We have a component name, try to open it
|
||||||
//
|
//
|
||||||
@ -1351,6 +1373,7 @@ FatLocateOFile (
|
|||||||
//
|
//
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Search the compName in the directory
|
// Search the compName in the directory
|
||||||
//
|
//
|
||||||
@ -1367,9 +1390,10 @@ FatLocateOFile (
|
|||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DirIntended && (Attributes & FAT_ATTRIBUTE_DIRECTORY) == 0) {
|
if (DirIntended && ((Attributes & FAT_ATTRIBUTE_DIRECTORY) == 0)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// It's the last component name - return with the open
|
// It's the last component name - return with the open
|
||||||
// path and the remaining name
|
// path and the remaining name
|
||||||
|
@ -55,7 +55,7 @@ FatFlushDataCacheRange (
|
|||||||
for (PageNo = StartPageNo; PageNo < EndPageNo; PageNo++) {
|
for (PageNo = StartPageNo; PageNo < EndPageNo; PageNo++) {
|
||||||
GroupNo = PageNo & GroupMask;
|
GroupNo = PageNo & GroupMask;
|
||||||
CacheTag = &DiskCache->CacheTag[GroupNo];
|
CacheTag = &DiskCache->CacheTag[GroupNo];
|
||||||
if (CacheTag->RealSize > 0 && CacheTag->PageNo == PageNo) {
|
if ((CacheTag->RealSize > 0) && (CacheTag->PageNo == PageNo)) {
|
||||||
//
|
//
|
||||||
// When reading data form disk directly, if some dirty data
|
// When reading data form disk directly, if some dirty data
|
||||||
// in cache is in this rang, this data in the Buffer need to
|
// in cache is in this rang, this data in the Buffer need to
|
||||||
@ -126,12 +126,12 @@ FatExchangeCachePage (
|
|||||||
MaxSize = DiskCache->LimitAddress - EntryPos;
|
MaxSize = DiskCache->LimitAddress - EntryPos;
|
||||||
if (MaxSize < RealSize) {
|
if (MaxSize < RealSize) {
|
||||||
DEBUG ((DEBUG_INFO, "FatDiskIo: Cache Page OutBound occurred! \n"));
|
DEBUG ((DEBUG_INFO, "FatDiskIo: Cache Page OutBound occurred! \n"));
|
||||||
RealSize = (UINTN) MaxSize;
|
RealSize = (UINTN)MaxSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteCount = 1;
|
WriteCount = 1;
|
||||||
if (DataType == CacheFat && IoMode == WriteDisk) {
|
if ((DataType == CacheFat) && (IoMode == WriteDisk)) {
|
||||||
WriteCount = Volume->NumFats;
|
WriteCount = Volume->NumFats;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ FatGetCachePage (
|
|||||||
UINTN OldPageNo;
|
UINTN OldPageNo;
|
||||||
|
|
||||||
OldPageNo = CacheTag->PageNo;
|
OldPageNo = CacheTag->PageNo;
|
||||||
if (CacheTag->RealSize > 0 && OldPageNo == PageNo) {
|
if ((CacheTag->RealSize > 0) && (OldPageNo == PageNo)) {
|
||||||
//
|
//
|
||||||
// Cache Hit occurred
|
// Cache Hit occurred
|
||||||
//
|
//
|
||||||
@ -188,12 +188,13 @@ FatGetCachePage (
|
|||||||
//
|
//
|
||||||
// Write dirty cache page back to disk
|
// Write dirty cache page back to disk
|
||||||
//
|
//
|
||||||
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {
|
if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
|
||||||
Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, NULL);
|
Status = FatExchangeCachePage (Volume, CacheDataType, WriteDisk, CacheTag, NULL);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Load new data from disk;
|
// Load new data from disk;
|
||||||
//
|
//
|
||||||
@ -319,8 +320,8 @@ FatAccessCache (
|
|||||||
EntryPos = Offset - DiskCache->BaseAddress;
|
EntryPos = Offset - DiskCache->BaseAddress;
|
||||||
PageAlignment = DiskCache->PageAlignment;
|
PageAlignment = DiskCache->PageAlignment;
|
||||||
PageSize = (UINTN)1 << PageAlignment;
|
PageSize = (UINTN)1 << PageAlignment;
|
||||||
PageNo = (UINTN) RShiftU64 (EntryPos, PageAlignment);
|
PageNo = (UINTN)RShiftU64 (EntryPos, PageAlignment);
|
||||||
UnderRun = ((UINTN) EntryPos) & (PageSize - 1);
|
UnderRun = ((UINTN)EntryPos) & (PageSize - 1);
|
||||||
|
|
||||||
if (UnderRun > 0) {
|
if (UnderRun > 0) {
|
||||||
Length = PageSize - UnderRun;
|
Length = PageSize - UnderRun;
|
||||||
@ -355,6 +356,7 @@ FatAccessCache (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If these access data over laps the relative cache range, these cache pages need
|
// If these access data over laps the relative cache range, these cache pages need
|
||||||
// to be updated.
|
// to be updated.
|
||||||
@ -363,6 +365,7 @@ FatAccessCache (
|
|||||||
Buffer += AlignedSize;
|
Buffer += AlignedSize;
|
||||||
BufferSize -= AlignedSize;
|
BufferSize -= AlignedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The access of the OverRun data
|
// The access of the OverRun data
|
||||||
//
|
//
|
||||||
@ -401,7 +404,7 @@ FatVolumeFlushCache (
|
|||||||
DISK_CACHE *DiskCache;
|
DISK_CACHE *DiskCache;
|
||||||
CACHE_TAG *CacheTag;
|
CACHE_TAG *CacheTag;
|
||||||
|
|
||||||
for (CacheDataType = (CACHE_DATA_TYPE) 0; CacheDataType < CacheMaxType; CacheDataType++) {
|
for (CacheDataType = (CACHE_DATA_TYPE)0; CacheDataType < CacheMaxType; CacheDataType++) {
|
||||||
DiskCache = &Volume->DiskCache[CacheDataType];
|
DiskCache = &Volume->DiskCache[CacheDataType];
|
||||||
if (DiskCache->Dirty) {
|
if (DiskCache->Dirty) {
|
||||||
//
|
//
|
||||||
@ -410,7 +413,7 @@ FatVolumeFlushCache (
|
|||||||
GroupMask = DiskCache->GroupMask;
|
GroupMask = DiskCache->GroupMask;
|
||||||
for (GroupIndex = 0; GroupIndex <= GroupMask; GroupIndex++) {
|
for (GroupIndex = 0; GroupIndex <= GroupMask; GroupIndex++) {
|
||||||
CacheTag = &DiskCache->CacheTag[GroupIndex];
|
CacheTag = &DiskCache->CacheTag[GroupIndex];
|
||||||
if (CacheTag->RealSize > 0 && CacheTag->Dirty) {
|
if ((CacheTag->RealSize > 0) && CacheTag->Dirty) {
|
||||||
//
|
//
|
||||||
// Write back all Dirty Data Cache Page to disk
|
// Write back all Dirty Data Cache Page to disk
|
||||||
//
|
//
|
||||||
@ -424,6 +427,7 @@ FatVolumeFlushCache (
|
|||||||
DiskCache->Dirty = FALSE;
|
DiskCache->Dirty = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Flush the block device.
|
// Flush the block device.
|
||||||
//
|
//
|
||||||
|
@ -224,14 +224,17 @@ FatUnload (
|
|||||||
if (ComponentName2 == NULL) {
|
if (ComponentName2 == NULL) {
|
||||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
ImageHandle,
|
ImageHandle,
|
||||||
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
|
&gEfiDriverBindingProtocolGuid,
|
||||||
|
&gFatDriverBinding,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
ImageHandle,
|
ImageHandle,
|
||||||
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
|
&gEfiDriverBindingProtocolGuid,
|
||||||
&gEfiComponentName2ProtocolGuid, ComponentName2,
|
&gFatDriverBinding,
|
||||||
|
&gEfiComponentName2ProtocolGuid,
|
||||||
|
ComponentName2,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -239,16 +242,21 @@ FatUnload (
|
|||||||
if (ComponentName2 == NULL) {
|
if (ComponentName2 == NULL) {
|
||||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
ImageHandle,
|
ImageHandle,
|
||||||
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
|
&gEfiDriverBindingProtocolGuid,
|
||||||
&gEfiComponentNameProtocolGuid, ComponentName,
|
&gFatDriverBinding,
|
||||||
|
&gEfiComponentNameProtocolGuid,
|
||||||
|
ComponentName,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = gBS->UninstallMultipleProtocolInterfaces (
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
ImageHandle,
|
ImageHandle,
|
||||||
&gEfiDriverBindingProtocolGuid, &gFatDriverBinding,
|
&gEfiDriverBindingProtocolGuid,
|
||||||
&gEfiComponentNameProtocolGuid, ComponentName,
|
&gFatDriverBinding,
|
||||||
&gEfiComponentName2ProtocolGuid, ComponentName2,
|
&gEfiComponentNameProtocolGuid,
|
||||||
|
ComponentName,
|
||||||
|
&gEfiComponentName2ProtocolGuid,
|
||||||
|
ComponentName2,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -293,7 +301,7 @@ FatDriverBindingSupported (
|
|||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiDiskIoProtocolGuid,
|
&gEfiDiskIoProtocolGuid,
|
||||||
(VOID **) &DiskIo,
|
(VOID **)&DiskIo,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||||
@ -302,6 +310,7 @@ FatDriverBindingSupported (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Close the I/O Abstraction(s) used to perform the supported test
|
// Close the I/O Abstraction(s) used to perform the supported test
|
||||||
//
|
//
|
||||||
@ -371,13 +380,14 @@ FatDriverBindingStart (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Open our required BlockIo and DiskIo
|
// Open our required BlockIo and DiskIo
|
||||||
//
|
//
|
||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiBlockIoProtocolGuid,
|
&gEfiBlockIoProtocolGuid,
|
||||||
(VOID **) &BlockIo,
|
(VOID **)&BlockIo,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
@ -389,7 +399,7 @@ FatDriverBindingStart (
|
|||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiDiskIoProtocolGuid,
|
&gEfiDiskIoProtocolGuid,
|
||||||
(VOID **) &DiskIo,
|
(VOID **)&DiskIo,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||||
@ -401,7 +411,7 @@ FatDriverBindingStart (
|
|||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiDiskIo2ProtocolGuid,
|
&gEfiDiskIo2ProtocolGuid,
|
||||||
(VOID **) &DiskIo2,
|
(VOID **)&DiskIo2,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
EFI_OPEN_PROTOCOL_BY_DRIVER
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||||
@ -453,6 +463,7 @@ Exit:
|
|||||||
if (LockedByMe) {
|
if (LockedByMe) {
|
||||||
FatReleaseLock ();
|
FatReleaseLock ();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,7 +501,7 @@ FatDriverBindingStop (
|
|||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiSimpleFileSystemProtocolGuid,
|
&gEfiSimpleFileSystemProtocolGuid,
|
||||||
(VOID **) &FileSystem,
|
(VOID **)&FileSystem,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
@ -512,6 +523,7 @@ FatDriverBindingStop (
|
|||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = gBS->CloseProtocol (
|
Status = gBS->CloseProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiDiskIoProtocolGuid,
|
&gEfiDiskIoProtocolGuid,
|
||||||
|
@ -97,7 +97,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
//
|
//
|
||||||
#define PATH_NAME_SEPARATOR L'\\'
|
#define PATH_NAME_SEPARATOR L'\\'
|
||||||
|
|
||||||
|
|
||||||
#define EFI_PATH_STRING_LENGTH 260
|
#define EFI_PATH_STRING_LENGTH 260
|
||||||
#define EFI_FILE_STRING_LENGTH 255
|
#define EFI_FILE_STRING_LENGTH 255
|
||||||
#define FAT_MAX_ALLOCATE_SIZE 0xA00000
|
#define FAT_MAX_ALLOCATE_SIZE 0xA00000
|
||||||
@ -696,6 +695,7 @@ FatWriteEx (
|
|||||||
//
|
//
|
||||||
// DiskCache.c
|
// DiskCache.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Initialize the disk cache according to Volume's FatType.
|
Initialize the disk cache according to Volume's FatType.
|
||||||
@ -771,6 +771,7 @@ FatVolumeFlushCache (
|
|||||||
//
|
//
|
||||||
// Flush.c
|
// Flush.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Flush the data associated with an open file.
|
Flush the data associated with an open file.
|
||||||
@ -859,6 +860,7 @@ FatCleanupVolume (
|
|||||||
//
|
//
|
||||||
// FileSpace.c
|
// FileSpace.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Shrink the end of the open file base on the file size.
|
Shrink the end of the open file base on the file size.
|
||||||
@ -961,6 +963,7 @@ FatComputeFreeInfo (
|
|||||||
//
|
//
|
||||||
// Init.c
|
// Init.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Allocates volume structure, detects FAT file system, installs protocol,
|
Allocates volume structure, detects FAT file system, installs protocol,
|
||||||
@ -1018,6 +1021,7 @@ FatAbandonVolume (
|
|||||||
//
|
//
|
||||||
// Misc.c
|
// Misc.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Create the task
|
Create the task
|
||||||
@ -1251,6 +1255,7 @@ FatIsValidTime (
|
|||||||
//
|
//
|
||||||
// UnicodeCollation.c
|
// UnicodeCollation.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize Unicode Collation support.
|
Initialize Unicode Collation support.
|
||||||
|
|
||||||
@ -1398,6 +1403,7 @@ FatAllocateIFile (
|
|||||||
//
|
//
|
||||||
// OpenVolume.c
|
// OpenVolume.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Implements Simple File System Protocol interface function OpenVolume().
|
Implements Simple File System Protocol interface function OpenVolume().
|
||||||
@ -1420,6 +1426,7 @@ FatOpenVolume (
|
|||||||
//
|
//
|
||||||
// ReadWrite.c
|
// ReadWrite.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
This function reads data from a file or writes data to a file.
|
This function reads data from a file or writes data to a file.
|
||||||
@ -1501,6 +1508,7 @@ FatTruncateOFile (
|
|||||||
//
|
//
|
||||||
// DirectoryManage.c
|
// DirectoryManage.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Set the OFile's current directory cursor to the list head.
|
Set the OFile's current directory cursor to the list head.
|
||||||
@ -1759,6 +1767,7 @@ FatSetVolumeEntry (
|
|||||||
//
|
//
|
||||||
// Hash.c
|
// Hash.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Search the long name hash table for the directory entry.
|
Search the long name hash table for the directory entry.
|
||||||
@ -1822,6 +1831,7 @@ FatDeleteFromHashTable (
|
|||||||
//
|
//
|
||||||
// FileName.c
|
// FileName.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
This function checks whether the input FileName is a valid 8.3 short name.
|
This function checks whether the input FileName is a valid 8.3 short name.
|
||||||
@ -1928,7 +1938,7 @@ FatCheckSum (
|
|||||||
The position after Name in the Path
|
The position after Name in the Path
|
||||||
|
|
||||||
**/
|
**/
|
||||||
CHAR16*
|
CHAR16 *
|
||||||
FatGetNextNameComponent (
|
FatGetNextNameComponent (
|
||||||
IN CHAR16 *Path,
|
IN CHAR16 *Path,
|
||||||
OUT CHAR16 *Name
|
OUT CHAR16 *Name
|
||||||
@ -1956,6 +1966,7 @@ FatFileNameIsValid (
|
|||||||
//
|
//
|
||||||
// DirectoryCache.c
|
// DirectoryCache.c
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Discard the directory structure when an OFile will be freed.
|
Discard the directory structure when an OFile will be freed.
|
||||||
|
@ -42,7 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
#define FAT_POS_FAT32(a) ((a) * 4)
|
#define FAT_POS_FAT32(a) ((a) * 4)
|
||||||
#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
|
#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// FAT attribute define
|
// FAT attribute define
|
||||||
//
|
//
|
||||||
@ -134,7 +133,7 @@ typedef struct {
|
|||||||
typedef union {
|
typedef union {
|
||||||
FAT_BOOT_SECTOR_EXT FatBse;
|
FAT_BOOT_SECTOR_EXT FatBse;
|
||||||
FAT32_BOOT_SECTOR_EXT Fat32Bse;
|
FAT32_BOOT_SECTOR_EXT Fat32Bse;
|
||||||
} FAT_BSE;
|
} FAT_BSE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FAT_BOOT_SECTOR_BASIC FatBsb;
|
FAT_BOOT_SECTOR_BASIC FatBsb;
|
||||||
|
@ -58,12 +58,13 @@ FatCheckIs8Dot3Name (
|
|||||||
ExtendName = SeparateDot + 1;
|
ExtendName = SeparateDot + 1;
|
||||||
ExtendNameLen = TempName - ExtendName;
|
ExtendNameLen = TempName - ExtendName;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We scan the filename for the second time
|
// We scan the filename for the second time
|
||||||
// to check if there exists any extra blanks and dots
|
// to check if there exists any extra blanks and dots
|
||||||
//
|
//
|
||||||
while (--TempName >= FileName) {
|
while (--TempName >= FileName) {
|
||||||
if ((*TempName == L'.' || *TempName == L' ') && (TempName != SeparateDot)) {
|
if (((*TempName == L'.') || (*TempName == L' ')) && (TempName != SeparateDot)) {
|
||||||
//
|
//
|
||||||
// There exist extra blanks and dots
|
// There exist extra blanks and dots
|
||||||
//
|
//
|
||||||
@ -176,6 +177,7 @@ FatCreate8Dot3Name (
|
|||||||
UINTN Index;
|
UINTN Index;
|
||||||
UINTN Retry;
|
UINTN Retry;
|
||||||
UINT8 Segment;
|
UINT8 Segment;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
UINT32 Crc;
|
UINT32 Crc;
|
||||||
struct HEX_DATA {
|
struct HEX_DATA {
|
||||||
@ -195,6 +197,7 @@ FatCreate8Dot3Name (
|
|||||||
if (BaseTagLen > SPEC_BASE_TAG_LEN) {
|
if (BaseTagLen > SPEC_BASE_TAG_LEN) {
|
||||||
BaseTagLen = SPEC_BASE_TAG_LEN;
|
BaseTagLen = SPEC_BASE_TAG_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We first use the algorithm described by spec.
|
// We first use the algorithm described by spec.
|
||||||
//
|
//
|
||||||
@ -265,6 +268,7 @@ FatCheckNameCase (
|
|||||||
if (StrCmp (Str, Buffer) == 0) {
|
if (StrCmp (Str, Buffer) == 0) {
|
||||||
OutCaseFlag = InCaseFlag;
|
OutCaseFlag = InCaseFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Upper case a copy of the string, if it matches the
|
// Upper case a copy of the string, if it matches the
|
||||||
// original then the string is upper case
|
// original then the string is upper case
|
||||||
@ -350,6 +354,7 @@ FatGetFileNameViaCaseFlag (
|
|||||||
UINT8 CaseFlag;
|
UINT8 CaseFlag;
|
||||||
CHAR8 *File8Dot3Name;
|
CHAR8 *File8Dot3Name;
|
||||||
CHAR16 TempExt[1 + FAT_EXTEND_NAME_LEN + 1];
|
CHAR16 TempExt[1 + FAT_EXTEND_NAME_LEN + 1];
|
||||||
|
|
||||||
//
|
//
|
||||||
// Store file extension like ".txt"
|
// Store file extension like ".txt"
|
||||||
//
|
//
|
||||||
@ -380,6 +385,7 @@ FatCheckSum (
|
|||||||
{
|
{
|
||||||
UINTN ShortNameLen;
|
UINTN ShortNameLen;
|
||||||
UINT8 Sum;
|
UINT8 Sum;
|
||||||
|
|
||||||
Sum = 0;
|
Sum = 0;
|
||||||
for (ShortNameLen = FAT_NAME_LEN; ShortNameLen != 0; ShortNameLen--) {
|
for (ShortNameLen = FAT_NAME_LEN; ShortNameLen != 0; ShortNameLen--) {
|
||||||
Sum = (UINT8)((((Sum & 1) != 0) ? 0x80 : 0) + (Sum >> 1) + *ShortNameString++);
|
Sum = (UINT8)((((Sum & 1) != 0) ? 0x80 : 0) + (Sum >> 1) + *ShortNameString++);
|
||||||
@ -409,6 +415,7 @@ FatGetNextNameComponent (
|
|||||||
while (*Path != 0 && *Path != PATH_NAME_SEPARATOR) {
|
while (*Path != 0 && *Path != PATH_NAME_SEPARATOR) {
|
||||||
*Name++ = *Path++;
|
*Name++ = *Path++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*Name = 0;
|
*Name = 0;
|
||||||
//
|
//
|
||||||
// Get off of trailing path name separator
|
// Get off of trailing path name separator
|
||||||
@ -441,6 +448,7 @@ FatFileNameIsValid (
|
|||||||
{
|
{
|
||||||
CHAR16 *TempNamePointer;
|
CHAR16 *TempNamePointer;
|
||||||
CHAR16 TempChar;
|
CHAR16 TempChar;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trim Leading blanks
|
// Trim Leading blanks
|
||||||
//
|
//
|
||||||
@ -452,12 +460,13 @@ FatFileNameIsValid (
|
|||||||
while (*InputFileName != 0) {
|
while (*InputFileName != 0) {
|
||||||
*TempNamePointer++ = *InputFileName++;
|
*TempNamePointer++ = *InputFileName++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Trim Trailing blanks and dots
|
// Trim Trailing blanks and dots
|
||||||
//
|
//
|
||||||
while (TempNamePointer > OutputFileName) {
|
while (TempNamePointer > OutputFileName) {
|
||||||
TempChar = *(TempNamePointer - 1);
|
TempChar = *(TempNamePointer - 1);
|
||||||
if (TempChar != L' ' && TempChar != L'.') {
|
if ((TempChar != L' ') && (TempChar != L'.')) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,25 +484,28 @@ FatFileNameIsValid (
|
|||||||
if (TempNamePointer - OutputFileName > EFI_FILE_STRING_LENGTH) {
|
if (TempNamePointer - OutputFileName > EFI_FILE_STRING_LENGTH) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// See if there is any illegal characters within the name
|
// See if there is any illegal characters within the name
|
||||||
//
|
//
|
||||||
do {
|
do {
|
||||||
if (*OutputFileName < 0x20 ||
|
if ((*OutputFileName < 0x20) ||
|
||||||
*OutputFileName == '\"' ||
|
(*OutputFileName == '\"') ||
|
||||||
*OutputFileName == '*' ||
|
(*OutputFileName == '*') ||
|
||||||
*OutputFileName == '/' ||
|
(*OutputFileName == '/') ||
|
||||||
*OutputFileName == ':' ||
|
(*OutputFileName == ':') ||
|
||||||
*OutputFileName == '<' ||
|
(*OutputFileName == '<') ||
|
||||||
*OutputFileName == '>' ||
|
(*OutputFileName == '>') ||
|
||||||
*OutputFileName == '?' ||
|
(*OutputFileName == '?') ||
|
||||||
*OutputFileName == '\\' ||
|
(*OutputFileName == '\\') ||
|
||||||
*OutputFileName == '|'
|
(*OutputFileName == '|')
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputFileName++;
|
OutputFileName++;
|
||||||
} while (*OutputFileName != 0);
|
} while (*OutputFileName != 0);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
|
|
||||||
#include "Fat.h"
|
#include "Fat.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
Get the FAT entry of the volume, which is identified with the Index.
|
Get the FAT entry of the volume, which is identified with the Index.
|
||||||
@ -32,9 +31,10 @@ FatLoadFatEntry (
|
|||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
if (Index > (Volume->MaxCluster + 1)) {
|
if (Index > (Volume->MaxCluster + 1)) {
|
||||||
Volume->FatEntryBuffer = (UINT32) -1;
|
Volume->FatEntryBuffer = (UINT32)-1;
|
||||||
return &Volume->FatEntryBuffer;
|
return &Volume->FatEntryBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Compute buffer position needed
|
// Compute buffer position needed
|
||||||
//
|
//
|
||||||
@ -50,6 +50,7 @@ FatLoadFatEntry (
|
|||||||
default:
|
default:
|
||||||
Pos = FAT_POS_FAT32 (Index);
|
Pos = FAT_POS_FAT32 (Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set the position and read the buffer
|
// Set the position and read the buffer
|
||||||
//
|
//
|
||||||
@ -63,7 +64,7 @@ FatLoadFatEntry (
|
|||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
Volume->FatEntryBuffer = (UINT32) -1;
|
Volume->FatEntryBuffer = (UINT32)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Volume->FatEntryBuffer;
|
return &Volume->FatEntryBuffer;
|
||||||
@ -95,7 +96,7 @@ FatGetFatEntry (
|
|||||||
Pos = FatLoadFatEntry (Volume, Index);
|
Pos = FatLoadFatEntry (Volume, Index);
|
||||||
|
|
||||||
if (Index > (Volume->MaxCluster + 1)) {
|
if (Index > (Volume->MaxCluster + 1)) {
|
||||||
return (UINTN) -1;
|
return (UINTN)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (Volume->FatType) {
|
switch (Volume->FatType) {
|
||||||
@ -155,16 +156,17 @@ FatSetFatEntry (
|
|||||||
}
|
}
|
||||||
|
|
||||||
OriginalVal = FatGetFatEntry (Volume, Index);
|
OriginalVal = FatGetFatEntry (Volume, Index);
|
||||||
if (Value == FAT_CLUSTER_FREE && OriginalVal != FAT_CLUSTER_FREE) {
|
if ((Value == FAT_CLUSTER_FREE) && (OriginalVal != FAT_CLUSTER_FREE)) {
|
||||||
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
|
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
|
||||||
if (Index < Volume->FatInfoSector.FreeInfo.NextCluster) {
|
if (Index < Volume->FatInfoSector.FreeInfo.NextCluster) {
|
||||||
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32) Index;
|
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32)Index;
|
||||||
}
|
}
|
||||||
} else if (Value != FAT_CLUSTER_FREE && OriginalVal == FAT_CLUSTER_FREE) {
|
} else if ((Value != FAT_CLUSTER_FREE) && (OriginalVal == FAT_CLUSTER_FREE)) {
|
||||||
if (Volume->FatInfoSector.FreeInfo.ClusterCount != 0) {
|
if (Volume->FatInfoSector.FreeInfo.ClusterCount != 0) {
|
||||||
Volume->FatInfoSector.FreeInfo.ClusterCount -= 1;
|
Volume->FatInfoSector.FreeInfo.ClusterCount -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Make sure the entry is in memory
|
// Make sure the entry is in memory
|
||||||
//
|
//
|
||||||
@ -185,26 +187,28 @@ FatSetFatEntry (
|
|||||||
Accum = Value | (Accum & FAT_CLUSTER_UNMASK_FAT12);
|
Accum = Value | (Accum & FAT_CLUSTER_UNMASK_FAT12);
|
||||||
}
|
}
|
||||||
|
|
||||||
En12[0] = (UINT8) (Accum & 0xFF);
|
En12[0] = (UINT8)(Accum & 0xFF);
|
||||||
En12[1] = (UINT8) (Accum >> 8);
|
En12[1] = (UINT8)(Accum >> 8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Fat16:
|
case Fat16:
|
||||||
En16 = Pos;
|
En16 = Pos;
|
||||||
*En16 = (UINT16) Value;
|
*En16 = (UINT16)Value;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
En32 = Pos;
|
En32 = Pos;
|
||||||
*En32 = (*En32 & FAT_CLUSTER_UNMASK_FAT32) | (UINT32) (Value & FAT_CLUSTER_MASK_FAT32);
|
*En32 = (*En32 & FAT_CLUSTER_UNMASK_FAT32) | (UINT32)(Value & FAT_CLUSTER_MASK_FAT32);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the volume's dirty bit is not set, set it now
|
// If the volume's dirty bit is not set, set it now
|
||||||
//
|
//
|
||||||
if (!Volume->FatDirty && Volume->FatType != Fat12) {
|
if (!Volume->FatDirty && (Volume->FatType != Fat12)) {
|
||||||
Volume->FatDirty = TRUE;
|
Volume->FatDirty = TRUE;
|
||||||
FatAccessVolumeDirty (Volume, WriteFat, &Volume->DirtyValue);
|
FatAccessVolumeDirty (Volume, WriteFat, &Volume->DirtyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Write the updated fat entry value to the volume
|
// Write the updated fat entry value to the volume
|
||||||
// The fat is the first fat, and other fat will be in sync
|
// The fat is the first fat, and other fat will be in sync
|
||||||
@ -242,8 +246,7 @@ FatFreeClusters (
|
|||||||
UINTN LastCluster;
|
UINTN LastCluster;
|
||||||
|
|
||||||
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
|
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
|
||||||
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
|
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
|
||||||
|
|
||||||
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
|
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
|
||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
@ -277,21 +280,21 @@ FatAllocateCluster (
|
|||||||
// Start looking at FatFreePos for the next unallocated cluster
|
// Start looking at FatFreePos for the next unallocated cluster
|
||||||
//
|
//
|
||||||
if (Volume->DiskError) {
|
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 the end of the list, return no available cluster
|
||||||
//
|
//
|
||||||
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
|
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
|
||||||
if (Volume->FreeInfoValid && 0 < (INT32) (Volume->FatInfoSector.FreeInfo.ClusterCount)) {
|
if (Volume->FreeInfoValid && (0 < (INT32)(Volume->FatInfoSector.FreeInfo.ClusterCount))) {
|
||||||
Volume->FreeInfoValid = FALSE;
|
Volume->FreeInfoValid = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FatComputeFreeInfo (Volume);
|
FatComputeFreeInfo (Volume);
|
||||||
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
|
if (Volume->FatInfoSector.FreeInfo.NextCluster > (Volume->MaxCluster + 1)) {
|
||||||
return (UINTN) FAT_CLUSTER_LAST;
|
return (UINTN)FAT_CLUSTER_LAST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,6 +302,7 @@ FatAllocateCluster (
|
|||||||
if (Cluster == FAT_CLUSTER_FREE) {
|
if (Cluster == FAT_CLUSTER_FREE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Try the next cluster
|
// Try the next cluster
|
||||||
//
|
//
|
||||||
@ -370,10 +374,8 @@ FatShrinkEof (
|
|||||||
LastCluster = FAT_CLUSTER_FREE;
|
LastCluster = FAT_CLUSTER_FREE;
|
||||||
|
|
||||||
if (NewSize != 0) {
|
if (NewSize != 0) {
|
||||||
|
|
||||||
for (CurSize = 0; CurSize < NewSize; CurSize++) {
|
for (CurSize = 0; CurSize < NewSize; CurSize++) {
|
||||||
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
|
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
|
||||||
|
|
||||||
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
|
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatShrinkEof: cluster chain corrupt\n"));
|
||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
@ -382,8 +384,7 @@ FatShrinkEof (
|
|||||||
Cluster = FatGetFatEntry (Volume, Cluster);
|
Cluster = FatGetFatEntry (Volume, Cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
|
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Check to see if the file is already completely truncated
|
// Check to see if the file is already completely truncated
|
||||||
@ -391,11 +392,13 @@ FatShrinkEof (
|
|||||||
if (Cluster == FAT_CLUSTER_FREE) {
|
if (Cluster == FAT_CLUSTER_FREE) {
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The file is being completely truncated.
|
// The file is being completely truncated.
|
||||||
//
|
//
|
||||||
OFile->FileCluster = FAT_CLUSTER_FREE;
|
OFile->FileCluster = FAT_CLUSTER_FREE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set CurrentCluster == FileCluster
|
// Set CurrentCluster == FileCluster
|
||||||
// to force a recalculation of Position related stuffs
|
// to force a recalculation of Position related stuffs
|
||||||
@ -450,7 +453,7 @@ FatGrowEof (
|
|||||||
// If the file is already large enough, do nothing
|
// If the file is already large enough, do nothing
|
||||||
//
|
//
|
||||||
CurSize = FatSizeToClusters (Volume, OFile->FileSize);
|
CurSize = FatSizeToClusters (Volume, OFile->FileSize);
|
||||||
NewSize = FatSizeToClusters (Volume, (UINTN) NewSizeInBytes);
|
NewSize = FatSizeToClusters (Volume, (UINTN)NewSizeInBytes);
|
||||||
|
|
||||||
if (CurSize < NewSize) {
|
if (CurSize < NewSize) {
|
||||||
//
|
//
|
||||||
@ -461,8 +464,7 @@ FatGrowEof (
|
|||||||
ClusterCount = 0;
|
ClusterCount = 0;
|
||||||
|
|
||||||
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
|
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
|
||||||
if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
|
if ((Cluster < FAT_MIN_CLUSTER) || (Cluster > Volume->MaxCluster + 1)) {
|
||||||
|
|
||||||
DEBUG (
|
DEBUG (
|
||||||
(DEBUG_INIT | DEBUG_ERROR,
|
(DEBUG_INIT | DEBUG_ERROR,
|
||||||
"FatGrowEof: cluster chain corrupt\n")
|
"FatGrowEof: cluster chain corrupt\n")
|
||||||
@ -484,8 +486,8 @@ FatGrowEof (
|
|||||||
Status = EFI_VOLUME_CORRUPTED;
|
Status = EFI_VOLUME_CORRUPTED;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Loop until we've allocated enough space
|
// Loop until we've allocated enough space
|
||||||
//
|
//
|
||||||
@ -495,7 +497,7 @@ FatGrowEof (
|
|||||||
NewCluster = FatAllocateCluster (Volume);
|
NewCluster = FatAllocateCluster (Volume);
|
||||||
if (FAT_END_OF_FAT_CHAIN (NewCluster)) {
|
if (FAT_END_OF_FAT_CHAIN (NewCluster)) {
|
||||||
if (LastCluster != FAT_CLUSTER_FREE) {
|
if (LastCluster != FAT_CLUSTER_FREE) {
|
||||||
FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
|
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
|
||||||
OFile->FileLastCluster = LastCluster;
|
OFile->FileLastCluster = LastCluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +505,7 @@ FatGrowEof (
|
|||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NewCluster < FAT_MIN_CLUSTER || NewCluster > Volume->MaxCluster + 1) {
|
if ((NewCluster < FAT_MIN_CLUSTER) || (NewCluster > Volume->MaxCluster + 1)) {
|
||||||
Status = EFI_VOLUME_CORRUPTED;
|
Status = EFI_VOLUME_CORRUPTED;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
@ -529,12 +531,12 @@ FatGrowEof (
|
|||||||
// a second time. There are other, less predictable scenarios
|
// a second time. There are other, less predictable scenarios
|
||||||
// where this could happen, as well.
|
// where this could happen, as well.
|
||||||
//
|
//
|
||||||
FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
|
FatSetFatEntry (Volume, LastCluster, (UINTN)FAT_CLUSTER_LAST);
|
||||||
OFile->FileLastCluster = LastCluster;
|
OFile->FileLastCluster = LastCluster;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OFile->FileSize = (UINTN) NewSizeInBytes;
|
OFile->FileSize = (UINTN)NewSizeInBytes;
|
||||||
OFile->Dirty = TRUE;
|
OFile->Dirty = TRUE;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
@ -596,22 +598,22 @@ FatOFilePosition (
|
|||||||
//
|
//
|
||||||
Cluster = OFile->FileCurrentCluster;
|
Cluster = OFile->FileCurrentCluster;
|
||||||
StartPos = OFile->Position;
|
StartPos = OFile->Position;
|
||||||
if (Position < StartPos || OFile->FileCluster == Cluster) {
|
if ((Position < StartPos) || (OFile->FileCluster == Cluster)) {
|
||||||
StartPos = 0;
|
StartPos = 0;
|
||||||
Cluster = OFile->FileCluster;
|
Cluster = OFile->FileCluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (StartPos + ClusterSize <= Position) {
|
while (StartPos + ClusterSize <= Position) {
|
||||||
StartPos += ClusterSize;
|
StartPos += ClusterSize;
|
||||||
if (Cluster == FAT_CLUSTER_FREE || (Cluster >= FAT_CLUSTER_SPECIAL)) {
|
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
|
||||||
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatOFilePosition:"" cluster chain corrupt\n"));
|
DEBUG ((DEBUG_INIT | DEBUG_ERROR, "FatOFilePosition:" " cluster chain corrupt\n"));
|
||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cluster = FatGetFatEntry (Volume, Cluster);
|
Cluster = FatGetFatEntry (Volume, Cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
|
if ((Cluster < FAT_MIN_CLUSTER) || (Cluster > Volume->MaxCluster + 1)) {
|
||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,6 +657,7 @@ FatPhysicalDirSize (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
|
|
||||||
ASSERT_VOLUME_LOCKED (Volume);
|
ASSERT_VOLUME_LOCKED (Volume);
|
||||||
//
|
//
|
||||||
// Run the cluster chain for the OFile
|
// Run the cluster chain for the OFile
|
||||||
@ -666,7 +669,7 @@ FatPhysicalDirSize (
|
|||||||
//
|
//
|
||||||
if (Cluster != 0) {
|
if (Cluster != 0) {
|
||||||
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
|
while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
|
||||||
if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
|
if ((Cluster == FAT_CLUSTER_FREE) || (Cluster >= FAT_CLUSTER_SPECIAL)) {
|
||||||
DEBUG (
|
DEBUG (
|
||||||
(DEBUG_INIT | DEBUG_ERROR,
|
(DEBUG_INIT | DEBUG_ERROR,
|
||||||
"FATDirSize: cluster chain corrupt\n")
|
"FATDirSize: cluster chain corrupt\n")
|
||||||
@ -700,8 +703,9 @@ FatPhysicalFileSize (
|
|||||||
{
|
{
|
||||||
UINTN ClusterSizeMask;
|
UINTN ClusterSizeMask;
|
||||||
UINT64 PhysicalSize;
|
UINT64 PhysicalSize;
|
||||||
|
|
||||||
ClusterSizeMask = Volume->ClusterSize - 1;
|
ClusterSizeMask = Volume->ClusterSize - 1;
|
||||||
PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64) ClusterSizeMask));
|
PhysicalSize = (RealSize + ClusterSizeMask) & (~((UINT64)ClusterSizeMask));
|
||||||
return PhysicalSize;
|
return PhysicalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,7 +727,6 @@ FatComputeFreeInfo (
|
|||||||
// If we don't have valid info, compute it now
|
// If we don't have valid info, compute it now
|
||||||
//
|
//
|
||||||
if (!Volume->FreeInfoValid) {
|
if (!Volume->FreeInfoValid) {
|
||||||
|
|
||||||
Volume->FreeInfoValid = TRUE;
|
Volume->FreeInfoValid = TRUE;
|
||||||
Volume->FatInfoSector.FreeInfo.ClusterCount = 0;
|
Volume->FatInfoSector.FreeInfo.ClusterCount = 0;
|
||||||
for (Index = Volume->MaxCluster + 1; Index >= FAT_MIN_CLUSTER; Index--) {
|
for (Index = Volume->MaxCluster + 1; Index >= FAT_MIN_CLUSTER; Index--) {
|
||||||
@ -733,7 +736,7 @@ FatComputeFreeInfo (
|
|||||||
|
|
||||||
if (FatGetFatEntry (Volume, Index) == FAT_CLUSTER_FREE) {
|
if (FatGetFatEntry (Volume, Index) == FAT_CLUSTER_FREE) {
|
||||||
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
|
Volume->FatInfoSector.FreeInfo.ClusterCount += 1;
|
||||||
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32) Index;
|
Volume->FatInfoSector.FreeInfo.NextCluster = (UINT32)Index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ FatFlushEx (
|
|||||||
if (Volume->ReadOnly) {
|
if (Volume->ReadOnly) {
|
||||||
return EFI_WRITE_PROTECTED;
|
return EFI_WRITE_PROTECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If read only, return error
|
// If read only, return error
|
||||||
//
|
//
|
||||||
@ -67,6 +68,7 @@ FatFlushEx (
|
|||||||
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
|
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task = FatCreateTask (IFile, Token);
|
Task = FatCreateTask (IFile, Token);
|
||||||
if (Task == NULL) {
|
if (Task == NULL) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
@ -193,6 +195,7 @@ FatIFileClose (
|
|||||||
if (OFile->CheckLink.ForwardLink == NULL) {
|
if (OFile->CheckLink.ForwardLink == NULL) {
|
||||||
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
|
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Done. Free the open instance structure
|
// Done. Free the open instance structure
|
||||||
//
|
//
|
||||||
@ -250,10 +253,11 @@ FatOFileFlush (
|
|||||||
DirEnt->Entry.Attributes |= FAT_ATTRIBUTE_ARCHIVE;
|
DirEnt->Entry.Attributes |= FAT_ATTRIBUTE_ARCHIVE;
|
||||||
OFile->Archive = FALSE;
|
OFile->Archive = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Write the directory entry
|
// Write the directory entry
|
||||||
//
|
//
|
||||||
if (Parent != NULL && !DirEnt->Invalid) {
|
if ((Parent != NULL) && !DirEnt->Invalid) {
|
||||||
//
|
//
|
||||||
// Write the OFile's directory entry
|
// Write the OFile's directory entry
|
||||||
//
|
//
|
||||||
@ -265,11 +269,13 @@ FatOFileFlush (
|
|||||||
|
|
||||||
OFile->Dirty = FALSE;
|
OFile->Dirty = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check the parent
|
// Check the parent
|
||||||
//
|
//
|
||||||
OFile = Parent;
|
OFile = Parent;
|
||||||
} while (OFile != NULL);
|
} while (OFile != NULL);
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,6 +314,7 @@ FatCheckOFileRef (
|
|||||||
//
|
//
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Free the Ofile
|
// Free the Ofile
|
||||||
//
|
//
|
||||||
@ -380,12 +387,14 @@ FatCleanupVolume (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Flag the OFile
|
// Flag the OFile
|
||||||
//
|
//
|
||||||
if (OFile != NULL) {
|
if (OFile != NULL) {
|
||||||
FatSetVolumeError (OFile, EfiStatus);
|
FatSetVolumeError (OFile, EfiStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Clean up any dangling OFiles that don't have IFiles
|
// Clean up any dangling OFiles that don't have IFiles
|
||||||
// we don't check return status here because we want the
|
// we don't check return status here because we want the
|
||||||
@ -403,16 +412,18 @@ FatCleanupVolume (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Update that the volume is not dirty
|
// Update that the volume is not dirty
|
||||||
//
|
//
|
||||||
if (Volume->FatDirty && Volume->FatType != Fat12) {
|
if (Volume->FatDirty && (Volume->FatType != Fat12)) {
|
||||||
Volume->FatDirty = FALSE;
|
Volume->FatDirty = FALSE;
|
||||||
Status = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue);
|
Status = FatAccessVolumeDirty (Volume, WriteFat, &Volume->NotDirtyValue);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Flush all dirty cache entries to disk
|
// Flush all dirty cache entries to disk
|
||||||
//
|
//
|
||||||
@ -421,11 +432,12 @@ FatCleanupVolume (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the volume is cleared , remove it.
|
// If the volume is cleared , remove it.
|
||||||
// The only time volume be invalidated is in DriverBindingStop.
|
// The only time volume be invalidated is in DriverBindingStop.
|
||||||
//
|
//
|
||||||
if (Volume->Root == NULL && !Volume->Valid) {
|
if ((Volume->Root == NULL) && !Volume->Valid) {
|
||||||
//
|
//
|
||||||
// Free the volume structure
|
// Free the volume structure
|
||||||
//
|
//
|
||||||
@ -458,6 +470,7 @@ FatSetVolumeError (
|
|||||||
if (!EFI_ERROR (OFile->Error)) {
|
if (!EFI_ERROR (OFile->Error)) {
|
||||||
OFile->Error = Status;
|
OFile->Error = Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set the error on each child OFile
|
// Set the error on each child OFile
|
||||||
//
|
//
|
||||||
|
@ -25,6 +25,7 @@ FatHashLongName (
|
|||||||
{
|
{
|
||||||
UINT32 HashValue;
|
UINT32 HashValue;
|
||||||
CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
|
CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
|
||||||
|
|
||||||
StrnCpyS (
|
StrnCpyS (
|
||||||
UpCasedLongFileName,
|
UpCasedLongFileName,
|
||||||
ARRAY_SIZE (UpCasedLongFileName),
|
ARRAY_SIZE (UpCasedLongFileName),
|
||||||
@ -52,6 +53,7 @@ FatHashShortName (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 HashValue;
|
UINT32 HashValue;
|
||||||
|
|
||||||
gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);
|
gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);
|
||||||
return (HashValue & HASH_TABLE_MASK);
|
return (HashValue & HASH_TABLE_MASK);
|
||||||
}
|
}
|
||||||
@ -73,10 +75,12 @@ FatLongNameHashSearch (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_DIRENT **PreviousHashNode;
|
FAT_DIRENT **PreviousHashNode;
|
||||||
|
|
||||||
for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];
|
for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];
|
||||||
*PreviousHashNode != NULL;
|
*PreviousHashNode != NULL;
|
||||||
PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink
|
PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {
|
if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -102,10 +106,12 @@ FatShortNameHashSearch (
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_DIRENT **PreviousHashNode;
|
FAT_DIRENT **PreviousHashNode;
|
||||||
|
|
||||||
for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];
|
for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];
|
||||||
*PreviousHashNode != NULL;
|
*PreviousHashNode != NULL;
|
||||||
PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink
|
PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {
|
if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -142,13 +142,13 @@ FatGetVolumeInfo (
|
|||||||
|
|
||||||
Info->Size = ResultSize;
|
Info->Size = ResultSize;
|
||||||
Info->ReadOnly = Volume->ReadOnly;
|
Info->ReadOnly = Volume->ReadOnly;
|
||||||
Info->BlockSize = (UINT32) Volume->ClusterSize;
|
Info->BlockSize = (UINT32)Volume->ClusterSize;
|
||||||
Info->VolumeSize = LShiftU64 (Volume->MaxCluster, ClusterAlignment);
|
Info->VolumeSize = LShiftU64 (Volume->MaxCluster, ClusterAlignment);
|
||||||
Info->FreeSpace = LShiftU64 (
|
Info->FreeSpace = LShiftU64 (
|
||||||
Volume->FatInfoSector.FreeInfo.ClusterCount,
|
Volume->FatInfoSector.FreeInfo.ClusterCount,
|
||||||
ClusterAlignment
|
ClusterAlignment
|
||||||
);
|
);
|
||||||
CopyMem ((CHAR8 *) Buffer + Size, Name, NameSize);
|
CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
*BufferSize = ResultSize;
|
*BufferSize = ResultSize;
|
||||||
@ -188,7 +188,7 @@ FatGetVolumeLabelInfo (
|
|||||||
Status = EFI_BUFFER_TOO_SMALL;
|
Status = EFI_BUFFER_TOO_SMALL;
|
||||||
if (*BufferSize >= ResultSize) {
|
if (*BufferSize >= ResultSize) {
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
CopyMem ((CHAR8 *) Buffer + Size, Name, NameSize);
|
CopyMem ((CHAR8 *)Buffer + Size, Name, NameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
*BufferSize = ResultSize;
|
*BufferSize = ResultSize;
|
||||||
@ -218,9 +218,9 @@ FatSetVolumeInfo (
|
|||||||
{
|
{
|
||||||
EFI_FILE_SYSTEM_INFO *Info;
|
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;
|
return EFI_BAD_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ FatSetVolumeLabelInfo (
|
|||||||
{
|
{
|
||||||
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) {
|
if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL + 2) {
|
||||||
return EFI_BAD_BUFFER_SIZE;
|
return EFI_BAD_BUFFER_SIZE;
|
||||||
@ -312,11 +312,12 @@ FatSetFileInfo (
|
|||||||
if (Parent == NULL) {
|
if (Parent == NULL) {
|
||||||
return EFI_ACCESS_DENIED;
|
return EFI_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Make sure there's a valid input buffer
|
// Make sure there's a valid input buffer
|
||||||
//
|
//
|
||||||
NewInfo = Buffer;
|
NewInfo = Buffer;
|
||||||
if (BufferSize < SIZE_OF_EFI_FILE_INFO + 2 || NewInfo->Size > BufferSize) {
|
if ((BufferSize < SIZE_OF_EFI_FILE_INFO + 2) || (NewInfo->Size > BufferSize)) {
|
||||||
return EFI_BAD_BUFFER_SIZE;
|
return EFI_BAD_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,17 +351,18 @@ FatSetFileInfo (
|
|||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewAttribute = (UINT8) NewInfo->Attribute;
|
NewAttribute = (UINT8)NewInfo->Attribute;
|
||||||
//
|
//
|
||||||
// Can not change the directory attribute bit
|
// Can not change the directory attribute bit
|
||||||
//
|
//
|
||||||
if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) {
|
if ((NewAttribute ^ DirEnt->Entry.Attributes) & EFI_FILE_DIRECTORY) {
|
||||||
return EFI_ACCESS_DENIED;
|
return EFI_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set the current attributes even if the IFile->ReadOnly is TRUE
|
// Set the current attributes even if the IFile->ReadOnly is TRUE
|
||||||
//
|
//
|
||||||
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
|
// 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
|
// File was not found. We do not allow rename of the current directory if
|
||||||
// there are open files below the current directory
|
// there are open files below the current directory
|
||||||
//
|
//
|
||||||
if (!IsListEmpty (&OFile->ChildHead) || Parent == OFile) {
|
if (!IsListEmpty (&OFile->ChildHead) || (Parent == OFile)) {
|
||||||
return EFI_ACCESS_DENIED;
|
return EFI_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,6 +388,7 @@ FatSetFileInfo (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create new dirent
|
// Create new dirent
|
||||||
//
|
//
|
||||||
@ -413,7 +416,7 @@ FatSetFileInfo (
|
|||||||
ASSERT (OFile->Parent != NULL);
|
ASSERT (OFile->Parent != NULL);
|
||||||
for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) {
|
for (DotOFile = OFile; DotOFile != OFile->Parent->Parent; DotOFile = DotOFile->Parent) {
|
||||||
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
||||||
if (EFI_ERROR (Status) || DirEnt == NULL || !FatIsDotDirEnt (DirEnt)) {
|
if (EFI_ERROR (Status) || (DirEnt == NULL) || !FatIsDotDirEnt (DirEnt)) {
|
||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,6 +427,7 @@ FatSetFileInfo (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the file is renamed, we should append the ARCHIVE attribute
|
// If the file is renamed, we should append the ARCHIVE attribute
|
||||||
//
|
//
|
||||||
@ -434,11 +438,12 @@ FatSetFileInfo (
|
|||||||
//
|
//
|
||||||
return EFI_ACCESS_DENIED;
|
return EFI_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the file size has changed, apply it
|
// If the file size has changed, apply it
|
||||||
//
|
//
|
||||||
if (NewInfo->FileSize != OFile->FileSize) {
|
if (NewInfo->FileSize != OFile->FileSize) {
|
||||||
if (OFile->ODir != NULL || ReadOnly) {
|
if ((OFile->ODir != NULL) || ReadOnly) {
|
||||||
//
|
//
|
||||||
// If this is a directory or the file is read only, we can't change the file size
|
// If this is a directory or the file is read only, we can't change the file size
|
||||||
//
|
//
|
||||||
@ -448,7 +453,7 @@ FatSetFileInfo (
|
|||||||
if (NewInfo->FileSize > OFile->FileSize) {
|
if (NewInfo->FileSize > OFile->FileSize) {
|
||||||
Status = FatExpandOFile (OFile, NewInfo->FileSize);
|
Status = FatExpandOFile (OFile, NewInfo->FileSize);
|
||||||
} else {
|
} else {
|
||||||
Status = FatTruncateOFile (OFile, (UINTN) NewInfo->FileSize);
|
Status = FatTruncateOFile (OFile, (UINTN)NewInfo->FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
|
@ -68,6 +68,7 @@ FatAllocateVolume (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize cache
|
// Initialize cache
|
||||||
//
|
//
|
||||||
@ -75,6 +76,7 @@ FatAllocateVolume (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Install our protocol interfaces on the device's handle
|
// Install our protocol interfaces on the device's handle
|
||||||
//
|
//
|
||||||
@ -87,6 +89,7 @@ FatAllocateVolume (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Volume installed
|
// Volume installed
|
||||||
//
|
//
|
||||||
@ -146,6 +149,7 @@ FatAbandonVolume (
|
|||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
LockedByMe = TRUE;
|
LockedByMe = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The volume is still being used. Hence, set error flag for all OFiles still in
|
// The volume is still being used. Hence, set error flag for all OFiles still in
|
||||||
// use. In two cases, we could get here. One is EFI_MEDIA_CHANGED, the other is
|
// use. In two cases, we could get here. One is EFI_MEDIA_CHANGED, the other is
|
||||||
@ -236,13 +240,14 @@ FatOpenDevice (
|
|||||||
SectorsPerFat = FatBs.FatBse.Fat32Bse.LargeSectorsPerFat;
|
SectorsPerFat = FatBs.FatBse.Fat32Bse.LargeSectorsPerFat;
|
||||||
FatType = Fat32;
|
FatType = Fat32;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Is boot sector a fat sector?
|
// Is boot sector a fat sector?
|
||||||
// (Note that so far we only know if the sector is FAT32 or not, we don't
|
// (Note that so far we only know if the sector is FAT32 or not, we don't
|
||||||
// know if the sector is Fat16 or Fat12 until later when we can compute
|
// know if the sector is Fat16 or Fat12 until later when we can compute
|
||||||
// the volume size)
|
// the volume size)
|
||||||
//
|
//
|
||||||
if (FatBs.FatBsb.ReservedSectors == 0 || FatBs.FatBsb.NumFats == 0 || Sectors == 0) {
|
if ((FatBs.FatBsb.ReservedSectors == 0) || (FatBs.FatBsb.NumFats == 0) || (Sectors == 0)) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +255,8 @@ FatOpenDevice (
|
|||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockAlignment = (UINT8) HighBitSet32 (FatBs.FatBsb.SectorSize);
|
BlockAlignment = (UINT8)HighBitSet32 (FatBs.FatBsb.SectorSize);
|
||||||
if (BlockAlignment > MAX_BLOCK_ALIGNMENT || BlockAlignment < MIN_BLOCK_ALIGNMENT) {
|
if ((BlockAlignment > MAX_BLOCK_ALIGNMENT) || (BlockAlignment < MIN_BLOCK_ALIGNMENT)) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,18 +264,20 @@ FatOpenDevice (
|
|||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
SectorsPerClusterAlignment = (UINT8) HighBitSet32 (FatBs.FatBsb.SectorsPerCluster);
|
SectorsPerClusterAlignment = (UINT8)HighBitSet32 (FatBs.FatBsb.SectorsPerCluster);
|
||||||
if (SectorsPerClusterAlignment > MAX_SECTORS_PER_CLUSTER_ALIGNMENT) {
|
if (SectorsPerClusterAlignment > MAX_SECTORS_PER_CLUSTER_ALIGNMENT) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FatBs.FatBsb.Media <= 0xf7 &&
|
if ((FatBs.FatBsb.Media <= 0xf7) &&
|
||||||
FatBs.FatBsb.Media != 0xf0 &&
|
(FatBs.FatBsb.Media != 0xf0) &&
|
||||||
FatBs.FatBsb.Media != 0x00 &&
|
(FatBs.FatBsb.Media != 0x00) &&
|
||||||
FatBs.FatBsb.Media != 0x01
|
(FatBs.FatBsb.Media != 0x01)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize fields the volume information for this FatType
|
// Initialize fields the volume information for this FatType
|
||||||
//
|
//
|
||||||
@ -278,6 +285,7 @@ FatOpenDevice (
|
|||||||
if (FatBs.FatBsb.RootEntries == 0) {
|
if (FatBs.FatBsb.RootEntries == 0) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Unpack fat12, fat16 info
|
// Unpack fat12, fat16 info
|
||||||
//
|
//
|
||||||
@ -286,9 +294,10 @@ FatOpenDevice (
|
|||||||
//
|
//
|
||||||
// If this is fat32, refuse to mount mirror-disabled volumes
|
// If this is fat32, refuse to mount mirror-disabled volumes
|
||||||
//
|
//
|
||||||
if ((SectorsPerFat == 0 || FatBs.FatBse.Fat32Bse.FsVersion != 0) || (FatBs.FatBse.Fat32Bse.ExtendedFlags & 0x80)) {
|
if (((SectorsPerFat == 0) || (FatBs.FatBse.Fat32Bse.FsVersion != 0)) || (FatBs.FatBse.Fat32Bse.ExtendedFlags & 0x80)) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Unpack fat32 info
|
// Unpack fat32 info
|
||||||
//
|
//
|
||||||
@ -334,12 +343,14 @@ FatOpenDevice (
|
|||||||
if (Volume->MaxCluster < FAT_MAX_FAT16_CLUSTER) {
|
if (Volume->MaxCluster < FAT_MAX_FAT16_CLUSTER) {
|
||||||
return EFI_VOLUME_CORRUPTED;
|
return EFI_VOLUME_CORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// fat32 fat-entries are 4 bytes
|
// fat32 fat-entries are 4 bytes
|
||||||
//
|
//
|
||||||
Volume->FatEntrySize = sizeof (UINT32);
|
Volume->FatEntrySize = sizeof (UINT32);
|
||||||
DirtyMask = FAT32_DIRTY_MASK;
|
DirtyMask = FAT32_DIRTY_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get the DirtyValue and NotDirtyValue
|
// Get the DirtyValue and NotDirtyValue
|
||||||
// We should keep the initial value as the NotDirtyValue
|
// We should keep the initial value as the NotDirtyValue
|
||||||
@ -353,6 +364,7 @@ FatOpenDevice (
|
|||||||
|
|
||||||
Volume->DirtyValue = Volume->NotDirtyValue & DirtyMask;
|
Volume->DirtyValue = Volume->NotDirtyValue & DirtyMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If present, read the fat hint info
|
// If present, read the fat hint info
|
||||||
//
|
//
|
||||||
@ -360,23 +372,27 @@ FatOpenDevice (
|
|||||||
Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize;
|
Volume->FreeInfoPos = FatBs.FatBse.Fat32Bse.FsInfoSector * BlockSize;
|
||||||
if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) {
|
if (FatBs.FatBse.Fat32Bse.FsInfoSector != 0) {
|
||||||
FatDiskIo (Volume, ReadDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, NULL);
|
FatDiskIo (Volume, ReadDisk, Volume->FreeInfoPos, sizeof (FAT_INFO_SECTOR), &Volume->FatInfoSector, NULL);
|
||||||
if (Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE &&
|
if ((Volume->FatInfoSector.Signature == FAT_INFO_SIGNATURE) &&
|
||||||
Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE &&
|
(Volume->FatInfoSector.InfoBeginSignature == FAT_INFO_BEGIN_SIGNATURE) &&
|
||||||
Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE &&
|
(Volume->FatInfoSector.InfoEndSignature == FAT_INFO_END_SIGNATURE) &&
|
||||||
Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster
|
(Volume->FatInfoSector.FreeInfo.ClusterCount <= Volume->MaxCluster)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
Volume->FreeInfoValid = TRUE;
|
Volume->FreeInfoValid = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Just make up a FreeInfo.NextCluster for use by allocate cluster
|
// Just make up a FreeInfo.NextCluster for use by allocate cluster
|
||||||
//
|
//
|
||||||
if (FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster ||
|
if ((FAT_MIN_CLUSTER > Volume->FatInfoSector.FreeInfo.NextCluster) ||
|
||||||
Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1
|
(Volume->FatInfoSector.FreeInfo.NextCluster > Volume->MaxCluster + 1)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
Volume->FatInfoSector.FreeInfo.NextCluster = FAT_MIN_CLUSTER;
|
Volume->FatInfoSector.FreeInfo.NextCluster = FAT_MIN_CLUSTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We are now defining FAT Type
|
// We are now defining FAT Type
|
||||||
//
|
//
|
||||||
|
@ -36,6 +36,7 @@ FatCreateTask (
|
|||||||
InitializeListHead (&Task->Subtasks);
|
InitializeListHead (&Task->Subtasks);
|
||||||
InitializeListHead (&Task->Link);
|
InitializeListHead (&Task->Link);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task;
|
return Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ FatDestroyTask (
|
|||||||
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
|
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
|
||||||
Link = FatDestroySubtask (Subtask);
|
Link = FatDestroySubtask (Subtask);
|
||||||
}
|
}
|
||||||
|
|
||||||
FreePool (Task);
|
FreePool (Task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,10 +157,10 @@ FatQueueTask (
|
|||||||
for ( Link = GetFirstNode (&Task->Subtasks), NextLink = GetNextNode (&Task->Subtasks, Link)
|
for ( Link = GetFirstNode (&Task->Subtasks), NextLink = GetNextNode (&Task->Subtasks, Link)
|
||||||
; Link != &Task->Subtasks
|
; Link != &Task->Subtasks
|
||||||
; Link = NextLink, NextLink = Link->ForwardLink
|
; Link = NextLink, NextLink = Link->ForwardLink
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
|
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
|
||||||
if (Subtask->Write) {
|
if (Subtask->Write) {
|
||||||
|
|
||||||
Status = IFile->OFile->Volume->DiskIo2->WriteDiskEx (
|
Status = IFile->OFile->Volume->DiskIo2->WriteDiskEx (
|
||||||
IFile->OFile->Volume->DiskIo2,
|
IFile->OFile->Volume->DiskIo2,
|
||||||
IFile->OFile->Volume->MediaId,
|
IFile->OFile->Volume->MediaId,
|
||||||
@ -177,6 +179,7 @@ FatQueueTask (
|
|||||||
Subtask->Buffer
|
Subtask->Buffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -260,7 +263,7 @@ FatOnAccessComplete (
|
|||||||
//
|
//
|
||||||
ASSERT (EfiGetCurrentTpl () == FatTaskLock.Tpl);
|
ASSERT (EfiGetCurrentTpl () == FatTaskLock.Tpl);
|
||||||
|
|
||||||
Subtask = (FAT_SUBTASK *) Context;
|
Subtask = (FAT_SUBTASK *)Context;
|
||||||
Task = Subtask->Task;
|
Task = Subtask->Task;
|
||||||
Status = Subtask->DiskIo2Token.TransactionStatus;
|
Status = Subtask->DiskIo2Token.TransactionStatus;
|
||||||
|
|
||||||
@ -354,7 +357,7 @@ FatDiskIo (
|
|||||||
} else {
|
} else {
|
||||||
Subtask->Signature = FAT_SUBTASK_SIGNATURE;
|
Subtask->Signature = FAT_SUBTASK_SIGNATURE;
|
||||||
Subtask->Task = Task;
|
Subtask->Task = Task;
|
||||||
Subtask->Write = (BOOLEAN) (IoMode == WriteDisk);
|
Subtask->Write = (BOOLEAN)(IoMode == WriteDisk);
|
||||||
Subtask->Offset = Offset;
|
Subtask->Offset = Offset;
|
||||||
Subtask->Buffer = Buffer;
|
Subtask->Buffer = Buffer;
|
||||||
Subtask->BufferSize = BufferSize;
|
Subtask->BufferSize = BufferSize;
|
||||||
@ -464,6 +467,7 @@ FatFreeVolume (
|
|||||||
if (Volume->CacheBuffer != NULL) {
|
if (Volume->CacheBuffer != NULL) {
|
||||||
FreePool (Volume->CacheBuffer);
|
FreePool (Volume->CacheBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Free directory cache
|
// Free directory cache
|
||||||
//
|
//
|
||||||
@ -489,7 +493,7 @@ FatEfiTimeToFatTime (
|
|||||||
// ignores timezone info in source ETime
|
// ignores timezone info in source ETime
|
||||||
//
|
//
|
||||||
if (ETime->Year > 1980) {
|
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) {
|
if (ETime->Year >= 1980 + FAT_MAX_YEAR_FROM_1980) {
|
||||||
@ -500,7 +504,7 @@ FatEfiTimeToFatTime (
|
|||||||
FTime->Date.Day = ETime->Day;
|
FTime->Date.Day = ETime->Day;
|
||||||
FTime->Time.Hour = ETime->Hour;
|
FTime->Time.Hour = ETime->Hour;
|
||||||
FTime->Time.Minute = ETime->Minute;
|
FTime->Time.Minute = ETime->Minute;
|
||||||
FTime->Time.DoubleSecond = (UINT16) (ETime->Second / 2);
|
FTime->Time.DoubleSecond = (UINT16)(ETime->Second / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -517,12 +521,12 @@ FatFatTimeToEfiTime (
|
|||||||
OUT EFI_TIME *ETime
|
OUT EFI_TIME *ETime
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ETime->Year = (UINT16) (FTime->Date.Year + 1980);
|
ETime->Year = (UINT16)(FTime->Date.Year + 1980);
|
||||||
ETime->Month = (UINT8) FTime->Date.Month;
|
ETime->Month = (UINT8)FTime->Date.Month;
|
||||||
ETime->Day = (UINT8) FTime->Date.Day;
|
ETime->Day = (UINT8)FTime->Date.Day;
|
||||||
ETime->Hour = (UINT8) FTime->Time.Hour;
|
ETime->Hour = (UINT8)FTime->Time.Hour;
|
||||||
ETime->Minute = (UINT8) FTime->Time.Minute;
|
ETime->Minute = (UINT8)FTime->Time.Minute;
|
||||||
ETime->Second = (UINT8) (FTime->Time.DoubleSecond * 2);
|
ETime->Second = (UINT8)(FTime->Time.DoubleSecond * 2);
|
||||||
ETime->Nanosecond = 0;
|
ETime->Nanosecond = 0;
|
||||||
ETime->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
|
ETime->TimeZone = EFI_UNSPECIFIED_TIMEZONE;
|
||||||
ETime->Daylight = 0;
|
ETime->Daylight = 0;
|
||||||
@ -579,30 +583,30 @@ FatIsValidTime (
|
|||||||
// Check the fields for range problems
|
// Check the fields for range problems
|
||||||
// Fat can only support from 1980
|
// Fat can only support from 1980
|
||||||
//
|
//
|
||||||
if (Time->Year < 1980 ||
|
if ((Time->Year < 1980) ||
|
||||||
Time->Month < 1 ||
|
(Time->Month < 1) ||
|
||||||
Time->Month > 12 ||
|
(Time->Month > 12) ||
|
||||||
Time->Day < 1 ||
|
(Time->Day < 1) ||
|
||||||
Time->Day > 31 ||
|
(Time->Day > 31) ||
|
||||||
Time->Hour > 23 ||
|
(Time->Hour > 23) ||
|
||||||
Time->Minute > 59 ||
|
(Time->Minute > 59) ||
|
||||||
Time->Second > 59 ||
|
(Time->Second > 59) ||
|
||||||
Time->Nanosecond > 999999999
|
(Time->Nanosecond > 999999999)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
ValidTime = FALSE;
|
ValidTime = FALSE;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Perform a more specific check of the day of the month
|
// Perform a more specific check of the day of the month
|
||||||
//
|
//
|
||||||
Day = mMonthDays[Time->Month - 1];
|
Day = mMonthDays[Time->Month - 1];
|
||||||
if (Time->Month == 2 && IS_LEAP_YEAR (Time->Year)) {
|
if ((Time->Month == 2) && IS_LEAP_YEAR (Time->Year)) {
|
||||||
Day += 1;
|
Day += 1;
|
||||||
//
|
//
|
||||||
// 1 extra day this month
|
// 1 extra day this month
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Time->Day > Day) {
|
if (Time->Day > Day) {
|
||||||
ValidTime = FALSE;
|
ValidTime = FALSE;
|
||||||
}
|
}
|
||||||
|
@ -100,10 +100,11 @@ FatOFileOpen (
|
|||||||
DirEnt = NULL;
|
DirEnt = NULL;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
ASSERT_VOLUME_LOCKED (Volume);
|
ASSERT_VOLUME_LOCKED (Volume);
|
||||||
WriteMode = (BOOLEAN) (OpenMode & EFI_FILE_MODE_WRITE);
|
WriteMode = (BOOLEAN)(OpenMode & EFI_FILE_MODE_WRITE);
|
||||||
if (Volume->ReadOnly && WriteMode) {
|
if (Volume->ReadOnly && WriteMode) {
|
||||||
return EFI_WRITE_PROTECTED;
|
return EFI_WRITE_PROTECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Verify the source file handle isn't in an error state
|
// Verify the source file handle isn't in an error state
|
||||||
//
|
//
|
||||||
@ -111,6 +112,7 @@ FatOFileOpen (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get new OFile for the file
|
// Get new OFile for the file
|
||||||
//
|
//
|
||||||
@ -150,14 +152,16 @@ FatOFileOpen (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the file's attribute is read only, and the open is for
|
// If the file's attribute is read only, and the open is for
|
||||||
// read-write, then the access is denied.
|
// read-write, then the access is denied.
|
||||||
//
|
//
|
||||||
FileAttributes = OFile->DirEnt->Entry.Attributes;
|
FileAttributes = OFile->DirEnt->Entry.Attributes;
|
||||||
if ((FileAttributes & EFI_FILE_READ_ONLY) != 0 && (FileAttributes & FAT_ATTRIBUTE_DIRECTORY) == 0 && WriteMode) {
|
if (((FileAttributes & EFI_FILE_READ_ONLY) != 0) && ((FileAttributes & FAT_ATTRIBUTE_DIRECTORY) == 0) && WriteMode) {
|
||||||
return EFI_ACCESS_DENIED;
|
return EFI_ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create an open instance of the OFile
|
// Create an open instance of the OFile
|
||||||
//
|
//
|
||||||
@ -166,7 +170,7 @@ FatOFileOpen (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
(*NewIFile)->ReadOnly = (BOOLEAN)!WriteMode;
|
(*NewIFile)->ReadOnly = (BOOLEAN) !WriteMode;
|
||||||
|
|
||||||
DEBUG ((DEBUG_INFO, "FSOpen: Open '%S' %r\n", FileName, Status));
|
DEBUG ((DEBUG_INFO, "FSOpen: Open '%S' %r\n", FileName, Status));
|
||||||
return FatOFileFlush (OFile);
|
return FatOFileFlush (OFile);
|
||||||
@ -214,6 +218,7 @@ FatOpenEx (
|
|||||||
if (FileName == NULL) {
|
if (FileName == NULL) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check for a valid mode
|
// Check for a valid mode
|
||||||
//
|
//
|
||||||
@ -230,7 +235,7 @@ FatOpenEx (
|
|||||||
//
|
//
|
||||||
// Check for valid Attributes for file creation case.
|
// Check for valid Attributes for file creation case.
|
||||||
//
|
//
|
||||||
if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && (Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0) {
|
if (((OpenMode & EFI_FILE_MODE_CREATE) != 0) && ((Attributes & (EFI_FILE_READ_ONLY | (~EFI_FILE_VALID_ATTR))) != 0)) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +253,7 @@ FatOpenEx (
|
|||||||
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
|
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task = FatCreateTask (IFile, Token);
|
Task = FatCreateTask (IFile, Token);
|
||||||
if (Task == NULL) {
|
if (Task == NULL) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
@ -262,7 +268,7 @@ FatOpenEx (
|
|||||||
//
|
//
|
||||||
// Open the file
|
// 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
|
// If the file was opened, return the handle to the caller
|
||||||
@ -270,6 +276,7 @@ FatOpenEx (
|
|||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
*NewHandle = &NewIFile->Handle;
|
*NewHandle = &NewIFile->Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Unlock
|
// Unlock
|
||||||
//
|
//
|
||||||
|
@ -41,6 +41,7 @@ FatOpenVolume (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Open a new instance to the root
|
// Open a new instance to the root
|
||||||
//
|
//
|
||||||
|
@ -91,12 +91,14 @@ FatSetPosition (
|
|||||||
|
|
||||||
FatResetODirCursor (OFile);
|
FatResetODirCursor (OFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set the position
|
// Set the position
|
||||||
//
|
//
|
||||||
if (Position == (UINT64)-1) {
|
if (Position == (UINT64)-1) {
|
||||||
Position = OFile->FileSize;
|
Position = OFile->FileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Set the position
|
// Set the position
|
||||||
//
|
//
|
||||||
@ -131,7 +133,7 @@ FatIFileReadDir (
|
|||||||
|
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
ODir = OFile->ODir;
|
ODir = OFile->ODir;
|
||||||
CurrentPos = ((UINT32) IFile->Position) / sizeof (FAT_DIRECTORY_ENTRY);
|
CurrentPos = ((UINT32)IFile->Position) / sizeof (FAT_DIRECTORY_ENTRY);
|
||||||
|
|
||||||
//
|
//
|
||||||
// We need to relocate the directory
|
// We need to relocate the directory
|
||||||
@ -142,12 +144,13 @@ FatIFileReadDir (
|
|||||||
//
|
//
|
||||||
FatResetODirCursor (OFile);
|
FatResetODirCursor (OFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We seek the next directory entry's position
|
// We seek the next directory entry's position
|
||||||
//
|
//
|
||||||
do {
|
do {
|
||||||
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
||||||
if (EFI_ERROR (Status) || DirEnt == NULL) {
|
if (EFI_ERROR (Status) || (DirEnt == NULL)) {
|
||||||
//
|
//
|
||||||
// Something error occurred or reach the end of directory,
|
// Something error occurred or reach the end of directory,
|
||||||
// return 0 buffersize
|
// return 0 buffersize
|
||||||
@ -156,6 +159,7 @@ FatIFileReadDir (
|
|||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
} while (ODir->CurrentPos <= CurrentPos);
|
} while (ODir->CurrentPos <= CurrentPos);
|
||||||
|
|
||||||
Status = FatGetDirEntInfo (OFile->Volume, DirEnt, BufferSize, Buffer);
|
Status = FatGetDirEntInfo (OFile->Volume, DirEnt, BufferSize, Buffer);
|
||||||
|
|
||||||
Done:
|
Done:
|
||||||
@ -253,6 +257,7 @@ FatIFileAccess (
|
|||||||
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
|
if (FHand->Revision < EFI_FILE_PROTOCOL_REVISION2) {
|
||||||
return EFI_UNSUPPORTED;
|
return EFI_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
Task = FatCreateTask (IFile, Token);
|
Task = FatCreateTask (IFile, Token);
|
||||||
if (Task == NULL) {
|
if (Task == NULL) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
@ -283,7 +288,7 @@ FatIFileAccess (
|
|||||||
//
|
//
|
||||||
// Adjust the actual size read
|
// Adjust the actual size read
|
||||||
//
|
//
|
||||||
*BufferSize -= (UINTN) EndPosition - OFile->FileSize;
|
*BufferSize -= (UINTN)EndPosition - OFile->FileSize;
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// We expand the file size of OFile
|
// 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;
|
IFile->Position += *BufferSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -479,6 +484,7 @@ FatAccessOFile (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Clip length to block run
|
// Clip length to block run
|
||||||
//
|
//
|
||||||
@ -491,6 +497,7 @@ FatAccessOFile (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Data was successfully accessed
|
// Data was successfully accessed
|
||||||
//
|
//
|
||||||
@ -501,11 +508,13 @@ FatAccessOFile (
|
|||||||
OFile->Dirty = TRUE;
|
OFile->Dirty = TRUE;
|
||||||
OFile->Archive = TRUE;
|
OFile->Archive = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Make sure no outbound occurred
|
// Make sure no outbound occurred
|
||||||
//
|
//
|
||||||
ASSERT (Position <= OFile->FileSize);
|
ASSERT (Position <= OFile->FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Update the number of bytes accessed
|
// Update the number of bytes accessed
|
||||||
//
|
//
|
||||||
@ -584,7 +593,7 @@ FatWriteZeroPool (
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN) AppendedSize;
|
WriteSize = AppendedSize > BufferSize ? BufferSize : (UINTN)AppendedSize;
|
||||||
AppendedSize -= WriteSize;
|
AppendedSize -= WriteSize;
|
||||||
Status = FatAccessOFile (OFile, WriteData, WritePos, &WriteSize, ZeroBuffer, NULL);
|
Status = FatAccessOFile (OFile, WriteData, WritePos, &WriteSize, ZeroBuffer, NULL);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
|
@ -55,8 +55,8 @@ InitializeUnicodeCollationSupportWorker (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
|
Iso639Language = (BOOLEAN)(ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
|
||||||
GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL);
|
GetEfiGlobalVariable2 (VariableName, (VOID **)&Language, NULL);
|
||||||
|
|
||||||
ReturnStatus = EFI_UNSUPPORTED;
|
ReturnStatus = EFI_UNSUPPORTED;
|
||||||
for (Index = 0; Index < NumHandles; Index++) {
|
for (Index = 0; Index < NumHandles; Index++) {
|
||||||
@ -66,7 +66,7 @@ InitializeUnicodeCollationSupportWorker (
|
|||||||
Status = gBS->OpenProtocol (
|
Status = gBS->OpenProtocol (
|
||||||
Handles[Index],
|
Handles[Index],
|
||||||
ProtocolGuid,
|
ProtocolGuid,
|
||||||
(VOID **) &Uci,
|
(VOID **)&Uci,
|
||||||
AgentHandle,
|
AgentHandle,
|
||||||
NULL,
|
NULL,
|
||||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
@ -121,7 +121,6 @@ InitializeUnicodeCollationSupport (
|
|||||||
IN EFI_HANDLE AgentHandle
|
IN EFI_HANDLE AgentHandle
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
Status = EFI_UNSUPPORTED;
|
Status = EFI_UNSUPPORTED;
|
||||||
@ -133,7 +132,7 @@ InitializeUnicodeCollationSupport (
|
|||||||
AgentHandle,
|
AgentHandle,
|
||||||
&gEfiUnicodeCollation2ProtocolGuid,
|
&gEfiUnicodeCollation2ProtocolGuid,
|
||||||
L"PlatformLang",
|
L"PlatformLang",
|
||||||
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
|
(CONST CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
|
||||||
);
|
);
|
||||||
//
|
//
|
||||||
// If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
|
// If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
|
||||||
@ -144,14 +143,13 @@ InitializeUnicodeCollationSupport (
|
|||||||
AgentHandle,
|
AgentHandle,
|
||||||
&gEfiUnicodeCollationProtocolGuid,
|
&gEfiUnicodeCollationProtocolGuid,
|
||||||
L"Lang",
|
L"Lang",
|
||||||
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang)
|
(CONST CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLang)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
||||||
|
|
||||||
@ -179,7 +177,6 @@ FatStriCmp (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Uppercase a string.
|
Uppercase a string.
|
||||||
|
|
||||||
@ -198,7 +195,6 @@ FatStrUpr (
|
|||||||
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
|
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Lowercase a string
|
Lowercase a string
|
||||||
|
|
||||||
@ -217,7 +213,6 @@ FatStrLwr (
|
|||||||
mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
|
mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert FAT string to unicode string.
|
Convert FAT string to unicode string.
|
||||||
|
|
||||||
@ -237,13 +232,12 @@ FatFatToStr (
|
|||||||
{
|
{
|
||||||
ASSERT (Fat != NULL);
|
ASSERT (Fat != NULL);
|
||||||
ASSERT (String != NULL);
|
ASSERT (String != NULL);
|
||||||
ASSERT (((UINTN) String & 0x01) == 0);
|
ASSERT (((UINTN)String & 0x01) == 0);
|
||||||
ASSERT (mUnicodeCollationInterface != NULL);
|
ASSERT (mUnicodeCollationInterface != NULL);
|
||||||
|
|
||||||
mUnicodeCollationInterface->FatToStr (mUnicodeCollationInterface, FatSize, Fat, String);
|
mUnicodeCollationInterface->FatToStr (mUnicodeCollationInterface, FatSize, Fat, String);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Convert unicode string to Fat string.
|
Convert unicode string to Fat string.
|
||||||
|
|
||||||
|
@ -60,8 +60,8 @@ FatFindEltoritoPartitions (
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *) PrivateData->BlockData;
|
VolDescriptor = (CDROM_VOLUME_DESCRIPTOR *)PrivateData->BlockData;
|
||||||
Catalog = (ELTORITO_CATALOG *) VolDescriptor;
|
Catalog = (ELTORITO_CATALOG *)VolDescriptor;
|
||||||
|
|
||||||
//
|
//
|
||||||
// the ISO-9660 volume descriptor starts at 32k on the media
|
// the ISO-9660 volume descriptor starts at 32k on the media
|
||||||
@ -74,7 +74,6 @@ FatFindEltoritoPartitions (
|
|||||||
// Loop: handle one volume descriptor per time
|
// Loop: handle one volume descriptor per time
|
||||||
//
|
//
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
|
|
||||||
VolDescriptorLba += 1;
|
VolDescriptorLba += 1;
|
||||||
if (VolDescriptorLba > ParentBlockDev->LastBlock) {
|
if (VolDescriptorLba > ParentBlockDev->LastBlock) {
|
||||||
//
|
//
|
||||||
@ -93,23 +92,27 @@ FatFindEltoritoPartitions (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check for valid volume descriptor signature
|
// Check for valid volume descriptor signature
|
||||||
//
|
//
|
||||||
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_END ||
|
if ((VolDescriptor->Unknown.Type == CDVOL_TYPE_END) ||
|
||||||
CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0
|
(CompareMem (VolDescriptor->Unknown.Id, CDVOL_ID, sizeof (VolDescriptor->Unknown.Id)) != 0)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// end of Volume descriptor list
|
// end of Volume descriptor list
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
|
// Read the Volume Space Size from Primary Volume Descriptor 81-88 byte
|
||||||
//
|
//
|
||||||
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
|
if (VolDescriptor->Unknown.Type == CDVOL_TYPE_CODED) {
|
||||||
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
|
VolSpaceSize = VolDescriptor->PrimaryVolume.VolSpaceSize[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Is it an El Torito volume descriptor?
|
// Is it an El Torito volume descriptor?
|
||||||
//
|
//
|
||||||
@ -117,9 +120,11 @@ FatFindEltoritoPartitions (
|
|||||||
VolDescriptor->BootRecordVolume.SystemId,
|
VolDescriptor->BootRecordVolume.SystemId,
|
||||||
CDVOL_ELTORITO_ID,
|
CDVOL_ELTORITO_ID,
|
||||||
sizeof (CDVOL_ELTORITO_ID) - 1
|
sizeof (CDVOL_ELTORITO_ID) - 1
|
||||||
) != 0) {
|
) != 0)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read in the boot El Torito boot catalog
|
// Read in the boot El Torito boot catalog
|
||||||
//
|
//
|
||||||
@ -138,16 +143,17 @@ FatFindEltoritoPartitions (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We don't care too much about the Catalog header's contents, but we do want
|
// We don't care too much about the Catalog header's contents, but we do want
|
||||||
// to make sure it looks like a Catalog header
|
// to make sure it looks like a Catalog header
|
||||||
//
|
//
|
||||||
if (Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG || Catalog->Catalog.Id55AA != 0xAA55) {
|
if ((Catalog->Catalog.Indicator != ELTORITO_ID_CATALOG) || (Catalog->Catalog.Id55AA != 0xAA55)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Check = 0;
|
Check = 0;
|
||||||
CheckBuffer = (UINT16 *) Catalog;
|
CheckBuffer = (UINT16 *)Catalog;
|
||||||
for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
|
for (Index = 0; Index < sizeof (ELTORITO_CATALOG) / sizeof (UINT16); Index += 1) {
|
||||||
Check += CheckBuffer[Index];
|
Check += CheckBuffer[Index];
|
||||||
}
|
}
|
||||||
@ -166,7 +172,7 @@ FatFindEltoritoPartitions (
|
|||||||
//
|
//
|
||||||
// Check this entry
|
// Check this entry
|
||||||
//
|
//
|
||||||
if (Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE || Catalog->Boot.Lba == 0) {
|
if ((Catalog->Boot.Indicator != ELTORITO_ID_SECTION_BOOTABLE) || (Catalog->Boot.Lba == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +180,6 @@ FatFindEltoritoPartitions (
|
|||||||
SectorCount = Catalog->Boot.SectorCount;
|
SectorCount = Catalog->Boot.SectorCount;
|
||||||
|
|
||||||
switch (Catalog->Boot.MediaType) {
|
switch (Catalog->Boot.MediaType) {
|
||||||
|
|
||||||
case ELTORITO_NO_EMULATION:
|
case ELTORITO_NO_EMULATION:
|
||||||
SubBlockSize = ParentBlockDev->BlockSize;
|
SubBlockSize = ParentBlockDev->BlockSize;
|
||||||
SectorCount = Catalog->Boot.SectorCount;
|
SectorCount = Catalog->Boot.SectorCount;
|
||||||
@ -202,13 +207,13 @@ FatFindEltoritoPartitions (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (SectorCount < 2) {
|
if (SectorCount < 2) {
|
||||||
SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32) (ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32) (VolSpaceSize - Catalog->Boot.Lba);
|
SectorCount = (VolSpaceSize > ParentBlockDev->LastBlock + 1) ? (UINT32)(ParentBlockDev->LastBlock - Catalog->Boot.Lba + 1) : (UINT32)(VolSpaceSize - Catalog->Boot.Lba);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register this partition
|
// Register this partition
|
||||||
//
|
//
|
||||||
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
|
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
|
||||||
|
|
||||||
Found = TRUE;
|
Found = TRUE;
|
||||||
|
|
||||||
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
|
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
|
||||||
@ -229,5 +234,4 @@ FatFindEltoritoPartitions (
|
|||||||
ParentBlockDev->PartitionChecked = TRUE;
|
ParentBlockDev->PartitionChecked = TRUE;
|
||||||
|
|
||||||
return Found;
|
return Found;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
|
|
||||||
#include "FatLitePeim.h"
|
#include "FatLitePeim.h"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check if there is a valid FAT in the corresponding Block device
|
Check if there is a valid FAT in the corresponding Block device
|
||||||
of the volume and if yes, fill in the relevant fields for the
|
of the volume and if yes, fill in the relevant fields for the
|
||||||
@ -60,8 +59,8 @@ FatGetBpbInfo (
|
|||||||
}
|
}
|
||||||
|
|
||||||
CopyMem (
|
CopyMem (
|
||||||
(UINT8 *) (&Bpb),
|
(UINT8 *)(&Bpb),
|
||||||
(UINT8 *) (&BpbEx),
|
(UINT8 *)(&BpbEx),
|
||||||
sizeof (PEI_FAT_BOOT_SECTOR)
|
sizeof (PEI_FAT_BOOT_SECTOR)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -77,60 +76,65 @@ FatGetBpbInfo (
|
|||||||
SectorsPerFat = BpbEx.LargeSectorsPerFat;
|
SectorsPerFat = BpbEx.LargeSectorsPerFat;
|
||||||
Volume->FatType = Fat32;
|
Volume->FatType = Fat32;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Filter out those not a FAT
|
// Filter out those not a FAT
|
||||||
//
|
//
|
||||||
if (Bpb.Ia32Jump[0] != 0xe9 && Bpb.Ia32Jump[0] != 0xeb && Bpb.Ia32Jump[0] != 0x49) {
|
if ((Bpb.Ia32Jump[0] != 0xe9) && (Bpb.Ia32Jump[0] != 0xeb) && (Bpb.Ia32Jump[0] != 0x49)) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bpb.ReservedSectors == 0 || Bpb.NoFats == 0 || Sectors == 0) {
|
if ((Bpb.ReservedSectors == 0) || (Bpb.NoFats == 0) || (Sectors == 0)) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bpb.SectorsPerCluster != 1 &&
|
if ((Bpb.SectorsPerCluster != 1) &&
|
||||||
Bpb.SectorsPerCluster != 2 &&
|
(Bpb.SectorsPerCluster != 2) &&
|
||||||
Bpb.SectorsPerCluster != 4 &&
|
(Bpb.SectorsPerCluster != 4) &&
|
||||||
Bpb.SectorsPerCluster != 8 &&
|
(Bpb.SectorsPerCluster != 8) &&
|
||||||
Bpb.SectorsPerCluster != 16 &&
|
(Bpb.SectorsPerCluster != 16) &&
|
||||||
Bpb.SectorsPerCluster != 32 &&
|
(Bpb.SectorsPerCluster != 32) &&
|
||||||
Bpb.SectorsPerCluster != 64 &&
|
(Bpb.SectorsPerCluster != 64) &&
|
||||||
Bpb.SectorsPerCluster != 128
|
(Bpb.SectorsPerCluster != 128)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Volume->FatType == Fat32 && (SectorsPerFat == 0 || BpbEx.FsVersion != 0)) {
|
if ((Volume->FatType == Fat32) && ((SectorsPerFat == 0) || (BpbEx.FsVersion != 0))) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Bpb.Media != 0xf0 &&
|
if ((Bpb.Media != 0xf0) &&
|
||||||
Bpb.Media != 0xf8 &&
|
(Bpb.Media != 0xf8) &&
|
||||||
Bpb.Media != 0xf9 &&
|
(Bpb.Media != 0xf9) &&
|
||||||
Bpb.Media != 0xfb &&
|
(Bpb.Media != 0xfb) &&
|
||||||
Bpb.Media != 0xfc &&
|
(Bpb.Media != 0xfc) &&
|
||||||
Bpb.Media != 0xfd &&
|
(Bpb.Media != 0xfd) &&
|
||||||
Bpb.Media != 0xfe &&
|
(Bpb.Media != 0xfe) &&
|
||||||
Bpb.Media != 0xff &&
|
(Bpb.Media != 0xff) &&
|
||||||
//
|
//
|
||||||
// FujitsuFMR
|
// FujitsuFMR
|
||||||
//
|
//
|
||||||
Bpb.Media != 0x00 &&
|
(Bpb.Media != 0x00) &&
|
||||||
Bpb.Media != 0x01 &&
|
(Bpb.Media != 0x01) &&
|
||||||
Bpb.Media != 0xfa
|
(Bpb.Media != 0xfa)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Volume->FatType != Fat32 && Bpb.RootEntries == 0) {
|
if ((Volume->FatType != Fat32) && (Bpb.RootEntries == 0)) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If this is fat32, refuse to mount mirror-disabled volumes
|
// If this is fat32, refuse to mount mirror-disabled volumes
|
||||||
//
|
//
|
||||||
if (Volume->FatType == Fat32 && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
|
if ((Volume->FatType == Fat32) && ((BpbEx.ExtendedFlags & 0x80) != 0)) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fill in the volume structure fields
|
// Fill in the volume structure fields
|
||||||
// (Sectors & SectorsPerFat is computed earlier already)
|
// (Sectors & SectorsPerFat is computed earlier already)
|
||||||
@ -149,14 +153,13 @@ FatGetBpbInfo (
|
|||||||
Volume->FatPos = MultU64x32 (FatLba, Volume->SectorSize);
|
Volume->FatPos = MultU64x32 (FatLba, Volume->SectorSize);
|
||||||
Volume->RootDirPos = MultU64x32 (RootLba, Volume->SectorSize);
|
Volume->RootDirPos = MultU64x32 (RootLba, Volume->SectorSize);
|
||||||
Volume->FirstClusterPos = MultU64x32 (FirstClusterLba, 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;
|
Volume->RootDirCluster = BpbEx.RootDirFirstCluster;
|
||||||
|
|
||||||
//
|
//
|
||||||
// If this is not a fat32, determine if it's a fat16 or fat12
|
// If this is not a fat32, determine if it's a fat16 or fat12
|
||||||
//
|
//
|
||||||
if (Volume->FatType != Fat32) {
|
if (Volume->FatType != Fat32) {
|
||||||
|
|
||||||
if (Volume->MaxCluster >= 65525) {
|
if (Volume->MaxCluster >= 65525) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
@ -167,7 +170,6 @@ FatGetBpbInfo (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets the next cluster in the cluster chain
|
Gets the next cluster in the cluster chain
|
||||||
|
|
||||||
@ -207,7 +209,6 @@ FatGetNextCluster (
|
|||||||
if ((*NextCluster) >= 0x0ffffff7) {
|
if ((*NextCluster) >= 0x0ffffff7) {
|
||||||
*NextCluster |= (-1 &~0xf);
|
*NextCluster |= (-1 &~0xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (Volume->FatType == Fat16) {
|
} else if (Volume->FatType == Fat16) {
|
||||||
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
|
FatEntryPos = Volume->FatPos + MultU64x32 (2, Cluster);
|
||||||
|
|
||||||
@ -219,7 +220,6 @@ FatGetNextCluster (
|
|||||||
if ((*NextCluster) >= 0xfff7) {
|
if ((*NextCluster) >= 0xfff7) {
|
||||||
*NextCluster |= (-1 &~0xf);
|
*NextCluster |= (-1 &~0xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
|
FatEntryPos = Volume->FatPos + DivU64x32Remainder (MultU64x32 (3, Cluster), 2, &Dummy);
|
||||||
|
|
||||||
@ -230,6 +230,7 @@ FatGetNextCluster (
|
|||||||
} else {
|
} else {
|
||||||
*NextCluster = (*NextCluster) & 0x0fff;
|
*NextCluster = (*NextCluster) & 0x0fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
|
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
|
||||||
//
|
//
|
||||||
@ -243,10 +244,8 @@ FatGetNextCluster (
|
|||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
|
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
|
||||||
|
|
||||||
@ -274,24 +273,22 @@ FatSetFilePos (
|
|||||||
UINT32 PrevCluster;
|
UINT32 PrevCluster;
|
||||||
|
|
||||||
if (File->IsFixedRootDir) {
|
if (File->IsFixedRootDir) {
|
||||||
|
|
||||||
if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {
|
if (Pos >= MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos) {
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
File->CurrentPos += Pos;
|
File->CurrentPos += Pos;
|
||||||
File->StraightReadAmount = (UINT32) (MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
|
File->StraightReadAmount = (UINT32)(MultU64x32 (File->Volume->RootEntries, 32) - File->CurrentPos);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
|
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
|
||||||
AlignedPos = (UINT32) File->CurrentPos - (UINT32) Offset;
|
AlignedPos = (UINT32)File->CurrentPos - (UINT32)Offset;
|
||||||
|
|
||||||
while
|
while
|
||||||
(
|
(
|
||||||
!FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
|
!FAT_CLUSTER_FUNCTIONAL (File->CurrentCluster) &&
|
||||||
AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
|
AlignedPos + File->Volume->ClusterSize <= File->CurrentPos + Pos
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
AlignedPos += File->Volume->ClusterSize;
|
AlignedPos += File->Volume->ClusterSize;
|
||||||
Status = FatGetNextCluster (
|
Status = FatGetNextCluster (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
@ -329,14 +326,12 @@ FatSetFilePos (
|
|||||||
}
|
}
|
||||||
|
|
||||||
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
|
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
|
||||||
File->StraightReadAmount -= (UINT32) Offset;
|
File->StraightReadAmount -= (UINT32)Offset;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads file data. Updates the file's CurrentPos.
|
Reads file data. Updates the file's CurrentPos.
|
||||||
|
|
||||||
@ -381,14 +376,13 @@ FatReadFile (
|
|||||||
Size,
|
Size,
|
||||||
Buffer
|
Buffer
|
||||||
);
|
);
|
||||||
File->CurrentPos += (UINT32) Size;
|
File->CurrentPos += (UINT32)Size;
|
||||||
return Status;
|
return Status;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
|
if ((File->Attributes & FAT_ATTR_DIRECTORY) == 0) {
|
||||||
Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
|
Size = Size < (File->FileSize - File->CurrentPos) ? Size : (File->FileSize - File->CurrentPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// This is a normal cluster based file
|
// This is a normal cluster based file
|
||||||
//
|
//
|
||||||
@ -408,10 +402,11 @@ FatReadFile (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Advance the file's current pos and current cluster
|
// Advance the file's current pos and current cluster
|
||||||
//
|
//
|
||||||
FatSetFilePos (PrivateData, File, (UINT32) Amount);
|
FatSetFilePos (PrivateData, File, (UINT32)Amount);
|
||||||
|
|
||||||
BufferPtr += Amount;
|
BufferPtr += Amount;
|
||||||
Size -= Amount;
|
Size -= Amount;
|
||||||
@ -421,7 +416,6 @@ FatReadFile (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function reads the next item in the parent directory and
|
This function reads the next item in the parent directory and
|
||||||
initializes the output parameter SubFile (CurrentPos is initialized to 0).
|
initializes the output parameter SubFile (CurrentPos is initialized to 0).
|
||||||
@ -452,7 +446,7 @@ FatReadNextDirectoryEntry (
|
|||||||
CHAR16 BaseName[9];
|
CHAR16 BaseName[9];
|
||||||
CHAR16 Ext[4];
|
CHAR16 Ext[4];
|
||||||
|
|
||||||
ZeroMem ((UINT8 *) SubFile, sizeof (PEI_FAT_FILE));
|
ZeroMem ((UINT8 *)SubFile, sizeof (PEI_FAT_FILE));
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pick a valid directory entry
|
// Pick a valid directory entry
|
||||||
@ -465,6 +459,7 @@ FatReadNextDirectoryEntry (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We only search for *FILE* in root directory
|
// We only search for *FILE* in root directory
|
||||||
// Long file name entry is *NOT* supported
|
// Long file name entry is *NOT* supported
|
||||||
@ -472,35 +467,38 @@ FatReadNextDirectoryEntry (
|
|||||||
if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {
|
if (((DirEntry.Attributes & FAT_ATTR_DIRECTORY) == FAT_ATTR_DIRECTORY) || (DirEntry.Attributes == FAT_ATTR_LFN)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// if this is a terminator dir entry, just return EFI_NOT_FOUND
|
// if this is a terminator dir entry, just return EFI_NOT_FOUND
|
||||||
//
|
//
|
||||||
if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {
|
if (DirEntry.FileName[0] == EMPTY_ENTRY_MARK) {
|
||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// If this not an invalid entry neither an empty entry, this is what we want.
|
// If this not an invalid entry neither an empty entry, this is what we want.
|
||||||
// otherwise we will start a new loop to continue to find something meaningful
|
// otherwise we will start a new loop to continue to find something meaningful
|
||||||
//
|
//
|
||||||
if ((UINT8) DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
|
if ((UINT8)DirEntry.FileName[0] != DELETE_ENTRY_MARK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// fill in the output parameter
|
// fill in the output parameter
|
||||||
//
|
//
|
||||||
EngFatToStr (8, DirEntry.FileName, BaseName);
|
EngFatToStr (8, DirEntry.FileName, BaseName);
|
||||||
EngFatToStr (3, DirEntry.FileName + 8, Ext);
|
EngFatToStr (3, DirEntry.FileName + 8, Ext);
|
||||||
|
|
||||||
Pos = (UINT16 *) SubFile->FileName;
|
Pos = (UINT16 *)SubFile->FileName;
|
||||||
SetMem ((UINT8 *) Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
|
SetMem ((UINT8 *)Pos, FAT_MAX_FILE_NAME_LENGTH, 0);
|
||||||
CopyMem ((UINT8 *) Pos, (UINT8 *) BaseName, 2 * (StrLen (BaseName) + 1));
|
CopyMem ((UINT8 *)Pos, (UINT8 *)BaseName, 2 * (StrLen (BaseName) + 1));
|
||||||
|
|
||||||
if (Ext[0] != 0) {
|
if (Ext[0] != 0) {
|
||||||
Pos += StrLen (BaseName);
|
Pos += StrLen (BaseName);
|
||||||
*Pos = '.';
|
*Pos = '.';
|
||||||
Pos++;
|
Pos++;
|
||||||
CopyMem ((UINT8 *) Pos, (UINT8 *) Ext, 2 * (StrLen (Ext) + 1));
|
CopyMem ((UINT8 *)Pos, (UINT8 *)Ext, 2 * (StrLen (Ext) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
SubFile->Attributes = DirEntry.Attributes;
|
SubFile->Attributes = DirEntry.Attributes;
|
||||||
|
@ -33,7 +33,6 @@ BlockIoNotifyEntry (
|
|||||||
IN VOID *Ppi
|
IN VOID *Ppi
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Discover all the block I/O devices to find the FAT volume.
|
Discover all the block I/O devices to find the FAT volume.
|
||||||
|
|
||||||
@ -62,7 +61,7 @@ UpdateBlocksAndVolumes (
|
|||||||
PEI_FAT_VOLUME Volume;
|
PEI_FAT_VOLUME Volume;
|
||||||
EFI_PEI_SERVICES **PeiServices;
|
EFI_PEI_SERVICES **PeiServices;
|
||||||
|
|
||||||
PeiServices = (EFI_PEI_SERVICES **) GetPeiServicesTablePointer ();
|
PeiServices = (EFI_PEI_SERVICES **)GetPeiServicesTablePointer ();
|
||||||
BlockIo2Ppi = NULL;
|
BlockIo2Ppi = NULL;
|
||||||
BlockIoPpi = NULL;
|
BlockIoPpi = NULL;
|
||||||
//
|
//
|
||||||
@ -84,16 +83,17 @@ UpdateBlocksAndVolumes (
|
|||||||
&gEfiPeiVirtualBlockIo2PpiGuid,
|
&gEfiPeiVirtualBlockIo2PpiGuid,
|
||||||
BlockIoPpiInstance,
|
BlockIoPpiInstance,
|
||||||
&TempPpiDescriptor,
|
&TempPpiDescriptor,
|
||||||
(VOID **) &BlockIo2Ppi
|
(VOID **)&BlockIo2Ppi
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = PeiServicesLocatePpi (
|
Status = PeiServicesLocatePpi (
|
||||||
&gEfiPeiVirtualBlockIoPpiGuid,
|
&gEfiPeiVirtualBlockIoPpiGuid,
|
||||||
BlockIoPpiInstance,
|
BlockIoPpiInstance,
|
||||||
&TempPpiDescriptor,
|
&TempPpiDescriptor,
|
||||||
(VOID **) &BlockIoPpi
|
(VOID **)&BlockIoPpi
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
//
|
//
|
||||||
// Done with all Block Io Ppis
|
// Done with all Block Io Ppis
|
||||||
@ -114,12 +114,12 @@ UpdateBlocksAndVolumes (
|
|||||||
&NumberBlockDevices
|
&NumberBlockDevices
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
|
for (Index = 1; Index <= NumberBlockDevices && PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE; Index++) {
|
||||||
|
|
||||||
if (BlockIo2) {
|
if (BlockIo2) {
|
||||||
Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
|
Status = BlockIo2Ppi->GetBlockDeviceMediaInfo (
|
||||||
PeiServices,
|
PeiServices,
|
||||||
@ -130,6 +130,7 @@ UpdateBlocksAndVolumes (
|
|||||||
if (EFI_ERROR (Status) || !Media2.MediaPresent) {
|
if (EFI_ERROR (Status) || !Media2.MediaPresent) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
|
||||||
@ -144,10 +145,11 @@ UpdateBlocksAndVolumes (
|
|||||||
if (EFI_ERROR (Status) || !Media.MediaPresent) {
|
if (EFI_ERROR (Status) || !Media.MediaPresent) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32)Media.BlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
|
||||||
@ -157,10 +159,11 @@ UpdateBlocksAndVolumes (
|
|||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].Logical = FALSE;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PartitionChecked = FALSE;
|
||||||
|
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8) Index;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].PhysicalDevNo = (UINT8)Index;
|
||||||
PrivateData->BlockDeviceCount++;
|
PrivateData->BlockDeviceCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Find out all logical devices
|
// Find out all logical devices
|
||||||
//
|
//
|
||||||
@ -178,8 +181,8 @@ UpdateBlocksAndVolumes (
|
|||||||
// Add the detected volume to the volume array
|
// Add the detected volume to the volume array
|
||||||
//
|
//
|
||||||
CopyMem (
|
CopyMem (
|
||||||
(UINT8 *) &(PrivateData->Volume[PrivateData->VolumeCount]),
|
(UINT8 *)&(PrivateData->Volume[PrivateData->VolumeCount]),
|
||||||
(UINT8 *) &Volume,
|
(UINT8 *)&Volume,
|
||||||
sizeof (PEI_FAT_VOLUME)
|
sizeof (PEI_FAT_VOLUME)
|
||||||
);
|
);
|
||||||
PrivateData->VolumeCount += 1;
|
PrivateData->VolumeCount += 1;
|
||||||
@ -192,7 +195,6 @@ UpdateBlocksAndVolumes (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
BlockIo installation notification function. Find out all the current BlockIO
|
BlockIo installation notification function. Find out all the current BlockIO
|
||||||
PPIs in the system and add them into private data. Assume there is
|
PPIs in the system and add them into private data. Assume there is
|
||||||
@ -220,10 +222,10 @@ BlockIoNotifyEntry (
|
|||||||
} else {
|
} else {
|
||||||
UpdateBlocksAndVolumes (mPrivateData, FALSE);
|
UpdateBlocksAndVolumes (mPrivateData, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
|
Installs the Device Recovery Module PPI, Initialize BlockIo Ppi
|
||||||
installation notification
|
installation notification
|
||||||
@ -263,12 +265,12 @@ FatPeimEntry (
|
|||||||
return EFI_OUT_OF_RESOURCES;
|
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)
|
// 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;
|
PrivateData->Signature = PEI_FAT_PRIVATE_DATA_SIGNATURE;
|
||||||
|
|
||||||
@ -287,6 +289,7 @@ FatPeimEntry (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Other initializations
|
// Other initializations
|
||||||
//
|
//
|
||||||
@ -319,7 +322,6 @@ FatPeimEntry (
|
|||||||
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
|
return PeiServicesNotifyPpi (&PrivateData->NotifyDescriptor[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the number of DXE capsules residing on the device.
|
Returns the number of DXE capsules residing on the device.
|
||||||
|
|
||||||
@ -364,7 +366,7 @@ GetNumberRecoveryCapsules (
|
|||||||
//
|
//
|
||||||
RecoveryCapsuleCount = 0;
|
RecoveryCapsuleCount = 0;
|
||||||
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
|
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)) {
|
if (EFI_ERROR (Status)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -381,7 +383,6 @@ GetNumberRecoveryCapsules (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the size and type of the requested recovery capsule.
|
Returns the size and type of the requested recovery capsule.
|
||||||
|
|
||||||
@ -442,7 +443,7 @@ GetRecoveryCapsuleInfo (
|
|||||||
//
|
//
|
||||||
RecoveryCapsuleCount = 0;
|
RecoveryCapsuleCount = 0;
|
||||||
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
|
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)) {
|
if (EFI_ERROR (Status)) {
|
||||||
continue;
|
continue;
|
||||||
@ -452,7 +453,7 @@ GetRecoveryCapsuleInfo (
|
|||||||
//
|
//
|
||||||
// Get file size
|
// Get file size
|
||||||
//
|
//
|
||||||
*Size = (UINTN) (((PEI_FAT_FILE *) Handle)->FileSize);
|
*Size = (UINTN)(((PEI_FAT_FILE *)Handle)->FileSize);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Find corresponding physical block device
|
// Find corresponding physical block device
|
||||||
@ -461,6 +462,7 @@ GetRecoveryCapsuleInfo (
|
|||||||
while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) {
|
while (PrivateData->BlockDevice[BlockDeviceNo].Logical && BlockDeviceNo < PrivateData->BlockDeviceCount) {
|
||||||
BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo;
|
BlockDeviceNo = PrivateData->BlockDevice[BlockDeviceNo].ParentDevNo;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Fill in the Capsule Type GUID according to the block device type
|
// Fill in the Capsule Type GUID according to the block device type
|
||||||
//
|
//
|
||||||
@ -483,6 +485,7 @@ GetRecoveryCapsuleInfo (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
|
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo != NULL) {
|
||||||
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
|
switch (PrivateData->BlockDevice[BlockDeviceNo].DevType) {
|
||||||
case LegacyFloppy:
|
case LegacyFloppy:
|
||||||
@ -513,7 +516,6 @@ GetRecoveryCapsuleInfo (
|
|||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Loads a DXE capsule from some media into memory.
|
Loads a DXE capsule from some media into memory.
|
||||||
|
|
||||||
@ -566,17 +568,16 @@ LoadRecoveryCapsule (
|
|||||||
//
|
//
|
||||||
RecoveryCapsuleCount = 0;
|
RecoveryCapsuleCount = 0;
|
||||||
for (Index = 0; Index < PrivateData->VolumeCount; Index++) {
|
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)) {
|
if (EFI_ERROR (Status)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
|
if (CapsuleInstance - 1 == RecoveryCapsuleCount) {
|
||||||
|
|
||||||
Status = FatReadFile (
|
Status = FatReadFile (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
Handle,
|
Handle,
|
||||||
(UINTN) (((PEI_FAT_FILE *) Handle)->FileSize),
|
(UINTN)(((PEI_FAT_FILE *)Handle)->FileSize),
|
||||||
Buffer
|
Buffer
|
||||||
);
|
);
|
||||||
return Status;
|
return Status;
|
||||||
@ -588,7 +589,6 @@ LoadRecoveryCapsule (
|
|||||||
return EFI_NOT_FOUND;
|
return EFI_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Finds the recovery file on a FAT volume.
|
Finds the recovery file on a FAT volume.
|
||||||
This function finds the recovery file named FileName on a specified FAT volume and returns
|
This function finds the recovery file named FileName on a specified FAT volume and returns
|
||||||
@ -631,7 +631,7 @@ FindRecoveryFile (
|
|||||||
// Construct root directory file
|
// Construct root directory file
|
||||||
//
|
//
|
||||||
ZeroMem (&Parent, sizeof (PEI_FAT_FILE));
|
ZeroMem (&Parent, sizeof (PEI_FAT_FILE));
|
||||||
Parent.IsFixedRootDir = (BOOLEAN) ((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
|
Parent.IsFixedRootDir = (BOOLEAN)((PrivateData->Volume[VolumeIndex].FatType == Fat32) ? FALSE : TRUE);
|
||||||
Parent.Attributes = FAT_ATTR_DIRECTORY;
|
Parent.Attributes = FAT_ATTR_DIRECTORY;
|
||||||
Parent.CurrentPos = 0;
|
Parent.CurrentPos = 0;
|
||||||
Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
|
Parent.CurrentCluster = Parent.IsFixedRootDir ? 0 : PrivateData->Volume[VolumeIndex].RootDirCluster;
|
||||||
@ -642,6 +642,7 @@ FindRecoveryFile (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Search for recovery capsule in root directory
|
// Search for recovery capsule in root directory
|
||||||
//
|
//
|
||||||
@ -671,5 +672,4 @@ FindRecoveryFile (
|
|||||||
*Handle = File;
|
*Handle = File;
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ typedef struct {
|
|||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
UINT8 Ia32Jump[3];
|
UINT8 Ia32Jump[3];
|
||||||
CHAR8 OemId[8];
|
CHAR8 OemId[8];
|
||||||
|
|
||||||
@ -97,11 +96,9 @@ typedef struct {
|
|||||||
CHAR8 Id[4];
|
CHAR8 Id[4];
|
||||||
CHAR8 FatLabel[11];
|
CHAR8 FatLabel[11];
|
||||||
CHAR8 SystemId[8];
|
CHAR8 SystemId[8];
|
||||||
|
|
||||||
} PEI_FAT_BOOT_SECTOR;
|
} PEI_FAT_BOOT_SECTOR;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
UINT8 Ia32Jump[3];
|
UINT8 Ia32Jump[3];
|
||||||
CHAR8 OemId[8];
|
CHAR8 OemId[8];
|
||||||
|
|
||||||
@ -130,7 +127,6 @@ typedef struct {
|
|||||||
CHAR8 Id[4];
|
CHAR8 Id[4];
|
||||||
CHAR8 FatLabel[11];
|
CHAR8 FatLabel[11];
|
||||||
CHAR8 SystemId[8];
|
CHAR8 SystemId[8];
|
||||||
|
|
||||||
} PEI_FAT_BOOT_SECTOR_EX;
|
} PEI_FAT_BOOT_SECTOR_EX;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
@ -9,10 +9,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
|
|
||||||
#include "FatLitePeim.h"
|
#include "FatLitePeim.h"
|
||||||
|
|
||||||
|
|
||||||
#define CHAR_FAT_VALID 0x01
|
#define CHAR_FAT_VALID 0x01
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Converts a union code character to upper case.
|
Converts a union code character to upper case.
|
||||||
This functions converts a unicode character to upper case.
|
This functions converts a unicode character to upper case.
|
||||||
@ -29,14 +27,13 @@ ToUpper (
|
|||||||
IN CHAR16 Letter
|
IN CHAR16 Letter
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ('a' <= Letter && Letter <= 'z') {
|
if (('a' <= Letter) && (Letter <= 'z')) {
|
||||||
Letter = (CHAR16) (Letter - 0x20);
|
Letter = (CHAR16)(Letter - 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Letter;
|
return Letter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads a block of data from the block device by calling
|
Reads a block of data from the block device by calling
|
||||||
underlying Block I/O service.
|
underlying Block I/O service.
|
||||||
@ -83,7 +80,7 @@ FatReadBlock (
|
|||||||
//
|
//
|
||||||
if (BlockDev->BlockIo2 != NULL) {
|
if (BlockDev->BlockIo2 != NULL) {
|
||||||
Status = BlockDev->BlockIo2->ReadBlocks (
|
Status = BlockDev->BlockIo2->ReadBlocks (
|
||||||
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
|
(EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
|
||||||
BlockDev->BlockIo2,
|
BlockDev->BlockIo2,
|
||||||
BlockDev->PhysicalDevNo,
|
BlockDev->PhysicalDevNo,
|
||||||
Lba,
|
Lba,
|
||||||
@ -92,7 +89,7 @@ FatReadBlock (
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
Status = BlockDev->BlockIo->ReadBlocks (
|
Status = BlockDev->BlockIo->ReadBlocks (
|
||||||
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
|
(EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
|
||||||
BlockDev->BlockIo,
|
BlockDev->BlockIo,
|
||||||
BlockDev->PhysicalDevNo,
|
BlockDev->PhysicalDevNo,
|
||||||
Lba,
|
Lba,
|
||||||
@ -100,7 +97,6 @@ FatReadBlock (
|
|||||||
Buffer
|
Buffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Status = FatReadDisk (
|
Status = FatReadDisk (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
@ -114,7 +110,6 @@ FatReadBlock (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Find a cache block designated to specific Block device and Lba.
|
Find a cache block designated to specific Block device and Lba.
|
||||||
If not found, invalidate an oldest one and use it. (LRU cache)
|
If not found, invalidate an oldest one and use it. (LRU cache)
|
||||||
@ -150,15 +145,16 @@ FatGetCacheBlock (
|
|||||||
//
|
//
|
||||||
for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {
|
for (Index = 0; Index < PEI_FAT_CACHE_SIZE; Index++) {
|
||||||
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
|
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
|
||||||
if (CacheBuffer->Valid && CacheBuffer->BlockDeviceNo == BlockDeviceNo && CacheBuffer->Lba == Lba) {
|
if (CacheBuffer->Valid && (CacheBuffer->BlockDeviceNo == BlockDeviceNo) && (CacheBuffer->Lba == Lba)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Index < PEI_FAT_CACHE_SIZE) {
|
if (Index < PEI_FAT_CACHE_SIZE) {
|
||||||
*CachePtr = (CHAR8 *) CacheBuffer->Buffer;
|
*CachePtr = (CHAR8 *)CacheBuffer->Buffer;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We have to find an invalid cache buffer
|
// We have to find an invalid cache buffer
|
||||||
//
|
//
|
||||||
@ -167,6 +163,7 @@ FatGetCacheBlock (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Use the cache buffer
|
// Use the cache buffer
|
||||||
//
|
//
|
||||||
@ -202,12 +199,11 @@ FatGetCacheBlock (
|
|||||||
}
|
}
|
||||||
|
|
||||||
CacheBuffer->Valid = TRUE;
|
CacheBuffer->Valid = TRUE;
|
||||||
*CachePtr = (CHAR8 *) CacheBuffer->Buffer;
|
*CachePtr = (CHAR8 *)CacheBuffer->Buffer;
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Disk reading.
|
Disk reading.
|
||||||
|
|
||||||
@ -292,7 +288,6 @@ FatReadDisk (
|
|||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This version is different from the version in Unicode collation
|
This version is different from the version in Unicode collation
|
||||||
protocol in that this version strips off trailing blanks.
|
protocol in that this version strips off trailing blanks.
|
||||||
@ -325,6 +320,7 @@ EngFatToStr (
|
|||||||
if (*Fat == ' ') {
|
if (*Fat == ' ') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*String = *Fat;
|
*String = *Fat;
|
||||||
String += 1;
|
String += 1;
|
||||||
Fat += 1;
|
Fat += 1;
|
||||||
@ -334,7 +330,6 @@ EngFatToStr (
|
|||||||
*String = 0;
|
*String = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
||||||
|
|
||||||
@ -366,5 +361,5 @@ EngStriColl (
|
|||||||
UpperS2 = ToUpper (*Str2);
|
UpperS2 = ToUpper (*Str2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (BOOLEAN) ((*Str2 != 0) ? FALSE : TRUE);
|
return (BOOLEAN)((*Str2 != 0) ? FALSE : TRUE);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
// The block device
|
// The block device
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
UINT32 BlockSize;
|
UINT32 BlockSize;
|
||||||
UINT64 LastBlock;
|
UINT64 LastBlock;
|
||||||
UINT32 IoAlign;
|
UINT32 IoAlign;
|
||||||
@ -80,7 +79,6 @@ typedef struct {
|
|||||||
// the Volume structure
|
// the Volume structure
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
UINTN BlockDeviceNo;
|
UINTN BlockDeviceNo;
|
||||||
UINTN VolumeNo;
|
UINTN VolumeNo;
|
||||||
UINT64 VolumeSize;
|
UINT64 VolumeSize;
|
||||||
@ -94,14 +92,12 @@ typedef struct {
|
|||||||
UINT64 RootDirPos;
|
UINT64 RootDirPos;
|
||||||
UINT32 RootEntries;
|
UINT32 RootEntries;
|
||||||
UINT32 RootDirCluster;
|
UINT32 RootDirCluster;
|
||||||
|
|
||||||
} PEI_FAT_VOLUME;
|
} PEI_FAT_VOLUME;
|
||||||
|
|
||||||
//
|
//
|
||||||
// File instance
|
// File instance
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
PEI_FAT_VOLUME *Volume;
|
PEI_FAT_VOLUME *Volume;
|
||||||
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
|
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
|
||||||
|
|
||||||
@ -114,21 +110,18 @@ typedef struct {
|
|||||||
|
|
||||||
UINT8 Attributes;
|
UINT8 Attributes;
|
||||||
UINT32 FileSize;
|
UINT32 FileSize;
|
||||||
|
|
||||||
} PEI_FAT_FILE;
|
} PEI_FAT_FILE;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Cache Buffer
|
// Cache Buffer
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
BOOLEAN Valid;
|
BOOLEAN Valid;
|
||||||
UINTN BlockDeviceNo;
|
UINTN BlockDeviceNo;
|
||||||
UINT64 Lba;
|
UINT64 Lba;
|
||||||
UINT32 Lru;
|
UINT32 Lru;
|
||||||
UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
|
UINT64 Buffer[PEI_FAT_MAX_BLOCK_SIZE / 8];
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
|
|
||||||
} PEI_FAT_CACHE_BUFFER;
|
} PEI_FAT_CACHE_BUFFER;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -142,7 +135,6 @@ typedef struct {
|
|||||||
#define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
|
#define PEI_FAT_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('p', 'f', 'a', 't')
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
UINTN Signature;
|
UINTN Signature;
|
||||||
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
|
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
|
||||||
EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
|
EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
|
||||||
@ -160,7 +152,6 @@ typedef struct {
|
|||||||
PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
|
PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
|
||||||
PEI_FAT_FILE File;
|
PEI_FAT_FILE File;
|
||||||
PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
|
PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
|
||||||
|
|
||||||
} PEI_FAT_PRIVATE_DATA;
|
} PEI_FAT_PRIVATE_DATA;
|
||||||
|
|
||||||
#define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
|
#define PEI_FAT_PRIVATE_DATA_FROM_THIS(a) \
|
||||||
@ -178,7 +169,6 @@ typedef struct {
|
|||||||
#define UNPACK_UINT32(a) \
|
#define UNPACK_UINT32(a) \
|
||||||
(UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
|
(UINT32) ((((UINT8 *) a)[0] << 0) | (((UINT8 *) a)[1] << 8) | (((UINT8 *) a)[2] << 16) | (((UINT8 *) a)[3] << 24))
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// API functions
|
// API functions
|
||||||
//
|
//
|
||||||
@ -209,7 +199,6 @@ FindRecoveryFile (
|
|||||||
OUT PEI_FILE_HANDLE *Handle
|
OUT PEI_FILE_HANDLE *Handle
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the number of DXE capsules residing on the device.
|
Returns the number of DXE capsules residing on the device.
|
||||||
This function, by whatever mechanism, searches for DXE capsules from the associated device and
|
This function, by whatever mechanism, searches for DXE capsules from the associated device and
|
||||||
@ -236,7 +225,6 @@ GetNumberRecoveryCapsules (
|
|||||||
OUT UINTN *NumberRecoveryCapsules
|
OUT UINTN *NumberRecoveryCapsules
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the size and type of the requested recovery capsule.
|
Returns the size and type of the requested recovery capsule.
|
||||||
This function returns the size and type of the capsule specified by CapsuleInstance.
|
This function returns the size and type of the capsule specified by CapsuleInstance.
|
||||||
@ -274,7 +262,6 @@ GetRecoveryCapsuleInfo (
|
|||||||
OUT EFI_GUID *CapsuleType
|
OUT EFI_GUID *CapsuleType
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Loads a DXE capsule from some media into memory.
|
Loads a DXE capsule from some media into memory.
|
||||||
|
|
||||||
@ -303,7 +290,6 @@ LoadRecoveryCapsule (
|
|||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This version is different from the version in Unicode collation
|
This version is different from the version in Unicode collation
|
||||||
protocol in that this version strips off trailing blanks.
|
protocol in that this version strips off trailing blanks.
|
||||||
@ -326,7 +312,6 @@ EngFatToStr (
|
|||||||
OUT CHAR16 *Str
|
OUT CHAR16 *Str
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
||||||
|
|
||||||
@ -342,7 +327,6 @@ EngStriColl (
|
|||||||
IN CHAR16 *Str2
|
IN CHAR16 *Str2
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads a block of data from the block device by calling
|
Reads a block of data from the block device by calling
|
||||||
underlying Block I/O service.
|
underlying Block I/O service.
|
||||||
@ -368,7 +352,6 @@ FatReadBlock (
|
|||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check if there is a valid FAT in the corresponding Block device
|
Check if there is a valid FAT in the corresponding Block device
|
||||||
of the volume and if yes, fill in the relevant fields for the
|
of the volume and if yes, fill in the relevant fields for the
|
||||||
@ -394,7 +377,6 @@ FatGetBpbInfo (
|
|||||||
IN OUT PEI_FAT_VOLUME *Volume
|
IN OUT PEI_FAT_VOLUME *Volume
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Gets the next cluster in the cluster chain.
|
Gets the next cluster in the cluster chain.
|
||||||
|
|
||||||
@ -416,7 +398,6 @@ FatGetNextCluster (
|
|||||||
OUT UINT32 *NextCluster
|
OUT UINT32 *NextCluster
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Disk reading.
|
Disk reading.
|
||||||
|
|
||||||
@ -439,7 +420,6 @@ FatReadDisk (
|
|||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
|
Set a file's CurrentPos and CurrentCluster, then compute StraightReadAmount.
|
||||||
|
|
||||||
@ -460,7 +440,6 @@ FatSetFilePos (
|
|||||||
IN UINT32 Pos
|
IN UINT32 Pos
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads file data. Updates the file's CurrentPos.
|
Reads file data. Updates the file's CurrentPos.
|
||||||
|
|
||||||
@ -482,7 +461,6 @@ FatReadFile (
|
|||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function reads the next item in the parent directory and
|
This function reads the next item in the parent directory and
|
||||||
initializes the output parameter SubFile (CurrentPos is initialized to 0).
|
initializes the output parameter SubFile (CurrentPos is initialized to 0).
|
||||||
@ -507,7 +485,6 @@ FatReadNextDirectoryEntry (
|
|||||||
OUT PEI_FAT_FILE *SubFile
|
OUT PEI_FAT_FILE *SubFile
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This function finds partitions (logical devices) in physical block devices.
|
This function finds partitions (logical devices) in physical block devices.
|
||||||
|
|
||||||
|
@ -62,7 +62,6 @@ PartitionCheckGptHeaderCRC (
|
|||||||
return (GptHdrCrc == Crc);
|
return (GptHdrCrc == Crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check if the CRC field in the Partition table header is valid
|
Check if the CRC field in the Partition table header is valid
|
||||||
for Partition entry array.
|
for Partition entry array.
|
||||||
@ -83,10 +82,10 @@ PartitionCheckGptEntryArrayCRC (
|
|||||||
UINT32 Crc;
|
UINT32 Crc;
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
|
|
||||||
Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
|
Size = (UINTN)MultU64x32 (PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
|
||||||
Crc = CalculateCrc32 (PartEntry, Size);
|
Crc = CalculateCrc32 (PartEntry, Size);
|
||||||
|
|
||||||
return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
|
return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,13 +127,14 @@ PartitionCheckGptHeader (
|
|||||||
AlternateLba = PRIMARY_PART_HEADER_LBA;
|
AlternateLba = PRIMARY_PART_HEADER_LBA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
|
if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
|
||||||
(PartHdr->Header.Revision != 0x00010000) ||
|
(PartHdr->Header.Revision != 0x00010000) ||
|
||||||
(PartHdr->Header.HeaderSize < 92) ||
|
(PartHdr->Header.HeaderSize < 92) ||
|
||||||
(PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
|
(PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
|
||||||
(!PartitionCheckGptHeaderCRC (PartHdr)) ||
|
(!PartitionCheckGptHeaderCRC (PartHdr)) ||
|
||||||
(PartHdr->Header.Reserved != 0)
|
(PartHdr->Header.Reserved != 0)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
|
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -150,17 +150,18 @@ PartitionCheckGptHeader (
|
|||||||
// 5. Must be remain 128*128 bytes for backup entry array.
|
// 5. Must be remain 128*128 bytes for backup entry array.
|
||||||
// 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
|
// 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
|
||||||
//
|
//
|
||||||
if ( (PartHdr->MyLBA != Lba) ||
|
if ((PartHdr->MyLBA != Lba) ||
|
||||||
(PartHdr->AlternateLBA != AlternateLba) ||
|
(PartHdr->AlternateLBA != AlternateLba) ||
|
||||||
(PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
|
(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->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
|
||||||
(PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
|
(PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
|
||||||
(PartHdr->PartitionEntryLBA < 2) ||
|
(PartHdr->PartitionEntryLBA < 2) ||
|
||||||
(PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
|
(PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
|
||||||
(PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA && PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA) ||
|
((PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA) && (PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA)) ||
|
||||||
(PartHdr->SizeOfPartitionEntry%128 != 0) ||
|
(PartHdr->SizeOfPartitionEntry%128 != 0) ||
|
||||||
(PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
|
(PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
|
DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -250,19 +251,21 @@ PartitionCheckGptEntryArray (
|
|||||||
if (EntryArraySizeRemainder != 0) {
|
if (EntryArraySizeRemainder != 0) {
|
||||||
PartitionEntryBlockNumb++;
|
PartitionEntryBlockNumb++;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
|
PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
|
||||||
|
|
||||||
PartitionEntryBuffer = (EFI_PARTITION_ENTRY *) AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
|
PartitionEntryBuffer = (EFI_PARTITION_ENTRY *)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
|
||||||
if (PartitionEntryBuffer == NULL) {
|
if (PartitionEntryBuffer == NULL) {
|
||||||
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
|
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
|
||||||
goto EXIT;
|
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) {
|
if (PartitionEntryStatus == NULL) {
|
||||||
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
|
DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
|
ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
|
||||||
|
|
||||||
Status = FatReadBlock (
|
Status = FatReadBlock (
|
||||||
@ -283,19 +286,20 @@ PartitionCheckGptEntryArray (
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Index1 = 0; Index1 < PartHdr->NumberOfPartitionEntries; Index1++) {
|
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)) {
|
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
StartingLBA = Entry->StartingLBA;
|
StartingLBA = Entry->StartingLBA;
|
||||||
EndingLBA = Entry->EndingLBA;
|
EndingLBA = Entry->EndingLBA;
|
||||||
if (StartingLBA > EndingLBA ||
|
if ((StartingLBA > EndingLBA) ||
|
||||||
StartingLBA < PartHdr->FirstUsableLBA ||
|
(StartingLBA < PartHdr->FirstUsableLBA) ||
|
||||||
StartingLBA > PartHdr->LastUsableLBA ||
|
(StartingLBA > PartHdr->LastUsableLBA) ||
|
||||||
EndingLBA < PartHdr->FirstUsableLBA ||
|
(EndingLBA < PartHdr->FirstUsableLBA) ||
|
||||||
EndingLBA > PartHdr->LastUsableLBA
|
(EndingLBA > PartHdr->LastUsableLBA)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
PartitionEntryStatus[Index1].OutOfRange = TRUE;
|
PartitionEntryStatus[Index1].OutOfRange = TRUE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -308,12 +312,12 @@ PartitionCheckGptEntryArray (
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Index2 = Index1 + 1; Index2 < PartHdr->NumberOfPartitionEntries; Index2++) {
|
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)) {
|
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {
|
if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
|
||||||
//
|
//
|
||||||
// This region overlaps with the Index1'th region
|
// This region overlaps with the Index1'th region
|
||||||
//
|
//
|
||||||
@ -325,10 +329,11 @@ PartitionCheckGptEntryArray (
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
|
for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
|
||||||
if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)||
|
if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
|
||||||
PartitionEntryStatus[Index].OutOfRange ||
|
PartitionEntryStatus[Index].OutOfRange ||
|
||||||
PartitionEntryStatus[Index].Overlap ||
|
PartitionEntryStatus[Index].Overlap ||
|
||||||
PartitionEntryStatus[Index].OsSpecific) {
|
PartitionEntryStatus[Index].OsSpecific)
|
||||||
|
{
|
||||||
//
|
//
|
||||||
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
|
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
|
||||||
// partition Entries
|
// partition Entries
|
||||||
@ -401,7 +406,7 @@ PartitionCheckGptStructure (
|
|||||||
EFI_PEI_LBA GptHeaderLBA;
|
EFI_PEI_LBA GptHeaderLBA;
|
||||||
|
|
||||||
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
||||||
PartHdr = (EFI_PARTITION_TABLE_HEADER *) PrivateData->BlockData;
|
PartHdr = (EFI_PARTITION_TABLE_HEADER *)PrivateData->BlockData;
|
||||||
|
|
||||||
if (IsPrimary) {
|
if (IsPrimary) {
|
||||||
GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
|
GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
|
||||||
@ -452,7 +457,7 @@ PartitionCheckProtectiveMbr (
|
|||||||
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
|
|
||||||
ProtectiveMbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
|
ProtectiveMbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
|
||||||
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -482,11 +487,12 @@ PartitionCheckProtectiveMbr (
|
|||||||
//
|
//
|
||||||
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
|
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
|
||||||
MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
|
MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
|
||||||
if (MbrPartition->BootIndicator == 0x00 &&
|
if ((MbrPartition->BootIndicator == 0x00) &&
|
||||||
MbrPartition->StartSector == 0x02 &&
|
(MbrPartition->StartSector == 0x02) &&
|
||||||
MbrPartition->OSIndicator == PMBR_GPT_PARTITION &&
|
(MbrPartition->OSIndicator == PMBR_GPT_PARTITION) &&
|
||||||
UNPACK_UINT32 (MbrPartition->StartingLBA) == 1
|
(UNPACK_UINT32 (MbrPartition->StartingLBA) == 1)
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,12 +37,13 @@ PartitionValidMbr (
|
|||||||
if (Mbr->Signature != MBR_SIGNATURE) {
|
if (Mbr->Signature != MBR_SIGNATURE) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The BPB also has this signature, so it can not be used alone.
|
// The BPB also has this signature, so it can not be used alone.
|
||||||
//
|
//
|
||||||
MbrValid = FALSE;
|
MbrValid = FALSE;
|
||||||
for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) {
|
for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) {
|
||||||
if (Mbr->Partition[Index1].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0) {
|
if ((Mbr->Partition[Index1].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,12 +66,12 @@ PartitionValidMbr (
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {
|
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {
|
||||||
if (Mbr->Partition[Index2].OSIndicator == 0x00 || UNPACK_INT32 (Mbr->Partition[Index2].SizeInLBA) == 0) {
|
if ((Mbr->Partition[Index2].OSIndicator == 0x00) || (UNPACK_INT32 (Mbr->Partition[Index2].SizeInLBA) == 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1;
|
NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1;
|
||||||
if (NewEndingLBA >= StartingLBA && UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA) {
|
if ((NewEndingLBA >= StartingLBA) && (UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA)) {
|
||||||
//
|
//
|
||||||
// This region overlaps with the Index1'th region
|
// This region overlaps with the Index1'th region
|
||||||
//
|
//
|
||||||
@ -78,6 +79,7 @@ PartitionValidMbr (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Non of the regions overlapped so MBR is O.K.
|
// Non of the regions overlapped so MBR is O.K.
|
||||||
//
|
//
|
||||||
@ -116,12 +118,12 @@ FatFindMbrPartitions (
|
|||||||
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
||||||
|
|
||||||
if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Found = FALSE;
|
Found = FALSE;
|
||||||
Mbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
|
Mbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
|
||||||
|
|
||||||
Status = FatReadBlock (
|
Status = FatReadBlock (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
@ -134,21 +136,22 @@ FatFindMbrPartitions (
|
|||||||
if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev->LastBlock)) {
|
if (EFI_ERROR (Status) || !PartitionValidMbr (Mbr, ParentBlockDev->LastBlock)) {
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We have a valid mbr - add each partition
|
// We have a valid mbr - add each partition
|
||||||
//
|
//
|
||||||
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
|
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
|
||||||
if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) == 0) {
|
if ((Mbr->Partition[Index].OSIndicator == 0x00) || (UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) == 0)) {
|
||||||
//
|
//
|
||||||
// Don't use null MBR entries
|
// Don't use null MBR entries
|
||||||
//
|
//
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Register this partition
|
// Register this partition
|
||||||
//
|
//
|
||||||
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
|
if (PrivateData->BlockDeviceCount < PEI_FAT_MAX_BLOCK_DEVICE) {
|
||||||
|
|
||||||
Found = TRUE;
|
Found = TRUE;
|
||||||
|
|
||||||
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
|
BlockDev = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
|
||||||
|
Reference in New Issue
Block a user