2008-04-09 09:07:50 +02:00
|
|
|
/** @file
|
2008-05-21 03:40:12 +02:00
|
|
|
Handle services to image file.
|
|
|
|
|
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation. <BR>
|
2007-11-09 08:26:24 +01:00
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
#include "DxeMain.h"
|
2008-09-23 09:35:34 +02:00
|
|
|
#include "Image.h"
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-09-09 07:36:40 +02:00
|
|
|
/**
|
|
|
|
Search a handle to a device on a specified device path that supports a specified protocol,
|
|
|
|
interface of that protocol on that handle is another output.
|
|
|
|
|
2008-09-18 10:42:11 +02:00
|
|
|
|
|
|
|
|
2008-09-09 07:36:40 +02:00
|
|
|
@param Protocol The protocol to search for
|
|
|
|
@param FilePath The specified device path
|
|
|
|
@param Interface Interface of the protocol on the handle
|
|
|
|
@param Handle The handle to the device on the specified device
|
|
|
|
path that supports the protocol.
|
|
|
|
|
|
|
|
@return Status code.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
CoreDevicePathToInterface (
|
|
|
|
IN EFI_GUID *Protocol,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL **FilePath,
|
|
|
|
OUT VOID **Interface,
|
|
|
|
OUT EFI_HANDLE *Handle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = CoreLocateDevicePath (Protocol, FilePath, Handle);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = CoreHandleProtocol (*Handle, Protocol, Interface);
|
|
|
|
}
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Opens a file for (simple) reading. The simple read abstraction
|
|
|
|
will access the file either from a memory copy, from a file
|
|
|
|
system interface, or from the load file interface.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param BootPolicy Policy for Open Image File.
|
|
|
|
@param SourceBuffer Pointer to the memory location containing copy
|
|
|
|
of the image to be loaded.
|
|
|
|
@param SourceSize The size in bytes of SourceBuffer.
|
|
|
|
@param FilePath The specific file path from which the image is
|
|
|
|
loaded
|
|
|
|
@param DeviceHandle Pointer to the return device handle.
|
|
|
|
@param ImageFileHandle Pointer to the image file handle.
|
|
|
|
@param AuthenticationStatus Pointer to a caller-allocated UINT32 in which
|
|
|
|
the authentication status is returned.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS Image file successfully opened.
|
|
|
|
@retval EFI_LOAD_ERROR If the caller passed a copy of the file, and
|
|
|
|
SourceSize is 0.
|
|
|
|
@retval EFI_INVALID_PARAMETER File path is not valid.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_NOT_FOUND File not found.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
CoreOpenImageFile (
|
|
|
|
IN BOOLEAN BootPolicy,
|
|
|
|
IN VOID *SourceBuffer OPTIONAL,
|
|
|
|
IN UINTN SourceSize,
|
2007-11-09 08:26:24 +01:00
|
|
|
IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
|
2007-07-04 12:51:54 +02:00
|
|
|
OUT EFI_HANDLE *DeviceHandle,
|
|
|
|
IN IMAGE_FILE_HANDLE *ImageFileHandle,
|
|
|
|
OUT UINT32 *AuthenticationStatus
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_DEVICE_PATH_PROTOCOL *TempFilePath;
|
|
|
|
FILEPATH_DEVICE_PATH *FilePathNode;
|
|
|
|
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FwVolFilePathNode;
|
|
|
|
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
|
|
|
|
EFI_FILE_HANDLE FileHandle;
|
|
|
|
EFI_FILE_HANDLE LastHandle;
|
|
|
|
EFI_LOAD_FILE_PROTOCOL *LoadFile;
|
2009-04-03 10:13:16 +02:00
|
|
|
EFI_LOAD_FILE2_PROTOCOL *LoadFile2;
|
2007-09-04 08:12:48 +02:00
|
|
|
EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_SECTION_TYPE SectionType;
|
|
|
|
UINT8 *Pe32Buffer;
|
|
|
|
UINTN Pe32BufferSize;
|
|
|
|
EFI_FV_FILETYPE Type;
|
|
|
|
EFI_FV_FILE_ATTRIBUTES Attrib;
|
|
|
|
EFI_FILE_INFO *FileInfo;
|
|
|
|
UINTN FileInfoSize;
|
|
|
|
EFI_GUID *NameGuid;
|
2008-03-19 03:05:57 +01:00
|
|
|
FILEPATH_DEVICE_PATH *OriginalFilePathNode;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-03-19 03:05:57 +01:00
|
|
|
OriginalFilePathNode = NULL;
|
2007-07-04 12:51:54 +02:00
|
|
|
*AuthenticationStatus = 0;
|
|
|
|
ZeroMem (ImageFileHandle, sizeof (IMAGE_FILE_HANDLE));
|
|
|
|
ImageFileHandle->Signature = IMAGE_FILE_HANDLE_SIGNATURE;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the caller passed a copy of the file, then just use it
|
|
|
|
//
|
|
|
|
if (SourceBuffer != NULL) {
|
|
|
|
ImageFileHandle->Source = SourceBuffer;
|
|
|
|
ImageFileHandle->SourceSize = SourceSize;
|
2008-07-18 11:50:09 +02:00
|
|
|
*DeviceHandle = NULL;
|
2007-11-09 08:26:24 +01:00
|
|
|
CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, FilePath, DeviceHandle);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (SourceSize > 0) {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
Status = EFI_LOAD_ERROR;
|
|
|
|
}
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Make sure FilePath is valid
|
|
|
|
//
|
2007-11-09 08:26:24 +01:00
|
|
|
if (*FilePath == NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Check to see if it's in a Firmware Volume
|
|
|
|
//
|
2007-11-09 08:26:24 +01:00
|
|
|
FwVolFilePathNode = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) *FilePath;
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = CoreDevicePathToInterface (
|
2007-11-09 08:26:24 +01:00
|
|
|
&gEfiFirmwareVolume2ProtocolGuid,
|
|
|
|
(EFI_DEVICE_PATH_PROTOCOL **)&FwVolFilePathNode,
|
|
|
|
(VOID*)&FwVol,
|
2007-07-04 12:51:54 +02:00
|
|
|
DeviceHandle
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// For FwVol File system there is only a single file name that is a GUID.
|
|
|
|
//
|
|
|
|
NameGuid = EfiGetNameGuidFromFwVolDevicePathNode (FwVolFilePathNode);
|
|
|
|
if (NameGuid != NULL) {
|
|
|
|
|
|
|
|
SectionType = EFI_SECTION_PE32;
|
|
|
|
Pe32Buffer = NULL;
|
|
|
|
Status = FwVol->ReadSection (
|
2007-11-09 08:26:24 +01:00
|
|
|
FwVol,
|
|
|
|
NameGuid,
|
|
|
|
SectionType,
|
2007-07-04 12:51:54 +02:00
|
|
|
0,
|
|
|
|
(VOID **)&Pe32Buffer,
|
|
|
|
&Pe32BufferSize,
|
|
|
|
AuthenticationStatus
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Try a raw file, since a PE32 SECTION does not exist
|
|
|
|
//
|
|
|
|
if (Pe32Buffer != NULL) {
|
|
|
|
CoreFreePool (Pe32Buffer);
|
|
|
|
*AuthenticationStatus = 0;
|
|
|
|
}
|
|
|
|
Pe32Buffer = NULL;
|
|
|
|
Status = FwVol->ReadFile (
|
2007-11-09 08:26:24 +01:00
|
|
|
FwVol,
|
|
|
|
NameGuid,
|
2007-07-04 12:51:54 +02:00
|
|
|
(VOID **)&Pe32Buffer,
|
|
|
|
&Pe32BufferSize,
|
|
|
|
&Type,
|
|
|
|
&Attrib,
|
|
|
|
AuthenticationStatus
|
|
|
|
);
|
|
|
|
}
|
2007-11-09 08:26:24 +01:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// One of the reads passed so we are done
|
|
|
|
//
|
|
|
|
ImageFileHandle->Source = Pe32Buffer;
|
|
|
|
ImageFileHandle->SourceSize = Pe32BufferSize;
|
|
|
|
ImageFileHandle->FreeBuffer = TRUE;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Attempt to access the file via a file system interface
|
|
|
|
//
|
2007-11-09 08:26:24 +01:00
|
|
|
FilePathNode = (FILEPATH_DEVICE_PATH *) *FilePath;
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = CoreDevicePathToInterface (
|
2007-11-09 08:26:24 +01:00
|
|
|
&gEfiSimpleFileSystemProtocolGuid,
|
|
|
|
(EFI_DEVICE_PATH_PROTOCOL **)&FilePathNode,
|
|
|
|
(VOID*)&Volume,
|
2007-07-04 12:51:54 +02:00
|
|
|
DeviceHandle
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Open the Volume to get the File System handle
|
|
|
|
//
|
|
|
|
Status = Volume->OpenVolume (Volume, &FileHandle);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
2008-03-19 03:05:57 +01:00
|
|
|
// Duplicate the device path to avoid the access to unaligned device path node.
|
|
|
|
// Because the device path consists of one or more FILE PATH MEDIA DEVICE PATH
|
2008-07-24 04:54:45 +02:00
|
|
|
// nodes, It assures the fields in device path nodes are 2 byte aligned.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
FilePathNode = (FILEPATH_DEVICE_PATH *)DuplicateDevicePath((EFI_DEVICE_PATH_PROTOCOL *)(UINTN)FilePathNode);
|
2008-03-19 03:05:57 +01:00
|
|
|
if (FilePathNode == NULL) {
|
|
|
|
FileHandle->Close (FileHandle);
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
} else {
|
|
|
|
OriginalFilePathNode = FilePathNode;
|
|
|
|
//
|
|
|
|
// Parse each MEDIA_FILEPATH_DP node. There may be more than one, since the
|
|
|
|
// directory information and filename can be seperate. The goal is to inch
|
|
|
|
// our way down each device path node and close the previous node
|
|
|
|
//
|
|
|
|
while (!IsDevicePathEnd (&FilePathNode->Header)) {
|
|
|
|
if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||
|
|
|
|
DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP) {
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Exit loop on Error
|
|
|
|
//
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
LastHandle = FileHandle;
|
|
|
|
FileHandle = NULL;
|
|
|
|
|
|
|
|
Status = LastHandle->Open (
|
|
|
|
LastHandle,
|
|
|
|
&FileHandle,
|
|
|
|
FilePathNode->PathName,
|
|
|
|
EFI_FILE_MODE_READ,
|
|
|
|
0
|
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
2008-03-19 03:05:57 +01:00
|
|
|
// Close the previous node
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-03-19 03:05:57 +01:00
|
|
|
LastHandle->Close (LastHandle);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-03-19 03:05:57 +01:00
|
|
|
FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-07-24 04:54:45 +02:00
|
|
|
// Free the allocated memory pool
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2008-03-19 03:05:57 +01:00
|
|
|
CoreFreePool(OriginalFilePathNode);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// We have found the file. Now we need to read it. Before we can read the file we need to
|
|
|
|
// figure out how big the file is.
|
|
|
|
//
|
|
|
|
FileInfo = NULL;
|
2008-09-18 10:42:11 +02:00
|
|
|
FileInfoSize = 0;
|
|
|
|
Status = FileHandle->GetInfo (
|
|
|
|
FileHandle,
|
|
|
|
&gEfiFileInfoGuid,
|
|
|
|
&FileInfoSize,
|
|
|
|
FileInfo
|
|
|
|
);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
FileInfo = AllocatePool (FileInfoSize);
|
|
|
|
if (FileInfo != NULL) {
|
|
|
|
Status = FileHandle->GetInfo (
|
|
|
|
FileHandle,
|
|
|
|
&gEfiFileInfoGuid,
|
|
|
|
&FileInfoSize,
|
|
|
|
FileInfo
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Done;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-09-18 10:42:11 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Allocate space for the file
|
|
|
|
//
|
2009-02-16 03:07:32 +01:00
|
|
|
ASSERT (FileInfo != NULL);
|
2008-08-27 16:29:23 +02:00
|
|
|
ImageFileHandle->Source = AllocatePool ((UINTN)FileInfo->FileSize);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (ImageFileHandle->Source != NULL) {
|
|
|
|
//
|
|
|
|
// Read the file into the buffer we allocated
|
|
|
|
//
|
2008-07-18 11:50:09 +02:00
|
|
|
ImageFileHandle->SourceSize = (UINTN) FileInfo->FileSize;
|
2007-07-04 12:51:54 +02:00
|
|
|
ImageFileHandle->FreeBuffer = TRUE;
|
|
|
|
Status = FileHandle->Read (FileHandle, &ImageFileHandle->SourceSize, ImageFileHandle->Source);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Close the file since we are done
|
|
|
|
//
|
|
|
|
FileHandle->Close (FileHandle);
|
2008-09-18 10:42:11 +02:00
|
|
|
CoreFreePool (FileInfo);
|
2007-07-04 12:51:54 +02:00
|
|
|
} else {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-09 08:26:24 +01:00
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2009-04-03 10:13:16 +02:00
|
|
|
//
|
|
|
|
// Try LoadFile2 style
|
|
|
|
//
|
|
|
|
if (!BootPolicy) {
|
|
|
|
TempFilePath = *FilePath;
|
|
|
|
Status = CoreDevicePathToInterface (
|
|
|
|
&gEfiLoadFile2ProtocolGuid,
|
|
|
|
&TempFilePath,
|
|
|
|
(VOID*)&LoadFile2,
|
|
|
|
DeviceHandle
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Call LoadFile2 with the correct buffer size
|
|
|
|
//
|
|
|
|
ASSERT (ImageFileHandle->SourceSize == 0);
|
|
|
|
ASSERT (ImageFileHandle->Source == NULL);
|
|
|
|
|
|
|
|
Status = LoadFile2->LoadFile (
|
|
|
|
LoadFile2,
|
|
|
|
TempFilePath,
|
|
|
|
BootPolicy,
|
|
|
|
&ImageFileHandle->SourceSize,
|
|
|
|
ImageFileHandle->Source
|
|
|
|
);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
ImageFileHandle->Source = AllocatePool (ImageFileHandle->SourceSize);
|
|
|
|
if (ImageFileHandle->Source == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
} else {
|
|
|
|
Status = LoadFile2->LoadFile (
|
|
|
|
LoadFile2,
|
|
|
|
TempFilePath,
|
|
|
|
BootPolicy,
|
|
|
|
&ImageFileHandle->SourceSize,
|
|
|
|
ImageFileHandle->Source
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
ImageFileHandle->FreeBuffer = TRUE;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Try LoadFile style
|
|
|
|
//
|
|
|
|
|
2007-11-09 08:26:24 +01:00
|
|
|
TempFilePath = *FilePath;
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = CoreDevicePathToInterface (
|
2008-07-18 11:50:09 +02:00
|
|
|
&gEfiLoadFileProtocolGuid,
|
|
|
|
&TempFilePath,
|
|
|
|
(VOID*) &LoadFile,
|
|
|
|
DeviceHandle
|
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// Call LoadFile with the correct buffer size
|
|
|
|
//
|
2008-09-18 10:42:11 +02:00
|
|
|
ASSERT (ImageFileHandle->SourceSize == 0);
|
|
|
|
ASSERT (ImageFileHandle->Source == NULL);
|
|
|
|
Status = LoadFile->LoadFile (
|
|
|
|
LoadFile,
|
|
|
|
TempFilePath,
|
|
|
|
BootPolicy,
|
|
|
|
&ImageFileHandle->SourceSize,
|
|
|
|
ImageFileHandle->Source
|
|
|
|
);
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
ImageFileHandle->Source = AllocatePool (ImageFileHandle->SourceSize);
|
|
|
|
if (ImageFileHandle->Source == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
} else {
|
|
|
|
Status = LoadFile->LoadFile (
|
|
|
|
LoadFile,
|
|
|
|
TempFilePath,
|
|
|
|
BootPolicy,
|
|
|
|
&ImageFileHandle->SourceSize,
|
|
|
|
ImageFileHandle->Source
|
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-18 11:03:36 +02:00
|
|
|
if (!EFI_ERROR (Status)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
ImageFileHandle->FreeBuffer = TRUE;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Nothing else to try
|
|
|
|
//
|
2008-09-18 10:42:11 +02:00
|
|
|
DEBUG ((DEBUG_LOAD|DEBUG_WARN, "CoreOpenImageFile: Device did not support a known load protocol\n"));
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = EFI_NOT_FOUND;
|
|
|
|
|
|
|
|
Done:
|
|
|
|
//
|
|
|
|
// If the file was not accessed, clean up
|
|
|
|
//
|
2008-09-18 11:03:36 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2007-07-04 12:51:54 +02:00
|
|
|
if (ImageFileHandle->FreeBuffer) {
|
|
|
|
//
|
|
|
|
// Free the source buffer if we allocated it
|
|
|
|
//
|
|
|
|
CoreFreePool (ImageFileHandle->Source);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Read image file (specified by UserHandle) into user specified buffer with specified offset
|
|
|
|
and length.
|
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@param UserHandle Image file handle
|
|
|
|
@param Offset Offset to the source file
|
|
|
|
@param ReadSize For input, pointer of size to read; For output,
|
|
|
|
pointer of size actually read.
|
|
|
|
@param Buffer Buffer to write into
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
@retval EFI_SUCCESS Successfully read the specified part of file
|
2008-05-09 09:08:30 +02:00
|
|
|
into buffer.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreReadImageFile (
|
|
|
|
IN VOID *UserHandle,
|
|
|
|
IN UINTN Offset,
|
|
|
|
IN OUT UINTN *ReadSize,
|
|
|
|
OUT VOID *Buffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN EndPosition;
|
|
|
|
IMAGE_FILE_HANDLE *FHand;
|
|
|
|
|
|
|
|
FHand = (IMAGE_FILE_HANDLE *)UserHandle;
|
|
|
|
ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Move data from our local copy of the file
|
|
|
|
//
|
|
|
|
EndPosition = Offset + *ReadSize;
|
|
|
|
if (EndPosition > FHand->SourceSize) {
|
|
|
|
*ReadSize = (UINT32)(FHand->SourceSize - Offset);
|
2007-11-09 08:26:24 +01:00
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Offset >= FHand->SourceSize) {
|
|
|
|
*ReadSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|