本文整理汇总了C++中EFI_FILE_HANDLE::Open方法的典型用法代码示例。如果您正苦于以下问题:C++ EFI_FILE_HANDLE::Open方法的具体用法?C++ EFI_FILE_HANDLE::Open怎么用?C++ EFI_FILE_HANDLE::Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EFI_FILE_HANDLE
的用法示例。
在下文中一共展示了EFI_FILE_HANDLE::Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2:
/**
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;
}
示例3:
/**
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;
}
示例4: GetMyVol
/**
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;
}
示例5: sizeof
EFI_STATUS
GetProtocolAssertion (
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CHAR16 *FilePath,
OUT UINT32 *PassNumber,
OUT UINT32 *WarnNumber,
OUT UINT32 *FailNumber
)
/*++
Routine Description:
Get the assertion number of a protocol or service.
Arguments:
DevicePath - Device path of the key files.
FilePath - Path of the key files.
PassNumber - The number of passed assertions.
WarnNumber - The number of warning assertions.
FailNumber - The number of failed assertions.
Returns:
EFI_SUCCESS - Get instance assertion number successfully.
--*/
{
EFI_STATUS Status;
EFI_HANDLE DeviceHandle;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE LogDir;
UINTN FileInfoSize;
EFI_FILE_INFO *FileInfo;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
UINTN BufferSize;
CHAR16 *Buffer;
CHAR16 *FileName;
CHAR16 *LogName;
CHAR16 *TempName;
CHAR16 *CaseIndexStr;
CHAR16 *CaseIterationStr;
//
// Check parameters
//
if ((DevicePath == NULL) || (FilePath == NULL) ||
(PassNumber == NULL) || (WarnNumber == NULL) ||
(FailNumber == 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 log directory
//
Status = RootDir->Open (
RootDir,
&LogDir,
FilePath,
EFI_FILE_MODE_READ,
EFI_FILE_DIRECTORY
);
if (EFI_ERROR (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: ProcessCapsules
//.........这里部分代码省略.........
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;
rc = BdsLibRegisterNewOption (BootOptionList, pDevicePath, L"Mac Boot", L"BootOrder");
VBoxLogFlowFuncMarkRC(rc);
}
}
}
else
{
VBoxLogFlowFuncMarkVar(BootOption0080->LoadOptionsSize, "%d");
if (BootOption0080->LoadOptionsSize)
VBoxLogFlowFuncMarkVar(BootOption0080->LoadOptions, "%s");
#if 0
/* Boot0080 option is found */
UINT16 *BootOrder;
UINTN BootOrderSize;
UINTN Index = 0;
CHAR16 *BootOptionName;
ASSERT(BootOption0080->Signature == BDS_LOAD_OPTION_SIGNATURE);
BootOrder = BdsLibGetVariableAndSize (
L"BootOrder",
示例8: 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);
//.........这里部分代码省略.........
示例9: DuplicateDevicePath
//.........这里部分代码省略.........
if (ImageBuffer != NULL) {
FreePool (ImageBuffer);
*AuthenticationStatus = 0;
}
ImageBuffer = NULL;
Status = FwVol->ReadFile (
FwVol,
FvNameGuid,
(VOID **)&ImageBuffer,
&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 (
示例10: sizeof
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: 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
//.........这里部分代码省略.........
示例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: 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;
}
}
//
//.........这里部分代码省略.........
示例14: 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;
}
示例15: while
EFI_STATUS
EFIAPI
TOLOpen (
IN EFI_TEST_OUTPUT_LIBRARY_PROTOCOL *This,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN CHAR16 *FileName,
IN BOOLEAN OverwriteFile,
OUT EFI_FILE **FileHandle
)
/*++
Routine Description:
One interface function of the TestOutputLibrary to open a file.
Arguments:
This - the protocol instance structure.
DevicePath - the file's root device path.
FileName - the file's name relative to the root.
OverwriteFile - whether to overwrite the file.
FileHandle - return the file's handle.
Returns:
EFI_SUCCESS - open the file successfully.
EFI_NOT_READY - to overwrite an opened file is not allowed.
EFI_OUT_OF_RESOURCES - not enough memory.
--*/
{
EFI_STATUS Status;
TEST_OUTPUT_FILE *OutputFile;
TEST_OUTPUT_PRIVATE_DATA *Private;
EFI_HANDLE DeviceHandle;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol;
EFI_FILE_HANDLE RootDir;
EFI_FILE_HANDLE Handle;
UINTN BufSize;
CHAR8 Buffer[2];
EFI_DEVICE_PATH_PROTOCOL *PreDevicePath;
Private = TEST_OUTPUT_PRIVATE_DATA_FROM_THIS (This);
//
// Search the file in OutputFileList to see whether the file has been opened
//
OutputFile = Private->OutputFileList;
while (OutputFile != NULL) {
if ((SctDevicePathCompare (DevicePath, OutputFile->DevicePath) == 0) &&
(StrCmp (FileName, OutputFile->FileName) == 0)) {
break;
}
OutputFile = OutputFile->Next;
}
if (OutputFile == NULL) {
//
// Not found, open the file and add to the list
//
PreDevicePath = DevicePath;
//
// Determine device handle for fs protocol on specified device path
//
Status = BS->LocateDevicePath (
&gEfiSimpleFileSystemProtocolGuid,
&PreDevicePath,
&DeviceHandle
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Determine volume for file system on device handle
//
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,
//.........这里部分代码省略.........