0

Hello I am currently programming a UEFI bootloader with GNU-EFI and I am just about to program a small config system I have tested it so far and it works, but now I did not want to have everything in one file and split it into several files. Now I have the problem that in my File.c file in the ReadFile function somehow the buffer is not returned. I already checked if the buffer contains anything at all and t does. Hope someone can help me.

File.c

UINT8 *ReadFile(EFI_FILE_HANDLE Volume, CHAR16 *FileName) {

    // Declare variables
    EFI_STATUS Status;
    EFI_FILE_HANDLE FileHandle;
    UINT64 ReadSize;
    UINT8 *Buffer;

    // Open the file
    Status = uefi_call_wrapper(
        Volume->Open,
        5,
        Volume,
        &FileHandle,
        FileName,
        EFI_FILE_MODE_READ,
        EFI_FILE_READ_ONLY | EFI_FILE_HIDDEN | EFI_FILE_SYSTEM
    );
    if(EFI_ERROR(Status)) {
        Print(L"Could not open file! Reason: %r\n", Status);
    }

    // Read the contents of the file
    ReadSize = FileSize(FileHandle);
    Buffer = AllocatePool(ReadSize);

    Status = uefi_call_wrapper(
        FileHandle->Read,
        3,
        FileHandle,
        &ReadSize,
        Buffer
    );
    if(EFI_ERROR(Status)) {
        Print(L"Could not read file! Reason: %r\n", Status);
    }

    // Close the file
    Status = uefi_call_wrapper(
        FileHandle->Close,
        1,
        FileHandle
    );
    if(EFI_ERROR(Status)) {
        Print(L"Could not close file! Reason: %r\n", Status);
    }

    return Buffer;
}

Main.c

    UINT8 *Buffer = ReadFile(Volume, FileName);

    Print(L"File content:\n%a\n", Buffer);
Robin
  • 1
  • 1
  • Please, clarify precisely what you mean when you say that the ```ReadSize``` function doesn’t return ```Buffer```: I see no such function in the code. – picchiolu Dec 31 '22 at 17:06
  • Also, please rephrase your question so that it reflects the actual problem you are facing. – picchiolu Dec 31 '22 at 17:10
  • sorry i mean ReadFile function – Robin Dec 31 '22 at 17:52
  • 1
    Robin, bets to post a [mcve] – chux - Reinstate Monica Dec 31 '22 at 18:30
  • any compiler warnings? – pm100 Dec 31 '22 at 19:09
  • no warnings from compile – Robin Dec 31 '22 at 20:01
  • Are you using the correct format in ```Print``` to print the content of ```Buffer```? ```%a``` is for ASCII strings. – picchiolu Dec 31 '22 at 21:35
  • yes i used it correctly i added the print function also in a the ReadFile function to test if something is in the buffer – Robin Dec 31 '22 at 22:35
  • @Robin I am sorry but the wording of your question is a bit ambiguous: you seem to suggest that, before splitting the code into different files, everything worked ("... I have tested it so far and it works, but now I did not want to have everything in one file and split it into several files. Now I have the problem..."). Did the problem appear only after you split the code into several files? – picchiolu Jan 01 '23 at 00:45

0 Answers0