2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; version 2 of the License.
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * You should have received a copy of the GNU General Public License
12 * along with this program; if not, write to the Free Software
13 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 * Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights
17 * Author: Ge Song <ge.song@hxt-semitech.com>
28 #include <sys/statfs.h>
29 #include <sys/types.h>
31 #include "efi/efivar.h"
33 #include "talloc/talloc.h"
35 static const struct efi_mount efi_mount = {
36 .path = "/tmp/pb-test-efivar",
37 .guid = "c9c07add-256e-4452-b911-f8d0d35a1ac7",
39 static const char v_name[] = "petitboot-test-one";
40 static const char v_data[] = "petitboot-efi-tester";
44 efi_del_variable(&efi_mount, v_name);
45 rmdir(efi_mount.path);
51 struct efi_data *efi_data;
54 __pb_log_init(stderr, true);
56 rc = mkdir(efi_mount.path, 0755);
59 pb_log("mkdir exists\n");
61 pb_log("mkdir failed: (%d) %s\n", errno,
67 if (!efi_check_mount_magic(&efi_mount, false))
70 efi_data = talloc_zero(NULL, struct efi_data);
71 efi_data->attributes = EFI_DEFALT_ATTRIBUTES;
72 efi_data->data = talloc_strdup(efi_data, v_data);
73 efi_data->data_size = sizeof(v_data);
75 if (efi_set_variable(&efi_mount, v_name, efi_data))
78 talloc_free(efi_data);
80 if (efi_get_variable(NULL, &efi_mount, v_name, &efi_data))
83 if (!efi_data->data) {
84 pb_log("No efi_data->data\n");
88 if (strcmp((char *)efi_data->data, v_data)) {
89 pb_log("Bad efi_data->data: '%s' != '%s'\n",
90 (char *)efi_data->data, v_data);
94 if (efi_del_variable(&efi_mount, v_name))
97 /* Get after delete should fail. */
98 if (!efi_get_variable(NULL, &efi_mount, v_name, &efi_data))
101 finish(EXIT_SUCCESS);