summaryrefslogtreecommitdiffstats
path: root/src/detection/bootmgr/bootmgr_linux.c
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/bootmgr/bootmgr_linux.c
Add the files
Diffstat (limited to 'src/detection/bootmgr/bootmgr_linux.c')
-rw-r--r--src/detection/bootmgr/bootmgr_linux.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/detection/bootmgr/bootmgr_linux.c b/src/detection/bootmgr/bootmgr_linux.c
new file mode 100644
index 0000000..0fd019a
--- /dev/null
+++ b/src/detection/bootmgr/bootmgr_linux.c
@@ -0,0 +1,32 @@
+#include "bootmgr.h"
+#include "common/io.h"
+#include "efi_helper.h"
+
+#include <stdalign.h>
+
+#define FF_EFIVARS_PATH_PREFIX "/sys/firmware/efi/efivars/"
+
+const char* ffDetectBootmgr(FFBootmgrResult* result) {
+ alignas(uint16_t) uint8_t buffer[2048];
+
+ if (ffReadFileData(FF_EFIVARS_PATH_PREFIX "BootCurrent-" FF_EFI_GLOBAL_GUID, sizeof(buffer), buffer) != 6) {
+ return "Failed to read efivar: BootCurrent";
+ }
+
+ result->order = *(uint16_t*) &buffer[4];
+
+ snprintf((char*) buffer, sizeof(buffer), FF_EFIVARS_PATH_PREFIX "Boot%04X-" FF_EFI_GLOBAL_GUID, result->order);
+
+ ssize_t size = ffReadFileData((const char*) buffer, sizeof(buffer), buffer);
+ if (size < 5 + (int) sizeof(FFEfiLoadOption) || size == (ssize_t) sizeof(buffer)) {
+ return "Failed to read efivar: Boot####";
+ }
+
+ ffEfiFillLoadOption((FFEfiLoadOption*) &buffer[4], result);
+
+ if (ffReadFileData(FF_EFIVARS_PATH_PREFIX "SecureBoot-" FF_EFI_GLOBAL_GUID, sizeof(buffer), buffer) >= 5) {
+ result->secureBoot = buffer[4] == 1;
+ }
+
+ return NULL;
+}