Skip to content

Commit e224ef7

Browse files
committed
connectefi: resync with Upstream
Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
1 parent 4f16d1a commit e224ef7

1 file changed

Lines changed: 43 additions & 40 deletions

File tree

grub-core/commands/efi/connectefi.c

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,37 @@
2121
#include <grub/efi/api.h>
2222
#include <grub/efi/pci.h>
2323
#include <grub/efi/efi.h>
24-
#include <grub/efi/disk.h>
2524
#include <grub/command.h>
2625
#include <grub/err.h>
2726
#include <grub/i18n.h>
2827

2928
GRUB_MOD_LICENSE ("GPLv3+");
3029

31-
typedef struct handle_list
30+
struct grub_efi_already_handled
3231
{
32+
struct grub_efi_already_handled *next;
33+
struct grub_efi_already_handled **prev;
3334
grub_efi_handle_t handle;
34-
struct handle_list *next;
35-
} handle_list_t;
35+
};
3636

37-
static handle_list_t *already_handled = NULL;
37+
static struct grub_efi_already_handled *already_handled;
3838

39-
static grub_err_t
40-
add_handle (grub_efi_handle_t handle)
41-
{
42-
handle_list_t *e;
43-
e = grub_malloc (sizeof (*e));
44-
if (! e)
45-
return grub_errno;
46-
e->handle = handle;
47-
e->next = already_handled;
48-
already_handled = e;
49-
return GRUB_ERR_NONE;
50-
}
51-
52-
static int
39+
static struct grub_efi_already_handled *
5340
is_in_list (grub_efi_handle_t handle)
5441
{
55-
handle_list_t *e;
56-
for (e = already_handled; e != NULL; e = e->next)
42+
struct grub_efi_already_handled *e;
43+
44+
FOR_LIST_ELEMENTS (e, already_handled)
5745
if (e->handle == handle)
58-
return 1;
59-
return 0;
46+
return e;
47+
48+
return NULL;
6049
}
6150

6251
static void
6352
free_handle_list (void)
6453
{
65-
handle_list_t *e;
54+
struct grub_efi_already_handled *e;
6655
while ((e = already_handled) != NULL)
6756
{
6857
already_handled = already_handled->next;
@@ -107,17 +96,22 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
10796
if (argc != 1)
10897
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
10998

110-
if (grub_strcmp(args[0], N_("pciroot")) == 0)
99+
if (grub_strcmp(args[0], "pciroot") == 0)
111100
{
112101
items = pciroot_items;
113102
nitems = ARRAY_SIZE (pciroot_items);
114103
}
115-
else if ((grub_strcmp(args[0], N_("scsi")) == 0) ||
116-
(grub_strcmp(args[0], N_("disk")) == 0))
104+
else if ((grub_strcmp(args[0], "disk") == 0) ||
105+
(grub_strcmp(args[0], "scsi") == 0))
117106
{
118107
items = disk_items;
119108
nitems = ARRAY_SIZE (disk_items);
120109
}
110+
else if (grub_strcmp(args[0], N_("all")) == 0)
111+
{
112+
items = NULL;
113+
nitems = 1;
114+
}
121115
else
122116
return grub_error (GRUB_ERR_BAD_ARGUMENT,
123117
N_("unexpected argument `%s'"), args[0]);
@@ -130,10 +124,15 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
130124

131125
loop:
132126
loop++;
133-
grub_dprintf ("efi", "step '%s' loop %d:\n", items[s].name, loop);
134-
135-
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL,
136-
&items[s].guid, 0, &num_handles);
127+
if (items != NULL)
128+
{
129+
grub_dprintf ("efi", "step '%s' loop %d:\n", items[s].name, loop);
130+
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL,
131+
&items[s].guid, 0, &num_handles);
132+
}
133+
else
134+
handles = grub_efi_locate_handle (GRUB_EFI_ALL_HANDLES,
135+
NULL, NULL, &num_handles);
137136

138137
if (!handles)
139138
continue;
@@ -145,15 +144,15 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
145144
unsigned j;
146145

147146
/* Skip already handled handles */
148-
if (is_in_list (handle))
147+
if (is_in_list (handle) != NULL)
149148
{
150149
grub_dprintf ("efi", " handle %p: already processed\n",
151150
handle);
152151
continue;
153152
}
154153

155154
status = grub_efi_connect_controller(handle, NULL, NULL,
156-
items[s].flags & SEARCHED_ITEM_FLAG_RECURSIVE ? 1 : 0);
155+
!items || items[s].flags & SEARCHED_ITEM_FLAG_RECURSIVE ? 1 : 0);
157156
if (status == GRUB_EFI_SUCCESS)
158157
{
159158
connected++;
@@ -164,15 +163,18 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
164163
grub_dprintf ("efi", " handle %p: failed to connect (%d)\n",
165164
handle, (grub_efi_int8_t) status);
166165

167-
if ((grub_err = add_handle (handle)) != GRUB_ERR_NONE)
166+
struct grub_efi_already_handled *item = grub_malloc(sizeof (*item));
167+
if (!item)
168168
break; /* fatal */
169+
grub_list_push (GRUB_AS_LIST_P (&already_handled), GRUB_AS_LIST (item));
170+
item->handle = handle;
169171
}
170172

171173
grub_free (handles);
172174
if (grub_err != GRUB_ERR_NONE)
173175
break; /* fatal */
174176

175-
if (items[s].flags & SEARCHED_ITEM_FLAG_LOOP && connected)
177+
if (items && items[s].flags & SEARCHED_ITEM_FLAG_LOOP && connected)
176178
{
177179
connected = 0;
178180
goto loop;
@@ -194,14 +196,15 @@ static grub_command_t cmd;
194196
GRUB_MOD_INIT(connectefi)
195197
{
196198
cmd = grub_register_command ("connectefi", grub_cmd_connectefi,
197-
N_("pciroot|scsi|disk"),
199+
/* TRANSLATORS: only translate 'all' keyword */
200+
N_("pciroot|disk|scsi|all"),
198201
N_("Connect EFI handles."
199202
" If 'pciroot' is specified, connect PCI"
200203
" root EFI handles recursively."
201-
" If 'scsi' is specified, connect SCSI"
202-
" I/O EFI handles recursively (deprecated, same as 'disk')."
203-
" If 'disk' is specified, connect disk"
204-
" I/O EFI handles recursively."));
204+
" If 'disk' or 'scsi' is specified, connect"
205+
" SCSI and DISK I/O EFI handles recursively."
206+
" If 'all' is specified, connect all"
207+
" EFI handles recursively."));
205208
}
206209

207210
GRUB_MOD_FINI(connectefi)

0 commit comments

Comments
 (0)