2 efivars_sysfs.[ch] - Manipulates EFI variables as exported in /sys/firmware/efi/vars
4 Copyright (C) 2001,2003 Dell Computer Corporation <Matt_Domsch@dell.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <sys/types.h>
34 #include "efibootmgr.h"
35 #include "efivars_sysfs.h"
38 sysfs_read_variable(const char *name, efi_variable_t *var)
40 char filename[PATH_MAX];
43 char buffer[PATH_MAX+40];
44 if (!name || !var) return EFI_INVALID_PARAMETER;
45 memset(buffer, 0, sizeof(buffer));
47 snprintf(filename, PATH_MAX-1, "%s/%s/raw_var", SYSFS_DIR_EFI_VARS,name);
48 fd = open(filename, O_RDONLY);
52 readsize = read(fd, var, sizeof(*var));
53 if (readsize != sizeof(*var)) {
55 return EFI_INVALID_PARAMETER;
62 sysfs_write_variable(const char *filename, efi_variable_t *var)
66 char buffer[PATH_MAX+40];
68 if (!filename || !var) return EFI_INVALID_PARAMETER;
69 memset(buffer, 0, sizeof(buffer));
71 fd = open(filename, O_WRONLY);
73 return EFI_INVALID_PARAMETER;
75 writesize = write(fd, var, sizeof(*var));
76 if (writesize != sizeof(*var)) {
78 return EFI_INVALID_PARAMETER;
86 sysfs_edit_variable(const char *name, efi_variable_t *var)
88 char filename[PATH_MAX];
89 if (!var) return EFI_INVALID_PARAMETER;
90 snprintf(filename, PATH_MAX-1, "%s/%s/raw_var", SYSFS_DIR_EFI_VARS,name);
91 return sysfs_write_variable(filename, var);
95 sysfs_create_variable(efi_variable_t *var)
97 char filename[PATH_MAX];
98 if (!var) return EFI_INVALID_PARAMETER;
99 snprintf(filename, PATH_MAX-1, "%s/%s", SYSFS_DIR_EFI_VARS,"new_var");
100 return sysfs_write_variable(filename, var);
104 sysfs_delete_variable(efi_variable_t *var)
106 char filename[PATH_MAX];
107 if (!var) return EFI_INVALID_PARAMETER;
108 snprintf(filename, PATH_MAX-1, "%s/%s", SYSFS_DIR_EFI_VARS,"del_var");
109 return sysfs_write_variable(filename, var);
112 struct efivar_kernel_calls sysfs_kernel_calls = {
113 .read = sysfs_read_variable,
114 .edit = sysfs_edit_variable,
115 .create = sysfs_create_variable,
116 .delete = sysfs_delete_variable,
117 .path = SYSFS_DIR_EFI_VARS,