本文整理汇总了C++中EFI_FILE_HANDLE::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ EFI_FILE_HANDLE::Read方法的具体用法?C++ EFI_FILE_HANDLE::Read怎么用?C++ EFI_FILE_HANDLE::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EFI_FILE_HANDLE
的用法示例。
在下文中一共展示了EFI_FILE_HANDLE::Read方法的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: 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;
}
示例3: sizeof
/**
Read a file from this volume.
@param[in] Vol File System Volume
@param[in] FileName The file to be read.
@param[out] BufferSize The file buffer size
@param[out] Buffer The file buffer
@retval EFI_SUCCESS Read file successfully
@retval EFI_NOT_FOUND File not found
**/
EFI_STATUS
ReadFileFromVol (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol,
IN CHAR16 *FileName,
OUT UINTN *BufferSize,
OUT VOID **Buffer
)
{
EFI_STATUS Status;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
UINTN FileInfoSize;
EFI_FILE_INFO *FileInfo;
UINTN TempBufferSize;
VOID *TempBuffer;
//
// 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,
0
);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return Status;
}
RootDir->Close (RootDir);
//
// Get the file information
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
FileInfo = AllocateZeroPool (FileInfoSize);
if (FileInfo == NULL) {
Handle->Close (Handle);
return Status;
}
Status = Handle->GetInfo (
Handle,
&gEfiFileInfoGuid,
&FileInfoSize,
FileInfo
);
if (EFI_ERROR (Status)) {
Handle->Close (Handle);
gBS->FreePool (FileInfo);
return Status;
}
//
// Allocate buffer for the file data. The last CHAR16 is for L'\0'
//
TempBufferSize = (UINTN) FileInfo->FileSize + sizeof(CHAR16);
TempBuffer = AllocateZeroPool (TempBufferSize);
if (TempBuffer == NULL) {
Handle->Close (Handle);
gBS->FreePool (FileInfo);
return Status;
}
gBS->FreePool (FileInfo);
//
// Read the file data to the buffer
//
Status = Handle->Read (
Handle,
&TempBufferSize,
TempBuffer
);
if (EFI_ERROR (Status)) {
Handle->Close (Handle);
gBS->FreePool (TempBuffer);
return Status;
//.........这里部分代码省略.........
示例4:
EFI_STATUS
EFIAPI
TrlReadResetRecord (
IN EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *This,
OUT UINTN *Size,
OUT VOID *Buffer
)
/*++
Routine Description:
One interface function of the TestRecoveryLibrary to read reset record.
Arguments:
This - the protocol instance structure.
Size - return the bytes been read.
Buffer - buffer to store the record, it can't less than 1024Bytes.
Returns:
EFI_SUCCESS - read the record successfully.
EFI_INVALID_PARAMETER - invalid parameters.
--*/
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
TEST_RECOVERY_PRIVATE_DATA *Private;
EFI_DEVICE_PATH_PROTOCOL *PreDevicePath;
Private = TEST_RECOVERY_PRIVATE_DATA_FROM_TRL (This);
//
// Determine device handle for fs protocol on specified device path
//
PreDevicePath = Private->DevicePath;
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&PreDevicePath,
&DeviceHandle
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Determine volume for file system on device handle
//
Status = gBS->HandleProtocol (
DeviceHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID*)&Vol
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open volume for file system on device path
//
Status = Vol->OpenVolume (Vol, &RootDir);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open file for read
//
Status = RootDir->Open (
RootDir,
&Handle,
Private->FileName,
EFI_FILE_MODE_READ,
0
);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return Status;
}
*Size = MAX_BUFFER_SIZE;
Status = Handle->Read (Handle, Size, Buffer);
Handle->Close (Handle);
RootDir->Close (RootDir);
return Status;
}
示例5: if
//.........这里部分代码省略.........
// get EFI_FILE_INFO for bootmgfw.efi //
//=========================================================================//
Status = FileHandle->GetInfo(FileHandle, &gFileInfo, &Size, FileInfoBuffer);
if(EFI_ERROR(Status)) {
FileHandle->Close(FileHandle);
RootFs->Close(RootFs);
return Status;
}
//=========================================================================//
// get size of bootmgfw.efi //
//=========================================================================//
Size = FileInfoBuffer->FileSize;
//=========================================================================//
// free EFI_FILE_INFO buffer //
//=========================================================================//
BS->FreePool(FileInfoBuffer);
//=========================================================================//
// allocate memory for bootmgfw.efi //
//=========================================================================//
BootmgrBuffer = AllocatePool(Size);
if (!BootmgrBuffer) {
BS->FreePool(BootmgrBuffer);
FileHandle->Close(FileHandle);
RootFs->Close(RootFs);
return Status;
}
//=========================================================================//
// read bootmgfw.efi into buffer //
//=========================================================================//
Status = FileHandle->Read(FileHandle, &Size, BootmgrBuffer);
if (EFI_ERROR (Status)) {
BS->FreePool(BootmgrBuffer);
FileHandle->Close(FileHandle);
RootFs->Close(RootFs);
return Status;
}
//=========================================================================//
// close handle for bootmgfw.efi //
//=========================================================================//
Status = FileHandle->Close(FileHandle);
if (EFI_ERROR (Status)) {
}
//=========================================================================//
// close handle for file system root //
//=========================================================================//
Status = RootFs->Close(RootFs);
if (EFI_ERROR (Status)) {
}
//=========================================================================//
// load bootmgfw.efi from buffer to execution space //
//=========================================================================//
Status = BS->LoadImage(FALSE, ImageHandle, 0, BootmgrBuffer, Size, &BootmgrHandle);
if (EFI_ERROR (Status)) {
BS->FreePool(BootmgrBuffer);
return Status;
}
BS->FreePool(BootmgrBuffer);
//=========================================================================//
// set bootmgfw.efi start variables //
//=========================================================================//
Status = BS->HandleProtocol(BootmgrHandle, &gLoadedImageProtocol, (VOID **) &BootmgrLoadedImage);
if (EFI_ERROR (Status)) {
return Status;
}
BootmgrLoadedImage->DeviceHandle = DeviceHandle;
BootmgrLoadedImage->ParentHandle = NULL;
BootmgrLoadedImage->FilePath = FileDevicePath(DeviceHandle, BOOTMGFW);
//=========================================================================//
// start bootmgfw.efi execution //
//=========================================================================//
Status = BS->StartImage(BootmgrHandle, 0, 0);
//============================================================================//
// should never get here show error //
//============================================================================//
if (BootmgrHandle != NULL) {
Status = BS->UnloadImage(BootmgrHandle);
}
return Status;
}
示例6: sizeof
EFI_STATUS
ReadFileFromVol (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol,
IN CHAR16 *FileName,
OUT UINTN *BufferSize,
OUT VOID **Buffer
)
/*++
Routine Description:
Read a file.
Arguments:
Vol - File System Volume
FileName - The file to be read.
BufferSize - The file buffer size
Buffer - The file buffer
Returns:
EFI_SUCCESS - read file successfully
EFI_NOT_FOUND - file not found
--*/
{
EFI_STATUS Status;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
UINTN FileInfoSize;
EFI_FILE_INFO *FileInfo;
UINTN TempBufferSize;
VOID *TempBuffer;
//
// 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,
0
);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return Status;
}
RootDir->Close (RootDir);
//
// Get the file information
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
FileInfo = EfiLibAllocateZeroPool (FileInfoSize);
if (FileInfo == NULL) {
Handle->Close (Handle);
return Status;
}
Status = Handle->GetInfo (
Handle,
&gEfiFileInfoGuid,
&FileInfoSize,
FileInfo
);
if (EFI_ERROR (Status)) {
Handle->Close (Handle);
gBS->FreePool (FileInfo);
return Status;
}
//
// Allocate buffer for the file data. The last CHAR16 is for L'\0'
//
TempBufferSize = (UINTN) FileInfo->FileSize + sizeof(CHAR16);
TempBuffer = EfiLibAllocateZeroPool (TempBufferSize);
if (TempBuffer == NULL) {
Handle->Close (Handle);
gBS->FreePool (FileInfo);
return Status;
}
gBS->FreePool (FileInfo);
//
// Read the file data to the buffer
//
Status = Handle->Read (
//.........这里部分代码省略.........
示例7: sizeof
//.........这里部分代码省略.........
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open directory - %r", Status));
RootDir->Close (RootDir);
return Status;
}
RootDir->Close (RootDir);
//
// Allocate memory for the entries in the directory
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
Status = BS->AllocatePool (
EfiBootServicesData,
FileInfoSize,
&FileInfo
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status));
LogDir->Close (LogDir);
return Status;
}
//
// Walk through each file in the directory
//
while (TRUE) {
//
// Read a file entry
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
Status = LogDir->Read (
LogDir,
&FileInfoSize,
FileInfo
);
if (EFI_ERROR (Status) || (FileInfoSize == 0)) {
break;
}
if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
//
// This is a file
//
//
// Only deal with the EFI key file
//
if (!SctStrEndWith (FileInfo->FileName, L".ekl")) {
continue;
}
//
// Read the file to a buffer
//
FileName = PoolPrint (L"%s\\%s", FilePath, FileInfo->FileName);
if (FileName == NULL) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources"));
return EFI_OUT_OF_RESOURCES;
}
Status = ReadFileToBuffer (
DevicePath,
FileName,
示例8: sizeof
BOOLEAN
BOpt_IsEfiApp (
IN EFI_FILE_HANDLE Dir,
IN UINT16 *FileName
)
/*++
Routine Description:
Check whether current FileName point to a valid Efi Application
Arguments:
Dir - Pointer to current Directory
FileName - Pointer to current File name.
Returns:
TRUE - Is a valid Efi Application
FALSE - not a valid Efi Application
--*/
{
UINTN BufferSize;
EFI_IMAGE_DOS_HEADER DosHdr;
EFI_IMAGE_NT_HEADERS PeHdr;
EFI_IMAGE_OPTIONAL_HEADER32 *PeOpt32;
EFI_IMAGE_OPTIONAL_HEADER64 *PeOpt64;
UINT16 Subsystem;
EFI_FILE_HANDLE File;
EFI_STATUS Status;
Status = Dir->Open (Dir, &File, FileName, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
return FALSE;
}
BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
File->Read (File, &BufferSize, &DosHdr);
if (DosHdr.e_magic != EFI_IMAGE_DOS_SIGNATURE) {
File->Close (File);
return FALSE;
}
File->SetPosition (File, DosHdr.e_lfanew);
BufferSize = sizeof (EFI_IMAGE_NT_HEADERS);
File->Read (File, &BufferSize, &PeHdr);
if (PeHdr.Signature != EFI_IMAGE_NT_SIGNATURE) {
File->Close (File);
return FALSE;
}
//
// Determine PE type and read subsytem
// BugBug : We should be using EFI_IMAGE_MACHINE_TYPE_SUPPORTED (machine)
// macro to detect the machine type.
// We should not be using EFI_IMAGE_OPTIONAL_HEADER32 and
// EFI_IMAGE_OPTIONAL_HEADER64
//
if (PeHdr.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
PeOpt32 = (EFI_IMAGE_OPTIONAL_HEADER32 *) &(PeHdr.OptionalHeader);
Subsystem = PeOpt32->Subsystem;
} else if (PeHdr.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
PeOpt64 = (EFI_IMAGE_OPTIONAL_HEADER64 *) &(PeHdr.OptionalHeader);
Subsystem = PeOpt64->Subsystem;
} else {
return FALSE;
}
if (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
File->Close (File);
return TRUE;
} else {
File->Close (File);
return FALSE;
}
}
示例9: EfiLibFileInfo
EFI_STATUS
BOpt_FindFiles (
IN BMM_CALLBACK_DATA *CallbackData,
IN BM_MENU_ENTRY *MenuEntry
)
/*++
Routine Description
Find files under current directory
All files and sub-directories in current directory
will be stored in DirectoryMenu for future use.
Arguments:
FileOption -- Pointer for Dir to explore
Returns:
TRUE -- Get files from current dir successfully
FALSE -- Can't get files from current dir
--*/
{
EFI_FILE_HANDLE NewDir;
EFI_FILE_HANDLE Dir;
EFI_FILE_INFO *DirInfo;
UINTN BufferSize;
UINTN DirBufferSize;
BM_MENU_ENTRY *NewMenuEntry;
BM_FILE_CONTEXT *FileContext;
BM_FILE_CONTEXT *NewFileContext;
UINTN Pass;
EFI_STATUS Status;
UINTN OptionNumber;
FileContext = (BM_FILE_CONTEXT *) MenuEntry->VariableContext;
Dir = FileContext->FHandle;
OptionNumber = 0;
//
// Open current directory to get files from it
//
Status = Dir->Open (
Dir,
&NewDir,
FileContext->FileName,
EFI_FILE_READ_ONLY,
0
);
if (!FileContext->IsRoot) {
Dir->Close (Dir);
}
if (EFI_ERROR (Status)) {
return Status;
}
DirInfo = EfiLibFileInfo (NewDir);
if (!DirInfo) {
return EFI_NOT_FOUND;
}
if (!(DirInfo->Attribute & EFI_FILE_DIRECTORY)) {
return EFI_INVALID_PARAMETER;
}
FileContext->DevicePath = EfiFileDevicePath (
FileContext->Handle,
FileContext->FileName
);
DirBufferSize = sizeof (EFI_FILE_INFO) + 1024;
DirInfo = EfiAllocateZeroPool (DirBufferSize);
if (!DirInfo) {
return EFI_OUT_OF_RESOURCES;
}
//
// Get all files in current directory
// Pass 1 to get Directories
// Pass 2 to get files that are EFI images
//
for (Pass = 1; Pass <= 2; Pass++) {
NewDir->SetPosition (NewDir, 0);
for (;;) {
BufferSize = DirBufferSize;
Status = NewDir->Read (NewDir, &BufferSize, DirInfo);
if (EFI_ERROR (Status) || BufferSize == 0) {
break;
}
if ((DirInfo->Attribute & EFI_FILE_DIRECTORY && Pass == 2) ||
(!(DirInfo->Attribute & EFI_FILE_DIRECTORY) && Pass == 1)
) {
//
// Pass 1 is for Directories
// Pass 2 is for file names
//
continue;
}
if (!(BOpt_IsEfiImageName (DirInfo->FileName) || DirInfo->Attribute & EFI_FILE_DIRECTORY)) {
//
// Slip file unless it is a directory entry or a .EFI file
//.........这里部分代码省略.........
示例10: GetFloppyDevicePath
/**
* Read a file from floppy disk.
*/
EFI_STATUS
ReadFloppyFile (
IN CHAR16 *FileName,
OUT UINT32 *Length,
OUT VOID **Buffer
)
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
EFI_FILE_INFO *FileInfo;
UINTN FileInfoSize;
VOID* FileBuffer;
UINTN FileSize;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
//
// Get floppy device path
//
Status = GetFloppyDevicePath (&DevicePath);
if (EFI_ERROR(Status)) {
return Status;
}
//
// Determine device handle for fs protocol on floppy device path
//
Status = gtBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&DevicePath,
&DeviceHandle
);
if (EFI_ERROR(Status) ) {
return Status;
}
//
// Determine volume for file system on device handle
//
Status = gtBS->HandleProtocol (
DeviceHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID*)&Vol
);
if (EFI_ERROR(Status) ) {
return Status;
}
//
// Open volume for file system on device path
//
Status = Vol->OpenVolume (Vol, &RootDir);
if (Status == EFI_MEDIA_CHANGED) {
//
// Reopen the volume
//
Status = gtBS->HandleProtocol (
DeviceHandle,
&gEfiSimpleFileSystemProtocolGuid,
(VOID*)&Vol
);
if (EFI_ERROR(Status) ) {
return Status;
}
Status = Vol->OpenVolume (Vol, &RootDir);
}
if (EFI_ERROR(Status) ) {
return Status;
}
//
// Open file for read
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_READ,
0
);
if (EFI_ERROR(Status) ) {
RootDir->Close (RootDir);
return Status;
}
//
// Get file size
//
FileInfoSize = 1;
Status = gtBS->AllocatePool (
EfiBootServicesData,
FileInfoSize,
&FileInfo
);
//.........这里部分代码省略.........
示例11: FileInfo
/**
Find files under the current directory. All files and sub-directories
in current directory will be stored in DirectoryMenu for future use.
@param[in] MenuEntry The Menu Entry.
@retval EFI_SUCCESS Get files from current dir successfully.
@return Other Can't get files from current dir.
**/
EFI_STATUS
FindFiles (
IN SECUREBOOT_MENU_ENTRY *MenuEntry
)
{
EFI_FILE_HANDLE NewDir;
EFI_FILE_HANDLE Dir;
EFI_FILE_INFO *DirInfo;
UINTN BufferSize;
UINTN DirBufferSize;
SECUREBOOT_MENU_ENTRY *NewMenuEntry;
SECUREBOOT_FILE_CONTEXT *FileContext;
SECUREBOOT_FILE_CONTEXT *NewFileContext;
UINTN Pass;
EFI_STATUS Status;
UINTN OptionNumber;
FileContext = (SECUREBOOT_FILE_CONTEXT *) MenuEntry->FileContext;
Dir = FileContext->FHandle;
OptionNumber = 0;
//
// Open current directory to get files from it
//
Status = Dir->Open (
Dir,
&NewDir,
FileContext->FileName,
EFI_FILE_READ_ONLY,
0
);
if (!FileContext->IsRoot) {
Dir->Close (Dir);
}
if (EFI_ERROR (Status)) {
return Status;
}
DirInfo = FileInfo (NewDir);
if (DirInfo == NULL) {
return EFI_NOT_FOUND;
}
if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
return EFI_INVALID_PARAMETER;
}
FileContext->DevicePath = FileDevicePath (
FileContext->Handle,
FileContext->FileName
);
DirBufferSize = sizeof (EFI_FILE_INFO) + 1024;
DirInfo = AllocateZeroPool (DirBufferSize);
if (DirInfo == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Get all files in current directory
// Pass 1 to get Directories
// Pass 2 to get files that are EFI images
//
for (Pass = 1; Pass <= 2; Pass++) {
NewDir->SetPosition (NewDir, 0);
for (;;) {
BufferSize = DirBufferSize;
Status = NewDir->Read (NewDir, &BufferSize, DirInfo);
if (EFI_ERROR (Status) || BufferSize == 0) {
break;
}
if (((DirInfo->Attribute & EFI_FILE_DIRECTORY) != 0 && Pass == 2) ||
((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0 && Pass == 1)
) {
//
// Pass 1 is for Directories
// Pass 2 is for file names
//
continue;
}
NewMenuEntry = CreateMenuEntry ();
if (NULL == NewMenuEntry) {
return EFI_OUT_OF_RESOURCES;
}
NewFileContext = (SECUREBOOT_FILE_CONTEXT *) NewMenuEntry->FileContext;
NewFileContext->Handle = FileContext->Handle;
NewFileContext->FileName = AppendFileName (
//.........这里部分代码省略.........
示例12: GetTestSupportLibrary
//.........这里部分代码省略.........
);
if (EFI_ERROR(Status)) {
continue;
}
//
//read the Compressed file into memory.
//
Status = OpenFileAndGetSize (
FileName,
&CompressedFHandle,
&CompressedFileSize
);
if (EFI_ERROR(Status)) {
Print (L"Can not open the File :%s\r\n", FileName);
gtBS->FreePool (FileName);
continue;
}
gtBS->FreePool (FileName);
Buffer = AllocatePool (CompressedFileSize);
if (Buffer == NULL) {
CompressedFHandle->Close (CompressedFHandle);
Print (L"Can not allocate %xh buffer.\r\n", CompressedFileSize);
continue;
}
BufferSize = CompressedFileSize;
Status = CompressedFHandle->Read (
CompressedFHandle,
&BufferSize,
Buffer
);
if (EFI_ERROR(Status)) {
CompressedFHandle->Close (CompressedFHandle);
Print (L"File Read Error Status %r\r\n", Status);
gtBS->FreePool (Buffer);
continue;
}
//
//now verify the check points.
//
Status = Decompress->GetInfo (
Decompress,
Buffer,
CompressedFileSize,
&DestinationSize,
&ScratchSize
);
if (Status == EFI_SUCCESS) {
AssertionType = EFI_TEST_ASSERTION_PASSED;
} else {
AssertionType = EFI_TEST_ASSERTION_FAILED;
}
//
//record assertion
//
StandardLib->RecordAssertion (
示例13: sizeof
EFI_STATUS
ReadFileToBuffer (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CHAR16 *FileName,
OUT UINTN *BufferSize,
OUT VOID **Buffer
)
/*++
Routine Description:
Read a file.
--*/
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
UINTN FileInfoSize;
EFI_FILE_INFO *FileInfo;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
UINTN TempBufferSize;
VOID *TempBuffer;
//
// Check parameters
//
if ((DevicePath == NULL) || (FileName == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
//
// Locate the device handle
//
RemainingDevicePath = DevicePath;
Status = BS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&RemainingDevicePath,
&DeviceHandle
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate device path - %r", Status));
return Status;
}
//
// Locate the simple file system
//
Status = BS->HandleProtocol (
DeviceHandle,
&gEfiSimpleFileSystemProtocolGuid,
&Vol
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Handle protocol - %r", Status));
return Status;
}
//
// Open the root directory
//
Status = Vol->OpenVolume (Vol, &RootDir);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open volume - %r", Status));
return Status;
}
//
// Open the file
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_READ,
0
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open file - %r", Status));
RootDir->Close (RootDir);
return Status;
}
RootDir->Close (RootDir);
//
// Get the file information
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
Status = BS->AllocatePool (
EfiBootServicesData,
FileInfoSize,
&FileInfo
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status));
Handle->Close (Handle);
//.........这里部分代码省略.........
示例14: sizeof
//.........这里部分代码省略.........
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open support directory - %r", Status));
RootDir->Close (RootDir);
return Status;
}
RootDir->Close (RootDir);
//
// Allocate memory for the entries in the directory
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
Status = BS->AllocatePool (
EfiBootServicesData,
FileInfoSize,
&FileInfo
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status));
SupportDir->Close (SupportDir);
return Status;
}
//
// Walk through each file in the directory
//
while (TRUE) {
//
// Read a file entry
//
FileInfoSize = sizeof(EFI_FILE_INFO) + 1024;
Status = SupportDir->Read (
SupportDir,
&FileInfoSize,
FileInfo
);
if (EFI_ERROR (Status) || (FileInfoSize == 0)) {
break;
}
if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
//
// This is a file
//
if (SctStrEndWith (FileInfo->FileName, L".efi")) {
//
// Load the support file
//
FileName = PoolPrint (L"%s\\%s", FilePath, FileInfo->FileName);
if (FileName == NULL) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources"));
break;
}
Status = LoadSingleSupportFile (
DevicePath,
FileName,
&SupportFile
);
if (EFI_ERROR (Status)) {
EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Load a support file - %r", Status));
BS->FreePool (FileName);
continue;
}
示例15: 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;
}
//.........这里部分代码省略.........