MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / egLoadFile

Function egLoadFile

rEFIt_UEFI/libeg/image.cpp:57–116  ·  view source on GitHub ↗

Basic file operations should be separated into separate file

Source from the content-addressed store, hash-verified

55// Basic file operations should be separated into separate file
56//
57EFI_STATUS egLoadFile(IN EFI_FILE_HANDLE BaseDir, IN CONST CHAR16 *FileName,
58 OUT UINT8 **FileData, OUT UINTN *FileDataLength)
59{
60 EFI_STATUS Status = EFI_NOT_FOUND;
61 EFI_FILE_HANDLE FileHandle = 0;
62 EFI_FILE_INFO *FileInfo;
63 UINT64 ReadSize;
64 UINTN BufferSize;
65 UINT8 *Buffer;
66
67 if (!BaseDir) {
68 goto Error;
69 }
70
71 Status = BaseDir->Open(BaseDir, &FileHandle, (CHAR16*)FileName, EFI_FILE_MODE_READ, 0); // const missing in EFI_FILE_HANDLE->Open
72 if (EFI_ERROR(Status) || !FileHandle) {
73 goto Error;
74 }
75
76 FileInfo = EfiLibFileInfo(FileHandle);
77 if (FileInfo == NULL) {
78 FileHandle->Close(FileHandle);
79 goto Error;
80 }
81 ReadSize = FileInfo->FileSize;
82 if (ReadSize > MAX_FILE_SIZE)
83 ReadSize = MAX_FILE_SIZE;
84 FreePool(FileInfo);
85
86 BufferSize = (UINTN)ReadSize; // was limited to 1 GB above, so this is safe
87 Buffer = (UINT8 *) AllocatePool (BufferSize);
88 if (Buffer == NULL) {
89 FileHandle->Close(FileHandle);
90 Status = EFI_OUT_OF_RESOURCES;
91 goto Error;
92 }
93
94 Status = FileHandle->Read(FileHandle, &BufferSize, Buffer);
95 FileHandle->Close(FileHandle);
96 if (EFI_ERROR(Status)) {
97 FreePool(Buffer);
98 goto Error;
99 }
100
101 if(FileData) {
102 *FileData = Buffer;
103 }
104 if (FileDataLength) {
105 *FileDataLength = BufferSize;
106 }
107 return Status;
108Error:
109 if (FileData) {
110 *FileData = NULL;
111 }
112 if (FileDataLength) {
113 *FileDataLength = 0;
114 }

Callers 15

setup_nvidia_devpropFunction · 0.85
StartupSoundPlayFunction · 0.85
load_vbios_fileFunction · 0.85
SaveOemDsdtFunction · 0.85
LoadPatchedAMLFunction · 0.85
PatchACPIFunction · 0.85
LoadAcpiTableFunction · 0.85
LoadKextMethod · 0.85
LoadNvramPlistFunction · 0.85
GetSleepImageLocationFunction · 0.85
LoadUserSettingsFunction · 0.85
GetBundleVersionFunction · 0.85

Calls 6

EfiLibFileInfoFunction · 0.70
FreePoolFunction · 0.50
AllocatePoolFunction · 0.50
OpenMethod · 0.45
CloseMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected