]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: (bsd) implement regular bsd menu callback
authorKarel Zak <kzak@redhat.com>
Wed, 10 Jul 2013 12:54:25 +0000 (14:54 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:47:06 +0000 (16:47 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk-menu.c
fdisks/fdisk.c
fdisks/fdiskbsdlabel.c
fdisks/fdiskbsdlabel.h

index 7bbca6f494c919306a4f4fa68d8ca471c83daa5e..7adf003b7f65580bad5d195870fc7116fed58b99 100644 (file)
@@ -53,6 +53,7 @@ DECLARE_MENU_CB(gpt_menu_cb);
 DECLARE_MENU_CB(sun_menu_cb);
 DECLARE_MENU_CB(geo_menu_cb);
 DECLARE_MENU_CB(dos_menu_cb);
+DECLARE_MENU_CB(bsd_menu_cb);
 
 /*
  * Menu entry macros:
@@ -199,16 +200,14 @@ struct menu menu_dos = {
 };
 
 struct menu menu_bsd = {
-/*     .callback = bsd_menu_cb,*/
+       .callback = bsd_menu_cb,
        .label = FDISK_DISKLABEL_OSF,
        .entries = {
                MENU_SEP(N_("BSD")),
                MENU_ENT('e', N_("edit drive data")),
                MENU_ENT('i', N_("install bootstrap")),
                MENU_ENT('s', N_("show complete disklabel")),
-#if !defined (__alpha__)
                MENU_ENT('x', N_("link BSD partition to non-BSD partition")),
-#endif
                { 0, NULL }
        }
 };
@@ -550,6 +549,40 @@ static int sun_menu_cb(struct fdisk_context **cxt0,
        return rc;
 }
 
+/*
+ * This is fdisk frontend for BSD specific libfdisk functions that
+ * are not expported by generic libfdisk API.
+ */
+static int bsd_menu_cb(struct fdisk_context **cxt0,
+                      const struct menu *menu __attribute__((__unused__)),
+                      const struct menu_entry *ent)
+{
+       struct fdisk_context *cxt = *cxt0;
+       int rc = 0;
+
+       assert(cxt);
+       assert(ent);
+       assert(fdisk_is_disklabel(cxt, OSF));
+
+       DBG(FRONTEND, dbgprint("enter BSD menu"));
+
+       switch(ent->key) {
+       case 'e':
+               rc = fdisk_bsd_edit_disklabel(cxt);
+               break;
+       case 'i':
+               rc = fdisk_bsd_write_bootstrap(cxt);
+               break;
+       case 's':
+               xbsd_print_disklabel(cxt, 1);
+               break;
+       case 'x':
+               rc = fdisk_bsd_link_partition(cxt);
+               break;
+       }
+       return rc;
+}
+
 /* C/H/S commands */
 static int geo_menu_cb(struct fdisk_context **cxt0,
                       const struct menu *menu __attribute__((__unused__)),
index 4bae2375548b8dd3b17ba225a6fdc2ad6d150752..34db0a1b1e1346ebf1378d71933ed651e1814a47 100644 (file)
@@ -500,18 +500,6 @@ static void command_prompt(struct fdisk_context *cxt)
 
        assert(cxt);
 
-       if (fdisk_is_disklabel(cxt, OSF)) {
-               putchar('\n');
-               /* OSF label, and no DOS label */
-               printf(_("Detected an OSF/1 disklabel on %s, entering "
-                        "disklabel mode.\n"),
-                      cxt->dev_path);
-               bsd_command_prompt(cxt);
-
-               /* If we return we may want to make an empty DOS label? */
-               fdisk_context_switch_label(cxt, "dos");
-       }
-
        while (1) {
                assert(cxt->label);
 
index 2bac1b0a73656718dde6ed0ce95b71f73789007a..16473227377a5861538a846ec5bb80cd0bfd5372 100644 (file)
@@ -121,8 +121,6 @@ struct fdisk_bsd_label {
 
 
 static int xbsd_delete_part (struct fdisk_context *cxt, size_t partnum);
-static void xbsd_edit_disklabel (struct fdisk_context *cxt);
-static int xbsd_write_bootstrap (struct fdisk_context *cxt);
 static void xbsd_change_fstype (struct fdisk_context *cxt);
 static int xbsd_get_part_index (struct fdisk_context *cxt, int max, int *n);
 static int xbsd_check_new_partition (struct fdisk_context *cxt, int *i);
@@ -138,7 +136,6 @@ void alpha_bootblock_checksum (char *boot);
 
 #if !defined (__alpha__)
 static int xbsd_translate_fstype (int linux_type);
-static void xbsd_link_part (struct fdisk_context *cxt);
 #endif
 
 
@@ -352,46 +349,6 @@ static int xbsd_create_disklabel(struct fdisk_context *cxt)
        return rc;
 }
 
-
-void
-bsd_command_prompt (struct fdisk_context *cxt)
-{
-
-  while (1) {
-    char buf[16];
-    int rc;
-    size_t n;
-
-    /*
-     * BIG-FAT-TODO: don't use bsd_command_prompt(), just initialialize BSD
-     * stuff by label probe() libfdisk function, and use standard fdisk.c
-     * menu code.
-     */
-    putchar ('\n');
-    rc = get_user_reply(cxt, _("BSD disklabel command (m for help): "),
-                           buf, sizeof(buf));
-    if (rc)
-      return;
-
-    switch (tolower(buf[0])) {
-      case 'e':
-       xbsd_edit_disklabel (cxt);
-       break;
-      case 'i':
-       xbsd_write_bootstrap (cxt);
-       break;
-      case 's':
-             xbsd_print_disklabel (cxt, 1);
-       break;
-#if !defined (__alpha__)
-      case 'x':
-       xbsd_link_part (cxt);
-       break;
-#endif
-    }
-  }
-}
-
 static int xbsd_delete_part(
                struct fdisk_context *cxt,
                size_t partnum)
@@ -528,7 +485,7 @@ static uint16_t ask_uint16(struct fdisk_context *cxt,
        return dflt;
 }
 
-static void xbsd_edit_disklabel(struct fdisk_context *cxt)
+int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt)
 {
        struct bsd_disklabel *d = self_disklabel(cxt);
        uintmax_t res;
@@ -556,6 +513,7 @@ static void xbsd_edit_disklabel(struct fdisk_context *cxt)
        d->d_trkseek = ask_uint32(cxt, d->d_trkseek, _("track-to-track seek"));
 
        d->d_secperunit = d->d_secpercyl * d->d_ncylinders;
+       return 0;
 }
 
 static int xbsd_get_bootstrap(struct fdisk_context *cxt,
@@ -579,7 +537,7 @@ static int xbsd_get_bootstrap(struct fdisk_context *cxt,
        return 0;
 }
 
-static int xbsd_write_bootstrap (struct fdisk_context *cxt)
+int fdisk_bsd_write_bootstrap(struct fdisk_context *cxt)
 {
        struct bsd_disklabel dl, *d = self_disklabel(cxt);
        struct fdisk_bsd_label *l = self_label(cxt);
@@ -915,26 +873,30 @@ xbsd_translate_fstype (int linux_type)
       return BSD_FS_OTHER;
   }
 }
+#endif
 
 /*
  * link partition from parent (DOS) to nested BSD partition table
  */
-static void
-xbsd_link_part (struct fdisk_context *cxt)
+int fdisk_bsd_link_partition(struct fdisk_context *cxt)
 {
        size_t k;
-       int i;
+       int i, rc;
        struct dos_partition *p;
        struct bsd_disklabel *d = self_disklabel(cxt);
 
-       if (!cxt->parent || !fdisk_is_disklabel(cxt->parent, DOS))
-               return;         /* not nested PT */
+       if (!cxt->parent || !fdisk_is_disklabel(cxt->parent, DOS)) {
+               fdisk_warnx(cxt, _("BSD label is not nested within a DOS partition"));
+               return -EINVAL;
+       }
 
-       if (fdisk_ask_partnum(cxt->parent, &k, FALSE))
-               return;
+       rc = fdisk_ask_partnum(cxt->parent, &k, FALSE);
+       if (rc)
+               return rc;
 
-       if (xbsd_check_new_partition(cxt, &i))
-               return;
+       rc = xbsd_check_new_partition(cxt, &i);
+       if (rc)
+               return rc;
 
        /* TODO: what about to update label->dos_part? */
        p = fdisk_dos_get_partition(cxt->parent, k);
@@ -942,8 +904,9 @@ xbsd_link_part (struct fdisk_context *cxt)
        d->d_partitions[i].p_size   = dos_partition_get_size(p);
        d->d_partitions[i].p_offset = dos_partition_get_start(p);
        d->d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind);
+
+       return 0;
 }
-#endif
 
 #if defined (__alpha__)
 
index 1ba7d92e3f55e264c4310bf19cf015b12a85cba8..b7274fdba202c209238d9487ec1c141c5230aa71 100644 (file)
 #include <stdint.h>
 #include "pt-bsd.h"
 
-extern void bsd_command_prompt(struct fdisk_context *cxt);
 extern int btrydev(struct fdisk_context *cxt);
 extern void xbsd_print_disklabel(struct fdisk_context *cxt, int);
 
+/* public bsd specific functions */
+extern int fdisk_bsd_edit_disklabel(struct fdisk_context *cxt);
+extern int fdisk_bsd_write_bootstrap(struct fdisk_context *cxt);
+extern int fdisk_bsd_link_partition(struct fdisk_context *cxt);
+
+
 #endif /* FDISK_BSD_LABEL_H */