fwvolread.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 518 行 · 第 1/2 页
C
518 行
Buffer. On output, *BufferSize contains the number
of bytes required to read the file.
FoundType - FoundType is a pointer to a caller allocated
EFI_FV_FILETYPE that on successful return from Read()
contains the type of file read. This output reflects
the file type irrespective of the value of the
SectionType input.
FileAttributes - FileAttributes is a pointer to a caller allocated
EFI_FV_FILE_ATTRIBUTES. On successful return from
Read(), *FileAttributes contains the attributes of
the file read.
AuthenticationStatus - AuthenticationStatus is a pointer to a caller
allocated UINTN in which the authentication status
is returned.
Returns:
EFI_SUCCESS - Successfully read to memory buffer.
EFI_WARN_BUFFER_TOO_SMALL - Buffer too small.
EFI_NOT_FOUND - Not found.
EFI_DEVICE_ERROR - Device error.
EFI_ACCESS_DENIED - Could not read.
EFI_INVALID_PARAMETER - Invalid parameter.
EFI_OUT_OF_RESOURCES - Not enough buffer to be allocated.
--*/
{
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_GUID SearchNameGuid;
EFI_FV_FILETYPE LocalFoundType;
EFI_FV_FILE_ATTRIBUTES LocalAttributes;
UINTN FileSize;
UINT8 *SrcPtr;
EFI_FFS_FILE_HEADER *FfsHeader;
UINTN InputBufferSize;
if (NULL == NameGuid) {
return EFI_INVALID_PARAMETER;
}
FvDevice = FV_DEVICE_FROM_THIS (This);
//
// Keep looking until we find the matching NameGuid.
// The Key is really an FfsFileEntry
//
FvDevice->LastKey = 0;
do {
LocalFoundType = 0;
Status = FvGetNextFile (
This,
&FvDevice->LastKey,
&LocalFoundType,
&SearchNameGuid,
&LocalAttributes,
&FileSize
);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}
} while (!EfiCompareGuid (&SearchNameGuid, NameGuid));
//
// Get a pointer to the header
//
FfsHeader = FvDevice->LastKey->FfsHeader;
//
// Remember callers buffer size
//
InputBufferSize = *BufferSize;
//
// Calculate return values
//
*FoundType = FfsHeader->Type;
*FileAttributes = FfsAttributes2FvFileAttributes (FfsHeader->Attributes);
*AuthenticationStatus = 0;
*BufferSize = FileSize;
if (Buffer == NULL) {
//
// If Buffer is NULL, we only want to get the information colected so far
//
return EFI_SUCCESS;
}
//
// Skip over file header
//
SrcPtr = ((UINT8 *)FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);
Status = EFI_SUCCESS;
if (*Buffer == NULL) {
//
// Caller passed in a pointer so allocate buffer for them
//
*Buffer = CoreAllocateBootServicesPool (FileSize);
if (*Buffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else if (FileSize > InputBufferSize) {
//
// Callers buffer was not big enough
//
Status = EFI_WARN_BUFFER_TOO_SMALL;
FileSize = InputBufferSize;
}
//
// Copy data into callers buffer
//
EfiCommonLibCopyMem (*Buffer, SrcPtr, FileSize);
return Status;
}
EFI_STATUS
EFIAPI
FvReadFileSection (
IN EFI_FIRMWARE_VOLUME_PROTOCOL *This,
IN EFI_GUID *NameGuid,
IN EFI_SECTION_TYPE SectionType,
IN UINTN SectionInstance,
IN OUT VOID **Buffer,
IN OUT UINTN *BufferSize,
OUT UINT32 *AuthenticationStatus
)
/*++
Routine Description:
Locates a section in a given FFS File and
copies it to the supplied buffer (not including section header).
Arguments:
This - Indicates the calling context.
NameGuid - Pointer to an EFI_GUID, which is the filename.
SectionType - Indicates the section type to return.
SectionInstance - Indicates which instance of sections with a type of
SectionType to return.
Buffer - Buffer is a pointer to pointer to a buffer in which
the file or section contents or are returned.
BufferSize - BufferSize is a pointer to caller allocated UINTN.
AuthenticationStatus -AuthenticationStatus is a pointer to a caller
allocated UINT32 in which the authentication status
is returned.
Returns:
EFI_SUCCESS - Successfully read the file section into buffer.
EFI_WARN_BUFFER_TOO_SMALL - Buffer too small.
EFI_NOT_FOUND - Section not found.
EFI_DEVICE_ERROR - Device error.
EFI_ACCESS_DENIED - Could not read.
EFI_INVALID_PARAMETER - Invalid parameter.
--*/
{
EFI_STATUS Status;
FV_DEVICE *FvDevice;
EFI_FV_FILETYPE FileType;
EFI_FV_FILE_ATTRIBUTES FileAttributes;
UINTN FileSize;
UINT8 *FileBuffer;
EFI_SECTION_EXTRACTION_PROTOCOL *Sep;
FFS_FILE_LIST_ENTRY *FfsEntry;
if (NULL == NameGuid || Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
FvDevice = FV_DEVICE_FROM_THIS (This);
//
// Read the whole file into buffer
//
FileBuffer = NULL;
Status = FvReadFile (
This,
NameGuid,
&FileBuffer,
&FileSize,
&FileType,
&FileAttributes,
AuthenticationStatus
);
//
// Get the last key used by our call to FvReadFile as it is the FfsEntry for this file.
//
FfsEntry = (FFS_FILE_LIST_ENTRY *)FvDevice->LastKey;
if (EFI_ERROR (Status)) {
return Status;
}
//
// Check to see that the file actually HAS sections before we go any further.
//
if (FileType == EFI_FV_FILETYPE_RAW) {
Status = EFI_NOT_FOUND;
goto Done;
}
//
// Use FfsEntry to cache Section Extraction Protocol Inforomation
//
if (FfsEntry->StreamHandle == 0) {
//
// Located the protocol
//
Status = CoreLocateProtocol (&gEfiSectionExtractionProtocolGuid, NULL, &Sep);
//
// Section Extraction Protocol is part of Dxe Core so this should never fail
//
ASSERT_EFI_ERROR (Status);
Status = Sep->OpenSectionStream (
Sep,
FileSize,
FileBuffer,
&FfsEntry->StreamHandle
);
if (EFI_ERROR (Status)) {
goto Done;
}
FfsEntry->Sep = Sep;
} else {
//
// Get cached copy of Sep
//
Sep = FfsEntry->Sep;
}
//
// If SectionType == 0 We need the whole section stream
//
Status = Sep->GetSection (
Sep,
FfsEntry->StreamHandle,
(SectionType == 0) ? NULL : &SectionType,
NULL,
(SectionType == 0) ? 0 : SectionInstance,
Buffer,
BufferSize,
AuthenticationStatus
);
//
// Close of stream defered to close of FfsHeader list to allow SEP to cache data
//
Done:
CoreFreePool (FileBuffer);
return Status;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?