Remove a few menu entries if raid/lvm/cgd/gpt are not available.

This commit is contained in:
martin 2014-08-06 10:03:49 +00:00
parent 438e08f560
commit 169405fcaa
3 changed files with 88 additions and 11 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: defs.h,v 1.2 2014/08/03 16:09:38 martin Exp $ */
/* $NetBSD: defs.h,v 1.3 2014/08/06 10:03:49 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@ -412,6 +412,10 @@ char dist_postfix[SSTRSIZE];
/* needed prototypes */
void set_menu_numopts(int, int);
void remove_color_options(void);
void remove_raid_options(void);
void remove_lvm_options(void);
void remove_cgd_options(void);
void remove_gpt_options(void);
/* Machine dependent functions .... */
void md_init(void);

View File

@ -1,4 +1,4 @@
/* $NetBSD: menus.mi,v 1.3 2014/08/04 08:50:13 martin Exp $ */
/* $NetBSD: menus.mi,v 1.4 2014/08/06 10:03:49 martin Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -62,19 +62,14 @@ src_prompt(const char *prompt, char *buf, size_t size)
msg_prompt_win(prompt, -1, 12, 0, 0, buf, buf, size);
}
void
remove_color_options()
static void
remove_sub_menu(int menuID)
{
/*
* Current terminal type does not support colors, so remove all
* menu entries (actually that is: Utils/Color Scheme) that do not
* make any sense in this case.
*/
for (size_t i = 0; i < DYN_MENU_START; i++) {
for (int j = 0; j < menu_def[i].numopts; j++) {
if ((menu_def[i].opts[j].opt_flags & OPT_SUB)
&& menu_def[i].opts[j].opt_menu == MENU_colors) {
&& menu_def[i].opts[j].opt_menu == menuID) {
for (int k = j + 1; k < menu_def[i].numopts;
k++) {
@ -89,6 +84,75 @@ remove_color_options()
}
}
static void
remove_menu_option(int menuID, const char *option)
{
for (int j = 0; j < menu_def[menuID].numopts; j++) {
if (menu_def[menuID].opts[j].opt_name == option) {
for (int k = j + 1; k < menu_def[menuID].numopts;
k++) {
menu_def[menuID].opts[k-1] =
menu_def[menuID].opts[k];
}
menu_def[menuID].numopts--;
return;
}
}
}
void
remove_color_options()
{
/*
* Current terminal type does not support colors, so remove all
* menu entries (actually that is: Utils/Color Scheme) that do not
* make any sense in this case.
*/
remove_sub_menu(MENU_colors);
}
void
remove_raid_options()
{
/*
* No raidframe available, remove the following menu entries:
*/
remove_menu_option(MENU_pmdiskentry, MSG_fmtasraid);
remove_menu_option(MENU_pmpartentry, MSG_fmtasraid);
}
void
remove_lvm_options()
{
/*
* No LVM available, remove the following menu entries:
*/
remove_menu_option(MENU_pmdiskentry, MSG_fmtaslvm);
remove_menu_option(MENU_pmpartentry, MSG_fmtaslvm);
}
void
remove_gpt_options()
{
/*
* No GPT available, remove the following menu entries:
*/
remove_menu_option(MENU_pmdiskentry, MSG_switchgpt);
remove_menu_option(MENU_pmpartentry, MSG_switchgpt);
}
void
remove_cgd_options()
{
/*
* No CGD available, remove the following menu entries:
*/
remove_menu_option(MENU_pmdiskentry, MSG_encrypt);
remove_menu_option(MENU_pmpartentry, MSG_encrypt);
}
}
default y=12, no exit, scrollable;

View File

@ -1,4 +1,4 @@
/* $NetBSD: partman.c,v 1.2 2014/08/05 08:39:39 martin Exp $ */
/* $NetBSD: partman.c,v 1.3 2014/08/06 10:03:49 martin Exp $ */
/*
* Copyright 2012 Eugene Lozovoy
@ -2707,6 +2707,15 @@ partman(void)
have_gpt = binary_available("gpt");
have_dk = binary_available("dkctl");
if (!have_raid)
remove_raid_options();
if (!have_lvm)
remove_lvm_options();
if (!have_gpt)
remove_gpt_options();
if (!have_cgd)
remove_cgd_options();
raids_t_info = (structinfo_t) {
.max = MAX_RAID,
.entry_size = sizeof raids[0],