3
Copyright (c) 1998 Intel Corporation
33
Status = BS->AllocatePool (PoolAllocationType, Size, &p);
34
if (EFI_ERROR(Status)) {
35
DEBUG((D_ERROR, "AllocatePool: out of pool %x\n", Status));
48
p = AllocatePool (Size);
67
NewPool = AllocatePool (NewSize);
72
CopyMem (NewPool, OldPool, OldSize < NewSize ? OldSize : NewSize);
87
BS->FreePool (Buffer);
98
RtZeroMem (Buffer, Size);
108
RtSetMem (Buffer, Size, Value);
118
RtCopyMem (Dest, Src, len);
128
return RtCompareMem (Dest, Src, len);
133
IN OUT EFI_STATUS *Status,
134
IN OUT VOID **Buffer,
141
Helper function called as part of the code needed
142
to allocate the proper sized buffer for various
147
Status - Current status
149
Buffer - Current allocated buffer, or NULL
151
BufferSize - Current buffer size needed
155
TRUE - if the buffer was reallocated and the caller
156
should try the API again.
163
// If this is an initial request, buffer will be null with a new buffer size
166
if (!*Buffer && BufferSize) {
167
*Status = EFI_BUFFER_TOO_SMALL;
171
// If the status code is "buffer too small", resize the buffer
175
if (*Status == EFI_BUFFER_TOO_SMALL) {
181
*Buffer = AllocatePool (BufferSize);
186
*Status = EFI_OUT_OF_RESOURCES;
191
// If there's an error, free the buffer
194
if (!TryAgain && EFI_ERROR(*Status) && *Buffer) {
203
EFI_MEMORY_DESCRIPTOR *
205
OUT UINTN *NoEntries,
207
OUT UINTN *DescriptorSize,
208
OUT UINT32 *DescriptorVersion
212
EFI_MEMORY_DESCRIPTOR *Buffer;
216
// Initialize for GrowBuffer loop
220
BufferSize = sizeof(EFI_MEMORY_DESCRIPTOR);
223
// Call the real function
226
while (GrowBuffer (&Status, (VOID **) &Buffer, BufferSize)) {
227
Status = BS->GetMemoryMap (&BufferSize, Buffer, MapKey, DescriptorSize, DescriptorVersion);
231
// Convert buffer size to NoEntries
234
if (!EFI_ERROR(Status)) {
235
*NoEntries = BufferSize / *DescriptorSize;
242
LibGetVariableAndSize (
244
IN EFI_GUID *VendorGuid,
253
// Initialize for GrowBuffer loop
260
// Call the real function
263
while (GrowBuffer (&Status, &Buffer, BufferSize)) {
264
Status = RT->GetVariable (
273
*VarSize = BufferSize;
283
IN EFI_GUID *VendorGuid
288
return LibGetVariableAndSize (Name, VendorGuid, &VarSize);
300
VarBuf = LibGetVariable(VarName,VarGuid);
302
Status = EFI_NOT_FOUND;
306
// Delete variable from Storage
308
Status = RT->SetVariable (
310
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
313
ASSERT (!EFI_ERROR(Status));
321
LibInsertToTailOfBootOrder (
322
IN UINT16 BootOption,
323
IN BOOLEAN OnlyInsertIfEmpty
326
UINT16 *BootOptionArray;
327
UINT16 *NewBootOptionArray;
332
BootOptionArray = LibGetVariableAndSize (VarBootOrder, &EfiGlobalVariable, &VarSize);
333
if (VarSize != 0 && OnlyInsertIfEmpty) {
334
if (BootOptionArray) {
335
FreePool (BootOptionArray);
337
return EFI_UNSUPPORTED;
340
VarSize += sizeof(UINT16);
341
NewBootOptionArray = AllocatePool (VarSize);
343
for (Index = 0; Index < ((VarSize/sizeof(UINT16)) - 1); Index++) {
344
NewBootOptionArray[Index] = BootOptionArray[Index];
347
// Insert in the tail of the array
349
NewBootOptionArray[Index] = BootOption;
351
Status = RT->SetVariable (
352
VarBootOrder, &EfiGlobalVariable,
353
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
354
VarSize, (VOID*) NewBootOptionArray
357
if (NewBootOptionArray) {
358
FreePool (NewBootOptionArray);
360
if (BootOptionArray) {
361
FreePool (BootOptionArray);
369
IN MASTER_BOOT_RECORD *Mbr,
370
IN EFI_BLOCK_IO *BlkIo
373
UINT32 StartingLBA, EndingLBA;
378
if (Mbr->Signature != MBR_SIGNATURE) {
380
// The BPB also has this signature, so it can not be used alone.
386
for (i=0; i<MAX_MBR_PARTITIONS; i++) {
387
if ( Mbr->Partition[i].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) == 0 ) {
391
StartingLBA = EXTRACT_UINT32(Mbr->Partition[i].StartingLBA);
392
EndingLBA = StartingLBA + EXTRACT_UINT32(Mbr->Partition[i].SizeInLBA) - 1;
393
if (EndingLBA > BlkIo->Media->LastBlock) {
395
// Compatability Errata:
396
// Some systems try to hide drive space with thier INT 13h driver
397
// This does not hide space from the OS driver. This means the MBR
398
// that gets created from DOS is smaller than the MBR created from
399
// a real OS (NT & Win98). This leads to BlkIo->LastBlock being
400
// wrong on some systems FDISKed by the OS.
403
if (BlkIo->Media->LastBlock < MIN_MBR_DEVICE_SIZE) {
405
// If this is a very small device then trust the BlkIo->LastBlock
410
if (EndingLBA > (BlkIo->Media->LastBlock + MBR_ERRATA_PAD)) {
415
for (j=i+1; j<MAX_MBR_PARTITIONS; j++) {
416
if (Mbr->Partition[j].OSIndicator == 0x00 || EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) == 0) {
419
if ( EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) >= StartingLBA &&
420
EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) <= EndingLBA ) {
422
// The Start of this region overlaps with the i'th region
426
NewEndingLBA = EXTRACT_UINT32(Mbr->Partition[j].StartingLBA) + EXTRACT_UINT32(Mbr->Partition[j].SizeInLBA) - 1;
427
if ( NewEndingLBA >= StartingLBA && NewEndingLBA <= EndingLBA ) {
429
// The End of this region overlaps with the i'th region
436
// Non of the regions overlapped so MBR is O.K.
447
return RtDecimaltoBCD (DecValue);
456
return RtBCDtoDecimal (BcdValue);
460
LibGetSystemConfigurationTable(
461
IN EFI_GUID *TableGuid,
468
for(Index=0;Index<ST->NumberOfTableEntries;Index++) {
469
if (CompareGuid(TableGuid,&(ST->ConfigurationTable[Index].VendorGuid))==0) {
470
*Table = ST->ConfigurationTable[Index].VendorTable;
474
return EFI_NOT_FOUND;
480
IN EFI_HANDLE Handle,
481
IN UI_STRING_TYPE StringType,
482
IN ISO_639_2 *LangCode,
483
IN BOOLEAN ReturnDevicePathStrOnMismatch
487
UI_STRING_TYPE Index;
488
UI_STRING_ENTRY *Array;
491
Status = BS->HandleProtocol (Handle, &UiProtocol, (VOID *)&Ui);
492
if (EFI_ERROR(Status)) {
493
return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL;
497
// Skip the first strings
499
for (Index = UiDeviceString, Array = Ui->Entry; Index < StringType; Index++, Array++) {
500
while (Array->LangCode) {
506
// Search for the match
508
while (Array->LangCode) {
509
if (strcmpa (Array->LangCode, LangCode) == 0) {
510
return Array->UiString;
513
return (ReturnDevicePathStrOnMismatch) ? DevicePathToStr(DevicePathFromHandle(Handle)) : NULL;