--- Begin Message ---
Package: elilo
Version: 3.6-3.1
Severity: normal
Tags: patch
eliloalt doesn't work anymore with the new efivars module. For one
thing, the old module exposed itself through /proc/efi/vars; now it's
/sys/firmware/efi/vars. Also, the semantics for creating and deleting
variables have changed. This patch detects which path is available, and
changes eliloalt's semantics based on that.
-- System Information:
Debian Release: 4.0
APT prefers stable
APT policy: (500, 'stable')
Architecture: ia64
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-4-mckinley
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Versions of packages elilo depends on:
ii debconf 1.5.11 Debian configuration
management sy
ii dosfstools 2.11-2.1 Utilities to create and
check MS-D
ii efibootmgr 0.5.3-2 Interact with the EFI Boot
Manager
elilo recommends no packages.
-- debconf information:
elilo/format: true
* elilo/runme: false
--- eliloalt.c.old 2007-05-31 15:16:16.000000000 -0600
+++ eliloalt.c 2007-06-01 15:20:34.000000000 -0600
@@ -32,6 +32,7 @@
* be run by root.
*/
#include <sys/types.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
@@ -47,8 +48,9 @@
#define ELILOALT_VERSION "0.02"
#define ELILO_ALT_NAME "EliloAlt"
-#define EFIVAR_DIR "/proc/efi/vars"
-#define ELILO_ALTVAR EFIVAR_DIR"/"ELILO_ALT_NAME"-00000000-0000-0000-0000-000000000000"
+#define OLDEFIVAR_DIR "/proc/efi/vars"
+#define NEWEFIVAR_DIR "/sys/firmware/efi/vars"
+#define ELILO_ALTVAR ELILO_ALT_NAME"-00000000-0000-0000-0000-000000000000"
#define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
@@ -81,6 +83,11 @@
} __attribute__((packed)) efi_variable_t;
static char *elilo_alt_name = ELILO_ALT_NAME;
+static char *efi_vars_dir = NULL;
+static char *elilo_altvar = NULL;
+static char *elilo_newvar = NULL;
+static char *elilo_delvar = NULL;
+unsigned char efivars_version = -1;
static struct option cmd_options[]={
{ "version", 0, 0, 1},
@@ -129,9 +136,9 @@
if (getuid() != 0) {
fatal_error("This program must be run as root\n");
}
- efi_vars = opendir(EFIVAR_DIR);
+ efi_vars = opendir(efi_vars_dir);
if (efi_vars == NULL) {
- fatal_error("Cannot access %s\n", EFIVAR_DIR);
+ fatal_error("Cannot access %s\n", efi_vars_dir);
}
if (!find_entry) {
closedir(efi_vars);
@@ -143,9 +150,9 @@
break;
}
if (entry == NULL) {
- fatal_error("Cannot find entry in %s\n", EFIVAR_DIR);
+ fatal_error("Cannot find entry in %s\n", efi_vars_dir);
}
- sprintf(name, "%s/%s", EFIVAR_DIR, entry->d_name);
+ sprintf(name, "%s/%s", efi_vars_dir, entry->d_name);
closedir(efi_vars);
return name;
}
@@ -157,10 +164,17 @@
int fd, r, i;
check_proc_efi(0);
-
- fd = open(ELILO_ALTVAR, O_WRONLY);
- if (fd == -1) {
- fatal_error("variable not defined\n");
+
+ if (efivars_version == 1) {
+ fd = open(elilo_altvar, O_WRONLY);
+ if (fd == -1) {
+ fatal_error("variable not defined\n");
+ }
+ } else {
+ fd = open(elilo_delvar, O_WRONLY);
+ if (fd == -1) {
+ fatal_error("can't open %s\n", elilo_delvar);
+ }
}
memset(&var, 0, sizeof(var));
@@ -176,7 +190,7 @@
r = write(fd, &var, sizeof(var));
if (r != sizeof(var)) {
- fatal_error("Variable %s defined but invalid content\n", ELILO_ALTVAR);
+ fatal_error("Variable %s defined but invalid content\n", elilo_altvar);
}
close(fd);
}
@@ -191,7 +205,7 @@
check_proc_efi(0);
- fd = open(ELILO_ALTVAR, O_RDONLY);
+ fd = open(elilo_altvar, O_RDONLY);
if (fd == -1) {
fatal_error("variable not defined\n");
}
@@ -200,7 +214,7 @@
r = read(fd, &var, sizeof(var));
if (r != sizeof(var)) {
- fatal_error("Variable %s defined but invalid content\n", ELILO_ALTVAR);
+ fatal_error("Variable %s defined but invalid content\n", elilo_altvar);
}
printf("EliloAlt=\"");
for(i=0; i < var.datasize; i+=1){
@@ -229,11 +243,19 @@
fatal_error("Variable content is too long, must be <= 512 characters\n");
}
- fd = open(name, O_WRONLY);
- if (fd == -1) {
- fatal_error("can't open %s: %s\n", ELILO_ALTVAR, strerror(errno));
+ if (efivars_version == 1) {
+ fd = open(name, O_WRONLY);
+ if (fd == -1) {
+ fatal_error("can't open %s: %s\n", name,
+ strerror(errno));
+ }
+ } else {
+ fd = open(elilo_newvar, O_WRONLY);
+ if (fd == -1) {
+ fatal_error("can't open %s: %s\n", elilo_newvar,
+ strerror(errno));
+ }
}
-
memset(&var, 0, sizeof(var));
for (i=0; i < sizeof(elilo_alt_name); i++) {
@@ -256,7 +278,7 @@
r = write(fd, &var, sizeof(var));
if (r != sizeof(var)) {
- fatal_error("Variable %s defined but invalid content %d\n", ELILO_ALTVAR, r);
+ fatal_error("Variable %s defined but invalid content %d\n", elilo_altvar, r);
}
close(fd);
@@ -266,6 +288,26 @@
main(int argc, char **argv)
{
int c;
+ struct stat statbuf;
+
+ if (stat(OLDEFIVAR_DIR, &statbuf) == 0) {
+ efi_vars_dir = strdup(OLDEFIVAR_DIR);
+ efivars_version = 1;
+ } else if (stat(NEWEFIVAR_DIR, &statbuf) == 0) {
+ efi_vars_dir = strdup(NEWEFIVAR_DIR);
+ elilo_newvar = malloc(strlen(efi_vars_dir) +
+ strlen("new_var") + 2);
+ sprintf(elilo_newvar, "%s/%s", efi_vars_dir, "new_var");
+ elilo_delvar = malloc(strlen(efi_vars_dir) +
+ strlen("del_var") + 2);
+ sprintf(elilo_delvar, "%s/%s", efi_vars_dir, "del_var");
+ efivars_version = 2;
+ } else {
+ fatal_error("No EFI vars dir found\n\ttried:\n\t%s\n\t%s",
+ OLDEFIVAR_DIR, NEWEFIVAR_DIR);
+ }
+ elilo_altvar = malloc(strlen(efi_vars_dir)+strlen(ELILO_ALTVAR)+2);
+ sprintf(elilo_altvar, "%s/%s", efi_vars_dir, ELILO_ALTVAR);
while ((c=getopt_long(argc, argv,"hdps:", cmd_options, 0)) != -1) {
switch(c) {
--- End Message ---