Re: Examples opening and reading/writing a file with EDK2


Laszlo Ersek
 

On 12/31/19 21:38, alejandro.estay@gmail.com wrote:

EFI_STATUS EFIAPI UefiMain (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
//DEBUG ((EFI_D_INFO, "My Entry point: 0x%08x\r\n", (CHAR16*)UefiMainMySampleApp ) );
Print(L"abriendo archivo...\n");
EFI_HANDLE_PROTOCOL HandleProtocol = SystemTable->BootServices->HandleProtocol;
call_status = HandleProtocol(ImageHandle, &gEfiLoadedImageProtocolGuid, (void**)&LoadedImage);
call_status = HandleProtocol(LoadedImage->DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, (void**)&FileSystem);
FileSystem->OpenVolume(FileSystem, &Root);
(Side comment: please always check the returns status.)

call_status = Root->Open(Root, &text_file, L"text_img", EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY);
if (call_status != EFI_SUCCESS)
{
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"imagen no encontrada\r\n");
return call_status;
}
else
{
call_status=ChangeFrequency(EFI_DEFAULT_BEEP_ALTFREQUENCY);

GenerateBeep();

SystemTable->ConOut->OutputString(SystemTable->ConOut, L"leyendo\r\n");


call_status=Root->Read(text_file, &buffer_siz, &image_text);
This call looks invalid (undefined behavior), likely due to a copy/paste
error. It should be:

text_file->Read (text_file, ...)
^^^^^^^^^ ^^^^^^^^^

and not

Root->Read (text_file, ...)
^^^^ ^^^^^^^^^

HTH,
Laszlo



SystemTable->ConOut->OutputString(SystemTable->ConOut, image_text);
}

return EFI_SUCCESS;
}

Join discuss@edk2.groups.io to automatically receive all group messages.