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.
|
||||||
@ -130,11 +130,11 @@ FatComponentNameGetDriverName (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatComponentNameGetControllerName (
|
FatComponentNameGetControllerName (
|
||||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||||
IN EFI_HANDLE ControllerHandle,
|
IN EFI_HANDLE ControllerHandle,
|
||||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||||
IN CHAR8 *Language,
|
IN CHAR8 *Language,
|
||||||
OUT CHAR16 **ControllerName
|
OUT CHAR16 **ControllerName
|
||||||
);
|
);
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -149,13 +149,13 @@ 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"
|
||||||
};
|
};
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
|
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
|
||||||
{
|
{
|
||||||
"eng;en",
|
"eng;en",
|
||||||
L"FAT File System Driver"
|
L"FAT File System Driver"
|
||||||
@ -166,7 +166,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatDriverNameTable[] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[] = {
|
GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[] = {
|
||||||
{
|
{
|
||||||
"eng;en",
|
"eng;en",
|
||||||
L"FAT File System"
|
L"FAT File System"
|
||||||
@ -177,7 +177,6 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mFatControllerNameTable[]
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrieves a Unicode string that is the user readable name of the driver.
|
Retrieves a Unicode string that is the user readable name of the driver.
|
||||||
|
|
||||||
@ -305,11 +304,11 @@ FatComponentNameGetDriverName (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatComponentNameGetControllerName (
|
FatComponentNameGetControllerName (
|
||||||
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
||||||
IN EFI_HANDLE ControllerHandle,
|
IN EFI_HANDLE ControllerHandle,
|
||||||
IN EFI_HANDLE ChildHandle OPTIONAL,
|
IN EFI_HANDLE ChildHandle OPTIONAL,
|
||||||
IN CHAR8 *Language,
|
IN CHAR8 *Language,
|
||||||
OUT CHAR16 **ControllerName
|
OUT CHAR16 **ControllerName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
@ -14,14 +14,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
//
|
//
|
||||||
// FatFsLock - Global lock for synchronizing all requests.
|
// FatFsLock - Global lock for synchronizing all requests.
|
||||||
//
|
//
|
||||||
EFI_LOCK FatFsLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK);
|
EFI_LOCK FatFsLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_CALLBACK);
|
||||||
|
|
||||||
EFI_LOCK FatTaskLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
|
EFI_LOCK FatTaskLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_NOTIFY);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Filesystem interface functions
|
// Filesystem interface functions
|
||||||
//
|
//
|
||||||
EFI_FILE_PROTOCOL FatFileInterface = {
|
EFI_FILE_PROTOCOL FatFileInterface = {
|
||||||
EFI_FILE_PROTOCOL_REVISION,
|
EFI_FILE_PROTOCOL_REVISION,
|
||||||
FatOpen,
|
FatOpen,
|
||||||
FatClose,
|
FatClose,
|
||||||
|
@ -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
|
||||||
|
@ -19,7 +19,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatFreeODir (
|
FatFreeODir (
|
||||||
IN FAT_ODIR *ODir
|
IN FAT_ODIR *ODir
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_DIRENT *DirEnt;
|
FAT_DIRENT *DirEnt;
|
||||||
@ -50,7 +50,7 @@ FatFreeODir (
|
|||||||
STATIC
|
STATIC
|
||||||
FAT_ODIR *
|
FAT_ODIR *
|
||||||
FatAllocateODir (
|
FatAllocateODir (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
@ -78,14 +78,14 @@ FatAllocateODir (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatDiscardODir (
|
FatDiscardODir (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
|
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
ODir = OFile->ODir;
|
ODir = OFile->ODir;
|
||||||
if (!OFile->DirEnt->Invalid) {
|
if (!OFile->DirEnt->Invalid) {
|
||||||
//
|
//
|
||||||
// If OFile does not represent a deleted file, then we will cache the directory
|
// If OFile does not represent a deleted file, then we will cache the directory
|
||||||
@ -107,6 +107,7 @@ FatDiscardODir (
|
|||||||
ODir = NULL;
|
ODir = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Release ODir Structure
|
// Release ODir Structure
|
||||||
//
|
//
|
||||||
@ -127,14 +128,14 @@ FatDiscardODir (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatRequestODir (
|
FatRequestODir (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN DirCacheTag;
|
UINTN DirCacheTag;
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
FAT_ODIR *CurrentODir;
|
FAT_ODIR *CurrentODir;
|
||||||
LIST_ENTRY *CurrentODirLink;
|
LIST_ENTRY *CurrentODirLink;
|
||||||
|
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
ODir = NULL;
|
ODir = NULL;
|
||||||
@ -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);
|
||||||
@ -171,10 +173,11 @@ FatRequestODir (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatCleanupODirCache (
|
FatCleanupODirCache (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
@ -24,14 +24,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAccessEntry (
|
FatAccessEntry (
|
||||||
IN FAT_OFILE *Parent,
|
IN FAT_OFILE *Parent,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN UINTN EntryPos,
|
IN UINTN EntryPos,
|
||||||
IN OUT VOID *Entry
|
IN OUT VOID *Entry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Position;
|
UINTN Position;
|
||||||
UINTN BufferSize;
|
UINTN BufferSize;
|
||||||
|
|
||||||
Position = EntryPos * sizeof (FAT_DIRECTORY_ENTRY);
|
Position = EntryPos * sizeof (FAT_DIRECTORY_ENTRY);
|
||||||
if (Position >= Parent->FileSize) {
|
if (Position >= Parent->FileSize) {
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,17 +61,17 @@ FatAccessEntry (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatStoreDirEnt (
|
FatStoreDirEnt (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_DIRECTORY_LFN LfnEntry;
|
FAT_DIRECTORY_LFN LfnEntry;
|
||||||
UINTN EntryPos;
|
UINTN EntryPos;
|
||||||
CHAR16 *LfnBufferPointer;
|
CHAR16 *LfnBufferPointer;
|
||||||
CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
|
CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
|
||||||
UINT8 EntryCount;
|
UINT8 EntryCount;
|
||||||
UINT8 LfnOrdinal;
|
UINT8 LfnOrdinal;
|
||||||
|
|
||||||
EntryPos = DirEnt->EntryPos;
|
EntryPos = DirEnt->EntryPos;
|
||||||
EntryCount = DirEnt->EntryCount;
|
EntryCount = DirEnt->EntryCount;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +164,7 @@ FatIsDotDirEnt (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatSetDirEntCluster (
|
FatSetDirEntCluster (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Cluster;
|
UINTN Cluster;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,11 +185,11 @@ FatSetDirEntCluster (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatUpdateDirEntClusterSizeInfo (
|
FatUpdateDirEntClusterSizeInfo (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,14 +203,15 @@ FatUpdateDirEntClusterSizeInfo (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatCloneDirEnt (
|
FatCloneDirEnt (
|
||||||
IN FAT_DIRENT *DirEnt1,
|
IN FAT_DIRENT *DirEnt1,
|
||||||
IN FAT_DIRENT *DirEnt2
|
IN FAT_DIRENT *DirEnt2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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,
|
||||||
@ -228,22 +230,22 @@ FatCloneDirEnt (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatLoadLongNameEntry (
|
FatLoadLongNameEntry (
|
||||||
IN FAT_OFILE *Parent,
|
IN FAT_OFILE *Parent,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
|
CHAR16 LfnBuffer[MAX_LFN_ENTRIES * LFN_CHAR_TOTAL + 1];
|
||||||
CHAR16 *LfnBufferPointer;
|
CHAR16 *LfnBufferPointer;
|
||||||
CHAR8 *File8Dot3Name;
|
CHAR8 *File8Dot3Name;
|
||||||
UINTN EntryPos;
|
UINTN EntryPos;
|
||||||
UINT8 LfnOrdinal;
|
UINT8 LfnOrdinal;
|
||||||
UINT8 LfnChecksum;
|
UINT8 LfnChecksum;
|
||||||
FAT_DIRECTORY_LFN LfnEntry;
|
FAT_DIRECTORY_LFN LfnEntry;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
EntryPos = DirEnt->EntryPos;
|
EntryPos = DirEnt->EntryPos;
|
||||||
File8Dot3Name = DirEnt->Entry.FileName;
|
File8Dot3Name = DirEnt->Entry.FileName;
|
||||||
LfnBufferPointer = LfnBuffer;
|
LfnBufferPointer = LfnBuffer;
|
||||||
//
|
//
|
||||||
// Computes checksum for LFN
|
// Computes checksum for LFN
|
||||||
//
|
//
|
||||||
@ -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
|
||||||
@ -312,13 +316,14 @@ FatLoadLongNameEntry (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatAddDirEnt (
|
FatAddDirEnt (
|
||||||
IN FAT_ODIR *ODir,
|
IN FAT_ODIR *ODir,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -338,14 +343,14 @@ FatAddDirEnt (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatLoadNextDirEnt (
|
FatLoadNextDirEnt (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
OUT FAT_DIRENT **PtrDirEnt
|
OUT FAT_DIRENT **PtrDirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_DIRENT *DirEnt;
|
FAT_DIRENT *DirEnt;
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
FAT_DIRECTORY_ENTRY Entry;
|
FAT_DIRECTORY_ENTRY Entry;
|
||||||
|
|
||||||
ODir = OFile->ODir;
|
ODir = OFile->ODir;
|
||||||
//
|
//
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -440,40 +446,40 @@ Done:
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetDirEntInfo (
|
FatGetDirEntInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN FAT_DIRENT *DirEnt,
|
IN FAT_DIRENT *DirEnt,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
UINTN NameSize;
|
UINTN NameSize;
|
||||||
UINTN ResultSize;
|
UINTN ResultSize;
|
||||||
UINTN Cluster;
|
UINTN Cluster;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_FILE_INFO *Info;
|
EFI_FILE_INFO *Info;
|
||||||
FAT_DIRECTORY_ENTRY *Entry;
|
FAT_DIRECTORY_ENTRY *Entry;
|
||||||
FAT_DATE_TIME FatLastAccess;
|
FAT_DATE_TIME FatLastAccess;
|
||||||
|
|
||||||
ASSERT_VOLUME_LOCKED (Volume);
|
ASSERT_VOLUME_LOCKED (Volume);
|
||||||
|
|
||||||
Size = SIZE_OF_EFI_FILE_INFO;
|
Size = SIZE_OF_EFI_FILE_INFO;
|
||||||
NameSize = StrSize (DirEnt->FileString);
|
NameSize = StrSize (DirEnt->FileString);
|
||||||
ResultSize = Size + NameSize;
|
ResultSize = Size + NameSize;
|
||||||
|
|
||||||
Status = EFI_BUFFER_TOO_SMALL;
|
Status = EFI_BUFFER_TOO_SMALL;
|
||||||
if (*BufferSize >= ResultSize) {
|
if (*BufferSize >= ResultSize) {
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
Entry = &DirEnt->Entry;
|
Entry = &DirEnt->Entry;
|
||||||
Info = Buffer;
|
Info = Buffer;
|
||||||
Info->Size = ResultSize;
|
Info->Size = ResultSize;
|
||||||
if ((Entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) != 0) {
|
if ((Entry->Attributes & FAT_ATTRIBUTE_DIRECTORY) != 0) {
|
||||||
Cluster = (Entry->FileClusterHigh << 16) | Entry->FileCluster;
|
Cluster = (Entry->FileClusterHigh << 16) | Entry->FileCluster;
|
||||||
Info->PhysicalSize = FatPhysicalDirSize (Volume, Cluster);
|
Info->PhysicalSize = FatPhysicalDirSize (Volume, Cluster);
|
||||||
Info->FileSize = Info->PhysicalSize;
|
Info->FileSize = Info->PhysicalSize;
|
||||||
} else {
|
} else {
|
||||||
Info->FileSize = Entry->FileSize;
|
Info->FileSize = Entry->FileSize;
|
||||||
Info->PhysicalSize = FatPhysicalFileSize (Volume, Entry->FileSize);
|
Info->PhysicalSize = FatPhysicalFileSize (Volume, Entry->FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZeroMem (&FatLastAccess.Time, sizeof (FatLastAccess.Time));
|
ZeroMem (&FatLastAccess.Time, sizeof (FatLastAccess.Time));
|
||||||
@ -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;
|
||||||
@ -504,9 +510,9 @@ FatGetDirEntInfo (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSearchODir (
|
FatSearchODir (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN CHAR16 *FileNameString,
|
IN CHAR16 *FileNameString,
|
||||||
OUT FAT_DIRENT **PtrDirEnt
|
OUT FAT_DIRENT **PtrDirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN PossibleShortName;
|
BOOLEAN PossibleShortName;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,7 +571,7 @@ FatSearchODir (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatResetODirCursor (
|
FatResetODirCursor (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
@ -588,8 +595,8 @@ FatResetODirCursor (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetNextDirEnt (
|
FatGetNextDirEnt (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
OUT FAT_DIRENT **PtrDirEnt
|
OUT FAT_DIRENT **PtrDirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -617,8 +624,8 @@ FatGetNextDirEnt (
|
|||||||
//
|
//
|
||||||
// End of directory, return NULL
|
// End of directory, return NULL
|
||||||
//
|
//
|
||||||
DirEnt = NULL;
|
DirEnt = NULL;
|
||||||
ODir->CurrentPos = ODir->CurrentEndPos;
|
ODir->CurrentPos = ODir->CurrentEndPos;
|
||||||
} else {
|
} else {
|
||||||
ODir->CurrentCursor = ODir->CurrentCursor->ForwardLink;
|
ODir->CurrentCursor = ODir->CurrentCursor->ForwardLink;
|
||||||
DirEnt = DIRENT_FROM_LINK (ODir->CurrentCursor);
|
DirEnt = DIRENT_FROM_LINK (ODir->CurrentCursor);
|
||||||
@ -640,8 +647,8 @@ FatGetNextDirEnt (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatSetEntryCount (
|
FatSetEntryCount (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 *FileString;
|
CHAR16 *FileString;
|
||||||
@ -650,9 +657,9 @@ FatSetEntryCount (
|
|||||||
//
|
//
|
||||||
// Get new entry count and set the 8.3 name
|
// Get new entry count and set the 8.3 name
|
||||||
//
|
//
|
||||||
DirEnt->EntryCount = 1;
|
DirEnt->EntryCount = 1;
|
||||||
FileString = DirEnt->FileString;
|
FileString = DirEnt->FileString;
|
||||||
File8Dot3Name = DirEnt->Entry.FileName;
|
File8Dot3Name = DirEnt->Entry.FileName;
|
||||||
SetMem (File8Dot3Name, FAT_NAME_LEN, ' ');
|
SetMem (File8Dot3Name, FAT_NAME_LEN, ' ');
|
||||||
if (StrCmp (FileString, L".") == 0) {
|
if (StrCmp (FileString, L".") == 0) {
|
||||||
//
|
//
|
||||||
@ -664,8 +671,8 @@ FatSetEntryCount (
|
|||||||
//
|
//
|
||||||
// ".." entry
|
// ".." entry
|
||||||
//
|
//
|
||||||
File8Dot3Name[0] = '.';
|
File8Dot3Name[0] = '.';
|
||||||
File8Dot3Name[1] = '.';
|
File8Dot3Name[1] = '.';
|
||||||
FatCloneDirEnt (DirEnt, OFile->Parent->DirEnt);
|
FatCloneDirEnt (DirEnt, OFile->Parent->DirEnt);
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
@ -719,13 +726,13 @@ FatExpandODir (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSeekVolumeId (
|
FatSeekVolumeId (
|
||||||
IN FAT_OFILE *Root,
|
IN FAT_OFILE *Root,
|
||||||
OUT FAT_DIRENT *DirEnt
|
OUT FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN EntryPos;
|
UINTN EntryPos;
|
||||||
FAT_DIRECTORY_ENTRY *Entry;
|
FAT_DIRECTORY_ENTRY *Entry;
|
||||||
|
|
||||||
EntryPos = 0;
|
EntryPos = 0;
|
||||||
Entry = &DirEnt->Entry;
|
Entry = &DirEnt->Entry;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -766,19 +774,19 @@ FatSeekVolumeId (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatFirstFitInsertDirEnt (
|
FatFirstFitInsertDirEnt (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
LIST_ENTRY *CurrentEntry;
|
LIST_ENTRY *CurrentEntry;
|
||||||
FAT_DIRENT *CurrentDirEnt;
|
FAT_DIRENT *CurrentDirEnt;
|
||||||
UINT32 CurrentPos;
|
UINT32 CurrentPos;
|
||||||
UINT32 LabelPos;
|
UINT32 LabelPos;
|
||||||
UINT32 NewEntryPos;
|
UINT32 NewEntryPos;
|
||||||
UINT16 EntryCount;
|
UINT16 EntryCount;
|
||||||
FAT_DIRENT LabelDirEnt;
|
FAT_DIRENT LabelDirEnt;
|
||||||
|
|
||||||
LabelPos = 0;
|
LabelPos = 0;
|
||||||
if (OFile->Parent == NULL) {
|
if (OFile->Parent == NULL) {
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -839,8 +848,8 @@ Done:
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatNewEntryPos (
|
FatNewEntryPos (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,15 +914,15 @@ FatNewEntryPos (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetVolumeEntry (
|
FatGetVolumeEntry (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN CHAR16 *Name
|
IN CHAR16 *Name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_DIRENT LabelDirEnt;
|
FAT_DIRENT LabelDirEnt;
|
||||||
|
|
||||||
*Name = 0;
|
*Name = 0;
|
||||||
Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
|
Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
if (!LabelDirEnt.Invalid) {
|
if (!LabelDirEnt.Invalid) {
|
||||||
FatNameToStr (LabelDirEnt.Entry.FileName, FAT_NAME_LEN, FALSE, Name);
|
FatNameToStr (LabelDirEnt.Entry.FileName, FAT_NAME_LEN, FALSE, Name);
|
||||||
@ -934,16 +946,16 @@ FatGetVolumeEntry (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetVolumeEntry (
|
FatSetVolumeEntry (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN CHAR16 *Name
|
IN CHAR16 *Name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_DIRENT LabelDirEnt;
|
FAT_DIRENT LabelDirEnt;
|
||||||
FAT_OFILE *Root;
|
FAT_OFILE *Root;
|
||||||
|
|
||||||
Root = Volume->Root;
|
Root = Volume->Root;
|
||||||
Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
|
Status = FatSeekVolumeId (Volume->Root, &LabelDirEnt);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
@ -983,7 +995,7 @@ FatSetVolumeEntry (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatCreateDotDirEnts (
|
FatCreateDotDirEnts (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -1002,6 +1014,7 @@ FatCreateDotDirEnts (
|
|||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create ".."
|
// Create ".."
|
||||||
//
|
//
|
||||||
@ -1025,10 +1038,10 @@ FatCreateDotDirEnts (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatCreateDirEnt (
|
FatCreateDirEnt (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN CHAR16 *FileName,
|
IN CHAR16 *FileName,
|
||||||
IN UINT8 Attributes,
|
IN UINT8 Attributes,
|
||||||
OUT FAT_DIRENT **PtrDirEnt
|
OUT FAT_DIRENT **PtrDirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_DIRENT *DirEnt;
|
FAT_DIRENT *DirEnt;
|
||||||
@ -1043,12 +1056,13 @@ FatCreateDirEnt (
|
|||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirEnt->Signature = FAT_DIRENT_SIGNATURE;
|
DirEnt->Signature = FAT_DIRENT_SIGNATURE;
|
||||||
DirEnt->FileString = AllocateCopyPool (StrSize (FileName), FileName);
|
DirEnt->FileString = AllocateCopyPool (StrSize (FileName), FileName);
|
||||||
if (DirEnt->FileString == NULL) {
|
if (DirEnt->FileString == NULL) {
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -1085,8 +1099,8 @@ Done:
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatRemoveDirEnt (
|
FatRemoveDirEnt (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_ODIR *ODir;
|
FAT_ODIR *ODir;
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -1125,8 +1140,8 @@ FatRemoveDirEnt (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatOpenDirEnt (
|
FatOpenDirEnt (
|
||||||
IN FAT_OFILE *Parent,
|
IN FAT_OFILE *Parent,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
@ -1158,16 +1173,16 @@ FatOpenDirEnt (
|
|||||||
//
|
//
|
||||||
// The newly created OFile is root
|
// The newly created OFile is root
|
||||||
//
|
//
|
||||||
Volume = VOLUME_FROM_ROOT_DIRENT (DirEnt);
|
Volume = VOLUME_FROM_ROOT_DIRENT (DirEnt);
|
||||||
Volume->Root = OFile;
|
Volume->Root = OFile;
|
||||||
OFile->FileCluster = Volume->RootCluster;
|
OFile->FileCluster = Volume->RootCluster;
|
||||||
if (Volume->FatType != Fat32) {
|
if (Volume->FatType != Fat32) {
|
||||||
OFile->IsFixedRootDir = TRUE;
|
OFile->IsFixedRootDir = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OFile->FileCurrentCluster = OFile->FileCluster;
|
OFile->FileCurrentCluster = OFile->FileCluster;
|
||||||
OFile->Volume = Volume;
|
OFile->Volume = Volume;
|
||||||
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
|
InsertHeadList (&Volume->CheckRef, &OFile->CheckLink);
|
||||||
|
|
||||||
OFile->FileSize = DirEnt->Entry.FileSize;
|
OFile->FileSize = DirEnt->Entry.FileSize;
|
||||||
@ -1199,15 +1214,15 @@ FatOpenDirEnt (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatCloseDirEnt (
|
FatCloseDirEnt (
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
|
|
||||||
OFile = DirEnt->OFile;
|
OFile = DirEnt->OFile;
|
||||||
ASSERT (OFile != NULL);
|
ASSERT (OFile != NULL);
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
|
|
||||||
if (OFile->ODir != NULL) {
|
if (OFile->ODir != NULL) {
|
||||||
FatDiscardODir (OFile);
|
FatDiscardODir (OFile);
|
||||||
@ -1251,10 +1266,10 @@ FatCloseDirEnt (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatLocateOFile (
|
FatLocateOFile (
|
||||||
IN OUT FAT_OFILE **PtrOFile,
|
IN OUT FAT_OFILE **PtrOFile,
|
||||||
IN CHAR16 *FileName,
|
IN CHAR16 *FileName,
|
||||||
IN UINT8 Attributes,
|
IN UINT8 Attributes,
|
||||||
OUT CHAR16 *NewFileName
|
OUT CHAR16 *NewFileName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -1273,13 +1288,14 @@ FatLocateOFile (
|
|||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
OFile = *PtrOFile;
|
OFile = *PtrOFile;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
|
|
||||||
DirIntended = FALSE;
|
DirIntended = FALSE;
|
||||||
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
|
||||||
|
@ -30,11 +30,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatFlushDataCacheRange (
|
FatFlushDataCacheRange (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN UINTN StartPageNo,
|
IN UINTN StartPageNo,
|
||||||
IN UINTN EndPageNo,
|
IN UINTN EndPageNo,
|
||||||
OUT UINT8 *Buffer
|
OUT UINT8 *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN PageNo;
|
UINTN PageNo;
|
||||||
@ -53,9 +53,9 @@ FatFlushDataCacheRange (
|
|||||||
PageSize = (UINTN)1 << PageAlignment;
|
PageSize = (UINTN)1 << PageAlignment;
|
||||||
|
|
||||||
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
|
||||||
@ -96,11 +96,11 @@ FatFlushDataCacheRange (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatExchangeCachePage (
|
FatExchangeCachePage (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN CACHE_DATA_TYPE DataType,
|
IN CACHE_DATA_TYPE DataType,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN CACHE_TAG *CacheTag,
|
IN CACHE_TAG *CacheTag,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -122,16 +122,16 @@ FatExchangeCachePage (
|
|||||||
EntryPos = DiskCache->BaseAddress + LShiftU64 (PageNo, PageAlignment);
|
EntryPos = DiskCache->BaseAddress + LShiftU64 (PageNo, PageAlignment);
|
||||||
RealSize = CacheTag->RealSize;
|
RealSize = CacheTag->RealSize;
|
||||||
if (IoMode == ReadDisk) {
|
if (IoMode == ReadDisk) {
|
||||||
RealSize = (UINTN)1 << PageAlignment;
|
RealSize = (UINTN)1 << PageAlignment;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,8 +147,8 @@ FatExchangeCachePage (
|
|||||||
EntryPos += Volume->FatSize;
|
EntryPos += Volume->FatSize;
|
||||||
} while (--WriteCount > 0);
|
} while (--WriteCount > 0);
|
||||||
|
|
||||||
CacheTag->Dirty = FALSE;
|
CacheTag->Dirty = FALSE;
|
||||||
CacheTag->RealSize = RealSize;
|
CacheTag->RealSize = RealSize;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,17 +168,17 @@ FatExchangeCachePage (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetCachePage (
|
FatGetCachePage (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN CACHE_DATA_TYPE CacheDataType,
|
IN CACHE_DATA_TYPE CacheDataType,
|
||||||
IN UINTN PageNo,
|
IN UINTN PageNo,
|
||||||
IN CACHE_TAG *CacheTag
|
IN CACHE_TAG *CacheTag
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
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,17 +188,18 @@ 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;
|
||||||
//
|
//
|
||||||
CacheTag->PageNo = PageNo;
|
CacheTag->PageNo = PageNo;
|
||||||
Status = FatExchangeCachePage (Volume, CacheDataType, ReadDisk, CacheTag, NULL);
|
Status = FatExchangeCachePage (Volume, CacheDataType, ReadDisk, CacheTag, NULL);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
@ -223,13 +224,13 @@ FatGetCachePage (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAccessUnalignedCachePage (
|
FatAccessUnalignedCachePage (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN CACHE_DATA_TYPE CacheDataType,
|
IN CACHE_DATA_TYPE CacheDataType,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN UINTN PageNo,
|
IN UINTN PageNo,
|
||||||
IN UINTN Offset,
|
IN UINTN Offset,
|
||||||
IN UINTN Length,
|
IN UINTN Length,
|
||||||
IN OUT VOID *Buffer
|
IN OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -247,10 +248,10 @@ FatAccessUnalignedCachePage (
|
|||||||
Source = DiskCache->CacheBase + (GroupNo << DiskCache->PageAlignment) + Offset;
|
Source = DiskCache->CacheBase + (GroupNo << DiskCache->PageAlignment) + Offset;
|
||||||
Destination = Buffer;
|
Destination = Buffer;
|
||||||
if (IoMode != ReadDisk) {
|
if (IoMode != ReadDisk) {
|
||||||
CacheTag->Dirty = TRUE;
|
CacheTag->Dirty = TRUE;
|
||||||
DiskCache->Dirty = TRUE;
|
DiskCache->Dirty = TRUE;
|
||||||
Destination = Source;
|
Destination = Source;
|
||||||
Source = Buffer;
|
Source = Buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyMem (Destination, Source, Length);
|
CopyMem (Destination, Source, Length);
|
||||||
@ -290,13 +291,13 @@ FatAccessUnalignedCachePage (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAccessCache (
|
FatAccessCache (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN CACHE_DATA_TYPE CacheDataType,
|
IN CACHE_DATA_TYPE CacheDataType,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN UINT64 Offset,
|
IN UINT64 Offset,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
IN OUT UINT8 *Buffer,
|
IN OUT UINT8 *Buffer,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -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;
|
||||||
@ -338,8 +339,8 @@ FatAccessCache (
|
|||||||
PageNo++;
|
PageNo++;
|
||||||
}
|
}
|
||||||
|
|
||||||
AlignedPageCount = BufferSize >> PageAlignment;
|
AlignedPageCount = BufferSize >> PageAlignment;
|
||||||
OverRunPageNo = PageNo + AlignedPageCount;
|
OverRunPageNo = PageNo + AlignedPageCount;
|
||||||
//
|
//
|
||||||
// The access of the Aligned data
|
// The access of the Aligned data
|
||||||
//
|
//
|
||||||
@ -355,14 +356,16 @@ 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.
|
||||||
//
|
//
|
||||||
FatFlushDataCacheRange (Volume, IoMode, PageNo, OverRunPageNo, Buffer);
|
FatFlushDataCacheRange (Volume, IoMode, PageNo, OverRunPageNo, Buffer);
|
||||||
Buffer += AlignedSize;
|
Buffer += AlignedSize;
|
||||||
BufferSize -= AlignedSize;
|
BufferSize -= AlignedSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The access of the OverRun data
|
// The access of the OverRun data
|
||||||
//
|
//
|
||||||
@ -390,18 +393,18 @@ FatAccessCache (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatVolumeFlushCache (
|
FatVolumeFlushCache (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
CACHE_DATA_TYPE CacheDataType;
|
CACHE_DATA_TYPE CacheDataType;
|
||||||
UINTN GroupIndex;
|
UINTN GroupIndex;
|
||||||
UINTN GroupMask;
|
UINTN GroupMask;
|
||||||
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.
|
||||||
//
|
//
|
||||||
@ -443,7 +447,7 @@ FatVolumeFlushCache (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatInitializeDiskCache (
|
FatInitializeDiskCache (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DISK_CACHE *DiskCache;
|
DISK_CACHE *DiskCache;
|
||||||
@ -457,23 +461,23 @@ FatInitializeDiskCache (
|
|||||||
// Configure the parameters of disk cache
|
// Configure the parameters of disk cache
|
||||||
//
|
//
|
||||||
if (Volume->FatType == Fat12) {
|
if (Volume->FatType == Fat12) {
|
||||||
FatCacheGroupCount = FAT_FATCACHE_GROUP_MIN_COUNT;
|
FatCacheGroupCount = FAT_FATCACHE_GROUP_MIN_COUNT;
|
||||||
DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MIN_ALIGNMENT;
|
DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MIN_ALIGNMENT;
|
||||||
DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MIN_ALIGNMENT;
|
DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MIN_ALIGNMENT;
|
||||||
} else {
|
} else {
|
||||||
FatCacheGroupCount = FAT_FATCACHE_GROUP_MAX_COUNT;
|
FatCacheGroupCount = FAT_FATCACHE_GROUP_MAX_COUNT;
|
||||||
DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MAX_ALIGNMENT;
|
DiskCache[CacheFat].PageAlignment = FAT_FATCACHE_PAGE_MAX_ALIGNMENT;
|
||||||
DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MAX_ALIGNMENT;
|
DiskCache[CacheData].PageAlignment = FAT_DATACACHE_PAGE_MAX_ALIGNMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiskCache[CacheData].GroupMask = FAT_DATACACHE_GROUP_COUNT - 1;
|
DiskCache[CacheData].GroupMask = FAT_DATACACHE_GROUP_COUNT - 1;
|
||||||
DiskCache[CacheData].BaseAddress = Volume->RootPos;
|
DiskCache[CacheData].BaseAddress = Volume->RootPos;
|
||||||
DiskCache[CacheData].LimitAddress = Volume->VolumeSize;
|
DiskCache[CacheData].LimitAddress = Volume->VolumeSize;
|
||||||
DiskCache[CacheFat].GroupMask = FatCacheGroupCount - 1;
|
DiskCache[CacheFat].GroupMask = FatCacheGroupCount - 1;
|
||||||
DiskCache[CacheFat].BaseAddress = Volume->FatPos;
|
DiskCache[CacheFat].BaseAddress = Volume->FatPos;
|
||||||
DiskCache[CacheFat].LimitAddress = Volume->FatPos + Volume->FatSize;
|
DiskCache[CacheFat].LimitAddress = Volume->FatPos + Volume->FatSize;
|
||||||
FatCacheSize = FatCacheGroupCount << DiskCache[CacheFat].PageAlignment;
|
FatCacheSize = FatCacheGroupCount << DiskCache[CacheFat].PageAlignment;
|
||||||
DataCacheSize = FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment;
|
DataCacheSize = FAT_DATACACHE_GROUP_COUNT << DiskCache[CacheData].PageAlignment;
|
||||||
//
|
//
|
||||||
// Allocate the Fat Cache buffer
|
// Allocate the Fat Cache buffer
|
||||||
//
|
//
|
||||||
@ -482,7 +486,7 @@ FatInitializeDiskCache (
|
|||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
Volume->CacheBuffer = CacheBuffer;
|
Volume->CacheBuffer = CacheBuffer;
|
||||||
DiskCache[CacheFat].CacheBase = CacheBuffer;
|
DiskCache[CacheFat].CacheBase = CacheBuffer;
|
||||||
DiskCache[CacheData].CacheBase = CacheBuffer + FatCacheSize;
|
DiskCache[CacheData].CacheBase = CacheBuffer + FatCacheSize;
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
|
@ -22,8 +22,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatEntryPoint (
|
FatEntryPoint (
|
||||||
IN EFI_HANDLE ImageHandle,
|
IN EFI_HANDLE ImageHandle,
|
||||||
IN EFI_SYSTEM_TABLE *SystemTable
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +39,7 @@ FatEntryPoint (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatUnload (
|
FatUnload (
|
||||||
IN EFI_HANDLE ImageHandle
|
IN EFI_HANDLE ImageHandle
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,7 +113,7 @@ FatDriverBindingStop (
|
|||||||
//
|
//
|
||||||
// DriverBinding protocol instance
|
// DriverBinding protocol instance
|
||||||
//
|
//
|
||||||
EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding = {
|
EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding = {
|
||||||
FatDriverBindingSupported,
|
FatDriverBindingSupported,
|
||||||
FatDriverBindingStart,
|
FatDriverBindingStart,
|
||||||
FatDriverBindingStop,
|
FatDriverBindingStop,
|
||||||
@ -136,11 +136,11 @@ EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding = {
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatEntryPoint (
|
FatEntryPoint (
|
||||||
IN EFI_HANDLE ImageHandle,
|
IN EFI_HANDLE ImageHandle,
|
||||||
IN EFI_SYSTEM_TABLE *SystemTable
|
IN EFI_SYSTEM_TABLE *SystemTable
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialize the EFI Driver Library
|
// Initialize the EFI Driver Library
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -351,11 +360,11 @@ FatDriverBindingStart (
|
|||||||
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
EFI_BLOCK_IO_PROTOCOL *BlockIo;
|
||||||
EFI_DISK_IO_PROTOCOL *DiskIo;
|
EFI_DISK_IO_PROTOCOL *DiskIo;
|
||||||
EFI_DISK_IO2_PROTOCOL *DiskIo2;
|
EFI_DISK_IO2_PROTOCOL *DiskIo2;
|
||||||
BOOLEAN LockedByMe;
|
BOOLEAN LockedByMe;
|
||||||
|
|
||||||
LockedByMe = FALSE;
|
LockedByMe = FALSE;
|
||||||
//
|
//
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,16 +483,16 @@ Exit:
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatDriverBindingStop (
|
FatDriverBindingStop (
|
||||||
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
||||||
IN EFI_HANDLE ControllerHandle,
|
IN EFI_HANDLE ControllerHandle,
|
||||||
IN UINTN NumberOfChildren,
|
IN UINTN NumberOfChildren,
|
||||||
IN EFI_HANDLE *ChildHandleBuffer
|
IN EFI_HANDLE *ChildHandleBuffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
|
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
EFI_DISK_IO2_PROTOCOL *DiskIo2;
|
EFI_DISK_IO2_PROTOCOL *DiskIo2;
|
||||||
|
|
||||||
DiskIo2 = NULL;
|
DiskIo2 = NULL;
|
||||||
//
|
//
|
||||||
@ -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
|
||||||
@ -505,19 +516,20 @@ FatDriverBindingStop (
|
|||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
if (DiskIo2 != NULL) {
|
if (DiskIo2 != NULL) {
|
||||||
Status = gBS->CloseProtocol (
|
Status = gBS->CloseProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiDiskIo2ProtocolGuid,
|
&gEfiDiskIo2ProtocolGuid,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle
|
ControllerHandle
|
||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = gBS->CloseProtocol (
|
Status = gBS->CloseProtocol (
|
||||||
ControllerHandle,
|
ControllerHandle,
|
||||||
&gEfiDiskIoProtocolGuid,
|
&gEfiDiskIoProtocolGuid,
|
||||||
This->DriverBindingHandle,
|
This->DriverBindingHandle,
|
||||||
ControllerHandle
|
ControllerHandle
|
||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -20,142 +20,141 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
//
|
//
|
||||||
// FAT entry values
|
// FAT entry values
|
||||||
//
|
//
|
||||||
#define FAT_CLUSTER_SPECIAL_EXT (MAX_UINTN & (~0xF))
|
#define FAT_CLUSTER_SPECIAL_EXT (MAX_UINTN & (~0xF))
|
||||||
#define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
|
#define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
|
||||||
#define FAT_CLUSTER_FREE 0
|
#define FAT_CLUSTER_FREE 0
|
||||||
#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
|
#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
|
||||||
#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
|
#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
|
||||||
#define FAT_CLUSTER_LAST (-1)
|
#define FAT_CLUSTER_LAST (-1)
|
||||||
#define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
|
#define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
|
||||||
#define FAT_MIN_CLUSTER 2
|
#define FAT_MIN_CLUSTER 2
|
||||||
#define FAT_MAX_FAT12_CLUSTER 0xFF5
|
#define FAT_MAX_FAT12_CLUSTER 0xFF5
|
||||||
#define FAT_MAX_FAT16_CLUSTER 0xFFF5
|
#define FAT_MAX_FAT16_CLUSTER 0xFFF5
|
||||||
#define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
|
#define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
|
||||||
#define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
|
#define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
|
||||||
#define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
|
#define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
|
||||||
#define FAT_CLUSTER_MASK_FAT12 0xFFF
|
#define FAT_CLUSTER_MASK_FAT12 0xFFF
|
||||||
#define FAT_CLUSTER_UNMASK_FAT12 0xF000
|
#define FAT_CLUSTER_UNMASK_FAT12 0xF000
|
||||||
#define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
|
#define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
|
||||||
#define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
|
#define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
|
||||||
#define FAT_POS_FAT12(a) ((a) * 3 / 2)
|
#define FAT_POS_FAT12(a) ((a) * 3 / 2)
|
||||||
#define FAT_POS_FAT16(a) ((a) * 2)
|
#define FAT_POS_FAT16(a) ((a) * 2)
|
||||||
#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
|
||||||
//
|
//
|
||||||
#define FAT_ATTRIBUTE_READ_ONLY 0x01
|
#define FAT_ATTRIBUTE_READ_ONLY 0x01
|
||||||
#define FAT_ATTRIBUTE_HIDDEN 0x02
|
#define FAT_ATTRIBUTE_HIDDEN 0x02
|
||||||
#define FAT_ATTRIBUTE_SYSTEM 0x04
|
#define FAT_ATTRIBUTE_SYSTEM 0x04
|
||||||
#define FAT_ATTRIBUTE_VOLUME_ID 0x08
|
#define FAT_ATTRIBUTE_VOLUME_ID 0x08
|
||||||
#define FAT_ATTRIBUTE_DIRECTORY 0x10
|
#define FAT_ATTRIBUTE_DIRECTORY 0x10
|
||||||
#define FAT_ATTRIBUTE_ARCHIVE 0x20
|
#define FAT_ATTRIBUTE_ARCHIVE 0x20
|
||||||
#define FAT_ATTRIBUTE_DEVICE 0x40
|
#define FAT_ATTRIBUTE_DEVICE 0x40
|
||||||
#define FAT_ATTRIBUTE_LFN 0x0F
|
#define FAT_ATTRIBUTE_LFN 0x0F
|
||||||
//
|
//
|
||||||
// Some Long File Name definitions
|
// Some Long File Name definitions
|
||||||
//
|
//
|
||||||
#define FAT_LFN_LAST 0x40 // Ordinal field
|
#define FAT_LFN_LAST 0x40 // Ordinal field
|
||||||
#define MAX_LFN_ENTRIES 20
|
#define MAX_LFN_ENTRIES 20
|
||||||
#define LFN_CHAR1_LEN 5
|
#define LFN_CHAR1_LEN 5
|
||||||
#define LFN_CHAR2_LEN 6
|
#define LFN_CHAR2_LEN 6
|
||||||
#define LFN_CHAR3_LEN 2
|
#define LFN_CHAR3_LEN 2
|
||||||
#define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
|
#define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
|
||||||
#define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
|
#define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
|
||||||
//
|
//
|
||||||
// Some 8.3 File Name definitions
|
// Some 8.3 File Name definitions
|
||||||
//
|
//
|
||||||
#define FAT_MAIN_NAME_LEN 8
|
#define FAT_MAIN_NAME_LEN 8
|
||||||
#define FAT_EXTEND_NAME_LEN 3
|
#define FAT_EXTEND_NAME_LEN 3
|
||||||
#define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
|
#define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
|
||||||
//
|
//
|
||||||
// Some directory entry information
|
// Some directory entry information
|
||||||
//
|
//
|
||||||
#define FAT_ENTRY_INFO_OFFSET 13
|
#define FAT_ENTRY_INFO_OFFSET 13
|
||||||
#define DELETE_ENTRY_MARK 0xE5
|
#define DELETE_ENTRY_MARK 0xE5
|
||||||
#define EMPTY_ENTRY_MARK 0x00
|
#define EMPTY_ENTRY_MARK 0x00
|
||||||
|
|
||||||
//
|
//
|
||||||
// Volume dirty Mask
|
// Volume dirty Mask
|
||||||
//
|
//
|
||||||
#define FAT16_DIRTY_MASK 0x7fff
|
#define FAT16_DIRTY_MASK 0x7fff
|
||||||
#define FAT32_DIRTY_MASK 0xf7ffffff
|
#define FAT32_DIRTY_MASK 0xf7ffffff
|
||||||
//
|
//
|
||||||
// internal flag
|
// internal flag
|
||||||
//
|
//
|
||||||
#define FAT_CASE_MIXED 0x01
|
#define FAT_CASE_MIXED 0x01
|
||||||
#define FAT_CASE_NAME_LOWER 0x08
|
#define FAT_CASE_NAME_LOWER 0x08
|
||||||
#define FAT_CASE_EXT_LOWER 0x10
|
#define FAT_CASE_EXT_LOWER 0x10
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT8 Ia32Jump[3];
|
UINT8 Ia32Jump[3];
|
||||||
CHAR8 OemId[8];
|
CHAR8 OemId[8];
|
||||||
UINT16 SectorSize;
|
UINT16 SectorSize;
|
||||||
UINT8 SectorsPerCluster;
|
UINT8 SectorsPerCluster;
|
||||||
UINT16 ReservedSectors;
|
UINT16 ReservedSectors;
|
||||||
UINT8 NumFats;
|
UINT8 NumFats;
|
||||||
UINT16 RootEntries; // < FAT32, root dir is fixed size
|
UINT16 RootEntries; // < FAT32, root dir is fixed size
|
||||||
UINT16 Sectors;
|
UINT16 Sectors;
|
||||||
UINT8 Media;
|
UINT8 Media;
|
||||||
UINT16 SectorsPerFat; // < FAT32
|
UINT16 SectorsPerFat; // < FAT32
|
||||||
UINT16 SectorsPerTrack; // (ignored)
|
UINT16 SectorsPerTrack; // (ignored)
|
||||||
UINT16 Heads; // (ignored)
|
UINT16 Heads; // (ignored)
|
||||||
UINT32 HiddenSectors; // (ignored)
|
UINT32 HiddenSectors; // (ignored)
|
||||||
UINT32 LargeSectors; // Used if Sectors==0
|
UINT32 LargeSectors; // Used if Sectors==0
|
||||||
} FAT_BOOT_SECTOR_BASIC;
|
} FAT_BOOT_SECTOR_BASIC;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT8 PhysicalDriveNumber; // (ignored)
|
UINT8 PhysicalDriveNumber; // (ignored)
|
||||||
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
||||||
UINT8 Signature; // (ignored)
|
UINT8 Signature; // (ignored)
|
||||||
CHAR8 Id[4];
|
CHAR8 Id[4];
|
||||||
CHAR8 FatLabel[11];
|
CHAR8 FatLabel[11];
|
||||||
CHAR8 SystemId[8];
|
CHAR8 SystemId[8];
|
||||||
} FAT_BOOT_SECTOR_EXT;
|
} FAT_BOOT_SECTOR_EXT;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT32 LargeSectorsPerFat; // FAT32
|
UINT32 LargeSectorsPerFat; // FAT32
|
||||||
UINT16 ExtendedFlags; // FAT32 (ignored)
|
UINT16 ExtendedFlags; // FAT32 (ignored)
|
||||||
UINT16 FsVersion; // FAT32 (ignored)
|
UINT16 FsVersion; // FAT32 (ignored)
|
||||||
UINT32 RootDirFirstCluster; // FAT32
|
UINT32 RootDirFirstCluster; // FAT32
|
||||||
UINT16 FsInfoSector; // FAT32
|
UINT16 FsInfoSector; // FAT32
|
||||||
UINT16 BackupBootSector; // FAT32
|
UINT16 BackupBootSector; // FAT32
|
||||||
UINT8 Reserved[12]; // FAT32 (ignored)
|
UINT8 Reserved[12]; // FAT32 (ignored)
|
||||||
UINT8 PhysicalDriveNumber; // (ignored)
|
UINT8 PhysicalDriveNumber; // (ignored)
|
||||||
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
||||||
UINT8 Signature; // (ignored)
|
UINT8 Signature; // (ignored)
|
||||||
CHAR8 Id[4];
|
CHAR8 Id[4];
|
||||||
CHAR8 FatLabel[11];
|
CHAR8 FatLabel[11];
|
||||||
CHAR8 SystemId[8];
|
CHAR8 SystemId[8];
|
||||||
} FAT32_BOOT_SECTOR_EXT;
|
} FAT32_BOOT_SECTOR_EXT;
|
||||||
|
|
||||||
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;
|
||||||
FAT_BSE FatBse;
|
FAT_BSE FatBse;
|
||||||
} FAT_BOOT_SECTOR;
|
} FAT_BOOT_SECTOR;
|
||||||
|
|
||||||
//
|
//
|
||||||
// FAT Info Structure
|
// FAT Info Structure
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT32 ClusterCount;
|
UINT32 ClusterCount;
|
||||||
UINT32 NextCluster;
|
UINT32 NextCluster;
|
||||||
} FAT_FREE_INFO;
|
} FAT_FREE_INFO;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT32 Signature;
|
UINT32 Signature;
|
||||||
UINT8 ExtraBootCode[480];
|
UINT8 ExtraBootCode[480];
|
||||||
UINT32 InfoBeginSignature;
|
UINT32 InfoBeginSignature;
|
||||||
FAT_FREE_INFO FreeInfo;
|
FAT_FREE_INFO FreeInfo;
|
||||||
UINT8 Reserved[12];
|
UINT8 Reserved[12];
|
||||||
UINT32 InfoEndSignature;
|
UINT32 InfoEndSignature;
|
||||||
} FAT_INFO_SECTOR;
|
} FAT_INFO_SECTOR;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -163,44 +162,44 @@ typedef struct {
|
|||||||
//
|
//
|
||||||
#define FAT_MAX_YEAR_FROM_1980 0x7f
|
#define FAT_MAX_YEAR_FROM_1980 0x7f
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT16 Day : 5;
|
UINT16 Day : 5;
|
||||||
UINT16 Month : 4;
|
UINT16 Month : 4;
|
||||||
UINT16 Year : 7; // From 1980
|
UINT16 Year : 7; // From 1980
|
||||||
} FAT_DATE;
|
} FAT_DATE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT16 DoubleSecond : 5;
|
UINT16 DoubleSecond : 5;
|
||||||
UINT16 Minute : 6;
|
UINT16 Minute : 6;
|
||||||
UINT16 Hour : 5;
|
UINT16 Hour : 5;
|
||||||
} FAT_TIME;
|
} FAT_TIME;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FAT_TIME Time;
|
FAT_TIME Time;
|
||||||
FAT_DATE Date;
|
FAT_DATE Date;
|
||||||
} FAT_DATE_TIME;
|
} FAT_DATE_TIME;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
CHAR8 FileName[11]; // 8.3 filename
|
CHAR8 FileName[11]; // 8.3 filename
|
||||||
UINT8 Attributes;
|
UINT8 Attributes;
|
||||||
UINT8 CaseFlag;
|
UINT8 CaseFlag;
|
||||||
UINT8 CreateMillisecond; // (creation milliseconds - ignored)
|
UINT8 CreateMillisecond; // (creation milliseconds - ignored)
|
||||||
FAT_DATE_TIME FileCreateTime;
|
FAT_DATE_TIME FileCreateTime;
|
||||||
FAT_DATE FileLastAccess;
|
FAT_DATE FileLastAccess;
|
||||||
UINT16 FileClusterHigh; // >= FAT32
|
UINT16 FileClusterHigh; // >= FAT32
|
||||||
FAT_DATE_TIME FileModificationTime;
|
FAT_DATE_TIME FileModificationTime;
|
||||||
UINT16 FileCluster;
|
UINT16 FileCluster;
|
||||||
UINT32 FileSize;
|
UINT32 FileSize;
|
||||||
} FAT_DIRECTORY_ENTRY;
|
} FAT_DIRECTORY_ENTRY;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT8 Ordinal;
|
UINT8 Ordinal;
|
||||||
CHAR8 Name1[10]; // (Really 5 chars, but not WCHAR aligned)
|
CHAR8 Name1[10]; // (Really 5 chars, but not WCHAR aligned)
|
||||||
UINT8 Attributes;
|
UINT8 Attributes;
|
||||||
UINT8 Type;
|
UINT8 Type;
|
||||||
UINT8 Checksum;
|
UINT8 Checksum;
|
||||||
CHAR16 Name2[6];
|
CHAR16 Name2[6];
|
||||||
UINT16 MustBeZero;
|
UINT16 MustBeZero;
|
||||||
CHAR16 Name3[2];
|
CHAR16 Name3[2];
|
||||||
} FAT_DIRECTORY_LFN;
|
} FAT_DIRECTORY_LFN;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
@ -23,16 +23,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatCheckIs8Dot3Name (
|
FatCheckIs8Dot3Name (
|
||||||
IN CHAR16 *FileName,
|
IN CHAR16 *FileName,
|
||||||
OUT CHAR8 *File8Dot3Name
|
OUT CHAR8 *File8Dot3Name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN PossibleShortName;
|
BOOLEAN PossibleShortName;
|
||||||
CHAR16 *TempName;
|
CHAR16 *TempName;
|
||||||
CHAR16 *ExtendName;
|
CHAR16 *ExtendName;
|
||||||
CHAR16 *SeparateDot;
|
CHAR16 *SeparateDot;
|
||||||
UINTN MainNameLen;
|
UINTN MainNameLen;
|
||||||
UINTN ExtendNameLen;
|
UINTN ExtendNameLen;
|
||||||
|
|
||||||
PossibleShortName = TRUE;
|
PossibleShortName = TRUE;
|
||||||
SeparateDot = NULL;
|
SeparateDot = NULL;
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -109,8 +110,8 @@ FatCheckIs8Dot3Name (
|
|||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINTN
|
||||||
FatTrimAsciiTrailingBlanks (
|
FatTrimAsciiTrailingBlanks (
|
||||||
IN CHAR8 *Name,
|
IN CHAR8 *Name,
|
||||||
IN UINTN Len
|
IN UINTN Len
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
while (Len > 0 && Name[Len - 1] == ' ') {
|
while (Len > 0 && Name[Len - 1] == ' ') {
|
||||||
@ -133,10 +134,10 @@ FatTrimAsciiTrailingBlanks (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatNameToStr (
|
FatNameToStr (
|
||||||
IN CHAR8 *FatName,
|
IN CHAR8 *FatName,
|
||||||
IN UINTN Len,
|
IN UINTN Len,
|
||||||
IN UINTN LowerCase,
|
IN UINTN LowerCase,
|
||||||
OUT CHAR16 *Str
|
OUT CHAR16 *Str
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@ -166,20 +167,21 @@ FatNameToStr (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatCreate8Dot3Name (
|
FatCreate8Dot3Name (
|
||||||
IN FAT_OFILE *Parent,
|
IN FAT_OFILE *Parent,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR8 *ShortName;
|
CHAR8 *ShortName;
|
||||||
CHAR8 *ShortNameChar;
|
CHAR8 *ShortNameChar;
|
||||||
UINTN BaseTagLen;
|
UINTN BaseTagLen;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
UINTN Retry;
|
UINTN Retry;
|
||||||
UINT8 Segment;
|
UINT8 Segment;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
UINT32 Crc;
|
UINT32 Crc;
|
||||||
struct HEX_DATA {
|
struct HEX_DATA {
|
||||||
UINT8 Segment : HASH_VALUE_TAG_LEN;
|
UINT8 Segment : HASH_VALUE_TAG_LEN;
|
||||||
} Hex[HASH_VALUE_TAG_LEN];
|
} Hex[HASH_VALUE_TAG_LEN];
|
||||||
} HashValue;
|
} HashValue;
|
||||||
//
|
//
|
||||||
@ -195,13 +197,14 @@ 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.
|
||||||
//
|
//
|
||||||
ShortNameChar = ShortName + BaseTagLen;
|
ShortNameChar = ShortName + BaseTagLen;
|
||||||
*ShortNameChar++ = '~';
|
*ShortNameChar++ = '~';
|
||||||
*ShortNameChar = '1';
|
*ShortNameChar = '1';
|
||||||
Retry = 0;
|
Retry = 0;
|
||||||
while (*FatShortNameHashSearch (Parent->ODir, ShortName) != NULL) {
|
while (*FatShortNameHashSearch (Parent->ODir, ShortName) != NULL) {
|
||||||
*ShortNameChar = (CHAR8)(*ShortNameChar + 1);
|
*ShortNameChar = (CHAR8)(*ShortNameChar + 1);
|
||||||
if (++Retry == MAX_SPEC_RETRY) {
|
if (++Retry == MAX_SPEC_RETRY) {
|
||||||
@ -225,8 +228,8 @@ FatCreate8Dot3Name (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ShortNameChar++ = '~';
|
*ShortNameChar++ = '~';
|
||||||
*ShortNameChar = '1';
|
*ShortNameChar = '1';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,8 +248,8 @@ FatCreate8Dot3Name (
|
|||||||
STATIC
|
STATIC
|
||||||
UINT8
|
UINT8
|
||||||
FatCheckNameCase (
|
FatCheckNameCase (
|
||||||
IN CHAR16 *Str,
|
IN CHAR16 *Str,
|
||||||
IN UINT8 InCaseFlag
|
IN UINT8 InCaseFlag
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 Buffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];
|
CHAR16 Buffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];
|
||||||
@ -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
|
||||||
@ -287,7 +291,7 @@ FatCheckNameCase (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatSetCaseFlag (
|
FatSetCaseFlag (
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 LfnBuffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];
|
CHAR16 LfnBuffer[FAT_MAIN_NAME_LEN + 1 + FAT_EXTEND_NAME_LEN + 1];
|
||||||
@ -342,14 +346,15 @@ FatSetCaseFlag (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatGetFileNameViaCaseFlag (
|
FatGetFileNameViaCaseFlag (
|
||||||
IN FAT_DIRENT *DirEnt,
|
IN FAT_DIRENT *DirEnt,
|
||||||
IN OUT CHAR16 *FileString,
|
IN OUT CHAR16 *FileString,
|
||||||
IN UINTN FileStringMax
|
IN UINTN FileStringMax
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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"
|
||||||
//
|
//
|
||||||
@ -378,8 +383,9 @@ FatCheckSum (
|
|||||||
IN CHAR8 *ShortNameString
|
IN CHAR8 *ShortNameString
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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++);
|
||||||
@ -402,13 +408,14 @@ FatCheckSum (
|
|||||||
**/
|
**/
|
||||||
CHAR16 *
|
CHAR16 *
|
||||||
FatGetNextNameComponent (
|
FatGetNextNameComponent (
|
||||||
IN CHAR16 *Path,
|
IN CHAR16 *Path,
|
||||||
OUT CHAR16 *Name
|
OUT CHAR16 *Name
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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.
|
||||||
@ -24,46 +23,48 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
STATIC
|
STATIC
|
||||||
VOID *
|
VOID *
|
||||||
FatLoadFatEntry (
|
FatLoadFatEntry (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN Index
|
IN UINTN Index
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Pos;
|
UINTN Pos;
|
||||||
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
|
||||||
//
|
//
|
||||||
switch (Volume->FatType) {
|
switch (Volume->FatType) {
|
||||||
case Fat12:
|
case Fat12:
|
||||||
Pos = FAT_POS_FAT12 (Index);
|
Pos = FAT_POS_FAT12 (Index);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Fat16:
|
case Fat16:
|
||||||
Pos = FAT_POS_FAT16 (Index);
|
Pos = FAT_POS_FAT16 (Index);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
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
|
||||||
//
|
//
|
||||||
Volume->FatEntryPos = Volume->FatPos + Pos;
|
Volume->FatEntryPos = Volume->FatPos + Pos;
|
||||||
Status = FatDiskIo (
|
Status = FatDiskIo (
|
||||||
Volume,
|
Volume,
|
||||||
ReadFat,
|
ReadFat,
|
||||||
Volume->FatEntryPos,
|
Volume->FatEntryPos,
|
||||||
Volume->FatEntrySize,
|
Volume->FatEntrySize,
|
||||||
&Volume->FatEntryBuffer,
|
&Volume->FatEntryBuffer,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
Volume->FatEntryBuffer = (UINT32) -1;
|
Volume->FatEntryBuffer = (UINT32)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Volume->FatEntryBuffer;
|
return &Volume->FatEntryBuffer;
|
||||||
@ -82,8 +83,8 @@ FatLoadFatEntry (
|
|||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINTN
|
||||||
FatGetFatEntry (
|
FatGetFatEntry (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN Index
|
IN UINTN Index
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
VOID *Pos;
|
VOID *Pos;
|
||||||
@ -95,27 +96,27 @@ 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) {
|
||||||
case Fat12:
|
case Fat12:
|
||||||
En12 = Pos;
|
En12 = Pos;
|
||||||
Accum = En12[0] | (En12[1] << 8);
|
Accum = En12[0] | (En12[1] << 8);
|
||||||
Accum = FAT_ODD_CLUSTER_FAT12 (Index) ? (Accum >> 4) : (Accum & FAT_CLUSTER_MASK_FAT12);
|
Accum = FAT_ODD_CLUSTER_FAT12 (Index) ? (Accum >> 4) : (Accum & FAT_CLUSTER_MASK_FAT12);
|
||||||
Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT12) ? FAT_CLUSTER_SPECIAL_EXT : 0);
|
Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT12) ? FAT_CLUSTER_SPECIAL_EXT : 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Fat16:
|
case Fat16:
|
||||||
En16 = Pos;
|
En16 = Pos;
|
||||||
Accum = *En16;
|
Accum = *En16;
|
||||||
Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT16) ? FAT_CLUSTER_SPECIAL_EXT : 0);
|
Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT16) ? FAT_CLUSTER_SPECIAL_EXT : 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
En32 = Pos;
|
En32 = Pos;
|
||||||
Accum = *En32 & FAT_CLUSTER_MASK_FAT32;
|
Accum = *En32 & FAT_CLUSTER_MASK_FAT32;
|
||||||
Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT32) ? FAT_CLUSTER_SPECIAL_EXT : 0);
|
Accum = Accum | ((Accum >= FAT_CLUSTER_SPECIAL_FAT32) ? FAT_CLUSTER_SPECIAL_EXT : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Accum;
|
return Accum;
|
||||||
@ -137,9 +138,9 @@ FatGetFatEntry (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetFatEntry (
|
FatSetFatEntry (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN Index,
|
IN UINTN Index,
|
||||||
IN UINTN Value
|
IN UINTN Value
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
VOID *Pos;
|
VOID *Pos;
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -174,37 +176,39 @@ FatSetFatEntry (
|
|||||||
// Update the value
|
// Update the value
|
||||||
//
|
//
|
||||||
switch (Volume->FatType) {
|
switch (Volume->FatType) {
|
||||||
case Fat12:
|
case Fat12:
|
||||||
En12 = Pos;
|
En12 = Pos;
|
||||||
Accum = En12[0] | (En12[1] << 8);
|
Accum = En12[0] | (En12[1] << 8);
|
||||||
Value = Value & FAT_CLUSTER_MASK_FAT12;
|
Value = Value & FAT_CLUSTER_MASK_FAT12;
|
||||||
|
|
||||||
if (FAT_ODD_CLUSTER_FAT12 (Index)) {
|
if (FAT_ODD_CLUSTER_FAT12 (Index)) {
|
||||||
Accum = (Value << 4) | (Accum & 0xF);
|
Accum = (Value << 4) | (Accum & 0xF);
|
||||||
} else {
|
} else {
|
||||||
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
|
||||||
@ -235,15 +239,14 @@ FatSetFatEntry (
|
|||||||
STATIC
|
STATIC
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatFreeClusters (
|
FatFreeClusters (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN Cluster
|
IN UINTN Cluster
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -268,30 +271,30 @@ FatFreeClusters (
|
|||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINTN
|
||||||
FatAllocateCluster (
|
FatAllocateCluster (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Cluster;
|
UINTN Cluster;
|
||||||
|
|
||||||
//
|
//
|
||||||
// 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,13 +302,14 @@ FatAllocateCluster (
|
|||||||
if (Cluster == FAT_CLUSTER_FREE) {
|
if (Cluster == FAT_CLUSTER_FREE) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Try the next cluster
|
// Try the next cluster
|
||||||
//
|
//
|
||||||
Volume->FatInfoSector.FreeInfo.NextCluster += 1;
|
Volume->FatInfoSector.FreeInfo.NextCluster += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cluster = Volume->FatInfoSector.FreeInfo.NextCluster;
|
Cluster = Volume->FatInfoSector.FreeInfo.NextCluster;
|
||||||
Volume->FatInfoSector.FreeInfo.NextCluster += 1;
|
Volume->FatInfoSector.FreeInfo.NextCluster += 1;
|
||||||
return Cluster;
|
return Cluster;
|
||||||
}
|
}
|
||||||
@ -323,11 +327,11 @@ FatAllocateCluster (
|
|||||||
STATIC
|
STATIC
|
||||||
UINTN
|
UINTN
|
||||||
FatSizeToClusters (
|
FatSizeToClusters (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN Size
|
IN UINTN Size
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Clusters;
|
UINTN Clusters;
|
||||||
|
|
||||||
Clusters = Size >> Volume->ClusterAlignment;
|
Clusters = Size >> Volume->ClusterAlignment;
|
||||||
if ((Size & (Volume->ClusterSize - 1)) > 0) {
|
if ((Size & (Volume->ClusterSize - 1)) > 0) {
|
||||||
@ -349,7 +353,7 @@ FatSizeToClusters (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatShrinkEof (
|
FatShrinkEof (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
@ -358,7 +362,7 @@ FatShrinkEof (
|
|||||||
UINTN Cluster;
|
UINTN Cluster;
|
||||||
UINTN LastCluster;
|
UINTN LastCluster;
|
||||||
|
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
ASSERT_VOLUME_LOCKED (Volume);
|
ASSERT_VOLUME_LOCKED (Volume);
|
||||||
|
|
||||||
NewSize = FatSizeToClusters (Volume, OFile->FileSize);
|
NewSize = FatSizeToClusters (Volume, OFile->FileSize);
|
||||||
@ -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
|
||||||
@ -424,8 +427,8 @@ FatShrinkEof (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGrowEof (
|
FatGrowEof (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN UINT64 NewSizeInBytes
|
IN UINT64 NewSizeInBytes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
@ -450,42 +453,41 @@ 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) {
|
||||||
//
|
//
|
||||||
// If we haven't found the files last cluster do it now
|
// If we haven't found the files last cluster do it now
|
||||||
//
|
//
|
||||||
if ((OFile->FileCluster != 0) && (OFile->FileLastCluster == 0)) {
|
if ((OFile->FileCluster != 0) && (OFile->FileLastCluster == 0)) {
|
||||||
Cluster = OFile->FileCluster;
|
Cluster = OFile->FileCluster;
|
||||||
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")
|
||||||
);
|
);
|
||||||
Status = EFI_VOLUME_CORRUPTED;
|
Status = EFI_VOLUME_CORRUPTED;
|
||||||
goto Done;
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClusterCount++;
|
ClusterCount++;
|
||||||
OFile->FileLastCluster = Cluster;
|
OFile->FileLastCluster = Cluster;
|
||||||
Cluster = FatGetFatEntry (Volume, Cluster);
|
Cluster = FatGetFatEntry (Volume, Cluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ClusterCount != CurSize) {
|
if (ClusterCount != CurSize) {
|
||||||
DEBUG (
|
DEBUG (
|
||||||
(DEBUG_INIT | DEBUG_ERROR,
|
(DEBUG_INIT | DEBUG_ERROR,
|
||||||
"FatGrowEof: cluster chain size does not match file size\n")
|
"FatGrowEof: cluster chain size does not match file size\n")
|
||||||
);
|
);
|
||||||
Status = EFI_VOLUME_CORRUPTED;
|
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;
|
||||||
}
|
}
|
||||||
@ -516,7 +518,7 @@ FatGrowEof (
|
|||||||
}
|
}
|
||||||
|
|
||||||
LastCluster = NewCluster;
|
LastCluster = NewCluster;
|
||||||
CurSize += 1;
|
CurSize += 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Terminate the cluster list
|
// Terminate the cluster list
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -558,9 +560,9 @@ Done:
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatOFilePosition (
|
FatOFilePosition (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN UINTN Position,
|
IN UINTN Position,
|
||||||
IN UINTN PosLimit
|
IN UINTN PosLimit
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
@ -579,8 +581,8 @@ FatOFilePosition (
|
|||||||
// from its fixed info in the fat bpb
|
// from its fixed info in the fat bpb
|
||||||
//
|
//
|
||||||
if (OFile->IsFixedRootDir) {
|
if (OFile->IsFixedRootDir) {
|
||||||
OFile->PosDisk = Volume->RootPos + Position;
|
OFile->PosDisk = Volume->RootPos + Position;
|
||||||
Run = OFile->FileSize - Position;
|
Run = OFile->FileSize - Position;
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Run the file's cluster chain to find the current position
|
// Run the file's cluster chain to find the current position
|
||||||
@ -594,30 +596,30 @@ FatOFilePosition (
|
|||||||
// when OFile->FileCluster is updated, so make a check of this
|
// when OFile->FileCluster is updated, so make a check of this
|
||||||
// and invalidate the original OFile->Position in this case
|
// and invalidate the original OFile->Position in this case
|
||||||
//
|
//
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
OFile->PosDisk = Volume->FirstClusterPos +
|
OFile->PosDisk = Volume->FirstClusterPos +
|
||||||
LShiftU64 (Cluster - FAT_MIN_CLUSTER, Volume->ClusterAlignment) +
|
LShiftU64 (Cluster - FAT_MIN_CLUSTER, Volume->ClusterAlignment) +
|
||||||
Position - StartPos;
|
Position - StartPos;
|
||||||
OFile->FileCurrentCluster = Cluster;
|
OFile->FileCurrentCluster = Cluster;
|
||||||
OFile->Position = StartPos;
|
OFile->Position = StartPos;
|
||||||
|
|
||||||
@ -650,11 +652,12 @@ FatOFilePosition (
|
|||||||
**/
|
**/
|
||||||
UINTN
|
UINTN
|
||||||
FatPhysicalDirSize (
|
FatPhysicalDirSize (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN Cluster
|
IN UINTN Cluster
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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,15 +669,15 @@ 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")
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size += Volume->ClusterSize;
|
Size += Volume->ClusterSize;
|
||||||
Cluster = FatGetFatEntry (Volume, Cluster);
|
Cluster = FatGetFatEntry (Volume, Cluster);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -694,14 +697,15 @@ FatPhysicalDirSize (
|
|||||||
**/
|
**/
|
||||||
UINT64
|
UINT64
|
||||||
FatPhysicalFileSize (
|
FatPhysicalFileSize (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN RealSize
|
IN UINTN RealSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,18 +718,17 @@ FatPhysicalFileSize (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatComputeFreeInfo (
|
FatComputeFreeInfo (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
|
|
||||||
//
|
//
|
||||||
// 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--) {
|
||||||
if (Volume->DiskError) {
|
if (Volume->DiskError) {
|
||||||
break;
|
break;
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,10 +35,10 @@ FatFlushEx (
|
|||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_TASK *Task;
|
FAT_TASK *Task;
|
||||||
|
|
||||||
IFile = IFILE_FROM_FHAND (FHand);
|
IFile = IFILE_FROM_FHAND (FHand);
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
Task = NULL;
|
Task = NULL;
|
||||||
|
|
||||||
//
|
//
|
||||||
// If the file has a permanent error, return it
|
// If the file has a permanent error, return it
|
||||||
@ -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;
|
||||||
@ -77,8 +79,8 @@ FatFlushEx (
|
|||||||
// Flush the OFile
|
// Flush the OFile
|
||||||
//
|
//
|
||||||
FatAcquireLock ();
|
FatAcquireLock ();
|
||||||
Status = FatOFileFlush (OFile);
|
Status = FatOFileFlush (OFile);
|
||||||
Status = FatCleanupVolume (OFile->Volume, OFile, Status, Task);
|
Status = FatCleanupVolume (OFile->Volume, OFile, Status, Task);
|
||||||
FatReleaseLock ();
|
FatReleaseLock ();
|
||||||
|
|
||||||
if (Token != NULL) {
|
if (Token != NULL) {
|
||||||
@ -132,9 +134,9 @@ FatClose (
|
|||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
|
|
||||||
IFile = IFILE_FROM_FHAND (FHand);
|
IFile = IFILE_FROM_FHAND (FHand);
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lock the volume
|
// Lock the volume
|
||||||
@ -169,14 +171,14 @@ FatClose (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatIFileClose (
|
FatIFileClose (
|
||||||
FAT_IFILE *IFile
|
FAT_IFILE *IFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
|
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
|
|
||||||
ASSERT_VOLUME_LOCKED (Volume);
|
ASSERT_VOLUME_LOCKED (Volume);
|
||||||
|
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -213,13 +216,13 @@ FatIFileClose (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatOFileFlush (
|
FatOFileFlush (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_OFILE *Parent;
|
FAT_OFILE *Parent;
|
||||||
FAT_DIRENT *DirEnt;
|
FAT_DIRENT *DirEnt;
|
||||||
FAT_DATE_TIME FatNow;
|
FAT_DATE_TIME FatNow;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Flush each entry up the tree while dirty
|
// Flush each entry up the tree while dirty
|
||||||
@ -233,8 +236,8 @@ FatOFileFlush (
|
|||||||
return OFile->Error;
|
return OFile->Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parent = OFile->Parent;
|
Parent = OFile->Parent;
|
||||||
DirEnt = OFile->DirEnt;
|
DirEnt = OFile->DirEnt;
|
||||||
if (OFile->Dirty) {
|
if (OFile->Dirty) {
|
||||||
//
|
//
|
||||||
// Update the last modification time
|
// Update the last modification time
|
||||||
@ -248,12 +251,13 @@ FatOFileFlush (
|
|||||||
OFile->PreserveLastModification = FALSE;
|
OFile->PreserveLastModification = FALSE;
|
||||||
if (OFile->Archive) {
|
if (OFile->Archive) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +293,7 @@ FatOFileFlush (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatCheckOFileRef (
|
FatCheckOFileRef (
|
||||||
IN FAT_OFILE *OFile
|
IN FAT_OFILE *OFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@ -308,6 +314,7 @@ FatCheckOFileRef (
|
|||||||
//
|
//
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Free the Ofile
|
// Free the Ofile
|
||||||
//
|
//
|
||||||
@ -328,11 +335,11 @@ FatCheckOFileRef (
|
|||||||
STATIC
|
STATIC
|
||||||
VOID
|
VOID
|
||||||
FatCheckVolumeRef (
|
FatCheckVolumeRef (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
FAT_OFILE *Parent;
|
FAT_OFILE *Parent;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check all files on the pending check list
|
// Check all files on the pending check list
|
||||||
@ -346,8 +353,8 @@ FatCheckVolumeRef (
|
|||||||
// Go up the tree cleaning up any un-referenced OFiles
|
// Go up the tree cleaning up any un-referenced OFiles
|
||||||
//
|
//
|
||||||
while (Parent != NULL) {
|
while (Parent != NULL) {
|
||||||
OFile = Parent;
|
OFile = Parent;
|
||||||
Parent = OFile->Parent;
|
Parent = OFile->Parent;
|
||||||
if (!FatCheckOFileRef (OFile)) {
|
if (!FatCheckOFileRef (OFile)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -373,19 +380,21 @@ FatCheckVolumeRef (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatCleanupVolume (
|
FatCleanupVolume (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN EFI_STATUS EfiStatus,
|
IN EFI_STATUS EfiStatus,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -445,12 +457,12 @@ FatCleanupVolume (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatSetVolumeError (
|
FatSetVolumeError (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN EFI_STATUS Status
|
IN EFI_STATUS Status
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LIST_ENTRY *Link;
|
LIST_ENTRY *Link;
|
||||||
FAT_OFILE *ChildOFile;
|
FAT_OFILE *ChildOFile;
|
||||||
|
|
||||||
//
|
//
|
||||||
// If this OFile doesn't already have an error, set one
|
// If this OFile doesn't already have an error, set one
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
|
@ -20,11 +20,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
STATIC
|
STATIC
|
||||||
UINT32
|
UINT32
|
||||||
FatHashLongName (
|
FatHashLongName (
|
||||||
IN CHAR16 *LongNameString
|
IN CHAR16 *LongNameString
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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),
|
||||||
@ -48,10 +49,11 @@ FatHashLongName (
|
|||||||
STATIC
|
STATIC
|
||||||
UINT32
|
UINT32
|
||||||
FatHashShortName (
|
FatHashShortName (
|
||||||
IN CHAR8 *ShortNameString
|
IN CHAR8 *ShortNameString
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -68,15 +70,17 @@ FatHashShortName (
|
|||||||
**/
|
**/
|
||||||
FAT_DIRENT **
|
FAT_DIRENT **
|
||||||
FatLongNameHashSearch (
|
FatLongNameHashSearch (
|
||||||
IN FAT_ODIR *ODir,
|
IN FAT_ODIR *ODir,
|
||||||
IN CHAR16 *LongNameString
|
IN CHAR16 *LongNameString
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -97,15 +101,17 @@ FatLongNameHashSearch (
|
|||||||
**/
|
**/
|
||||||
FAT_DIRENT **
|
FAT_DIRENT **
|
||||||
FatShortNameHashSearch (
|
FatShortNameHashSearch (
|
||||||
IN FAT_ODIR *ODir,
|
IN FAT_ODIR *ODir,
|
||||||
IN CHAR8 *ShortNameString
|
IN CHAR8 *ShortNameString
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -124,8 +130,8 @@ FatShortNameHashSearch (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatInsertToHashTable (
|
FatInsertToHashTable (
|
||||||
IN FAT_ODIR *ODir,
|
IN FAT_ODIR *ODir,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_DIRENT **HashTable;
|
FAT_DIRENT **HashTable;
|
||||||
@ -134,17 +140,17 @@ FatInsertToHashTable (
|
|||||||
//
|
//
|
||||||
// Insert hash table index for short name
|
// Insert hash table index for short name
|
||||||
//
|
//
|
||||||
HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);
|
HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);
|
||||||
HashTable = ODir->ShortNameHashTable;
|
HashTable = ODir->ShortNameHashTable;
|
||||||
DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];
|
DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];
|
||||||
HashTable[HashTableIndex] = DirEnt;
|
HashTable[HashTableIndex] = DirEnt;
|
||||||
//
|
//
|
||||||
// Insert hash table index for long name
|
// Insert hash table index for long name
|
||||||
//
|
//
|
||||||
HashTableIndex = FatHashLongName (DirEnt->FileString);
|
HashTableIndex = FatHashLongName (DirEnt->FileString);
|
||||||
HashTable = ODir->LongNameHashTable;
|
HashTable = ODir->LongNameHashTable;
|
||||||
DirEnt->LongNameForwardLink = HashTable[HashTableIndex];
|
DirEnt->LongNameForwardLink = HashTable[HashTableIndex];
|
||||||
HashTable[HashTableIndex] = DirEnt;
|
HashTable[HashTableIndex] = DirEnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,8 +163,8 @@ FatInsertToHashTable (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatDeleteFromHashTable (
|
FatDeleteFromHashTable (
|
||||||
IN FAT_ODIR *ODir,
|
IN FAT_ODIR *ODir,
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
*FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;
|
*FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;
|
||||||
|
@ -24,9 +24,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetVolumeInfo (
|
FatGetVolumeInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,9 +45,9 @@ FatGetVolumeInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetVolumeInfo (
|
FatSetVolumeInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
IN VOID *Buffer
|
IN VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,11 +66,11 @@ FatSetVolumeInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetOrGetInfo (
|
FatSetOrGetInfo (
|
||||||
IN BOOLEAN IsSet,
|
IN BOOLEAN IsSet,
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
IN EFI_GUID *Type,
|
IN EFI_GUID *Type,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
IN OUT VOID *Buffer
|
IN OUT VOID *Buffer
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,9 +87,9 @@ FatSetOrGetInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetFileInfo (
|
FatGetFileInfo (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return FatGetDirEntInfo (OFile->Volume, OFile->DirEnt, BufferSize, Buffer);
|
return FatGetDirEntInfo (OFile->Volume, OFile->DirEnt, BufferSize, Buffer);
|
||||||
@ -109,9 +109,9 @@ FatGetFileInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetVolumeInfo (
|
FatGetVolumeInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
@ -122,11 +122,11 @@ FatGetVolumeInfo (
|
|||||||
EFI_FILE_SYSTEM_INFO *Info;
|
EFI_FILE_SYSTEM_INFO *Info;
|
||||||
UINT8 ClusterAlignment;
|
UINT8 ClusterAlignment;
|
||||||
|
|
||||||
Size = SIZE_OF_EFI_FILE_SYSTEM_INFO;
|
Size = SIZE_OF_EFI_FILE_SYSTEM_INFO;
|
||||||
Status = FatGetVolumeEntry (Volume, Name);
|
Status = FatGetVolumeEntry (Volume, Name);
|
||||||
NameSize = StrSize (Name);
|
NameSize = StrSize (Name);
|
||||||
ResultSize = Size + NameSize;
|
ResultSize = Size + NameSize;
|
||||||
ClusterAlignment = Volume->ClusterAlignment;
|
ClusterAlignment = Volume->ClusterAlignment;
|
||||||
|
|
||||||
//
|
//
|
||||||
// If we don't have valid info, compute it now
|
// If we don't have valid info, compute it now
|
||||||
@ -135,20 +135,20 @@ FatGetVolumeInfo (
|
|||||||
|
|
||||||
Status = EFI_BUFFER_TOO_SMALL;
|
Status = EFI_BUFFER_TOO_SMALL;
|
||||||
if (*BufferSize >= ResultSize) {
|
if (*BufferSize >= ResultSize) {
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
Info = Buffer;
|
Info = Buffer;
|
||||||
ZeroMem (Info, SIZE_OF_EFI_FILE_SYSTEM_INFO);
|
ZeroMem (Info, SIZE_OF_EFI_FILE_SYSTEM_INFO);
|
||||||
|
|
||||||
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;
|
||||||
@ -169,26 +169,26 @@ FatGetVolumeInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatGetVolumeLabelInfo (
|
FatGetVolumeLabelInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
UINTN NameSize;
|
UINTN NameSize;
|
||||||
UINTN ResultSize;
|
UINTN ResultSize;
|
||||||
CHAR16 Name[FAT_NAME_LEN + 1];
|
CHAR16 Name[FAT_NAME_LEN + 1];
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
Size = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL;
|
Size = SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL;
|
||||||
Status = FatGetVolumeEntry (Volume, Name);
|
Status = FatGetVolumeEntry (Volume, Name);
|
||||||
NameSize = StrSize (Name);
|
NameSize = StrSize (Name);
|
||||||
ResultSize = Size + NameSize;
|
ResultSize = Size + NameSize;
|
||||||
|
|
||||||
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;
|
||||||
@ -211,16 +211,16 @@ FatGetVolumeLabelInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetVolumeInfo (
|
FatSetVolumeInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
IN VOID *Buffer
|
IN VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,14 +243,14 @@ FatSetVolumeInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetVolumeLabelInfo (
|
FatSetVolumeLabelInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
IN VOID *Buffer
|
IN VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_FILE_SYSTEM_VOLUME_LABEL *Info;
|
EFI_FILE_SYSTEM_VOLUME_LABEL *Info;
|
||||||
|
|
||||||
Info = (EFI_FILE_SYSTEM_VOLUME_LABEL *) Buffer;
|
Info = (EFI_FILE_SYSTEM_VOLUME_LABEL *)Buffer;
|
||||||
|
|
||||||
if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL + 2) {
|
if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_VOLUME_LABEL + 2) {
|
||||||
return EFI_BAD_BUFFER_SIZE;
|
return EFI_BAD_BUFFER_SIZE;
|
||||||
@ -285,38 +285,39 @@ FatSetVolumeLabelInfo (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatSetFileInfo (
|
FatSetFileInfo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN FAT_IFILE *IFile,
|
IN FAT_IFILE *IFile,
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
IN VOID *Buffer
|
IN VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_FILE_INFO *NewInfo;
|
EFI_FILE_INFO *NewInfo;
|
||||||
FAT_OFILE *DotOFile;
|
FAT_OFILE *DotOFile;
|
||||||
FAT_OFILE *Parent;
|
FAT_OFILE *Parent;
|
||||||
CHAR16 NewFileName[EFI_PATH_STRING_LENGTH];
|
CHAR16 NewFileName[EFI_PATH_STRING_LENGTH];
|
||||||
EFI_TIME ZeroTime;
|
EFI_TIME ZeroTime;
|
||||||
FAT_DIRENT *DirEnt;
|
FAT_DIRENT *DirEnt;
|
||||||
FAT_DIRENT *TempDirEnt;
|
FAT_DIRENT *TempDirEnt;
|
||||||
UINT8 NewAttribute;
|
UINT8 NewAttribute;
|
||||||
BOOLEAN ReadOnly;
|
BOOLEAN ReadOnly;
|
||||||
|
|
||||||
ZeroMem (&ZeroTime, sizeof (EFI_TIME));
|
ZeroMem (&ZeroTime, sizeof (EFI_TIME));
|
||||||
Parent = OFile->Parent;
|
Parent = OFile->Parent;
|
||||||
DirEnt = OFile->DirEnt;
|
DirEnt = OFile->DirEnt;
|
||||||
//
|
//
|
||||||
// If this is the root directory, we can't make any updates
|
// If this is the root directory, we can't make any updates
|
||||||
//
|
//
|
||||||
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)) {
|
||||||
@ -490,11 +495,11 @@ FatSetOrGetInfo (
|
|||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
|
|
||||||
IFile = IFILE_FROM_FHAND (FHand);
|
IFile = IFILE_FROM_FHAND (FHand);
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
|
|
||||||
Status = OFile->Error;
|
Status = OFile->Error;
|
||||||
if (Status == EFI_NOT_FOUND) {
|
if (Status == EFI_NOT_FOUND) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
@ -560,10 +565,10 @@ FatSetOrGetInfo (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatGetInfo (
|
FatGetInfo (
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
IN EFI_GUID *Type,
|
IN EFI_GUID *Type,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return FatSetOrGetInfo (FALSE, FHand, Type, BufferSize, Buffer);
|
return FatSetOrGetInfo (FALSE, FHand, Type, BufferSize, Buffer);
|
||||||
|
@ -25,10 +25,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAllocateVolume (
|
FatAllocateVolume (
|
||||||
IN EFI_HANDLE Handle,
|
IN EFI_HANDLE Handle,
|
||||||
IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
IN EFI_DISK_IO_PROTOCOL *DiskIo,
|
||||||
IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
|
IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
|
||||||
IN EFI_BLOCK_IO_PROTOCOL *BlockIo
|
IN EFI_BLOCK_IO_PROTOCOL *BlockIo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -45,15 +45,15 @@ FatAllocateVolume (
|
|||||||
//
|
//
|
||||||
// Initialize the structure
|
// Initialize the structure
|
||||||
//
|
//
|
||||||
Volume->Signature = FAT_VOLUME_SIGNATURE;
|
Volume->Signature = FAT_VOLUME_SIGNATURE;
|
||||||
Volume->Handle = Handle;
|
Volume->Handle = Handle;
|
||||||
Volume->DiskIo = DiskIo;
|
Volume->DiskIo = DiskIo;
|
||||||
Volume->DiskIo2 = DiskIo2;
|
Volume->DiskIo2 = DiskIo2;
|
||||||
Volume->BlockIo = BlockIo;
|
Volume->BlockIo = BlockIo;
|
||||||
Volume->MediaId = BlockIo->Media->MediaId;
|
Volume->MediaId = BlockIo->Media->MediaId;
|
||||||
Volume->ReadOnly = BlockIo->Media->ReadOnly;
|
Volume->ReadOnly = BlockIo->Media->ReadOnly;
|
||||||
Volume->VolumeInterface.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
|
Volume->VolumeInterface.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
|
||||||
Volume->VolumeInterface.OpenVolume = FatOpenVolume;
|
Volume->VolumeInterface.OpenVolume = FatOpenVolume;
|
||||||
InitializeListHead (&Volume->CheckRef);
|
InitializeListHead (&Volume->CheckRef);
|
||||||
InitializeListHead (&Volume->DirCacheList);
|
InitializeListHead (&Volume->DirCacheList);
|
||||||
//
|
//
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -113,7 +116,7 @@ Done:
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAbandonVolume (
|
FatAbandonVolume (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -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
|
||||||
@ -190,7 +194,7 @@ FatAbandonVolume (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatOpenDevice (
|
FatOpenDevice (
|
||||||
IN OUT FAT_VOLUME *Volume
|
IN OUT FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -213,8 +217,8 @@ FatOpenDevice (
|
|||||||
// This is the only part of FAT code that uses parent DiskIo,
|
// This is the only part of FAT code that uses parent DiskIo,
|
||||||
// Others use FatDiskIo which utilizes a Cache.
|
// Others use FatDiskIo which utilizes a Cache.
|
||||||
//
|
//
|
||||||
DiskIo = Volume->DiskIo;
|
DiskIo = Volume->DiskIo;
|
||||||
Status = DiskIo->ReadDisk (DiskIo, Volume->MediaId, 0, sizeof (FatBs), &FatBs);
|
Status = DiskIo->ReadDisk (DiskIo, Volume->MediaId, 0, sizeof (FatBs), &FatBs);
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
DEBUG ((DEBUG_INIT, "FatOpenDevice: read of part_lba failed %r\n", Status));
|
DEBUG ((DEBUG_INIT, "FatOpenDevice: read of part_lba failed %r\n", Status));
|
||||||
@ -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,35 +294,36 @@ 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
|
||||||
//
|
//
|
||||||
Volume->RootCluster = FatBs.FatBse.Fat32Bse.RootDirFirstCluster;
|
Volume->RootCluster = FatBs.FatBse.Fat32Bse.RootDirFirstCluster;
|
||||||
}
|
}
|
||||||
|
|
||||||
Volume->NumFats = FatBs.FatBsb.NumFats;
|
Volume->NumFats = FatBs.FatBsb.NumFats;
|
||||||
//
|
//
|
||||||
// Compute some fat locations
|
// Compute some fat locations
|
||||||
//
|
//
|
||||||
BlockSize = FatBs.FatBsb.SectorSize;
|
BlockSize = FatBs.FatBsb.SectorSize;
|
||||||
RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (BlockSize - 1)) / BlockSize;
|
RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (BlockSize - 1)) / BlockSize;
|
||||||
|
|
||||||
FatLba = FatBs.FatBsb.ReservedSectors;
|
FatLba = FatBs.FatBsb.ReservedSectors;
|
||||||
RootLba = FatBs.FatBsb.NumFats * SectorsPerFat + FatLba;
|
RootLba = FatBs.FatBsb.NumFats * SectorsPerFat + FatLba;
|
||||||
FirstClusterLba = RootLba + RootDirSectors;
|
FirstClusterLba = RootLba + RootDirSectors;
|
||||||
|
|
||||||
Volume->FatPos = FatLba * BlockSize;
|
Volume->FatPos = FatLba * BlockSize;
|
||||||
Volume->FatSize = SectorsPerFat * BlockSize;
|
Volume->FatSize = SectorsPerFat * BlockSize;
|
||||||
|
|
||||||
Volume->VolumeSize = LShiftU64 (Sectors, BlockAlignment);
|
Volume->VolumeSize = LShiftU64 (Sectors, BlockAlignment);
|
||||||
Volume->RootPos = LShiftU64 (RootLba, BlockAlignment);
|
Volume->RootPos = LShiftU64 (RootLba, BlockAlignment);
|
||||||
Volume->FirstClusterPos = LShiftU64 (FirstClusterLba, BlockAlignment);
|
Volume->FirstClusterPos = LShiftU64 (FirstClusterLba, BlockAlignment);
|
||||||
Volume->MaxCluster = (Sectors - FirstClusterLba) >> SectorsPerClusterAlignment;
|
Volume->MaxCluster = (Sectors - FirstClusterLba) >> SectorsPerClusterAlignment;
|
||||||
Volume->ClusterAlignment = (UINT8)(BlockAlignment + SectorsPerClusterAlignment);
|
Volume->ClusterAlignment = (UINT8)(BlockAlignment + SectorsPerClusterAlignment);
|
||||||
Volume->ClusterSize = (UINTN)1 << (Volume->ClusterAlignment);
|
Volume->ClusterSize = (UINTN)1 << (Volume->ClusterAlignment);
|
||||||
|
|
||||||
//
|
//
|
||||||
// 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
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
|
@ -22,11 +22,11 @@ UINT8 mMonthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|||||||
**/
|
**/
|
||||||
FAT_TASK *
|
FAT_TASK *
|
||||||
FatCreateTask (
|
FatCreateTask (
|
||||||
FAT_IFILE *IFile,
|
FAT_IFILE *IFile,
|
||||||
EFI_FILE_IO_TOKEN *Token
|
EFI_FILE_IO_TOKEN *Token
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_TASK *Task;
|
FAT_TASK *Task;
|
||||||
|
|
||||||
Task = AllocateZeroPool (sizeof (*Task));
|
Task = AllocateZeroPool (sizeof (*Task));
|
||||||
if (Task != NULL) {
|
if (Task != NULL) {
|
||||||
@ -36,6 +36,7 @@ FatCreateTask (
|
|||||||
InitializeListHead (&Task->Subtasks);
|
InitializeListHead (&Task->Subtasks);
|
||||||
InitializeListHead (&Task->Link);
|
InitializeListHead (&Task->Link);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task;
|
return Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,17 +49,18 @@ FatCreateTask (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatDestroyTask (
|
FatDestroyTask (
|
||||||
FAT_TASK *Task
|
FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LIST_ENTRY *Link;
|
LIST_ENTRY *Link;
|
||||||
FAT_SUBTASK *Subtask;
|
FAT_SUBTASK *Subtask;
|
||||||
|
|
||||||
Link = GetFirstNode (&Task->Subtasks);
|
Link = GetFirstNode (&Task->Subtasks);
|
||||||
while (!IsNull (&Task->Subtasks, Link)) {
|
while (!IsNull (&Task->Subtasks, Link)) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,10 +73,10 @@ FatDestroyTask (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatWaitNonblockingTask (
|
FatWaitNonblockingTask (
|
||||||
FAT_IFILE *IFile
|
FAT_IFILE *IFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN TaskQueueEmpty;
|
BOOLEAN TaskQueueEmpty;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
EfiAcquireLock (&FatTaskLock);
|
EfiAcquireLock (&FatTaskLock);
|
||||||
@ -94,10 +96,10 @@ FatWaitNonblockingTask (
|
|||||||
**/
|
**/
|
||||||
LIST_ENTRY *
|
LIST_ENTRY *
|
||||||
FatDestroySubtask (
|
FatDestroySubtask (
|
||||||
FAT_SUBTASK *Subtask
|
FAT_SUBTASK *Subtask
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LIST_ENTRY *Link;
|
LIST_ENTRY *Link;
|
||||||
|
|
||||||
gBS->CloseEvent (Subtask->DiskIo2Token.Event);
|
gBS->CloseEvent (Subtask->DiskIo2Token.Event);
|
||||||
|
|
||||||
@ -120,14 +122,14 @@ FatDestroySubtask (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatQueueTask (
|
FatQueueTask (
|
||||||
IN FAT_IFILE *IFile,
|
IN FAT_IFILE *IFile,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
LIST_ENTRY *Link;
|
LIST_ENTRY *Link;
|
||||||
LIST_ENTRY *NextLink;
|
LIST_ENTRY *NextLink;
|
||||||
FAT_SUBTASK *Subtask;
|
FAT_SUBTASK *Subtask;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sometimes the Task doesn't contain any subtasks, signal the event directly.
|
// Sometimes the Task doesn't contain any subtasks, signal the event directly.
|
||||||
@ -153,12 +155,12 @@ FatQueueTask (
|
|||||||
// handle list elements being removed during the traverse.
|
// handle list elements being removed during the traverse.
|
||||||
//
|
//
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -191,7 +194,7 @@ FatQueueTask (
|
|||||||
//
|
//
|
||||||
while (!IsNull (&Task->Subtasks, Link)) {
|
while (!IsNull (&Task->Subtasks, Link)) {
|
||||||
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
|
Subtask = CR (Link, FAT_SUBTASK, Link, FAT_SUBTASK_SIGNATURE);
|
||||||
Link = FatDestroySubtask (Subtask);
|
Link = FatDestroySubtask (Subtask);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsListEmpty (&Task->Subtasks)) {
|
if (IsListEmpty (&Task->Subtasks)) {
|
||||||
@ -225,12 +228,12 @@ FatQueueTask (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAccessVolumeDirty (
|
FatAccessVolumeDirty (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN VOID *DirtyValue
|
IN VOID *DirtyValue
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN WriteCount;
|
UINTN WriteCount;
|
||||||
|
|
||||||
WriteCount = Volume->FatEntrySize;
|
WriteCount = Volume->FatEntrySize;
|
||||||
return FatDiskIo (Volume, IoMode, Volume->FatPos + WriteCount, WriteCount, DirtyValue, NULL);
|
return FatDiskIo (Volume, IoMode, Volume->FatPos + WriteCount, WriteCount, DirtyValue, NULL);
|
||||||
@ -247,20 +250,20 @@ FatAccessVolumeDirty (
|
|||||||
VOID
|
VOID
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatOnAccessComplete (
|
FatOnAccessComplete (
|
||||||
IN EFI_EVENT Event,
|
IN EFI_EVENT Event,
|
||||||
IN VOID *Context
|
IN VOID *Context
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_SUBTASK *Subtask;
|
FAT_SUBTASK *Subtask;
|
||||||
FAT_TASK *Task;
|
FAT_TASK *Task;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Avoid someone in future breaks the below assumption.
|
// Avoid someone in future breaks the below assumption.
|
||||||
//
|
//
|
||||||
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;
|
||||||
|
|
||||||
@ -310,12 +313,12 @@ FatOnAccessComplete (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatDiskIo (
|
FatDiskIo (
|
||||||
IN FAT_VOLUME *Volume,
|
IN FAT_VOLUME *Volume,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN UINT64 Offset,
|
IN UINT64 Offset,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
IN OUT VOID *Buffer,
|
IN OUT VOID *Buffer,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -341,30 +344,30 @@ FatDiskIo (
|
|||||||
//
|
//
|
||||||
// Blocking access
|
// Blocking access
|
||||||
//
|
//
|
||||||
DiskIo = Volume->DiskIo;
|
DiskIo = Volume->DiskIo;
|
||||||
IoFunction = (IoMode == ReadDisk) ? DiskIo->ReadDisk : DiskIo->WriteDisk;
|
IoFunction = (IoMode == ReadDisk) ? DiskIo->ReadDisk : DiskIo->WriteDisk;
|
||||||
Status = IoFunction (DiskIo, Volume->MediaId, Offset, BufferSize, Buffer);
|
Status = IoFunction (DiskIo, Volume->MediaId, Offset, BufferSize, Buffer);
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Non-blocking access
|
// Non-blocking access
|
||||||
//
|
//
|
||||||
Subtask = AllocateZeroPool (sizeof (*Subtask));
|
Subtask = AllocateZeroPool (sizeof (*Subtask));
|
||||||
if (Subtask == NULL) {
|
if (Subtask == NULL) {
|
||||||
Status = EFI_OUT_OF_RESOURCES;
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
} 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;
|
||||||
Status = gBS->CreateEvent (
|
Status = gBS->CreateEvent (
|
||||||
EVT_NOTIFY_SIGNAL,
|
EVT_NOTIFY_SIGNAL,
|
||||||
TPL_NOTIFY,
|
TPL_NOTIFY,
|
||||||
FatOnAccessComplete,
|
FatOnAccessComplete,
|
||||||
Subtask,
|
Subtask,
|
||||||
&Subtask->DiskIo2Token.Event
|
&Subtask->DiskIo2Token.Event
|
||||||
);
|
);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
InsertTailList (&Task->Subtasks, &Subtask->Link);
|
InsertTailList (&Task->Subtasks, &Subtask->Link);
|
||||||
} else {
|
} else {
|
||||||
@ -436,7 +439,7 @@ FatReleaseLock (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatFreeDirEnt (
|
FatFreeDirEnt (
|
||||||
IN FAT_DIRENT *DirEnt
|
IN FAT_DIRENT *DirEnt
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (DirEnt->FileString != NULL) {
|
if (DirEnt->FileString != NULL) {
|
||||||
@ -455,7 +458,7 @@ FatFreeDirEnt (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatFreeVolume (
|
FatFreeVolume (
|
||||||
IN FAT_VOLUME *Volume
|
IN FAT_VOLUME *Volume
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -481,26 +485,26 @@ FatFreeVolume (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatEfiTimeToFatTime (
|
FatEfiTimeToFatTime (
|
||||||
IN EFI_TIME *ETime,
|
IN EFI_TIME *ETime,
|
||||||
OUT FAT_DATE_TIME *FTime
|
OUT FAT_DATE_TIME *FTime
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// 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) {
|
||||||
FTime->Date.Year = FAT_MAX_YEAR_FROM_1980;
|
FTime->Date.Year = FAT_MAX_YEAR_FROM_1980;
|
||||||
}
|
}
|
||||||
|
|
||||||
FTime->Date.Month = ETime->Month;
|
FTime->Date.Month = ETime->Month;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -513,16 +517,16 @@ FatEfiTimeToFatTime (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatFatTimeToEfiTime (
|
FatFatTimeToEfiTime (
|
||||||
IN FAT_DATE_TIME *FTime,
|
IN FAT_DATE_TIME *FTime,
|
||||||
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;
|
||||||
@ -537,20 +541,20 @@ FatFatTimeToEfiTime (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatGetCurrentFatTime (
|
FatGetCurrentFatTime (
|
||||||
OUT FAT_DATE_TIME *FatNow
|
OUT FAT_DATE_TIME *FatNow
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_TIME Now;
|
EFI_TIME Now;
|
||||||
|
|
||||||
Status = gRT->GetTime (&Now, NULL);
|
Status = gRT->GetTime (&Now, NULL);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
FatEfiTimeToFatTime (&Now, FatNow);
|
FatEfiTimeToFatTime (&Now, FatNow);
|
||||||
} else {
|
} else {
|
||||||
ZeroMem (&Now, sizeof (EFI_TIME));
|
ZeroMem (&Now, sizeof (EFI_TIME));
|
||||||
Now.Year = 1980;
|
Now.Year = 1980;
|
||||||
Now.Month = 1;
|
Now.Month = 1;
|
||||||
Now.Day = 1;
|
Now.Day = 1;
|
||||||
FatEfiTimeToFatTime (&Now, FatNow);
|
FatEfiTimeToFatTime (&Now, FatNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -567,11 +571,11 @@ FatGetCurrentFatTime (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatIsValidTime (
|
FatIsValidTime (
|
||||||
IN EFI_TIME *Time
|
IN EFI_TIME *Time
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINTN Day;
|
UINTN Day;
|
||||||
BOOLEAN ValidTime;
|
BOOLEAN ValidTime;
|
||||||
|
|
||||||
ValidTime = TRUE;
|
ValidTime = TRUE;
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAllocateIFile (
|
FatAllocateIFile (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
OUT FAT_IFILE **PtrIFile
|
OUT FAT_IFILE **PtrIFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_IFILE *IFile;
|
FAT_IFILE *IFile;
|
||||||
|
|
||||||
ASSERT_VOLUME_LOCKED (OFile->Volume);
|
ASSERT_VOLUME_LOCKED (OFile->Volume);
|
||||||
|
|
||||||
@ -83,11 +83,11 @@ FatAllocateIFile (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatOFileOpen (
|
FatOFileOpen (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
OUT FAT_IFILE **NewIFile,
|
OUT FAT_IFILE **NewIFile,
|
||||||
IN CHAR16 *FileName,
|
IN CHAR16 *FileName,
|
||||||
IN UINT64 OpenMode,
|
IN UINT64 OpenMode,
|
||||||
IN UINT8 Attributes
|
IN UINT8 Attributes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
@ -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);
|
||||||
@ -194,12 +198,12 @@ FatOFileOpen (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatOpenEx (
|
FatOpenEx (
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
OUT EFI_FILE_PROTOCOL **NewHandle,
|
OUT EFI_FILE_PROTOCOL **NewHandle,
|
||||||
IN CHAR16 *FileName,
|
IN CHAR16 *FileName,
|
||||||
IN UINT64 OpenMode,
|
IN UINT64 OpenMode,
|
||||||
IN UINT64 Attributes,
|
IN UINT64 Attributes,
|
||||||
IN OUT EFI_FILE_IO_TOKEN *Token
|
IN OUT EFI_FILE_IO_TOKEN *Token
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_IFILE *IFile;
|
FAT_IFILE *IFile;
|
||||||
@ -214,23 +218,24 @@ 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
|
||||||
//
|
//
|
||||||
switch (OpenMode) {
|
switch (OpenMode) {
|
||||||
case EFI_FILE_MODE_READ:
|
case EFI_FILE_MODE_READ:
|
||||||
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
|
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
|
||||||
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE:
|
case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return EFI_INVALID_PARAMETER;
|
return EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// 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
|
||||||
//
|
//
|
||||||
@ -309,11 +316,11 @@ FatOpenEx (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatOpen (
|
FatOpen (
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
OUT EFI_FILE_PROTOCOL **NewHandle,
|
OUT EFI_FILE_PROTOCOL **NewHandle,
|
||||||
IN CHAR16 *FileName,
|
IN CHAR16 *FileName,
|
||||||
IN UINT64 OpenMode,
|
IN UINT64 OpenMode,
|
||||||
IN UINT64 Attributes
|
IN UINT64 Attributes
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return FatOpenEx (FHand, NewHandle, FileName, OpenMode, Attributes, NULL);
|
return FatOpenEx (FHand, NewHandle, FileName, OpenMode, Attributes, NULL);
|
||||||
|
@ -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
|
||||||
//
|
//
|
||||||
|
@ -25,12 +25,12 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatGetPosition (
|
FatGetPosition (
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
OUT UINT64 *Position
|
OUT UINT64 *Position
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_IFILE *IFile;
|
FAT_IFILE *IFile;
|
||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
|
|
||||||
IFile = IFILE_FROM_FHAND (FHand);
|
IFile = IFILE_FROM_FHAND (FHand);
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
@ -66,8 +66,8 @@ FatSetPosition (
|
|||||||
IN UINT64 Position
|
IN UINT64 Position
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_IFILE *IFile;
|
FAT_IFILE *IFile;
|
||||||
FAT_OFILE *OFile;
|
FAT_OFILE *OFile;
|
||||||
|
|
||||||
IFile = IFILE_FROM_FHAND (FHand);
|
IFile = IFILE_FROM_FHAND (FHand);
|
||||||
OFile = IFile->OFile;
|
OFile = IFile->OFile;
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -118,9 +120,9 @@ FatSetPosition (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatIFileReadDir (
|
FatIFileReadDir (
|
||||||
IN FAT_IFILE *IFile,
|
IN FAT_IFILE *IFile,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -129,9 +131,9 @@ FatIFileReadDir (
|
|||||||
FAT_DIRENT *DirEnt;
|
FAT_DIRENT *DirEnt;
|
||||||
UINT32 CurrentPos;
|
UINT32 CurrentPos;
|
||||||
|
|
||||||
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:
|
||||||
@ -193,11 +197,11 @@ Done:
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatIFileAccess (
|
FatIFileAccess (
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
IN OUT VOID *Buffer,
|
IN OUT VOID *Buffer,
|
||||||
IN EFI_FILE_IO_TOKEN *Token
|
IN EFI_FILE_IO_TOKEN *Token
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -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;
|
||||||
@ -269,7 +274,7 @@ FatIFileAccess (
|
|||||||
//
|
//
|
||||||
ASSERT (IoMode == ReadData);
|
ASSERT (IoMode == ReadData);
|
||||||
Status = FatIFileReadDir (IFile, BufferSize, Buffer);
|
Status = FatIFileReadDir (IFile, BufferSize, Buffer);
|
||||||
OFile = NULL;
|
OFile = NULL;
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// Access a file
|
// Access a file
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -355,7 +360,7 @@ EFIAPI
|
|||||||
FatRead (
|
FatRead (
|
||||||
IN EFI_FILE_PROTOCOL *FHand,
|
IN EFI_FILE_PROTOCOL *FHand,
|
||||||
IN OUT UINTN *BufferSize,
|
IN OUT UINTN *BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return FatIFileAccess (FHand, ReadData, BufferSize, Buffer, NULL);
|
return FatIFileAccess (FHand, ReadData, BufferSize, Buffer, NULL);
|
||||||
@ -453,12 +458,12 @@ FatWriteEx (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatAccessOFile (
|
FatAccessOFile (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN IO_MODE IoMode,
|
IN IO_MODE IoMode,
|
||||||
IN UINTN Position,
|
IN UINTN Position,
|
||||||
IN OUT UINTN *DataBufferSize,
|
IN OUT UINTN *DataBufferSize,
|
||||||
IN OUT UINT8 *UserBuffer,
|
IN OUT UINT8 *UserBuffer,
|
||||||
IN FAT_TASK *Task
|
IN FAT_TASK *Task
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FAT_VOLUME *Volume;
|
FAT_VOLUME *Volume;
|
||||||
@ -466,8 +471,8 @@ FatAccessOFile (
|
|||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN BufferSize;
|
UINTN BufferSize;
|
||||||
|
|
||||||
BufferSize = *DataBufferSize;
|
BufferSize = *DataBufferSize;
|
||||||
Volume = OFile->Volume;
|
Volume = OFile->Volume;
|
||||||
ASSERT_VOLUME_LOCKED (Volume);
|
ASSERT_VOLUME_LOCKED (Volume);
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
@ -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
|
||||||
//
|
//
|
||||||
@ -498,14 +505,16 @@ FatAccessOFile (
|
|||||||
UserBuffer += Len;
|
UserBuffer += Len;
|
||||||
BufferSize -= Len;
|
BufferSize -= Len;
|
||||||
if (IoMode == WriteData) {
|
if (IoMode == WriteData) {
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -526,15 +535,15 @@ FatAccessOFile (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatExpandOFile (
|
FatExpandOFile (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN UINT64 ExpandedSize
|
IN UINT64 ExpandedSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
UINTN WritePos;
|
UINTN WritePos;
|
||||||
|
|
||||||
WritePos = OFile->FileSize;
|
WritePos = OFile->FileSize;
|
||||||
Status = FatGrowEof (OFile, ExpandedSize);
|
Status = FatGrowEof (OFile, ExpandedSize);
|
||||||
if (!EFI_ERROR (Status)) {
|
if (!EFI_ERROR (Status)) {
|
||||||
Status = FatWriteZeroPool (OFile, WritePos);
|
Status = FatWriteZeroPool (OFile, WritePos);
|
||||||
}
|
}
|
||||||
@ -566,8 +575,8 @@ FatWriteZeroPool (
|
|||||||
UINTN BufferSize;
|
UINTN BufferSize;
|
||||||
UINTN WriteSize;
|
UINTN WriteSize;
|
||||||
|
|
||||||
AppendedSize = OFile->FileSize - WritePos;
|
AppendedSize = OFile->FileSize - WritePos;
|
||||||
BufferSize = AppendedSize;
|
BufferSize = AppendedSize;
|
||||||
if (AppendedSize > FAT_MAX_ALLOCATE_SIZE) {
|
if (AppendedSize > FAT_MAX_ALLOCATE_SIZE) {
|
||||||
//
|
//
|
||||||
// If the appended size is larger, maybe we can not allocate the whole
|
// If the appended size is larger, maybe we can not allocate the whole
|
||||||
@ -584,9 +593,9 @@ 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)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -611,8 +620,8 @@ FatWriteZeroPool (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatTruncateOFile (
|
FatTruncateOFile (
|
||||||
IN FAT_OFILE *OFile,
|
IN FAT_OFILE *OFile,
|
||||||
IN UINTN TruncatedSize
|
IN UINTN TruncatedSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
OFile->FileSize = TruncatedSize;
|
OFile->FileSize = TruncatedSize;
|
||||||
|
@ -28,10 +28,10 @@ EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL;
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
InitializeUnicodeCollationSupportWorker (
|
InitializeUnicodeCollationSupportWorker (
|
||||||
IN EFI_HANDLE AgentHandle,
|
IN EFI_HANDLE AgentHandle,
|
||||||
IN EFI_GUID *ProtocolGuid,
|
IN EFI_GUID *ProtocolGuid,
|
||||||
IN CONST CHAR16 *VariableName,
|
IN CONST CHAR16 *VariableName,
|
||||||
IN CONST CHAR8 *DefaultLanguage
|
IN CONST CHAR8 *DefaultLanguage
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS ReturnStatus;
|
EFI_STATUS ReturnStatus;
|
||||||
@ -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
|
||||||
@ -89,7 +89,7 @@ InitializeUnicodeCollationSupportWorker (
|
|||||||
if (BestLanguage != NULL) {
|
if (BestLanguage != NULL) {
|
||||||
FreePool (BestLanguage);
|
FreePool (BestLanguage);
|
||||||
mUnicodeCollationInterface = Uci;
|
mUnicodeCollationInterface = Uci;
|
||||||
ReturnStatus = EFI_SUCCESS;
|
ReturnStatus = EFI_SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,11 +118,10 @@ InitializeUnicodeCollationSupportWorker (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
InitializeUnicodeCollationSupport (
|
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.
|
||||||
|
|
||||||
@ -164,8 +162,8 @@ InitializeUnicodeCollationSupport (
|
|||||||
**/
|
**/
|
||||||
INTN
|
INTN
|
||||||
FatStriCmp (
|
FatStriCmp (
|
||||||
IN CHAR16 *S1,
|
IN CHAR16 *S1,
|
||||||
IN CHAR16 *S2
|
IN CHAR16 *S2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT (StrSize (S1) != 0);
|
ASSERT (StrSize (S1) != 0);
|
||||||
@ -179,7 +177,6 @@ FatStriCmp (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Uppercase a string.
|
Uppercase a string.
|
||||||
|
|
||||||
@ -189,7 +186,7 @@ FatStriCmp (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatStrUpr (
|
FatStrUpr (
|
||||||
IN OUT CHAR16 *String
|
IN OUT CHAR16 *String
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT (StrSize (String) != 0);
|
ASSERT (StrSize (String) != 0);
|
||||||
@ -198,7 +195,6 @@ FatStrUpr (
|
|||||||
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
|
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Lowercase a string
|
Lowercase a string
|
||||||
|
|
||||||
@ -208,7 +204,7 @@ FatStrUpr (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatStrLwr (
|
FatStrLwr (
|
||||||
IN OUT CHAR16 *String
|
IN OUT CHAR16 *String
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT (StrSize (String) != 0);
|
ASSERT (StrSize (String) != 0);
|
||||||
@ -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.
|
||||||
|
|
||||||
@ -230,20 +225,19 @@ FatStrLwr (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
FatFatToStr (
|
FatFatToStr (
|
||||||
IN UINTN FatSize,
|
IN UINTN FatSize,
|
||||||
IN CHAR8 *Fat,
|
IN CHAR8 *Fat,
|
||||||
OUT CHAR16 *String
|
OUT CHAR16 *String
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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.
|
||||||
|
|
||||||
@ -257,9 +251,9 @@ FatFatToStr (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatStrToFat (
|
FatStrToFat (
|
||||||
IN CHAR16 *String,
|
IN CHAR16 *String,
|
||||||
IN UINTN FatSize,
|
IN UINTN FatSize,
|
||||||
OUT CHAR8 *Fat
|
OUT CHAR8 *Fat
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ASSERT (Fat != NULL);
|
ASSERT (Fat != NULL);
|
||||||
|
@ -25,33 +25,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatFindEltoritoPartitions (
|
FatFindEltoritoPartitions (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
BOOLEAN Found;
|
BOOLEAN Found;
|
||||||
PEI_FAT_BLOCK_DEVICE *BlockDev;
|
PEI_FAT_BLOCK_DEVICE *BlockDev;
|
||||||
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
||||||
UINT32 VolDescriptorLba;
|
UINT32 VolDescriptorLba;
|
||||||
UINT32 Lba;
|
UINT32 Lba;
|
||||||
CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
|
CDROM_VOLUME_DESCRIPTOR *VolDescriptor;
|
||||||
ELTORITO_CATALOG *Catalog;
|
ELTORITO_CATALOG *Catalog;
|
||||||
UINTN Check;
|
UINTN Check;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
UINTN MaxIndex;
|
UINTN MaxIndex;
|
||||||
UINT16 *CheckBuffer;
|
UINT16 *CheckBuffer;
|
||||||
UINT32 SubBlockSize;
|
UINT32 SubBlockSize;
|
||||||
UINT32 SectorCount;
|
UINT32 SectorCount;
|
||||||
UINT32 VolSpaceSize;
|
UINT32 VolSpaceSize;
|
||||||
|
|
||||||
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
|
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Found = FALSE;
|
Found = FALSE;
|
||||||
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
||||||
VolSpaceSize = 0;
|
VolSpaceSize = 0;
|
||||||
|
|
||||||
//
|
//
|
||||||
// CD_ROM has the fixed block size as 2048 bytes
|
// CD_ROM has the fixed block size as 2048 bytes
|
||||||
@ -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) {
|
||||||
//
|
//
|
||||||
@ -84,32 +83,36 @@ FatFindEltoritoPartitions (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status = FatReadBlock (
|
Status = FatReadBlock (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
ParentBlockDevNo,
|
ParentBlockDevNo,
|
||||||
VolDescriptorLba,
|
VolDescriptorLba,
|
||||||
ParentBlockDev->BlockSize,
|
ParentBlockDev->BlockSize,
|
||||||
VolDescriptor
|
VolDescriptor
|
||||||
);
|
);
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -129,25 +134,26 @@ FatFindEltoritoPartitions (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status = FatReadBlock (
|
Status = FatReadBlock (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
ParentBlockDevNo,
|
ParentBlockDevNo,
|
||||||
Lba,
|
Lba,
|
||||||
ParentBlockDev->BlockSize,
|
ParentBlockDev->BlockSize,
|
||||||
Catalog
|
Catalog
|
||||||
);
|
);
|
||||||
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,60 +172,59 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubBlockSize = 512;
|
SubBlockSize = 512;
|
||||||
SectorCount = Catalog->Boot.SectorCount;
|
SectorCount = Catalog->Boot.SectorCount;
|
||||||
|
|
||||||
switch (Catalog->Boot.MediaType) {
|
switch (Catalog->Boot.MediaType) {
|
||||||
|
case ELTORITO_NO_EMULATION:
|
||||||
|
SubBlockSize = ParentBlockDev->BlockSize;
|
||||||
|
SectorCount = Catalog->Boot.SectorCount;
|
||||||
|
break;
|
||||||
|
|
||||||
case ELTORITO_NO_EMULATION:
|
case ELTORITO_HARD_DISK:
|
||||||
SubBlockSize = ParentBlockDev->BlockSize;
|
break;
|
||||||
SectorCount = Catalog->Boot.SectorCount;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ELTORITO_HARD_DISK:
|
case ELTORITO_12_DISKETTE:
|
||||||
break;
|
SectorCount = 0x50 * 0x02 * 0x0F;
|
||||||
|
break;
|
||||||
|
|
||||||
case ELTORITO_12_DISKETTE:
|
case ELTORITO_14_DISKETTE:
|
||||||
SectorCount = 0x50 * 0x02 * 0x0F;
|
SectorCount = 0x50 * 0x02 * 0x12;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ELTORITO_14_DISKETTE:
|
case ELTORITO_28_DISKETTE:
|
||||||
SectorCount = 0x50 * 0x02 * 0x12;
|
SectorCount = 0x50 * 0x02 * 0x24;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ELTORITO_28_DISKETTE:
|
default:
|
||||||
SectorCount = 0x50 * 0x02 * 0x24;
|
SectorCount = 0;
|
||||||
break;
|
SubBlockSize = ParentBlockDev->BlockSize;
|
||||||
|
break;
|
||||||
default:
|
|
||||||
SectorCount = 0;
|
|
||||||
SubBlockSize = ParentBlockDev->BlockSize;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
BlockDev->BlockSize = SubBlockSize;
|
||||||
|
BlockDev->LastBlock = SectorCount - 1;
|
||||||
BlockDev->BlockSize = SubBlockSize;
|
BlockDev->IoAlign = ParentBlockDev->IoAlign;
|
||||||
BlockDev->LastBlock = SectorCount - 1;
|
BlockDev->Logical = TRUE;
|
||||||
BlockDev->IoAlign = ParentBlockDev->IoAlign;
|
BlockDev->PartitionChecked = FALSE;
|
||||||
BlockDev->Logical = TRUE;
|
BlockDev->StartingPos = MultU64x32 (Catalog->Boot.Lba, ParentBlockDev->BlockSize);
|
||||||
BlockDev->PartitionChecked = FALSE;
|
BlockDev->ParentDevNo = ParentBlockDevNo;
|
||||||
BlockDev->StartingPos = MultU64x32 (Catalog->Boot.Lba, ParentBlockDev->BlockSize);
|
|
||||||
BlockDev->ParentDevNo = ParentBlockDevNo;
|
|
||||||
|
|
||||||
PrivateData->BlockDeviceCount++;
|
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
|
||||||
@ -49,25 +48,25 @@ FatGetBpbInfo (
|
|||||||
// Read in the BPB
|
// Read in the BPB
|
||||||
//
|
//
|
||||||
Status = FatReadDisk (
|
Status = FatReadDisk (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
Volume->BlockDeviceNo,
|
Volume->BlockDeviceNo,
|
||||||
0,
|
0,
|
||||||
sizeof (PEI_FAT_BOOT_SECTOR_EX),
|
sizeof (PEI_FAT_BOOT_SECTOR_EX),
|
||||||
&BpbEx
|
&BpbEx
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyMem (
|
CopyMem (
|
||||||
(UINT8 *) (&Bpb),
|
(UINT8 *)(&Bpb),
|
||||||
(UINT8 *) (&BpbEx),
|
(UINT8 *)(&BpbEx),
|
||||||
sizeof (PEI_FAT_BOOT_SECTOR)
|
sizeof (PEI_FAT_BOOT_SECTOR)
|
||||||
);
|
);
|
||||||
|
|
||||||
Volume->FatType = FatUnknown;
|
Volume->FatType = FatUnknown;
|
||||||
|
|
||||||
Sectors = Bpb.Sectors;
|
Sectors = Bpb.Sectors;
|
||||||
if (Sectors == 0) {
|
if (Sectors == 0) {
|
||||||
Sectors = Bpb.LargeSectors;
|
Sectors = Bpb.LargeSectors;
|
||||||
}
|
}
|
||||||
@ -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)
|
||||||
@ -141,22 +145,21 @@ FatGetBpbInfo (
|
|||||||
|
|
||||||
RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (Volume->SectorSize - 1)) / Volume->SectorSize;
|
RootDirSectors = ((Volume->RootEntries * sizeof (FAT_DIRECTORY_ENTRY)) + (Volume->SectorSize - 1)) / Volume->SectorSize;
|
||||||
|
|
||||||
FatLba = Bpb.ReservedSectors;
|
FatLba = Bpb.ReservedSectors;
|
||||||
RootLba = Bpb.NoFats * SectorsPerFat + FatLba;
|
RootLba = Bpb.NoFats * SectorsPerFat + FatLba;
|
||||||
FirstClusterLba = RootLba + RootDirSectors;
|
FirstClusterLba = RootLba + RootDirSectors;
|
||||||
|
|
||||||
Volume->VolumeSize = MultU64x32 (Sectors, Volume->SectorSize);
|
Volume->VolumeSize = MultU64x32 (Sectors, Volume->SectorSize);
|
||||||
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
|
||||||
|
|
||||||
@ -198,7 +200,7 @@ FatGetNextCluster (
|
|||||||
if (Volume->FatType == Fat32) {
|
if (Volume->FatType == Fat32) {
|
||||||
FatEntryPos = Volume->FatPos + MultU64x32 (4, Cluster);
|
FatEntryPos = Volume->FatPos + MultU64x32 (4, Cluster);
|
||||||
|
|
||||||
Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);
|
Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 4, NextCluster);
|
||||||
*NextCluster &= 0x0fffffff;
|
*NextCluster &= 0x0fffffff;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -207,11 +209,10 @@ 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);
|
||||||
|
|
||||||
Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
|
Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
|
// Pad high bits for our FAT_CLUSTER_... macro definitions to work
|
||||||
@ -219,17 +220,17 @@ 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);
|
||||||
|
|
||||||
Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
|
Status = FatReadDisk (PrivateData, Volume->BlockDeviceNo, FatEntryPos, 2, NextCluster);
|
||||||
|
|
||||||
if ((Cluster & 0x01) != 0) {
|
if ((Cluster & 0x01) != 0) {
|
||||||
*NextCluster = (*NextCluster) >> 4;
|
*NextCluster = (*NextCluster) >> 4;
|
||||||
} 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,31 +273,29 @@ 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,
|
||||||
File->Volume,
|
File->Volume,
|
||||||
File->CurrentCluster,
|
File->CurrentCluster,
|
||||||
&File->CurrentCluster
|
&File->CurrentCluster
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
@ -313,12 +310,12 @@ FatSetFilePos (
|
|||||||
// Calculate the amount of consecutive cluster occupied by the file.
|
// Calculate the amount of consecutive cluster occupied by the file.
|
||||||
// FatReadFile() will use it to read these blocks once.
|
// FatReadFile() will use it to read these blocks once.
|
||||||
//
|
//
|
||||||
File->StraightReadAmount = 0;
|
File->StraightReadAmount = 0;
|
||||||
Cluster = File->CurrentCluster;
|
Cluster = File->CurrentCluster;
|
||||||
while (!FAT_CLUSTER_FUNCTIONAL (Cluster)) {
|
while (!FAT_CLUSTER_FUNCTIONAL (Cluster)) {
|
||||||
File->StraightReadAmount += File->Volume->ClusterSize;
|
File->StraightReadAmount += File->Volume->ClusterSize;
|
||||||
PrevCluster = Cluster;
|
PrevCluster = Cluster;
|
||||||
Status = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);
|
Status = FatGetNextCluster (PrivateData, File->Volume, Cluster, &Cluster);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
@ -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.
|
||||||
|
|
||||||
@ -375,53 +370,52 @@ FatReadFile (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status = FatReadDisk (
|
Status = FatReadDisk (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
File->Volume->BlockDeviceNo,
|
File->Volume->BlockDeviceNo,
|
||||||
File->Volume->RootDirPos + File->CurrentPos,
|
File->Volume->RootDirPos + File->CurrentPos,
|
||||||
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
|
||||||
//
|
//
|
||||||
while (Size != 0) {
|
while (Size != 0) {
|
||||||
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
|
DivU64x32Remainder (File->CurrentPos, File->Volume->ClusterSize, &Offset);
|
||||||
PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);
|
PhysicalAddr = File->Volume->FirstClusterPos + MultU64x32 (File->Volume->ClusterSize, File->CurrentCluster - 2);
|
||||||
|
|
||||||
Amount = File->StraightReadAmount;
|
Amount = File->StraightReadAmount;
|
||||||
Amount = Size > Amount ? Amount : Size;
|
Amount = Size > Amount ? Amount : Size;
|
||||||
Status = FatReadDisk (
|
Status = FatReadDisk (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
File->Volume->BlockDeviceNo,
|
File->Volume->BlockDeviceNo,
|
||||||
PhysicalAddr + Offset,
|
PhysicalAddr + Offset,
|
||||||
Amount,
|
Amount,
|
||||||
BufferPtr
|
BufferPtr
|
||||||
);
|
);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
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).
|
||||||
@ -446,13 +440,13 @@ FatReadNextDirectoryEntry (
|
|||||||
OUT PEI_FAT_FILE *SubFile
|
OUT PEI_FAT_FILE *SubFile
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
FAT_DIRECTORY_ENTRY DirEntry;
|
FAT_DIRECTORY_ENTRY DirEntry;
|
||||||
CHAR16 *Pos;
|
CHAR16 *Pos;
|
||||||
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;
|
||||||
@ -509,10 +507,10 @@ FatReadNextDirectoryEntry (
|
|||||||
SubFile->CurrentCluster |= DirEntry.FileClusterHigh << 16;
|
SubFile->CurrentCluster |= DirEntry.FileClusterHigh << 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubFile->CurrentPos = 0;
|
SubFile->CurrentPos = 0;
|
||||||
SubFile->FileSize = DirEntry.FileSize;
|
SubFile->FileSize = DirEntry.FileSize;
|
||||||
SubFile->StartingCluster = SubFile->CurrentCluster;
|
SubFile->StartingCluster = SubFile->CurrentCluster;
|
||||||
SubFile->Volume = ParentDir->Volume;
|
SubFile->Volume = ParentDir->Volume;
|
||||||
|
|
||||||
//
|
//
|
||||||
// in Pei phase, time parameters do not need to be filled for minimum use.
|
// in Pei phase, time parameters do not need to be filled for minimum use.
|
||||||
|
@ -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.
|
||||||
|
|
||||||
@ -46,23 +45,23 @@ BlockIoNotifyEntry (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
UpdateBlocksAndVolumes (
|
UpdateBlocksAndVolumes (
|
||||||
IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN OUT PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN BOOLEAN BlockIo2
|
IN BOOLEAN BlockIo2
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
|
EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor;
|
||||||
UINTN BlockIoPpiInstance;
|
UINTN BlockIoPpiInstance;
|
||||||
EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
|
EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIoPpi;
|
||||||
EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
|
EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2Ppi;
|
||||||
UINTN NumberBlockDevices;
|
UINTN NumberBlockDevices;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
EFI_PEI_BLOCK_IO_MEDIA Media;
|
EFI_PEI_BLOCK_IO_MEDIA Media;
|
||||||
EFI_PEI_BLOCK_IO2_MEDIA Media2;
|
EFI_PEI_BLOCK_IO2_MEDIA Media2;
|
||||||
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;
|
||||||
//
|
//
|
||||||
@ -81,19 +80,20 @@ UpdateBlocksAndVolumes (
|
|||||||
for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_FAT_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
|
for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_FAT_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
|
||||||
if (BlockIo2) {
|
if (BlockIo2) {
|
||||||
Status = PeiServicesLocatePpi (
|
Status = PeiServicesLocatePpi (
|
||||||
&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,10 +130,11 @@ 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].InterfaceType = Media2.InterfaceType;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo2 = BlockIo2Ppi;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].InterfaceType = Media2.InterfaceType;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media2.LastBlock;
|
||||||
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = Media2.BlockSize;
|
||||||
} else {
|
} else {
|
||||||
Status = BlockIoPpi->GetBlockDeviceMediaInfo (
|
Status = BlockIoPpi->GetBlockDeviceMediaInfo (
|
||||||
PeiServices,
|
PeiServices,
|
||||||
@ -144,23 +145,25 @@ 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].DevType = Media.DeviceType;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockIo = BlockIoPpi;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].DevType = Media.DeviceType;
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32) Media.BlockSize;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].LastBlock = Media.LastBlock;
|
||||||
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].BlockSize = (UINT32)Media.BlockSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
|
PrivateData->BlockDevice[PrivateData->BlockDeviceCount].IoAlign = 0;
|
||||||
//
|
//
|
||||||
// Not used here
|
// Not used here
|
||||||
//
|
//
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -171,15 +174,15 @@ UpdateBlocksAndVolumes (
|
|||||||
//
|
//
|
||||||
PrivateData->VolumeCount = 0;
|
PrivateData->VolumeCount = 0;
|
||||||
for (Index = 0; Index < PrivateData->BlockDeviceCount; Index++) {
|
for (Index = 0; Index < PrivateData->BlockDeviceCount; Index++) {
|
||||||
Volume.BlockDeviceNo = Index;
|
Volume.BlockDeviceNo = Index;
|
||||||
Status = FatGetBpbInfo (PrivateData, &Volume);
|
Status = FatGetBpbInfo (PrivateData, &Volume);
|
||||||
if (Status == EFI_SUCCESS) {
|
if (Status == EFI_SUCCESS) {
|
||||||
//
|
//
|
||||||
// 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
|
||||||
@ -241,8 +243,8 @@ BlockIoNotifyEntry (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
FatPeimEntry (
|
FatPeimEntry (
|
||||||
IN EFI_PEI_FILE_HANDLE FileHandle,
|
IN EFI_PEI_FILE_HANDLE FileHandle,
|
||||||
IN CONST EFI_PEI_SERVICES **PeiServices
|
IN CONST EFI_PEI_SERVICES **PeiServices
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -255,38 +257,39 @@ FatPeimEntry (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Status = PeiServicesAllocatePages (
|
Status = PeiServicesAllocatePages (
|
||||||
EfiBootServicesCode,
|
EfiBootServicesCode,
|
||||||
(sizeof (PEI_FAT_PRIVATE_DATA) - 1) / PEI_FAT_MEMORY_PAGE_SIZE + 1,
|
(sizeof (PEI_FAT_PRIVATE_DATA) - 1) / PEI_FAT_MEMORY_PAGE_SIZE + 1,
|
||||||
&Address
|
&Address
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
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;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Installs Ppi
|
// Installs Ppi
|
||||||
//
|
//
|
||||||
PrivateData->DeviceRecoveryPpi.GetNumberRecoveryCapsules = GetNumberRecoveryCapsules;
|
PrivateData->DeviceRecoveryPpi.GetNumberRecoveryCapsules = GetNumberRecoveryCapsules;
|
||||||
PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo = GetRecoveryCapsuleInfo;
|
PrivateData->DeviceRecoveryPpi.GetRecoveryCapsuleInfo = GetRecoveryCapsuleInfo;
|
||||||
PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule = LoadRecoveryCapsule;
|
PrivateData->DeviceRecoveryPpi.LoadRecoveryCapsule = LoadRecoveryCapsule;
|
||||||
|
|
||||||
PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
|
PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
|
||||||
PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
|
PrivateData->PpiDescriptor.Guid = &gEfiPeiDeviceRecoveryModulePpiGuid;
|
||||||
PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
|
PrivateData->PpiDescriptor.Ppi = &PrivateData->DeviceRecoveryPpi;
|
||||||
|
|
||||||
Status = PeiServicesInstallPpi (&PrivateData->PpiDescriptor);
|
Status = PeiServicesInstallPpi (&PrivateData->PpiDescriptor);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_OUT_OF_RESOURCES;
|
return EFI_OUT_OF_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Other initializations
|
// Other initializations
|
||||||
//
|
//
|
||||||
@ -305,21 +308,20 @@ FatPeimEntry (
|
|||||||
//
|
//
|
||||||
PrivateData->NotifyDescriptor[0].Flags =
|
PrivateData->NotifyDescriptor[0].Flags =
|
||||||
(
|
(
|
||||||
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
|
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
|
||||||
);
|
);
|
||||||
PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
|
PrivateData->NotifyDescriptor[0].Guid = &gEfiPeiVirtualBlockIoPpiGuid;
|
||||||
PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
|
PrivateData->NotifyDescriptor[0].Notify = BlockIoNotifyEntry;
|
||||||
PrivateData->NotifyDescriptor[1].Flags =
|
PrivateData->NotifyDescriptor[1].Flags =
|
||||||
(
|
(
|
||||||
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
|
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
|
||||||
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
|
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
|
||||||
);
|
);
|
||||||
PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
|
PrivateData->NotifyDescriptor[1].Guid = &gEfiPeiVirtualBlockIo2PpiGuid;
|
||||||
PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
|
PrivateData->NotifyDescriptor[1].Notify = BlockIoNotifyEntry;
|
||||||
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.
|
||||||
|
|
||||||
@ -346,9 +348,9 @@ FatPeimEntry (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
GetNumberRecoveryCapsules (
|
GetNumberRecoveryCapsules (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
||||||
OUT UINTN *NumberRecoveryCapsules
|
OUT UINTN *NumberRecoveryCapsules
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -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.
|
||||||
|
|
||||||
@ -410,11 +411,11 @@ GetNumberRecoveryCapsules (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
GetRecoveryCapsuleInfo (
|
GetRecoveryCapsuleInfo (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
||||||
IN UINTN CapsuleInstance,
|
IN UINTN CapsuleInstance,
|
||||||
OUT UINTN *Size,
|
OUT UINTN *Size,
|
||||||
OUT EFI_GUID *CapsuleType
|
OUT EFI_GUID *CapsuleType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -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,45 +462,47 @@ 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
|
||||||
//
|
//
|
||||||
if (BlockDeviceNo < PrivateData->BlockDeviceCount) {
|
if (BlockDeviceNo < PrivateData->BlockDeviceCount) {
|
||||||
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo2 != NULL) {
|
if (PrivateData->BlockDevice[BlockDeviceNo].BlockIo2 != NULL) {
|
||||||
switch (PrivateData->BlockDevice[BlockDeviceNo].InterfaceType) {
|
switch (PrivateData->BlockDevice[BlockDeviceNo].InterfaceType) {
|
||||||
case MSG_ATAPI_DP:
|
case MSG_ATAPI_DP:
|
||||||
CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
|
CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_USB_DP:
|
case MSG_USB_DP:
|
||||||
CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
|
CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_NVME_NAMESPACE_DP:
|
case MSG_NVME_NAMESPACE_DP:
|
||||||
CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
|
CopyGuid (CapsuleType, &gRecoveryOnFatNvmeDiskGuid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
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:
|
||||||
CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
|
CopyGuid (CapsuleType, &gRecoveryOnFatFloppyDiskGuid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IdeCDROM:
|
case IdeCDROM:
|
||||||
case IdeLS120:
|
case IdeLS120:
|
||||||
CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
|
CopyGuid (CapsuleType, &gRecoveryOnFatIdeDiskGuid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UsbMassStorage:
|
case UsbMassStorage:
|
||||||
CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
|
CopyGuid (CapsuleType, &gRecoveryOnFatUsbDiskGuid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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.
|
||||||
|
|
||||||
@ -536,10 +538,10 @@ GetRecoveryCapsuleInfo (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LoadRecoveryCapsule (
|
LoadRecoveryCapsule (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
||||||
IN UINTN CapsuleInstance,
|
IN UINTN CapsuleInstance,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -566,19 +568,18 @@ 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,17 +631,18 @@ 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;
|
||||||
Parent.StartingCluster = Parent.CurrentCluster;
|
Parent.StartingCluster = Parent.CurrentCluster;
|
||||||
Parent.Volume = &PrivateData->Volume[VolumeIndex];
|
Parent.Volume = &PrivateData->Volume[VolumeIndex];
|
||||||
|
|
||||||
Status = FatSetFilePos (PrivateData, &Parent, 0);
|
Status = FatSetFilePos (PrivateData, &Parent, 0);
|
||||||
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
//
|
//
|
||||||
// API data structures
|
// API data structures
|
||||||
//
|
//
|
||||||
typedef VOID *PEI_FILE_HANDLE;
|
typedef VOID *PEI_FILE_HANDLE;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
Fat12,
|
Fat12,
|
||||||
|
@ -13,25 +13,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
//
|
//
|
||||||
// Definitions
|
// Definitions
|
||||||
//
|
//
|
||||||
#define FAT_ATTR_READ_ONLY 0x01
|
#define FAT_ATTR_READ_ONLY 0x01
|
||||||
#define FAT_ATTR_HIDDEN 0x02
|
#define FAT_ATTR_HIDDEN 0x02
|
||||||
#define FAT_ATTR_SYSTEM 0x04
|
#define FAT_ATTR_SYSTEM 0x04
|
||||||
#define FAT_ATTR_VOLUME_ID 0x08
|
#define FAT_ATTR_VOLUME_ID 0x08
|
||||||
#define FAT_ATTR_DIRECTORY 0x10
|
#define FAT_ATTR_DIRECTORY 0x10
|
||||||
#define FAT_ATTR_ARCHIVE 0x20
|
#define FAT_ATTR_ARCHIVE 0x20
|
||||||
#define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
|
#define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
|
||||||
|
|
||||||
#define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
|
#define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
|
||||||
#define FAT_CLUSTER_FREE 0
|
#define FAT_CLUSTER_FREE 0
|
||||||
#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
|
#define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
|
||||||
#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
|
#define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
|
||||||
#define FAT_CLUSTER_LAST (-1)
|
#define FAT_CLUSTER_LAST (-1)
|
||||||
|
|
||||||
#define DELETE_ENTRY_MARK 0xE5
|
#define DELETE_ENTRY_MARK 0xE5
|
||||||
#define EMPTY_ENTRY_MARK 0x00
|
#define EMPTY_ENTRY_MARK 0x00
|
||||||
|
|
||||||
#define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
|
#define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
|
||||||
#define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
|
#define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Directory Entry
|
// Directory Entry
|
||||||
@ -39,33 +39,33 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT16 Day : 5;
|
UINT16 Day : 5;
|
||||||
UINT16 Month : 4;
|
UINT16 Month : 4;
|
||||||
UINT16 Year : 7; // From 1980
|
UINT16 Year : 7; // From 1980
|
||||||
} FAT_DATE;
|
} FAT_DATE;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
UINT16 DoubleSecond : 5;
|
UINT16 DoubleSecond : 5;
|
||||||
UINT16 Minute : 6;
|
UINT16 Minute : 6;
|
||||||
UINT16 Hour : 5;
|
UINT16 Hour : 5;
|
||||||
} FAT_TIME;
|
} FAT_TIME;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FAT_TIME Time;
|
FAT_TIME Time;
|
||||||
FAT_DATE Date;
|
FAT_DATE Date;
|
||||||
} FAT_DATE_TIME;
|
} FAT_DATE_TIME;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
CHAR8 FileName[11]; // 8.3 filename
|
CHAR8 FileName[11]; // 8.3 filename
|
||||||
UINT8 Attributes;
|
UINT8 Attributes;
|
||||||
UINT8 CaseFlag;
|
UINT8 CaseFlag;
|
||||||
UINT8 CreateMillisecond; // (creation milliseconds - ignored)
|
UINT8 CreateMillisecond; // (creation milliseconds - ignored)
|
||||||
FAT_DATE_TIME FileCreateTime;
|
FAT_DATE_TIME FileCreateTime;
|
||||||
FAT_DATE FileLastAccess;
|
FAT_DATE FileLastAccess;
|
||||||
UINT16 FileClusterHigh; // >= FAT32
|
UINT16 FileClusterHigh; // >= FAT32
|
||||||
FAT_DATE_TIME FileModificationTime;
|
FAT_DATE_TIME FileModificationTime;
|
||||||
UINT16 FileCluster;
|
UINT16 FileCluster;
|
||||||
UINT32 FileSize;
|
UINT32 FileSize;
|
||||||
} FAT_DIRECTORY_ENTRY;
|
} FAT_DIRECTORY_ENTRY;
|
||||||
|
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
@ -75,62 +75,58 @@ typedef struct {
|
|||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
UINT8 Ia32Jump[3];
|
||||||
|
CHAR8 OemId[8];
|
||||||
|
|
||||||
UINT8 Ia32Jump[3];
|
UINT16 SectorSize;
|
||||||
CHAR8 OemId[8];
|
UINT8 SectorsPerCluster;
|
||||||
|
UINT16 ReservedSectors;
|
||||||
UINT16 SectorSize;
|
UINT8 NoFats;
|
||||||
UINT8 SectorsPerCluster;
|
UINT16 RootEntries; // < FAT32, root dir is fixed size
|
||||||
UINT16 ReservedSectors;
|
UINT16 Sectors;
|
||||||
UINT8 NoFats;
|
UINT8 Media; // (ignored)
|
||||||
UINT16 RootEntries; // < FAT32, root dir is fixed size
|
UINT16 SectorsPerFat; // < FAT32
|
||||||
UINT16 Sectors;
|
UINT16 SectorsPerTrack; // (ignored)
|
||||||
UINT8 Media; // (ignored)
|
UINT16 Heads; // (ignored)
|
||||||
UINT16 SectorsPerFat; // < FAT32
|
UINT32 HiddenSectors; // (ignored)
|
||||||
UINT16 SectorsPerTrack; // (ignored)
|
UINT32 LargeSectors; // => FAT32
|
||||||
UINT16 Heads; // (ignored)
|
UINT8 PhysicalDriveNumber; // (ignored)
|
||||||
UINT32 HiddenSectors; // (ignored)
|
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
||||||
UINT32 LargeSectors; // => FAT32
|
UINT8 Signature; // (ignored)
|
||||||
UINT8 PhysicalDriveNumber; // (ignored)
|
CHAR8 Id[4];
|
||||||
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
CHAR8 FatLabel[11];
|
||||||
UINT8 Signature; // (ignored)
|
CHAR8 SystemId[8];
|
||||||
CHAR8 Id[4];
|
|
||||||
CHAR8 FatLabel[11];
|
|
||||||
CHAR8 SystemId[8];
|
|
||||||
|
|
||||||
} PEI_FAT_BOOT_SECTOR;
|
} PEI_FAT_BOOT_SECTOR;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
UINT8 Ia32Jump[3];
|
||||||
|
CHAR8 OemId[8];
|
||||||
|
|
||||||
UINT8 Ia32Jump[3];
|
UINT16 SectorSize;
|
||||||
CHAR8 OemId[8];
|
UINT8 SectorsPerCluster;
|
||||||
|
UINT16 ReservedSectors;
|
||||||
UINT16 SectorSize;
|
UINT8 NoFats;
|
||||||
UINT8 SectorsPerCluster;
|
UINT16 RootEntries; // < FAT32, root dir is fixed size
|
||||||
UINT16 ReservedSectors;
|
UINT16 Sectors;
|
||||||
UINT8 NoFats;
|
UINT8 Media; // (ignored)
|
||||||
UINT16 RootEntries; // < FAT32, root dir is fixed size
|
UINT16 SectorsPerFat; // < FAT32
|
||||||
UINT16 Sectors;
|
UINT16 SectorsPerTrack; // (ignored)
|
||||||
UINT8 Media; // (ignored)
|
UINT16 Heads; // (ignored)
|
||||||
UINT16 SectorsPerFat; // < FAT32
|
UINT32 HiddenSectors; // (ignored)
|
||||||
UINT16 SectorsPerTrack; // (ignored)
|
UINT32 LargeSectors; // Used if Sectors==0
|
||||||
UINT16 Heads; // (ignored)
|
UINT32 LargeSectorsPerFat; // FAT32
|
||||||
UINT32 HiddenSectors; // (ignored)
|
UINT16 ExtendedFlags; // FAT32 (ignored)
|
||||||
UINT32 LargeSectors; // Used if Sectors==0
|
UINT16 FsVersion; // FAT32 (ignored)
|
||||||
UINT32 LargeSectorsPerFat; // FAT32
|
UINT32 RootDirFirstCluster; // FAT32
|
||||||
UINT16 ExtendedFlags; // FAT32 (ignored)
|
UINT16 FsInfoSector; // FAT32
|
||||||
UINT16 FsVersion; // FAT32 (ignored)
|
UINT16 BackupBootSector; // FAT32
|
||||||
UINT32 RootDirFirstCluster; // FAT32
|
UINT8 Reserved[12]; // FAT32 (ignored)
|
||||||
UINT16 FsInfoSector; // FAT32
|
UINT8 PhysicalDriveNumber; // (ignored)
|
||||||
UINT16 BackupBootSector; // FAT32
|
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
||||||
UINT8 Reserved[12]; // FAT32 (ignored)
|
UINT8 Signature; // (ignored)
|
||||||
UINT8 PhysicalDriveNumber; // (ignored)
|
CHAR8 Id[4];
|
||||||
UINT8 CurrentHead; // holds boot_sector_dirty bit
|
CHAR8 FatLabel[11];
|
||||||
UINT8 Signature; // (ignored)
|
CHAR8 SystemId[8];
|
||||||
CHAR8 Id[4];
|
|
||||||
CHAR8 FatLabel[11];
|
|
||||||
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.
|
||||||
@ -26,17 +24,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
CHAR16
|
CHAR16
|
||||||
ToUpper (
|
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.
|
||||||
@ -55,11 +52,11 @@ ToUpper (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatReadBlock (
|
FatReadBlock (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN BlockDeviceNo,
|
IN UINTN BlockDeviceNo,
|
||||||
IN EFI_PEI_LBA Lba,
|
IN EFI_PEI_LBA Lba,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
OUT VOID *Buffer
|
OUT VOID *Buffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -69,8 +66,8 @@ FatReadBlock (
|
|||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = EFI_SUCCESS;
|
Status = EFI_SUCCESS;
|
||||||
BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);
|
BlockDev = &(PrivateData->BlockDevice[BlockDeviceNo]);
|
||||||
|
|
||||||
if (BufferSize > MultU64x32 (BlockDev->LastBlock - Lba + 1, BlockDev->BlockSize)) {
|
if (BufferSize > MultU64x32 (BlockDev->LastBlock - Lba + 1, BlockDev->BlockSize)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
@ -83,38 +80,36 @@ 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,
|
||||||
|
Lba,
|
||||||
|
BufferSize,
|
||||||
|
Buffer
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
Status = BlockDev->BlockIo->ReadBlocks (
|
||||||
|
(EFI_PEI_SERVICES **)GetPeiServicesTablePointer (),
|
||||||
|
BlockDev->BlockIo,
|
||||||
BlockDev->PhysicalDevNo,
|
BlockDev->PhysicalDevNo,
|
||||||
Lba,
|
Lba,
|
||||||
BufferSize,
|
BufferSize,
|
||||||
Buffer
|
Buffer
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
Status = BlockDev->BlockIo->ReadBlocks (
|
|
||||||
(EFI_PEI_SERVICES **) GetPeiServicesTablePointer (),
|
|
||||||
BlockDev->BlockIo,
|
|
||||||
BlockDev->PhysicalDevNo,
|
|
||||||
Lba,
|
|
||||||
BufferSize,
|
|
||||||
Buffer
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Status = FatReadDisk (
|
Status = FatReadDisk (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
BlockDev->ParentDevNo,
|
BlockDev->ParentDevNo,
|
||||||
BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),
|
BlockDev->StartingPos + MultU64x32 (Lba, BlockDev->BlockSize),
|
||||||
BufferSize,
|
BufferSize,
|
||||||
Buffer
|
Buffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
//
|
//
|
||||||
@ -181,33 +178,32 @@ FatGetCacheBlock (
|
|||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
|
CacheBuffer = &(PrivateData->CacheBuffer[Index]);
|
||||||
|
|
||||||
CacheBuffer->BlockDeviceNo = BlockDeviceNo;
|
CacheBuffer->BlockDeviceNo = BlockDeviceNo;
|
||||||
CacheBuffer->Lba = Lba;
|
CacheBuffer->Lba = Lba;
|
||||||
CacheBuffer->Size = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;
|
CacheBuffer->Size = PrivateData->BlockDevice[BlockDeviceNo].BlockSize;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read in the data
|
// Read in the data
|
||||||
//
|
//
|
||||||
Status = FatReadBlock (
|
Status = FatReadBlock (
|
||||||
PrivateData,
|
PrivateData,
|
||||||
BlockDeviceNo,
|
BlockDeviceNo,
|
||||||
Lba,
|
Lba,
|
||||||
CacheBuffer->Size,
|
CacheBuffer->Size,
|
||||||
CacheBuffer->Buffer
|
CacheBuffer->Buffer
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheBuffer->Valid = TRUE;
|
CacheBuffer->Valid = TRUE;
|
||||||
*CachePtr = (CHAR8 *) CacheBuffer->Buffer;
|
*CachePtr = (CHAR8 *)CacheBuffer->Buffer;
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Disk reading.
|
Disk reading.
|
||||||
|
|
||||||
@ -246,8 +242,8 @@ FatReadDisk (
|
|||||||
//
|
//
|
||||||
// Read underrun
|
// Read underrun
|
||||||
//
|
//
|
||||||
Lba = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);
|
Lba = DivU64x32Remainder (StartingAddress, BlockSize, &Offset);
|
||||||
Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);
|
Status = FatGetCacheBlock (PrivateData, BlockDeviceNo, Lba, &CachePtr);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
@ -259,17 +255,17 @@ FatReadDisk (
|
|||||||
return EFI_SUCCESS;
|
return EFI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size -= Amount;
|
Size -= Amount;
|
||||||
BufferPtr += Amount;
|
BufferPtr += Amount;
|
||||||
StartingAddress += Amount;
|
StartingAddress += Amount;
|
||||||
Lba += 1;
|
Lba += 1;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read aligned parts
|
// Read aligned parts
|
||||||
//
|
//
|
||||||
OverRunLba = Lba + DivU64x32Remainder (Size, BlockSize, &Offset);
|
OverRunLba = Lba + DivU64x32Remainder (Size, BlockSize, &Offset);
|
||||||
|
|
||||||
Size -= Offset;
|
Size -= Offset;
|
||||||
Status = FatReadBlock (PrivateData, BlockDeviceNo, Lba, Size, BufferPtr);
|
Status = FatReadBlock (PrivateData, BlockDeviceNo, Lba, Size, BufferPtr);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return EFI_DEVICE_ERROR;
|
return EFI_DEVICE_ERROR;
|
||||||
@ -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.
|
||||||
@ -310,9 +305,9 @@ FatReadDisk (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
EngFatToStr (
|
EngFatToStr (
|
||||||
IN UINTN FatSize,
|
IN UINTN FatSize,
|
||||||
IN CHAR8 *Fat,
|
IN CHAR8 *Fat,
|
||||||
OUT CHAR16 *Str
|
OUT CHAR16 *Str
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CHAR16 *String;
|
CHAR16 *String;
|
||||||
@ -325,16 +320,16 @@ EngFatToStr (
|
|||||||
if (*Fat == ' ') {
|
if (*Fat == ' ') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*String = *Fat;
|
|
||||||
String += 1;
|
*String = *Fat;
|
||||||
Fat += 1;
|
String += 1;
|
||||||
|
Fat += 1;
|
||||||
FatSize -= 1;
|
FatSize -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*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);
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
// Definitions
|
// Definitions
|
||||||
//
|
//
|
||||||
|
|
||||||
#define PEI_FAT_CACHE_SIZE 4
|
#define PEI_FAT_CACHE_SIZE 4
|
||||||
#define PEI_FAT_MAX_BLOCK_SIZE 8192
|
#define PEI_FAT_MAX_BLOCK_SIZE 8192
|
||||||
#define FAT_MAX_FILE_NAME_LENGTH 128
|
#define FAT_MAX_FILE_NAME_LENGTH 128
|
||||||
#define PEI_FAT_MAX_BLOCK_DEVICE 64
|
#define PEI_FAT_MAX_BLOCK_DEVICE 64
|
||||||
#define PEI_FAT_MAX_BLOCK_IO_PPI 32
|
#define PEI_FAT_MAX_BLOCK_IO_PPI 32
|
||||||
#define PEI_FAT_MAX_VOLUME 64
|
#define PEI_FAT_MAX_VOLUME 64
|
||||||
|
|
||||||
#define PEI_FAT_MEMORY_PAGE_SIZE 0x1000
|
#define PEI_FAT_MEMORY_PAGE_SIZE 0x1000
|
||||||
|
|
||||||
//
|
//
|
||||||
// Data Structures
|
// Data Structures
|
||||||
@ -49,86 +49,79 @@ 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;
|
BOOLEAN Logical;
|
||||||
BOOLEAN Logical;
|
BOOLEAN PartitionChecked;
|
||||||
BOOLEAN PartitionChecked;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Following fields only valid for logical device
|
// Following fields only valid for logical device
|
||||||
//
|
//
|
||||||
CHAR8 PartitionFlag[8];
|
CHAR8 PartitionFlag[8];
|
||||||
UINT64 StartingPos;
|
UINT64 StartingPos;
|
||||||
UINTN ParentDevNo;
|
UINTN ParentDevNo;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Following fields only valid for physical device
|
// Following fields only valid for physical device
|
||||||
//
|
//
|
||||||
EFI_PEI_BLOCK_DEVICE_TYPE DevType;
|
EFI_PEI_BLOCK_DEVICE_TYPE DevType;
|
||||||
UINT8 InterfaceType;
|
UINT8 InterfaceType;
|
||||||
//
|
//
|
||||||
// EFI_PEI_READ_BLOCKS ReadFunc;
|
// EFI_PEI_READ_BLOCKS ReadFunc;
|
||||||
//
|
//
|
||||||
EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
|
EFI_PEI_RECOVERY_BLOCK_IO_PPI *BlockIo;
|
||||||
EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
|
EFI_PEI_RECOVERY_BLOCK_IO2_PPI *BlockIo2;
|
||||||
UINT8 PhysicalDevNo;
|
UINT8 PhysicalDevNo;
|
||||||
} PEI_FAT_BLOCK_DEVICE;
|
} PEI_FAT_BLOCK_DEVICE;
|
||||||
|
|
||||||
//
|
//
|
||||||
// the Volume structure
|
// the Volume structure
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
UINTN BlockDeviceNo;
|
||||||
UINTN BlockDeviceNo;
|
UINTN VolumeNo;
|
||||||
UINTN VolumeNo;
|
UINT64 VolumeSize;
|
||||||
UINT64 VolumeSize;
|
UINTN MaxCluster;
|
||||||
UINTN MaxCluster;
|
CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
|
||||||
CHAR16 VolumeLabel[FAT_MAX_FILE_NAME_LENGTH];
|
PEI_FAT_TYPE FatType;
|
||||||
PEI_FAT_TYPE FatType;
|
UINT64 FatPos;
|
||||||
UINT64 FatPos;
|
UINT32 SectorSize;
|
||||||
UINT32 SectorSize;
|
UINT32 ClusterSize;
|
||||||
UINT32 ClusterSize;
|
UINT64 FirstClusterPos;
|
||||||
UINT64 FirstClusterPos;
|
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;
|
||||||
|
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
|
||||||
|
|
||||||
PEI_FAT_VOLUME *Volume;
|
BOOLEAN IsFixedRootDir;
|
||||||
CHAR16 FileName[FAT_MAX_FILE_NAME_LENGTH];
|
|
||||||
|
|
||||||
BOOLEAN IsFixedRootDir;
|
UINT32 StartingCluster;
|
||||||
|
UINT32 CurrentPos;
|
||||||
UINT32 StartingCluster;
|
UINT32 StraightReadAmount;
|
||||||
UINT32 CurrentPos;
|
UINT32 CurrentCluster;
|
||||||
UINT32 StraightReadAmount;
|
|
||||||
UINT32 CurrentCluster;
|
|
||||||
|
|
||||||
UINT8 Attributes;
|
|
||||||
UINT32 FileSize;
|
|
||||||
|
|
||||||
|
UINT8 Attributes;
|
||||||
|
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,25 +135,23 @@ 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;
|
||||||
|
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
|
||||||
|
EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
|
||||||
|
EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
|
||||||
|
|
||||||
UINTN Signature;
|
UINT8 UnicodeCaseMap[0x300];
|
||||||
EFI_PEI_DEVICE_RECOVERY_MODULE_PPI DeviceRecoveryPpi;
|
CHAR8 *EngUpperMap;
|
||||||
EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
|
CHAR8 *EngLowerMap;
|
||||||
EFI_PEI_NOTIFY_DESCRIPTOR NotifyDescriptor[2];
|
CHAR8 *EngInfoMap;
|
||||||
|
|
||||||
UINT8 UnicodeCaseMap[0x300];
|
|
||||||
CHAR8 *EngUpperMap;
|
|
||||||
CHAR8 *EngLowerMap;
|
|
||||||
CHAR8 *EngInfoMap;
|
|
||||||
|
|
||||||
UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
|
|
||||||
UINTN BlockDeviceCount;
|
|
||||||
PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
|
|
||||||
UINTN VolumeCount;
|
|
||||||
PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
|
|
||||||
PEI_FAT_FILE File;
|
|
||||||
PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
|
|
||||||
|
|
||||||
|
UINT64 BlockData[PEI_FAT_MAX_BLOCK_SIZE / 8];
|
||||||
|
UINTN BlockDeviceCount;
|
||||||
|
PEI_FAT_BLOCK_DEVICE BlockDevice[PEI_FAT_MAX_BLOCK_DEVICE];
|
||||||
|
UINTN VolumeCount;
|
||||||
|
PEI_FAT_VOLUME Volume[PEI_FAT_MAX_VOLUME];
|
||||||
|
PEI_FAT_FILE File;
|
||||||
|
PEI_FAT_CACHE_BUFFER CacheBuffer[PEI_FAT_CACHE_SIZE];
|
||||||
} PEI_FAT_PRIVATE_DATA;
|
} 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
|
||||||
@ -231,12 +220,11 @@ FindRecoveryFile (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
GetNumberRecoveryCapsules (
|
GetNumberRecoveryCapsules (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
||||||
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.
|
||||||
@ -267,14 +255,13 @@ GetNumberRecoveryCapsules (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
GetRecoveryCapsuleInfo (
|
GetRecoveryCapsuleInfo (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
||||||
IN UINTN CapsuleInstance,
|
IN UINTN CapsuleInstance,
|
||||||
OUT UINTN *Size,
|
OUT UINTN *Size,
|
||||||
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.
|
||||||
|
|
||||||
@ -297,13 +284,12 @@ GetRecoveryCapsuleInfo (
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
EFIAPI
|
EFIAPI
|
||||||
LoadRecoveryCapsule (
|
LoadRecoveryCapsule (
|
||||||
IN EFI_PEI_SERVICES **PeiServices,
|
IN EFI_PEI_SERVICES **PeiServices,
|
||||||
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
IN EFI_PEI_DEVICE_RECOVERY_MODULE_PPI *This,
|
||||||
IN UINTN CapsuleInstance,
|
IN UINTN CapsuleInstance,
|
||||||
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.
|
||||||
@ -321,12 +307,11 @@ LoadRecoveryCapsule (
|
|||||||
**/
|
**/
|
||||||
VOID
|
VOID
|
||||||
EngFatToStr (
|
EngFatToStr (
|
||||||
IN UINTN FatSize,
|
IN UINTN FatSize,
|
||||||
IN CHAR8 *Fat,
|
IN CHAR8 *Fat,
|
||||||
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.
|
||||||
@ -361,14 +345,13 @@ EngStriColl (
|
|||||||
**/
|
**/
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
FatReadBlock (
|
FatReadBlock (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN BlockDeviceNo,
|
IN UINTN BlockDeviceNo,
|
||||||
IN EFI_PEI_LBA Lba,
|
IN EFI_PEI_LBA Lba,
|
||||||
IN UINTN BufferSize,
|
IN UINTN BufferSize,
|
||||||
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.
|
||||||
|
|
||||||
|
@ -23,9 +23,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
// GPT Partition Entry Status
|
// GPT Partition Entry Status
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
BOOLEAN OutOfRange;
|
BOOLEAN OutOfRange;
|
||||||
BOOLEAN Overlap;
|
BOOLEAN Overlap;
|
||||||
BOOLEAN OsSpecific;
|
BOOLEAN OsSpecific;
|
||||||
} EFI_PARTITION_ENTRY_STATUS;
|
} EFI_PARTITION_ENTRY_STATUS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,8 +42,8 @@ PartitionCheckGptHeaderCRC (
|
|||||||
IN EFI_PARTITION_TABLE_HEADER *PartHeader
|
IN EFI_PARTITION_TABLE_HEADER *PartHeader
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 GptHdrCrc;
|
UINT32 GptHdrCrc;
|
||||||
UINT32 Crc;
|
UINT32 Crc;
|
||||||
|
|
||||||
GptHdrCrc = PartHeader->Header.CRC32;
|
GptHdrCrc = PartHeader->Header.CRC32;
|
||||||
|
|
||||||
@ -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.
|
||||||
@ -76,17 +75,17 @@ PartitionCheckGptHeaderCRC (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
PartitionCheckGptEntryArrayCRC (
|
PartitionCheckGptEntryArrayCRC (
|
||||||
IN EFI_PARTITION_TABLE_HEADER *PartHeader,
|
IN EFI_PARTITION_TABLE_HEADER *PartHeader,
|
||||||
IN EFI_PARTITION_ENTRY *PartEntry
|
IN EFI_PARTITION_ENTRY *PartEntry
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,14 +108,14 @@ PartitionCheckGptHeader (
|
|||||||
IN EFI_PARTITION_TABLE_HEADER *PartHdr
|
IN EFI_PARTITION_TABLE_HEADER *PartHdr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
||||||
EFI_PEI_LBA Lba;
|
EFI_PEI_LBA Lba;
|
||||||
EFI_PEI_LBA AlternateLba;
|
EFI_PEI_LBA AlternateLba;
|
||||||
EFI_PEI_LBA EntryArrayLastLba;
|
EFI_PEI_LBA EntryArrayLastLba;
|
||||||
|
|
||||||
UINT64 PartitionEntryArraySize;
|
UINT64 PartitionEntryArraySize;
|
||||||
UINT64 PartitionEntryBlockNumb;
|
UINT64 PartitionEntryBlockNumb;
|
||||||
UINT32 EntryArraySizeRemainder;
|
UINT32 EntryArraySizeRemainder;
|
||||||
|
|
||||||
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
@ -219,30 +220,30 @@ PartitionCheckGptEntryArray (
|
|||||||
IN EFI_PARTITION_TABLE_HEADER *PartHdr
|
IN EFI_PARTITION_TABLE_HEADER *PartHdr
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
||||||
PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
|
PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
|
||||||
|
|
||||||
UINT64 PartitionEntryArraySize;
|
UINT64 PartitionEntryArraySize;
|
||||||
UINT64 PartitionEntryBlockNumb;
|
UINT64 PartitionEntryBlockNumb;
|
||||||
UINT32 EntryArraySizeRemainder;
|
UINT32 EntryArraySizeRemainder;
|
||||||
|
|
||||||
EFI_PARTITION_ENTRY *PartitionEntryBuffer;
|
EFI_PARTITION_ENTRY *PartitionEntryBuffer;
|
||||||
EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
|
EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
|
||||||
|
|
||||||
BOOLEAN Found;
|
BOOLEAN Found;
|
||||||
EFI_LBA StartingLBA;
|
EFI_LBA StartingLBA;
|
||||||
EFI_LBA EndingLBA;
|
EFI_LBA EndingLBA;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
UINTN Index1;
|
UINTN Index1;
|
||||||
UINTN Index2;
|
UINTN Index2;
|
||||||
EFI_PARTITION_ENTRY *Entry;
|
EFI_PARTITION_ENTRY *Entry;
|
||||||
|
|
||||||
PartitionEntryBuffer = NULL;
|
PartitionEntryBuffer = NULL;
|
||||||
PartitionEntryStatus = NULL;
|
PartitionEntryStatus = NULL;
|
||||||
|
|
||||||
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
|
||||||
Found = FALSE;
|
Found = FALSE;
|
||||||
|
|
||||||
PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
|
PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
|
||||||
EntryArraySizeRemainder = 0;
|
EntryArraySizeRemainder = 0;
|
||||||
@ -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,27 +312,28 @@ 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
|
||||||
//
|
//
|
||||||
PartitionEntryStatus[Index1].Overlap = TRUE;
|
PartitionEntryStatus[Index1].Overlap = TRUE;
|
||||||
PartitionEntryStatus[Index2].Overlap = TRUE;
|
PartitionEntryStatus[Index2].Overlap = TRUE;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -340,8 +345,8 @@ PartitionCheckGptEntryArray (
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Found = TRUE;
|
Found = TRUE;
|
||||||
BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
|
BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
|
||||||
|
|
||||||
BlockDevPtr->BlockSize = ParentBlockDev->BlockSize;
|
BlockDevPtr->BlockSize = ParentBlockDev->BlockSize;
|
||||||
BlockDevPtr->LastBlock = PartitionEntryBuffer[Index].EndingLBA;
|
BlockDevPtr->LastBlock = PartitionEntryBuffer[Index].EndingLBA;
|
||||||
@ -352,13 +357,13 @@ PartitionCheckGptEntryArray (
|
|||||||
PartitionEntryBuffer[Index].StartingLBA,
|
PartitionEntryBuffer[Index].StartingLBA,
|
||||||
ParentBlockDev->BlockSize
|
ParentBlockDev->BlockSize
|
||||||
);
|
);
|
||||||
BlockDevPtr->ParentDevNo = ParentBlockDevNo;
|
BlockDevPtr->ParentDevNo = ParentBlockDevNo;
|
||||||
|
|
||||||
PrivateData->BlockDeviceCount++;
|
PrivateData->BlockDeviceCount++;
|
||||||
|
|
||||||
DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
|
DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
|
||||||
DEBUG ((DEBUG_INFO, ", 0x%lx]\n", BlockDevPtr->LastBlock));
|
DEBUG ((DEBUG_INFO, ", 0x%lx]\n", BlockDevPtr->LastBlock));
|
||||||
DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
|
DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
EXIT:
|
EXIT:
|
||||||
@ -390,18 +395,18 @@ EXIT:
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
PartitionCheckGptStructure (
|
PartitionCheckGptStructure (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo,
|
IN UINTN ParentBlockDevNo,
|
||||||
IN BOOLEAN IsPrimary
|
IN BOOLEAN IsPrimary
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
||||||
EFI_PARTITION_TABLE_HEADER *PartHdr;
|
EFI_PARTITION_TABLE_HEADER *PartHdr;
|
||||||
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;
|
||||||
@ -442,18 +447,18 @@ PartitionCheckGptStructure (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
PartitionCheckProtectiveMbr (
|
PartitionCheckProtectiveMbr (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
MASTER_BOOT_RECORD *ProtectiveMbr;
|
MASTER_BOOT_RECORD *ProtectiveMbr;
|
||||||
MBR_PARTITION_RECORD *MbrPartition;
|
MBR_PARTITION_RECORD *MbrPartition;
|
||||||
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]);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read Protective MBR
|
// Read Protective MBR
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -510,18 +516,18 @@ PartitionCheckProtectiveMbr (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatFindGptPartitions (
|
FatFindGptPartitions (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN Found;
|
BOOLEAN Found;
|
||||||
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
|
||||||
|
|
||||||
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
|
if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 exceed FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
|
DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceed FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -23,26 +23,27 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
PartitionValidMbr (
|
PartitionValidMbr (
|
||||||
IN MASTER_BOOT_RECORD *Mbr,
|
IN MASTER_BOOT_RECORD *Mbr,
|
||||||
IN EFI_PEI_LBA LastLba
|
IN EFI_PEI_LBA LastLba
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
UINT32 StartingLBA;
|
UINT32 StartingLBA;
|
||||||
UINT32 EndingLBA;
|
UINT32 EndingLBA;
|
||||||
UINT32 NewEndingLBA;
|
UINT32 NewEndingLBA;
|
||||||
INTN Index1;
|
INTN Index1;
|
||||||
INTN Index2;
|
INTN Index2;
|
||||||
BOOLEAN MbrValid;
|
BOOLEAN MbrValid;
|
||||||
|
|
||||||
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.
|
||||||
//
|
//
|
||||||
@ -98,8 +100,8 @@ PartitionValidMbr (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatFindMbrPartitions (
|
FatFindMbrPartitions (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
EFI_STATUS Status;
|
EFI_STATUS Status;
|
||||||
@ -113,55 +115,56 @@ FatFindMbrPartitions (
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
ParentBlockDevNo,
|
ParentBlockDevNo,
|
||||||
0,
|
0,
|
||||||
ParentBlockDev->BlockSize,
|
ParentBlockDev->BlockSize,
|
||||||
Mbr
|
Mbr
|
||||||
);
|
);
|
||||||
|
|
||||||
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]);
|
BlockDev->BlockSize = MBR_SIZE;
|
||||||
|
BlockDev->LastBlock = UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) - 1;
|
||||||
BlockDev->BlockSize = MBR_SIZE;
|
BlockDev->IoAlign = ParentBlockDev->IoAlign;
|
||||||
BlockDev->LastBlock = UNPACK_INT32 (Mbr->Partition[Index].SizeInLBA) - 1;
|
BlockDev->Logical = TRUE;
|
||||||
BlockDev->IoAlign = ParentBlockDev->IoAlign;
|
BlockDev->PartitionChecked = FALSE;
|
||||||
BlockDev->Logical = TRUE;
|
BlockDev->StartingPos = MultU64x32 (
|
||||||
BlockDev->PartitionChecked = FALSE;
|
UNPACK_INT32 (Mbr->Partition[Index].StartingLBA),
|
||||||
BlockDev->StartingPos = MultU64x32 (
|
ParentBlockDev->BlockSize
|
||||||
UNPACK_INT32 (Mbr->Partition[Index].StartingLBA),
|
);
|
||||||
ParentBlockDev->BlockSize
|
|
||||||
);
|
|
||||||
BlockDev->ParentDevNo = ParentBlockDevNo;
|
BlockDev->ParentDevNo = ParentBlockDevNo;
|
||||||
|
|
||||||
PrivateData->BlockDeviceCount++;
|
PrivateData->BlockDeviceCount++;
|
||||||
|
@ -24,8 +24,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatFindEltoritoPartitions (
|
FatFindEltoritoPartitions (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,8 +42,8 @@ FatFindEltoritoPartitions (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatFindMbrPartitions (
|
FatFindMbrPartitions (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,8 +61,8 @@ FatFindMbrPartitions (
|
|||||||
**/
|
**/
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
FatFindGptPartitions (
|
FatFindGptPartitions (
|
||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
IN PEI_FAT_PRIVATE_DATA *PrivateData,
|
||||||
IN UINTN ParentBlockDevNo
|
IN UINTN ParentBlockDevNo
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,8 +76,8 @@ FatFindPartitions (
|
|||||||
IN PEI_FAT_PRIVATE_DATA *PrivateData
|
IN PEI_FAT_PRIVATE_DATA *PrivateData
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
BOOLEAN Found;
|
BOOLEAN Found;
|
||||||
UINTN Index;
|
UINTN Index;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
Found = FALSE;
|
Found = FALSE;
|
||||||
|
Reference in New Issue
Block a user