efivars.c revision ff47c895c8c2132ef98ef4182213a0ba79eefb73
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <fcntl.h>
#include "util.h"
#include "utf8.h"
#include "efivars.h"
bool is_efiboot(void) {
}
int efi_get_variable(sd_id128_t vendor, const char *name, uint32_t *attribute, void **value, size_t *size) {
_cleanup_free_ char *p = NULL;
uint32_t a;
ssize_t n;
void *r;
if (asprintf(&p,
"/sys/firmware/efi/efivars/%s-%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
return -ENOMEM;
if (fd < 0)
return -errno;
return -errno;
return -EIO;
return -E2BIG;
if (n < 0)
return (int) n;
if (n != sizeof(a))
return -EIO;
if (!r)
return -ENOMEM;
if (n < 0) {
free(r);
return (int) -n;
}
free(r);
return -EIO;
}
/* Always NUL terminate (2 bytes, to protect UTF-16) */
*value = r;
if (attribute)
*attribute = a;
return 0;
}
_cleanup_free_ void *i = NULL;
_cleanup_free_ char *j = NULL;
int r;
uint64_t x;
assert(u);
if (r < 0)
return r;
j = utf16_to_utf8(i, is);
if (!j)
return -ENOMEM;
r = safe_atou64(j, &x);
if (r < 0)
return r;
*u = x;
return 0;
}
uint64_t x, y;
int r;
if (r < 0)
return r;
if (r < 0)
return r;
if (y == 0 || y < x)
return -EIO;
if (y > USEC_PER_HOUR)
return -EIO;
*firmware = x;
*loader = y;
return 0;
}
int efi_get_boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) {
usec_t x, y, a;
int r;
if (!n) {
n = &_n;
}
r = get_boot_usec(&x, &y);
if (r < 0)
return r;
/* Let's convert this to timestamps where the firmware
* since usec_t is unsigned and the kernel's monotonic clock
* begins at kernel initialization we'll actually initialize
* the monotonic timestamps here as negative of the actual
* value. */
return 0;
}
int efi_get_loader_device_part_uuid(sd_id128_t *u) {
_cleanup_free_ void *s = NULL;
_cleanup_free_ char *p = NULL;
int r, parsed[16];
unsigned i;
assert(u);
if (r < 0)
return r;
p = utf16_to_utf8(s, ss);
if (!p)
return -ENOMEM;
if (sscanf(p, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
return -EIO;
for (i = 0; i < ELEMENTSOF(parsed); i++)
return 0;
}