2727
2828GRUB_MOD_LICENSE ("GPLv3+" );
2929
30- typedef struct handle_list
30+ struct grub_efi_already_handled
3131{
32+ struct grub_efi_already_handled * next ;
33+ struct grub_efi_already_handled * * prev ;
3234 grub_efi_handle_t handle ;
33- struct handle_list * next ;
34- } handle_list_t ;
35+ };
3536
36- static handle_list_t * already_handled = NULL ;
37+ static struct grub_efi_already_handled * already_handled ;
3738
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 *
5240is_in_list (grub_efi_handle_t handle )
5341{
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 )
5645 if (e -> handle == handle )
57- return 1 ;
58- return 0 ;
46+ return e ;
47+
48+ return NULL ;
5949}
6050
6151static void
6252free_handle_list (void )
6353{
64- handle_list_t * e ;
54+ struct grub_efi_already_handled * e ;
6555 while ((e = already_handled ) != NULL )
6656 {
6757 already_handled = already_handled -> next ;
@@ -105,16 +95,21 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
10595 if (argc != 1 )
10696 return grub_error (GRUB_ERR_BAD_ARGUMENT , N_ ("one argument expected" ));
10797
108- if (grub_strcmp (args [0 ], N_ ( "pciroot" ) ) == 0 )
98+ if (grub_strcmp (args [0 ], "pciroot" ) == 0 )
10999 {
110100 items = pciroot_items ;
111101 nitems = ARRAY_SIZE (pciroot_items );
112102 }
113- else if (grub_strcmp (args [0 ], N_ ( "scsi" ) ) == 0 )
103+ else if (grub_strcmp (args [0 ], "scsi" ) == 0 )
114104 {
115105 items = scsi_items ;
116106 nitems = ARRAY_SIZE (scsi_items );
117107 }
108+ else if (grub_strcmp (args [0 ], N_ ("all" )) == 0 )
109+ {
110+ items = NULL ;
111+ nitems = 1 ;
112+ }
118113 else
119114 return grub_error (GRUB_ERR_BAD_ARGUMENT ,
120115 N_ ("unexpected argument `%s'" ), args [0 ]);
@@ -127,10 +122,15 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
127122
128123loop :
129124 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 );
134134
135135 if (!handles )
136136 continue ;
@@ -142,15 +142,15 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
142142 unsigned j ;
143143
144144 /* Skip already handled handles */
145- if (is_in_list (handle ))
145+ if (is_in_list (handle ) != NULL )
146146 {
147147 grub_dprintf ("efi" , " handle %p: already processed\n" ,
148148 handle );
149149 continue ;
150150 }
151151
152152 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 );
154154 if (status == GRUB_EFI_SUCCESS )
155155 {
156156 connected ++ ;
@@ -161,15 +161,18 @@ grub_cmd_connectefi (grub_command_t cmd __attribute__ ((unused)),
161161 grub_dprintf ("efi" , " handle %p: failed to connect (%d)\n" ,
162162 handle , (grub_efi_int8_t ) status );
163163
164- if ((grub_err = add_handle (handle )) != GRUB_ERR_NONE )
164+ struct grub_efi_already_handled * item = grub_malloc (sizeof (* item ));
165+ if (!item )
165166 break ; /* fatal */
167+ grub_list_push (GRUB_AS_LIST_P (& already_handled ), GRUB_AS_LIST (item ));
168+ item -> handle = handle ;
166169 }
167170
168171 grub_free (handles );
169172 if (grub_err != GRUB_ERR_NONE )
170173 break ; /* fatal */
171174
172- if (items [s ].flags & SEARCHED_ITEM_FLAG_LOOP && connected )
175+ if (items && items [s ].flags & SEARCHED_ITEM_FLAG_LOOP && connected )
173176 {
174177 connected = 0 ;
175178 goto loop ;
@@ -191,12 +194,15 @@ static grub_command_t cmd;
191194GRUB_MOD_INIT (connectefi )
192195{
193196 cmd = grub_register_command ("connectefi" , grub_cmd_connectefi ,
194- N_ ("pciroot|scsi" ),
197+ /* TRANSLATORS: only translate 'all' keyword */
198+ N_ ("pciroot|scsi|all" ),
195199 N_ ("Connect EFI handles."
196200 " If 'pciroot' is specified, connect PCI"
197201 " root EFI handles recursively."
198202 " 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)." ));
200206}
201207
202208GRUB_MOD_FINI (connectefi )
0 commit comments