summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
diff options
context:
space:
mode:
authorRonald Cron <Ronald.Cron@arm.com>2014-12-12 19:06:10 +0000
committeroliviermartin <oliviermartin@Edk2>2014-12-12 19:06:10 +0000
commit95204533ad8ef83e0f5128ce03831eb5bcbac6cf (patch)
treebb621751a1724a0d9788f2367bd6de5c17e98650 /ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
parentfb08c45511edba2bc8f129135d1916eab02ee2fc (diff)
downloadedk2-platforms-95204533ad8ef83e0f5128ce03831eb5bcbac6cf.tar.xz
ArmPlatformPkg/BootMonFs: Fix the setting of information about a file
Rework the setting of information about a file, in particular file resizing, file renaming and the returned error codes in case of error. This rework has implied a rework of the read, write, close and flush functions. To strickly separate what has been actually written to the media (flushed) from what has not been written when a file is open, an "Info" field has been added to the description of a file. The field is used to store the modifications done to the file by the means of SetInfo() like the change of the name or of the size. Such changes are written to the media only when a flush occurs. When a file is open, the information pointed to by the "Info" field is always up-to-date. This is not the case of the information stored in the "HwDescription" of the file description which from now is just a mirror of what is written on the media. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ronald Cron <Ronald.Cron@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16511 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c')
-rw-r--r--ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c89
1 files changed, 70 insertions, 19 deletions
diff --git a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
index 5eb7afca7c..3d71760fef 100644
--- a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
+++ b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
@@ -54,6 +54,30 @@ EFI_FILE_PROTOCOL mBootMonFsFileTemplate = {
BootMonFsFlushFile
};
+/**
+ Search for a file given its name coded in Ascii.
+
+ When searching through the files of the volume, if a file is currently not
+ open, its name was written on the media and is kept in RAM in the
+ "HwDescription.Footer.Filename[]" field of the file's description.
+
+ If a file is currently open, its name might not have been written on the
+ media yet, and as the "HwDescription" is a mirror in RAM of what is on the
+ media the "HwDescription.Footer.Filename[]" might be outdated. In that case,
+ the up to date name of the file is stored in the "Info" field of the file's
+ description.
+
+ @param[in] Instance Pointer to the description of the volume in which
+ the file has to be search for.
+ @param[in] AsciiFileName Name of the file.
+
+ @param[out] File Pointer to the description of the file if the
+ file was found.
+
+ @retval EFI_SUCCESS The file was found.
+ @retval EFI_NOT_FOUND The file was not found.
+
+**/
EFI_STATUS
BootMonGetFileFromAsciiFileName (
IN BOOTMON_FS_INSTANCE *Instance,
@@ -61,22 +85,26 @@ BootMonGetFileFromAsciiFileName (
OUT BOOTMON_FS_FILE **File
)
{
- LIST_ENTRY *Entry;
- BOOTMON_FS_FILE *FileEntry;
-
- // Remove the leading '\\'
- if (*AsciiFileName == '\\') {
- AsciiFileName++;
- }
+ LIST_ENTRY *Entry;
+ BOOTMON_FS_FILE *FileEntry;
+ CHAR8 OpenFileAsciiFileName[MAX_NAME_LENGTH];
+ CHAR8 *AsciiFileNameToCompare;
// Go through all the files in the list and return the file handle
for (Entry = GetFirstNode (&Instance->RootFile->Link);
- !IsNull (&Instance->RootFile->Link, Entry);
- Entry = GetNextNode (&Instance->RootFile->Link, Entry)
- )
+ !IsNull (&Instance->RootFile->Link, Entry);
+ Entry = GetNextNode (&Instance->RootFile->Link, Entry)
+ )
{
FileEntry = BOOTMON_FS_FILE_FROM_LINK_THIS (Entry);
- if (AsciiStrCmp (FileEntry->HwDescription.Footer.Filename, AsciiFileName) == 0) {
+ if (FileEntry->Info != NULL) {
+ UnicodeStrToAsciiStr (FileEntry->Info->FileName, OpenFileAsciiFileName);
+ AsciiFileNameToCompare = OpenFileAsciiFileName;
+ } else {
+ AsciiFileNameToCompare = FileEntry->HwDescription.Footer.Filename;
+ }
+
+ if (AsciiStrCmp (AsciiFileNameToCompare, AsciiFileName) == 0) {
*File = FileEntry;
return EFI_SUCCESS;
}
@@ -291,6 +319,7 @@ BootMonFsDriverStart (
BOOTMON_FS_INSTANCE *Instance;
EFI_STATUS Status;
UINTN VolumeNameSize;
+ EFI_FILE_INFO *Info;
Instance = AllocateZeroPool (sizeof (BOOTMON_FS_INSTANCE));
if (Instance == NULL) {
@@ -307,8 +336,7 @@ BootMonFsDriverStart (
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
- FreePool (Instance);
- return Status;
+ goto Error;
}
Status = gBS->OpenProtocol (
@@ -320,8 +348,7 @@ BootMonFsDriverStart (
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
- FreePool (Instance);
- return Status;
+ goto Error;
}
//
@@ -350,10 +377,16 @@ BootMonFsDriverStart (
// Initialize the root file
Status = BootMonFsCreateFile (Instance, &Instance->RootFile);
if (EFI_ERROR (Status)) {
- FreePool (Instance);
- return Status;
+ goto Error;
}
+ Info = AllocateZeroPool (sizeof (EFI_FILE_INFO));
+ if (Info == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Error;
+ }
+ Instance->RootFile->Info = Info;
+
// Initialize the DevicePath of the Instance
Status = gBS->OpenProtocol (
ControllerHandle,
@@ -364,8 +397,7 @@ BootMonFsDriverStart (
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
- FreePool (Instance);
- return Status;
+ goto Error;
}
//
@@ -376,9 +408,24 @@ BootMonFsDriverStart (
&gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,
NULL
);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
InsertTailList (&mInstances, &Instance->Link);
+ return EFI_SUCCESS;
+
+Error:
+
+ if (Instance->RootFile != NULL) {
+ if (Instance->RootFile->Info != NULL) {
+ FreePool (Instance->RootFile->Info);
+ }
+ FreePool (Instance->RootFile);
+ }
+ FreePool (Instance);
+
return Status;
}
@@ -434,6 +481,10 @@ BootMonFsDriverStop (
&gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,
NULL);
+ FreePool (Instance->RootFile->Info);
+ FreePool (Instance->RootFile);
+ FreePool (Instance);
+
return Status;
}