menu_defect.c revision 052b6e8a13e1fb4be51ba482db6bb2e9833fa717
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains functions to implement the defect menu commands.
*/
#include "global.h"
#include <unistd.h>
#include <string.h>
#include "misc.h"
#include "menu_defect.h"
#include "param.h"
#include "ctlr_scsi.h"
/*
* This is the working defect list. All the commands here operate on
* the working list, except for 'commit'. This way the user can
* change his mind at any time without having mangled the current defect
* list.
*/
struct defect_list work_list;
#ifdef __STDC__
/* Function prototypes for ANSI C Compilers */
static int commit_list(void);
#else /* __STDC__ */
/* Function prototypes for non-ANSI C Compilers */
static int commit_list();
#endif /* __STDC__ */
/*
* This routine implements the 'restore' command. It sets the working
* list equal to the current list.
*/
int
{
int i;
/*
* If the working list has not been modified, there's nothing to do.
*/
err_print("working list was not modified.\n");
return (0);
}
/*
* Make sure the user is serious.
*/
if (check("Ready to update working list, continue"))
return (-1);
/*
* Lock out interrupts so the lists can't get mangled.
*/
/*
* Kill off the old working list.
*/
/*
* If the current isn't null, set the working list to be a
* copy of it.
*/
}
/*
* Initialize the flags since they are now in sync.
*/
fmt_print("working list set to null.\n\n");
else
fmt_print("working list updated, total of %d defects.\n\n",
return (0);
}
/*
* This routine implements the 'original' command. It extracts the
* manufacturer's defect list from the current disk.
*/
int
{
int status;
/*
* If the controller does not support the extraction, we're out
* of luck.
*/
err_print("Controller does not support extracting ");
err_print("manufacturer's defect list.\n");
return (-1);
}
/*
* Make sure the user is serious. Note, for SCSI disks
* since this is instantaneous, we will just do it and
* not ask for confirmation.
*/
"Ready to update working list. This cannot be interrupted\n\
and may take a long while. Continue"))
return (-1);
/*
* Lock out interrupts so we don't get half the list.
*/
/*
* Kill off the working list.
*/
fmt_print("Extracting manufacturer's defect list...");
/*
* Do the extraction.
*/
if (status)
fmt_print("Extraction failed.\n\n");
else {
fmt_print("Extraction complete.\n");
fmt_print("Working list updated, total of %d defects.\n\n",
}
/*
* Mark the working list dirty since we modified it.
*/
/*
* Return status.
*/
return (status);
}
/*
* This routine implements the 'extract' command. It extracts the
* entire defect list from the current disk.
*/
int
{
int status;
/*
* If the controller does not support the extraction, we are out
* of luck.
*/
err_print("Controller does not support extracting ");
err_print("current defect list.\n");
return (-1);
}
/*
* If disk is unformatted, you really shouldn't do this.
* However, ask user to be sure.
*/
if (! (cur_flags & DISK_FORMATTED) &&
(check(
"Cannot extract defect list from an unformatted disk. Continue")))
return (-1);
/*
* If this takes a long time, let's ask the user if he
* doesn't mind waiting. Note, for SCSI disks
* this operation is instantaneous so we won't ask for
* for confirmation.
*/
"Ready to extract working list. This cannot be interrupted\n\
and may take a long while. Continue"))
return (-1);
/*
* Lock out interrupts so we don't get half the list and
* Kill off the working list.
*/
fmt_print("Extracting defect list...");
/*
* Do the extraction.
*/
if (status) {
if (!EMBEDDED_SCSI) {
if (cur_flags & DISK_FORMATTED)
status = 0;
fmt_print("Extraction complete.\n");
"Working list updated, total of %d defects.\n\n",
} else {
fmt_print("Extraction failed.\n\n");
}
} else {
fmt_print("Extraction failed.\n\n");
}
} else {
fmt_print("Extraction complete.\n");
fmt_print("Working list updated, total of %d defects.\n\n",
}
/*
* Mark the working list dirty since we modified it.
*/
/*
* Return status.
*/
return (status);
}
/*
* This routine implements the 'add' command. It allows the user to
* enter the working defect list manually. It loops infinitely until
* the user breaks out with a ctrl-C.
*/
int
d_add()
{
struct defect_entry def;
/*
* Ask the user which mode of input he'd like to use.
*/
fmt_print(" 0. bytes-from-index\n");
fmt_print(" 1. logical block\n");
deflt = 0;
fmt_print("\nEnter Control-C to terminate.\n");
loop:
if (type) {
/*
* Mode selected is logical block. Input the defective block
* and fill in the defect entry with the info.
*/
} else {
}
} else {
/*
* Mode selected is bytes-from-index. Input the information
* about the defect and fill in the defect entry.
*/
"Enter defect's cylinder number", ':',
/*
* Note: a length of -1 means the length is not known. We
* make this the default value.
*/
deflt = -1;
}
/*
* Calculate where in the defect list this defect belongs
* and print it out.
*/
/*
* Lock out interrupts so lists don't get mangled.
* Also, mark the working list dirty since we are modifying it.
*/
/*
* If the list is null, create it with zero length. This is
* necessary because the routines to add a defect to the list
* assume the list is initialized.
*/
}
/*
* Add the defect to the working list.
*/
/*
* Loop back for the next defect.
*/
goto loop;
/*NOTREACHED*/
#ifdef lint
return (0);
#endif
}
/*
* This routine implements the 'delete' command. It allows the user
* to manually delete a defect from the working list.
*/
int
d_delete()
{
/*
* If the working list is null or zero length, there's nothing
* to delete.
*/
err_print("No defects to delete.\n");
return (-1);
}
/*
* Ask the user which defect should be deleted. Bounds are off by
* one because user sees a one-relative list.
*/
/*
*
* The user thinks it's one relative but it's not really.
*/
--num;
/*
* Print the defect selected and ask the user for confirmation.
*/
/*
* Lock out interrupts so the lists don't get mangled.
*/
/*
* Move down all the defects beyond the one deleted so the defect
* list is still fully populated.
*/
/*
* If the size of the list in sectors has changed, reallocate
* the list to shrink it appropriately.
*/
/*
* Decrement the defect count.
*/
/*
* Recalculate the list's checksum.
*/
/*
* Mark the working list dirty since we modified it.
*/
return (0);
}
/*
* This routine implements the 'print' command. It prints the working
* defect list out in human-readable format.
*/
int
d_print()
{
int i, nomore = 0;
int c, one_line = 0;
int tty_lines = get_tty_lines();
/*
* If the working list is null, there's nothing to print.
*/
if (EMBEDDED_SCSI)
"No list defined,extract primary or grown or both defects list first.\n");
else
err_print("No working list defined.\n");
return (-1);
}
/*
* If we're running from a file, don't use the paging scheme.
* If we are running interactive, turn off echoing.
*/
nomore++;
else {
echo_off();
charmode_on();
}
/* Print out the banner. */
/*
* Loop through the each defect in the working list.
*/
/*
* If we are paging and hit the end of a page, wait for
* the user to hit either space-bar, "q", or return
* before going on.
*/
if (one_line ||
/*
* Get the next character.
*/
fmt_print("- hit space for more - ");
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') {
fmt_print(" \015");
goto PRINT_EXIT;
}
/* Handle ^D */
if (c == '\004')
fullabort();
}
/*
* Print the defect.
*/
}
fmt_print("total of %d defects.\n\n", i);
/*
* If we were doing paging, turn echoing back on.
*/
if (!nomore) {
charmode_off();
echo_on();
}
return (0);
}
/*
* This routine implements the 'dump' command. It writes the working
* defect list to a file.
*/
int
d_dump()
{
int i, status = 0;
char *str;
struct defect_entry *dptr;
/*
* If the working list is null, there's nothing to do.
*/
if (EMBEDDED_SCSI)
"No list defined,extract primary or grown or both defects list first.\n");
else
err_print("No working list defined.\n");
return (-1);
}
/*
* Ask the user for the name of the defect file. Note that the
* input will be in malloc'd space since we are inputting
* type OSTR.
*/
/*
* Lock out interrupts so the file doesn't get half written.
*/
/*
* Open the file for writing.
*/
err_print("unable to open defect file.\n");
status = -1;
goto out;
}
/*
* Print a header containing the magic number, count, and checksum.
*/
/*
* Loop through each defect in the working list. Write the
* defect info to the defect file.
*/
}
fmt_print("defect file updated, total of %d defects.\n", i);
/*
* Close the defect file.
*/
out:
/*
* Destroy the string used for the file name.
*/
fmt_print("\n");
return (status);
}
/*
* This routine implements the 'load' command. It reads the working
* list in from a file.
*/
int
d_load()
{
char *str;
struct defect_entry *dptr;
/*
* Ask the user for the name of the defect file. Note that the
* input will be malloc'd space since we inputted type OSTR.
*/
/*
* Copy the file name into local space then destroy the string
* it came in. This is simply a precaution against later having
* to remember to destroy this space.
*/
/*
* See if the defect file is accessable. If not, we can't load
* from it. We do this here just so we can get out before asking
* the user for confirmation.
*/
if (status) {
err_print("defect file not accessable.\n");
return (-1);
}
/*
* Make sure the user is serious.
*/
if (check("ready to update working list, continue"))
return (-1);
/*
* Lock out interrupts so the list doesn't get half loaded.
*/
/*
* Open the defect file.
*/
err_print("unable to open defect file.\n");
return (-1);
}
/*
* Scan in the header.
*/
/*
* If the header is wrong, this isn't a good defect file.
*/
err_print("Defect file is corrupted.\n");
status = -1;
goto out;
}
/*
* Kill off any old defects in the working list.
*/
/*
* Load the working list header with the header info.
*/
if (magicno == NO_CHECKSUM)
else
/*
* Allocate space for the new list.
*/
SECSIZE);
/*
* Mark the working list dirty since we are modifying it.
*/
/*
* Loop through each defect in the defect file.
*/
for (i = 0; i < count; i++) {
/*
* Scan the info into the defect entry.
*/
/*
* If it didn't scan right, give up.
*/
if (items != 5)
goto bad;
}
/*
* Check to be sure the checksum from the defect file was correct
* unless there wasn't supposed to be a checksum.
* If there was supposed to be a valid checksum and there isn't
* then give up.
*/
goto bad;
fmt_print("working list updated, total of %d defects.\n", i);
goto out;
bad:
/*
* Some kind of error occurred. Kill off the working list and
* mark the status bad.
*/
err_print("Defect file is corrupted, working list set to NULL.\n");
status = -1;
out:
/*
* Close the defect file.
*/
fmt_print("\n");
return (status);
}
/*
* This routine implements the 'commit' command. It causes the current
* defect list to be set equal to the working defect list. It is the only
* way that changes made to the working list can actually take effect in
* the next format.
*/
int
d_commit()
{
/*
* If the working list wasn't modified, no commit is necessary.
*/
err_print("working list was not modified.\n");
return (0);
}
/*
* Make sure the user is serious.
*/
if (check("Ready to update Current Defect List, continue"))
return (-1);
return (do_commit());
}
int
{
int status;
if ((status = commit_list()) == 0) {
/*
* Remind the user to format the drive, since changing
* the list does nothing unless a format is performed.
*/
"Disk must be reformatted for changes to take effect.\n\n");
}
return (status);
}
static int
{
int i;
/*
* Lock out interrupts so the list doesn't get half copied.
*/
/*
* Kill off any current defect list.
*/
/*
* If the working list is null, initialize it to zero length.
* This is so the user can do a commit on a null list and get
* a zero length list. Otherwise there would be no way to get
* a zero length list conveniently.
*/
}
/*
* Copy the working list into the current list.
*/
/*
* Mark the working list clean, since it is now the same as the
* current list. Note we do not mark the current list dirty,
* even though it has been changed. This is because it does
* not reflect the state of disk, so we don't want it written
* out until a format has been done. The format will mark it
* dirty and write it out.
*/
if (EMBEDDED_SCSI)
fmt_print("Defect List has a total of %d defects.\n",
else
fmt_print("Current Defect List updated, total of %d defects.\n",
return (0);
}
/*
* This routine implements the 'create' command. It creates the
* manufacturer's defect on the current disk from the defect list
*/
int
d_create()
{
int status;
/*
* If the controller does not support the extraction, we're out
* of luck.
*/
err_print("Controller does not support creating ");
err_print("manufacturer's defect list.\n");
return (-1);
}
/*
* Make sure the user is serious. Note, for SCSI disks
* since this is instantaneous, we will just do it and
* not ask for confirmation.
*/
"Ready to create the manufacturers defect information on the disk.\n\
This cannot be interrupted and may take a long while.\n\
IT WILL DESTROY ALL OF THE DATA ON THE DISK! Continue"))
return (-1);
/*
* Lock out interrupts so we don't get half the list.
*/
fmt_print("Creating manufacturer's defect list...");
/*
* Do the Creation
*/
if (status) {
fmt_print("Creation failed.\n\n");
} else {
fmt_print("Creation complete.\n");
}
/*
* Return status.
*/
return (status);
}
/*
* Extract primary defect list - SCSI only
*/
int
{
int status;
/*
* Lock out interrupts so we don't get half the list and
* Kill off the working list.
*/
fmt_print("Extracting primary defect list...");
/*
* Do the extraction.
*/
if (status) {
fmt_print("Extraction failed.\n\n");
} else {
fmt_print("Extraction complete.\n");
/*
* Mark the working list dirty since we modified it.
* Automatically commit it, for SCSI only.
*/
status = commit_list();
fmt_print("\n");
}
/*
* Return status.
*/
return (status);
}
/*
* Extract grown defects list - SCSI only
*/
int
d_grown()
{
int status;
/*
* Lock out interrupts so we don't get half the list and
* Kill off the working list.
*/
fmt_print("Extracting grown defects list...");
/*
* Do the extraction.
*/
if (status) {
fmt_print("Extraction failed.\n\n");
} else {
fmt_print("Extraction complete.\n");
/*
* Mark the working list dirty since we modified it.
* Automatically commit it, for SCSI only.
*/
status = commit_list();
fmt_print("\n");
}
/*
* Return status.
*/
return (status);
}
/*
* Extract both primary and grown defects list - SCSI only
*/
int
d_both()
{
int status;
/*
* Lock out interrupts so we don't get half the list and
* Kill off the working list.
*/
fmt_print("Extracting both primary and grown defects lists...");
/*
* Do the extraction.
*/
if (status) {
fmt_print("Extraction failed.\n\n");
} else {
fmt_print("Extraction complete.\n");
/*
* Mark the working list dirty since we modified it.
* Automatically commit it, for SCSI only.
*/
status = commit_list();
fmt_print("\n");
}
/*
* Return status.
*/
return (status);
}