mirror of
https://github.com/acidanthera/OpenCorePkg.git
synced 2025-12-08 19:25:01 +00:00
OcFileLib: Implement AllocateCopyFileData
This commit is contained in:
parent
0a16c8a126
commit
b2e55152ea
@ -186,6 +186,22 @@ SetFileData (
|
||||
IN UINT32 Size
|
||||
);
|
||||
|
||||
/**
|
||||
Read all bytes from EFI_FILE_PROTOCOL and return a buffer.
|
||||
|
||||
@param[in] File A pointer to the file protocol.
|
||||
@param[out] Buffer A pointer for the returned buffer.
|
||||
@param[out] BufferSize A pointer for the size of the returned buffer.
|
||||
|
||||
@retval EFI_SUCCESS on success.
|
||||
**/
|
||||
EFI_STATUS
|
||||
AllocateCopyFileData (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
OUT UINT8 **Buffer,
|
||||
OUT UINT32 *BufferSize
|
||||
);
|
||||
|
||||
/**
|
||||
Get file information of specified type.
|
||||
|
||||
|
||||
@ -246,3 +246,37 @@ SetFileData (
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
AllocateCopyFileData (
|
||||
IN EFI_FILE_PROTOCOL *File,
|
||||
OUT UINT8 **Buffer,
|
||||
OUT UINT32 *BufferSize
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT8 *FileBuffer;
|
||||
UINT32 ReadSize;
|
||||
|
||||
//
|
||||
// Get full file data.
|
||||
//
|
||||
Status = GetFileSize (File, &ReadSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
FileBuffer = AllocatePool (ReadSize);
|
||||
if (FileBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
Status = GetFileData (File, 0, ReadSize, FileBuffer);
|
||||
if (EFI_ERROR (Status)) {
|
||||
FreePool (FileBuffer);
|
||||
return Status;
|
||||
}
|
||||
|
||||
*Buffer = FileBuffer;
|
||||
*BufferSize = ReadSize;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user