27
27
28
28
GRUB_MOD_LICENSE ("GPLv3+" );
29
29
30
- typedef struct handle_list
30
+ struct grub_efi_already_handled
31
31
{
32
+ struct grub_efi_already_handled * next ;
33
+ struct grub_efi_already_handled * * prev ;
32
34
grub_efi_handle_t handle ;
33
- struct handle_list * next ;
34
- } handle_list_t ;
35
+ };
35
36
36
- static handle_list_t * already_handled = NULL ;
37
+ static struct grub_efi_already_handled * already_handled ;
37
38
38
- static grub_err_t
39
- add_handle (grub_efi_handle_t handle )
40
- {
41
- handle_list_t * e ;
42
- e = grub_malloc (sizeof (* e ));
43
- if (! e )
44
- return grub_errno ;
45
- e -> handle = handle ;
46
- e -> next = already_handled ;
47
- already_handled = e ;
48
- return GRUB_ERR_NONE ;
49
- }
50
-
51
- static int
39
+ static struct grub_efi_already_handled *
52
40
is_in_list (grub_efi_handle_t handle )
53
41
{
54
- handle_list_t * e ;
55
- for (e = already_handled ; e != NULL ; e = e -> next )
42
+ struct grub_efi_already_handled * e ;
43
+
44
+ FOR_LIST_ELEMENTS (e , already_handled )
56
45
if (e -> handle == handle )
57
- return 1 ;
58
- return 0 ;
46
+ return e ;
47
+
48
+ return NULL ;
59
49
}
60
50
61
51
static void
62
52
free_handle_list (void )
63
53
{
64
- handle_list_t * e ;
54
+ struct grub_efi_already_handled * e ;
65
55
while ((e = already_handled ) != NULL )
66
56
{
67
57
already_handled = already_handled -> next ;
@@ -105,16 +95,21 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
105
95
if (argc != 1 )
106
96
return grub_error (GRUB_ERR_BAD_ARGUMENT , N_ ("one argument expected" ));
107
97
108
- if (grub_strcmp (args [0 ], N_ ( "pciroot" ) ) == 0 )
98
+ if (grub_strcmp (args [0 ], "pciroot" ) == 0 )
109
99
{
110
100
items = pciroot_items ;
111
101
nitems = ARRAY_SIZE (pciroot_items );
112
102
}
113
- else if (grub_strcmp (args [0 ], N_ ( "scsi" ) ) == 0 )
103
+ else if (grub_strcmp (args [0 ], "scsi" ) == 0 )
114
104
{
115
105
items = scsi_items ;
116
106
nitems = ARRAY_SIZE (scsi_items );
117
107
}
108
+ else if (grub_strcmp (args [0 ], N_ ("all" )) == 0 )
109
+ {
110
+ items = NULL ;
111
+ nitems = 1 ;
112
+ }
118
113
else
119
114
return grub_error (GRUB_ERR_BAD_ARGUMENT ,
120
115
N_ ("unexpected argument `%s'" ), args [0 ]);
@@ -127,10 +122,15 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
127
122
128
123
loop :
129
124
loop ++ ;
130
- grub_dprintf ("efi" , "step '%s' loop %d:\n" , items [s ].name , loop );
131
-
132
- handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL ,
133
- & items [s ].guid , 0 , & num_handles );
125
+ if (items != NULL )
126
+ {
127
+ grub_dprintf ("efi" , "step '%s' loop %d:\n" , items [s ].name , loop );
128
+ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL ,
129
+ & items [s ].guid , 0 , & num_handles );
130
+ }
131
+ else
132
+ handles = grub_efi_locate_handle (GRUB_EFI_ALL_HANDLES ,
133
+ NULL , NULL , & num_handles );
134
134
135
135
if (!handles )
136
136
continue ;
@@ -142,15 +142,15 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
142
142
unsigned j ;
143
143
144
144
/* Skip already handled handles */
145
- if (is_in_list (handle ))
145
+ if (is_in_list (handle ) != NULL )
146
146
{
147
147
grub_dprintf ("efi" , " handle %p: already processed\n" ,
148
148
handle );
149
149
continue ;
150
150
}
151
151
152
152
status = grub_efi_connect_controller (handle , NULL , NULL ,
153
- items [s ].flags & SEARCHED_ITEM_FLAG_RECURSIVE ? 1 : 0 );
153
+ ! items || items [s ].flags & SEARCHED_ITEM_FLAG_RECURSIVE ? 1 : 0 );
154
154
if (status == GRUB_EFI_SUCCESS )
155
155
{
156
156
connected ++ ;
@@ -161,15 +161,18 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
161
161
grub_dprintf ("efi" , " handle %p: failed to connect (%d)\n" ,
162
162
handle , (grub_efi_int8_t ) status );
163
163
164
- if ((grub_err = add_handle (handle )) != GRUB_ERR_NONE )
164
+ struct grub_efi_already_handled * item = grub_malloc (sizeof (* item ));
165
+ if (!item )
165
166
break ; /* fatal */
167
+ grub_list_push (GRUB_AS_LIST_P (& already_handled ), GRUB_AS_LIST (item ));
168
+ item -> handle = handle ;
166
169
}
167
170
168
171
grub_free (handles );
169
172
if (grub_err != GRUB_ERR_NONE )
170
173
break ; /* fatal */
171
174
172
- if (items [s ].flags & SEARCHED_ITEM_FLAG_LOOP && connected )
175
+ if (items && items [s ].flags & SEARCHED_ITEM_FLAG_LOOP && connected )
173
176
{
174
177
connected = 0 ;
175
178
goto loop ;
@@ -191,12 +194,15 @@ static grub_command_t cmd;
191
194
GRUB_MOD_INIT (connectefi )
192
195
{
193
196
cmd = grub_register_command ("connectefi" , grub_cmd_connectefi ,
194
- N_ ("pciroot|scsi" ),
197
+ /* TRANSLATORS: only translate 'all' keyword */
198
+ N_ ("pciroot|scsi|all" ),
195
199
N_ ("Connect EFI handles."
196
200
" If 'pciroot' is specified, connect PCI"
197
201
" root EFI handles recursively."
198
202
" If 'scsi' is specified, connect SCSI"
199
- " I/O EFI handles recursively." ));
203
+ " I/O EFI handles recursively."
204
+ " If 'all' is specified, connect all"
205
+ " EFI handles recursively (use with care)." ));
200
206
}
201
207
202
208
GRUB_MOD_FINI (connectefi )
0 commit comments