Skip to content

Commit a88c20c

Browse files
committed
Fix return code and impl on FreeBSD
1 parent 918e17d commit a88c20c

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

qefi.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ extern "C" {
701701
// Use FreeBSD system-level libefivar
702702
#include <efivar.h>
703703
}
704+
#include <iostream>
704705

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

719720
efi_guid_t guid;
720721
return_code = efi_str_to_guid(c_uuid, &guid);
721-
if (return_code != 0)
722+
if (return_code < 0)
722723
{
723724
return return_code;
724725
}
726+
return_code = efi_get_variable_size(guid, c_name, size);
725727

726-
return efi_get_variable_size(guid, c_name, size);
728+
return 0;
727729
}
728730

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

738740
efi_guid_t guid;
739741
return_code = efi_str_to_guid(c_uuid, &guid);
740-
if (return_code != 0)
742+
if (return_code < 0)
741743
{
742744
return return_code;
743745
}
744746

745747
return_code = efi_get_variable_size(guid, c_name, size);
746-
if (size == 0 || return_code != 0)
748+
if (*size == 0 || return_code < 0)
747749
{
748750
return return_code;
749751
}
750752

751-
return efi_get_variable(guid, c_name, data, size, attributes);
753+
uint8_t *temp_data;
754+
return_code = efi_get_variable(guid, c_name, &temp_data, size, attributes);
755+
if (*size == 0 || return_code < 0)
756+
{
757+
return return_code;
758+
}
759+
// Allocate to have the same behaviour with Linux efivar
760+
*data = (uint8_t *)malloc(*size);
761+
std::memcpy(*data, temp_data, *size);
762+
763+
if (return_code < 0)
764+
{
765+
return return_code;
766+
}
767+
return 0;
752768
}
753769

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

764780
efi_guid_t guid;
765781
return_code = efi_str_to_guid(c_uuid, &guid);
766-
if (return_code != 0)
782+
if (return_code < 0)
767783
{
768784
return return_code;
769785
}
770786

771787
// Arg "mode" is not supported here
772-
return efi_set_variable(guid, c_name, data, data_size, attributes);
788+
return_code = efi_set_variable(guid, c_name, data, data_size, attributes);
789+
790+
if (return_code < 0)
791+
{
792+
return return_code;
793+
}
794+
795+
return 0;
773796
}
774797

775798
#else

0 commit comments

Comments
 (0)