TianoCore EDK2 master
Loading...
Searching...
No Matches
SecureBootConfigMisc.c
Go to the documentation of this file.
1
10
29 IN EFI_FILE_HANDLE FileHandle,
30 IN OUT VOID **BufferPtr,
31 OUT UINTN *FileSize,
32 IN UINTN AdditionAllocateSize
33 )
34
35{
36 UINTN BufferSize;
37 UINT64 SourceFileSize;
38 VOID *Buffer;
39 EFI_STATUS Status;
40
41 if ((FileHandle == NULL) || (FileSize == NULL)) {
42 return EFI_INVALID_PARAMETER;
43 }
44
45 Buffer = NULL;
46
47 //
48 // Get the file size
49 //
50 Status = FileHandle->SetPosition (FileHandle, (UINT64)-1);
51 if (EFI_ERROR (Status)) {
52 goto ON_EXIT;
53 }
54
55 Status = FileHandle->GetPosition (FileHandle, &SourceFileSize);
56 if (EFI_ERROR (Status)) {
57 goto ON_EXIT;
58 }
59
60 Status = FileHandle->SetPosition (FileHandle, 0);
61 if (EFI_ERROR (Status)) {
62 goto ON_EXIT;
63 }
64
65 BufferSize = (UINTN)SourceFileSize + AdditionAllocateSize;
66 Buffer = AllocateZeroPool (BufferSize);
67 if (Buffer == NULL) {
68 return EFI_OUT_OF_RESOURCES;
69 }
70
71 BufferSize = (UINTN)SourceFileSize;
72 *FileSize = BufferSize;
73
74 Status = FileHandle->Read (FileHandle, &BufferSize, Buffer);
75 if (EFI_ERROR (Status) || (BufferSize != *FileSize)) {
76 FreePool (Buffer);
77 Buffer = NULL;
78 Status = EFI_BAD_BUFFER_SIZE;
79 goto ON_EXIT;
80 }
81
82ON_EXIT:
83
84 *BufferPtr = Buffer;
85 return Status;
86}
87
94VOID
96 IN EFI_FILE_HANDLE FileHandle
97 )
98{
99 if (FileHandle != NULL) {
100 FileHandle->Close (FileHandle);
101 }
102}
103
119EFIAPI
121 IN CONST UINTN *Integer,
122 IN UINTN IntSizeInWords,
123 OUT UINT8 *OctetString,
124 IN UINTN OSSizeInBytes
125 )
126{
127 CONST UINT8 *Ptr1;
128 UINT8 *Ptr2;
129
130 for (Ptr1 = (CONST UINT8 *)Integer, Ptr2 = OctetString + OSSizeInBytes - 1;
131 Ptr1 < (UINT8 *)(Integer + IntSizeInWords) && Ptr2 >= OctetString;
132 Ptr1++, Ptr2--)
133 {
134 *Ptr2 = *Ptr1;
135 }
136
137 for ( ; Ptr1 < (CONST UINT8 *)(Integer + IntSizeInWords) && *Ptr1 == 0; Ptr1++) {
138 }
139
140 if (Ptr1 < (CONST UINT8 *)(Integer + IntSizeInWords)) {
141 return EFI_BUFFER_TOO_SMALL;
142 }
143
144 if (Ptr2 >= OctetString) {
145 ZeroMem (OctetString, Ptr2 - OctetString + 1);
146 }
147
148 return EFI_SUCCESS;
149}
150
161UINTN
163 IN EFI_GUID *Guid,
164 IN CHAR16 *Buffer,
165 IN UINTN BufferSize
166 )
167{
168 UINTN Size;
169
170 Size = UnicodeSPrint (
171 Buffer,
172 BufferSize,
173 L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
174 (UINTN)Guid->Data1,
175 (UINTN)Guid->Data2,
176 (UINTN)Guid->Data3,
177 (UINTN)Guid->Data4[0],
178 (UINTN)Guid->Data4[1],
179 (UINTN)Guid->Data4[2],
180 (UINTN)Guid->Data4[3],
181 (UINTN)Guid->Data4[4],
182 (UINTN)Guid->Data4[5],
183 (UINTN)Guid->Data4[6],
184 (UINTN)Guid->Data4[7]
185 );
186
187 //
188 // SPrint will null terminate the string. The -1 skips the null
189 //
190 return Size - 1;
191}
UINT64 UINTN
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI Int2OctStr(IN CONST UINTN *Integer, IN UINTN IntSizeInWords, OUT UINT8 *OctetString, IN UINTN OSSizeInBytes)
UINTN GuidToString(IN EFI_GUID *Guid, IN CHAR16 *Buffer, IN UINTN BufferSize)
EFI_STATUS ReadFileContent(IN EFI_FILE_HANDLE FileHandle, IN OUT VOID **BufferPtr, OUT UINTN *FileSize, IN UINTN AdditionAllocateSize)
VOID CloseFile(IN EFI_FILE_HANDLE FileHandle)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Base.h:213