From fd1e0384d9bdbfe6b00ded6e80449e47f52914fc Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 29 Jun 2007 15:42:25 +0200 Subject: added support for the "savemap" keyword Usage: savemap :: ... --- stage2/builtins.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ stage2/shared.h | 10 +++++++++ 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/stage2/builtins.c b/stage2/builtins.c index 7fe6cc6..2869db2 100644 --- a/stage2/builtins.c +++ b/stage2/builtins.c @@ -61,6 +61,8 @@ int default_entry = 0; /* The fallback entry. */ int fallback_entryno; int fallback_entries[MAX_FALLBACK_ENTRIES]; +/* the save map. Ends with saved == -1 */ +struct savemap savemap[MAX_SAVEMAP]; /* The number of current entry. */ int current_entryno; /* The address for Multiboot command-line buffer. */ @@ -100,6 +102,7 @@ init_config (void) password = 0; fallback_entryno = -1; fallback_entries[0] = -1; + savemap[0].saved = -1; grub_timeout = -1; } @@ -1193,6 +1196,59 @@ static struct builtin builtin_fallback = }; +/* savemap */ +static int +savemap_func (char *arg, int flags) +{ + int i = 0; + int saved, backup, real; + + while (*arg) + { + if (! safe_parse_maxint (&arg, &saved)) + return 1; + if (*arg++ != ':') + return 1; + if (! safe_parse_maxint (&arg, &real)) + return 1; + if (*arg++ != ':') + return 1; + if (! safe_parse_maxint (&arg, &backup)) + return 1; + + savemap[i].saved = saved; + savemap[i].real = real; + savemap[i].backup = backup; + + i++; + + if (i == MAX_SAVEMAP) + break; + + arg = skip_to (0, arg); + } + + if (i < MAX_SAVEMAP) + savemap[i].saved = -1; + + return 0; +} + +static struct builtin builtin_savemap = +{ + "savemap", + savemap_func, + BUILTIN_MENU, +#if 0 + "savemap SAVED:REAL:NEXT...", + "Define a boot sequence trying several images. Boot attemps on" + " id SAVED will be mapped to id REAL, and will be retried upon" + " next boot on id NEXT in case of failure." + " To be used with savedefault savemap." +#endif +}; + + /* find */ /* Search for the filename ARG in all of partitions. */ static int @@ -4849,6 +4905,7 @@ struct builtin *builtin_table[] = &builtin_root, &builtin_rootnoverify, &builtin_savedefault, + &builtin_savemap, #ifdef SUPPORT_SERIAL &builtin_serial, #endif /* SUPPORT_SERIAL */ diff --git a/stage2/shared.h b/stage2/shared.h index f01d6ee..0e862af 100644 --- a/stage2/shared.h +++ b/stage2/shared.h @@ -589,6 +589,7 @@ extern void assign_device_name (int drive, const char *device); #ifndef STAGE1_5 /* GUI interface variables. */ +# define MAX_SAVEMAP 16 # define MAX_FALLBACK_ENTRIES 8 extern int fallback_entries[MAX_FALLBACK_ENTRIES]; extern int fallback_entryno; @@ -839,6 +840,15 @@ struct builtin /* All the builtins are registered in this. */ extern struct builtin *builtin_table[]; +struct savemap { + int saved; + int real; + int backup; +}; + +extern struct savemap savemap[MAX_SAVEMAP]; +extern int backup_entry; + /* The constants for kernel types. */ typedef enum { -- 1.4.4.3