linklen = strlen(filepath);
if (linklen > PATH_MAX) {
errno = ENAMETOOLONG;
+ efi_error("filepath length exceeds PATH_MAX");
return -1;
}
strcpy(linkbuf, filepath);
ssize_t l;
l = readlink(linkbuf, tmp, PATH_MAX);
- if (l < 0)
+ if (l < 0) {
+ efi_error("readlink failed");
return -1;
+ }
tmp[l] = '\0';
linklen = l;
strcpy(linkbuf, tmp);
} while (1);
mounts = fopen("/proc/self/mounts", "r");
- if (mounts == NULL)
- return rc;
+ if (mounts == NULL) {
+ efi_error("couldn not open /proc/self/mounts");
+ return -1;
+ }
struct mntent *me;
while (1) {
errno = 0;
me = getmntent(mounts);
if (!me) {
- if (feof(mounts))
+ if (feof(mounts)) {
errno = ENOENT;
+ efi_error("could not find mountpoint");
+ }
goto err;
}
if (rc < 0) {
if (errno == ENOENT)
continue;
+ efi_error("could not stat mountpoint");
goto err;
}
if (strncmp(linkbuf, me->mnt_dir, mntlen))
continue;
*devicep = strdup(me->mnt_fsname);
- if (!*devicep)
+ if (!*devicep) {
+ errno = ENOMEM;
+ efi_error("strdup failed");
goto err;
+ }
*relpathp = strdup(linkbuf + mntlen);
if (!*relpathp) {
free(*devicep);
*devicep = NULL;
+ errno = ENOMEM;
+ efi_error("strdup failed");
goto err;
}
ret = 0;
int rc;
rc = asprintfa(&diskpath, "/dev/%s", info->disk_name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not allocate buffer");
return -1;
+ }
+
+ rc = open(diskpath, flags);
+ if (rc < 0)
+ efi_error("could not open disk");
- return open(diskpath, flags);
+ return rc;
}
static char *
int saved_errno;
fd = open(devpath, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("could not open device for ESP");
goto err;
+ }
rc = eb_disk_info_from_fd(fd, &info);
- if (rc < 0 && errno != ENOSYS)
+ if (rc < 0 && errno != ENOSYS) {
+ efi_error("could not get ESP disk info");
goto err;
+ }
if (partition > 0)
info.part = partition;
&& (!(options & EFIBOOT_ABBREV_FILE)
&& !(options & EFIBOOT_ABBREV_HD))) {
sz = efidp_make_edd10(buf, size, info.edd10_devicenum);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make EDD 1.0 device path");
return -1;
+ }
off = sz;
} else if (!(options & EFIBOOT_ABBREV_FILE)
&& !(options & EFIBOOT_ABBREV_HD)) {
* from there.
*/
sz = make_blockdev_path(buf, size, &info);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not create device path");
return -1;
+ }
off += sz;
}
int rc;
rc = set_disk_and_part_name(&info);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not set disk and partition name");
goto err;
+ }
disk_fd = open_disk(&info,
- (options& EFIBOOT_OPTIONS_WRITE_SIGNATURE)?O_RDWR:O_RDONLY);
- if (disk_fd < 0)
+ (options & EFIBOOT_OPTIONS_WRITE_SIGNATURE)
+ ? O_RDWR : O_RDONLY);
+ if (disk_fd < 0) {
+ efi_error("could not open disk");
goto err;
+ }
sz = make_hd_dn(buf, size, off, disk_fd, info.part, options);
saved_errno = errno;
close(disk_fd);
errno = saved_errno;
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make HD() DP node");
goto err;
+ }
off += sz;
}
char *filepath = strdupa(relpath);
tilt_slashes(filepath);
sz = efidp_make_file(buf+off, size?size-off:0, filepath);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make File() DP node");
goto err;
+ }
off += sz;
sz = efidp_make_end_entire(buf+off, size?size-off:0);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make EndEntire DP node");
goto err;
+ }
off += sz;
ret = off;
err:
saved_errno = errno;
va_end(ap);
errno = saved_errno;
+ if (ret < 0)
+ efi_error("could not generate File DP from ESP");
return ret;
}
int saved_errno;
rc = find_file(filepath, &child_devpath, &relpath);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not canonicalize fs path");
return -1;
+ }
rc = find_parent_devpath(child_devpath, &parent_devpath);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not find parent device for file");
return -1;
+ }
rc = get_partition_number(child_devpath);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not get partition number for device");
goto err;
+ }
va_start(ap, options);
saved_errno = errno;
va_end(ap);
errno = saved_errno;
+ if (ret < 0)
+ efi_error("could not generate File DP from ESP");
err:
saved_errno = errno;
if (child_devpath)
uint16_t protocol __attribute__((unused)),
uint8_t addr_origin __attribute__((unused)))
{
+ ssize_t ret;
+
#if 0
if (local_addr == NULL || remote_addr == NULL ||
gateway_addr == NULL || netmask == NULL) {
return -1;
}
#endif
- return efidp_make_ipv4(buf, size, 0, 0, 0, 0, 0, 0, 0, 0);
+ ret = efidp_make_ipv4(buf, size, 0, 0, 0, 0, 0, 0, 0, 0);
+ if (ret < 0)
+ efi_error("could not make ipv4 DP node");
+ return ret;
}
ssize_t
ssize_t sz;
sz = make_mac_path(buf, size, ifname);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make MAC DP node");
return -1;
+ }
off += sz;
sz = make_ipv4_path(buf+off, size?size-off:0, local_addr, remote_addr,
gateway_addr, netmask, local_port, remote_port,
protocol, addr_origin);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make IPV4 DP node");
return -1;
+ }
off += sz;
sz = efidp_make_end_entire(buf+off, size?size-off:0);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("could not make EndEntire DP node");
return -1;
+ }
off += sz;
return off;
static inline int
is_mbr_valid(legacy_mbr *mbr)
{
+ int ret;
if (!mbr)
return 0;
- return (mbr->signature == MSDOS_MBR_SIGNATURE);
+ ret = (mbr->signature == MSDOS_MBR_SIGNATURE);
+ if (!ret) {
+ errno = ENOTTY;
+ efi_error("mbr signature is not MSDOS_MBR_SIGNATURE");
+ }
+ return ret;
}
/************************************************************
{
/* Until I can handle these... */
//fprintf(stderr, "Extended partition info not supported.\n");
+ errno = ENOSYS;
+ efi_error("extended partition info is not supported");
return -1;
}
struct stat stat;
struct timeval tv;
- if (!mbr)
+ if (!mbr) {
+ errno = EINVAL;
+ efi_error("mbr argument must not be NULL");
return -1;
- if (!is_mbr_valid(mbr))
+ }
+ if (!is_mbr_valid(mbr)) {
+ errno = ENOENT;
+ efi_error("mbr is not valid");
return -1;
+ }
*mbr_type = 0x01;
*signature_type = 0x01;
rc = fstat(fd, &stat);
if (rc < 0) {
if (report_errors)
- perror("stat disk");
+ perror("fstat disk");
+ efi_error("could not fstat disk");
return rc;
}
if (rc < 0) {
if (report_errors)
perror("gettimeofday");
+ efi_error("gettimeofday failed");
return rc;
}
/* Write it to the disk */
lseek(fd, 0, SEEK_SET);
rc = write(fd, mbr, sizeof(*mbr));
+ if (rc < 0) {
+ efi_error("could not write MBR signature");
+ return rc;
+ }
}
*(uint32_t *)signature = mbr->unique_mbr_signature;
if (num > 4) {
/* Extended partition */
- return msdos_disk_get_extended_partition_info(fd, mbr, num,
- start, size);
+ rc = msdos_disk_get_extended_partition_info(fd, mbr, num,
+ start, size);
+ if (rc < 0) {
+ efi_error("could not get extended partition info");
+ return rc;
+ }
} else if (num == 0) {
/* Whole disk */
*start = 0;
int sector_size = get_sector_size(fd);
mbr_size = lcm(sizeof(*mbr), sector_size);
- if ((rc = posix_memalign(&mbr_sector, sector_size, mbr_size)) != 0)
+ if ((rc = posix_memalign(&mbr_sector, sector_size, mbr_size)) != 0) {
+ efi_error("posix_memalign failed");
goto error;
+ }
memset(mbr_sector, '\0', mbr_size);
offset = lseek(fd, 0, SEEK_SET);
this_bytes_read = read(fd, mbr_sector, mbr_size);
if (this_bytes_read < (ssize_t)sizeof(*mbr)) {
+ efi_error("short read trying to read mbr data");
rc=1;
goto error_free_mbr;
}
mbr_type,
signature_type);
if (mbr_invalid) {
+ efi_error("neither MBR nor GPT is valid");
rc=1;
goto error_free_mbr;
}
+ efi_error_clear();
}
error_free_mbr:
free(mbr_sector);
errno = 0;
rc = get_partition_info(fd, options,
- partition>0?partition:1, &part_start,
+ partition > 0 ? partition : 1, &part_start,
&part_size, signature, &format,
&signature_type);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not get partition info");
return rc;
+ }
- return efidp_make_hd(buf, size, partition>0?partition:1, part_start,
- part_size, signature, format, signature_type);
+ rc = efidp_make_hd(buf, size, partition>0?partition:1, part_start,
+ part_size, signature, format, signature_type);
+ if (rc < 0)
+ efi_error("could not make HD DP node");
+ return rc;
}
acpi_hid->hid = hid;
}
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
strcpy(next, cidstr);
}
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
pci->device = device;
pci->function = function;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
memcpy(&edd_dp->vendor_guid, &edd10_guid, sizeof (edd10_guid));
edd_dp->hardware_device = hardware_device;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
memset(buf+4, 0, req-4);
utf8_to_ucs2(file->name, req-4, 1, lf);
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
hd->format = format;
hd->signature_type = signature_type;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
case EFIDP_MSG_ISCSI: {
ssize_t sz = efidp_node_size(dp)
- offsetof(efidp_iscsi, target_name);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("bad DP node size");
return -1;
+ }
if (sz > EFIDP_ISCSI_MAX_TARGET_NAME_LEN)
sz = EFIDP_ISCSI_MAX_TARGET_NAME_LEN;
break;
case EFIDP_MSG_URI: {
ssize_t sz = efidp_node_size(dp) - offsetof(efidp_uri, uri);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("bad DP node size");
return -1;
+ }
char uri[sz + 1];
memcpy(uri, dp->uri.uri, sz);
memcpy(mac->mac_addr, mac_addr,
mac_addr_size > 32 ? 32 : mac_addr_size);
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
*((char *)ipv4->gateway) = htonl(gateway);
*((char *)ipv4->netmask) = htonl(netmask);
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
scsi->target = target;
scsi->lun = lun;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
memset(nvme->ieee_eui_64, '\0',
sizeof (nvme->ieee_eui_64));
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
sata->port_multiplier_port = port_multiplier_port;
sata->lun = lun;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
atapi->slave = slave;
atapi->lun = lun;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
sas->drive_bay_id = 0;
sas->rtp = 0;
}
+
+ if (sz < 0)
+ efi_error("efidp_make_generic failed");
+
return sz;
}
{
if (dp->length <= 4) {
errno = ENOSPC;
+ efi_error("DP was smaller than DP header");
return NULL;
}
return (void *)((uint8_t *)dp + sizeof (dp));
{
if (dn->length < 4 || bufsize > (size_t)dn->length - 4) {
errno = ENOSPC;
+ efi_error("DP was smaller than DP header");
return -1;
}
void *data = efidp_data_address(dn);
- if (!data)
+ if (!data) {
+ efi_error("efidp_data_address failed");
return -1;
+ }
memcpy(data, buf, bufsize);
return 0;
}
efidp new;
sz = efidp_size(dp);
- if (sz < 0)
+ if (sz < 0) {
+ efi_error("efidp_size(dp) returned error");
return sz;
+ }
if (add(sz, extra, &plus)) {
errno = EOVERFLOW;
+ efi_error("arithmetic overflow computing allocation size");
return -1;
}
new = calloc(1, plus);
- if (!new)
+ if (!new) {
+ efi_error("allocation failed");
return -1;
+ }
memcpy(new, dp, sz);
*out = new;
__attribute__((__visibility__ ("default")))
efidp_duplicate_path(const_efidp dp, efidp *out)
{
- return efidp_duplicate_extra(dp, out, 0);
+ int rc;
+ rc = efidp_duplicate_extra(dp, out, 0);
+ if (rc < 0)
+ efi_error("efi_duplicate_extra(dp, out, 0) returned error");
+ return rc;
}
int
const_efidp le;
int rc;
- if (!dp0 && !dp1)
- return efidp_duplicate_path((const_efidp)&end_entire, out);
+ if (!dp0 && !dp1) {
+ rc = efidp_duplicate_path((const_efidp)&end_entire, out);
+ if (rc < 0)
+ efi_error("efidp_duplicate_path failed");
+ return rc;
+ }
- if (dp0 && !dp1)
- return efidp_duplicate_path(dp0, out);
+ if (dp0 && !dp1) {
+ rc = efidp_duplicate_path(dp0, out);
+ if (rc < 0)
+ efi_error("efidp_duplicate_path failed");
+ return rc;
+ }
- if (!dp0 && dp1)
- return efidp_duplicate_path(dp1, out);
+ if (!dp0 && dp1) {
+ rc = efidp_duplicate_path(dp1, out);
+ if (rc < 0)
+ efi_error("efidp_duplicate_path failed");
+ return rc;
+ }
lsz = efidp_size(dp0);
- if (lsz < 0)
+ if (lsz < 0) {
+ efi_error("efidp_size(dp0) returned error");
return -1;
+ }
rsz = efidp_size(dp1);
- if (rsz < 0)
+ if (lsz < 0) {
+ efi_error("efidp_size(dp1) returned error");
return -1;
+ }
le = dp0;
while (1) {
if (efidp_type(le) == EFIDP_END_TYPE &&
efidp_subtype(le) == EFIDP_END_ENTIRE) {
ssize_t lesz = efidp_size(le);
- if (lesz < 0)
- return -1;
lsz -= lesz;
break;
}
rc = efidp_get_next_end(le, &le);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("efidp_get_next_end() returned error");
return -1;
+ }
}
efidp new;
if (add(lsz, rsz, &newsz)) {
errno = EOVERFLOW;
+ efi_error("arithmetic overflow computing allocation size");
return -1;
}
new = malloc(newsz);
- if (!new)
+ if (!new) {
+ efi_error("allocation failed");
return -1;
+ }
*out = new;
memcpy(new, dp0, lsz);
ssize_t lsz, rsz, newsz;
int rc;
- if (!dp && !dn)
- return efidp_duplicate_path((const_efidp)(const efidp_header * const)&end_entire, out);
+ if (!dp && !dn) {
+ rc = efidp_duplicate_path(
+ (const_efidp)(const efidp_header * const)&end_entire,
+ out);
+ if (rc < 0)
+ efi_error("efidp_duplicate_path() failed");
+ return rc;
+ }
lsz = efidp_size(dp);
- if (lsz < 0)
+ if (lsz < 0) {
+ efi_error("efidp_size(dp) returned error");
return -1;
+ }
+ if (dp && !dn) {
+ rc = efidp_duplicate_path(dp, out);
+ if (rc < 0)
+ efi_error("efidp_duplicate_path() failed");
+ return rc;
+ }
+
+ lsz = efidp_size(dp);
+ if (lsz < 0)
+ return -1;
- if (dp && !dn)
- return efidp_duplicate_path(dp, out);
rsz = efidp_node_size(dn);
if (rsz < 0)
if (!dp && dn) {
if (add(rsz, sizeof(end_entire), &newsz)) {
errno = EOVERFLOW;
+ efi_error(
+ "arithmetic overflow computing allocation size");
return -1;
}
efidp new = malloc(rsz + sizeof (end_entire));
- if (!new)
+ if (!new) {
+ efi_error("allocation failed");
return -1;
+ }
memcpy(new, dn, dn->length);
memcpy((uint8_t *)new + dn->length, &end_entire,
return 0;
}
- lsz = efidp_size(dp);
- if (lsz < 0)
- return -1;
-
- rsz = efidp_node_size(dn);
- if (rsz < 0)
- return -1;
-
const_efidp le;
le = dp;
while (1) {
}
rc = efidp_get_next_end(le, &le);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("efidp_get_next_end() returned error");
return -1;
+ }
}
if (add(lsz, rsz, &newsz) || add(newsz, sizeof(end_entire), &newsz)) {
errno = EOVERFLOW;
+ efi_error("arithmetic overflow computing allocation size");
return -1;
}
efidp new = malloc(newsz);
- if (!new)
+ if (!new) {
+ efi_error("allocation failed");
return -1;
+ }
*out = new;
memcpy(new, dp, lsz);
limit -= efidp_node_size(dp);
int rc = efidp_next_node(dp, &dp);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("could not format DP");
return rc;
+ }
}
return off+1;
}
efidp out __attribute__((unused)),
size_t size __attribute__((unused)))
{
+ efi_error("not implented");
errno = -ENOSYS;
return -1;
}
efidp out __attribute__((unused)),
size_t size __attribute__((unused)))
{
+ efi_error("not implented");
errno = -ENOSYS;
return -1;
}
if (!size)
return total_size;
if (size < total_size) {
+ efi_error("total size is bigger than size limit");
errno = ENOSPC;
return -1;
}
#include "ucs2.h"
-#define format(buf, size, off, fmt, args...) ({ \
+#define format(buf, size, off, dp_type, fmt, args...) ({ \
ssize_t _x = 0; \
if ((off) >= 0) { \
_x = snprintf(((buf)+(off)), \
((size)?((size)-(off)):0), \
fmt, ## args); \
- if (_x < 0) \
+ if (_x < 0) { \
+ efi_error( \
+ "could not build %s DP string", \
+ (dp_type)); \
return _x; \
+ } \
(off) += _x; \
} \
off; \
})
-#define format_helper(fn, buf, size, off, args...) ({ \
+#define format_helper(fn, buf, size, off, dp_type, args...) ({ \
ssize_t _x; \
_x = (fn)(((buf)+(off)), \
- ((size)?((size)-(off)):0), ## args); \
+ ((size)?((size)-(off)):0), dp_type, ## args); \
if (_x < 0) \
+ efi_error("could not build %s DP string", \
+ dp_type); \
(off) += _x; \
})
(void *)__newbuf; \
})
-#define format_guid(buf, size, off, guid) ({ \
+#define format_guid(buf, size, off, dp_type, guid) ({ \
int _rc; \
char *_guidstr = NULL; \
\
_rc = efi_guid_to_str(guid, &_guidstr); \
- format(buf, size, off, "%s", _guidstr); \
+ if (_rc < 0) { \
+ efi_error("could not build %s GUID DP string", \
+ dp_type); \
+ } else { \
+ _guidstr = onstack(_guidstr, \
+ strlen(_guidstr)+1); \
+ _rc = format(buf, size, off, dp_type, "%s", \
+ _guidstr); \
+ } \
+ _rc; \
})
static inline ssize_t
__attribute__((__unused__))
-format_hex_helper(char *buf, size_t size, const void * const addr,
- const size_t len)
+format_hex_helper(char *buf, size_t size, const char *dp_type,
+ const void * const addr, const size_t len)
{
ssize_t off = 0;
for (size_t i = 0; i < len; i++) {
- format(buf, size, off, "%02x",
+ format(buf, size, off, dp_type, "%02x",
*((const unsigned char * const )addr+i));
}
return off;
}
-#define format_hex(buf, size, off, addr, len) \
- format_helper(format_hex_helper, buf, size, off, addr, len)
+#define format_hex(buf, size, off, dp_type, addr, len) \
+ format_helper(format_hex_helper, buf, size, off, dp_type, addr, len)
static inline ssize_t
__attribute__((__unused__))
return off;
}
-#define format_vendor(buf, size, off, label, dp) \
+#define format_vendor(buf, size, off, label, dp) \
format_helper(format_vendor_helper, buf, size, off, label, dp)
-#define format_ucs2(buf, size, off, str, len) ({ \
+#define format_ucs2(buf, size, off, dp_type, str, len) ({ \
uint16_t _ucs2buf[(len)]; \
memset(_ucs2buf, '\0', sizeof (_ucs2buf)); \
memcpy(_ucs2buf, str, sizeof (_ucs2buf) \
if (_asciibuf == NULL) \
return -1; \
_asciibuf = onstack(_asciibuf, (len)); \
- format(buf, size, off, "%s", _asciibuf); \
+ format(buf, size, off, dp_type, "%s", _asciibuf); \
})
-#define format_array(buf, size, off, fmt, type, addr, len) ({ \
+#define format_array(buf, size, off, dp_type, fmt, type, addr, len) ({ \
for (size_t _i = 0; _i < len; _i++) { \
if (_i != 0) \
- format(buf, size, off, ","); \
- format(buf, size, off, fmt, \
+ format(buf, size, off, dp_type, ","); \
+ format(buf, size, off, dp_type, fmt, \
((type *)addr)[_i]); \
} \
- (off); \
+ off; \
})
extern ssize_t _format_hw_dn(char *buf, size_t size, const_efidp dp);
*/
#include <ctype.h>
+#include <err.h>
#include <fcntl.h>
#include <popt.h>
#include <stdio.h>
""
};
+static int verbose_errors = 0;
+
+static void
+show_errors(void)
+{
+ int rc = 0;
+
+ if (!verbose_errors)
+ return;
+
+ printf("Error trace:\n");
+ for (int i = 0; rc > 0; i++) {
+ char *filename = NULL;
+ char *function = NULL;
+ int line = 0;
+ char *message = NULL;
+ int error = 0;
+
+ rc = efi_error_get(i, &filename, &function, &line, &message,
+ &error);
+ if (rc < 0)
+ err(1, "error fetching trace value");
+ if (rc == 0)
+ break;
+ printf(" %s:%d %s(): %s: %s", filename, line, function,
+ strerror(error), message);
+ }
+}
+
static void
list_all_variables(void)
{
if (rc < 0) {
fprintf(stderr, "efivar: error listing variables: %m\n");
+ show_errors();
exit(1);
}
}
if (right[1] != '-' || right[2] == '\0') {
bad_name:
errno = -EINVAL;
- fprintf(stderr, "efivar: invalid name \"%s\"\n", guid_name);
+ fprintf(stderr, "efivar: invalid name \"%s\"\n",
+ guid_name);
+ show_errors();
exit(1);
}
name_pos = right + 1 - guid_name;
rc = efi_get_variable(guid, name, &data, &data_size, &attributes);
if (rc < 0) {
fprintf(stderr, "efivar: show variable: %m\n");
+ show_errors();
exit(1);
}
&old_attributes);
if (rc < 0) {
fprintf(stderr, "efivar: %m\n");
+ show_errors();
exit(1);
}
if (rc < 0) {
fprintf(stderr, "efivar: %m\n");
+ show_errors();
exit(1);
}
}
{
if (name == NULL) {
fprintf(stderr, "Invalid variable name\n");
+ show_errors();
exit(1);
}
}
typeof(buf.f_type) magic = EFIVARFS_MAGIC;
if (!memcmp(&buf.f_type, &magic, sizeof (magic)))
return 1;
+ else
+ efi_error("bad fs type for %s", path);
tmp = getenv("EFIVARFS_PATH");
- if (tmp && !strcmp(tmp, path))
+ if (tmp && !strcmp(tmp, path)) {
+ efi_error_clear();
return 1;
+ }
+ } else {
+ efi_error("statfs(%s) failed", path);
}
+ } else {
+ efi_error("access(%s, F_OK) failed", path);
}
return 0;
if (rc < 0) {
if (errno == ENOTTY)
rc = 0;
+ else
+ efi_error("ioctl(%d, FS_IOC_GETFLAGS) failed", fd);
} else if ((immutable && !(flags & FS_IMMUTABLE_FL)) ||
(!immutable && (flags & FS_IMMUTABLE_FL))) {
if (immutable)
flags &= ~FS_IMMUTABLE_FL;
rc = ioctl(fd, FS_IOC_SETFLAGS, &flags);
+ if (rc < 0)
+ efi_error("ioctl(%d, FS_IOC_SETFLAGS) failed", fd);
}
return rc;
fd = open(path, O_RDONLY);
if (fd < 0) {
- if (errno == ENOTTY)
+ if (errno == ENOTTY) {
+ efi_error("open(%s, O_RDONLY) failed", path);
return 0;
- else
+ } else {
return fd;
+ }
}
rc = efivarfs_set_fd_immutable(fd, immutable);
error = errno;
close(fd);
errno = error;
+ if (rc < 0)
+ efi_error("efivarfs_set_fd_immutable(%d, %d) on %s failed",
+ fd, immutable, path);
return rc;
}
typeof(errno) errno_value;
rc = make_efivarfs_path(&path, guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("make_efivarfs_path failed");
goto err;
+ }
struct stat statbuf = { 0, };
rc = stat(path, &statbuf);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("stat(%s) failed", path);
goto err;
+ }
ret = 0;
/* Compensate for the size of the Attributes field. */
uint32_t attribs;
ret = efi_get_variable(guid, name, &data, &data_size, &attribs);
- if (ret < 0)
+ if (ret < 0) {
+ efi_error("efi_get_variable failed");
return ret;
+ }
*attributes = attribs;
if (data)
char *path;
int rc = make_efivarfs_path(&path, guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("make_efivarfs_path failed");
return -1;
+ }
int fd = open(path, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s)", path);
goto err;
+ }
rc = read(fd, &ret_attributes, sizeof (ret_attributes));
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("read failed");
goto err;
+ }
rc = read_file(fd, &ret_data, &size);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("read_file failed");
goto err;
+ }
*attributes = ret_attributes;
*data = ret_data;
{
char *path;
int rc = make_efivarfs_path(&path, guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("make_efivarfs_path failed");
return -1;
+ }
efivarfs_set_immutable(path, 0);
rc = unlink(path);
+ if (rc < 0)
+ efi_error("unlink failed");
typeof(errno) errno_value = errno;
free(path);
int ret = -1;
if (strlen(name) > 1024) {
+ efi_error("name too long (%zd of 1024)", strlen(name));
errno = EINVAL;
return -1;
}
char *path;
int rc = make_efivarfs_path(&path, guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("make_efivarfs_path failed");
return -1;
+ }
int fd = -1;
if (!access(path, F_OK) && !(attributes & EFI_VARIABLE_APPEND_WRITE)) {
rc = efi_del_variable(guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("efi_del_variable failed");
goto err;
+ }
}
fd = open(path, O_WRONLY|O_CREAT, mode);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_WRONLY|O_CREAT, mode) failed", path);
goto err;
+ }
efivarfs_set_fd_immutable(fd, 0);
memcpy(buf, &attributes, sizeof (attributes));
memcpy(buf + sizeof (attributes), data, data_size);
- rc = write(fd, buf, sizeof (attributes) + data_size);
+#if 0
+ errno = ENOSPC;
+ rc = -1;
+#else
+ rc = write(fd, buf, sizeof (attributes) + data_size);
+#endif
if (rc >= 0) {
ret = 0;
efivarfs_set_fd_immutable(fd, 1);
} else {
+ efi_error("write failed");
efivarfs_set_fd_immutable(fd, 0);
unlink(path);
}
efivarfs_append_variable(efi_guid_t guid, const char *name, uint8_t *data,
size_t data_size, uint32_t attributes)
{
+ int rc;
attributes |= EFI_VARIABLE_APPEND_WRITE;
- return efivarfs_set_variable(guid, name, data, data_size, attributes, 0);
+ rc = efivarfs_set_variable(guid, name, data, data_size, attributes, 0);
+ if (rc < 0)
+ efi_error("efivarfs_set_variable failed");
+ return rc;
}
static int
efivarfs_get_next_variable_name(efi_guid_t **guid, char **name)
{
- return generic_get_next_variable_name(get_efivarfs_path(), guid, name);
+ int rc;
+ rc = generic_get_next_variable_name(get_efivarfs_path(), guid, name);
+ if (rc < 0)
+ efi_error("generic_get_next_variable_name failed");
+ return rc;
}
static int
{
char *path;
int rc = make_efivarfs_path(&path, guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("make_efivarfs_path failed");
return -1;
+ }
rc = chmod(path, mode);
int saved_errno = errno;
+ if (rc < 0)
+ efi_error("chmod(%s,0%o) failed", path, mode);
free(path);
errno = saved_errno;
return -1;
if (!guid || !name) {
errno = EINVAL;
+ efi_error("invalid arguments");
return -1;
}
if ((*guid == NULL && *name != NULL) ||
(*guid != NULL && *name == NULL)) {
errno = EINVAL;
+ efi_error("invalid arguments");
return -1;
}
/* if dir is NULL, we're also starting over */
if (!dir) {
dir = opendir(path);
- if (!dir)
+ if (!dir) {
+ efi_error("opendir(%s) failed", path);
return -1;
+ }
int fd = dirfd(dir);
if (fd < 0) {
typeof(errno) errno_value = errno;
+ efi_error("dirfd failed");
closedir(dir);
errno = errno_value;
return -1;
}
int flags = fcntl(fd, F_GETFD);
if (flags < 0) {
- warn("fcntl(fd, F_GETFD) failed");
+ efi_error("fcntl(fd, F_GETFD) failed");
} else {
flags |= FD_CLOEXEC;
if (fcntl(fd, F_SETFD, flags) < 0)
- warn("fcntl(fd, F_SETFD, "
- "flags | FD_CLOEXEC) failed");
+ efi_error("fcntl(fd, F_SETFD, flags | FD_CLOEXEC) failed");
}
*guid = NULL;
closedir(dir);
dir = NULL;
errno = EINVAL;
+ efi_error("text_to_guid failed");
return -1;
}
attributes &= ~EFI_VARIABLE_APPEND_WRITE;
rc = efi_del_variable(guid, name);
if (rc < 0) {
+ efi_error("efi_del_variable failed");
free(data);
free(d);
return rc;
* let our caller attempt to clean up :/
*/
rc = efi_set_variable(guid, name, d, ds, attributes, 0600);
+ if (rc < 0)
+ efi_error("efi_set_variable failed");
free(d);
free(data);
- return rc;
} else if (errno == ENOENT) {
data = new_data;
data_size = new_data_size;
attributes = new_attributes & ~EFI_VARIABLE_APPEND_WRITE;
rc = efi_set_variable(guid, name, data, data_size,
attributes, 0600);
- return rc;
}
+ if (rc < 0)
+ efi_error("efi_set_variable failed");
return rc;
}
__attribute__((__visibility__ ("default")))
efi_str_to_guid(const char *s, efi_guid_t *guid)
{
- return text_to_guid(s, guid);
+ int rc;
+ rc = text_to_guid(s, guid);
+ if (rc < 0)
+ efi_error("text_to_guid(\"%s\",...)", s);
+ return rc;
}
int
int rc = -1;
if (!sp) {
- return snprintf(NULL, 0, GUID_FORMAT,
+ rc = snprintf(NULL, 0, GUID_FORMAT,
le32_to_cpu(guid->a),
le16_to_cpu(guid->b),
le16_to_cpu(guid->c),
guid->e[0], guid->e[1], guid->e[2], guid->e[3],
guid->e[4], guid->e[5]);
} else if (sp && *sp) {
- return snprintf(*sp, GUID_LENGTH_WITH_NUL, GUID_FORMAT,
+ rc = snprintf(*sp, GUID_LENGTH_WITH_NUL, GUID_FORMAT,
le32_to_cpu(guid->a),
le16_to_cpu(guid->b),
le16_to_cpu(guid->c),
if (rc >= 0)
*sp = ret;
}
+ if (rc < 0)
+ efi_error("Could not format guid");
return rc;
}
if (!tmp) {
*result = NULL;
errno = ENOENT;
+ efi_error("GUID is not in common GUID list");
return -1;
}
*name = strndup(result->name, sizeof (result->name) -1);
return *name ? (int)strlen(*name) : -1;
}
- return efi_guid_to_str(guid, name);
+ rc = efi_guid_to_str(guid, name);
+ if (rc >= 0)
+ efi_error_clear();
+ return rc;
}
int
*symbol = strndup(result->symbol, sizeof (result->symbol) -1);
return *symbol ? (int)strlen(*symbol) : -1;
}
+ efi_error_clear();
errno = EINVAL;
return -1;
}
switch (hdr->type) {
case EFIDP_HARDWARE_TYPE:
if (hdr->subtype != EFIDP_HW_VENDOR &&
- hdr->length > 1024)
+ hdr->length > 1024) {
+ errno = EINVAL;
+ efi_error("invalid hardware node");
return 0;
+ }
break;
case EFIDP_ACPI_TYPE:
- if (hdr->length > 1024)
+ if (hdr->length > 1024) {
+ errno = EINVAL;
+ efi_error("invalid ACPI node");
return 0;
+ }
break;
case EFIDP_MESSAGE_TYPE:
if (hdr->subtype != EFIDP_MSG_VENDOR &&
- hdr->length > 1024)
+ hdr->length > 1024) {
+ errno = EINVAL;
+ efi_error("invalid message node");
return 0;
+ }
break;
case EFIDP_MEDIA_TYPE:
if (hdr->subtype != EFIDP_MEDIA_VENDOR &&
- hdr->length > 1024)
+ hdr->length > 1024) {
+ errno = EINVAL;
+ efi_error("invalid media node");
return 0;
+ }
break;
case EFIDP_BIOS_BOOT_TYPE:
break;
case EFIDP_END_TYPE:
- if (hdr->length > 4)
+ if (hdr->length > 4) {
+ errno = EINVAL;
+ efi_error("invalid end node");
return 0;
+ }
break;
default:
+ errno = EINVAL;
+ efi_error("invalid device path node type");
return 0;
}
- if (limit < hdr->length)
+ if (limit < hdr->length) {
+ errno = EINVAL;
+ efi_error("device path node length overruns buffer");
return 0;
+ }
limit -= hdr->length;
if (hdr->type != EFIDP_END_TYPE &&
}
if (limit < 0) {
errno = EINVAL;
+ efi_error("device path node length overruns buffer");
return 0;
}
return 1;
_efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
size_t data_size, uint32_t attributes)
{
- return ops->set_variable(guid, name, data, data_size, attributes, 0600);
+ int rc;
+ rc = ops->set_variable(guid, name, data, data_size, attributes, 0600);
+ if (rc < 0)
+ efi_error("ops->set_variable() failed");
+ return rc;
}
__asm__(".symver _efi_set_variable,_efi_set_variable@");
_efi_set_variable_variadic(efi_guid_t guid, const char *name, uint8_t *data,
size_t data_size, uint32_t attributes, ...)
{
- return ops->set_variable(guid, name, data, data_size, attributes, 0600);
+ int rc;
+ rc = ops->set_variable(guid, name, data, data_size, attributes, 0600);
+ if (rc < 0)
+ efi_error("ops->set_variable() failed");
+ return rc;
}
__asm__(".symver _efi_set_variable_variadic,efi_set_variable@");
efi_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
size_t data_size, uint32_t attributes, mode_t mode)
{
- return ops->set_variable(guid, name, data, data_size, attributes, mode);
+ int rc;
+ rc = ops->set_variable(guid, name, data, data_size, attributes, mode);
+ if (rc < 0)
+ efi_error("ops->set_variable() failed");
+ else
+ efi_error_clear();
+ return rc;
}
__asm__(".symver efi_set_variable,efi_set_variable@@LIBEFIVAR_0.24");
efi_append_variable(efi_guid_t guid, const char *name, uint8_t *data,
size_t data_size, uint32_t attributes)
{
- if (!ops->append_variable)
- return generic_append_variable(guid, name, data, data_size,
- attributes);
- return ops->append_variable(guid, name, data, data_size, attributes);
+ int rc;
+ if (!ops->append_variable) {
+ rc = generic_append_variable(guid, name, data, data_size,
+ attributes);
+ if (rc < 0)
+ efi_error("generic_append_variable() failed");
+ else
+ efi_error_clear();
+ return rc;
+ }
+ rc = ops->append_variable(guid, name, data, data_size, attributes);
+ if (rc < 0)
+ efi_error("ops->append_variable() failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
__attribute__((__visibility__ ("default")))
efi_del_variable(efi_guid_t guid, const char *name)
{
+ int rc;
if (!ops->del_variable) {
+ efi_error("del_variable() is not implemented");
errno = ENOSYS;
return -1;
}
- return ops->del_variable(guid, name);
+ rc = ops->del_variable(guid, name);
+ if (rc < 0)
+ efi_error("ops->del_variable() failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
efi_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
size_t *data_size, uint32_t *attributes)
{
+ int rc;
if (!ops->get_variable) {
+ efi_error("get_variable() is not implemented");
errno = ENOSYS;
return -1;
}
- return ops->get_variable(guid, name, data, data_size, attributes);
+ rc = ops->get_variable(guid, name, data, data_size, attributes);
+ if (rc < 0)
+ efi_error("ops->get_variable failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
efi_get_variable_attributes(efi_guid_t guid, const char *name,
uint32_t *attributes)
{
+ int rc;
if (!ops->get_variable_attributes) {
+ efi_error("get_variable_attributes() is not implemented");
errno = ENOSYS;
return -1;
}
- return ops->get_variable_attributes(guid, name, attributes);
+ rc = ops->get_variable_attributes(guid, name, attributes);
+ if (rc < 0)
+ efi_error("ops->get_variable_attributes() failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
__attribute__((__visibility__ ("default")))
efi_get_variable_size(efi_guid_t guid, const char *name, size_t *size)
{
+ int rc;
if (!ops->get_variable_size) {
+ efi_error("get_variable_size() is not implemented");
errno = ENOSYS;
return -1;
}
- return ops->get_variable_size(guid, name, size);
+ rc = ops->get_variable_size(guid, name, size);
+ if (rc < 0)
+ efi_error("ops->get_variable_size() failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
__attribute__((__visibility__ ("default")))
efi_get_next_variable_name(efi_guid_t **guid, char **name)
{
+ int rc;
if (!ops->get_next_variable_name) {
+ efi_error("get_next_variable_name() is not implemented");
errno = ENOSYS;
return -1;
}
- return ops->get_next_variable_name(guid, name);
+ rc = ops->get_next_variable_name(guid, name);
+ if (rc < 0)
+ efi_error("ops->get_next_variable_name() failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
__attribute__((__visibility__ ("default")))
efi_chmod_variable(efi_guid_t guid, const char *name, mode_t mode)
{
+ int rc;
if (!ops->chmod_variable) {
+ efi_error("chmod_variable() is not implemented");
errno = ENOSYS;
return -1;
}
- return ops->chmod_variable(guid, name, mode);
+ rc = ops->chmod_variable(guid, name, mode);
+ if (rc < 0)
+ efi_error("ops->chmod_variable() failed");
+ else
+ efi_error_clear();
+ return rc;
}
int
ops = ops_list[i];
break;
}
- } else if (ops_list[i]->probe()) {
+ } else {
+ int rc = ops_list[i]->probe();
+ if (rc <= 0)
+ efi_error("ops_list[%d]->probe() failed", i);
+ else
+ efi_error_clear();
+
ops = ops_list[i];
break;
}
int rc;
d = opendir("/sys/class/ata_device/");
- if (!d)
+ if (!d) {
+ efi_error("opendir failed on /sys/class/ata_device/");
return -1;
+ }
while ((de = readdir(d)) != NULL) {
uint32_t found_print_id;
strcat(raw_var, "/raw_var");
int fd = openat(dfd, raw_var, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("openat failed");
return -1;
+ }
char buf[4096];
ssize_t sz, total = 0;
int errno_value;
int ret = -1;
int fd = open(filename, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_RDONLY) failed", filename);
goto err;
+ }
int rc = read_file(fd, &buf, &bufsize);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("read_file(%s) failed", filename);
goto err;
+ }
long long size = strtoll((char *)buf, NULL, 0);
if ((size == LLONG_MIN || size == LLONG_MAX) && errno == ERANGE) {
char *newvar;
/* If we can't tell if it's 64bit or not, this interface is no good. */
- if (is_64bit() < 0)
+ if (is_64bit() < 0) {
+ efi_error("is_64bit() failed");
return 0;
- if (asprintfa(&newvar, "%s%s", get_vars_path(), "new_var") < 0)
+ }
+ if (asprintfa(&newvar, "%s%s", get_vars_path(), "new_var") < 0) {
+ efi_error("asprintfa failed");
return 0;
+ }
if (!access(newvar, F_OK))
return 1;
+ efi_error("access(%s, F_OK) failed", newvar);
return 0;
}
name, guid.a, guid.b, guid.c, bswap_16(guid.d),
guid.e[0], guid.e[1], guid.e[2], guid.e[3],
guid.e[4], guid.e[5]);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("asprintf failed");
goto err;
+ }
size_t retsize = 0;
rc = get_size_from_file(path, &retsize);
if (rc >= 0) {
ret = 0;
*size = retsize;
+ } else if (rc < 0) {
+ efi_error("get_size_from_file(%s) failed", path);
}
err:
errno_value = errno;
uint32_t attribs;
ret = efi_get_variable(guid, name, &data, &data_size, &attribs);
- if (ret < 0)
+ if (ret < 0) {
+ efi_error("efi_get_variable() failed");
return ret;
+ }
*attributes = attribs;
if (data)
name, guid.a, guid.b, guid.c, bswap_16(guid.d),
guid.e[0], guid.e[1], guid.e[2],
guid.e[3], guid.e[4], guid.e[5]);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("asprintf failed");
return -1;
+ }
int fd = open(path, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_RDONLY) failed", path);
goto err;
+ }
rc = read_file(fd, &buf, &bufsize);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("read_file(%s) failed", path);
goto err;
+ }
bufsize -= 1; /* read_file pads out 1 extra byte to NUL it */
if (bufsize != sizeof(efi_kernel_variable_64_t)) {
errno = EFBIG;
+ efi_error("file size is wrong for 64-bit variable (%zd of %zd)",
+ bufsize, sizeof(efi_kernel_variable_64_t));
goto err;
}
var64 = (void *)buf;
*data = malloc(var64->DataSize);
- if (!*data)
+ if (!*data) {
+ efi_error("malloc failed");
goto err;
+ }
memcpy(*data, var64->Data, var64->DataSize);
*data_size = var64->DataSize;
*attributes = var64->Attributes;
efi_kernel_variable_32_t *var32;
if (bufsize != sizeof(efi_kernel_variable_32_t)) {
+ efi_error("file size is wrong for 32-bit variable (%zd of %zd)",
+ bufsize, sizeof(efi_kernel_variable_32_t));
errno = EFBIG;
goto err;
}
var32 = (void *)buf;
*data = malloc(var32->DataSize);
- if (!*data)
+ if (!*data) {
+ efi_error("malloc failed");
goto err;
+ }
memcpy(*data, var32->Data, var32->DataSize);
*data_size = var32->DataSize;
*attributes = var32->Attributes;
name, guid.a, guid.b, guid.c, bswap_16(guid.d),
guid.e[0], guid.e[1], guid.e[2],
guid.e[3], guid.e[4], guid.e[5]);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("asprintf failed");
return -1;
+ }
uint8_t *buf = NULL;
size_t buf_size = 0;
char *delvar;
int fd = open(path, O_RDONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_RDONLY) failed", path);
goto err;
+ }
rc = read_file(fd, &buf, &buf_size);
buf_size -= 1; /* read_file pads out 1 extra byte to NUL it */
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("read_file(%s) failed", path);
goto err;
+ }
if (buf_size != sizeof(efi_kernel_variable_64_t) &&
buf_size != sizeof(efi_kernel_variable_32_t)) {
+ efi_error("variable size %zd is not 32-bit (%zd) or 64-bit (%zd)",
+ buf_size, sizeof(efi_kernel_variable_32_t),
+ sizeof(efi_kernel_variable_64_t));
+
errno = EFBIG;
goto err;
}
- if (asprintfa(&delvar, "%s%s", get_vars_path(), "del_var") < 0)
+ if (asprintfa(&delvar, "%s%s", get_vars_path(), "del_var") < 0) {
+ efi_error("asprintfa() failed");
goto err;
+ }
close(fd);
fd = open(delvar, O_WRONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_WRONLY) failed", delvar);
goto err;
+ }
rc = write(fd, buf, buf_size);
if (rc >= 0)
ret = 0;
+ else
+ efi_error("write() failed");
err:
errno_value = errno;
name, guid.a, guid.b, guid.c, bswap_16(guid.d),
guid.e[0], guid.e[1], guid.e[2], guid.e[3],
guid.e[4], guid.e[5]);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("asprintf failed");
return -1;
+ }
rc = _vars_chmod_variable(path, mode);
int saved_errno = errno;
+ efi_error("_vars_chmod_variable() failed");
free(path);
errno = saved_errno;
return rc;
int ret = -1;
if (strlen(name) > 1024) {
+ efi_error("variable name size is too large (%zd of 1024)",
+ strlen(name));
errno = EINVAL;
return -1;
}
if (data_size > 1024) {
+ efi_error("variable data size is too large (%zd of 1024)",
+ data_size);
errno = ENOSPC;
return -1;
}
name, guid.a, guid.b, guid.c, bswap_16(guid.d),
guid.e[0], guid.e[1], guid.e[2], guid.e[3],
guid.e[4], guid.e[5]);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("asprintf failed");
return -1;
+ }
len = rc;
int fd = -1;
if (!access(path, F_OK)) {
rc = efi_del_variable(guid, name);
- if (rc < 0)
+ if (rc < 0) {
+ efi_error("efi_del_variable failed");
goto err;
+ }
}
char *newvar;
- if (asprintfa(&newvar, "%s%s", get_vars_path(), "new_var") < 0)
+ if (asprintfa(&newvar, "%s%s", get_vars_path(), "new_var") < 0) {
+ efi_error("asprintfa failed");
goto err;
-
+ }
if (is_64bit()) {
efi_kernel_variable_64_t var64 = {
memcpy(var64.Data, data, data_size);
fd = open(newvar, O_WRONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_WRONLY) failed", newvar);
goto err;
+ }
rc = write(fd, &var64, sizeof(var64));
} else {
memcpy(var32.Data, data, data_size);
fd = open(newvar, O_WRONLY);
- if (fd < 0)
+ if (fd < 0) {
+ efi_error("open(%s, O_WRONLY) failed", newvar);
goto err;
+ }
rc = write(fd, &var32, sizeof(var32));
}
if (rc >= 0)
ret = 0;
+ else
+ efi_error("write() failed");
/* this is inherently racy, but there's no way to do it correctly with
* this kernel API. Fortunately, all directory contents get created
static int
vars_get_next_variable_name(efi_guid_t **guid, char **name)
{
- return generic_get_next_variable_name(get_vars_path(), guid, name);
+ int rc;
+ const char *vp = get_vars_path();
+ rc = generic_get_next_variable_name(vp, guid, name);
+ if (rc < 0)
+ efi_error("generic_get_next_variable_name(%s,...) failed", vp);
+ return rc;
}
struct efi_var_operations vars_ops = {