startup.c revision 69ed0c8ece2346b34605e2c9567c9f7b0dad5dc8
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file contains the code to perform program startup. This
* includes reading the data file and the search for disks.
*/
#include "global.h"
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <fcntl.h>
#include <errno.h>
#include <memory.h>
#include <dirent.h>
#include "startup.h"
#include "param.h"
#include "label.h"
#include "misc.h"
#include "menu_command.h"
#include "partition.h"
#include "ctlr_scsi.h"
#include "auto_sense.h"
extern struct ctlr_type ctlr_types[];
extern int nctypes;
extern struct ctlr_ops genericops;
extern long strtol();
extern int errno;
#ifdef __STDC__
/* Function prototypes for ANSI C Compilers */
static void usage(void);
static int sup_prxfile(void);
static void sup_setpath(void);
static void sup_setdtype(void);
static int sup_change_spec(struct disk_type *, char *);
static void sup_setpart(void);
static void search_for_logical_dev(char *devname);
static void search_duplicate_dtypes(void);
static void search_duplicate_pinfo(void);
struct partition_info *pp2);
static char *get_physical_name(char *);
static void sort_disk_list(void);
static int disk_name_compare(const void *, const void *);
static void make_controller_list(void);
static void check_for_duplicate_disknames(char *arglist[]);
#else /* __STDC__ */
/* Function prototypes for non-ANSI C Compilers */
static void usage();
static int sup_prxfile();
static void sup_setpath();
static void sup_setdtype();
static int sup_change_spec();
static void sup_setpart();
static void search_for_logical_dev();
static void add_device_to_disklist();
static int disk_is_known();
static void datafile_error();
static void search_duplicate_dtypes();
static void search_duplicate_pinfo();
static void check_dtypes_for_inconsistency();
static void check_pinfo_for_inconsistency();
static int str2cyls();
static struct chg_list *new_chg_list();
static char *get_physical_name();
static void sort_disk_list();
static int disk_name_compare();
static void make_controller_list();
static void check_for_duplicate_disknames();
#endif /* __STDC__ */
#if defined(sparc)
static char *other_ctlrs[] = {
"ata"
};
#define OTHER_CTLRS 1
static char *other_ctlrs[] = {
"ISP-80"
};
#define OTHER_CTLRS 2
#else
#endif
/*
* This global is used to store the current line # in the data file.
* It must be global because the I/O routines are allowed to side
* effect it to keep track of backslashed newlines.
*/
int data_lineno; /* current line # in data file */
/*
* Search path as defined in the format.dat files
*/
static char **search_path = NULL;
static int name_represents_wholedisk(char *name);
/*
* This routine digests the options on the command line. It returns
* the index into argv of the first string that is not an option. If
* there are none, it returns -1.
*/
int
{
char *ptr;
int i;
int next;
/*
* Default is no extended messages. Can be enabled manually.
*/
option_msg = 0;
diag_msg = 0;
expert_mode = 0;
need_newline = 0;
dev_expert = 0;
/*
* Loop through the argument list, incrementing each time by
* an amount determined by the options found.
*/
/*
* Start out assuming an increment of 1.
*/
next = i + 1;
/*
* As soon as we hit a non-option, we're done.
*/
if (*argv[i] != '-')
return (i);
/*
* Loop through all the characters in this option string.
*/
/*
* Determine each option represented. For options
* that use a second string, increase the increment
* of the main loop so they aren't re-interpreted.
*/
switch (*ptr) {
case 's':
case 'S':
option_s = 1;
break;
case 'f':
case 'F':
goto badopt;
break;
case 'l':
case 'L':
goto badopt;
break;
case 'x':
case 'X':
goto badopt;
break;
case 'd':
case 'D':
goto badopt;
break;
case 't':
case 'T':
goto badopt;
break;
case 'p':
case 'P':
goto badopt;
break;
case 'm':
option_msg = 1;
break;
case 'M':
option_msg = 1;
diag_msg = 1;
break;
case 'e':
expert_mode = 1;
break;
#ifdef DEBUG
case 'z':
dev_expert = 1;
break;
#endif
default:
usage();
break;
}
}
}
/*
* All the command line strings were options. Return that fact.
*/
return (-1);
}
static void
usage()
{
err_print("Usage: format [-s][-d disk_name]");
err_print("[-t disk_type][-p partition_name]\n");
err_print("\t[-f cmd_file][-l log_file]");
err_print("[-x data_file] [-m] [-M] [-e] disk_list\n");
fullabort();
}
/*
* This routine reads in and digests the data file. The data file contains
* definitions for the search path, known disk types, and known partition
* maps.
*
* Note: for each file being processed, file_name is a pointer to that
* file's name. We are careful to make sure that file_name points to
* globally-accessible data, not data on the stack, because each
* disk/partition/controller definition now keeps a pointer to the
* filename in which it was defined. In the case of duplicate,
* conflicting definitions, we can thus tell the user exactly where
* the problem is occurring.
*/
void
sup_init()
{
int nopened_files = 0;
#if defined(sparc)
char fname[MAXPATHLEN];
char *path;
char *p;
#endif /* defined(sparc) */
/*
* Create a singly-linked list of controller types so that we may
* dynamically add unknown controllers to this for 3'rd
* party disk support.
*/
/*
* If a data file was specified on the command line, use it first
* If the file cannot be opened, fail. We want to guarantee
* that, if the user explicitly names a file, they can
* access it.
*
* option_x is already global, no need to dup it on the heap.
*/
if (option_x) {
if (sup_prxfile()) {
} else {
err_print("Unable to open data file '%s' - %s.\n",
fullabort();
}
}
#if defined(sparc)
/*
* Now look for an environment variable FORMAT_PATH.
* If found, we use it as a colon-separated list
* of directories. If no such environment variable
* is defined, use a default path of "/etc".
*/
path = "/etc";
}
/*
* Traverse the path one file at a time. Pick off
* the file name, and append the name "format.dat"
* at the end of the pathname.
* Whatever string we construct, duplicate it on the
* heap, so that file_name is globally accessible.
*/
while (*path != 0) {
p = fname;
*p++ = *path++;
if (p == fname)
continue;
*p = 0;
if (*path == ':')
path++;
/*
* If the path we have so far is a directory,
* look for a format.dat file in that directory,
* otherwise try using the path name specified.
* This permits arbitrary file names in the
* path specification, if this proves useful.
*/
err_print("Unable to access '%s' - %s.\n",
} else {
if (*(p-1) != '/')
*p++ = '/';
(void) strcpy(p, "format.dat");
}
if (sup_prxfile()) {
}
}
}
#endif /* defined(sparc) */
/*
* Check for duplicate disk or partitions definitions
* that are inconsistent - this would be very confusing.
*/
}
/*
* Open and process a format data file. Unfortunately, we use
* globals: file_name for the file name, and data_file
* for the descriptor. Return true if able to open the file.
*/
static int
{
int status;
/*
* Open the data file. Return 0 if unable to do so.
*/
return (0);
}
/*
* Step through the data file a meta-line at a time. There are
* typically several backslashed newlines in each meta-line,
* so data_lineno will be getting side effected along the way.
*/
data_lineno = 0;
for (;;) {
data_lineno++;
/*
* Get the keyword.
*/
/*
* If we hit the end of the data file, we're done.
*/
break;
/*
* If the line is blank, skip it.
*/
continue;
/*
* If the line starts with some key character, it's an error.
*/
if (status != SUP_STRING) {
continue;
}
/*
* Clean up the token and see which keyword it is. Call
* the appropriate routine to process the rest of the line.
*/
sup_setpath();
sup_setdtype();
sup_setpart();
else {
}
}
/*
* Close the data file.
*/
return (1);
}
/*
* This routine processes a 'search_path' line in the data file. The
* search path is a list of disk names that will be searched for by the
* program.
*
* The static path_size and path_alloc are used to build up the
* list of files comprising the search path. The static definitions
* enable supporting multiple search path definitions.
*/
static void
{
int status;
static int path_size;
static int path_alloc;
/*
* Pull in some grammar.
*/
return;
}
/*
* Loop through the entries.
*/
for (;;) {
/*
* Pull in the disk name.
*/
/*
* If we hit end of line, we're done.
*/
break;
/*
* If we hit some key character, it's an error.
*/
if (status != SUP_STRING) {
break;
}
/*
* Build the string into an argvlist. This array
* is dynamically sized, as necessary, and terminated
* with a null. Each name is alloc'ed on the heap,
* so no dangling references.
*/
&path_alloc, cleaned);
/*
* Pull in some grammar.
*/
break;
break;
}
}
}
/*
* This routine processes a 'disk_type' line in the data file. It defines
* the physical attributes of a brand of disk when connected to a specific
* controller type.
*/
static void
{
char *dtype_name, *ptr;
struct mctlr_list *mlp;
/*
* Pull in some grammar.
*/
return;
}
/*
* Pull in the name of the disk type.
*/
if (status != SUP_STRING) {
return;
}
/*
* Allocate space for the disk type and copy in the name.
*/
/*
* Save the filename/linenumber where this disk was defined
*/
/*
* Loop for each attribute.
*/
for (;;) {
/*
* Pull in some grammar.
*/
/*
* If we hit end of line, we're done.
*/
break;
return;
}
/*
* Pull in the attribute.
*/
/*
* If we hit end of line, we're done.
*/
break;
/*
* If we hit a key character, it's an error.
*/
if (status != SUP_STRING) {
return;
}
clean_token(ident, token);
/*
* Check to see if we've got a change specification
* If so, this routine will parse the entire
* specification, so just restart at top of loop
*/
if (sup_change_spec(dtype, ident)) {
continue;
}
/*
* Pull in more grammar.
*/
return;
}
/*
* Pull in the value of the attribute.
*/
if (status != SUP_STRING) {
return;
}
/*
* If the attribute defined the ctlr...
*/
if (strcmp(ident, "ctlr") == 0) {
/*
* Match the value with a ctlr type.
*/
cleaned) == 0)
break;
}
/*
* If we couldn't match it, it's an error.
*/
for (i = 0; i < OTHER_CTLRS; i++) {
== 0) {
return;
}
}
if (i == OTHER_CTLRS) {
"Unknown controller '%s'",
cleaned);
return;
}
}
/*
* Found a match. Add this disk type to the list
* for the ctlr type if we can complete the
* disk specification correctly.
*/
continue;
}
/*
* All other attributes require a numeric value. Convert
* the value to a number.
*/
if (*ptr != '\0') {
datafile_error("Expecting an integer, found '%s'",
cleaned);
return;
}
/*
* Figure out which attribute it was and fill in the
* appropriate value. Also note that the attribute
* has been defined.
*/
if (strcmp(ident, "ncyl") == 0) {
} else if (strcmp(ident, "acyl") == 0) {
} else if (strcmp(ident, "pcyl") == 0) {
} else if (strcmp(ident, "nhead") == 0) {
} else if (strcmp(ident, "nsect") == 0) {
} else if (strcmp(ident, "rpm") == 0) {
} else if (strcmp(ident, "bpt") == 0) {
} else if (strcmp(ident, "bps") == 0) {
} else if (strcmp(ident, "drive_type") == 0) {
flags |= SUP_DRTYPE;
} else if (strcmp(ident, "cache") == 0) {
} else if (strcmp(ident, "prefetch") == 0) {
flags |= SUP_PREFETCH;
} else if (strcmp(ident, "read_retries") == 0) {
} else if (strcmp(ident, "write_retries") == 0) {
} else if (strcmp(ident, "min_prefetch") == 0) {
flags |= SUP_CACHE_MIN;
} else if (strcmp(ident, "max_prefetch") == 0) {
flags |= SUP_CACHE_MAX;
} else if (strcmp(ident, "trks_zone") == 0) {
flags |= SUP_TRKS_ZONE;
} else if (strcmp(ident, "atrks") == 0) {
} else if (strcmp(ident, "asect") == 0) {
} else if (strcmp(ident, "psect") == 0) {
} else if (strcmp(ident, "phead") == 0) {
} else if (strcmp(ident, "fmt_time") == 0) {
flags |= SUP_FMTTIME;
} else if (strcmp(ident, "cyl_skew") == 0) {
flags |= SUP_CYLSKEW;
} else if (strcmp(ident, "trk_skew") == 0) {
flags |= SUP_TRKSKEW;
} else {
datafile_error("Unknown keyword '%s'", ident);
}
}
/*
* Check to be sure all the necessary attributes have been defined.
* If any are missing, it's an error. Also, log options for later
* use by specific driver.
*/
return;
}
return;
}
return;
}
/*
* Add this disk type to the list for the ctlr type
*/
} else {
}
}
/*
* Parse a SCSI mode page change specification.
*
* Return:
* 0: not change specification, continue parsing
* 1: was change specification, it was ok,
* or we already handled the error.
*/
static int
{
char *p;
char *p2;
int pageno;
int byteno;
int mode;
int value;
TOKEN ident;
int tilde;
int i;
/*
* Syntax: p[<nn>|0x<xx>]
*/
if (*id != 'p') {
return (0);
}
if (*p2 != 0) {
return (0);
}
/*
* Once we get this far, we know we have the
* beginnings of a change specification.
* If there's a problem now, report the problem,
* and return 1, so that the caller can restart
* parsing at the next expression.
*/
if (!scsi_supported_page(pageno)) {
return (1);
}
/*
* Next token should be the byte offset
*/
return (1);
}
clean_token(ident, token);
/*
* Syntax: b[<nn>|0x<xx>]
*/
p = ident;
if (*p++ != 'b') {
datafile_error("Unknown keyword '%s'", ident);
return (1);
}
if (*p2 != 0) {
datafile_error("Unknown keyword '%s'", ident);
return (1);
}
datafile_error("Unsupported byte offset '%s'", ident);
return (1);
}
/*
* Get the operator for this expression
*/
switch (sup_gettoken(token)) {
case SUP_EQL:
mode = CHG_MODE_ABS;
break;
case SUP_OR:
mode = CHG_MODE_SET;
break;
case SUP_AND:
mode = CHG_MODE_CLR;
break;
}
if (mode == CHG_MODE_UNDEFINED) {
return (1);
}
/*
* Get right-hand of expression - accept optional tilde
*/
tilde = 0;
tilde = 1;
i = sup_gettoken(token);
}
if (i != SUP_STRING) {
return (1);
}
clean_token(ident, token);
if (*p != 0) {
return (1);
}
/*
* Apply the tilde operator, if found.
* Constrain to a byte value.
*/
if (tilde) {
}
value &= 0xff;
/*
* We parsed a successful change specification expression.
* Add it to the list for this disk type.
*/
return (1);
}
/*
* This routine processes a 'partition' line in the data file. It defines
* a known partition map for a particular disk type on a particular
* controller type.
*/
static void
{
char *pinfo_name;
struct mctlr_list *mlp;
/*
* Pull in some grammar.
*/
return;
}
/*
* Pull in the name of the map.
*/
if (status != SUP_STRING) {
return;
}
/*
* Allocate space for the partition map and fill in the name.
*/
/*
* Save the filename/linenumber where this partition was defined
*/
/*
* Install default vtoc information into the new partition table
*/
/*
* Loop for each attribute in the line.
*/
for (;;) {
/*
* Pull in some grammar.
*/
/*
* If we hit end of line, we're done.
*/
break;
return;
}
/*
* Pull in the attribute.
*/
/*
* If we hit end of line, we're done.
*/
break;
if (status != SUP_STRING) {
return;
}
clean_token(ident, token);
/*
* Pull in more grammar.
*/
return;
}
/*
* Pull in the value of the attribute.
*/
/*
* If we hit a key character, it's an error.
*/
if (status != SUP_STRING) {
return;
}
/*
* If the attribute is the ctlr, save the ctlr name and
* mark it defined.
*/
if (strcmp(ident, "ctlr") == 0) {
continue;
/*
* If the attribute is the disk, save the disk name and
* mark it defined.
*/
} else if (strcmp(ident, "disk") == 0) {
continue;
}
/*
* If we now know both the controller name and the
* disk name, let's see if we can find the controller
* and disk type. This will give us the geometry,
* which can permit us to accept partitions specs
* in cylinders or blocks.
*/
/*
* Attempt to match the specified ctlr to a known type.
*/
ctlr) == 0)
break;
}
/*
* If no match is found, it's an error.
*/
for (i = 0; i < OTHER_CTLRS; i++) {
return;
}
}
if (i == OTHER_CTLRS) {
"Unknown controller '%s'", ctlr);
return;
}
}
/*
* Attempt to match the specified disk to a known type.
*/
break;
}
/*
* If no match is found, it's an error.
*/
return;
}
/*
* Now that we know the disk type, set up the
* globals that let that magic macro "spc()"
* do it's thing. Sorry that this is glued
* together so poorly...
*/
}
/*
* By now, the disk and controller type must be defined
*/
return;
}
/*
* The rest of the attributes are all single letters.
* Make sure the specified attribute is a single letter.
*/
if (strlen(ident) != 1) {
datafile_error("Unknown keyword '%s'", ident);
return;
}
/*
* Also make sure it is within the legal range of letters.
*/
datafile_error("Unknown keyword '%s'", ident);
return;
}
/*
* Here's the index of the partition we're dealing with
*/
index = ident[0] - PARTITION_BASE;
/*
* For SunOS 5.0, we support the additional syntax:
* [<tag>, ] [<flag>, ] <start>, <end>
* instead of:
* <start>, <end>
*
* <tag> may be one of: boot, root, swap, etc.
* <flag> consists of two characters:
* W (writable) or R (read-only)
* M (mountable) or U (unmountable)
*
* Start with the defaults assigned above:
*/
/*
* First try to match token against possible tag values
*/
/*
* Found valid tag. Use it and advance parser
*/
"Expecting ', ', found '%s'", token);
return;
}
if (status != SUP_STRING) {
datafile_error("Expecting value, found '%s'",
token);
return;
}
}
/*
* Try to match token against possible flag values
*/
/*
* Found valid flag. Use it and advance parser
*/
datafile_error("Expecting ', ', found '%s'",
token);
return;
}
if (status != SUP_STRING) {
datafile_error("Expecting value, found '%s'",
token);
return;
}
}
/*
* All other attributes have a pair of numeric values.
* Convert the first value to a number. This value
* is the starting cylinder number of the partition.
*/
datafile_error("Expecting an integer, found '%s'",
cleaned);
return;
}
/*
* Pull in some grammar.
*/
return;
}
/*
* Pull in the second value.
*/
if (status != SUP_STRING) {
return;
}
/*
* Convert the second value to a number. This value
* is the number of blocks composing the partition.
* If the token is terminated with a 'c', the units
* are cylinders, not blocks. Also accept a 'b', if
* they choose to be so specific.
*/
datafile_error("Expecting an integer, found '%s'",
cleaned);
return;
}
/*
* Fill in the appropriate map entry with the values.
*/
#if defined(_SUNOS_VTOC_16)
if (val2 == 0) {
}
#endif /* defined(_SUNOS_VTOC_16) */
}
/*
* Check to be sure that all necessary attributes were defined.
*/
return;
}
/*
* Add this partition map to the list of known maps for the
*/
else {
}
}
/*
* Open the disk device - just a wrapper for open.
*/
int
{
}
/*
* This routine performs the disk search during startup. It looks for
* all the disks in the search path, and creates a list of those that
* are found.
*/
void
{
char **sp;
char s[MAXPATHLEN];
char path[MAXPATHLEN];
char curdir[MAXPATHLEN];
int i;
/*
* Change directory to the device directory. This
* gives us the most efficient access to that directory.
* Remember where we were, and return there when finished.
*/
err_print("Cannot get current directory - %s\n",
fullabort();
}
err_print("Cannot set directory to %s - %s\n",
fullabort();
}
/*
* If there were disks specified on the command line,
* use those disks, and nothing but those disks.
*/
}
} else {
/*
* If there were no disks specified on the command line,
* search for all disks attached to the system.
*/
fmt_print("Searching for disks...");
need_newline = 1;
/*
* Find all disks specified in search_path definitions
* in whatever format.dat files were processed.
*/
sp = search_path;
search_for_logical_dev(*sp++);
}
}
/*
* Open the device directory
*/
err_print("Cannot open %s - %s\n",
fullabort();
}
/*
* First find all nodes which do not conform to
* standard disk naming conventions. This permits
* all user-defined names to override the default names.
*/
continue;
/*
* If non-conventional name represents
* a link to non-s2 slice , ignore it.
*/
}
}
}
}
/*
* Now find all nodes corresponding to the standard
* device naming conventions.
*/
continue;
}
}
/*
* Close the directory
*/
err_print("Cannot close directory %s - %s\n",
fullabort();
}
need_newline = 0;
fmt_print("done\n");
}
/*
* Return to whence we came
*/
err_print("Cannot set directory to %s - %s\n",
fullabort();
}
/*
* If we didn't find any disks, give up.
*/
if (geteuid() == 0) {
err_print("No disks found!\n");
} else {
err_print("No permission (or no disks found)!\n");
}
fullabort();
}
/*
* Tell user the results of the auto-configure process
*/
i = 0;
float scaled;
if (i++ == 0) {
fmt_print("\n");
}
fmt_print("configured ");
} else {
fmt_print("configured and labeled ");
}
else
fmt_print("with capacity of ");
if (scaled > 1024.0) {
} else {
}
}
}
}
/*
* For a given "logical" disk name as specified in a format.dat
* search path, try to find the device it actually refers to.
* Since we are trying to maintain 4.x naming convention
* compatibility in 5.0, this involves a little bit of work.
* We also want to be able to function under 4.x, if needed.
*
* canonical: standard name reference. append a partition
* reference, and open that file in the device directory.
* examples: SVR4: c0t0d0
* 4.x: sd0
*
* absolute: begins with a '/', and is assumed to be an
* absolute pathname to some node.
*
* relative: non-canonical, doesn't begin with a '/'.
* assumed to be the name of a file in the appropriate
* device directory.
*/
static void
search_for_logical_dev(char *devname)
{
char path[MAXPATHLEN];
char *partition = "s2";
/*
* If the name is an absolute path name, accept it as is
*/
if (*devname == '/') {
} else if (canonical_name(devname)) {
/*
* If canonical name, construct a standard path name.
*/
} else if (canonical4x_name(devname)) {
/*
* Check to see if it's a 4.x file name in the /dev
* directory on 5.0. Here, we only accept the
* canonicalized form: sd0.
*/
} else {
/*
* If it's not a canonical name, then it may be a
* reference to an actual file name in the device
* directory itself.
*/
}
/* now add the device */
}
/*
* Add a device to the disk list, if it appears to be a disk,
* and we haven't already found it under some other name.
*/
static void
{
struct disk_info *search_disk;
struct ctlr_info *search_ctlr;
struct partition_info *search_parts;
struct partition_info *parts;
struct dk_label search_label;
struct mctlr_list *mlp;
int search_file;
int status;
int i;
int access_flags = 0;
/*
* Attempt to open the disk. If it fails, skip it.
*/
return;
}
/*
* Must be a character device
*/
(void) close(search_file);
return;
}
/*
* Attempt to read the configuration info on the disk.
* Again, if it fails, we assume the disk's not there.
* Note we must close the file for the disk before we
* continue.
*/
(void) close(search_file);
return;
}
/* If it is a removable media, skip it. */
if (!expert_mode) {
int isremovable, ret;
if ((ret >= 0) && (isremovable != 0)) {
(void) close(search_file);
return;
}
}
} else {
}
/*
* If the type of disk is one we don't know about,
* add it to the list.
*/
break;
}
}
&mediainfo) < 0) {
}
}
/*
* Skip CDROM devices, they are read only.
* But not devices like Iomega Rev Drive which
* identifies itself as a CDROM, but has a removable
* disk.
*/
(void) close(search_file);
return;
}
/*
* create the new ctlr_type structure and fill it in.
*/
/*
* DKIOCINFO returned a controller name longer
* than DK_DEVLEN bytes, which means more of the
* dk_cinfo structure may be corrupt. We don't
* allow the user to perform any operations on
* the device in this case
*/
err_print("\nError: Device %s: controller "
"name (%s)\nis invalid. Device will not "
(void) close(search_file);
destroy_data((char *)tctlr);
return;
} else {
/*
* copy the generic disk ops structure into local copy.
*/
}
}
}
/*
* Search through all disks known at this time, to
* determine if we're already identified this disk.
* If so, then there's no need to include it a
* second time. This permits the user-defined names
* to supercede the standard conventional names.
*/
if (disk_is_known(&dkinfo)) {
(void) close(search_file);
return;
}
#if defined(sparc)
/*
* Because opening id with FNDELAY always succeeds,
* read the label early on to see whether the device
* really exists. A result of DSK_RESERVED
* means the disk may be reserved.
* In the future, it will be good
* to move these into controller specific files and have a common
* generic check for reserved disks here, including intel disks.
*/
char *first_sector;
switch (i) {
case DSK_RESERVED:
break;
case DSK_UNAVAILABLE:
break;
default:
break;
}
}
#endif /* defined(sparc) */
/*
* The disk appears to be present. Allocate space for the
* disk structure and add it to the list of found disks.
*/
else {
;
}
/*
* Fill in some info from the ioctls.
*/
if (is_efi_type(search_file)) {
} else {
}
/*
* Remember the names of the disk
*/
/*
* Remember the lba size of the disk
*/
/*
* Determine if this device is linked to a physical name.
*/
/*
* Try to match the ctlr for this disk with a ctlr we
* have already found. A match is assumed if the ctlrs
* are at the same address && ctypes agree
*/
break;
/*
* If no match was found, we need to identify this ctlr.
*/
if (search_ctlr == NULL) {
/*
* Match the type of the ctlr to a known type.
*/
break;
}
/*
* If no match was found, it's an error.
* Close the disk and report the error.
*/
err_print("\nError: found disk attached to ");
err_print("unsupported controller type '%d'.\n",
(void) close(search_file);
return;
}
/*
* Allocate space for the ctlr structure and add it
* to the list of found ctlrs.
*/
search_ctlr = (struct ctlr_info *)
else {
;
}
/*
* Fill in info from the ioctl.
*/
for (i = 0; i < DK_DEVLEN; i++) {
}
/*
* Make sure these can be used as simple strings
*/
search_ctlr->ctlr_cname[i] = 0;
search_ctlr->ctlr_dname[i] = 0;
}
/*
* By this point, we have a known ctlr. Link the disk
* to the ctlr.
*/
if (access_flags & DSK_RESERVED)
else
(void) close(search_file);
return;
} else {
}
/*
* Attempt to read the primary label.
* (Note that this is really through the DKIOCGVTOC
* ioctl, then converted from vtoc to label.)
*/
} else {
}
/*
* If reading the label failed, and this is a SCSI
* disk, we can attempt to auto-sense the disk
* Configuration.
*/
if (option_msg && diag_msg) {
err_print("%s: attempting auto configuration\n",
}
switch (search_disk->label_type) {
case (L_TYPE_SOLARIS):
/*
* Auto config worked, so we now have
* a valid label for the disk. Mark
* the disk as needing the label flushed.
*/
status = 0;
}
break;
case (L_TYPE_EFI):
/*
* Auto config worked, so we now have
* a valid label for the disk.
*/
status = 0;
}
break;
default:
/* Should never happen */
break;
}
}
/*
* Close the file for this disk.
*/
(void) close(search_file);
/*
* If we didn't successfully read the label, or the label
* appears corrupt, just leave the disk as an unknown type.
*/
if (status == -1) {
return;
}
if (!checklabel(&search_label)) {
return;
}
return;
}
}
/*
* The label looks ok. Mark the disk as labeled.
*/
search_dtype = (struct disk_type *)
} else {
}
}
search_parts = (struct partition_info *)
zalloc(sizeof (struct partition_info));
/*
* Copy the volume name, if present
*/
V_RESERVED) {
} else {
}
break;
}
}
return;
}
/*
* Attempt to match the disk type in the label with a
* known disk type.
*/
search_dtype != NULL;
break;
/*
* If no match was found, we need to create a disk type
* for this disk.
*/
if (search_dtype == NULL) {
/*
* Allocate space for the disk type and add it
* to the list of disk types for this ctlr type.
*/
search_dtype = (struct disk_type *)
else {
}
/*
* Fill in the drive info from the disk label.
*/
search_dtype->dtype_asciilabel = (char *)
/*
* Mark the disk as needing specification of
* ctlr specific attributes. This is necessary
* because the label doesn't contain these attributes,
* and they aren't known at this point. They will
* be asked for if this disk is ever selected by
* the user.
* Note: for SCSI, we believe the label.
*/
}
}
/*
* By this time we have a known disk type. Link the disk
* to the disk type.
*/
/*
* Attempt to match the partition map in the label with
* a known partition map for this disk type.
*/
search_parts != NULL;
break;
}
/*
* If no match was made, we need to create a partition
* map for this disk.
*/
if (search_parts == NULL) {
/*
* Allocate space for the partition map and add
* it to the list of maps for this disk type.
*/
search_parts = (struct partition_info *)
zalloc(sizeof (struct partition_info));
else {
}
/*
* Fill in the name of the map with a name derived
* from the name of this disk. This is necessary
* because the label contains no name for the
* partition map.
*/
/*
* Fill in the partition info from the disk label.
*/
for (i = 0; i < NDKMAP; i++) {
#if defined(_SUNOS_VTOC_8)
search_parts->pinfo_map[i] =
search_label.dkl_map[i];
#elif defined(_SUNOS_VTOC_16)
#else
#endif
}
}
/*
* If the vtoc looks valid, copy the volume name and vtoc
* info from the label. Otherwise, install a default vtoc.
* This permits vtoc info to automatically appear in the sun
* label, without requiring an upgrade procedure.
*/
} else {
}
/*
* By this time we have a known partitition map. Link the
* disk to the partition map.
*/
}
/*
* Search the disk list for a disk with the identical configuration.
* Return true if one is found.
*/
static int
{
return (1);
}
}
return (0);
}
/*
* This routine checks to see if a given disk type matches the type
* in the disk label.
*/
int
{
return (0);
}
/*
* If the any of the physical characteristics are different, or
* the name is different, it doesn't match.
*/
return (0);
}
/*
* If those are all identical, assume it's a match.
*/
return (1);
}
/*
* This routine checks to see if a given partition map matches the map
* in the disk label.
*/
int
register struct partition_info *pinfo;
{
int i;
/*
* If any of the partition entries is different, it doesn't match.
*/
for (i = 0; i < NDKMAP; i++)
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
#else
#endif
return (0);
/*
* Compare the vtoc information for a match
* Do not require the volume name to be equal, for a match!
*/
return (0);
return (0);
for (i = 0; i < NDKMAP; i++) {
return (0);
return (0);
}
/*
* If they are all identical, it's a match.
*/
return (1);
}
/*
* This routine checks to see if the given disk name refers to the disk
* in the given disk structure.
*/
int
{
char s[MAXPATHLEN];
int fd;
/*
* Match the name of the disk in the disk_info structure
*/
return (1);
}
/*
* Check to see if it's a 4.x file name in the /dev
* directory on 5.0. Here, we only accept the
* canonicalized form: sd0.
*/
if (canonical4x_name(name) == 0) {
return (0);
}
(void) strcpy(s, "/dev/r");
(void) strcat(s, "c");
return (0);
}
return (0);
}
return (1);
}
return (0);
}
static void
{
int token_type;
/*
* Allow us to get by controllers that the other platforms don't
* know about.
*/
}
/*
* Re-sync the parsing at the beginning of the next line
* unless of course we're already there.
*/
do {
if (token_type == SUP_EOF) {
}
}
}
/*
* Search through all defined disk types for duplicate entries
* that are inconsistent with each other. Disks with different
* characteristics should be named differently.
* Note that this function only checks for duplicate disks
* for the same controller. It's possible to have two disks with
* the same name, but defined for different controllers.
* That may or may not be a problem...
*/
static void
{
struct mctlr_list *mlp;
}
}
}
}
/*
* Search through all defined partition types for duplicate entries
* that are inconsistent with each other. Partitions with different
* characteristics should be named differently.
* Note that this function only checks for duplicate partitions
* for the same disk. It's possible to have two partitions with
* the same name, but defined for different disks.
* That may or may not be a problem...
*/
static void
{
struct partition_info *pp1;
struct partition_info *pp2;
struct mctlr_list *mlp;
}
}
}
}
}
/*
* Determine if two particular disk definitions are inconsistent.
* Ie: same name, but different characteristics.
* If so, print an error message and abort.
*/
static void
{
int i;
int result;
/*
* If the name's different, we're ok
*/
return;
}
/*
* Compare all the disks' characteristics
*/
result = 0;
for (i = 0; i < NSPECIFICS; i++) {
}
result = 1;
break;
}
}
if (result) {
err_print("Inconsistent definitions for disk type '%s'\n",
err_print("%s (%d) - %s (%d)\n",
}
fullabort();
}
}
/*
* Determine if two particular partition definitions are inconsistent.
* Ie: same name, but different characteristics.
* If so, print an error message and abort.
*/
static void
struct partition_info *pp1;
struct partition_info *pp2;
{
int i;
int result;
#if defined(_SUNOS_VTOC_8)
#elif defined(_SUNOS_VTOC_16)
struct dkl_partition *vp1;
struct dkl_partition *vp2;
#else
#endif /* defined(_SUNOS_VTOC_8) */
/*
* If the name's different, we're ok
*/
return;
}
/*
* Compare all the partitions' characteristics
*/
result = 0;
}
/*
* Compare the significant portions of the vtoc information
*/
}
if (result) {
err_print("Inconsistent definitions for partition type '%s'\n",
pp1->pinfo_name);
err_print("%s (%d) - %s (%d)\n",
}
fullabort();
}
}
/*
* Convert a string of digits into a block number.
* The digits are assumed to be a block number unless the
* the string is terminated by 'c', in which case it is
* assumed to be in units of cylinders. Accept a 'b'
* to explictly specify blocks, for consistency.
*
* NB: uses the macro spc(), which requires that the
*
* Returns -1 in the case of an error.
*/
static uint_t
{
int blks;
char *p;
/*
* Check what terminated the conversion.
*/
if (*p != 0) {
/*
* Units specifier of 'c': convert cylinders to blocks
*/
if (*p == 'c') {
p++;
/*
* Ignore a 'b' specifier.
*/
} else if (*p == 'b') {
p++;
}
/*
* Anthing left over is an error
*/
if (*p != 0) {
blks = -1;
}
}
return (blks);
}
/*
* Convert a string of digits into a cylinder number.
* Accept a an optional 'c' specifier, for consistency.
*
* Returns -1 in the case of an error.
*/
int
{
int cyls;
char *p;
/*
* Check what terminated the conversion.
*/
if (*p != 0) {
/*
* Units specifier of 'c': accept it.
*/
if (*p == 'c') {
p++;
}
/*
* Anthing left over is an error
*/
if (*p != 0) {
cyls = -1;
}
}
return (cyls);
}
/*
* Create a new chg_list structure, and append it onto the
* end of the current chg_list under construction. By
* applying changes in the order in which listed in the
* data file, the changes we make are deterministic.
* Return a pointer to the new structure, so that the
* caller can fill in the appropriate information.
*/
static struct chg_list *
{
} else {
;
}
return (nc);
}
/*
* Follow symbolic links from the logical device name to
* the /devfs physical device name. To be complete, we
* handle the case of multiple links. This function
* either returns NULL (no links, or some other error),
* or the physical device name, alloc'ed on the heap.
*
* Note that the standard /devices prefix is stripped from
* the final pathname, if present. The trailing options
* are also removed (":c, raw").
*/
static char *
get_physical_name(char *path)
{
int i;
int level;
char *p;
char s[MAXPATHLEN];
char buf[MAXPATHLEN];
char dir[MAXPATHLEN];
char savedir[MAXPATHLEN];
return (NULL);
}
*p = 0;
}
if (s[0] == 0) {
(void) strcpy(s, "/");
}
if (chdir(s) == -1) {
err_print("cannot chdir() to %s - %s\n",
goto exit;
}
level = 0;
for (;;) {
/*
* See if there's a real file out there. If not,
* we have a dangling link and we ignore it.
*/
goto exit;
}
err_print("%s: lstat() failed - %s\n",
goto exit;
}
/*
* If the file is not a link, we're done one
* way or the other. If there were links,
* return the full pathname of the resulting
* file.
*/
if (level > 0) {
/*
* Strip trailing options from the
* physical device name
*/
*p = 0;
}
/*
* Get the current directory, and
* glue the pieces together.
*/
err_print("getcwd() failed - %s\n",
goto exit;
}
/*
* If we have the standard fixed
* /devices prefix, remove it.
*/
result = alloc_string(p);
}
goto exit;
}
if (i == -1) {
err_print("%s: readlink() failed - %s\n",
goto exit;
}
level++;
buf[i] = 0;
/*
* Break up the pathname into the directory
* reference, if applicable and simple filename.
* chdir()'ing to the directory allows us to
* handle links with relative pathnames correctly.
*/
*p = 0;
err_print("cannot chdir() to %s - %s\n",
goto exit;
}
(void) strcpy(s, p+1);
} else {
}
}
exit:
err_print("cannot chdir() to %s - %s\n",
}
return (result);
}
static void
{
int n;
struct disk_info *d;
/*
* Count the number of disks in the list
*/
n = 0;
n++;
}
if (n == 0) {
return;
}
/*
* Allocate a simple disk list array and fill it in
*/
*dp++ = d;
}
/*
* Sort the disk list array
*/
/*
* Rebuild the linked list disk list structure
*/
do {
/*
* Clean up
*/
(void) destroy_data((void *)disks);
}
/*
* Compare two disk names
*/
static int
const void *arg1,
const void *arg2)
{
char *s1;
char *s2;
int n1;
int n2;
char *p1;
char *p2;
for (;;) {
break;
}
break;
} else {
s1++;
s2++;
}
}
}
static void
{
int x;
struct mctlr_list *ctlrp;
for (x = nctypes; x != 0; x--) {
}
}
static void
char *arglist[];
{
char **disklist;
int len;
char s[MAXPATHLEN], t[MAXPATHLEN];
int diskno = 0;
int i;
/* Disk is in conventional format */
canonicalize_name(s, *disklist);
/*
* check if the disk is already present in
* disk list.
*/
for (i = 0; i < diskno; i++) {
canonicalize_name(t, arglist[i]);
break;
}
if (i != diskno)
continue;
}
diskno++;
}
}
#define DISK_PREFIX "/dev/rdsk/"
/*
* This Function checks if the non-conventional name is a a link to
* one of the conventional whole disk name.
*/
static int
char *name;
{
char symname[MAXPATHLEN];
char localname[MAXPATHLEN];
char *nameptr;
if (conventional_name(nameptr)) {
if (whole_disk_name(nameptr))
return (0);
else
return (1);
}
}
return (0);
}