]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: add a default response for the partition type dialog
authorFrancesco Cosoleto <cosoleto@gmail.com>
Fri, 6 May 2011 15:23:32 +0000 (17:23 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 10 May 2011 11:50:11 +0000 (13:50 +0200)
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 <cosoleto@gmail.com>
fdisk/fdisk.c

index 9356356c408817d575f959fa57863fe2563e4a25..ac9035cc7cb53dbbb44fe60f9f9e2807bf92a00f 100644 (file)
@@ -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);