fdisk: add asktype "string" and support UUID partition change

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-05-15 13:33:24 +02:00
parent 34b06299ce
commit d87c7ce2bf
2 changed files with 21 additions and 3 deletions

View file

@ -8,6 +8,7 @@
#include "c.h" #include "c.h"
#include "strutils.h" #include "strutils.h"
#include "rpmatch.h" #include "rpmatch.h"
#include "xalloc.h"
#include "fdisk.h" #include "fdisk.h"
@ -196,12 +197,23 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
fputs(fdisk_ask_get_query(ask), stdout); fputs(fdisk_ask_get_query(ask), stdout);
rc = get_user_reply(cxt, _(" [Y]es/[N]o: "), buf, sizeof(buf)); rc = get_user_reply(cxt, _(" [Y]es/[N]o: "), buf, sizeof(buf));
if (rc == 0) if (rc == 0)
ask->data.yesno.result = rpmatch(buf); fdisk_ask_yesno_set_result(ask, rpmatch(buf));
DBG(ASK, dbgprint("yes-no ask: reply '%s' [rc=%d]", buf, rc)); DBG(ASK, dbgprint("yes-no ask: reply '%s' [rc=%d]", buf, rc));
break; break;
case FDISK_ASKTYPE_TABLE: case FDISK_ASKTYPE_TABLE:
tt_print_table(fdisk_ask_get_table(ask)); tt_print_table(fdisk_ask_get_table(ask));
break; break;
case FDISK_ASKTYPE_STRING:
{
char prmt[BUFSIZ];
snprintf(prmt, sizeof(prmt), "%s: ", fdisk_ask_get_query(ask));
fputc('\n', stdout);
rc = get_user_reply(cxt, prmt, buf, sizeof(buf));
if (rc == 0)
fdisk_ask_string_set_result(ask, xstrdup(buf));
DBG(ASK, dbgprint("string ask: reply '%s' [rc=%d]", buf, rc));
break;
}
default: default:
warnx(_("internal error: unsupported dialog type %d"), fdisk_ask_get_type(ask)); warnx(_("internal error: unsupported dialog type %d"), fdisk_ask_get_type(ask));
return -EINVAL; return -EINVAL;

View file

@ -69,7 +69,7 @@ static const struct menulist_descr menulist[] = {
{'c', N_("toggle the dos compatibility flag"), {FDISK_DISKLABEL_DOS, 0}}, {'c', N_("toggle the dos compatibility flag"), {FDISK_DISKLABEL_DOS, 0}},
{'c', N_("toggle the mountable flag"), {FDISK_DISKLABEL_SUN, 0}}, {'c', N_("toggle the mountable flag"), {FDISK_DISKLABEL_SUN, 0}},
{'d', N_("delete a partition"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_OSF | FDISK_DISKLABEL_GPT, 0}}, {'d', N_("delete a partition"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_OSF | FDISK_DISKLABEL_GPT, 0}},
{'d', N_("print the raw data in the partition table"), {0, FDISK_DISKLABEL_ANY}}, {'d', N_("print the raw data of the first sector"), {0, FDISK_DISKLABEL_ANY}},
{'e', N_("change number of extra sectors per cylinder"), {0, FDISK_DISKLABEL_SUN}}, {'e', N_("change number of extra sectors per cylinder"), {0, FDISK_DISKLABEL_SUN}},
{'e', N_("edit drive data"), {FDISK_DISKLABEL_OSF, 0}}, {'e', N_("edit drive data"), {FDISK_DISKLABEL_OSF, 0}},
{'e', N_("list extended partitions"), {0, FDISK_DISKLABEL_DOS}}, {'e', N_("list extended partitions"), {0, FDISK_DISKLABEL_DOS}},
@ -94,6 +94,7 @@ static const struct menulist_descr menulist[] = {
{'s', N_("show complete disklabel"), {FDISK_DISKLABEL_OSF, 0}}, {'s', N_("show complete disklabel"), {FDISK_DISKLABEL_OSF, 0}},
{'t', N_("change a partition's system id"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_OSF, 0}}, {'t', N_("change a partition's system id"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_OSF, 0}},
{'u', N_("change display/entry units"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_OSF, 0}}, {'u', N_("change display/entry units"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_OSF, 0}},
{'u', N_("change partition UUID"), {0, FDISK_DISKLABEL_GPT}},
{'v', N_("verify the partition table"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI, FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI}}, {'v', N_("verify the partition table"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI, FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI}},
{'w', N_("write disklabel to disk"), {FDISK_DISKLABEL_OSF, 0}}, {'w', N_("write disklabel to disk"), {FDISK_DISKLABEL_OSF, 0}},
{'w', N_("write table to disk and exit"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_GPT, FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI}}, {'w', N_("write table to disk and exit"), {FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI | FDISK_DISKLABEL_GPT, FDISK_DISKLABEL_DOS | FDISK_DISKLABEL_SUN | FDISK_DISKLABEL_SGI}},
@ -856,7 +857,7 @@ expert_command_prompt(struct fdisk_context *cxt)
case 'p': case 'p':
if (fdisk_is_disklabel(cxt, SUN)) if (fdisk_is_disklabel(cxt, SUN))
list_table(cxt, 1); list_table(cxt, 1);
else else if (fdisk_is_disklabel(cxt, DOS))
dos_list_table_expert(cxt, 0); dos_list_table_expert(cxt, 0);
break; break;
case 'q': case 'q':
@ -873,6 +874,11 @@ expert_command_prompt(struct fdisk_context *cxt)
"compatibility\n")); "compatibility\n"));
fdisk_override_geometry(cxt, user_cylinders, user_heads, user_sectors); fdisk_override_geometry(cxt, user_cylinders, user_heads, user_sectors);
break; break;
case 'u':
if (fdisk_is_disklabel(cxt, GPT) &&
fdisk_ask_partnum(cxt, &n, FALSE) == 0)
fdisk_gpt_partition_set_uuid(cxt, n);
break;
case 'v': case 'v':
verify(cxt); verify(cxt);
break; break;