summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2013-07-10 14:54:25 +0200
committerKarel Zak <kzak@redhat.com>2013-09-16 16:47:06 +0200
commitb529ea2abc1ef432a55e0af4560c4fb85e05c53d (patch)
treec18e174c726a475e165175885a90053a558df3ec
parentd5b243144e527cf47150b7d1da580821421b90d4 (diff)
downloadutil-linux-b529ea2abc1ef432a55e0af4560c4fb85e05c53d.tar.gz
fdisk: (bsd) implement regular bsd menu callback
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--fdisks/fdisk-menu.c39
-rw-r--r--fdisks/fdisk.c12
-rw-r--r--fdisks/fdiskbsdlabel.c73
-rw-r--r--fdisks/fdiskbsdlabel.h7
4 files changed, 60 insertions, 71 deletions
diff --git a/fdisks/fdisk-menu.c b/fdisks/fdisk-menu.c
index 7bbca6f4..7adf003b 100644
--- a/fdisks/fdisk-menu.c
+++ b/fdisks/fdisk-menu.c
@@ -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__)),
diff --git a/fdisks/fdisk.c b/fdisks/fdisk.c
index 4bae2375..34db0a1b 100644
--- a/fdisks/fdisk.c
+++ b/fdisks/fdisk.c
@@ -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);
diff --git a/fdisks/fdiskbsdlabel.c b/fdisks/fdiskbsdlabel.c
index 2bac1b0a..16473227 100644
--- a/fdisks/fdiskbsdlabel.c
+++ b/fdisks/fdiskbsdlabel.c
@@ -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__)
diff --git a/fdisks/fdiskbsdlabel.h b/fdisks/fdiskbsdlabel.h
index 1ba7d92e..b7274fdb 100644
--- a/fdisks/fdiskbsdlabel.h
+++ b/fdisks/fdiskbsdlabel.h
@@ -37,8 +37,13 @@
#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 */