main.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 the main entry point of the program and other
* routines relating to the general flow.
*/
#include "global.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <memory.h>
#include <string.h>
#include <errno.h>
#ifdef sparc
#endif
#include "main.h"
#include "analyze.h"
#include "menu.h"
#include "param.h"
#include "misc.h"
#include "startup.h"
#include "menu_command.h"
#include "menu_partition.h"
#include "prompts.h"
#include "checkmount.h"
#include "label.h"
extern struct menu_item menu_command[];
#ifdef __STDC__
/*
* Local prototypes for ANSI C compilers
*/
static void get_disk_characteristics(void);
#else /* __STDC__ */
/*
* Local prototypes for non-ANSI C compilers
*/
static void get_disk_characteristics();
#endif /* __STDC__ */
/*
* This is the main entry point.
*/
int
{
int i;
int ret_code = 1;
char **arglist;
struct partition_info *parts;
solaris_offset = 0;
/*
* Decode the command line options.
*/
/*
* If we are to run from a command file, open it up.
*/
if (option_f) {
err_print("Unable to open command file '%s'.\n",
option_f);
fullabort();
}
}
/*
* If we are logging, open the log file.
*/
if (option_l) {
err_print("Unable to open log file '%s'.\n",
option_l);
fullabort();
}
}
/*
* Read in the data file and initialize the hardware structs.
*/
sup_init();
/*
* If there are no disks on the command line, search the
* appropriate device directory for character devices that
* look like disks.
*/
if (i < 0) {
/*
* There were disks on the command line. They comprise the
* search list.
*/
} else {
}
/*
* Perform the search for disks.
*/
/*
* Catch ctrl-C and ctrl-Z so critical sections can be
* implemented. We use sigaction, as this sets up the
* signal handler permanently, and also automatically
* restarts any interrupted system call.
*/
err_print("sigaction(SIGINT) failed - %s\n",
fullabort();
}
err_print("sigaction(SIGTSTP) failed - %s\n",
fullabort();
}
err_print("sigaction(SIGALRM) failed - %s\n",
fullabort();
}
/*
* If there was only 1 disk on the command line, mark it
* to be the current disk. If it wasn't found, it's an error.
*/
if (i == argc - 1) {
err_print("Unable to find specified disk '%s'.\n",
argv[i]);
fullabort();
}
}
/*
* A disk was forced on the command line.
*/
if (option_d) {
/*
* Find it in the list of found disks and mark it to
* be the current disk.
*/
break;
/*
* If it wasn't found, it's an error.
*/
err_print("Unable to find specified disk '%s'.\n",
option_d);
fullabort();
}
}
/*
* A disk type was forced on the command line.
*/
/*
* Only legal if a disk was also forced.
*/
err_print("Must specify disk as well as type.\n");
fullabort();
}
/*
* Find the specified type in the list of legal types
* for the disk.
*/
break;
/*
* If it wasn't found, it's an error.
*/
"Specified type '%s' is not a known type.\n", option_t);
fullabort();
}
/*
* If the specified type is not the same as the type
* in the disk label, update the type and nullify the
* partition map.
*/
}
}
/*
* A partition map was forced on the command line.
*/
if (option_p) {
/*
* Only legal if both disk and type were also forced.
*/
err_print("Must specify disk and type as well ");
err_print("as partitiion.\n");
fullabort();
}
/*
* Find the specified map in the list of legal maps
* for the type.
*/
break;
/*
* If it wasn't found, it's an error.
*/
"Specified table '%s' is not a known table.\n", option_p);
fullabort();
}
/*
* Update the map.
*/
}
/*
* If a disk was marked to become current, initialize the state
* to make it current. If not, ask user to pick one.
*/
while (ret_code) {
}
}
#ifdef BUG1134748
/*
* if -f command-file is specified, check for disk and disktype
* input also. For SCSI disks, the type input may not be needed
* since format would have figured that using inquiry information.
*/
if (option_f) {
err_print("Must specify a disk using -d option.\n");
fullabort();
}
err_print("Must specify disk as well as type.\n");
fullabort();
}
}
#endif /* BUG1134748 */
/*
* Run the command menu.
*/
/*
* normal ending. Explicitly return(0);
*/
return (0);
}
/*
* This routine initializes the internal state to ready it for a new
* current disk. There are a zillion state variables that store
* information on the current disk, and they must all be updated.
* We also tell SunOS about the disk, since it may not know if the
* disk wasn't labeled at boot time.
*/
void
{
int status;
#ifdef sparc
int i;
#endif
/*
* If there was an old current disk, close the file for it.
*/
/*
* Kill off any defect lists still lying around.
*/
/*
* If there were any buffers, free them up.
*/
destroy_data((char *)cur_buf);
}
if ((char *)pattern_buf != NULL) {
destroy_data((char *)pattern_buf);
pattern_buf = NULL;
}
/*
* Fill in the hardware struct pointers for the new disk.
*/
cur_flags = 0;
/*
* Open a file for the new disk.
*/
fullabort();
}
#ifdef sparc
/*
* If the new disk uses bad-144, initialize the bad block table.
*/
for (i = 0; i < NDKBAD; i++) {
}
}
#endif
/*
* If the type of the new disk is known...
*/
/*
* Initialize the physical characteristics.
* If need disk specs, prompt for undefined disk
* characteristics. If running from a file,
* use defaults.
*/
}
/*
* Alternates per cylinder are forced to 0 or 1,
* independent of what the label says. This works
* because we know which ctlr we are dealing with.
*/
apc = 1;
else
apc = 0;
/*
* Initialize the surface analysis info. We always start
* out with scan set for the whole disk. Note,
* for SCSI disks, we can only scan the data area.
*/
scan_lower = 0;
}
/*
* Allocate the buffers.
*/
/*
* Tell the user which disk (s)he selected.
*/
if (chk_volname(cur_disk)) {
fmt_print("\n");
} else {
}
/*
* If the drive is formatted...
*/
if ((*cur_ops->op_ck_format)()) {
/*
* Mark it formatted.
*/
/*
* Read the defect list, if we have one.
*/
if (!EMBEDDED_SCSI) {
}
#ifdef sparc
/*
* If the disk does BAD-144, we do an ioctl to
* tell SunOS about the bad block table.
*/
"Warning: error telling SunOS bad block map table.\n");
}
}
#endif
fmt_print("[disk formatted");
if (!EMBEDDED_SCSI) {
fmt_print(", defect list found");
} else {
fmt_print(", no defect list found");
}
}
fmt_print("]");
/*
* Drive wasn't formatted. Tell the user in case he
* disagrees.
*/
} else if (EMBEDDED_SCSI) {
fmt_print("[disk unformatted]");
} else {
/*
* Make sure the user is serious. Note, for
* SCSI disks since this is instantaneous, we
* will just do it and not ask for confirmation.
*/
status = 0;
if (check("\n\
Ready to get manufacturer's defect list from unformatted drive.\n\
This cannot be interrupted and takes a long while.\n\
Continue"))
status = 1;
else
"Extracting manufacturer's defect list...");
}
/*
* Extract manufacturer's defect list.
*/
} else {
status = 1;
}
fmt_print("[disk unformatted");
if (status != 0) {
fmt_print(", no defect list found]");
} else {
fmt_print(", defect list found]");
}
}
} else {
/*
* Disk type is not known.
* Initialize physical characteristics to 0 and tell the
* user we don't know what type the disk is.
*/
}
fmt_print("\n");
/*
* Check to see if there are any mounted file systems on the
* disk. If there are, print a warning.
*/
err_print("Warning: Current Disk has mounted partitions.\n");
/*
* Get the Solaris Fdisk Partition information
*/
}
/*
* Prompt for some undefined disk characteristics.
* Used when there is no disk definition, but the
* disk has a valid label, so basically we're
* prompting for everything that isn't in the label.
*/
static void
{
/*
* The need_spefs flag is used to tell us that this disk
* is not a known type and the ctlr specific info must
* be prompted for. We only prompt for the info that applies
* to this ctlr.
*/
/*
* If we're running with input from a file, use
* reasonable defaults, since prompting for the
* information will probably mess things up.
*/
if (option_f) {
cur_dtype->dtype_phead = 0;
cur_dtype->dtype_psect = 0;
cur_dtype->dtype_cyl_skew = 0;
cur_dtype->dtype_trk_skew = 0;
cur_dtype->dtype_trks_zone = 0;
cur_dtype->dtype_atrks = 0;
cur_dtype->dtype_asect = 0;
cur_dtype->dtype_cache = 0;
cur_dtype->dtype_threshold = 0;
cur_dtype->dtype_prefetch_min = 0;
cur_dtype->dtype_prefetch_max = 0;
}
} else {
#ifdef sparc
cur_dtype->dtype_dr_type = 0;
#endif
}
}