本文整理汇总了C++中EFI_FILE_HANDLE::Close方法的典型用法代码示例。如果您正苦于以下问题:C++ EFI_FILE_HANDLE::Close方法的具体用法?C++ EFI_FILE_HANDLE::Close怎么用?C++ EFI_FILE_HANDLE::Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EFI_FILE_HANDLE
的用法示例。
在下文中一共展示了EFI_FILE_HANDLE::Close方法的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: LibGetFileHandleFromDevicePath
/**
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;
}
示例3: AllocateZeroPool
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;
}
示例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:
/**
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;
}
示例6: 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);
//.........这里部分代码省略.........
示例7: while
//.........这里部分代码省略.........
Status = BS->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;
}
//
// Determine the existence of the file
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ,
0
);
if (Status == EFI_NOT_FOUND) {
//
// The file not exist, create it
//
Status = SctCreateFile (RootDir, FileName, &Handle);
if (EFI_ERROR (Status)) {
RootDir->Close (RootDir);
return Status;
}
//
// Write the head of Unicode text file
//
Buffer[0] = 0xff;
Buffer[1] = 0xfe;
BufSize = 2;
Status = Handle->Write (Handle, &BufSize, Buffer);
if (EFI_ERROR (Status)) {
Handle->Close (Handle);
return Status;
}
} else if (EFI_ERROR (Status)) {
RootDir->Close(RootDir);
return Status;
}
if (OverwriteFile) {
//
// Overwrite the file
//
//
// Delete the file
//
Status = Handle->Delete (Handle);
//
// EFI_FILE.Delete() return a warning status
//
示例8: AsciiStrToUnicodeStr
/**
Internal work function to fill in EFI_OPEN_FILE information for the Fs and BlkIo
@param File Open file handle
@param FileName Name of file after device stripped off
**/
EFI_STATUS
EblFileDevicePath (
IN OUT EFI_OPEN_FILE *File,
IN CHAR8 *FileName,
IN CONST UINT64 OpenMode
)
{
EFI_STATUS Status;
UINTN Size;
FILEPATH_DEVICE_PATH *FilePath;
EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
CHAR16 UnicodeFileName[MAX_PATHNAME];
EFI_BLOCK_IO_PROTOCOL *BlkIo;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
EFI_FILE_HANDLE Root;
if ( *FileName != 0 ) {
AsciiStrToUnicodeStr (FileName, UnicodeFileName);
} else {
AsciiStrToUnicodeStr ("\\", UnicodeFileName);
}
Size = StrSize (UnicodeFileName);
FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + sizeof (EFI_DEVICE_PATH_PROTOCOL));
if (FileDevicePath != NULL) {
FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
FilePath->Header.Type = MEDIA_DEVICE_PATH;
FilePath->Header.SubType = MEDIA_FILEPATH_DP;
CopyMem (&FilePath->PathName, UnicodeFileName, Size);
SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
if (File->EfiHandle != NULL) {
File->DevicePath = DevicePathFromHandle (File->EfiHandle);
}
File->DevicePath = AppendDevicePath (File->DevicePath, FileDevicePath);
FreePool (FileDevicePath);
}
Status = gBS->HandleProtocol (File->EfiHandle, &gEfiBlockIoProtocolGuid, (VOID **)&BlkIo);
if (!EFI_ERROR (Status)) {
File->FsBlockIoMedia = BlkIo->Media;
File->FsBlockIo = BlkIo;
// If we are not opening the device this will get over written with file info
File->MaxPosition = MultU64x32 (BlkIo->Media->LastBlock + 1, BlkIo->Media->BlockSize);
}
if (File->Type == EfiOpenFileSystem) {
Status = gBS->HandleProtocol (File->EfiHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
if (!EFI_ERROR (Status)) {
Status = Fs->OpenVolume (Fs, &Root);
if (!EFI_ERROR (Status)) {
// Get information about the volume
Size = 0;
Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo);
if (Status == EFI_BUFFER_TOO_SMALL) {
File->FsInfo = AllocatePool (Size);
Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, File->FsInfo);
}
// Get information about the file
Status = Root->Open (Root, &File->FsFileHandle, UnicodeFileName, OpenMode, 0);
if (!EFI_ERROR (Status)) {
Size = 0;
Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, NULL);
if (Status == EFI_BUFFER_TOO_SMALL) {
File->FsFileInfo = AllocatePool (Size);
Status = File->FsFileHandle->GetInfo (File->FsFileHandle, &gEfiFileInfoGuid, &Size, File->FsFileInfo);
if (!EFI_ERROR (Status)) {
File->Size = (UINTN)File->FsFileInfo->FileSize;
File->MaxPosition = (UINT64)File->Size;
}
}
}
Root->Close (Root);
}
}
} else if (File->Type == EfiOpenBlockIo) {
File->Size = (UINTN)File->MaxPosition;
}
return Status;
}
示例9: FreePool
/**
Update Device List Global Variables
**/
VOID
EblUpdateDeviceLists (
VOID
)
{
EFI_STATUS Status;
UINTN Size;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
EFI_FILE_HANDLE Root;
UINTN Index;
if (mBlkIo != NULL) {
FreePool (mBlkIo);
}
gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &mBlkIoCount, &mBlkIo);
if (mFv != NULL) {
FreePool (mFv);
}
gBS->LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &mFvCount, &mFv);
if (mLoadFile != NULL) {
FreePool (mLoadFile);
}
gBS->LocateHandleBuffer (ByProtocol, &gEfiLoadFileProtocolGuid, NULL, &mLoadFileCount, &mLoadFile);
if (mFs != NULL) {
FreePool (mFs);
}
if (&mFsInfo[0] != NULL) {
// Need to Free the mFsInfo prior to recalculating mFsCount so don't move this code
for (Index = 0; Index < mFsCount; Index++) {
if (mFsInfo[Index] != NULL) {
FreePool (mFsInfo[Index]);
}
}
FreePool (mFsInfo);
}
gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &mFsCount, &mFs);
mFsInfo = AllocateZeroPool (mFsCount * sizeof (EFI_FILE_SYSTEM_INFO *));
if (mFsInfo == NULL) {
// If we can't do this then we can't support file system entries
mFsCount = 0;
} else {
// Loop through all the file system structures and cache the file system info data
for (Index =0; Index < mFsCount; Index++) {
Status = gBS->HandleProtocol (mFs[Index], &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
if (!EFI_ERROR (Status)) {
Status = Fs->OpenVolume (Fs, &Root);
if (!EFI_ERROR (Status)) {
// Get information about the volume
Size = 0;
Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]);
if (Status == EFI_BUFFER_TOO_SMALL) {
mFsInfo[Index] = AllocatePool (Size);
Status = Root->GetInfo (Root, &gEfiFileSystemInfoGuid, &Size, mFsInfo[Index]);
}
Root->Close (Root);
}
}
}
}
}
示例10: GetFloppyDevicePath
/**
* Write a file to floppy disk.
*/
EFI_STATUS
WriteFloppyFile (
IN CHAR16 *FileName,
IN OUT UINT32 Length,
IN VOID *Buffer
)
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINTN BufLen;
//
// 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;
}
//
// Determine the existence of the file
//
Status = RootDir->Open (
RootDir,
&Handle,
FileName,
EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
0
);
if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_FOUND)) {
RootDir->Close (RootDir);
return Status;
}
if (Status == EFI_SUCCESS) {
//
// Delete the existent file
//
Status = Handle->Delete (Handle);
if (Status != EFI_SUCCESS) {
Handle->Close (Handle);
RootDir->Close (RootDir);
return Status;
}
}
//
//.........这里部分代码省略.........
示例11: DuplicateDevicePath
//.........这里部分代码省略.........
&ImageBufferSize,
&Type,
&Attrib,
AuthenticationStatus
);
}
}
}
if (!EFI_ERROR (Status)) {
goto Finish;
}
}
//
// Attempt to access the file via a file system interface
//
DevicePathNode = OrigDevicePathNode;
Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &DevicePathNode, &Handle);
if (!EFI_ERROR (Status)) {
Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID**)&Volume);
if (!EFI_ERROR (Status)) {
//
// Open the Volume to get the File System handle
//
Status = Volume->OpenVolume (Volume, &FileHandle);
if (!EFI_ERROR (Status)) {
//
// 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
// nodes, It assures the fields in device path nodes are 2 byte aligned.
//
TempDevicePathNode = DuplicateDevicePath (DevicePathNode);
if (TempDevicePathNode == NULL) {
FileHandle->Close (FileHandle);
//
// Setting Status to an EFI_ERROR value will cause the rest of
// the file system support below to be skipped.
//
Status = EFI_OUT_OF_RESOURCES;
}
//
// 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
//
DevicePathNode = TempDevicePathNode;
while (!EFI_ERROR (Status) && !IsDevicePathEnd (DevicePathNode)) {
if (DevicePathType (DevicePathNode) != MEDIA_DEVICE_PATH ||
DevicePathSubType (DevicePathNode) != MEDIA_FILEPATH_DP) {
Status = EFI_UNSUPPORTED;
break;
}
LastHandle = FileHandle;
FileHandle = NULL;
Status = LastHandle->Open (
LastHandle,
&FileHandle,
((FILEPATH_DEVICE_PATH *) DevicePathNode)->PathName,
EFI_FILE_MODE_READ,
0
);
//
// Close the previous node
示例12: 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 (
//.........这里部分代码省略.........
示例13: 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;
}
}
示例14:
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;
}
示例15: ASSERT
EFI_STATUS
FileOpen (
IN EFI_DEVICE_PATH_PROTOCOL *Device,
IN CHAR16 *MappedFile,
OUT EFI_FILE_PROTOCOL **File,
IN UINT64 OpenMode
)
{
EFI_HANDLE Handle;
EFI_FILE_HANDLE Root;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_STATUS Status;
*File = NULL;
Status = gBS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&Device,
&Handle
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->HandleProtocol (
Handle,
&gEfiSimpleFileSystemProtocolGuid,
&Volume
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Open the root directory of the volume
//
Root = NULL;
Status = Volume->OpenVolume (
Volume,
&Root
);
ASSERT_EFI_ERROR (Status);
ASSERT (Root != NULL);
//
// Open file
//
Status = Root->Open (
Root,
File,
MappedFile,
OpenMode,
0
);
if (EFI_ERROR (Status)) {
*File = NULL;
}
//
// Close the Root directory
//
Root->Close (Root);
return Status;
}