3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2015 Intel Corporation. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <sys/types.h>
37 #include <sys/param.h>
40 #include "peripheral/efivars.h"
42 #define SYSFS_EFIVARS "/sys/firmware/efi/efivars"
52 (efi_guid_t) { 0xd5f9d775, 0x1a09, 0x4e89, \
53 { 0x96, 0xcf, 0x1d, 0x19, 0x55, 0x4d, 0xa6, 0x67 } }
55 static void efivars_pathname(const char *name, char *pathname, size_t size)
57 static efi_guid_t guid = VENDOR_GUID;
59 snprintf(pathname, size - 1,
60 "%s/%s-%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
61 SYSFS_EFIVARS, name, guid.data1, guid.data2, guid.data3,
62 guid.data4[0], guid.data4[1], guid.data4[2], guid.data4[3],
63 guid.data4[4], guid.data4[5], guid.data4[6], guid.data4[7]);
66 int efivars_read(const char *name, uint32_t *attributes,
67 void *data, size_t size)
69 char pathname[PATH_MAX];
75 efivars_pathname(name, pathname, PATH_MAX);
77 fd = open(pathname, O_RDONLY | O_CLOEXEC);
81 iov[0].iov_base = &attr;
82 iov[0].iov_len = sizeof(attr);
83 iov[1].iov_base = data;
84 iov[1].iov_len = size;
86 len = readv(fd, iov, 2);
99 int efivars_write(const char *name, uint32_t attributes,
100 const void *data, size_t size)
102 char pathname[PATH_MAX];
107 efivars_pathname(name, pathname, PATH_MAX);
109 buf = malloc(size + sizeof(attributes));
113 fd = open(pathname, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC,
114 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
120 memcpy(buf, &attributes, sizeof(attributes));
121 memcpy(buf + sizeof(attributes), data, size);
123 written = write(fd, buf, size + sizeof(attributes));