return 0;
}
+char* efi_variable_path(sd_id128_t vendor, const char *name) {
+ char *p;
+
+ if (asprintf(&p,
+ "/sys/firmware/efi/efivars/%s-" SD_ID128_UUID_FORMAT_STR,
+ name, SD_ID128_FORMAT_VAL(vendor)) < 0)
+ return NULL;
+
+ return p;
+}
+
int efi_get_variable(
sd_id128_t vendor,
const char *name,
assert(value);
assert(size);
- if (asprintf(&p,
- "/sys/firmware/efi/efivars/%s-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- name, SD_ID128_FORMAT_VAL(vendor)) < 0)
+ p = efi_variable_path(vendor, name);
+ if (!p)
return -ENOMEM;
fd = open(p, O_RDONLY|O_NOCTTY|O_CLOEXEC);
assert(name);
assert(value || size == 0);
- if (asprintf(&p,
- "/sys/firmware/efi/efivars/%s-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- name, SD_ID128_FORMAT_VAL(vendor)) < 0)
+ p = efi_variable_path(vendor, name);
+ if (!p)
return -ENOMEM;
/* Newer efivarfs protects variables that are not in a whitelist with FS_IMMUTABLE_FL by default, to protect
int efi_get_reboot_to_firmware(void);
int efi_set_reboot_to_firmware(bool value);
+char* efi_variable_path(sd_id128_t vendor, const char *name);
int efi_get_variable(sd_id128_t vendor, const char *name, uint32_t *attribute, void **value, size_t *size);
int efi_get_variable_string(sd_id128_t vendor, const char *name, char **p);
int efi_set_variable(sd_id128_t vendor, const char *name, const void *value, size_t size);