@@ -678,16 +678,6 @@ void qefi_set_variable(QUuid uuid, QString name, QByteArray value)
678
678
679
679
#else
680
680
/* Implementation based on libefivar */
681
- extern " C" {
682
- #include < fcntl.h>
683
- #include < stdio.h>
684
- #include < unistd.h>
685
- #include < stdlib.h>
686
-
687
- #include < sys/ioctl.h>
688
- #include < sys/stat.h>
689
- #include < sys/types.h>
690
-
691
681
#define EFI_VARIABLE_NON_VOLATILE ((uint64_t )0x0000000000000001 )
692
682
#define EFI_VARIABLE_BOOTSERVICE_ACCESS ((uint64_t )0x0000000000000002 )
693
683
#define EFI_VARIABLE_RUNTIME_ACCESS ((uint64_t )0x0000000000000004 )
@@ -696,13 +686,101 @@ extern "C" {
696
686
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS ((uint64_t )0x0000000000000020 )
697
687
#define EFI_VARIABLE_APPEND_WRITE ((uint64_t )0x0000000000000040 )
698
688
#define EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS ((uint64_t )0x0000000000000080 )
699
- }
700
689
701
690
#include < QByteArray>
702
691
#include < QFile>
703
692
#include < QFileInfo>
704
693
705
694
/* Get rid of efivar */
695
+ #if defined(Q_OS_FREEBSD)
696
+
697
+ extern " C" {
698
+ // Use FreeBSD system-level libefivar
699
+ #include < efivar.h>
700
+ }
701
+
702
+ int qefivar_variables_supported (void )
703
+ {
704
+ return efi_variables_supported ();
705
+ }
706
+
707
+ static int qefivar_get_variable_size (const QUuid &uuid, const QString &name, size_t *size)
708
+ {
709
+ int return_code;
710
+
711
+ std::string std_name = name.toStdString ();
712
+ const char *c_name = std_name.c_str ();
713
+ std::string std_uuid = uuid.toString (QUuid::WithoutBraces).toStdString ();
714
+ const char *c_uuid = std_uuid.c_str ();
715
+
716
+ efi_guid_t guid;
717
+ return_code = efi_str_to_guid (c_uuid, &guid);
718
+ if (return_code != 0 )
719
+ {
720
+ return return_code;
721
+ }
722
+
723
+ return efi_get_variable_size (guid, c_name, size);
724
+ }
725
+
726
+ static int qefivar_get_variable (QUuid &uuid, QString &name, uint8_t **data, size_t *size, uint32_t *attributes)
727
+ {
728
+ int return_code;
729
+
730
+ std::string std_name = name.toStdString ();
731
+ const char *c_name = std_name.c_str ();
732
+ std::string std_uuid = uuid.toString (QUuid::WithoutBraces).toStdString ();
733
+ const char *c_uuid = std_uuid.c_str ();
734
+
735
+ efi_guid_t guid;
736
+ return_code = efi_str_to_guid (c_uuid, &guid);
737
+ if (return_code != 0 )
738
+ {
739
+ return return_code;
740
+ }
741
+
742
+ return_code = efi_get_variable_size (guid, c_name, size);
743
+ if (size == 0 || return_code != 0 )
744
+ {
745
+ return return_code;
746
+ }
747
+
748
+ return efi_get_variable (guid, c_name, data, size, attributes);
749
+ }
750
+
751
+ static int qefi_set_variable (const QUuid &uuid, const QString &name, const uint8_t *data,
752
+ size_t data_size, uint32_t attributes, mode_t mode)
753
+ {
754
+ int return_code;
755
+
756
+ std::string std_name = name.toStdString ();
757
+ const char *c_name = std_name.c_str ();
758
+ std::string std_uuid = uuid.toString (QUuid::WithoutBraces).toStdString ();
759
+ const char *c_uuid = std_uuid.c_str ();
760
+
761
+ efi_guid_t guid;
762
+ return_code = efi_str_to_guid (c_uuid, &guid);
763
+ if (return_code != 0 )
764
+ {
765
+ return ;
766
+ }
767
+
768
+ // Arg "mode" is not supported here
769
+ return efi_set_variable (guid, c_name, data, data_size, attributes);
770
+ }
771
+
772
+ #else
773
+ extern " C" {
774
+ #include < fcntl.h>
775
+ #include < stdio.h>
776
+ #include < unistd.h>
777
+ #include < stdlib.h>
778
+
779
+ #include < sys/ioctl.h>
780
+ #include < sys/stat.h>
781
+ #include < sys/types.h>
782
+ }
783
+
706
784
static QString const default_efivarfs_path = QStringLiteral(" /sys/firmware/efi/efivars/" );
707
785
static QString efivarfs_path;
708
786
@@ -727,7 +805,7 @@ static QString get_efivarfs_path(void)
727
805
return efivarfs_path;
728
806
}
729
807
730
- int efi_variables_supported (void )
808
+ int qefivar_variables_supported (void )
731
809
{
732
810
QFileInfo fileInfo (get_efivarfs_path ());
733
811
if (!fileInfo.exists () || !fileInfo.isDir ())
@@ -758,6 +836,11 @@ static int qefivar_efivarfs_get_variable_size(const QUuid &guid, const QString &
758
836
return ret;
759
837
}
760
838
839
+ static int inline qefivar_get_variable_size (const QUuid &guid, const QString &name, size_t *size)
840
+ {
841
+ return qefivar_efivarfs_get_variable_size (guid, name, size);
842
+ }
843
+
761
844
static int qefivar_efivarfs_get_variable (QUuid &guid, QString &name, uint8_t **data, size_t *size, uint32_t *attributes)
762
845
{
763
846
int ret = -1 ;
@@ -799,6 +882,11 @@ static int qefivar_efivarfs_get_variable(QUuid &guid, QString &name, uint8_t **d
799
882
return ret;
800
883
}
801
884
885
+ static int inline qefivar_get_variable (QUuid &guid, QString &name, uint8_t **data, size_t *size, uint32_t *attributes)
886
+ {
887
+ return qefivar_efivarfs_get_variable (guid, name, data, size, attributes);
888
+ }
889
+
802
890
static int
803
891
qefi_efivarfs_del_variable (const QUuid &guid, const QString &name)
804
892
{
@@ -867,11 +955,19 @@ qefi_efivarfs_set_variable(const QUuid &guid, const QString &name, const uint8_t
867
955
errno = errno_value;
868
956
return ret;
869
957
}
958
+
959
+ static inline int
960
+ qefi_set_variable (const QUuid &guid, const QString &name, const uint8_t *data,
961
+ size_t data_size, uint32_t attributes, mode_t mode)
962
+ {
963
+ return qefi_efivarfs_set_variable (guid, name, data, data_size, attributes, mode);
964
+ }
965
+ #endif
870
966
/* End: Get rid of efivar */
871
967
872
968
bool qefi_is_available ()
873
969
{
874
- return efi_variables_supported ();
970
+ return qefivar_variables_supported ();
875
971
}
876
972
877
973
bool qefi_has_privilege ()
@@ -884,15 +980,15 @@ quint16 qefi_get_variable_uint16(QUuid uuid, QString name)
884
980
{
885
981
int return_code;
886
982
size_t var_size;
887
- return_code = qefivar_efivarfs_get_variable_size (uuid, name, &var_size);
983
+ return_code = qefivar_get_variable_size (uuid, name, &var_size);
888
984
if (var_size == 0 || return_code != 0 )
889
985
{
890
986
return 0 ;
891
987
}
892
988
893
989
uint8_t *data;
894
990
uint32_t attributes;
895
- return_code = qefivar_efivarfs_get_variable (uuid, name, &data, &var_size, &attributes);
991
+ return_code = qefivar_get_variable (uuid, name, &data, &var_size, &attributes);
896
992
897
993
quint16 value;
898
994
if (return_code != 0 )
@@ -914,15 +1010,15 @@ QByteArray qefi_get_variable(QUuid uuid, QString name)
914
1010
int return_code;
915
1011
916
1012
size_t var_size;
917
- return_code = qefivar_efivarfs_get_variable_size (uuid, name, &var_size);
1013
+ return_code = qefivar_get_variable_size (uuid, name, &var_size);
918
1014
if (var_size == 0 || return_code != 0 )
919
1015
{
920
1016
return QByteArray ();
921
1017
}
922
1018
923
1019
uint8_t *data;
924
1020
uint32_t attributes;
925
- return_code = qefivar_efivarfs_get_variable (uuid, name, &data, &var_size, &attributes);
1021
+ return_code = qefivar_get_variable (uuid, name, &data, &var_size, &attributes);
926
1022
927
1023
QByteArray value;
928
1024
if (return_code != 0 )
@@ -951,7 +1047,7 @@ void qefi_set_variable_uint16(QUuid uuid, QString name, quint16 value)
951
1047
952
1048
uint8_t buffer[2 ];
953
1049
*((uint16_t *)buffer) = qToLittleEndian<quint16>(value);
954
- return_code = qefi_efivarfs_set_variable (uuid, name, buffer, 2 ,
1050
+ return_code = qefi_set_variable (uuid, name, buffer, 2 ,
955
1051
default_write_attribute,
956
1052
0644 );
957
1053
@@ -962,7 +1058,7 @@ void qefi_set_variable(QUuid uuid, QString name, QByteArray value)
962
1058
{
963
1059
int return_code;
964
1060
965
- return_code = qefi_efivarfs_set_variable (uuid, name, (uint8_t *)value.data (), value.size (),
1061
+ return_code = qefi_set_variable (uuid, name, (uint8_t *)value.data (), value.size (),
966
1062
default_write_attribute,
967
1063
0644 );
968
1064
0 commit comments