menu_command.c revision 9daef70d225b6364f70a31bb53a4d55b46150690
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file contains functions that implement the command menu commands.
*/
#include "global.h"
#include <time.h>
#include <sys/resource.h>
#include <strings.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#if defined(sparc)
#endif /* defined(sparc) */
#include "main.h"
#include "analyze.h"
#include "menu.h"
#include "menu_command.h"
#include "menu_defect.h"
#include "menu_partition.h"
#include "param.h"
#include "misc.h"
#include "label.h"
#include "startup.h"
#include "partition.h"
#include "prompts.h"
#include "checkdev.h"
#include "io.h"
#include "ctlr_scsi.h"
#include "auto_sense.h"
#include "modify_partition.h"
extern struct menu_item menu_partition[];
extern struct menu_item menu_analyze[];
extern struct menu_item menu_defect[];
/*
* Choices for the p_tag vtoc field
*/
slist_t ptag_choices[] = {
{ NULL }
};
/*
* Choices for the p_flag vtoc field
*/
slist_t pflag_choices[] = {
{ "wm", "read-write, mountable", 0 },
{ NULL }
};
/*
* This routine implements the 'disk' command. It allows the user to
* select a disk to be current. The list of choices is the list of
* disks that were found at startup time.
*/
int
c_disk()
{
int i;
int ndisks = 0;
int blind_select = 0;
int deflt;
int index;
int more = 0;
int more_quit = 0;
int one_line = 0;
int tty_lines;
/*
* This buffer holds the check() prompt that verifies we've got the right
* disk when performing a blind selection. The size should be sufficient
* to hold the prompt string, plus 256 characters for the disk name -
* way more than should ever be necessary. See the #define in misc.h.
*/
char chk_buf[BLIND_SELECT_VER_PROMPT];
if (istokenpresent()) {
/*
* disk number to be selected is already in the
* input stream .
*/
/*
* Get the disk number the user has given.
*/
i = 0;
i++;
}
/*
* Convert the token into an integer.
*/
return (0);
/*
* Check to be sure it is within the legal bounds.
*/
return (0);
}
goto checkdisk;
}
fmt_print("\n\nAVAILABLE DISK SELECTIONS:\n");
i = 0;
/*
* We have a real terminal for std input and output, enable
* more style of output for disk selection list.
*/
more = 1;
tty_lines = get_tty_lines();
echo_off();
charmode_on();
}
/*
* Loop through the list of found disks.
*/
/*
* If using more output, account 2 lines for each disk.
*/
int c;
/*
* Get the next character.
*/
fmt_print("- hit space for more or s to select - ");
c = getchar();
fmt_print("\015");
one_line = 0;
/*
* Handle display one line command
* (return key)
*/
if (c == '\012') {
one_line++;
}
/* Handle Quit command */
if (c == 'q') {
" \015");
more_quit++;
}
/* Handle ^D command */
if (c == '\004')
fullabort();
/* or get on with the show */
if (c == 's' || c == 'S') {
break;
}
}
/*
* If this is the current disk, mark it as
* the default.
*/
deflt = i;
}
pr_diskline(disk, i);
i++;
}
if (more) {
charmode_off();
echo_on();
}
/*
* Determine total number of disks, and ask the user which disk he
* would like to make current.
*/
ndisks++;
}
if (index >= i) {
blind_select = 1;
}
/*
* Find the disk chosen. Search through controllers/disks
* in the same original order, so we match what the user
* chose.
*/
i = 0;
if (i == index)
goto found;
i++;
}
/*
* Should never happen.
*/
impossible("no disk found");
if (blind_select) {
return (-1);
}
}
/*
* Update the state. We lock out interrupts so the state can't
* get half-updated.
*/
/*
* If type unknown and interactive, ask user to specify type.
* Also, set partition table (best guess) too.
*/
(void) c_type();
}
/*
* Get the Solaris Fdisk Partition information
*/
err_print("Reading the primary EFI GPT label ");
err_print("failed. Using backup label.\n");
err_print("Use the 'backup' command to restore ");
err_print("the primary label.\n");
}
#if defined(_SUNOS_VTOC_16)
/*
* If there is no fdisk solaris partition.
*/
err_print("No Solaris fdisk partition found.\n");
goto exit;
}
#endif /* defined(_SUNOS_VTOC_16) */
/*
* If the label of the disk is marked dirty,
* see if they'd like to label the disk now.
*/
if (check("Disk not labeled. Label it now") == 0) {
if (write_label()) {
err_print("Write label failed\n");
} else {
}
}
}
exit:
return (0);
}
/*
* This routine implements the 'type' command. It allows the user to
* specify the type of the current disk. It should be necessary only
* if the disk was not labelled or was somehow labelled incorrectly.
* The list of legal types for the disk comes from information that was
* in the data file.
*/
int
c_type()
{
int first_disk;
int auto_conf_choice;
int other_choice;
char volname[LEN_DKL_VVOL];
int volinit = 0;
/*
* There must be a current disk.
*/
err_print("Current Disk is not set.\n");
return (-1);
}
/*
* Print out the list of choices.
*/
fmt_print("\n\nAVAILABLE DRIVE TYPES:\n");
first_disk = 0;
auto_conf_choice = 0;
} else {
auto_conf_choice = -1;
}
i = first_disk;
/*
* If we pass the current type, mark it to be the default.
*/
deflt = i;
}
continue;
}
if (tptr->dtype_asciilabel)
}
other_choice = i;
fmt_print(" %d. other\n", i);
/*
* Ask the user which type the disk is.
*/
/*
*/
if (index == auto_conf_choice) {
float scaled;
int nparts;
/*
* User chose "auto configure".
*/
switch (cur_disk->label_type) {
case L_TYPE_SOLARIS:
err_print("Auto configure failed\n");
return (-1);
}
fmt_print("%s: configured with capacity of ",
if (scaled > 1024.0) {
} else {
}
fmt_print("<%s cyl %d alt %d hd %d sec %d>\n",
tptr->dtype_nsect);
break;
case L_TYPE_EFI:
err_print("Auto configure failed\n");
return (-1);
}
fmt_print("%s: configured with capacity of ",
if (scaled > 1024.0) {
} else {
}
fmt_print("\n");
nparts++) {
V_RESERVED) {
volinit = 1;
}
break;
}
}
fmt_print("Autoconfiguration failed.\n");
return (-1);
}
if (volinit) {
nparts++) {
V_RESERVED) {
(void) strcpy(
volname);
break;
}
}
}
return (0);
break;
default:
/* Should never happen */
return (-1);
}
/*
* User chose "other".
* Get the standard information on the new type.
* Put all information in a tmp structure, in
* case user aborts.
*/
d->dtype_ncyl = get_ncyl();
d->dtype_nhead = get_nhead();
d->dtype_nsect = get_nsect();
&d->dtype_options);
#if defined(sparc)
d->dtype_dr_type = 0;
#endif /* defined(sparc) */
d->dtype_asciilabel = get_asciilabel();
/*
* Add the new type to the list of possible types for
* this controller. We lock out interrupts so the lists
* can't get munged. We put off actually allocating the
* structure till here in case the user wanted to
* interrupt while still inputting information.
*/
else {
}
/*
* the new disk type does not have any defined
* partition table . Hence copy the current partition
* table if possible else create a default
* paritition table.
*/
}
if (write_label()) {
err_print("Write label failed\n");
} else {
}
return (0);
} else {
/*
* User picked an existing disk type.
*/
i = first_disk;
while (i < index) {
if (tptr->dtype_asciilabel) {
i++;
}
}
}
}
}
/*
* Check for mounted file systems in the format zone.
* One potential problem with this would be that check()
* always returns 'yes' when running out of a file. However,
* it is actually ok because we don't let the program get
* started if there are mounted file systems and we are
* running from a file.
*/
"Cannot set disk type while it has mounted partitions.\n\n");
return (-1);
}
/*
* check for partitions being used for swapping in format zone
*/
err_print("Cannot set disk type while its partition are \
currently being used for swapping.\n");
return (-1);
}
/*
* Check for partitions being used in SVM, VxVM or LU devices
*/
(diskaddr_t)-1, 0, 0)) {
err_print("Cannot set disk type while its "
"partitions are currently in use.\n");
return (-1);
}
/*
* If the type selected is different from the previous type,
* mark the disk as not labelled and reload the current
* partition info. This is not essential but probably the
* right thing to do, since the size of the disk has probably
* changed.
*/
}
/*
* Initialize the state of the current disk.
*/
(void) get_partition();
/*
* If the label of the disk is marked dirty,
* see if they'd like to label the disk now.
*/
if (check("Disk not labeled. Label it now") == 0) {
if (write_label()) {
err_print("Write label failed\n");
} else {
}
}
}
return (0);
}
/*
* This routine implements the 'partition' command. It simply runs
* the partition menu.
*/
int
{
/*
* There must be a current disk type and a current disk
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* Check for a valid fdisk table entry for Solaris
*/
if (!good_fdisk()) {
return (-1);
}
cur_menu++;
#ifdef not
/*
* If there is no current partition table, make one. This is
* so the commands within the menu never have to check for
* a non-existent table.
*/
err_print("making partition.\n");
#endif /* not */
/*
* Run the menu.
*/
cur_menu--;
return (0);
}
/*
* This routine implements the 'current' command. It describes the
* current disk.
*/
int
{
/*
* If there is no current disk, say so. Note that this is
* not an error since it is a legitimate response to the inquiry.
*/
fmt_print("No Current Disk.\n");
return (0);
}
/*
* Print out the info we have on the current disk.
*/
if (chk_volname(cur_disk)) {
fmt_print(": ");
}
fmt_print("\n");
fmt_print("<type unknown>\n");
} else if (cur_label == L_TYPE_SOLARIS) {
fmt_print("<%s cyl %d alt %d hd %d sec %d>\n",
} else if (cur_label == L_TYPE_EFI) {
fmt_print("\n");
}
} else {
fmt_print("type unknown");
} else if (cur_label == L_TYPE_SOLARIS) {
fmt_print("%s cyl %d alt %d hd %d sec %d",
} else if (cur_label == L_TYPE_EFI) {
fmt_print("\n");
}
fmt_print(">\n");
}
fmt_print("\n");
return (0);
}
/*
* This routine implements the 'format' command. It allows the user
* to format and verify any portion of the disk.
*/
int
c_format()
{
int format_interval;
int status;
/*
* There must be a current disk type and a current disk
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* There must be a format routine in cur_ops structure to have
* this routine work.
*/
"Cannot format this drive. Please use your Manufacturer supplied formatting "
"utility.\n");
return (-1);
}
/*
* There must be a current defect list. Except for
* unformatted SCSI disks. For them the defect list
* can only be retrieved after formatting the disk.
*/
! (cur_flags & DISK_FORMATTED)) {
err_print("Current Defect List must be initialized.\n");
return (-1);
}
/*
* Ask for the bounds of the format. We always use the whole
* disk as the default, since that is the most likely case.
* Note, for disks which must be formatted accross the whole disk,
* don't bother the user.
*/
if (cur_label == L_TYPE_SOLARIS) {
} else {
}
} else {
}
"Enter starting block number", ':',
"Enter ending block number", ':',
}
/*
* Some disks can format tracks. Make sure the whole track is
* specified for them.
*/
err_print("Controller requires formatting of ");
err_print("entire tracks.\n");
return (-1);
}
}
/*
* Check for mounted file systems in the format zone, and if we
* find any, make sure they are really serious. One potential
* problem with this would be that check() always returns 'yes'
* when running out of a file. However, it is actually ok
* because we don't let the program get started if there are
* mounted file systems and we are running from a file.
*/
"Cannot format disk while it has mounted partitions.\n\n");
return (-1);
}
/*
* check for partitions being used for swapping in format zone
*/
err_print("Cannot format disk while its partition are \
currently being used for swapping.\n");
return (-1);
}
/*
* Check for partitions being used in SVM, VxVM or LU devices
* in this format zone
*/
err_print("Cannot format disk while its partitions "
"are currently in use.\n");
return (-1);
}
"Ready to format. Formatting cannot be interrupted\n"
"and takes %d minutes (estimated). ", format_time);
/*
* Formatting time is (2 * time of 1 spin * number of
* tracks) + (step rate * number of cylinders) rounded
* up to the nearest minute. Note, a 10% fudge factor
* is thrown in for insurance.
*/
if (cur_dtype->dtype_fmt_time == 0)
/*
* ms.
*/
/*
* 20% done tick (sec)
*/
/*
* min.
*/
/*
* Check format time values and make adjustments
* to prevent sleeping too long (forever?) or
* too short.
*/
if (format_time <= 1) {
/*
* Format time is less than 1 min..
*/
format_time = 1;
}
if (format_interval < 11) {
/* Format time is less than 1 minute. */
if (format_interval < 2)
format_interval = 10;
} else {
/* Format time is greater than 1 minute. */
format_interval -= 10;
}
"Ready to format. Formatting cannot be interrupted\n"
"and takes %d minutes (estimated). ", format_time);
} else {
"Ready to format. Formatting cannot be interrupted.\n");
}
if (check("Continue")) {
return (-1);
}
/*
* Print the time so that the user will know when format started.
* Lock out interrupts. This could be a problem, since it could
* cause the user to sit for quite awhile with no control, but we
* don't have any other good way of keeping his gun from going off.
*/
fmt_print("Beginning format. The current time is %s\n",
/*
* Mark the defect list dirty so it will be rewritten when we are
* done. It is possible to qualify this so it doesn't always
* get rewritten, but it's not worth the trouble.
* Note: no defect lists for embedded scsi drives.
*/
if (!EMBEDDED_SCSI) {
}
/*
* If we are formatting over any of the labels, mark the label
* dirty so it will be rewritten.
*/
cur_flags |= LABEL_DIRTY;
}
if (start < 34) {
cur_flags |= LABEL_DIRTY;
}
}
if (start == 0) {
cur_flags |= LABEL_DIRTY;
}
/*
* Do the format. bugid 1009138 removed the use of fork to
* background the format and print a tick.
*/
if (status) {
err_print("failed\n");
return (-1);
}
fmt_print("done\n");
if (option_msg && diag_msg) {
}
/*
* If the defect list or label is dirty, write them out again.
* Note, for SCSI we have to wait til now to load defect list
* since we can't access it until after formatting a virgin disk.
*/
/* enter_critical(); */
err_print("Warning: unable to reload defect list\n");
return (-1);
}
}
}
if (cur_flags & LABEL_DIRTY) {
(void) write_label();
cur_flags &= ~LABEL_DIRTY;
}
/*
* Come up for air, since the verify step does not need to
* be atomic (it does it's own lockouts when necessary).
*/
/*
* If we are supposed to verify, we do the 'write' test over
* the format zone. The rest of the analysis parameters are
* left the way they were.
*/
if (scan_auto) {
scan_entire = 0;
scan_lower = start;
scan_upper = end;
fmt_print("\nVerifying media...");
}
/*
* If the defect list or label is dirty, write them out again.
*/
}
if (cur_flags & LABEL_DIRTY) {
cur_flags &= ~LABEL_DIRTY;
(void) write_label();
}
return (status);
}
/*
* This routine implements the 'repair' command. It allows the user
* to reallocate sectors on the disk that have gone bad.
*/
int
c_repair()
{
int status;
int buf_is_good;
int block_has_error;
int i;
/*
* There must be a current disk type (and therefore a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* The current disk must be formatted for repair to work.
*/
if (!(cur_flags & DISK_FORMATTED)) {
err_print("Current Disk is unformatted.\n");
return (-1);
}
/*
* Check for a valid fdisk table entry for Solaris
*/
if (!good_fdisk()) {
return (-1);
}
/*
* Repair is an optional command for controllers, so it may
* not be supported.
*/
err_print("Controller does not support repairing.\n");
err_print("or disk supports automatic defect management.\n");
return (-1);
}
/*
* There must be a defect list for non-embedded scsi devices,
* since we will add to it.
*/
err_print("Current Defect List must be initialized.\n");
return (-1);
}
/*
* Ask the user which sector has gone bad.
*/
} else {
}
"Enter absolute block number of defect", ':',
/*
* Check to see if there is a mounted file system over the
* specified sector. If there is, make sure the user is
* really serious.
*/
if (check("Repair is in a mounted partition, continue"))
return (-1);
}
/*
* check for partitions being used for swapping in format zone
*/
if (check("Repair is in a partition which is currently \
being used for swapping.\ncontinue"))
return (-1);
}
if (check("Repair is in a partition which is currently "
"in use.\ncontinue"))
return (-1);
}
/*
* Try to read the sector before repairing it. If we can
* get good data out of it, we can write that data back
* after the repair. If the sector looks ok, ask the
* user to confirm the repair, since it doesn't appear
* necessary. Try reading the block several times to
* see if we can read it consistently.
*
* First, let's see if the block appears to have problems...
*/
block_has_error = 1;
for (i = 0; i < 5; i++) {
if (status)
break; /* one of the tries failed */
}
if (status == 0) {
block_has_error = 0;
if (check("\
This block doesn't appear to be bad. Repair it anyway")) {
return (0);
}
}
/*
* Last chance...
*/
if (check("Ready to repair defect, continue")) {
return (-1);
}
/*
* We're committed to repairing it. Try to get any good
* data out of the block if possible. Note that we do
* not set the F_ALLERRS flag.
*/
buf_is_good = 0;
for (i = 0; i < 5; i++) {
if (status == 0) {
buf_is_good = 1;
break;
}
}
/*
* Lock out interrupts so the disk can't get out of sync with
* the defect list.
*/
fmt_print("Repairing ");
if (block_has_error) {
}
fmt_print(")...");
/*
* Do the repair.
*/
if (status) {
fmt_print("failed.\n\n");
} else {
/*
* The repair worked. Write the old data to the new
* block if we were able to read it, otherwise
* zero out the new block. If it looks like the
* new block is bad, let the user know that, too.
* Should we attempt auto-repair in this case?
*/
fmt_print("ok.\n");
if (!buf_is_good) {
}
if (status == 0) {
}
if (status) {
fmt_print(") also appears defective.\n");
}
fmt_print("\n");
/*
* Add the bad sector to the defect list, write out
* the defect list, and kill off the working list so
* it will get synced up with the current defect list
* next time we need it.
*
* For embedded scsi, we don't require a defect list.
* However, if we have one, add the defect if the
* list includes the grown list. If not, kill it
* to force a resync if we need the list later.
*/
if (EMBEDDED_SCSI) {
} else {
}
}
fmt_print("Current list updated\n");
}
} else {
}
}
/*
* Return status.
*/
return (status);
}
/*
* This routine implements the 'show' command. It translates a disk
* block given in any format into decimal, hexadecimal, and
*/
int
c_show()
{
/*
* There must be a current disk type, so we will know the geometry.
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* Ask the user for a disk block.
*/
} else {
}
/*
* Echo it back.
*/
fmt_print(")\n\n");
return (0);
}
/*
* This routine implements the 'label' command. It writes the
* primary and backup labels onto the current disk.
*/
int
c_label()
{
int status;
/*
* There must be a current disk type (and therefore a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* The current disk must be formatted to label it.
*/
if (!(cur_flags & DISK_FORMATTED)) {
err_print("Current Disk is unformatted.\n");
return (-1);
}
/*
* Check for a valid fdisk table entry for Solaris
*/
if (!good_fdisk()) {
return (-1);
}
/*
* Check to see if there are any mounted file systems anywhere
* on the current disk. If so, refuse to label the disk, but
* only if the partitions would change for the mounted partitions.
*
*/
/* Bleagh, too descriptive */
if (check_label_with_mount()) {
err_print("Cannot label disk while it has "
"mounted partitions.\n\n");
return (-1);
}
}
/*
* check to see if there any partitions being used for swapping
* on the current disk. If so, refuse to label the disk, but
* only if the partitions would change for the mounted partitions.
*/
if (check_label_with_swap()) {
err_print("Cannot label disk while its "
"partitions are currently being used for "
"swapping.\n");
return (-1);
}
}
/*
* Check to see if any partitions used for svm, vxvm or live upgrade
* are on the disk. If so, refuse to label the disk, but only
* if we are trying to shrink a partition in use.
*/
err_print("Cannot label disk when "
"partitions are in use as described.\n");
return (-1);
}
/*
* If there is not a current partition map, warn the user we
* are going to use the default. The default is the first
* partition map we encountered in the data file. If there is
* no default we give up.
*/
fmt_print("Current Partition Table is not set, "
"using default.\n");
err_print("No default available, cannot label.\n");
return (-1);
}
}
/*
* If expert (-e) mode, then ask user if they wish
* to change the current solaris label into an EFI one
*/
if (expert_mode) {
#if defined(_SUNOS_VTOC_8)
int i;
#endif
int choice;
/* Ask user what label to use */
fmt_print("[0] SMI Label\n");
fmt_print("[1] EFI Label\n");
if (cur_label == L_TYPE_SOLARIS)
deflt = 0;
else
deflt = 1;
goto expert_end;
goto expert_end;
}
switch (choice) {
case 0:
/*
* EFI label to SMI label
*/
fmt_print("Warning: SMI labels only support up to 2 TB.\n");
}
fmt_print("Warning: This disk has an EFI label. Changing to"
" SMI label will erase all\ncurrent partitions.\n");
if (check("Continue"))
return (-1);
#if defined(_FIRMWARE_NEEDS_FDISK)
fmt_print("You must use fdisk to delete the current "
"EFI partition and create a new\n"
"Solaris partition before you can convert the "
"label.\n");
return (-1);
#endif
}
#if defined(_FIRMWARE_NEEDS_FDISK)
fmt_print("You must use fdisk to create a Solaris "
"partition before you can convert the label.\n");
return (-1);
}
#endif
else
fmt_print("Autoconfiguration failed.\n");
return (-1);
}
if (status = write_label())
err_print("Label failed.\n");
else
return (status);
} else {
err_print("Label failed.\n");
return (-1);
}
case 1:
/*
* SMI label to EFI label
*/
fmt_print("Warning: This disk has an SMI label. Changing to "
"EFI label will erase all\ncurrent partitions.\n");
if (check("Continue")) {
return (-1);
}
return (-1);
}
#if defined(_SUNOS_VTOC_16)
#endif /* defined(_SUNOC_VTOC_16) */
#if defined(_SUNOS_VTOC_8)
for (i = 0; i < NDKMAP; i++) {
}
#endif /* defined(_SUNOS_VTOC_8) */
return (-1);
}
return (-1);
}
err_print("Warning: error writing EFI.\n");
return (-1);
} else {
}
/*
* copy over the EFI vtoc onto the SMI vtoc and return
* okay.
*/
fmt_print("Autoconfiguration failed.\n");
return (-1);
}
/*
* Get the Solais Fdisk Partition information.
*/
return (0);
}
}
/*
* Make sure the user is serious.
*/
if (check("Ready to label disk, continue")) {
return (-1);
}
/*
* Write the labels out (this will also notify unix) and
* return status.
*/
fmt_print("\n");
if (status = write_label())
err_print("Label failed.\n");
return (status);
}
/*
* This routine implements the 'analyze' command. It simply runs
* the analyze menu.
*/
int
{
/*
* There must be a current disk type (and therefor a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
cur_menu++;
/*
* Run the menu.
*/
cur_menu--;
return (0);
}
/*
* This routine implements the 'defect' command. It simply runs
* the defect menu.
*/
int
c_defect()
{
int i;
/*
* There must be a current disk type (and therefor a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* Check for the defect management and list management ops and
* display appropriate message.
*/
err_print("Controller does not support defect management\n");
err_print("or disk supports automatic defect management.\n");
return (-1);
}
cur_menu++;
/*
* Lock out interrupt while we manipulate the defect lists.
*/
/*
* If the working list is null but there is a current list,
* update the working list to be a copy of the current list.
*/
}
/*
* Run the menu.
*/
cur_menu--;
/*
* If the user has modified the working list but not committed
* it, warn him that he is probably making a mistake.
*/
if (!EMBEDDED_SCSI) {
"Warning: working defect list modified; but not committed.\n");
if (!check(
"Do you wish to commit changes to current defect list"))
(void) do_commit();
}
}
return (0);
}
/*
* This routine implements the 'backup' command. It allows the user
* to search for backup labels on the current disk. This is useful
* if the primary label was lost and the user wishes to recover the
* partition information for the disk. The disk is relabeled and
* the current defect list is written out if a backup label is found.
*/
int
c_backup()
{
/*
* There must be a current disk type (and therefore a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* The disk must be formatted to read backup labels.
*/
if (!(cur_flags & DISK_FORMATTED)) {
err_print("Current Disk is unformatted.\n");
return (-1);
}
/*
* Check for a valid fdisk table entry for Solaris
*/
if (!good_fdisk()) {
return (-1);
}
/*
* If we found a primary label on this disk, make sure
* the user is serious.
*/
EFI_GPT_PRIMARY_CORRUPT) == 0) &&
check("Disk has a primary label, still continue"))
return (-1);
fmt_print("Restoring primary label.\n");
if (write_label()) {
err_print("Failed\n");
return (-1);
}
return (0);
DSK_LABEL) &&
(check("Disk has a primary label, still continue"))) {
return (-1);
}
fmt_print("Searching for backup labels...");
/*
* Some disks have the backup labels in a strange place.
*/
head = 2;
else
/*
* Loop through each copy of the backup label.
*/
sec += 2) {
/*
* Attempt to read it.
*/
continue;
}
/*
* Verify that it is a reasonable label.
*/
if (!checklabel(&label))
continue;
continue;
/*
* Lock out interrupts while we manipulate lists.
*/
fmt_print("found.\n");
/*
* Find out which disk type the backup label claims.
*/
break;
/*
* If it disagrees with our current type, something
* real bad is happening.
*/
fmt_print("\
Unknown disk type in backup label\n");
return (-1);
}
fmt_print("Backup label claims different type:\n");
fmt_print(" <%s cyl %d alt %d hd %d sec %d>\n",
if (check("Continue")) {
return (-1);
}
}
/*
* Try to match the partition map with a known map.
*/
break;
/*
* If we couldn't match it, allocate space for a new one,
* fill in the info, and add it to the list. The name
* for the new map is derived from the disk name.
*/
parts = (struct partition_info *)
zalloc(sizeof (struct partition_info));
else {
}
for (i = 0; i < NDKMAP; i++)
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#endif /* defined(_SUNOS_VTOC_8) */
}
/*
* We now have a partition map. Make it the current map.
*/
/*
* Rewrite the labels and defect lists, as appropriate.
*/
if (EMBEDDED_SCSI) {
fmt_print("Restoring primary label.\n");
if (write_label())
return (-1);
} else {
fmt_print("Restoring primary label and defect list.\n");
if (write_label())
return (-1);
}
fmt_print("\n");
return (0);
}
/*
* If we didn't find any backup labels, say so.
*/
fmt_print("not found.\n\n");
return (0);
}
/*
* This routine is called by c_verify() for an EFI labeled disk
*/
static int
{
struct partition_info tmp_pinfo;
int status;
if (status != 0) {
err_print("Warning: Could not read label.\n");
return (-1);
}
err_print("Reading the primary EFI GPT label ");
err_print("failed. Using backup label.\n");
err_print("Use the 'backup' command to restore ");
err_print("the primary label.\n");
}
fmt_print("\n");
fmt_print("Volume name = <%8s>\n",
} else {
fmt_print("Volume name = < >\n");
}
fmt_print("ascii name = ");
fmt_print("\n");
fmt_print("accessible sectors = %llu\n",
return (0);
}
/*
* This routine implements the 'verify' command. It allows the user
* to read the labels on the current disk.
*/
int
c_verify()
{
struct partition_info tmp_pinfo;
int p_label_bad = 0;
int b_label_bad = 0;
int p_label_found = 0;
int b_label_found = 0;
char id_str[128];
/*
* There must be a current disk type (and therefore a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* The disk must be formatted to read labels.
*/
if (!(cur_flags & DISK_FORMATTED)) {
err_print("Current Disk is unformatted.\n");
return (-1);
}
/*
* Check for a valid fdisk table entry for Solaris
*/
if (!good_fdisk()) {
return (-1);
}
/*
* Branch off here if the disk is EFI labelled.
*/
if (cur_label == L_TYPE_EFI) {
return (c_verify_efi());
}
/*
* Attempt to read the primary label.
*/
if (status == -1) {
err_print("Warning: Could not read primary label.\n");
p_label_bad = 1;
} else {
/*
* Verify that it is a reasonable label.
*/
/*
* Save complete ascii string for printing later.
*/
err_print("\
Warning: Primary label appears to be corrupt.\n");
p_label_bad = 1;
} else {
p_label_found = 1;
/*
* Make sure it matches current label
*/
err_print("\
Warning: Primary label on disk appears to be different from\ncurrent label.\n");
p_label_bad = 1;
}
}
}
/*
* Read backup labels.
* Some disks have the backup labels in a strange place.
*/
head = 2;
else
/*
* Loop through each copy of the backup label.
*/
sec += 2) {
/*
* Attempt to read it.
*/
continue;
/*
* Verify that it is a reasonable label.
*/
if (!checklabel(&b_label))
continue;
/*
* Save complete label only if no primary label exists
*/
if (!p_label_found)
continue;
b_label_found = 1;
/*
* Compare against primary label
*/
if (p_label_found) {
p_label.dkl_asciilabel) != 0) ||
b_label_bad = 1;
} else {
for (i = 0; i < NDKMAP; i++) {
#if defined(_SUNOS_VTOC_8)
b_label_bad = 1;
break;
}
#elif defined(_SUNOS_VTOC_16)
b_label_bad = 1;
break;
}
#else
#endif /* defined(_SUNOS_VTOC_8) */
}
}
}
if (b_label_bad)
"Warning: Primary and backup labels do not match.\n");
break;
}
/*
* If we didn't find any backup labels, say so.
*/
if (!b_label_found)
err_print("Warning: Could not read backup labels.\n");
err_print("\n\
Warning: Check the current partitioning and 'label' the disk or use the\n\
\t 'backup' command.\n");
/*
* Print label information.
*/
if (p_label_found) {
fmt_print("\nPrimary label contents:\n");
} else if (b_label_found) {
fmt_print("\nBackup label contents:\n");
} else {
return (0);
}
/*
* Must put info into partition_info struct for
* for print routine.
*/
for (i = 0; i < NDKMAP; i++) {
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#endif /* defined(_SUNOS_VTOC_8) */
}
fmt_print("\n");
#if defined(_SUNOS_VTOC_16)
#endif /* defined(_SUNOS_VTOC_16) */
return (0);
}
/*
* This command implements the inquiry command, for embedded SCSI
* disks only, which issues a SCSI inquiry command, and
* displays the resulting vendor, product id and revision level.
*/
int
{
char inqbuf[255];
struct scsi_inquiry *inq;
err_print("Failed\n");
return (-1);
} else {
fmt_print("Vendor: ");
fmt_print("\nProduct: ");
fmt_print("\nRevision: ");
fmt_print("\n");
}
return (0);
}
/*
* This routine allows the user to set the 8-character
* volume name in the vtoc. It then writes both the
* primary and backup labels onto the current disk.
*/
int
{
int status;
char *prompt;
union {
int xfoo;
} x;
char *volname;
/*
* There must be a current disk type (and therefore a current disk).
*/
err_print("Current Disk Type is not set.\n");
return (-1);
}
/*
* The current disk must be formatted to label it.
*/
if (!(cur_flags & DISK_FORMATTED)) {
err_print("Current Disk is unformatted.\n");
return (-1);
}
/*
* Check for a valid fdisk table entry for Solaris
*/
if (!good_fdisk()) {
return (-1);
}
/*
* The current disk must be formatted to label it.
*/
"Please select a partition map for the disk first.\n");
return (-1);
}
/*
* Check to see if there are any mounted file systems anywhere
* on the current disk. If so, refuse to label the disk, but
* only if the partitions would change for the mounted partitions.
*
*/
/* Bleagh, too descriptive */
if (check_label_with_mount()) {
"Cannot label disk while it has mounted partitions.\n\n");
return (-1);
}
}
/*
* Check to see if there are partitions being used for swapping
* on the current disk. If so, refuse to label the disk, but
* only if the partitions would change for the swap partitions.
*
*/
/* Bleagh, too descriptive */
if (check_label_with_swap()) {
"Cannot label disk while its partitions are currently \
being used for swapping.\n\n");
return (-1);
}
}
/*
* Check to see if any partitions used for svm, vxvm, ZFS zpool
* or live upgrade are on the disk. If so, refuse to label the
* disk, but only if we are trying to shrink a partition in
* use.
*/
err_print("Cannot label disk while its partitions "
"are in use as described.\n");
return (-1);
}
/*
* Prompt for the disk volume name.
*/
prompt = "Enter 8-character volume name (remember quotes)";
/*
* Get the input using "get_inputline" since
* input would never return null string.
*/
/*
* Get input from the user.
*/
/*
* check for return.
*/
if (s1[0] == 0) {
volname = x.defvolname;
} else {
/*
* remove the " mark from volname.
*/
if (s1[0] == '"') {
int i = 1;
i++;
s1[i] = '\0';
} else {
};
}
/*
* Make sure the user is serious.
*/
if (check("Ready to label disk, continue")) {
fmt_print("\n");
return (-1);
}
/*
* Use the volume name chosen above
*/
LEN_DKL_VVOL));
if (cur_label == L_TYPE_EFI) {
}
/*
* Write the labels out (this will also notify unix) and
* return status.
*/
fmt_print("\n");
if (status = write_label())
err_print("Label failed.\n");
return (status);
}