OcFileLib: Implement AllocateCopyFileData

This commit is contained in:
Goldfish64 2020-07-25 21:26:02 -05:00
parent 0a16c8a126
commit b2e55152ea
2 changed files with 50 additions and 0 deletions

View File

@ -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.

View File

@ -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;
}