4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
29 * This file contains routines relating to running the menus.
38 /* Function prototypes for ANSI C Compilers */
39 static int (*find_enabled_menu_item())(struct menu_item
*menu
, int item
);
43 /* Function prototypes for non-ANSI C Compilers */
44 static int (*find_enabled_menu_item())();
48 static char cur_title
[MAXPATHLEN
];
51 * This routine takes a menu struct and concatenates the
52 * command names into an array of strings describing the menu.
53 * All menus have a 'quit' command at the bottom to exit the menu.
56 create_menu_list(menu
)
57 struct menu_item
*menu
;
59 register struct menu_item
*mptr
;
60 register char **cpptr
;
65 * A minimum list consists of the quit command, followed
66 * by a terminating null.
70 * Count the number of active commands in the menu and allocate
71 * space for the array of pointers.
73 for (mptr
= menu
; mptr
->menu_cmd
!= NULL
; mptr
++) {
74 if ((*mptr
->menu_state
)())
77 list
= (char **)zalloc(nitems
* sizeof (char *));
80 * Fill in the array with the names of the menu commands.
82 for (mptr
= menu
; mptr
->menu_cmd
!= NULL
; mptr
++) {
83 if ((*mptr
->menu_state
)()) {
84 *cpptr
++ = mptr
->menu_cmd
;
88 * Add the 'quit' command to the end.
95 * This routine takes a menu list created by the above routine and
96 * prints it nicely on the screen.
99 display_menu_list(list
)
104 for (str
= list
; *str
!= NULL
; str
++)
105 fmt_print(" %s\n", *str
);
109 * Find the "i"th enabled menu in a menu list. This depends
110 * on menu_state() returning the same status as when the
111 * original list of enabled commands was constructed.
114 find_enabled_menu_item(menu
, item
))()
115 struct menu_item
*menu
;
118 struct menu_item
*mp
;
120 for (mp
= menu
; mp
->menu_cmd
!= NULL
; mp
++) {
121 if ((*mp
->menu_state
)()) {
123 return (mp
->menu_func
);
132 * This routine 'runs' a menu. It repeatedly requests a command and
133 * executes the command chosen. It exits when the 'quit' command is
138 run_menu(menu
, title
, prompt
, display_flag
)
139 struct menu_item
*menu
;
152 * Create the menu list and display it.
154 list
= create_menu_list(menu
);
155 (void) strcpy(cur_title
, title
);
156 fmt_print("\n\n%s MENU:\n", title
);
157 display_menu_list(list
);
159 * Save the environment so a ctrl-C out of a command lands here.
164 * Ask the user which command they want to run.
166 ioparam
.io_charlist
= list
;
167 i
= input(FIO_MSTR
, prompt
, '>', &ioparam
, NULL
, CMD_INPUT
);
169 * If they choose 'quit', the party's over.
171 if ((f
= find_enabled_menu_item(menu
, i
)) == NULL
)
175 * Mark the saved environment active so the user can now
176 * do a ctrl-C to get out of the command.
180 * Run the command. If it returns an error and we are
181 * running out of a command file, the party's really over.
183 if ((*f
)() && option_f
)
186 * Mark the saved environment inactive so ctrl-C doesn't
187 * work at the menu itself.
191 * Since menu items are dynamic, some commands
192 * cause changes to occur. Destroy the old menu,
193 * and rebuild it, so we're always up-to-date.
195 destroy_data((char *)list
);
196 list
= create_menu_list(menu
);
198 * Redisplay menu, if we're returning to this one.
200 if (cur_menu
!= last_menu
) {
201 last_menu
= cur_menu
;
202 (void) strcpy(cur_title
, title
);
203 fmt_print("\n\n%s MENU:\n", title
);
204 display_menu_list(list
);
208 * Clean up the environment stack and throw away the menu list.
211 destroy_data((char *)list
);
215 * re-display the screen after exiting from shell escape
219 redisplay_menu_list(list
)
222 fmt_print("\n\n%s MENU:\n", cur_title
);
223 display_menu_list(list
);
228 * Glue to always return true. Used for menu items which
229 * are always enabled.
238 * Note: The following functions are used to enable the inclusion
239 * of device specific options (see init_menus.c). But when we are
240 * running non interactively with commands taken from a script file,
241 * current disk (cur_disk, cur_type, cur_ctype) may not be defined.
242 * They get defined when the script selects a disk using "disk" option
243 * in the main menu. However, in the normal interactive mode, the disk
244 * selection happens before entering the main menu.
247 * Return true for menu items enabled only for embedded SCSI controllers
252 if (cur_ctype
== NULL
&& option_f
)
254 return (EMBEDDED_SCSI
);
258 * Return false for menu items disabled only for embedded SCSI controllers
263 if (cur_ctype
== NULL
&& option_f
)
265 return (!EMBEDDED_SCSI
);
269 * Return false for menu items disabled for scsi controllers
274 if (cur_ctype
== NULL
&& option_f
)
280 * Return false for menu items disabled for efi labels
285 if ((cur_disk
== NULL
) && option_f
)
287 if (cur_disk
->label_type
== L_TYPE_EFI
)
293 disp_expert_change_expert_efi()
295 if ((cur_disk
== NULL
) && option_f
)
297 if ((cur_disk
->label_type
== L_TYPE_EFI
) && expert_mode
)
299 if (cur_disk
->label_type
!= L_TYPE_EFI
)
307 if ((cur_disk
== NULL
) && option_f
)
309 if (cur_disk
->label_type
!= L_TYPE_EFI
)
311 if (cur_parts
== NULL
)
317 disp_all_change_expert_efi()
319 if ((cur_disk
== NULL
) && option_f
)
321 if ((cur_disk
->label_type
!= L_TYPE_EFI
) || (!expert_mode
))
327 * Return true for menu items enabled scsi controllers
332 if (cur_ctype
== NULL
&& option_f
)
339 * Return true for menu items enabled if expert mode is enabled
344 if (cur_ctype
== NULL
&& option_f
)
346 return (SCSI
&& expert_mode
);
351 * Return true for menu items enabled if expert mode is enabled
356 return (expert_mode
);
358 #endif /* defined(i386) */
361 * Return true for menu items enabled if developer mode is enabled
370 * For x86, always return true for menu items enabled
371 * since fdisk is already supported on these two platforms.
372 * For Sparc, only return true for menu items enabled
373 * if a PCATA disk is selected.
376 support_fdisk_on_sparc()
380 * If it's a SCSI disk then we don't support fdisk and we
381 * don't need to know the type cause we can ask the disk,
382 * therefore we return true only if we *KNOW* it's an ATA
385 if (cur_ctype
&& cur_ctype
->ctype_ctype
== DKC_PCMCIA_ATA
) {
393 #error No Platform defined
394 #endif /* defined(sparc) */