summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2014-01-22 11:53:34 +0100
committerKarel Zak2014-03-11 11:35:13 +0100
commit00b4f26a5def0abca5ffa6ab30d11597447e1710 (patch)
treeb43d449a9a082eb1d705157671ef47965e5c825b
parentlibfdisk: add fdisk_table_get_partition() (diff)
downloadkernel-qcow2-util-linux-00b4f26a5def0abca5ffa6ab30d11597447e1710.tar.gz
kernel-qcow2-util-linux-00b4f26a5def0abca5ffa6ab30d11597447e1710.tar.xz
kernel-qcow2-util-linux-00b4f26a5def0abca5ffa6ab30d11597447e1710.zip
cfdisk: update menu according to the current partition
Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--fdisks/cfdisk.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/fdisks/cfdisk.c b/fdisks/cfdisk.c
index 586a5657b..76db18901 100644
--- a/fdisks/cfdisk.c
+++ b/fdisks/cfdisk.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <errno.h>
#include <signal.h>
+#include <ctype.h>
#ifdef HAVE_SLANG_H
#include <slang.h>
@@ -192,7 +193,6 @@ done:
return res;
}
-
static int lines_refresh(struct cfdisk *cf)
{
int rc;
@@ -240,6 +240,14 @@ static int lines_refresh(struct cfdisk *cf)
return 0;
}
+static struct fdisk_partition *get_current_partition(struct cfdisk *cf)
+{
+ assert(cf);
+ assert(cf->table);
+
+ return fdisk_table_get_partition(cf->table, cf->lines_idx);
+}
+
static int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
void *data __attribute__((__unused__)))
{
@@ -314,7 +322,9 @@ static void die_on_signal(int dummy __attribute__((__unused__)))
static void menu_update_ignore(struct cfdisk *cf)
{
- char *ignore = NULL;
+ char ignore[128] = { 0 };
+ int i = 0;
+ struct fdisk_partition *pa;
struct cfdisk_menu *m;
struct cfdisk_menudesc *d;
@@ -325,12 +335,24 @@ static void menu_update_ignore(struct cfdisk *cf)
switch (m->id) {
case CFDISK_MENU_MAIN:
+ pa = get_current_partition(cf);
+ if (!pa)
+ break;
+ if (fdisk_partition_is_freespace(pa)) {
+ ignore[i++] = 'd'; /* delete */
+ ignore[i++] = 't'; /* set type */
+ ignore[i++] = 'b'; /* set bootable */
+ } else
+ ignore[i++] = 'n';
+
break;
}
+ ignore[i] = '\0';
+
/* return if no change */
- if ( (!m->ignore && (!ignore || !*ignore))
- || (m->ignore && ignore && strcmp(m->ignore, ignore) == 0)) {
+ if ( (!m->ignore && !*ignore)
+ || (m->ignore && *ignore && strcmp(m->ignore, ignore) == 0)) {
return;
}
@@ -510,8 +532,14 @@ static void ui_draw_menu(struct cfdisk *cf)
DBG(FRONTEND, dbgprint("ui: menu: draw start"));
+ for (i = MENU_START_LINE; i < (size_t) LINES - 1; i++) {
+ move(i, 0);
+ clrtoeol();
+ }
+
menu_update_ignore(cf);
+ i = 0;
while ((d = menu_get_menuitem(cf, i)))
ui_draw_menuitem(cf, d, i++);
@@ -552,7 +580,9 @@ static int ui_menu_action(struct cfdisk *cf, int key)
if (!d)
return 0;
key = d->key;
- }
+
+ } else if (key != 'w' && key != 'W')
+ key = tolower(key); /* case insensitive except 'W'rite */
DBG(FRONTEND, dbgprint("ui: menu action: key=%c", key));