#include "BootMonFsInternal.h"\r
\r
EFI_DEVICE_PATH* mBootMonFsSupportedDevicePaths;\r
-EFI_HANDLE mImageHandle;\r
LIST_ENTRY mInstances;\r
\r
EFI_FILE_PROTOCOL mBootMonFsRootTemplate = {\r
BootMonFsFlushFile\r
};\r
\r
+/**\r
+ Search for a file given its name coded in Ascii.\r
+\r
+ When searching through the files of the volume, if a file is currently not\r
+ open, its name was written on the media and is kept in RAM in the\r
+ "HwDescription.Footer.Filename[]" field of the file's description.\r
+\r
+ If a file is currently open, its name might not have been written on the\r
+ media yet, and as the "HwDescription" is a mirror in RAM of what is on the\r
+ media the "HwDescription.Footer.Filename[]" might be outdated. In that case,\r
+ the up to date name of the file is stored in the "Info" field of the file's\r
+ description.\r
+\r
+ @param[in] Instance Pointer to the description of the volume in which\r
+ the file has to be search for.\r
+ @param[in] AsciiFileName Name of the file.\r
+\r
+ @param[out] File Pointer to the description of the file if the\r
+ file was found.\r
+\r
+ @retval EFI_SUCCESS The file was found.\r
+ @retval EFI_NOT_FOUND The file was not found.\r
+\r
+**/\r
EFI_STATUS\r
BootMonGetFileFromAsciiFileName (\r
IN BOOTMON_FS_INSTANCE *Instance,\r
OUT BOOTMON_FS_FILE **File\r
)\r
{\r
- LIST_ENTRY *Entry;\r
- BOOTMON_FS_FILE *FileEntry;\r
-\r
- // Remove the leading '\\'\r
- if (*AsciiFileName == '\\') {\r
- AsciiFileName++;\r
- }\r
+ LIST_ENTRY *Entry;\r
+ BOOTMON_FS_FILE *FileEntry;\r
+ CHAR8 OpenFileAsciiFileName[MAX_NAME_LENGTH];\r
+ CHAR8 *AsciiFileNameToCompare;\r
\r
// Go through all the files in the list and return the file handle\r
for (Entry = GetFirstNode (&Instance->RootFile->Link);\r
- !IsNull (&Instance->RootFile->Link, Entry);\r
- Entry = GetNextNode (&Instance->RootFile->Link, Entry)\r
- )\r
+ !IsNull (&Instance->RootFile->Link, Entry);\r
+ Entry = GetNextNode (&Instance->RootFile->Link, Entry)\r
+ )\r
{\r
FileEntry = BOOTMON_FS_FILE_FROM_LINK_THIS (Entry);\r
- if (AsciiStrCmp (FileEntry->HwDescription.Footer.Filename, AsciiFileName) == 0) {\r
+ if (FileEntry->Info != NULL) {\r
+ UnicodeStrToAsciiStrS (FileEntry->Info->FileName, OpenFileAsciiFileName,\r
+ MAX_NAME_LENGTH);\r
+ AsciiFileNameToCompare = OpenFileAsciiFileName;\r
+ } else {\r
+ AsciiFileNameToCompare = FileEntry->HwDescription.Footer.Filename;\r
+ }\r
+\r
+ if (AsciiStrCmp (AsciiFileNameToCompare, AsciiFileName) == 0) {\r
*File = FileEntry;\r
return EFI_SUCCESS;\r
}\r
ControllerHandle,\r
&gEfiDiskIoProtocolGuid,\r
(VOID **) &DiskIo,\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
);\r
gBS->CloseProtocol (\r
ControllerHandle,\r
&gEfiDiskIoProtocolGuid,\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle\r
);\r
\r
ControllerHandle,\r
&gEfiBlockIoProtocolGuid,\r
NULL,\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
);\r
ControllerHandle,\r
&gEfiDevicePathProtocolGuid,\r
(VOID **)&DevicePathProtocol,\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
);\r
}\r
}\r
\r
- gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, mImageHandle, ControllerHandle);\r
+ gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, gImageHandle, ControllerHandle);\r
return Status;\r
}\r
\r
BOOTMON_FS_INSTANCE *Instance;\r
EFI_STATUS Status;\r
UINTN VolumeNameSize;\r
+ EFI_FILE_INFO *Info;\r
\r
Instance = AllocateZeroPool (sizeof (BOOTMON_FS_INSTANCE));\r
if (Instance == NULL) {\r
ControllerHandle,\r
&gEfiBlockIoProtocolGuid,\r
(VOID **)&(Instance->BlockIo),\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
);\r
if (EFI_ERROR (Status)) {\r
- FreePool (Instance);\r
- return Status;\r
+ goto Error;\r
}\r
\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiDiskIoProtocolGuid,\r
(VOID **)&(Instance->DiskIo),\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
);\r
if (EFI_ERROR (Status)) {\r
- FreePool (Instance);\r
- return Status;\r
+ goto Error;\r
}\r
\r
//\r
// Initialize the root file\r
Status = BootMonFsCreateFile (Instance, &Instance->RootFile);\r
if (EFI_ERROR (Status)) {\r
- FreePool (Instance);\r
- return Status;\r
+ goto Error;\r
}\r
\r
+ Info = AllocateZeroPool (sizeof (EFI_FILE_INFO));\r
+ if (Info == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Error;\r
+ }\r
+ Instance->RootFile->Info = Info;\r
+\r
// Initialize the DevicePath of the Instance\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiDevicePathProtocolGuid,\r
(VOID **)&(Instance->DevicePath),\r
- mImageHandle,\r
+ gImageHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
);\r
if (EFI_ERROR (Status)) {\r
- FreePool (Instance);\r
- return Status;\r
+ goto Error;\r
}\r
\r
//\r
&gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,\r
NULL\r
);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
\r
InsertTailList (&mInstances, &Instance->Link);\r
\r
+ return EFI_SUCCESS;\r
+\r
+Error:\r
+\r
+ if (Instance->RootFile != NULL) {\r
+ if (Instance->RootFile->Info != NULL) {\r
+ FreePool (Instance->RootFile->Info);\r
+ }\r
+ FreePool (Instance->RootFile);\r
+ }\r
+ FreePool (Instance);\r
+\r
return Status;\r
}\r
\r
&gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,\r
NULL);\r
\r
+ FreePool (Instance->RootFile->Info);\r
+ FreePool (Instance->RootFile);\r
+ FreePool (Instance);\r
+\r
return Status;\r
}\r
\r
{\r
EFI_STATUS Status;\r
\r
- mImageHandle = ImageHandle;\r
InitializeListHead (&mInstances);\r
\r
// Initialize the list of Device Paths that could support BootMonFs\r