我想在 UEFI 中列出根目录的内容,但我没有找到任何协议可以做到这一点;因此我想打印目录文件的内容,但EFI_FILE_PROTOCOL
无法读取目录文件。我唯一能做的就是读取包含该信息的磁盘扇区,但EFI_BLOCK_IO_PROTOCOL
返回0x02
.
这是代码:
#include <efi.h>
#include <efilib.h>
EFI_STATUS
efi_main(EFI_HANDLE Image, EFI_SYSTEM_TABLE* Systab)
{
EFI_LOADED_IMAGE_PROTOCOL* LoadedImage;
EFI_BLOCK_IO_PROTOCOL* BlockIO;
UINT16* Buffer;
EFI_STATUS Status;
InitializeLib(Image, Systab);
Status = uefi_call_wrapper(BS->HandleProtocol, 3,
Image,
&gEfiLoadedImageProtocolGuid,
&LoadedImage);
if(Status != EFI_SUCCESS) {
Print(L"HandleProtocol() failed [0]\n");
}
Status = uefi_call_wrapper(BS->HandleProtocol, 3,
LoadedImage->DeviceHandle,
&gEfiBlockIoProtocolGuid,
&BlockIO);
if(Status != EFI_SUCCESS) {
Print(L"HandleProtocol() failed [1]\n");
}
Status = uefi_call_wrapper(BlockIO->ReadBlocks, 5,
BlockIO,
BlockIO->Media->MediaId,
(EFI_LBA)1,
BlockIO->Media->BlockSize,
Buffer);
if(Status != EFI_SUCCESS) {
Print(L"Failed to read disk with code 0x%x\n", Status);
}
else for(int i = 0; i < 512; i++) {
Print(L"%c", (CHAR8)Buffer[i]);
}
return EFI_SUCCESS;
}
你能看出我做错了什么吗?