2013-05-17 05:35:23 -05:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "c.h"
|
|
|
|
#include "fdisk.h"
|
2013-05-23 08:55:35 -05:00
|
|
|
#include "pt-sun.h"
|
2013-06-25 08:55:02 -05:00
|
|
|
#include "pt-mbr.h"
|
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
struct menu_entry {
|
2013-06-27 04:26:00 -05:00
|
|
|
const char key; /* command key */
|
|
|
|
const char *title; /* help string */
|
|
|
|
unsigned int normal : 1, /* normal mode */
|
|
|
|
expert : 1, /* expert mode */
|
|
|
|
hidden : 1; /* be sensitive for this key,
|
|
|
|
but don't print it in help */
|
2013-05-17 05:35:23 -05:00
|
|
|
|
2013-06-27 04:26:00 -05:00
|
|
|
enum fdisk_labeltype label; /* only for this label */
|
|
|
|
enum fdisk_labeltype exclude; /* all labels except this */
|
2013-05-17 05:35:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#define IS_MENU_SEP(e) ((e)->key == '-')
|
|
|
|
#define IS_MENU_HID(e) ((e)->hidden)
|
|
|
|
|
|
|
|
struct menu {
|
|
|
|
enum fdisk_labeltype label; /* only for this label */
|
|
|
|
enum fdisk_labeltype exclude; /* all labels except this */
|
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
int (*callback)(struct fdisk_context **,
|
2013-05-21 08:06:11 -05:00
|
|
|
const struct menu *,
|
|
|
|
const struct menu_entry *);
|
2013-05-17 05:35:23 -05:00
|
|
|
|
|
|
|
struct menu_entry entries[]; /* NULL terminated array */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu_context {
|
|
|
|
size_t menu_idx; /* the current menu */
|
|
|
|
size_t entry_idx; /* index with in the current menu */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MENU_CXT_EMPTY { 0, 0 }
|
2013-05-22 08:37:47 -05:00
|
|
|
#define DECLARE_MENU_CB(x) \
|
2013-07-10 07:17:58 -05:00
|
|
|
static int x(struct fdisk_context **, \
|
2013-05-22 08:37:47 -05:00
|
|
|
const struct menu *, \
|
|
|
|
const struct menu_entry *)
|
2013-05-17 05:35:23 -05:00
|
|
|
|
2013-05-22 08:37:47 -05:00
|
|
|
DECLARE_MENU_CB(gpt_menu_cb);
|
2013-05-23 08:55:35 -05:00
|
|
|
DECLARE_MENU_CB(sun_menu_cb);
|
2013-07-11 10:08:45 -05:00
|
|
|
DECLARE_MENU_CB(sgi_menu_cb);
|
2013-05-22 08:37:47 -05:00
|
|
|
DECLARE_MENU_CB(geo_menu_cb);
|
2013-06-25 08:55:02 -05:00
|
|
|
DECLARE_MENU_CB(dos_menu_cb);
|
2013-07-10 07:54:25 -05:00
|
|
|
DECLARE_MENU_CB(bsd_menu_cb);
|
2013-07-11 09:56:00 -05:00
|
|
|
DECLARE_MENU_CB(createlabel_menu_cb);
|
2013-05-21 08:29:01 -05:00
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
/*
|
|
|
|
* Menu entry macros:
|
|
|
|
* MENU_X* expert mode only
|
|
|
|
* MENU_B* both -- expert + normal mode
|
|
|
|
*
|
2013-06-27 04:26:00 -05:00
|
|
|
* *_E exclude this label
|
|
|
|
* *_H hidden
|
|
|
|
* *_L only for this label
|
2013-05-17 05:35:23 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* separator */
|
|
|
|
#define MENU_SEP(t) { .title = t, .key = '-', .normal = 1 }
|
|
|
|
#define MENU_XSEP(t) { .title = t, .key = '-', .expert = 1 }
|
|
|
|
#define MENU_BSEP(t) { .title = t, .key = '-', .expert = 1, .normal = 1 }
|
|
|
|
|
|
|
|
/* entry */
|
|
|
|
#define MENU_ENT(k, t) { .title = t, .key = k, .normal = 1 }
|
|
|
|
#define MENU_ENT_E(k, t, l) { .title = t, .key = k, .normal = 1, .exclude = l }
|
2013-06-27 04:26:00 -05:00
|
|
|
#define MENU_ENT_L(k, t, l) { .title = t, .key = k, .normal = 1, .label = l }
|
2013-05-17 05:35:23 -05:00
|
|
|
|
|
|
|
#define MENU_XENT(k, t) { .title = t, .key = k, .expert = 1 }
|
|
|
|
#define MENU_XENT_H(k, t) { .title = t, .key = k, .expert = 1, .hidden = 1 }
|
|
|
|
|
|
|
|
#define MENU_BENT(k, t) { .title = t, .key = k, .expert = 1, .normal = 1 }
|
|
|
|
|
|
|
|
|
|
|
|
/* Generic menu */
|
|
|
|
struct menu menu_generic = {
|
|
|
|
/* .callback = generic_menu_cb,*/
|
|
|
|
.entries = {
|
2013-05-17 08:01:31 -05:00
|
|
|
MENU_BSEP(N_("Generic")),
|
2013-05-17 05:35:23 -05:00
|
|
|
MENU_ENT ('d', N_("delete a partition")),
|
|
|
|
MENU_ENT ('l', N_("list known partition types")),
|
|
|
|
MENU_ENT ('n', N_("add a new partition")),
|
|
|
|
MENU_BENT ('p', N_("print the partition table")),
|
2013-05-17 08:01:31 -05:00
|
|
|
MENU_ENT ('t', N_("change a partition type")),
|
2013-07-10 07:59:49 -05:00
|
|
|
MENU_ENT_E('v', N_("verify the partition table"), FDISK_DISKLABEL_BSD),
|
2013-05-17 05:35:23 -05:00
|
|
|
|
2013-05-17 08:01:31 -05:00
|
|
|
MENU_XENT('d', N_("print the raw data of the first sector")),
|
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
MENU_SEP(N_("Misc")),
|
|
|
|
MENU_BENT ('m', N_("print this menu")),
|
|
|
|
MENU_ENT_E('u', N_("change display/entry units"), FDISK_DISKLABEL_GPT),
|
2013-07-10 07:59:49 -05:00
|
|
|
MENU_ENT_E('x', N_("extra functionality (experts only)"), FDISK_DISKLABEL_BSD),
|
2013-05-17 05:35:23 -05:00
|
|
|
|
2013-05-17 06:44:29 -05:00
|
|
|
MENU_BSEP(N_("Save & Exit")),
|
2013-07-10 07:59:49 -05:00
|
|
|
MENU_ENT_E('w', N_("write table to disk and exit"), FDISK_DISKLABEL_BSD),
|
|
|
|
MENU_ENT_L('w', N_("write table to disk"), FDISK_DISKLABEL_BSD),
|
2013-05-17 05:35:23 -05:00
|
|
|
MENU_BENT ('q', N_("quit without saving changes")),
|
|
|
|
MENU_XENT ('r', N_("return to main menu")),
|
2013-07-10 07:59:49 -05:00
|
|
|
MENU_ENT_L('r', N_("return to main menu"), FDISK_DISKLABEL_BSD),
|
2013-05-17 05:35:23 -05:00
|
|
|
|
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu menu_createlabel = {
|
2013-07-11 09:56:00 -05:00
|
|
|
.callback = createlabel_menu_cb,
|
2013-07-10 07:59:49 -05:00
|
|
|
.exclude = FDISK_DISKLABEL_BSD,
|
2013-05-17 05:35:23 -05:00
|
|
|
.entries = {
|
|
|
|
MENU_SEP(N_("Create a new label")),
|
|
|
|
MENU_ENT('g', N_("create a new empty GPT partition table")),
|
|
|
|
MENU_ENT('G', N_("create a new empty SGI (IRIX) partition table")),
|
|
|
|
MENU_ENT('o', N_("create a new empty DOS partition table")),
|
|
|
|
MENU_ENT('s', N_("create a new empty Sun partition table")),
|
|
|
|
|
|
|
|
/* backward compatibility -- be sensitive to 'g', but don't
|
|
|
|
* print it in the expert menu */
|
|
|
|
MENU_XENT_H('g', N_("create an IRIX (SGI) partition table")),
|
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-22 08:11:56 -05:00
|
|
|
struct menu menu_geo = {
|
2013-05-22 08:37:47 -05:00
|
|
|
.callback = geo_menu_cb,
|
2013-07-10 07:59:49 -05:00
|
|
|
.exclude = FDISK_DISKLABEL_GPT | FDISK_DISKLABEL_BSD,
|
2013-05-22 08:11:56 -05:00
|
|
|
.entries = {
|
|
|
|
MENU_XSEP(N_("Geometry")),
|
|
|
|
MENU_XENT('c', N_("change number of cylinders")),
|
|
|
|
MENU_XENT('h', N_("change number of heads")),
|
|
|
|
MENU_XENT('s', N_("change number of sectors/track")),
|
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
struct menu menu_gpt = {
|
2013-05-21 08:29:01 -05:00
|
|
|
.callback = gpt_menu_cb,
|
2013-05-17 05:35:23 -05:00
|
|
|
.label = FDISK_DISKLABEL_GPT,
|
|
|
|
.entries = {
|
|
|
|
MENU_XSEP(N_("GPT")),
|
2013-06-25 08:31:21 -05:00
|
|
|
MENU_XENT('i', N_("change disk GUID")),
|
2013-05-17 05:35:23 -05:00
|
|
|
MENU_XENT('n', N_("change partition name")),
|
2013-06-25 08:31:21 -05:00
|
|
|
MENU_XENT('u', N_("change partition UUID")),
|
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-17 06:44:29 -05:00
|
|
|
struct menu menu_sun = {
|
2013-05-23 08:55:35 -05:00
|
|
|
.callback = sun_menu_cb,
|
2013-05-17 06:44:29 -05:00
|
|
|
.label = FDISK_DISKLABEL_SUN,
|
|
|
|
.entries = {
|
|
|
|
MENU_BSEP(N_("Sun")),
|
|
|
|
MENU_ENT('a', N_("toggle a read only flag")),
|
|
|
|
MENU_ENT('c', N_("toggle the mountable flag")),
|
|
|
|
|
|
|
|
MENU_XENT('a', N_("change number of alternate cylinders")),
|
|
|
|
MENU_XENT('e', N_("change number of extra sectors per cylinder")),
|
|
|
|
MENU_XENT('i', N_("change interleave factor")),
|
|
|
|
MENU_XENT('o', N_("change rotation speed (rpm)")),
|
|
|
|
MENU_XENT('y', N_("change number of physical cylinders")),
|
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-17 08:01:31 -05:00
|
|
|
struct menu menu_sgi = {
|
2013-07-11 10:08:45 -05:00
|
|
|
.callback = sgi_menu_cb,
|
2013-05-17 08:01:31 -05:00
|
|
|
.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")),
|
2013-07-11 10:08:45 -05:00
|
|
|
MENU_ENT('i', N_("create SGI info")),
|
2013-05-17 08:01:31 -05:00
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu menu_dos = {
|
2013-06-25 08:55:02 -05:00
|
|
|
.callback = dos_menu_cb,
|
2013-05-17 08:01:31 -05:00
|
|
|
.label = FDISK_DISKLABEL_DOS,
|
|
|
|
.entries = {
|
|
|
|
MENU_BSEP(N_("DOS (MBR)")),
|
|
|
|
MENU_ENT('a', N_("toggle a bootable flag")),
|
|
|
|
MENU_ENT('b', N_("edit nested BSD disklabel")),
|
|
|
|
MENU_ENT('c', N_("toggle the dos compatibility flag")),
|
|
|
|
|
|
|
|
MENU_XENT('b', N_("move beginning of data in a partition")),
|
2013-05-22 08:11:56 -05:00
|
|
|
MENU_XENT('e', N_("list extended partitions")),
|
2013-05-17 08:01:31 -05:00
|
|
|
MENU_XENT('f', N_("fix partition order")),
|
|
|
|
MENU_XENT('i', N_("change the disk identifier")),
|
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu menu_bsd = {
|
2013-07-10 07:54:25 -05:00
|
|
|
.callback = bsd_menu_cb,
|
2013-07-10 07:59:49 -05:00
|
|
|
.label = FDISK_DISKLABEL_BSD,
|
2013-05-17 08:01:31 -05:00
|
|
|
.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")),
|
|
|
|
MENU_ENT('x', N_("link BSD partition to non-BSD partition")),
|
|
|
|
{ 0, NULL }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
static const struct menu *menus[] = {
|
2013-05-17 08:01:31 -05:00
|
|
|
&menu_gpt,
|
|
|
|
&menu_sun,
|
|
|
|
&menu_sgi,
|
|
|
|
&menu_dos,
|
|
|
|
&menu_bsd,
|
2013-05-22 08:11:56 -05:00
|
|
|
&menu_geo,
|
2013-05-17 05:35:23 -05:00
|
|
|
&menu_generic,
|
|
|
|
&menu_createlabel,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct menu_entry *next_menu_entry(
|
|
|
|
struct fdisk_context *cxt,
|
|
|
|
struct menu_context *mc)
|
|
|
|
{
|
|
|
|
while (mc->menu_idx < ARRAY_SIZE(menus)) {
|
|
|
|
const struct menu *m = menus[mc->menu_idx];
|
|
|
|
const struct menu_entry *e = &(m->entries[mc->entry_idx]);
|
|
|
|
|
2013-05-22 08:11:56 -05:00
|
|
|
/* no more entries */
|
2013-05-17 05:35:23 -05:00
|
|
|
if (e->title == NULL ||
|
2013-05-22 08:11:56 -05:00
|
|
|
/* menu wanted for specified labels only */
|
|
|
|
(m->label && cxt->label && !(m->label & cxt->label->id)) ||
|
|
|
|
/* menu excluded for specified labels */
|
|
|
|
(m->exclude && cxt->label && (m->exclude & cxt->label->id))) {
|
2013-05-17 05:35:23 -05:00
|
|
|
mc->menu_idx++;
|
|
|
|
mc->entry_idx = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-06-27 04:26:00 -05:00
|
|
|
/* excluded for the current label */
|
|
|
|
if ((e->exclude && cxt->label && e->exclude & cxt->label->id) ||
|
|
|
|
/* entry wanted for specified labels only */
|
|
|
|
(e->label && cxt->label && !(e->label & cxt->label->id)) ||
|
2013-05-17 05:35:23 -05:00
|
|
|
/* exclude non-expert entries in expect mode */
|
|
|
|
(e->expert == 0 && fdisk_context_display_details(cxt)) ||
|
|
|
|
/* exclude non-normal entries in normal mode */
|
|
|
|
(e->normal == 0 && !fdisk_context_display_details(cxt))) {
|
|
|
|
|
|
|
|
mc->entry_idx++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mc->entry_idx++;
|
|
|
|
return e;
|
|
|
|
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-17 07:11:51 -05:00
|
|
|
/* returns @menu and menu entry for then @key */
|
|
|
|
static const struct menu_entry *get_fdisk_menu_entry(
|
|
|
|
struct fdisk_context *cxt,
|
|
|
|
int key,
|
|
|
|
const struct menu **menu)
|
|
|
|
{
|
|
|
|
struct menu_context mc = MENU_CXT_EMPTY;
|
|
|
|
const struct menu_entry *e;
|
|
|
|
|
|
|
|
while ((e = next_menu_entry(cxt, &mc))) {
|
|
|
|
if (IS_MENU_SEP(e) || e->key != key)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (menu)
|
|
|
|
*menu = menus[mc.menu_idx];
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int menu_detect_collisions(struct fdisk_context *cxt)
|
|
|
|
{
|
|
|
|
struct menu_context mc = MENU_CXT_EMPTY;
|
|
|
|
const struct menu_entry *e, *r;
|
|
|
|
|
|
|
|
while ((e = next_menu_entry(cxt, &mc))) {
|
|
|
|
if (IS_MENU_SEP(e))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r = get_fdisk_menu_entry(cxt, e->key, NULL);
|
|
|
|
if (!r) {
|
2013-05-21 08:30:16 -05:00
|
|
|
DBG(FRONTEND, dbgprint("warning: not found "
|
2013-05-17 07:11:51 -05:00
|
|
|
"entry for %c", e->key));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (r != e) {
|
2013-05-21 08:30:16 -05:00
|
|
|
DBG(FRONTEND, dbgprint("warning: duplicate key '%c'",
|
2013-05-17 07:11:51 -05:00
|
|
|
e->key));
|
2013-06-27 03:54:19 -05:00
|
|
|
DBG(FRONTEND, dbgprint(" : %s", e->title));
|
|
|
|
DBG(FRONTEND, dbgprint(" : %s", r->title));
|
2013-05-17 07:11:51 -05:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-17 08:11:11 -05:00
|
|
|
int print_fdisk_menu(struct fdisk_context *cxt)
|
2013-05-17 05:35:23 -05:00
|
|
|
{
|
|
|
|
struct menu_context mc = MENU_CXT_EMPTY;
|
|
|
|
const struct menu_entry *e;
|
|
|
|
|
2013-05-21 08:30:16 -05:00
|
|
|
ON_DBG(FRONTEND, menu_detect_collisions(cxt));
|
2013-05-17 07:11:51 -05:00
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
if (fdisk_context_display_details(cxt))
|
2013-05-17 08:11:11 -05:00
|
|
|
printf(_("\nHelp (expert commands):\n"));
|
2013-05-17 05:35:23 -05:00
|
|
|
else
|
2013-05-17 08:11:11 -05:00
|
|
|
printf(_("\nHelp:\n"));
|
2013-05-17 05:35:23 -05:00
|
|
|
|
|
|
|
while ((e = next_menu_entry(cxt, &mc))) {
|
|
|
|
if (IS_MENU_HID(e))
|
|
|
|
continue; /* hidden entry */
|
|
|
|
if (IS_MENU_SEP(e))
|
|
|
|
printf("\n %s\n", _(e->title));
|
|
|
|
else
|
|
|
|
printf(" %c %s\n", e->key, _(e->title));
|
|
|
|
}
|
|
|
|
fputc('\n', stdout);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-21 08:06:11 -05:00
|
|
|
/* Asks for command, verify the key and perform the command or
|
|
|
|
* returns the command key if no callback for the command is
|
|
|
|
* implemented.
|
|
|
|
*
|
2013-07-10 07:17:58 -05:00
|
|
|
* Note that this function might exchange the context pointer to
|
|
|
|
* switch to another (nested) context.
|
|
|
|
*
|
2013-05-21 08:06:11 -05:00
|
|
|
* Returns: <0 on error
|
|
|
|
* 0 on success (the command performed)
|
|
|
|
* >0 if no callback (then returns the key)
|
|
|
|
*/
|
2013-07-10 07:17:58 -05:00
|
|
|
int process_fdisk_menu(struct fdisk_context **cxt0)
|
2013-05-21 08:06:11 -05:00
|
|
|
{
|
2013-07-10 07:17:58 -05:00
|
|
|
struct fdisk_context *cxt = *cxt0;
|
2013-05-21 08:06:11 -05:00
|
|
|
const struct menu_entry *ent;
|
|
|
|
const struct menu *menu;
|
|
|
|
int key, rc;
|
|
|
|
const char *prompt;
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
if (fdisk_context_display_details(cxt))
|
|
|
|
prompt = _("Expert command (m for help): ");
|
|
|
|
else
|
|
|
|
prompt = _("Command (m for help): ");
|
|
|
|
|
|
|
|
fputc('\n',stdout);
|
|
|
|
rc = get_user_reply(cxt, prompt, buf, sizeof(buf));
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
key = buf[0];
|
|
|
|
ent = get_fdisk_menu_entry(cxt, key, &menu);
|
|
|
|
if (!ent) {
|
|
|
|
fdisk_warnx(cxt, _("%c: unknown command"), key);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
rc = 0;
|
2013-05-21 08:30:16 -05:00
|
|
|
DBG(FRONTEND, dbgprint("selected: key=%c, entry='%s'",
|
2013-05-21 08:06:11 -05:00
|
|
|
key, ent->title));
|
|
|
|
/* hardcoded help */
|
2013-07-10 07:17:58 -05:00
|
|
|
if (key == 'm')
|
2013-05-21 08:06:11 -05:00
|
|
|
print_fdisk_menu(cxt);
|
|
|
|
|
|
|
|
/* menu has implemented callback, use it */
|
2013-07-10 07:17:58 -05:00
|
|
|
else if (menu->callback)
|
|
|
|
rc = menu->callback(cxt0, menu, ent);
|
|
|
|
else {
|
|
|
|
DBG(FRONTEND, dbgprint("no callback, return key '%c'", key));
|
|
|
|
return key;
|
|
|
|
}
|
2013-05-21 08:06:11 -05:00
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
DBG(FRONTEND, dbgprint("process menu done [rc=%d]", rc));
|
|
|
|
return rc;
|
2013-05-21 08:06:11 -05:00
|
|
|
}
|
|
|
|
|
2013-05-22 08:37:47 -05:00
|
|
|
|
2013-05-21 08:29:01 -05:00
|
|
|
/*
|
|
|
|
* This is fdisk frontend for GPT specific libfdisk functions that
|
|
|
|
* are not expported by generic libfdisk API.
|
|
|
|
*/
|
2013-07-10 07:17:58 -05:00
|
|
|
static int gpt_menu_cb(struct fdisk_context **cxt0,
|
2013-05-21 08:29:01 -05:00
|
|
|
const struct menu *menu __attribute__((__unused__)),
|
|
|
|
const struct menu_entry *ent)
|
|
|
|
{
|
2013-07-10 07:17:58 -05:00
|
|
|
struct fdisk_context *cxt = *cxt0;
|
2013-05-21 08:29:01 -05:00
|
|
|
size_t n;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
assert(ent);
|
|
|
|
assert(fdisk_is_disklabel(cxt, GPT));
|
|
|
|
|
2013-05-21 08:30:16 -05:00
|
|
|
DBG(FRONTEND, dbgprint("enter GPT menu"));
|
2013-05-21 08:29:01 -05:00
|
|
|
|
2013-06-25 08:31:21 -05:00
|
|
|
if (ent->key == 'i')
|
|
|
|
return fdisk_set_disklabel_id(cxt);
|
|
|
|
|
2013-05-21 08:29:01 -05:00
|
|
|
rc = fdisk_ask_partnum(cxt, &n, FALSE);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
switch(ent->key) {
|
|
|
|
case 'u':
|
|
|
|
rc = fdisk_gpt_partition_set_uuid(cxt, n);
|
|
|
|
break;
|
|
|
|
case 'n':
|
2013-05-21 09:12:10 -05:00
|
|
|
rc = fdisk_gpt_partition_set_name(cxt, n);
|
2013-05-21 08:29:01 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-06-25 08:55:02 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This is fdisk frontend for MBR specific libfdisk functions that
|
|
|
|
* are not expported by generic libfdisk API.
|
|
|
|
*/
|
2013-07-10 07:17:58 -05:00
|
|
|
static int dos_menu_cb(struct fdisk_context **cxt0,
|
2013-06-25 08:55:02 -05:00
|
|
|
const struct menu *menu __attribute__((__unused__)),
|
|
|
|
const struct menu_entry *ent)
|
|
|
|
{
|
2013-07-10 07:17:58 -05:00
|
|
|
struct fdisk_context *cxt = *cxt0;
|
2013-06-25 08:55:02 -05:00
|
|
|
int rc = 0;
|
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
DBG(FRONTEND, dbgprint("enter DOS menu"));
|
|
|
|
|
2013-06-25 08:55:02 -05:00
|
|
|
if (!ent->expert) {
|
|
|
|
switch (ent->key) {
|
|
|
|
case 'a':
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
rc = fdisk_ask_partnum(cxt, &n, FALSE);
|
|
|
|
if (!rc)
|
|
|
|
rc = fdisk_partition_toggle_flag(cxt, n, DOS_FLAG_ACTIVE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'b':
|
|
|
|
{
|
|
|
|
struct fdisk_context *bsd
|
|
|
|
= fdisk_new_nested_context(cxt, "bsd");
|
2013-06-27 03:54:19 -05:00
|
|
|
if (!bsd)
|
|
|
|
return -ENOMEM;
|
|
|
|
if (!fdisk_dev_has_disklabel(bsd))
|
|
|
|
rc = fdisk_create_disklabel(bsd, "bsd");
|
2013-07-10 07:17:58 -05:00
|
|
|
if (rc)
|
|
|
|
fdisk_free_context(bsd);
|
|
|
|
else
|
|
|
|
*cxt0 = cxt = bsd;
|
2013-06-25 08:55:02 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'c':
|
|
|
|
toggle_dos_compatibility_flag(cxt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* expert mode */
|
|
|
|
switch (ent->key) {
|
|
|
|
case 'b':
|
|
|
|
{
|
|
|
|
size_t n;
|
|
|
|
rc = fdisk_ask_partnum(cxt, &n, FALSE);
|
|
|
|
if (!rc)
|
2013-06-25 09:22:51 -05:00
|
|
|
rc = fdisk_dos_move_begin(cxt, n);
|
2013-06-25 08:55:02 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'e':
|
|
|
|
rc = fdisk_dos_list_extended(cxt);
|
|
|
|
break;
|
|
|
|
case 'f':
|
2013-06-25 09:22:51 -05:00
|
|
|
rc = fdisk_dos_fix_order(cxt);
|
2013-06-25 08:55:02 -05:00
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
rc = fdisk_set_disklabel_id(cxt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
static int sun_menu_cb(struct fdisk_context **cxt0,
|
2013-05-23 08:55:35 -05:00
|
|
|
const struct menu *menu __attribute__((__unused__)),
|
|
|
|
const struct menu_entry *ent)
|
|
|
|
{
|
2013-07-10 07:17:58 -05:00
|
|
|
struct fdisk_context *cxt = *cxt0;
|
2013-05-23 08:55:35 -05:00
|
|
|
int rc = 0;
|
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
DBG(FRONTEND, dbgprint("enter SUN menu"));
|
|
|
|
|
2013-05-23 08:55:35 -05:00
|
|
|
assert(cxt);
|
|
|
|
assert(ent);
|
|
|
|
assert(fdisk_is_disklabel(cxt, SUN));
|
|
|
|
|
|
|
|
DBG(FRONTEND, dbgprint("enter SUN menu"));
|
|
|
|
|
|
|
|
/* normal mode */
|
|
|
|
if (!ent->expert) {
|
|
|
|
size_t n;
|
|
|
|
|
|
|
|
rc = fdisk_ask_partnum(cxt, &n, FALSE);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
switch (ent->key) {
|
|
|
|
case 'a':
|
|
|
|
rc = fdisk_partition_toggle_flag(cxt, n, SUN_FLAG_RONLY);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
rc = fdisk_partition_toggle_flag(cxt, n, SUN_FLAG_UNMNT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* expert mode */
|
|
|
|
switch (ent->key) {
|
|
|
|
case 'a':
|
|
|
|
rc = fdisk_sun_set_alt_cyl(cxt);
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
rc = fdisk_sun_set_xcyl(cxt);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
rc = fdisk_sun_set_ilfact(cxt);
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
rc = fdisk_sun_set_rspeed(cxt);
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
rc = fdisk_sun_set_pcylcount(cxt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-07-11 10:08:45 -05:00
|
|
|
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':
|
2013-07-11 10:38:13 -05:00
|
|
|
fdisk_sgi_set_bootfile(cxt);
|
2013-07-11 10:08:45 -05:00
|
|
|
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':
|
2013-07-11 10:38:13 -05:00
|
|
|
rc = fdisk_sgi_create_info(cxt);
|
2013-07-11 10:08:45 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-07-10 07:54:25 -05:00
|
|
|
/*
|
|
|
|
* 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;
|
2013-07-10 10:00:11 -05:00
|
|
|
int rc = 0, org;
|
2013-07-10 07:54:25 -05:00
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
assert(ent);
|
2013-07-10 07:59:49 -05:00
|
|
|
assert(fdisk_is_disklabel(cxt, BSD));
|
2013-07-10 07:54:25 -05:00
|
|
|
|
|
|
|
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':
|
2013-07-10 10:00:11 -05:00
|
|
|
org = fdisk_context_display_details(cxt);
|
|
|
|
|
|
|
|
fdisk_context_enable_details(cxt, 1);
|
|
|
|
fdisk_list_disklabel(cxt);
|
|
|
|
fdisk_context_enable_details(cxt, org);
|
2013-07-10 07:54:25 -05:00
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
rc = fdisk_bsd_link_partition(cxt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-05-22 08:37:47 -05:00
|
|
|
/* C/H/S commands */
|
2013-07-10 07:17:58 -05:00
|
|
|
static int geo_menu_cb(struct fdisk_context **cxt0,
|
2013-05-22 08:37:47 -05:00
|
|
|
const struct menu *menu __attribute__((__unused__)),
|
|
|
|
const struct menu_entry *ent)
|
|
|
|
{
|
2013-07-10 07:17:58 -05:00
|
|
|
struct fdisk_context *cxt = *cxt0;
|
2013-05-22 08:37:47 -05:00
|
|
|
int rc = -EINVAL;
|
|
|
|
uintmax_t c = 0, h = 0, s = 0;
|
|
|
|
|
2013-07-10 07:17:58 -05:00
|
|
|
DBG(FRONTEND, dbgprint("enter GEO menu"));
|
|
|
|
|
2013-05-22 08:37:47 -05:00
|
|
|
assert(cxt);
|
|
|
|
assert(ent);
|
|
|
|
|
|
|
|
switch (ent->key) {
|
|
|
|
case 'c':
|
|
|
|
rc = fdisk_ask_number(cxt, 1, cxt->geom.cylinders,
|
|
|
|
1048576, _("Number of cylinders"), &c);
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
rc = fdisk_ask_number(cxt, 1, cxt->geom.heads,
|
|
|
|
256, _("Number of heads"), &h);
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
rc = fdisk_ask_number(cxt, 1, cxt->geom.sectors,
|
|
|
|
63, _("Number of sectors"), &s);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
fdisk_override_geometry(cxt, c, h, s);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-07-11 09:56:00 -05:00
|
|
|
static int createlabel_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;
|
|
|
|
|
|
|
|
DBG(FRONTEND, dbgprint("enter Create label menu"));
|
|
|
|
|
|
|
|
assert(cxt);
|
|
|
|
assert(ent);
|
|
|
|
|
2013-07-11 10:08:45 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-11 09:56:00 -05:00
|
|
|
switch (ent->key) {
|
|
|
|
case 'g':
|
|
|
|
fdisk_create_disklabel(cxt, "gpt");
|
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
fdisk_create_disklabel(cxt, "sgi");
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
fdisk_create_disklabel(cxt, "dos");
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
fdisk_create_disklabel(cxt, "sun");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-05-17 05:35:23 -05:00
|
|
|
#ifdef TEST_PROGRAM
|
|
|
|
struct fdisk_label *fdisk_new_dos_label(struct fdisk_context *cxt) { return NULL; }
|
|
|
|
struct fdisk_label *fdisk_new_bsd_label(struct fdisk_context *cxt) { return NULL; }
|
|
|
|
struct fdisk_label *fdisk_new_mac_label(struct fdisk_context *cxt) { return NULL; }
|
|
|
|
struct fdisk_label *fdisk_new_sgi_label(struct fdisk_context *cxt) { return NULL; }
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct fdisk_context *cxt;
|
|
|
|
int idx = 1;
|
|
|
|
|
|
|
|
fdisk_init_debug(0);
|
|
|
|
cxt = fdisk_new_context();
|
|
|
|
|
|
|
|
if (argc > idx && strcmp(argv[idx], "--expert") == 0) {
|
|
|
|
fdisk_context_enable_details(cxt, 1);
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
fdisk_context_switch_label(cxt, argc > idx ? argv[idx] : "gpt");
|
|
|
|
|
|
|
|
print_fdisk_menu(cxt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|