Skip to content

Commit

Permalink
Fix return code and impl on FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed Nov 15, 2024
1 parent 918e17d commit a88c20c
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions qefi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ extern "C" {
// Use FreeBSD system-level libefivar
#include <efivar.h>
}
#include <iostream>

int qefivar_variables_supported(void)
{
Expand All @@ -718,12 +719,13 @@ static int qefivar_get_variable_size(const QUuid &uuid, const QString &name, siz

efi_guid_t guid;
return_code = efi_str_to_guid(c_uuid, &guid);
if (return_code != 0)
if (return_code < 0)
{
return return_code;
}
return_code = efi_get_variable_size(guid, c_name, size);

return efi_get_variable_size(guid, c_name, size);
return 0;
}

static int qefivar_get_variable(QUuid &uuid, QString &name, uint8_t **data, size_t *size, uint32_t *attributes)
Expand All @@ -737,18 +739,32 @@ static int qefivar_get_variable(QUuid &uuid, QString &name, uint8_t **data, size

efi_guid_t guid;
return_code = efi_str_to_guid(c_uuid, &guid);
if (return_code != 0)
if (return_code < 0)
{
return return_code;
}

return_code = efi_get_variable_size(guid, c_name, size);
if (size == 0 || return_code != 0)
if (*size == 0 || return_code < 0)
{
return return_code;
}

return efi_get_variable(guid, c_name, data, size, attributes);
uint8_t *temp_data;
return_code = efi_get_variable(guid, c_name, &temp_data, size, attributes);
if (*size == 0 || return_code < 0)
{
return return_code;
}
// Allocate to have the same behaviour with Linux efivar
*data = (uint8_t *)malloc(*size);
std::memcpy(*data, temp_data, *size);

if (return_code < 0)
{
return return_code;
}
return 0;
}

static int qefivar_set_variable(const QUuid &uuid, const QString &name, uint8_t *data,
Expand All @@ -763,13 +779,20 @@ static int qefivar_set_variable(const QUuid &uuid, const QString &name, uint8_t

efi_guid_t guid;
return_code = efi_str_to_guid(c_uuid, &guid);
if (return_code != 0)
if (return_code < 0)
{
return return_code;
}

// Arg "mode" is not supported here
return efi_set_variable(guid, c_name, data, data_size, attributes);
return_code = efi_set_variable(guid, c_name, data, data_size, attributes);

if (return_code < 0)
{
return return_code;
}

return 0;
}

#else
Expand Down

0 comments on commit a88c20c

Please sign in to comment.