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

Function ReadFile

Library/OcFileLib/ReadFile.c:32–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30#include <Library/OcGuardLib.h>
31
32VOID *
33ReadFile (
34 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
35 IN CONST CHAR16 *FilePath,
36 OUT UINT32 *FileSize OPTIONAL,
37 IN UINT32 MaxFileSize OPTIONAL
38 )
39{
40 EFI_STATUS Status;
41 EFI_FILE_HANDLE Volume;
42 EFI_FILE_HANDLE FileHandle;
43 UINT8 *FileBuffer;
44 UINT32 FileBufferSize;
45 UINT32 FileReadSize;
46
47 ASSERT (FileSystem != NULL);
48 ASSERT (FilePath != NULL);
49
50 Status = FileSystem->OpenVolume (
51 FileSystem,
52 &Volume
53 );
54 if (EFI_ERROR(Status)) {
55 return NULL;
56 }
57
58 Status = SafeFileOpen (
59 Volume,
60 &FileHandle,
61 (CHAR16 *) FilePath,
62 EFI_FILE_MODE_READ,
63 0
64 );
65
66 Volume->Close (Volume);
67
68 if (EFI_ERROR(Status)) {
69 return NULL;
70 }
71
72 Status = GetFileSize (
73 FileHandle,
74 &FileReadSize
75 );
76 if (EFI_ERROR(Status)
77 || OcOverflowAddU32 (FileReadSize, sizeof (CHAR16), &FileBufferSize)
78 || (MaxFileSize > 0 && FileReadSize > MaxFileSize)) {
79 FileHandle->Close (FileHandle);
80 return NULL;
81 }
82
83 FileBuffer = AllocatePool (FileBufferSize);
84 if (FileBuffer != NULL) {
85 Status = GetFileData (
86 FileHandle,
87 0,
88 FileReadSize,
89 FileBuffer

Callers 4

File_ReadFunction · 0.50
InternalGetAppleImageFunction · 0.50

Calls 6

SafeFileOpenFunction · 0.85
GetFileDataFunction · 0.85
GetFileSizeFunction · 0.70
AllocatePoolFunction · 0.50
FreePoolFunction · 0.50
CloseMethod · 0.45

Tested by

no test coverage detected