cfdisk: add [Sort] operation
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
ee7f60034b
commit
d5314bf56f
|
@ -122,6 +122,7 @@ static struct cfdisk_menuitem main_menuitems[] = {
|
||||||
{ 'q', N_("Quit"), N_("Quit program without writing partition table") },
|
{ 'q', N_("Quit"), N_("Quit program without writing partition table") },
|
||||||
{ 't', N_("Type"), N_("Change the partition type") },
|
{ 't', N_("Type"), N_("Change the partition type") },
|
||||||
{ 'h', N_("Help"), N_("Print help screen") },
|
{ 'h', N_("Help"), N_("Print help screen") },
|
||||||
|
{ 's', N_("Sort"), N_("Fix partitions order") },
|
||||||
{ 'W', N_("Write"), N_("Write partition table to disk (this might destroy data)") },
|
{ 'W', N_("Write"), N_("Write partition table to disk (this might destroy data)") },
|
||||||
{ 0, NULL, NULL }
|
{ 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
@ -142,6 +143,8 @@ struct cfdisk {
|
||||||
size_t nlines; /* number of lines */
|
size_t nlines; /* number of lines */
|
||||||
size_t lines_idx; /* current line <0..N>, exclude header */
|
size_t lines_idx; /* current line <0..N>, exclude header */
|
||||||
size_t page_sz;
|
size_t page_sz;
|
||||||
|
|
||||||
|
unsigned int wrong_order :1; /* PT not in right order */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Initialize output columns -- we follow libcfdisk columns (usually specific
|
/* Initialize output columns -- we follow libcfdisk columns (usually specific
|
||||||
|
@ -332,6 +335,7 @@ static int lines_refresh(struct cfdisk *cf)
|
||||||
cf->linesbufsz = strlen(cf->linesbuf);
|
cf->linesbufsz = strlen(cf->linesbuf);
|
||||||
cf->nlines = fdisk_table_get_nents(cf->table) + 1; /* 1 for header line */
|
cf->nlines = fdisk_table_get_nents(cf->table) + 1; /* 1 for header line */
|
||||||
cf->page_sz = 0;
|
cf->page_sz = 0;
|
||||||
|
cf->wrong_order = fdisk_table_wrong_order(cf->table) ? 1 : 0;
|
||||||
|
|
||||||
if (MENU_START_LINE - TABLE_START_LINE < cf->nlines)
|
if (MENU_START_LINE - TABLE_START_LINE < cf->nlines)
|
||||||
cf->page_sz = MENU_START_LINE - TABLE_START_LINE - 1;
|
cf->page_sz = MENU_START_LINE - TABLE_START_LINE - 1;
|
||||||
|
@ -1512,6 +1516,7 @@ static int ui_help(void)
|
||||||
N_(" n Create new partition from free space"),
|
N_(" n Create new partition from free space"),
|
||||||
N_(" q Quit program without writing partition table"),
|
N_(" q Quit program without writing partition table"),
|
||||||
N_(" t Change the partition type"),
|
N_(" t Change the partition type"),
|
||||||
|
N_(" s Fix partitions order"),
|
||||||
N_(" W Write partition table to disk (must enter upper case W)"),
|
N_(" W Write partition table to disk (must enter upper case W)"),
|
||||||
N_(" Since this might destroy data on the disk, you must"),
|
N_(" Since this might destroy data on the disk, you must"),
|
||||||
N_(" either confirm or deny the write by entering `yes' or"),
|
N_(" either confirm or deny the write by entering `yes' or"),
|
||||||
|
@ -1557,7 +1562,8 @@ static int main_menu_ignore_keys(struct cfdisk *cf, char *ignore,
|
||||||
ignore[i++] = 'b';
|
ignore[i++] = 'b';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cf->wrong_order)
|
||||||
|
ignore[i++] = 's';
|
||||||
if (fdisk_context_is_readonly(cf->cxt))
|
if (fdisk_context_is_readonly(cf->cxt))
|
||||||
ignore[i++] = 'W';
|
ignore[i++] = 'W';
|
||||||
return i;
|
return i;
|
||||||
|
@ -1568,7 +1574,7 @@ static int main_menu_ignore_keys(struct cfdisk *cf, char *ignore,
|
||||||
static int main_menu_action(struct cfdisk *cf, int key)
|
static int main_menu_action(struct cfdisk *cf, int key)
|
||||||
{
|
{
|
||||||
size_t n;
|
size_t n;
|
||||||
int ref = 0, rc;
|
int ref = 0, rc, org_order = cf->wrong_order;
|
||||||
const char *info = NULL, *warn = NULL;
|
const char *info = NULL, *warn = NULL;
|
||||||
struct fdisk_partition *pa;
|
struct fdisk_partition *pa;
|
||||||
|
|
||||||
|
@ -1675,6 +1681,12 @@ static int main_menu_action(struct cfdisk *cf, int key)
|
||||||
info = _("Type of the partition %zu is unchanged.");
|
info = _("Type of the partition %zu is unchanged.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 's': /* fix order */
|
||||||
|
if (cf->wrong_order) {
|
||||||
|
fdisk_reorder_partitions(cf->cxt);
|
||||||
|
ref = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'W': /* Write */
|
case 'W': /* Write */
|
||||||
{
|
{
|
||||||
char buf[64] = { 0 };
|
char buf[64] = { 0 };
|
||||||
|
@ -1720,6 +1732,8 @@ static int main_menu_action(struct cfdisk *cf, int key)
|
||||||
ui_warnx(warn, n + 1);
|
ui_warnx(warn, n + 1);
|
||||||
else if (info)
|
else if (info)
|
||||||
ui_info(info, n + 1);
|
ui_info(info, n + 1);
|
||||||
|
else if (key == 'n' && cf->wrong_order && org_order == 0)
|
||||||
|
ui_info(_("Note that partition table entries are not in disk order now."));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue