]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: cleanup sgi menu callbackswq
authorKarel Zak <kzak@redhat.com>
Thu, 11 Jul 2013 15:08:45 +0000 (17:08 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:07 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk-menu.c
fdisks/fdisk.c

index 20c10e7cdc08ccd56a4b69cbfd38bb08edbc2c8f..7820c646a9711244e76e50efa501ac01659df21f 100644 (file)
@@ -49,6 +49,7 @@ struct menu_context {
 
 DECLARE_MENU_CB(gpt_menu_cb);
 DECLARE_MENU_CB(sun_menu_cb);
+DECLARE_MENU_CB(sgi_menu_cb);
 DECLARE_MENU_CB(geo_menu_cb);
 DECLARE_MENU_CB(dos_menu_cb);
 DECLARE_MENU_CB(bsd_menu_cb);
@@ -170,13 +171,14 @@ struct menu menu_sun = {
 };
 
 struct menu menu_sgi = {
-/*     .callback = sgi_menu_cb, */
+       .callback = sgi_menu_cb,
        .label = FDISK_DISKLABEL_SGI,
        .entries = {
                MENU_SEP(N_("SGI")),
                MENU_ENT('a', N_("select bootable partition")),
                MENU_ENT('b', N_("edit bootfile entry")),
                MENU_ENT('c', N_("select sgi swap partition")),
+               MENU_ENT('i', N_("create SGI info")),
                { 0, NULL }
        }
 };
@@ -548,6 +550,45 @@ static int sun_menu_cb(struct fdisk_context **cxt0,
        return rc;
 }
 
+static int sgi_menu_cb(struct fdisk_context **cxt0,
+                      const struct menu *menu __attribute__((__unused__)),
+                      const struct menu_entry *ent)
+{
+       struct fdisk_context *cxt = *cxt0;
+       int rc = -EINVAL;
+       size_t n = 0;
+
+       DBG(FRONTEND, dbgprint("enter SGI menu"));
+
+       assert(cxt);
+       assert(ent);
+       assert(fdisk_is_disklabel(cxt, SGI));
+
+       if (ent->expert)
+               return rc;
+
+       switch (ent->key) {
+       case 'a':
+               rc = fdisk_ask_partnum(cxt, &n, FALSE);
+               if (!rc)
+                       rc = fdisk_partition_toggle_flag(cxt, n, SGI_FLAG_BOOT);
+               break;
+       case 'b':
+               sgi_set_bootfile(cxt);
+               break;
+       case 'c':
+               rc = fdisk_ask_partnum(cxt, &n, FALSE);
+               if (!rc)
+                       rc = fdisk_partition_toggle_flag(cxt, n, SGI_FLAG_SWAP);
+               break;
+       case 'i':
+               rc = sgi_create_info(cxt);
+               break;
+       }
+
+       return rc;
+}
+
 /*
  * This is fdisk frontend for BSD specific libfdisk functions that
  * are not expported by generic libfdisk API.
@@ -632,6 +673,17 @@ static int createlabel_menu_cb(struct fdisk_context **cxt0,
        assert(cxt);
        assert(ent);
 
+       if (ent->expert) {
+               switch (ent->key) {
+               case 'g':
+                       /* Deprecated, use 'G' in main menu, just for backward
+                        * compatibility only. */
+                       rc = fdisk_create_disklabel(cxt, "sgi");
+                       break;
+               }
+               return rc;
+       }
+
        switch (ent->key) {
                case 'g':
                        fdisk_create_disklabel(cxt, "gpt");
index 9fd43485253c31c0a5be7e92b0cdcd1227474e51..172e9ce45109c4b28c77992e487febbd12be61f8 100644 (file)
@@ -388,11 +388,6 @@ expert_command_prompt(struct fdisk_context *cxt)
                case 'd':
                        print_raw(cxt);
                        break;
-               case 'g':
-                       /* Deprecated, use 'G' in main menu, just for backward
-                        * compatibility only. */
-                       fdisk_create_disklabel(cxt, "sgi");
-                       break;
                case 'p':
                        list_table(cxt);
                        break;
@@ -504,36 +499,10 @@ static void command_prompt(struct fdisk_context *cxt)
                 * are not yet implemented by menu callbacks. Let's
                 * perform the commands here */
                switch (c) {
-               case 'a':
-                       if (fdisk_is_disklabel(cxt, SGI) &&
-                                fdisk_ask_partnum(cxt, &n, FALSE) == 0)
-                               fdisk_partition_toggle_flag(cxt, n, SGI_FLAG_BOOT);
-                       else
-                               unknown_command(c);
-                       break;
-               case 'b':
-                       if (fdisk_is_disklabel(cxt, SGI))
-                               sgi_set_bootfile(cxt);
-                       else
-                               unknown_command(c);
-                       break;
-               case 'c':
-                       if (fdisk_is_disklabel(cxt, SGI) &&
-                                fdisk_ask_partnum(cxt, &n, FALSE) == 0)
-                               fdisk_partition_toggle_flag(cxt, n, SGI_FLAG_SWAP);
-                       else
-                               unknown_command(c);
-                       break;
                case 'd':
                        if (fdisk_ask_partnum(cxt, &n, FALSE) == 0)
                                delete_partition(cxt, n);
                        break;
-               case 'i':
-                       if (fdisk_is_disklabel(cxt, SGI))
-                               sgi_create_info(cxt);
-                       else
-                               unknown_command(c);
-                       break;
                case 'l':
                        list_partition_types(cxt);
                        break;