Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KZiQg-0006dY-Ad for mharc-grub-devel@gnu.org; Sun, 31 Aug 2008 04:37:02 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KZiQf-0006dT-2Y for grub-devel@gnu.org; Sun, 31 Aug 2008 04:37:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KZiQe-0006dH-Kw for grub-devel@gnu.org; Sun, 31 Aug 2008 04:37:00 -0400 Received: from [199.232.76.173] (port=58966 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KZiQe-0006dE-IO for grub-devel@gnu.org; Sun, 31 Aug 2008 04:37:00 -0400 Received: from gateway05.websitewelcome.com ([67.18.125.8]:36351) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1KZiQe-0008NG-4W for grub-devel@gnu.org; Sun, 31 Aug 2008 04:37:00 -0400 Received: (qmail 19659 invoked from network); 31 Aug 2008 07:01:59 -0000 Received: from gator297.hostgator.com (74.53.228.114) by gateway05.websitewelcome.com with SMTP; 31 Aug 2008 07:01:59 -0000 Received: from c-67-185-142-228.hsd1.wa.comcast.net ([67.185.142.228]:35315 helo=gamma.lan) by gator297.hostgator.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.68) (envelope-from ) id 1KZglL-0005Ep-F7 for grub-devel@gnu.org; Sun, 31 Aug 2008 01:50:15 -0500 Date: Sat, 30 Aug 2008 23:50:15 -0700 From: Colin D Bennett To: grub-devel@gnu.org Message-ID: <20080830235015.1095d788@gamma.lan> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.11; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/KzKhl66wJr_LuWODeJiZ7Ny"; protocol="application/pgp-signature"; micalg=PGP-SHA1 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator297.hostgator.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - gibibit.com X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] GSoC #04 Multiple fallback entries X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Aug 2008 08:37:01 -0000 --Sig_/KzKhl66wJr_LuWODeJiZ7Ny Content-Type: multipart/mixed; boundary="MP_/BF1bxgCNFh7EkTdMYx.0jmU" --MP_/BF1bxgCNFh7EkTdMYx.0jmU Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This patch adds support for multiple fallback entries. The entry numbers in the 'fallback' environment variable should be space-separated. Regards, Colin --MP_/BF1bxgCNFh7EkTdMYx.0jmU Content-Type: text/plain; name=04_ChangeLog.txt Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=04_ChangeLog.txt 2008-08-30 Colin D Bennett Allow multiple fallback entries. * include/grub/normal.h (grub_menu_execute_callback_t): New type. (grub_menu_execute_with_fallback): New prototype. (grub_menu_get_timeout): New prototype. (grub_menu_set_timeout): New prototype. * normal/menu.c (get_timeout): Renamed to grub_menu_get_timeout. (grub_menu_get_timeout): Renamed from get_timeout, and made global. (set_timeout): Renamed to grub_menu_set_timeout. (grub_menu_set_timeout): Renamed from set_timeout, and made global. (get_and_remove_first_entry_number): New function. (run_menu): Call grub_menu_get_timeout and grub_menu_set_timeout instead of the old function names. (grub_menu_execute_with_fallback): New function. (notify_booting): New function. (notify_fallback): New function. (notify_execution_failure): New function. (execution_callback): New struct definition. (show_menu): Use grub_menu_execute_with_fallback instead of directly handling the fallback here. --MP_/BF1bxgCNFh7EkTdMYx.0jmU Content-Type: text/x-patch; name=04_multiple-fallback.patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=04_multiple-fallback.patch =3D=3D=3D modified file 'include/grub/normal.h' --- include/grub/normal.h 2008-08-31 00:41:28 +0000 +++ include/grub/normal.h 2008-08-31 05:37:12 +0000 @@ -98,10 +98,24 @@ =20 extern struct grub_menu_viewer grub_normal_terminal_menu_viewer; =20 +typedef struct grub_menu_execute_callback +{ + void (*notify_booting) (void *userdata, grub_menu_entry_t entry); + void (*notify_fallback) (void *userdata, grub_menu_entry_t entry); + void (*notify_failure) (void *userdata); +}=20 +*grub_menu_execute_callback_t; + void grub_enter_normal_mode (const char *config); void grub_normal_execute (const char *config, int nested); +void grub_menu_execute_with_fallback (grub_menu_t menu, + grub_menu_entry_t entry, + grub_menu_execute_callback_t callbac= k, + void *callback_data); void grub_menu_entry_run (grub_menu_entry_t entry); void grub_menu_execute_entry(grub_menu_entry_t entry); +int grub_menu_get_timeout (void); +void grub_menu_set_timeout (int timeout); void grub_cmdline_run (int nested); int grub_cmdline_get (const char *prompt, char cmdline[], unsigned max_len, int echo_char, int readline); =3D=3D=3D modified file 'normal/menu.c' --- normal/menu.c 2008-08-31 00:41:28 +0000 +++ normal/menu.c 2008-08-31 05:37:12 +0000 @@ -242,8 +242,8 @@ =20 /* Return the current timeout. If the variable "timeout" is not set or invalid, return -1. */ -static int -get_timeout (void) +int +grub_menu_get_timeout (void) { char *val; int timeout; @@ -270,8 +270,8 @@ } =20 /* Set current timeout in the variable "timeout". */ -static void -set_timeout (int timeout) +void +grub_menu_set_timeout (int timeout) { /* Ignore TIMEOUT if it is zero, because it will be unset really soon. = */ if (timeout > 0) @@ -309,6 +309,43 @@ return entry; } =20 +/* Get the first entry number from the variable NAME, which is a=20 + space-separated list of nonnegative integers. The entry number which + is returned is stripped from the value of NAME. */ +static int +get_and_remove_first_entry_number (const char *name) +{ + char *val; + char *tail; + int entry; + =20 + val =3D grub_env_get (name); + if (! val) + return -1; + =20 + grub_error_push (); + =20 + entry =3D (int) grub_strtoul (val, &tail, 0); + + if (grub_errno =3D=3D GRUB_ERR_NONE) + { + /* Skip whitespace to find the next digit. */ + while (*tail && grub_isspace (*tail)) + tail++; + grub_env_set (name, tail); + } + else + { + grub_env_unset (name); + grub_errno =3D GRUB_ERR_NONE; + entry =3D -1; + } + + grub_error_pop (); + =20 + return entry; +} + static void print_timeout (int timeout, int offset, int second_stage) { @@ -341,7 +378,7 @@ default_entry =3D 0; =20 /* If timeout is 0, drawing is pointless (and ugly). */ - if (get_timeout () =3D=3D 0) + if (grub_menu_get_timeout () =3D=3D 0) return default_entry; =20 offset =3D default_entry; @@ -360,7 +397,7 @@ print_entries (menu, first, offset); grub_refresh (); =20 - timeout =3D get_timeout (); + timeout =3D grub_menu_get_timeout (); =20 if (timeout > 0) print_timeout (timeout, offset, 0); @@ -368,7 +405,7 @@ while (1) { int c; - timeout =3D get_timeout (); + timeout =3D grub_menu_get_timeout (); =20 if (timeout > 0) { @@ -378,7 +415,7 @@ if (current_time - saved_time >=3D 1000) { timeout--; - set_timeout (timeout); + grub_menu_set_timeout (timeout); saved_time =3D current_time; print_timeout (timeout, offset, 1); } @@ -508,6 +545,72 @@ grub_command_execute ("boot", 0); } =20 +/* Execute ENTRY from the menu MENU, falling back to entries specified + in the environment variable "fallback" if it fails. CALLBACK is a=20 + pointer to a struct of function pointers which are used to allow the + caller provide feedback to the user. */ +void +grub_menu_execute_with_fallback (grub_menu_t menu, + grub_menu_entry_t entry, + grub_menu_execute_callback_t callback, + void *callback_data) +{ + int fallback_entry; + + callback->notify_booting (callback_data, entry); + + grub_menu_execute_entry (entry); + + /* Deal with fallback entries. */ + while ((fallback_entry =3D get_and_remove_first_entry_number ("fallback"= )) + >=3D 0) + { + grub_print_error (); + grub_errno =3D GRUB_ERR_NONE; + + entry =3D get_entry (menu, fallback_entry); + callback->notify_fallback (callback_data, entry); + grub_menu_execute_entry (entry); + } + + if (grub_errno !=3D GRUB_ERR_NONE) + callback->notify_failure (callback_data); +} + +static void +notify_booting (void *userdata __attribute__((unused)), + grub_menu_entry_t entry) +{ + grub_printf (" Booting \'%s\'\n\n", entry->title); +} + +static void +notify_fallback (void *userdata __attribute__((unused)), + grub_menu_entry_t entry) +{ + grub_printf ("\n Falling back to \'%s\'\n\n", entry->title); + grub_millisleep (2000); +} + +static void +notify_execution_failure (void *userdata __attribute__((unused))) +{ + if (grub_errno !=3D GRUB_ERR_NONE) + { + grub_print_error (); + grub_errno =3D GRUB_ERR_NONE; + + grub_wait_after_message (); + } +} + +static struct grub_menu_execute_callback execution_callback =3D=20 +{ + .notify_booting =3D notify_booting, + .notify_fallback =3D notify_fallback, + .notify_failure =3D notify_execution_failure +}; + static grub_err_t show_menu (grub_menu_t menu, int nested) { @@ -515,8 +618,7 @@ { int boot_entry; grub_menu_entry_t e; - int fallback_entry; - =20 + boot_entry =3D run_menu (menu, nested); if (boot_entry < 0) break; @@ -524,35 +626,11 @@ e =3D get_entry (menu, boot_entry); if (! e) continue; /* Menu is empty. */ -=09 + grub_cls (); grub_setcursor (1); =20 - grub_printf (" Booting \'%s\'\n\n", e->title); - =20 - grub_menu_execute_entry (e); - - /* Deal with a fallback entry. */ - /* FIXME: Multiple fallback entries like GRUB Legacy. */ - fallback_entry =3D get_entry_number ("fallback"); - if (fallback_entry >=3D 0) - { - grub_print_error (); - grub_errno =3D GRUB_ERR_NONE; - =20 - e =3D get_entry (menu, fallback_entry); - grub_env_unset ("fallback"); - grub_printf ("\n Falling back to \'%s\'\n\n", e->title); - grub_menu_execute_entry (e); - } - - if (grub_errno !=3D GRUB_ERR_NONE) - { - grub_print_error (); - grub_errno =3D GRUB_ERR_NONE; - - grub_wait_after_message (); - } + grub_menu_execute_with_fallback (menu, e, &execution_callback, 0); } =20 return GRUB_ERR_NONE; --MP_/BF1bxgCNFh7EkTdMYx.0jmU-- --Sig_/KzKhl66wJr_LuWODeJiZ7Ny Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAki6PykACgkQokx8fzcGbYd3VQCeOXXWit1ksqRXaBS2pFYzfQDj OL0AnRb/9KMPuW7exK9TLlBQNKmWOpkH =3LNL -----END PGP SIGNATURE----- --Sig_/KzKhl66wJr_LuWODeJiZ7Ny--