ArmPkg/BdsLib: Close file after reading an Image
When loading an image from a file, close the file after reading from it. Use OpenProtocol instead of HandleProtocol to retrieve the simple file system protocol interface. 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@16586 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
f98f9d9808
commit
ad7e31b505
|
@ -467,27 +467,34 @@ BdsFileSystemSupport (
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BdsFileSystemLoadImage (
|
BdsFileSystemLoadImage (
|
||||||
IN EFI_DEVICE_PATH *DevicePath,
|
IN EFI_DEVICE_PATH *DevicePath,
|
||||||
IN EFI_HANDLE Handle,
|
IN EFI_HANDLE Handle,
|
||||||
IN EFI_DEVICE_PATH *RemainingDevicePath,
|
IN EFI_DEVICE_PATH *RemainingDevicePath,
|
||||||
IN EFI_ALLOCATE_TYPE Type,
|
IN EFI_ALLOCATE_TYPE Type,
|
||||||
IN OUT EFI_PHYSICAL_ADDRESS* Image,
|
IN OUT EFI_PHYSICAL_ADDRESS *Image,
|
||||||
OUT UINTN *ImageSize
|
OUT UINTN *ImageSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
FILEPATH_DEVICE_PATH* FilePathDevicePath;
|
EFI_STATUS Status;
|
||||||
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;
|
FILEPATH_DEVICE_PATH *FilePathDevicePath;
|
||||||
EFI_FILE_PROTOCOL *Fs;
|
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FsProtocol;
|
||||||
EFI_STATUS Status;
|
EFI_FILE_PROTOCOL *Fs;
|
||||||
EFI_FILE_INFO *FileInfo;
|
EFI_FILE_INFO *FileInfo;
|
||||||
EFI_FILE_PROTOCOL *File;
|
EFI_FILE_PROTOCOL *File;
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
|
|
||||||
ASSERT (IS_DEVICE_PATH_NODE (RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP));
|
ASSERT (IS_DEVICE_PATH_NODE (RemainingDevicePath, MEDIA_DEVICE_PATH, MEDIA_FILEPATH_DP));
|
||||||
|
|
||||||
FilePathDevicePath = (FILEPATH_DEVICE_PATH*)RemainingDevicePath;
|
FilePathDevicePath = (FILEPATH_DEVICE_PATH*)RemainingDevicePath;
|
||||||
|
|
||||||
Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&FsProtocol);
|
Status = gBS->OpenProtocol (
|
||||||
|
Handle,
|
||||||
|
&gEfiSimpleFileSystemProtocolGuid,
|
||||||
|
(VOID**)&FsProtocol,
|
||||||
|
gImageHandle,
|
||||||
|
Handle,
|
||||||
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
||||||
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
@ -495,13 +502,12 @@ BdsFileSystemLoadImage (
|
||||||
// Try to Open the volume and get root directory
|
// Try to Open the volume and get root directory
|
||||||
Status = FsProtocol->OpenVolume (FsProtocol, &Fs);
|
Status = FsProtocol->OpenVolume (FsProtocol, &Fs);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
goto CLOSE_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
File = NULL;
|
|
||||||
Status = Fs->Open (Fs, &File, FilePathDevicePath->PathName, EFI_FILE_MODE_READ, 0);
|
Status = Fs->Open (Fs, &File, FilePathDevicePath->PathName, EFI_FILE_MODE_READ, 0);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
goto CLOSE_PROTOCOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Size = 0;
|
Size = 0;
|
||||||
|
@ -509,7 +515,7 @@ BdsFileSystemLoadImage (
|
||||||
FileInfo = AllocatePool (Size);
|
FileInfo = AllocatePool (Size);
|
||||||
Status = File->GetInfo (File, &gEfiFileInfoGuid, &Size, FileInfo);
|
Status = File->GetInfo (File, &gEfiFileInfoGuid, &Size, FileInfo);
|
||||||
if (EFI_ERROR (Status)) {
|
if (EFI_ERROR (Status)) {
|
||||||
return Status;
|
goto CLOSE_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the file size
|
// Get the file size
|
||||||
|
@ -528,6 +534,16 @@ BdsFileSystemLoadImage (
|
||||||
Status = File->Read (File, &Size, (VOID*)(UINTN)(*Image));
|
Status = File->Read (File, &Size, (VOID*)(UINTN)(*Image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLOSE_FILE:
|
||||||
|
File->Close (File);
|
||||||
|
|
||||||
|
CLOSE_PROTOCOL:
|
||||||
|
gBS->CloseProtocol (
|
||||||
|
Handle,
|
||||||
|
&gEfiSimpleFileSystemProtocolGuid,
|
||||||
|
gImageHandle,
|
||||||
|
Handle);
|
||||||
|
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue