fdisk: move expect actions to menu callback

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-07-12 10:44:35 +02:00
parent 5e86087018
commit 8930996828
2 changed files with 45 additions and 49 deletions

View File

@ -54,6 +54,7 @@ DECLARE_MENU_CB(geo_menu_cb);
DECLARE_MENU_CB(dos_menu_cb);
DECLARE_MENU_CB(bsd_menu_cb);
DECLARE_MENU_CB(createlabel_menu_cb);
DECLARE_MENU_CB(generic_menu_cb);
/*
* Menu entry macros:
@ -83,7 +84,7 @@ DECLARE_MENU_CB(createlabel_menu_cb);
/* Generic menu */
struct menu menu_generic = {
/* .callback = generic_menu_cb,*/
.callback = generic_menu_cb,
.entries = {
MENU_BSEP(N_("Generic")),
MENU_ENT ('d', N_("delete a partition")),
@ -391,6 +392,45 @@ int process_fdisk_menu(struct fdisk_context **cxt0)
return rc;
}
/*
* Basic fdisk actions
*/
static int generic_menu_cb(struct fdisk_context **cxt0,
const struct menu *menu __attribute__((__unused__)),
const struct menu_entry *ent)
{
struct fdisk_context *cxt = *cxt0;
int rc = 0;
if (!ent->expert)
return ent->key;
/* expert mode */
switch (ent->key) {
case 'd':
print_raw(cxt);
break;
case 'p':
list_disk_geometry(cxt);
rc = fdisk_list_disklabel(cxt);
break;
case 'q':
fdisk_free_context(cxt);
printf("\n");
exit(EXIT_SUCCESS);
case 'r':
rc = fdisk_context_enable_details(cxt, 0);
break;
case 'v':
rc = fdisk_verify_disklabel(cxt);
break;
case 'w':
write_table(cxt);
break;
}
return rc;
}
/*
* This is fdisk frontend for GPT specific libfdisk functions that

View File

@ -192,7 +192,7 @@ static void change_partition_type(struct fdisk_context *cxt)
fdisk_free_parttype(org_t);
}
static void list_disk_geometry(struct fdisk_context *cxt)
void list_disk_geometry(struct fdisk_context *cxt)
{
char *id = NULL;
unsigned long long bytes = cxt->total_sectors * cxt->sector_size;
@ -232,7 +232,7 @@ static void list_disk_geometry(struct fdisk_context *cxt)
printf("\n");
}
static void write_table(struct fdisk_context *cxt)
void write_table(struct fdisk_context *cxt)
{
int rc;
@ -302,7 +302,7 @@ print_buffer(struct fdisk_context *cxt, unsigned char pbuffer[]) {
printf("\n");
}
static void print_raw(struct fdisk_context *cxt)
void print_raw(struct fdisk_context *cxt)
{
assert(cxt);
assert(cxt->label);
@ -317,50 +317,6 @@ static void print_raw(struct fdisk_context *cxt)
/* TODO: print also EBR (extended partition) buffer */
}
static void
expert_command_prompt(struct fdisk_context *cxt)
{
char c;
assert(cxt);
fdisk_context_enable_details(cxt, 1);
while(1) {
assert(cxt->label);
c = process_fdisk_menu(&cxt);
if (c <= 0)
continue;
/* well, process_fdisk_menu() returns commands that
* are not yet implemented by menu callbacks. Let's
* perform the commands here */
switch (c) {
case 'd':
print_raw(cxt);
break;
case 'p':
list_disk_geometry(cxt);
fdisk_list_disklabel(cxt);
break;
case 'q':
fdisk_free_context(cxt);
printf("\n");
exit(EXIT_SUCCESS);
case 'r':
fdisk_context_enable_details(cxt, 0);
return;
case 'v':
fdisk_verify_disklabel(cxt);
break;
case 'w':
write_table(cxt);
break;
}
}
}
static int is_ide_cdrom_or_tape(char *device)
{
int fd, ret;
@ -482,7 +438,7 @@ static void command_prompt(struct fdisk_context *cxt)
write_table(cxt);
break;
case 'x':
expert_command_prompt(cxt);
fdisk_context_enable_details(cxt, 1);
break;
case 'r':
if (cxt->parent) {