本文整理汇总了C++中EFI_FILE_HANDLE类的典型用法代码示例。如果您正苦于以下问题:C++ EFI_FILE_HANDLE类的具体用法?C++ EFI_FILE_HANDLE怎么用?C++ EFI_FILE_HANDLE使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EFI_FILE_HANDLE类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFileWithPadding
void* LoadFileWithPadding(EFI_FILE_HANDLE dir, const CHAR16* path, UINTN* size_ptr, UINTN padding) {
EFI_STATUS e;
EFI_FILE_HANDLE handle;
e = dir->Open(dir, &handle, (CHAR16*) path, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(e)) {
return 0;
}
EFI_FILE_INFO *info = LibFileInfo(handle);
UINTN size = info->FileSize;
FreePool(info);
void* data = 0;
e = BS->AllocatePool(EfiBootServicesData, size + padding, &data);
if (EFI_ERROR(e)) {
handle->Close(handle);
return 0;
}
e = handle->Read(handle, &size, data);
for (int i = 0; i < padding; ++i) {
*((char*)data + size + i) = 0;
}
handle->Close(handle);
if (EFI_ERROR(e)) {
FreePool(data);
return 0;
}
if (size_ptr) {
*size_ptr = size;
}
return data;
}
示例2: InstallAgent
EFI_STATUS
EFIAPI
InstallAgent(
IN EFI_FILE_HANDLE CurDir,
IN CHAR16 * FileNameUser
)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_FILE_HANDLE FileHandle;
CHAR16* FileNameScout;
FileNameScout = AllocateZeroPool(260*sizeof(CHAR16));
StrCpy(FileNameScout,FileNameUser);
StrCat(FileNameScout, FILE_NAME_SCOUT);
StrCat(FileNameScout, g_NAME_SCOUT);
Status = CurDir->Open (CurDir, &FileHandle, FileNameScout, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
FreePool(FileNameScout);
if (EFI_ERROR(Status))
{
#ifdef FORCE_DEBUG
Print(L"Error Open Agent File\n");
#endif
return Status;
}
#ifdef FORCE_DEBUG
Print(L"FileHandle->Write ... VirtualSize=%x [0]=%x [1]=%x [2]=%x [3]=%x\n",VirtualSize,((UINT8*)pSectiondata)[0],((UINT8*)pSectiondata)[1] * 0x100 ,((UINT8*)pSectiondata)[2] * 0x10000,((UINT8*)pSectiondata)[3] * 0x1000000);
#endif
Status=FileHandle->Write(FileHandle,&VirtualSize,(UINT8*)(pSectiondata));
if( Status != EFI_SUCCESS )
{
#ifdef FORCE_DEBUG
Print(L"Write File Agent Failed\n");
#endif
return Status;
}
else
{
#ifdef FORCE_DEBUG
Print(L"InstallAgent OK\n");
#endif
}
Status=FileHandle->Close(FileHandle);
if( Status != EFI_SUCCESS )
{
#ifdef FORCE_DEBUG
Print(L"Closing File Agent Failed\n");
#endif
return Status;
}
return EFI_SUCCESS;
}
示例3: GetNvVarsFile
/**
Open the NvVars file for reading or writing
@param[in] FsHandle - Handle for a gEfiSimpleFileSystemProtocolGuid instance
@param[in] ReadingFile - TRUE: open the file for reading. FALSE: writing
@param[out] NvVarsFile - If EFI_SUCCESS is returned, then this is updated
with the opened NvVars file.
@return EFI_SUCCESS if the file was opened
**/
EFI_STATUS
GetNvVarsFile (
IN EFI_HANDLE FsHandle,
IN BOOLEAN ReadingFile,
OUT EFI_FILE_HANDLE *NvVarsFile
)
{
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
EFI_FILE_HANDLE Root;
//
// Get the FileSystem protocol on that handle
//
Status = gBS->HandleProtocol (
FsHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID **)&Fs
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the volume (the root directory)
//
Status = Fs->OpenVolume (Fs, &Root);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Attempt to open the NvVars file in the root directory
//
Status = Root->Open (
Root,
NvVarsFile,
L"NvVars",
ReadingFile ?
EFI_FILE_MODE_READ :
(
EFI_FILE_MODE_CREATE |
EFI_FILE_MODE_READ |
EFI_FILE_MODE_WRITE
),
0
);
if (EFI_ERROR (Status)) {
return Status;
}
return Status;
}
示例4: SetPathCase
// Fix the case of a path by looking it up on the file system
static EFI_STATUS SetPathCase(CONST EFI_FILE_HANDLE Root, CHAR16* Path)
{
EFI_FILE_HANDLE FileHandle = NULL;
EFI_FILE_INFO* FileInfo;
UINTN i, Len;
UINTN Size;
EFI_STATUS Status;
if ((Root == NULL) || (Path == NULL) || (Path[0] != L'\\'))
return EFI_INVALID_PARAMETER;
FileInfo = (EFI_FILE_INFO*)AllocatePool(FILE_INFO_SIZE);
if (FileInfo == NULL)
return EFI_OUT_OF_RESOURCES;
Len = StrLen(Path);
// Find the last backslash in the path
for (i = Len-1; (i != 0) && (Path[i] != L'\\'); i--);
if (i != 0) {
Path[i] = 0;
// Recursively fix the case
Status = SetPathCase(Root, Path);
if (EFI_ERROR(Status))
goto out;
}
Status = Root->Open(Root, &FileHandle, (i==0)?L"\\":Path, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status))
goto out;
do {
Size = FILE_INFO_SIZE;
Status = FileHandle->Read(FileHandle, &Size, (VOID*)FileInfo);
if (EFI_ERROR(Status))
goto out;
if (_StriCmp(&Path[i+1], FileInfo->FileName) == 0) {
StrCpy(&Path[i+1], FileInfo->FileName);
Status = EFI_SUCCESS;
goto out;
}
Status = EFI_NOT_FOUND;
} while (Size != 0);
out:
Path[i] = L'\\';
if (FileHandle != NULL)
FileHandle->Close(FileHandle);
FreePool((VOID*)FileInfo);
return Status;
}
示例5: InsertFileLock
EFI_STATUS
EFIAPI
InsertFileLock(
IN EFI_FILE_HANDLE CurDir,
IN CHAR16 * FileNameUser
)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_FILE_HANDLE FileHandle;
CHAR16* FileNameElite;
FileNameElite = AllocateZeroPool(260*sizeof(CHAR16));
StrCpy(FileNameElite,FileNameUser);
StrCat(FileNameElite,FILE_NAME_ELITE);
StrCat(FileNameElite,g_NAME_ELITE);
#ifdef FORCE_DEBUG
Print(L"sto tentando di scrivere: %s\n",FILE_NAME_ELITE);
#endif
Status = CurDir->Open (CurDir, &FileHandle, FileNameElite, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
FreePool(FileNameElite);
if (EFI_ERROR(Status))
{
#ifdef FORCE_DEBUG
Print(L"Error Open File InsertFileLock\n");
#endif
return Status;
}
else
{
#ifdef FORCE_DEBUG
Print(L"InsertFileLock OK\n");
#endif
}
Status=FileHandle->Close(FileHandle);
if( Status != EFI_SUCCESS )
{
#ifdef FORCE_DEBUG
Print(L"Closing InsertFileLock File Failed\n");
#endif
return Status;
}
return EFI_SUCCESS;
}
示例6: RemoveFileLock
EFI_STATUS
EFIAPI
RemoveFileLock(
IN EFI_FILE_HANDLE CurDir,
IN CHAR16 * FileNameUser
)
{
EFI_STATUS Status = EFI_SUCCESS;
EFI_FILE_HANDLE FileHandle;
CHAR16* FileNameElite;
FileNameElite = AllocateZeroPool(260*sizeof(CHAR16));
StrCpy(FileNameElite,FileNameUser);
StrCat(FileNameElite,FILE_NAME_ELITE);
StrCat(FileNameElite,g_NAME_ELITE);
Status = CurDir->Open (CurDir, &FileHandle, FileNameElite, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
FreePool(FileNameElite);
if (EFI_ERROR(Status))
{
#ifdef FORCE_DEBUG
Print(L"Error Open File RemoveFileLock\n");
#endif
return Status;
}
else
{
#ifdef FORCE_DEBUG
Print(L"RemoveFileLock OK\n");
#endif
}
Status=FileHandle->Delete(FileHandle);
if( Status != EFI_SUCCESS )
{
#ifdef FORCE_DEBUG
Print(L"Write RemoveFileLock File Failed\n");
#endif
return Status;
}
return EFI_SUCCESS;
}
示例7: LibCreateNewFile
/**
Create a new file or folder in current directory.
@param FileName Point to the fileNmae or folder name.
@param CreateFile CreateFile== TRUE means create a new file.
CreateFile== FALSE means create a new Folder.
**/
EFI_STATUS
LibCreateNewFile (
IN CHAR16 *FileName,
IN BOOLEAN CreateFile
)
{
EFI_FILE_HANDLE FileHandle;
EFI_FILE_HANDLE NewHandle;
EFI_HANDLE DeviceHandle;
EFI_STATUS Status;
CHAR16 *ParentName;
CHAR16 *FullFileName;
NewHandle = NULL;
FullFileName = NULL;
LibGetFileHandleFromDevicePath(gFileExplorerPrivate.RetDevicePath, &FileHandle, &ParentName, &DeviceHandle);
FullFileName = LibAppendFileName (ParentName, FileName);
if (FullFileName == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (CreateFile) {
Status = FileHandle->Open(
FileHandle,
&NewHandle,
FullFileName,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE| EFI_FILE_MODE_CREATE,
0
);
if (EFI_ERROR (Status)) {
FileHandle->Close (FileHandle);
return Status;
}
} else {
Status = FileHandle->Open(
FileHandle,
&NewHandle,
FullFileName,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE| EFI_FILE_MODE_CREATE,
EFI_FILE_DIRECTORY
);
if (EFI_ERROR (Status)) {
FileHandle->Close (FileHandle);
return Status;
}
}
FileHandle->Close (FileHandle);
//
// Return the DevicePath of the new created file or folder.
//
gFileExplorerPrivate.RetDevicePath = FileDevicePath (DeviceHandle, FullFileName);
return EFI_SUCCESS;
}
示例8: LibGetFileHandleFromMenu
/**
Find the file handle from the input menu info.
@param MenuEntry Input Menu info.
@param RetFileHandle Return the file handle for the input device path.
@retval EFI_SUCESS Find the file handle success.
@retval Other Find the file handle failure.
**/
EFI_STATUS
LibGetFileHandleFromMenu (
IN MENU_ENTRY *MenuEntry,
OUT EFI_FILE_HANDLE *RetFileHandle
)
{
EFI_FILE_HANDLE Dir;
EFI_FILE_HANDLE NewDir;
FILE_CONTEXT *FileContext;
EFI_STATUS Status;
FileContext = (FILE_CONTEXT *) MenuEntry->VariableContext;
Dir = FileContext->FileHandle;
//
// Open current directory to get files from it
//
Status = Dir->Open (
Dir,
&NewDir,
FileContext->FileName,
EFI_FILE_READ_ONLY,
0
);
if (EFI_ERROR (Status)) {
return Status;
}
if (!FileContext->IsRoot) {
Dir->Close (Dir);
}
*RetFileHandle = NewDir;
return EFI_SUCCESS;
}
示例9: WriteFileFromBuffer
/**
Write a file.
@param[in] FileName The file to be written.
@param[in] BufferSize The file buffer size
@param[in] Buffer The file buffer
@retval EFI_SUCCESS Write file successfully
**/
EFI_STATUS
WriteFileFromBuffer (
IN CHAR16 *FileName,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
EFI_STATUS Status;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
UINTN TempBufferSize;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
Vol = GetMyVol();
if (Vol == NULL) {
return EFI_NOT_FOUND;
}
//
// Open the root directory
//
Status = Vol->OpenVolume (Vol, &RootDir);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the file
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE| EFI_FILE_MODE_CREATE,
0
);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return Status;
}
//
// Delete file
//
Status = Handle->Delete(Handle);
if (EFI_ERROR(Status)) {
return Status;
}
//
// Open the file again
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE| EFI_FILE_MODE_CREATE,
0
);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return Status;
}
RootDir->Close (RootDir);
//
// Write the file data from the buffer
//
TempBufferSize = BufferSize;
Status = Handle->Write (
Handle,
&TempBufferSize,
Buffer
);
if (EFI_ERROR (Status)) {
Handle->Close (Handle);
return Status;
}
Handle->Close (Handle);
return EFI_SUCCESS;
}
示例10: LoadSupportFiles
EFI_STATUS
LoadSupportFiles (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CHAR16 *FilePath,
IN BOOLEAN Recursive,
OUT EFI_LIST_ENTRY *SupportFileList
)
/*++
Routine Description:
Load all test support files.
Arguments:
DevicePath - Device path of the files.
FilePath - Path of the files.
Recursive - Recursively.
SupportFileList - Pointer to the support file list.
Returns:
EFI_SUCCESS - Successfully.
Other value - Something failed.
--*/
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE SupportDir;
CHAR16 *SubDir;
CHAR16 *FileName;
UINTN FileInfoSize;
EFI_FILE_INFO *FileInfo;
EFI_SCT_TEST_FILE *SupportFile;
EFI_DEVICE_PATH_PROTOCOL *RemainderPath;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
//
// Check parameters
//
if ((DevicePath == NULL) || (FilePath == NULL) || (SupportFileList == NULL)) {
return EFI_INVALID_PARAMETER;
}
//
// Debug information
//
EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Load support files from <%s>", FilePath));
//
// Locate the device handle from the device path
//
RemainderPath = DevicePath;
Status = BS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&RemainderPath,
&DeviceHandle
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate device handle - %r", Status));
return Status;
}
//
// Locate the volume of the file system
//
Status = BS->HandleProtocol (
DeviceHandle,
&gEfiSimpleFileSystemProtocolGuid,
&Vol
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate file system - %r", Status));
return Status;
}
//
// Open the root volume
//
Status = Vol->OpenVolume (Vol, &RootDir);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open root volume - %r", Status));
return Status;
}
//
// Open the support directory
//
Status = RootDir->Open (
RootDir,
&SupportDir,
FilePath,
EFI_FILE_MODE_READ,
EFI_FILE_DIRECTORY
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open support directory - %r", Status));
//.........这里部分代码省略.........
示例11: GetFileBufferByFilePath
EFIAPI
GetFileBufferByFilePath (
IN BOOLEAN BootPolicy,
IN CONST EFI_DEVICE_PATH_PROTOCOL *FilePath,
OUT UINTN *FileSize,
OUT UINT32 *AuthenticationStatus
)
{
EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
EFI_DEVICE_PATH_PROTOCOL *OrigDevicePathNode;
EFI_DEVICE_PATH_PROTOCOL *TempDevicePathNode;
EFI_HANDLE Handle;
EFI_GUID *FvNameGuid;
EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;
EFI_SECTION_TYPE SectionType;
UINT8 *ImageBuffer;
UINTN ImageBufferSize;
EFI_FV_FILETYPE Type;
EFI_FV_FILE_ATTRIBUTES Attrib;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_FILE_HANDLE FileHandle;
EFI_FILE_HANDLE LastHandle;
EFI_FILE_INFO *FileInfo;
UINTN FileInfoSize;
EFI_LOAD_FILE_PROTOCOL *LoadFile;
EFI_LOAD_FILE2_PROTOCOL *LoadFile2;
EFI_STATUS Status;
//
// Check input File device path.
//
if (FilePath == NULL || FileSize == NULL || AuthenticationStatus == NULL) {
return NULL;
}
//
// Init local variable
//
TempDevicePathNode = NULL;
FvNameGuid = NULL;
FileInfo = NULL;
FileHandle = NULL;
ImageBuffer = NULL;
ImageBufferSize = 0;
*AuthenticationStatus = 0;
//
// Copy File Device Path
//
OrigDevicePathNode = DuplicateDevicePath (FilePath);
if (OrigDevicePathNode == NULL) {
return NULL;
}
//
// Check whether this device path support FV2 protocol.
// Is so, this device path may contain a Image.
//
DevicePathNode = OrigDevicePathNode;
Status = gBS->LocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &DevicePathNode, &Handle);
if (!EFI_ERROR (Status)) {
//
// For FwVol File system there is only a single file name that is a GUID.
//
FvNameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((CONST MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevicePathNode);
if (FvNameGuid == NULL) {
Status = EFI_INVALID_PARAMETER;
} else {
//
// Read image from the firmware file
//
Status = gBS->HandleProtocol (Handle, &gEfiFirmwareVolume2ProtocolGuid, (VOID**)&FwVol);
if (!EFI_ERROR (Status)) {
SectionType = EFI_SECTION_PE32;
ImageBuffer = NULL;
Status = FwVol->ReadSection (
FwVol,
FvNameGuid,
SectionType,
0,
(VOID **)&ImageBuffer,
&ImageBufferSize,
AuthenticationStatus
);
if (EFI_ERROR (Status)) {
//
// Try a raw file, since a PE32 SECTION does not exist
//
if (ImageBuffer != NULL) {
FreePool (ImageBuffer);
*AuthenticationStatus = 0;
}
ImageBuffer = NULL;
Status = FwVol->ReadFile (
FwVol,
FvNameGuid,
(VOID **)&ImageBuffer,
&ImageBufferSize,
&Type,
&Attrib,
//.........这里部分代码省略.........
示例12: EntryPoint
EFI_STATUS
EntryPoint (
EFI_HANDLE ImageHandle,
EFI_SYSTEM_TABLE* SystemTable
)
{
EFI_STATUS Status = 0;
UINTN i = 0;
EFI_FILE_IO_INTERFACE *Vol = 0;
EFI_FILE_HANDLE RootFs = 0;
EFI_FILE_HANDLE FileHandle = 0;
EFI_HANDLE* Search = 0;
EFI_HANDLE DeviceHandle = 0;
UINTN Size = 0;
VOID* BootmgrBuffer = 0;
EFI_FILE_INFO* FileInfoBuffer = 0;
EFI_HANDLE BootmgrHandle = NULL;
EFI_LOADED_IMAGE *BootmgrLoadedImage = 0;
EFI_LOADED_IMAGE *LoadedImage = 0;
CHAR16 *BOOTMGFW = L"\\EFI\\Microsoft\\BOOT\\BOOTMGFW.EFI";
CHAR16 *BOOTMGFW_BAK = L"\\EFI\\Microsoft\\BOOT\\BOOTMGFW.BAK";
EFI_DEVICE_PATH_PROTOCOL* DevPath = 0;
ST = SystemTable;
BS = ST->BootServices;
RS = ST->RuntimeServices;
Status = Main();
//=========================================================================//
// get device handle for the loaded (this) image //
//=========================================================================//
Status = BS->HandleProtocol(ImageHandle, &gLoadedImageProtocol, (VOID **) &LoadedImage);
if (EFI_ERROR (Status)) {
return Status;
}
DeviceHandle = LoadedImage->DeviceHandle;
//=========================================================================//
// get file io interface for device image was loaded from //
//=========================================================================//
Status = BS->HandleProtocol(DeviceHandle, &gFileSystemProtocol, (VOID **) &Vol);
if (EFI_ERROR (Status)) {
return Status;
}
//=========================================================================//
// open file system root for the device image was loaded from //
//=========================================================================//
Status = Vol->OpenVolume(Vol, &RootFs);
if (EFI_ERROR (Status)) {
return Status;
}
//=========================================================================//
// try to open bootmgfw on file system that image was loaded from //
//=========================================================================//
//=========================================================================//
// look for BOOTMGFW.BAK first to support BOOTMGFW.EFI replacement //
// install method. //
//=========================================================================//
Status = RootFs->Open(RootFs, &FileHandle, BOOTMGFW_BAK, EFI_FILE_MODE_READ, 0);
if (Status == EFI_SUCCESS) {
BOOTMGFW = BOOTMGFW_BAK;
}
else if (Status == EFI_NOT_FOUND) {
/* if BOOTMGFW.BAK not found search for BOOTMGFW.EFI */
Status = RootFs->Open(RootFs, &FileHandle, BOOTMGFW, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
RootFs->Close(RootFs);
switch(Status) {
case EFI_NOT_FOUND:
//=========================================================================//
// failed to find bootmgfw on same device, look for it on other devices. //
// get array of device handle's that bootmgfw might be installed on //
// first get size of array //
//=========================================================================//
Size = 0;
Status = BS->LocateHandle(ByProtocol, &gFileSystemProtocol, NULL, &Size, 0);
if(Status == EFI_BUFFER_TOO_SMALL) {
/* allocate memory for array */
Search = (EFI_HANDLE *) AllocatePool(Size);
}
if(Search) {
/* get the array */
Status = BS->LocateHandle(ByProtocol, &gFileSystemProtocol, NULL, &Size, Search);
/* loop through handle's open each file system & try to open bootmgfw */
if(Status == EFI_SUCCESS) {
for(i = 0; i < Size / sizeof(EFI_HANDLE); i++) {
/* we already know bootmgfw is not in the same device as the loaded image, skip */
if(Search[i] == DeviceHandle) {
continue;
}
//.........这里部分代码省略.........
示例13: headers
/**
Get the headers (dos, image, optional header) from an image
@param Device SimpleFileSystem device handle
@param FileName File name for the image
@param DosHeader Pointer to dos header
@param Hdr The buffer in which to return the PE32, PE32+, or TE header.
@retval EFI_SUCCESS Successfully get the machine type.
@retval EFI_NOT_FOUND The file is not found.
@retval EFI_LOAD_ERROR File is not a valid image file.
**/
EFI_STATUS
EFIAPI
BdsLibGetImageHeader (
IN EFI_HANDLE Device,
IN CHAR16 *FileName,
OUT EFI_IMAGE_DOS_HEADER *DosHeader,
OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
)
{
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_FILE_HANDLE Root;
EFI_FILE_HANDLE ThisFile;
UINTN BufferSize;
UINT64 FileSize;
EFI_FILE_INFO *Info;
Root = NULL;
ThisFile = NULL;
//
// Handle the file system interface to the device
//
Status = gBS->HandleProtocol (
Device,
&gEfiSimpleFileSystemProtocolGuid,
(VOID *) &Volume
);
if (EFI_ERROR (Status)) {
goto Done;
}
Status = Volume->OpenVolume (
Volume,
&Root
);
if (EFI_ERROR (Status)) {
Root = NULL;
goto Done;
}
// ASSERT (Root != NULL);
Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
goto Done;
}
// ASSERT (ThisFile != NULL);
//
// Get file size
//
BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
do {
Info = NULL;
Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);
if (EFI_ERROR (Status)) {
goto Done;
}
Status = ThisFile->GetInfo (
ThisFile,
&gEfiFileInfoGuid,
&BufferSize,
Info
);
if (!EFI_ERROR (Status)) {
break;
}
if (Status != EFI_BUFFER_TOO_SMALL) {
FreePool (Info);
goto Done;
}
FreePool (Info);
} while (TRUE);
FileSize = Info->FileSize;
FreePool (Info);
//
// Read dos header
//
BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);
if (EFI_ERROR (Status) ||
BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||
FileSize <= DosHeader->e_lfanew ||
DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//.........这里部分代码省略.........
示例14: PlatformBdsPolicyBehavior
//.........这里部分代码省略.........
TryRunningQemuKernel ();
//
// Give one chance to enter the setup if we
// have the time out
//
if (Timeout != 0) {
//PlatformBdsEnterFrontPage (Timeout, FALSE);
}
DEBUG ((EFI_D_INFO, "BdsLibConnectAll\n"));
BdsLibConnectAll ();
#ifdef VBOX
{
UINTN cFileSystem = 0;
EFI_HANDLE *phFileSystem = NULL;
BDS_COMMON_OPTION *BootOption0080 = NULL;
EFI_STATUS rc = EFI_SUCCESS;
DEBUG ((EFI_D_INFO, "------------------ VBox Platform Specific Initialization Start -----------------------\n"));
BootOption0080 = BdsLibVariableToOption(BootOptionList, L"Boot0080");
if (!BootOption0080)
{
rc = gBS->LocateHandleBuffer (ByProtocol,
&gEfiSimpleFileSystemProtocolGuid,
NULL,
&cFileSystem,
&phFileSystem);
VBoxLogFlowFuncMarkRC(rc);
VBoxLogFlowFuncMarkVar(cFileSystem, "%d");
if ( rc == EFI_SUCCESS
&& cFileSystem > 0)
{
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *pFSVolume;
EFI_FILE_HANDLE hFSRoot;
EFI_FILE_HANDLE hBootEfiFile;
UINTN iFileSystem = 0;
/* Ok, we've found several simple file system handles
* 1. we should find if '\\System\\Library\\CoreServices\\boot.efi' present
* 2. Alter 'BootOrder' to include this file in boot sequence.
*/
for (iFileSystem = 0; iFileSystem < cFileSystem; ++iFileSystem)
{
EFI_DEVICE_PATH_PROTOCOL *pDevicePath = NULL;
/* mount and look up the boot.efi */
rc = gBS->HandleProtocol (phFileSystem[iFileSystem],
&gEfiSimpleFileSystemProtocolGuid,
(VOID *) &pFSVolume);
VBoxLogFlowFuncMarkVar(iFileSystem, "%d");
VBoxLogFlowFuncMarkRC(rc);
if (EFI_ERROR(rc))
continue;
rc = pFSVolume->OpenVolume(pFSVolume, &hFSRoot);
VBoxLogFlowFuncMarkRC(rc);
if (EFI_ERROR(rc))
continue;
rc = hFSRoot->Open(hFSRoot, &hBootEfiFile, L"\\System\\Library\\CoreServices\\boot.efi", EFI_FILE_MODE_READ, 0);
VBoxLogFlowFuncMarkRC(rc);
if (EFI_ERROR(rc))
continue;
/* nice file is found and we have to register it */
pDevicePath = FileDevicePath(phFileSystem[iFileSystem], L"\\System\\Library\\CoreServices\\boot.efi");
VBoxLogFlowFuncMarkVar(pDevicePath,"%p");
if (!pDevicePath)
continue;
示例15: FileExist
BOOLEAN
FileExist (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CHAR16 *FileName
)
/*++
Routine Description:
Check whether a file exists.
--*/
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
//
// Check parameters
//
if ((DevicePath == NULL) || (FileName == NULL)) {
return FALSE;
}
//
// Locate the device handle
//
RemainingDevicePath = DevicePath;
Status = BS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&RemainingDevicePath,
&DeviceHandle
);
if (EFI_ERROR (Status)) {
return FALSE;
}
//
// Locate the simple file system
//
Status = BS->HandleProtocol (
DeviceHandle,
&gEfiSimpleFileSystemProtocolGuid,
&Vol
);
if (EFI_ERROR (Status)) {
return FALSE;
}
//
// Open the root directory
//
Status = Vol->OpenVolume (Vol, &RootDir);
if (EFI_ERROR (Status)) {
return FALSE;
}
//
// Open the file
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_READ,
0
);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return FALSE;
}
RootDir->Close (RootDir);
Handle->Close (Handle);
return TRUE;
}