From 3b895e69140aa265929871217df9d34e40bad3fe Mon Sep 17 00:00:00 2001 From: "Ian M." Date: Fri, 11 Sep 2026 05:14:00 +0000 Subject: core: file: Get boot volume Signed-off-by: Ian M. --- core/file.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 core/file.c (limited to 'core/file.c') diff --git a/core/file.c b/core/file.c new file mode 100644 index 0000000..717e506 --- /dev/null +++ b/core/file.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2026, Apollo Telephone Laboratories. + * Provided under the BSD-3 clause. + */ + +#include +#include + +EFI_STATUS +FileGetVolume(IN EFI_HANDLE ImageHandle, OUT EFI_FILE_HANDLE *Handle) +{ + EFI_LOADED_IMAGE *LoadedImage = NULL; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *IoVolume; + EFI_GUID LipGuid = EFI_LOADED_IMAGE_PROTOCOL_GUID; + EFI_GUID FsGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; + EFI_FILE_HANDLE Volume; + EFI_STATUS Status; + + Status = FwiHandleProtocol( + ImageHandle, + &LipGuid, + (VOID **)&LoadedImage + ); + + if (EFI_ERROR(Status)) { + Print(L"fatal: could not get loaded image\n"); + return Status; + } + + Status = FwiHandleProtocol( + LoadedImage->DeviceHandle, + &FsGuid, + (VOID *)&IoVolume + ); + + if (EFI_ERROR(Status)) { + Print(L"fatal: could not I/O volume\n"); + return Status; + } + + Status = uefi_call_wrapper( + IoVolume->OpenVolume, + 2, + IoVolume, + &Volume + ); + + if (EFI_ERROR(Status)) { + Print(L"fatal: failed to get volume\n"); + return Status; + } + + *Handle = Volume; + return EFI_SUCCESS; +} -- cgit v1.2.3