summaryrefslogtreecommitdiffstats
path: root/fdisk/fdisk.c
diff options
context:
space:
mode:
authorFrancesco Cosoleto2011-05-06 17:23:32 +0200
committerKarel Zak2011-05-10 13:50:11 +0200
commit37b4484fe6af74c5744af88d5132969404e35029 (patch)
treebecefffa2cdacc1346e744488e58b2ac0b752803 /fdisk/fdisk.c
parentfdisk: change primary or extended partition type dialog (diff)
downloadkernel-qcow2-util-linux-37b4484fe6af74c5744af88d5132969404e35029.tar.gz
kernel-qcow2-util-linux-37b4484fe6af74c5744af88d5132969404e35029.tar.xz
kernel-qcow2-util-linux-37b4484fe6af74c5744af88d5132969404e35029.zip
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 <cosoleto@gmail.com>
Diffstat (limited to 'fdisk/fdisk.c')
-rw-r--r--fdisk/fdisk.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index 9356356c4..ac9035cc7 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);