From: Francesco Cosoleto Date: Fri, 6 May 2011 15:23:32 +0000 (+0200) Subject: fdisk: add a default response for the partition type dialog X-Git-Tag: v2.20-rc1~285 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=37b4484fe6af74c5744af88d5132969404e35029;p=thirdparty%2Futil-linux.git fdisk: add a default response for the partition type dialog The default response is 'p' until three primary partitions are created, then 'e'. The original idea is from Karel Zak. Signed-off-by: Francesco Cosoleto --- diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 9356356c40..ac9035cc7c 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -2532,17 +2532,25 @@ new_partition(void) { printf(_("Adding a primary partition\n")); add_partition(get_partition(0, 4), LINUX_NATIVE); } else { - char c, line[LINE_LENGTH]; + char c, dflt, line[LINE_LENGTH]; + + while (1) { + dflt = (free_primary == 1 && !extended_offset) ? 'e' : 'p'; snprintf(line, sizeof(line), _("Partition type:\n" " p primary (%d primary, %d extended, %d free)\n" "%s\n" - "Select: "), + "Select (default %c): "), 4 - (extended_offset ? 1 : 0) - free_primary, extended_offset ? 1 : 0, free_primary, - extended_offset ? _(" l logical (numbered from 5)") : _(" e extended")); + extended_offset ? _(" l logical (numbered from 5)") : _(" e extended"), + dflt); - while (1) { - if ((c = tolower(read_char(line))) == 'p') { + c = tolower(read_chars(line)); + if (c == '\n') { + c = dflt; + printf(_("Using default response %c\n"), c); + } + if (c == 'p') { int i = get_nonexisting_partition(0, 4); if (i >= 0) add_partition(i, LINUX_NATIVE);