[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#773689: Actually useful debdiff



Let me try sending a proper debdiff this time. :)


diff -Nru efivar-0.15/debian/changelog efivar-0.15/debian/changelog
--- efivar-0.15/debian/changelog	2014-11-03 10:26:48.000000000 -0600
+++ efivar-0.15/debian/changelog	2014-12-17 22:28:23.000000000 -0600
@@ -1,3 +1,10 @@
+efivar (0.15-3) unstable; urgency=medium
+
+  * Partially fix #773007 by defining DataSize based on whether our kernel is
+    32/64-bit.
+
+ -- Daniel Jared Dominguez <Jared_Dominguez@Dell.com>  Wed, 17 Dec 2014 22:26:58 -0600
+
 efivar (0.15-2) unstable; urgency=medium
* Apply upstream patches (Closes: #764386)
diff -Nru efivar-0.15/debian/patches/06-efi_variable_t.patch efivar-0.15/debian/patches/06-efi_variable_t.patch
--- efivar-0.15/debian/patches/06-efi_variable_t.patch	1969-12-31 18:00:00.000000000 -0600
+++ efivar-0.15/debian/patches/06-efi_variable_t.patch	2014-12-17 22:20:45.000000000 -0600
@@ -0,0 +1,72 @@
+commit 55837047290031fb3c66bfba0438b874f5cbf3b9
+Author: Peter Jones <pjones@redhat.com>
+Date:   Tue Nov 11 16:13:49 2014 -0500
+
+    Don't name anything efi_variable_t; we're going to export that elsewhere.
+ + Signed-off-by: Peter Jones <pjones@redhat.com>
+
+diff --git a/src/efivarfs.c b/src/efivarfs.c
+index c456401..e85599f 100644
+--- a/src/efivarfs.c
++++ b/src/efivarfs.c
+@@ -39,11 +39,6 @@
+ #  define EFIVARFS_MAGIC 0xde5e81e4
+ #endif
+ +-typedef struct efi_variable_t {
+-	uint32_t	Attributes;
+-	uint8_t		Data[];
+-} __attribute__((packed)) efi_variable_t;
+-
+ static int
+ efivarfs_probe(void)
+ {
+diff --git a/src/vars.c b/src/vars.c
+index ff00860..97487f0 100644
+--- a/src/vars.c
++++ b/src/vars.c
+@@ -31,14 +31,14 @@
+ + #define VARS_PATH "/sys/firmware/efi/vars/" + +-typedef struct efi_variable_t {
++typedef struct efi_kernel_variable_t {
+ 	uint16_t	VariableName[1024/sizeof(uint16_t)];
+ 	efi_guid_t	VendorGuid;
+ 	uint64_t	DataSize;
+ 	uint8_t		Data[1024];
+ 	efi_status_t	Status;
+ 	uint32_t	Attributes;
+-} __attribute__((packed)) efi_variable_t;
++} __attribute__((packed)) efi_kernel_variable_t;
+ + static int
+ get_size_from_file(const char *filename, size_t *retsize)
+@@ -160,7 +160,7 @@ vars_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
+ 	if (rc < 0)
+ 		goto err;
+ +- efi_variable_t *var = (void *)buf;
++	efi_kernel_variable_t *var = (void *)buf;
+ + *data = malloc(var->DataSize);
+ 	if (!*data)
+@@ -207,7 +207,7 @@ vars_del_variable(efi_guid_t guid, const char *name)
+ 		goto err;
+ + rc = read_file(fd, &buf, &buf_size);
+-	if (rc < 0 || buf_size != sizeof(efi_variable_t))
++	if (rc < 0 || buf_size != sizeof(efi_kernel_variable_t))
+ 		goto err;
+ + close(fd);
+@@ -327,7 +327,7 @@ vars_set_variable(efi_guid_t guid, const char *name, uint8_t *data,
+ 			goto err;
+ 	}
+ +- efi_variable_t var = {
++	efi_kernel_variable_t var = {
+ 		.VendorGuid = guid,
+ 		.DataSize = data_size,
+ 		.Status = 0,
diff -Nru efivar-0.15/debian/patches/07-num_bits.patch efivar-0.15/debian/patches/07-num_bits.patch
--- efivar-0.15/debian/patches/07-num_bits.patch	1969-12-31 18:00:00.000000000 -0600
+++ efivar-0.15/debian/patches/07-num_bits.patch	2014-12-17 22:30:24.000000000 -0600
@@ -0,0 +1,203 @@
+Based on commit d774e3699db4d04c72cf92e53c8161e9ac7ce2e2 (HEAD, refs/remotes/upstream/master, refs/heads/upstream)
+(Slightly modified to pretend that the erroneous 487a9ea0 doesn't exist. :)
+
+Author: Peter Jones <pjones@redhat.com>
+Date:   Tue Dec 16 14:31:19 2014 -0500
+
+    Make efivar's vars.c interface choose between 32 and 64 bit at runtime.
+ + We don't actually know what size the /kernel/ interface will use until
+    we're executed, because it's defined as "unsigned long", and we don't
+    know if a 32-bit build will be run on a 32-bit or 64-bit kernel.  So in
+    this case, we figure it out from uname.
+ + This makes the assumption that all the 64-bit arches we might care about
+    (ia64, x86_64, and aarch64) have "64" in "uname -m" somewhere, and that
+    none of the 32-bit architectures do.
+ + This should resolve the conflict between 487a9ea and a01d106, and
+    resolve issue #12 .
+ + Signed-off-by: Peter Jones <pjones@redhat.com>
+
+--- a/src/vars.c
++++ b/src/vars.c
+@@ -15,15 +15,15 @@
+  * You should have received a copy of the GNU Lesser General Public License
+  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+  */
+-
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include <sys/types.h>
+ #include <sys/stat.h>
++#include <sys/types.h>
++#include <sys/utsname.h>
+ + #include "lib.h"
+ #include "generics.h"
+@@ -31,14 +31,49 @@
+ + #define VARS_PATH "/sys/firmware/efi/vars/" + +-typedef struct efi_kernel_variable_t {
++typedef struct efi_kernel_variable_32_t {
++	uint16_t	VariableName[1024/sizeof(uint16_t)];
++	efi_guid_t	VendorGuid;
++	uint32_t	DataSize;
++	uint8_t		Data[1024];
++	efi_status_t	Status;
++	uint32_t	Attributes;
++} __attribute__((packed)) efi_kernel_variable_32_t;
++
++typedef struct efi_kernel_variable_64_t {
+ 	uint16_t	VariableName[1024/sizeof(uint16_t)];
+ 	efi_guid_t	VendorGuid;
+ 	uint64_t	DataSize;
+ 	uint8_t		Data[1024];
+ 	efi_status_t	Status;
+ 	uint32_t	Attributes;
+-} __attribute__((packed)) efi_kernel_variable_t;
++} __attribute__((packed)) efi_kernel_variable_64_t;
++
++/*
++ * Is there a better way to know if you're on a 64-bit kernel than this?
++ * Submit your patch here today!
++ */
++static int
++is_64bit(void)
++{
++	struct utsname utsname;
++	char machine[sizeof(utsname.machine) + 1];
++	static int sixtyfour_bit = -1;
++
++	if (sixtyfour_bit != -1)
++		return sixtyfour_bit;
++
++	int rc = uname(&utsname);
++	if (rc < 0)
++		return rc;
++
++	strncpy(machine, utsname.machine, sizeof(utsname.machine));
++	machine[sizeof(utsname.machine)] = '\0';
++	sixtyfour_bit = 0;
++	if (strstr(machine, "64") != NULL)
++		sixtyfour_bit = 1;
++	return sixtyfour_bit;
++}
+ + static int
+ get_size_from_file(const char *filename, size_t *retsize)
+@@ -81,6 +116,9 @@
+ static int
+ vars_probe(void)
+ {
++	/* If we can't tell if it's 64bit or not, this interface is no good. */
++	if (is_64bit() < 0)
++		return 0;
+ 	if (!access(VARS_PATH "new_var", F_OK))
+ 		return 1;
+ 	return 0;
+@@ -160,14 +198,26 @@
+ 	if (rc < 0)
+ 		goto err;
+ +- efi_kernel_variable_t *var = (void *)buf; + +- *data = malloc(var->DataSize);
+-	if (!*data)
+-		goto err;
+-	memcpy(*data, var->Data, var->DataSize);
+-	*data_size = var->DataSize;
+-	*attributes = var->Attributes;
++	if (is_64bit()) {
++		efi_kernel_variable_64_t *var64 = (void *)buf;
++
++		*data = malloc(var64->DataSize);
++		if (!*data)
++			goto err;
++		memcpy(*data, var64->Data, var64->DataSize);
++		*data_size = var64->DataSize;
++		*attributes = var64->Attributes;
++	} else {
++		efi_kernel_variable_32_t *var32 = (void *)buf;
++
++		*data = malloc(var32->DataSize);
++		if (!*data)
++			goto err;
++		memcpy(*data, var32->Data, var32->DataSize);
++		*data_size = var32->DataSize;
++		*attributes = var32->Attributes;
++	}
+ + ret = 0;
+ err:
+@@ -207,7 +257,8 @@
+ 		goto err;
+ + rc = read_file(fd, &buf, &buf_size);
+-	if (rc < 0 || buf_size != sizeof(efi_kernel_variable_t))
++	if (rc < 0 || (buf_size != sizeof(efi_kernel_variable_64_t) &&
++		       buf_size != sizeof(efi_kernel_variable_32_t)))
+ 		goto err;
+ + close(fd);
+@@ -327,20 +378,41 @@
+ 			goto err;
+ 	}
+ +- efi_kernel_variable_t var = {
+-		.VendorGuid = guid,
+-		.DataSize = data_size,
+-		.Status = 0,
+-		.Attributes = attributes
+-		};
+-	for (int i = 0; name[i] != '\0'; i++)
+-		var.VariableName[i] = name[i];
+-	memcpy(var.Data, data, data_size);
++	if (is_64bit()) {
++		efi_kernel_variable_64_t var64 = {
++			.VendorGuid = guid,
++			.DataSize = data_size,
++			.Status = 0,
++			.Attributes = attributes
++			};
++
++		for (int i = 0; name[i] != '\0'; i++)
++			var64.VariableName[i] = name[i];
++		memcpy(var64.Data, data, data_size);
++
++		fd = open(VARS_PATH "new_var", O_WRONLY);
++		if (fd < 0)
++			goto err;
++
++		rc = write(fd, &var64, sizeof(var64));
++	} else {
++		efi_kernel_variable_32_t var32 = {
++			.VendorGuid = guid,
++			.DataSize = data_size,
++			.Status = 0,
++			.Attributes = attributes
++			};
++		for (int i = 0; name[i] != '\0'; i++)
++			var32.VariableName[i] = name[i];
++		memcpy(var32.Data, data, data_size);
++
++		fd = open(VARS_PATH "new_var", O_WRONLY);
++		if (fd < 0)
++			goto err;
++
++		rc = write(fd, &var32, sizeof(var32));
++	}
+ +- fd = open(VARS_PATH "new_var", O_WRONLY);
+-	if (fd < 0)
+-		goto err;
+-	rc = write(fd, &var, sizeof(var));
+ 	if (rc >= 0)
+ 		ret = 0;
+ diff -Nru efivar-0.15/debian/patches/series efivar-0.15/debian/patches/series
--- efivar-0.15/debian/patches/series	2014-11-03 10:27:26.000000000 -0600
+++ efivar-0.15/debian/patches/series	2014-12-17 22:20:45.000000000 -0600
@@ -3,3 +3,5 @@
 03-errno.patch
 04-enomem.patch
 05-8k_vars.patch
+06-efi_variable_t.patch
+07-num_bits.patch


Reply to: