extlinux: add a --menu-save option
authorThomas Bächler <thomas@archlinux.org>
Mon, 7 Jun 2010 19:23:46 +0000 (21:23 +0200)
committerH. Peter Anvin <hpa@linux.intel.com>
Mon, 7 Jun 2010 21:54:25 +0000 (14:54 -0700)
Add the --menu-save option to set the MENU SAVE value from the running
system using extlinux.

From: Thomas Bächler <thomas@archlinux.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
extlinux/main.c
libinstaller/syslxopt.c
libinstaller/syslxopt.h
man/extlinux.1

index 0669bb9..8a0ac63 100644 (file)
@@ -381,6 +381,13 @@ int modify_adv(void)
            rv = -1;
        }
     }
+    if (opt.menu_save) {
+        if (syslinux_setadv(ADV_MENUSAVE, strlen(opt.menu_save), opt.menu_save)) {
+           fprintf(stderr, "%s: not enough space for menu-save label\n",
+                   program);
+           rv = -1;
+        }
+    }
 
     return rv;
 }
@@ -877,7 +884,7 @@ int main(int argc, char *argv[])
        usage(EX_USAGE, 0);
 
     if (opt.update_only == -1) {
-       if (opt.reset_adv || opt.set_once)
+       if (opt.reset_adv || opt.set_once || opt.menu_save)
            return modify_existing_adv(opt.directory);
        else
            usage(EX_USAGE, 0);
index 7718de3..728b19e 100644 (file)
@@ -38,6 +38,7 @@ struct sys_options opt = {
     .directory = NULL,
     .device = NULL,
     .offset = 0,
+    .menu_save = NULL,
 };
 
 const struct option long_options[] = {
@@ -55,10 +56,11 @@ const struct option long_options[] = {
     {"once", 1, NULL, 'o'},
     {"clear-once", 0, NULL, 'O'},
     {"reset-adv", 0, NULL, OPT_RESET_ADV},
+    {"menu-save", 1, NULL, 'M'},
     {0, 0, 0, 0}
 };
 
-const char short_options[] = "id:f:UuzS:H:rvho:O";
+const char short_options[] = "id:f:UuzS:H:rvho:OM:";
 
 void __attribute__ ((noreturn)) usage(int rv, int mode)
 {
@@ -83,6 +85,7 @@ void __attribute__ ((noreturn)) usage(int rv, int mode)
            "  --once=...   -o  Execute a command once upon boot\n"
            "  --clear-once -O  Clear the boot-once command\n"
            "  --reset-adv      Reset auxilliary data\n"
+           "  --menu-save= -M  Set the label to select as default on the next boot\n"
            "\n"
            "  Note: geometry is determined at boot time for devices which\n"
            "  are considered hard disks by the BIOS.  Unfortunately, this is\n"
@@ -155,6 +158,9 @@ void parse_options(int argc, char *argv[], int mode)
        case OPT_RESET_ADV:
            opt.reset_adv = 1;
            break;
+       case 'M':
+           opt.menu_save = optarg;
+           break;
        case 'v':
            fputs(program, stderr);
            fputs(" " VERSION_STR
index d925fa3..dfa6dc7 100644 (file)
@@ -13,6 +13,7 @@ struct sys_options {
     const char *directory;
     const char *device;
     unsigned int offset;
+    const char *menu_save;
 };
 
 enum long_only_opt {
index 426eeb3..c29f524 100644 (file)
@@ -28,6 +28,9 @@ Clear the boot-once command.
 \fB\-o\fR, \fB\-\-once\fR=\fIcommand\fR
 Execute a command once upon boot.
 .TP
+\fB\-M\fR, \fB\-\-menu\-save\fR=\fIlabel\fR
+Set the label to select as default on the next boot
+.TP
 \fB\-r\fR, \fB\-\-raid\fR
 Fall back to the next device on boot failure.
 .TP