10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51524Slh195018 * Common Development and Distribution License (the "License").
61524Slh195018 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12610SShengliang.Zhang@Sun.COM * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * This file contains the code to perform program startup. This
270Sstevel@tonic-gate * includes reading the data file and the search for disks.
280Sstevel@tonic-gate */
290Sstevel@tonic-gate #include "global.h"
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include <ctype.h>
320Sstevel@tonic-gate #include <stdlib.h>
330Sstevel@tonic-gate #include <unistd.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate #include <strings.h>
360Sstevel@tonic-gate #include <fcntl.h>
370Sstevel@tonic-gate #include <errno.h>
380Sstevel@tonic-gate #include <memory.h>
390Sstevel@tonic-gate #include <dirent.h>
400Sstevel@tonic-gate #include <sys/fcntl.h>
410Sstevel@tonic-gate #include <sys/param.h>
420Sstevel@tonic-gate #include <sys/stat.h>
430Sstevel@tonic-gate
440Sstevel@tonic-gate #include "startup.h"
450Sstevel@tonic-gate #include "param.h"
460Sstevel@tonic-gate #include "label.h"
470Sstevel@tonic-gate #include "misc.h"
480Sstevel@tonic-gate #include "menu_command.h"
490Sstevel@tonic-gate #include "partition.h"
500Sstevel@tonic-gate #include "ctlr_scsi.h"
510Sstevel@tonic-gate
520Sstevel@tonic-gate #include "auto_sense.h"
530Sstevel@tonic-gate
540Sstevel@tonic-gate extern struct ctlr_type ctlr_types[];
550Sstevel@tonic-gate extern int nctypes;
560Sstevel@tonic-gate extern struct ctlr_ops genericops;
570Sstevel@tonic-gate extern long strtol();
580Sstevel@tonic-gate
590Sstevel@tonic-gate extern int errno;
600Sstevel@tonic-gate
610Sstevel@tonic-gate #ifdef __STDC__
620Sstevel@tonic-gate
630Sstevel@tonic-gate /* Function prototypes for ANSI C Compilers */
640Sstevel@tonic-gate static void usage(void);
650Sstevel@tonic-gate static int sup_prxfile(void);
660Sstevel@tonic-gate static void sup_setpath(void);
670Sstevel@tonic-gate static void sup_setdtype(void);
680Sstevel@tonic-gate static int sup_change_spec(struct disk_type *, char *);
690Sstevel@tonic-gate static void sup_setpart(void);
700Sstevel@tonic-gate static void search_for_logical_dev(char *devname);
710Sstevel@tonic-gate static void add_device_to_disklist(char *devname, char *devpath);
720Sstevel@tonic-gate static int disk_is_known(struct dk_cinfo *dkinfo);
730Sstevel@tonic-gate static void datafile_error(char *errmsg, char *token);
740Sstevel@tonic-gate static void search_duplicate_dtypes(void);
750Sstevel@tonic-gate static void search_duplicate_pinfo(void);
760Sstevel@tonic-gate static void check_dtypes_for_inconsistency(struct disk_type *dp1,
770Sstevel@tonic-gate struct disk_type *dp2);
780Sstevel@tonic-gate static void check_pinfo_for_inconsistency(struct partition_info *pp1,
790Sstevel@tonic-gate struct partition_info *pp2);
807563SPrasad.Singamsetty@Sun.COM static uint_t str2blks(char *str);
810Sstevel@tonic-gate static int str2cyls(char *str);
820Sstevel@tonic-gate static struct chg_list *new_chg_list(struct disk_type *);
830Sstevel@tonic-gate static char *get_physical_name(char *);
840Sstevel@tonic-gate static void sort_disk_list(void);
850Sstevel@tonic-gate static int disk_name_compare(const void *, const void *);
860Sstevel@tonic-gate static void make_controller_list(void);
870Sstevel@tonic-gate static void check_for_duplicate_disknames(char *arglist[]);
880Sstevel@tonic-gate
890Sstevel@tonic-gate #else /* __STDC__ */
900Sstevel@tonic-gate
910Sstevel@tonic-gate /* Function prototypes for non-ANSI C Compilers */
920Sstevel@tonic-gate static void usage();
930Sstevel@tonic-gate static int sup_prxfile();
940Sstevel@tonic-gate static void sup_setpath();
950Sstevel@tonic-gate static void sup_setdtype();
960Sstevel@tonic-gate static int sup_change_spec();
970Sstevel@tonic-gate static void sup_setpart();
980Sstevel@tonic-gate static void search_for_logical_dev();
990Sstevel@tonic-gate static void add_device_to_disklist();
1000Sstevel@tonic-gate static int disk_is_known();
1010Sstevel@tonic-gate static void datafile_error();
1020Sstevel@tonic-gate static void search_duplicate_dtypes();
1030Sstevel@tonic-gate static void search_duplicate_pinfo();
1040Sstevel@tonic-gate static void check_dtypes_for_inconsistency();
1050Sstevel@tonic-gate static void check_pinfo_for_inconsistency();
1067563SPrasad.Singamsetty@Sun.COM static uint_t str2blks();
1070Sstevel@tonic-gate static int str2cyls();
1080Sstevel@tonic-gate static struct chg_list *new_chg_list();
1090Sstevel@tonic-gate static char *get_physical_name();
1100Sstevel@tonic-gate static void sort_disk_list();
1110Sstevel@tonic-gate static int disk_name_compare();
1120Sstevel@tonic-gate static void make_controller_list();
1130Sstevel@tonic-gate static void check_for_duplicate_disknames();
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate #endif /* __STDC__ */
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate #if defined(sparc)
1180Sstevel@tonic-gate static char *other_ctlrs[] = {
1190Sstevel@tonic-gate "ata"
1200Sstevel@tonic-gate };
1210Sstevel@tonic-gate #define OTHER_CTLRS 1
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate #elif defined(i386)
1240Sstevel@tonic-gate static char *other_ctlrs[] = {
1250Sstevel@tonic-gate "ISP-80"
1260Sstevel@tonic-gate };
1270Sstevel@tonic-gate #define OTHER_CTLRS 2
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate #else
1300Sstevel@tonic-gate #error No Platform defined.
1310Sstevel@tonic-gate #endif
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate * This global is used to store the current line # in the data file.
1360Sstevel@tonic-gate * It must be global because the I/O routines are allowed to side
1370Sstevel@tonic-gate * effect it to keep track of backslashed newlines.
1380Sstevel@tonic-gate */
1390Sstevel@tonic-gate int data_lineno; /* current line # in data file */
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate * Search path as defined in the format.dat files
1430Sstevel@tonic-gate */
1440Sstevel@tonic-gate static char **search_path = NULL;
1450Sstevel@tonic-gate
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate static int name_represents_wholedisk(char *name);
1480Sstevel@tonic-gate
149*12610SShengliang.Zhang@Sun.COM static void get_disk_name(int fd, char *disk_name);
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate * This routine digests the options on the command line. It returns
1530Sstevel@tonic-gate * the index into argv of the first string that is not an option. If
1540Sstevel@tonic-gate * there are none, it returns -1.
1550Sstevel@tonic-gate */
1560Sstevel@tonic-gate int
do_options(int argc,char * argv[])1570Sstevel@tonic-gate do_options(int argc, char *argv[])
1580Sstevel@tonic-gate {
1590Sstevel@tonic-gate char *ptr;
1600Sstevel@tonic-gate int i;
1610Sstevel@tonic-gate int next;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate /*
1640Sstevel@tonic-gate * Default is no extended messages. Can be enabled manually.
1650Sstevel@tonic-gate */
1660Sstevel@tonic-gate option_msg = 0;
1670Sstevel@tonic-gate diag_msg = 0;
1680Sstevel@tonic-gate expert_mode = 0;
1690Sstevel@tonic-gate need_newline = 0;
1700Sstevel@tonic-gate dev_expert = 0;
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate * Loop through the argument list, incrementing each time by
1740Sstevel@tonic-gate * an amount determined by the options found.
1750Sstevel@tonic-gate */
1760Sstevel@tonic-gate for (i = 1; i < argc; i = next) {
1770Sstevel@tonic-gate /*
1780Sstevel@tonic-gate * Start out assuming an increment of 1.
1790Sstevel@tonic-gate */
1800Sstevel@tonic-gate next = i + 1;
1810Sstevel@tonic-gate /*
1820Sstevel@tonic-gate * As soon as we hit a non-option, we're done.
1830Sstevel@tonic-gate */
1840Sstevel@tonic-gate if (*argv[i] != '-')
1850Sstevel@tonic-gate return (i);
1860Sstevel@tonic-gate /*
1870Sstevel@tonic-gate * Loop through all the characters in this option string.
1880Sstevel@tonic-gate */
1890Sstevel@tonic-gate for (ptr = argv[i] + 1; *ptr != '\0'; ptr++) {
1900Sstevel@tonic-gate /*
1910Sstevel@tonic-gate * Determine each option represented. For options
1920Sstevel@tonic-gate * that use a second string, increase the increment
1930Sstevel@tonic-gate * of the main loop so they aren't re-interpreted.
1940Sstevel@tonic-gate */
1950Sstevel@tonic-gate switch (*ptr) {
1965084Sjohnlev case 's':
1975084Sjohnlev case 'S':
1980Sstevel@tonic-gate option_s = 1;
1990Sstevel@tonic-gate break;
2005084Sjohnlev case 'f':
2015084Sjohnlev case 'F':
2020Sstevel@tonic-gate option_f = argv[next++];
2030Sstevel@tonic-gate if (next > argc)
2040Sstevel@tonic-gate goto badopt;
2050Sstevel@tonic-gate break;
2065084Sjohnlev case 'l':
2075084Sjohnlev case 'L':
2080Sstevel@tonic-gate option_l = argv[next++];
2090Sstevel@tonic-gate if (next > argc)
2100Sstevel@tonic-gate goto badopt;
2110Sstevel@tonic-gate break;
2125084Sjohnlev case 'x':
2135084Sjohnlev case 'X':
2140Sstevel@tonic-gate option_x = argv[next++];
2150Sstevel@tonic-gate if (next > argc)
2160Sstevel@tonic-gate goto badopt;
2170Sstevel@tonic-gate break;
2185084Sjohnlev case 'd':
2195084Sjohnlev case 'D':
2200Sstevel@tonic-gate option_d = argv[next++];
2210Sstevel@tonic-gate if (next > argc)
2220Sstevel@tonic-gate goto badopt;
2230Sstevel@tonic-gate break;
2245084Sjohnlev case 't':
2255084Sjohnlev case 'T':
2260Sstevel@tonic-gate option_t = argv[next++];
2270Sstevel@tonic-gate if (next > argc)
2280Sstevel@tonic-gate goto badopt;
2290Sstevel@tonic-gate break;
2305084Sjohnlev case 'p':
2315084Sjohnlev case 'P':
2320Sstevel@tonic-gate option_p = argv[next++];
2330Sstevel@tonic-gate if (next > argc)
2340Sstevel@tonic-gate goto badopt;
2350Sstevel@tonic-gate break;
2365084Sjohnlev case 'm':
2370Sstevel@tonic-gate option_msg = 1;
2380Sstevel@tonic-gate break;
2395084Sjohnlev case 'M':
2400Sstevel@tonic-gate option_msg = 1;
2410Sstevel@tonic-gate diag_msg = 1;
2420Sstevel@tonic-gate break;
2435084Sjohnlev case 'e':
2440Sstevel@tonic-gate expert_mode = 1;
2450Sstevel@tonic-gate break;
2460Sstevel@tonic-gate #ifdef DEBUG
2475084Sjohnlev case 'z':
2480Sstevel@tonic-gate dev_expert = 1;
2490Sstevel@tonic-gate break;
2500Sstevel@tonic-gate #endif
2515084Sjohnlev default:
2520Sstevel@tonic-gate badopt:
2530Sstevel@tonic-gate usage();
2540Sstevel@tonic-gate break;
2550Sstevel@tonic-gate }
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate /*
2590Sstevel@tonic-gate * All the command line strings were options. Return that fact.
2600Sstevel@tonic-gate */
2610Sstevel@tonic-gate return (-1);
2620Sstevel@tonic-gate }
2630Sstevel@tonic-gate
2640Sstevel@tonic-gate
2650Sstevel@tonic-gate static void
usage()2660Sstevel@tonic-gate usage()
2670Sstevel@tonic-gate {
2680Sstevel@tonic-gate err_print("Usage: format [-s][-d disk_name]");
2690Sstevel@tonic-gate err_print("[-t disk_type][-p partition_name]\n");
2700Sstevel@tonic-gate err_print("\t[-f cmd_file][-l log_file]");
2710Sstevel@tonic-gate err_print("[-x data_file] [-m] [-M] [-e] disk_list\n");
2720Sstevel@tonic-gate fullabort();
2730Sstevel@tonic-gate }
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate /*
2770Sstevel@tonic-gate * This routine reads in and digests the data file. The data file contains
2780Sstevel@tonic-gate * definitions for the search path, known disk types, and known partition
2790Sstevel@tonic-gate * maps.
2800Sstevel@tonic-gate *
2810Sstevel@tonic-gate * Note: for each file being processed, file_name is a pointer to that
2820Sstevel@tonic-gate * file's name. We are careful to make sure that file_name points to
2830Sstevel@tonic-gate * globally-accessible data, not data on the stack, because each
2840Sstevel@tonic-gate * disk/partition/controller definition now keeps a pointer to the
2850Sstevel@tonic-gate * filename in which it was defined. In the case of duplicate,
2860Sstevel@tonic-gate * conflicting definitions, we can thus tell the user exactly where
2870Sstevel@tonic-gate * the problem is occurring.
2880Sstevel@tonic-gate */
2890Sstevel@tonic-gate void
sup_init()2900Sstevel@tonic-gate sup_init()
2910Sstevel@tonic-gate {
2920Sstevel@tonic-gate int nopened_files = 0;
2930Sstevel@tonic-gate char fname[MAXPATHLEN];
2940Sstevel@tonic-gate char *path;
2950Sstevel@tonic-gate char *p;
2960Sstevel@tonic-gate struct stat stbuf;
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate /*
3000Sstevel@tonic-gate * Create a singly-linked list of controller types so that we may
3010Sstevel@tonic-gate * dynamically add unknown controllers to this for 3'rd
3020Sstevel@tonic-gate * party disk support.
3030Sstevel@tonic-gate */
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate make_controller_list();
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate /*
3080Sstevel@tonic-gate * If a data file was specified on the command line, use it first
3090Sstevel@tonic-gate * If the file cannot be opened, fail. We want to guarantee
3100Sstevel@tonic-gate * that, if the user explicitly names a file, they can
3110Sstevel@tonic-gate * access it.
3120Sstevel@tonic-gate *
3130Sstevel@tonic-gate * option_x is already global, no need to dup it on the heap.
3140Sstevel@tonic-gate */
3150Sstevel@tonic-gate if (option_x) {
3160Sstevel@tonic-gate file_name = option_x;
3170Sstevel@tonic-gate if (sup_prxfile()) {
3180Sstevel@tonic-gate nopened_files++;
3190Sstevel@tonic-gate } else {
3200Sstevel@tonic-gate err_print("Unable to open data file '%s' - %s.\n",
3215084Sjohnlev file_name, strerror(errno));
3220Sstevel@tonic-gate fullabort();
3230Sstevel@tonic-gate }
3240Sstevel@tonic-gate }
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate /*
3270Sstevel@tonic-gate * Now look for an environment variable FORMAT_PATH.
3280Sstevel@tonic-gate * If found, we use it as a colon-separated list
3290Sstevel@tonic-gate * of directories. If no such environment variable
3300Sstevel@tonic-gate * is defined, use a default path of "/etc".
3310Sstevel@tonic-gate */
3320Sstevel@tonic-gate path = getenv("FORMAT_PATH");
3330Sstevel@tonic-gate if (path == NULL) {
3340Sstevel@tonic-gate path = "/etc";
3350Sstevel@tonic-gate }
3360Sstevel@tonic-gate /*
3370Sstevel@tonic-gate * Traverse the path one file at a time. Pick off
3380Sstevel@tonic-gate * the file name, and append the name "format.dat"
3390Sstevel@tonic-gate * at the end of the pathname.
3400Sstevel@tonic-gate * Whatever string we construct, duplicate it on the
3410Sstevel@tonic-gate * heap, so that file_name is globally accessible.
3420Sstevel@tonic-gate */
3430Sstevel@tonic-gate while (*path != 0) {
3440Sstevel@tonic-gate p = fname;
3450Sstevel@tonic-gate while (*path != 0 && *path != ':')
3460Sstevel@tonic-gate *p++ = *path++;
3470Sstevel@tonic-gate if (p == fname)
3480Sstevel@tonic-gate continue;
3490Sstevel@tonic-gate *p = 0;
3500Sstevel@tonic-gate if (*path == ':')
3510Sstevel@tonic-gate path++;
3520Sstevel@tonic-gate /*
3530Sstevel@tonic-gate * If the path we have so far is a directory,
3540Sstevel@tonic-gate * look for a format.dat file in that directory,
3550Sstevel@tonic-gate * otherwise try using the path name specified.
3560Sstevel@tonic-gate * This permits arbitrary file names in the
3570Sstevel@tonic-gate * path specification, if this proves useful.
3580Sstevel@tonic-gate */
3590Sstevel@tonic-gate if (stat(fname, &stbuf) == -1) {
3600Sstevel@tonic-gate err_print("Unable to access '%s' - %s.\n",
3615084Sjohnlev fname, strerror(errno));
3620Sstevel@tonic-gate } else {
3630Sstevel@tonic-gate if (S_ISDIR(stbuf.st_mode)) {
3640Sstevel@tonic-gate if (*(p-1) != '/')
3650Sstevel@tonic-gate *p++ = '/';
3660Sstevel@tonic-gate (void) strcpy(p, "format.dat");
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate file_name = alloc_string(fname);
3690Sstevel@tonic-gate if (sup_prxfile()) {
3700Sstevel@tonic-gate nopened_files++;
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate /*
3760Sstevel@tonic-gate * Check for duplicate disk or partitions definitions
3770Sstevel@tonic-gate * that are inconsistent - this would be very confusing.
3780Sstevel@tonic-gate */
3790Sstevel@tonic-gate search_duplicate_dtypes();
3800Sstevel@tonic-gate search_duplicate_pinfo();
3810Sstevel@tonic-gate }
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate /*
3850Sstevel@tonic-gate * Open and process a format data file. Unfortunately, we use
3860Sstevel@tonic-gate * globals: file_name for the file name, and data_file
3870Sstevel@tonic-gate * for the descriptor. Return true if able to open the file.
3880Sstevel@tonic-gate */
3890Sstevel@tonic-gate static int
sup_prxfile()3900Sstevel@tonic-gate sup_prxfile()
3910Sstevel@tonic-gate {
3920Sstevel@tonic-gate int status;
3930Sstevel@tonic-gate TOKEN token;
3940Sstevel@tonic-gate TOKEN cleaned;
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate /*
3970Sstevel@tonic-gate * Open the data file. Return 0 if unable to do so.
3980Sstevel@tonic-gate */
3990Sstevel@tonic-gate data_file = fopen(file_name, "r");
4000Sstevel@tonic-gate if (data_file == NULL) {
4010Sstevel@tonic-gate return (0);
4020Sstevel@tonic-gate }
4030Sstevel@tonic-gate /*
4040Sstevel@tonic-gate * Step through the data file a meta-line at a time. There are
4050Sstevel@tonic-gate * typically several backslashed newlines in each meta-line,
4060Sstevel@tonic-gate * so data_lineno will be getting side effected along the way.
4070Sstevel@tonic-gate */
4080Sstevel@tonic-gate data_lineno = 0;
4090Sstevel@tonic-gate for (;;) {
4100Sstevel@tonic-gate data_lineno++;
4110Sstevel@tonic-gate /*
4120Sstevel@tonic-gate * Get the keyword.
4130Sstevel@tonic-gate */
4140Sstevel@tonic-gate status = sup_gettoken(token);
4150Sstevel@tonic-gate /*
4160Sstevel@tonic-gate * If we hit the end of the data file, we're done.
4170Sstevel@tonic-gate */
4180Sstevel@tonic-gate if (status == SUP_EOF)
4190Sstevel@tonic-gate break;
4200Sstevel@tonic-gate /*
4210Sstevel@tonic-gate * If the line is blank, skip it.
4220Sstevel@tonic-gate */
4230Sstevel@tonic-gate if (status == SUP_EOL)
4240Sstevel@tonic-gate continue;
4250Sstevel@tonic-gate /*
4260Sstevel@tonic-gate * If the line starts with some key character, it's an error.
4270Sstevel@tonic-gate */
4280Sstevel@tonic-gate if (status != SUP_STRING) {
4290Sstevel@tonic-gate datafile_error("Expecting keyword, found '%s'", token);
4300Sstevel@tonic-gate continue;
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate /*
4330Sstevel@tonic-gate * Clean up the token and see which keyword it is. Call
4340Sstevel@tonic-gate * the appropriate routine to process the rest of the line.
4350Sstevel@tonic-gate */
4360Sstevel@tonic-gate clean_token(cleaned, token);
4370Sstevel@tonic-gate if (strcmp(cleaned, "search_path") == 0)
4380Sstevel@tonic-gate sup_setpath();
4390Sstevel@tonic-gate else if (strcmp(cleaned, "disk_type") == 0)
4400Sstevel@tonic-gate sup_setdtype();
4410Sstevel@tonic-gate else if (strcmp(cleaned, "partition") == 0)
4420Sstevel@tonic-gate sup_setpart();
4430Sstevel@tonic-gate else {
4440Sstevel@tonic-gate datafile_error("Unknown keyword '%s'", cleaned);
4450Sstevel@tonic-gate }
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate /*
4480Sstevel@tonic-gate * Close the data file.
4490Sstevel@tonic-gate */
4500Sstevel@tonic-gate (void) fclose(data_file);
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate return (1);
4530Sstevel@tonic-gate }
4540Sstevel@tonic-gate
4550Sstevel@tonic-gate /*
4560Sstevel@tonic-gate * This routine processes a 'search_path' line in the data file. The
4570Sstevel@tonic-gate * search path is a list of disk names that will be searched for by the
4580Sstevel@tonic-gate * program.
4590Sstevel@tonic-gate *
4600Sstevel@tonic-gate * The static path_size and path_alloc are used to build up the
4610Sstevel@tonic-gate * list of files comprising the search path. The static definitions
4620Sstevel@tonic-gate * enable supporting multiple search path definitions.
4630Sstevel@tonic-gate */
4640Sstevel@tonic-gate static void
sup_setpath()4650Sstevel@tonic-gate sup_setpath()
4660Sstevel@tonic-gate {
4670Sstevel@tonic-gate TOKEN token;
4680Sstevel@tonic-gate TOKEN cleaned;
4690Sstevel@tonic-gate int status;
4700Sstevel@tonic-gate static int path_size;
4710Sstevel@tonic-gate static int path_alloc;
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate /*
4740Sstevel@tonic-gate * Pull in some grammar.
4750Sstevel@tonic-gate */
4760Sstevel@tonic-gate status = sup_gettoken(token);
4770Sstevel@tonic-gate if (status != SUP_EQL) {
4780Sstevel@tonic-gate datafile_error("Expecting '=', found '%s'", token);
4790Sstevel@tonic-gate return;
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate /*
4820Sstevel@tonic-gate * Loop through the entries.
4830Sstevel@tonic-gate */
4840Sstevel@tonic-gate for (;;) {
4850Sstevel@tonic-gate /*
4860Sstevel@tonic-gate * Pull in the disk name.
4870Sstevel@tonic-gate */
4880Sstevel@tonic-gate status = sup_gettoken(token);
4890Sstevel@tonic-gate /*
4900Sstevel@tonic-gate * If we hit end of line, we're done.
4910Sstevel@tonic-gate */
4920Sstevel@tonic-gate if (status == SUP_EOL)
4930Sstevel@tonic-gate break;
4940Sstevel@tonic-gate /*
4950Sstevel@tonic-gate * If we hit some key character, it's an error.
4960Sstevel@tonic-gate */
4970Sstevel@tonic-gate if (status != SUP_STRING) {
4980Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
4990Sstevel@tonic-gate break;
5000Sstevel@tonic-gate }
5010Sstevel@tonic-gate clean_token(cleaned, token);
5020Sstevel@tonic-gate /*
5030Sstevel@tonic-gate * Build the string into an argvlist. This array
5040Sstevel@tonic-gate * is dynamically sized, as necessary, and terminated
5050Sstevel@tonic-gate * with a null. Each name is alloc'ed on the heap,
5060Sstevel@tonic-gate * so no dangling references.
5070Sstevel@tonic-gate */
5080Sstevel@tonic-gate search_path = build_argvlist(search_path, &path_size,
5095084Sjohnlev &path_alloc, cleaned);
5100Sstevel@tonic-gate /*
5110Sstevel@tonic-gate * Pull in some grammar.
5120Sstevel@tonic-gate */
5130Sstevel@tonic-gate status = sup_gettoken(token);
5140Sstevel@tonic-gate if (status == SUP_EOL)
5150Sstevel@tonic-gate break;
5160Sstevel@tonic-gate if (status != SUP_COMMA) {
5170Sstevel@tonic-gate datafile_error("Expecting ', ', found '%s'", token);
5180Sstevel@tonic-gate break;
5190Sstevel@tonic-gate }
5200Sstevel@tonic-gate }
5210Sstevel@tonic-gate }
5220Sstevel@tonic-gate
5230Sstevel@tonic-gate /*
5240Sstevel@tonic-gate * This routine processes a 'disk_type' line in the data file. It defines
5250Sstevel@tonic-gate * the physical attributes of a brand of disk when connected to a specific
5260Sstevel@tonic-gate * controller type.
5270Sstevel@tonic-gate */
5280Sstevel@tonic-gate static void
sup_setdtype()5290Sstevel@tonic-gate sup_setdtype()
5300Sstevel@tonic-gate {
5310Sstevel@tonic-gate TOKEN token, cleaned, ident;
5320Sstevel@tonic-gate int val, status, i;
5330Sstevel@tonic-gate ulong_t flags = 0;
5340Sstevel@tonic-gate struct disk_type *dtype, *type;
5350Sstevel@tonic-gate struct ctlr_type *ctype;
5360Sstevel@tonic-gate char *dtype_name, *ptr;
5370Sstevel@tonic-gate struct mctlr_list *mlp;
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate * Pull in some grammar.
5410Sstevel@tonic-gate */
5420Sstevel@tonic-gate status = sup_gettoken(token);
5430Sstevel@tonic-gate if (status != SUP_EQL) {
5440Sstevel@tonic-gate datafile_error("Expecting '=', found '%s'", token);
5450Sstevel@tonic-gate return;
5460Sstevel@tonic-gate }
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate * Pull in the name of the disk type.
5490Sstevel@tonic-gate */
5500Sstevel@tonic-gate status = sup_gettoken(token);
5510Sstevel@tonic-gate if (status != SUP_STRING) {
5520Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
5530Sstevel@tonic-gate return;
5540Sstevel@tonic-gate }
5550Sstevel@tonic-gate clean_token(cleaned, token);
5560Sstevel@tonic-gate /*
5570Sstevel@tonic-gate * Allocate space for the disk type and copy in the name.
5580Sstevel@tonic-gate */
5590Sstevel@tonic-gate dtype_name = (char *)zalloc(strlen(cleaned) + 1);
5600Sstevel@tonic-gate (void) strcpy(dtype_name, cleaned);
5610Sstevel@tonic-gate dtype = (struct disk_type *)zalloc(sizeof (struct disk_type));
5620Sstevel@tonic-gate dtype->dtype_asciilabel = dtype_name;
5630Sstevel@tonic-gate /*
5640Sstevel@tonic-gate * Save the filename/linenumber where this disk was defined
5650Sstevel@tonic-gate */
5660Sstevel@tonic-gate dtype->dtype_filename = file_name;
5670Sstevel@tonic-gate dtype->dtype_lineno = data_lineno;
5680Sstevel@tonic-gate /*
5690Sstevel@tonic-gate * Loop for each attribute.
5700Sstevel@tonic-gate */
5710Sstevel@tonic-gate for (;;) {
5720Sstevel@tonic-gate /*
5730Sstevel@tonic-gate * Pull in some grammar.
5740Sstevel@tonic-gate */
5750Sstevel@tonic-gate status = sup_gettoken(token);
5760Sstevel@tonic-gate /*
5770Sstevel@tonic-gate * If we hit end of line, we're done.
5780Sstevel@tonic-gate */
5790Sstevel@tonic-gate if (status == SUP_EOL)
5800Sstevel@tonic-gate break;
5810Sstevel@tonic-gate if (status != SUP_COLON) {
5820Sstevel@tonic-gate datafile_error("Expecting ':', found '%s'", token);
5830Sstevel@tonic-gate return;
5840Sstevel@tonic-gate }
5850Sstevel@tonic-gate /*
5860Sstevel@tonic-gate * Pull in the attribute.
5870Sstevel@tonic-gate */
5880Sstevel@tonic-gate status = sup_gettoken(token);
5890Sstevel@tonic-gate /*
5900Sstevel@tonic-gate * If we hit end of line, we're done.
5910Sstevel@tonic-gate */
5920Sstevel@tonic-gate if (status == SUP_EOL)
5930Sstevel@tonic-gate break;
5940Sstevel@tonic-gate /*
5950Sstevel@tonic-gate * If we hit a key character, it's an error.
5960Sstevel@tonic-gate */
5970Sstevel@tonic-gate if (status != SUP_STRING) {
5980Sstevel@tonic-gate datafile_error("Expecting keyword, found '%s'", token);
5990Sstevel@tonic-gate return;
6000Sstevel@tonic-gate }
6010Sstevel@tonic-gate clean_token(ident, token);
6020Sstevel@tonic-gate /*
6030Sstevel@tonic-gate * Check to see if we've got a change specification
6040Sstevel@tonic-gate * If so, this routine will parse the entire
6050Sstevel@tonic-gate * specification, so just restart at top of loop
6060Sstevel@tonic-gate */
6070Sstevel@tonic-gate if (sup_change_spec(dtype, ident)) {
6080Sstevel@tonic-gate continue;
6090Sstevel@tonic-gate }
6100Sstevel@tonic-gate /*
6110Sstevel@tonic-gate * Pull in more grammar.
6120Sstevel@tonic-gate */
6130Sstevel@tonic-gate status = sup_gettoken(token);
6140Sstevel@tonic-gate if (status != SUP_EQL) {
6150Sstevel@tonic-gate datafile_error("Expecting '=', found '%s'", token);
6160Sstevel@tonic-gate return;
6170Sstevel@tonic-gate }
6180Sstevel@tonic-gate /*
6190Sstevel@tonic-gate * Pull in the value of the attribute.
6200Sstevel@tonic-gate */
6210Sstevel@tonic-gate status = sup_gettoken(token);
6220Sstevel@tonic-gate if (status != SUP_STRING) {
6230Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
6240Sstevel@tonic-gate return;
6250Sstevel@tonic-gate }
6260Sstevel@tonic-gate clean_token(cleaned, token);
6270Sstevel@tonic-gate /*
6280Sstevel@tonic-gate * If the attribute defined the ctlr...
6290Sstevel@tonic-gate */
6300Sstevel@tonic-gate if (strcmp(ident, "ctlr") == 0) {
6310Sstevel@tonic-gate /*
6320Sstevel@tonic-gate * Match the value with a ctlr type.
6330Sstevel@tonic-gate */
6340Sstevel@tonic-gate mlp = controlp;
6350Sstevel@tonic-gate
6360Sstevel@tonic-gate while (mlp != NULL) {
6370Sstevel@tonic-gate if (strcmp(mlp->ctlr_type->ctype_name,
6380Sstevel@tonic-gate cleaned) == 0)
6390Sstevel@tonic-gate break;
6400Sstevel@tonic-gate mlp = mlp->next;
6410Sstevel@tonic-gate }
6420Sstevel@tonic-gate /*
6430Sstevel@tonic-gate * If we couldn't match it, it's an error.
6440Sstevel@tonic-gate */
6450Sstevel@tonic-gate if (mlp == NULL) {
6460Sstevel@tonic-gate for (i = 0; i < OTHER_CTLRS; i++) {
6470Sstevel@tonic-gate if (strcmp(other_ctlrs[i], cleaned)
6480Sstevel@tonic-gate == 0) {
6490Sstevel@tonic-gate datafile_error(NULL, NULL);
6500Sstevel@tonic-gate return;
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate }
6530Sstevel@tonic-gate if (i == OTHER_CTLRS) {
6545084Sjohnlev datafile_error(
6555084Sjohnlev "Unknown controller '%s'",
6565084Sjohnlev cleaned);
6575084Sjohnlev return;
6580Sstevel@tonic-gate }
6590Sstevel@tonic-gate }
6600Sstevel@tonic-gate /*
6610Sstevel@tonic-gate * Found a match. Add this disk type to the list
6620Sstevel@tonic-gate * for the ctlr type if we can complete the
6630Sstevel@tonic-gate * disk specification correctly.
6640Sstevel@tonic-gate */
6650Sstevel@tonic-gate ctype = mlp->ctlr_type;
6660Sstevel@tonic-gate flags |= SUP_CTLR;
6670Sstevel@tonic-gate continue;
6680Sstevel@tonic-gate }
6690Sstevel@tonic-gate /*
6700Sstevel@tonic-gate * All other attributes require a numeric value. Convert
6710Sstevel@tonic-gate * the value to a number.
6720Sstevel@tonic-gate */
6730Sstevel@tonic-gate val = (int)strtol(cleaned, &ptr, 0);
6740Sstevel@tonic-gate if (*ptr != '\0') {
6750Sstevel@tonic-gate datafile_error("Expecting an integer, found '%s'",
6765084Sjohnlev cleaned);
6770Sstevel@tonic-gate return;
6780Sstevel@tonic-gate }
6790Sstevel@tonic-gate /*
6800Sstevel@tonic-gate * Figure out which attribute it was and fill in the
6810Sstevel@tonic-gate * appropriate value. Also note that the attribute
6820Sstevel@tonic-gate * has been defined.
6830Sstevel@tonic-gate */
6840Sstevel@tonic-gate if (strcmp(ident, "ncyl") == 0) {
6850Sstevel@tonic-gate dtype->dtype_ncyl = val;
6860Sstevel@tonic-gate flags |= SUP_NCYL;
6870Sstevel@tonic-gate } else if (strcmp(ident, "acyl") == 0) {
6880Sstevel@tonic-gate dtype->dtype_acyl = val;
6890Sstevel@tonic-gate flags |= SUP_ACYL;
6900Sstevel@tonic-gate } else if (strcmp(ident, "pcyl") == 0) {
6910Sstevel@tonic-gate dtype->dtype_pcyl = val;
6920Sstevel@tonic-gate flags |= SUP_PCYL;
6930Sstevel@tonic-gate } else if (strcmp(ident, "nhead") == 0) {
6940Sstevel@tonic-gate dtype->dtype_nhead = val;
6950Sstevel@tonic-gate flags |= SUP_NHEAD;
6960Sstevel@tonic-gate } else if (strcmp(ident, "nsect") == 0) {
6970Sstevel@tonic-gate dtype->dtype_nsect = val;
6980Sstevel@tonic-gate flags |= SUP_NSECT;
6990Sstevel@tonic-gate } else if (strcmp(ident, "rpm") == 0) {
7000Sstevel@tonic-gate dtype->dtype_rpm = val;
7010Sstevel@tonic-gate flags |= SUP_RPM;
7020Sstevel@tonic-gate } else if (strcmp(ident, "bpt") == 0) {
7030Sstevel@tonic-gate dtype->dtype_bpt = val;
7040Sstevel@tonic-gate flags |= SUP_BPT;
7050Sstevel@tonic-gate } else if (strcmp(ident, "bps") == 0) {
7060Sstevel@tonic-gate dtype->dtype_bps = val;
7070Sstevel@tonic-gate flags |= SUP_BPS;
7080Sstevel@tonic-gate } else if (strcmp(ident, "drive_type") == 0) {
7090Sstevel@tonic-gate dtype->dtype_dr_type = val;
7100Sstevel@tonic-gate flags |= SUP_DRTYPE;
7110Sstevel@tonic-gate } else if (strcmp(ident, "cache") == 0) {
7120Sstevel@tonic-gate dtype->dtype_cache = val;
7130Sstevel@tonic-gate flags |= SUP_CACHE;
7140Sstevel@tonic-gate } else if (strcmp(ident, "prefetch") == 0) {
7150Sstevel@tonic-gate dtype->dtype_threshold = val;
7160Sstevel@tonic-gate flags |= SUP_PREFETCH;
7170Sstevel@tonic-gate } else if (strcmp(ident, "read_retries") == 0) {
7180Sstevel@tonic-gate dtype->dtype_read_retries = val;
7190Sstevel@tonic-gate flags |= SUP_READ_RETRIES;
7200Sstevel@tonic-gate } else if (strcmp(ident, "write_retries") == 0) {
7210Sstevel@tonic-gate dtype->dtype_write_retries = val;
7220Sstevel@tonic-gate flags |= SUP_WRITE_RETRIES;
7230Sstevel@tonic-gate } else if (strcmp(ident, "min_prefetch") == 0) {
7240Sstevel@tonic-gate dtype->dtype_prefetch_min = val;
7250Sstevel@tonic-gate flags |= SUP_CACHE_MIN;
7260Sstevel@tonic-gate } else if (strcmp(ident, "max_prefetch") == 0) {
7270Sstevel@tonic-gate dtype->dtype_prefetch_max = val;
7280Sstevel@tonic-gate flags |= SUP_CACHE_MAX;
7290Sstevel@tonic-gate } else if (strcmp(ident, "trks_zone") == 0) {
7300Sstevel@tonic-gate dtype->dtype_trks_zone = val;
7310Sstevel@tonic-gate flags |= SUP_TRKS_ZONE;
7320Sstevel@tonic-gate } else if (strcmp(ident, "atrks") == 0) {
7330Sstevel@tonic-gate dtype->dtype_atrks = val;
7340Sstevel@tonic-gate flags |= SUP_ATRKS;
7350Sstevel@tonic-gate } else if (strcmp(ident, "asect") == 0) {
7360Sstevel@tonic-gate dtype->dtype_asect = val;
7370Sstevel@tonic-gate flags |= SUP_ASECT;
7380Sstevel@tonic-gate } else if (strcmp(ident, "psect") == 0) {
7390Sstevel@tonic-gate dtype->dtype_psect = val;
7400Sstevel@tonic-gate flags |= SUP_PSECT;
7410Sstevel@tonic-gate } else if (strcmp(ident, "phead") == 0) {
7420Sstevel@tonic-gate dtype->dtype_phead = val;
7430Sstevel@tonic-gate flags |= SUP_PHEAD;
7440Sstevel@tonic-gate } else if (strcmp(ident, "fmt_time") == 0) {
7450Sstevel@tonic-gate dtype->dtype_fmt_time = val;
7460Sstevel@tonic-gate flags |= SUP_FMTTIME;
7470Sstevel@tonic-gate } else if (strcmp(ident, "cyl_skew") == 0) {
7480Sstevel@tonic-gate dtype->dtype_cyl_skew = val;
7490Sstevel@tonic-gate flags |= SUP_CYLSKEW;
7500Sstevel@tonic-gate } else if (strcmp(ident, "trk_skew") == 0) {
7510Sstevel@tonic-gate dtype->dtype_trk_skew = val;
7520Sstevel@tonic-gate flags |= SUP_TRKSKEW;
7530Sstevel@tonic-gate } else {
7540Sstevel@tonic-gate datafile_error("Unknown keyword '%s'", ident);
7550Sstevel@tonic-gate }
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate /*
7580Sstevel@tonic-gate * Check to be sure all the necessary attributes have been defined.
7590Sstevel@tonic-gate * If any are missing, it's an error. Also, log options for later
7600Sstevel@tonic-gate * use by specific driver.
7610Sstevel@tonic-gate */
7620Sstevel@tonic-gate dtype->dtype_options = flags;
7630Sstevel@tonic-gate if ((flags & SUP_MIN_DRIVE) != SUP_MIN_DRIVE) {
7640Sstevel@tonic-gate datafile_error("Incomplete specification", "");
7650Sstevel@tonic-gate return;
7660Sstevel@tonic-gate }
7670Sstevel@tonic-gate if ((!(ctype->ctype_flags & CF_SCSI)) && (!(flags & SUP_BPT)) &&
7680Sstevel@tonic-gate (!(ctype->ctype_flags & CF_NOFORMAT))) {
7690Sstevel@tonic-gate datafile_error("Incomplete specification", "");
7700Sstevel@tonic-gate return;
7710Sstevel@tonic-gate }
7720Sstevel@tonic-gate if ((ctype->ctype_flags & CF_SMD_DEFS) && (!(flags & SUP_BPS))) {
7730Sstevel@tonic-gate datafile_error("Incomplete specification", "");
7740Sstevel@tonic-gate return;
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate /*
7770Sstevel@tonic-gate * Add this disk type to the list for the ctlr type
7780Sstevel@tonic-gate */
7790Sstevel@tonic-gate assert(flags & SUP_CTLR);
7800Sstevel@tonic-gate type = ctype->ctype_dlist;
7810Sstevel@tonic-gate if (type == NULL) {
7820Sstevel@tonic-gate ctype->ctype_dlist = dtype;
7830Sstevel@tonic-gate } else {
7840Sstevel@tonic-gate while (type->dtype_next != NULL)
7850Sstevel@tonic-gate type = type->dtype_next;
7860Sstevel@tonic-gate type->dtype_next = dtype;
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate }
7890Sstevel@tonic-gate
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate /*
7920Sstevel@tonic-gate * Parse a SCSI mode page change specification.
7930Sstevel@tonic-gate *
7940Sstevel@tonic-gate * Return:
7950Sstevel@tonic-gate * 0: not change specification, continue parsing
7960Sstevel@tonic-gate * 1: was change specification, it was ok,
7970Sstevel@tonic-gate * or we already handled the error.
7980Sstevel@tonic-gate */
7990Sstevel@tonic-gate static int
sup_change_spec(struct disk_type * disk,char * id)8000Sstevel@tonic-gate sup_change_spec(struct disk_type *disk, char *id)
8010Sstevel@tonic-gate {
8020Sstevel@tonic-gate char *p;
8030Sstevel@tonic-gate char *p2;
8040Sstevel@tonic-gate int pageno;
8050Sstevel@tonic-gate int byteno;
8060Sstevel@tonic-gate int mode;
8070Sstevel@tonic-gate int value;
8080Sstevel@tonic-gate TOKEN token;
8090Sstevel@tonic-gate TOKEN ident;
8100Sstevel@tonic-gate struct chg_list *cp;
8110Sstevel@tonic-gate int tilde;
8120Sstevel@tonic-gate int i;
8130Sstevel@tonic-gate
8140Sstevel@tonic-gate /*
8150Sstevel@tonic-gate * Syntax: p[<nn>|0x<xx>]
8160Sstevel@tonic-gate */
8170Sstevel@tonic-gate if (*id != 'p') {
8180Sstevel@tonic-gate return (0);
8190Sstevel@tonic-gate }
8200Sstevel@tonic-gate pageno = (int)strtol(id+1, &p2, 0);
8210Sstevel@tonic-gate if (*p2 != 0) {
8220Sstevel@tonic-gate return (0);
8230Sstevel@tonic-gate }
8240Sstevel@tonic-gate /*
8250Sstevel@tonic-gate * Once we get this far, we know we have the
8260Sstevel@tonic-gate * beginnings of a change specification.
8270Sstevel@tonic-gate * If there's a problem now, report the problem,
8280Sstevel@tonic-gate * and return 1, so that the caller can restart
8290Sstevel@tonic-gate * parsing at the next expression.
8300Sstevel@tonic-gate */
8310Sstevel@tonic-gate if (!scsi_supported_page(pageno)) {
8320Sstevel@tonic-gate datafile_error("Unsupported mode page '%s'", id);
8330Sstevel@tonic-gate return (1);
8340Sstevel@tonic-gate }
8350Sstevel@tonic-gate /*
8360Sstevel@tonic-gate * Next token should be the byte offset
8370Sstevel@tonic-gate */
8380Sstevel@tonic-gate if (sup_gettoken(token) != SUP_STRING) {
8390Sstevel@tonic-gate datafile_error("Unexpected value '%s'", token);
8400Sstevel@tonic-gate return (1);
8410Sstevel@tonic-gate }
8420Sstevel@tonic-gate clean_token(ident, token);
8430Sstevel@tonic-gate
8440Sstevel@tonic-gate /*
8450Sstevel@tonic-gate * Syntax: b[<nn>|0x<xx>]
8460Sstevel@tonic-gate */
8470Sstevel@tonic-gate p = ident;
8480Sstevel@tonic-gate if (*p++ != 'b') {
8490Sstevel@tonic-gate datafile_error("Unknown keyword '%s'", ident);
8500Sstevel@tonic-gate return (1);
8510Sstevel@tonic-gate }
8520Sstevel@tonic-gate byteno = (int)strtol(p, &p2, 10);
8530Sstevel@tonic-gate if (*p2 != 0) {
8540Sstevel@tonic-gate datafile_error("Unknown keyword '%s'", ident);
8550Sstevel@tonic-gate return (1);
8560Sstevel@tonic-gate }
8570Sstevel@tonic-gate if (byteno == 0 || byteno == 1) {
8580Sstevel@tonic-gate datafile_error("Unsupported byte offset '%s'", ident);
8590Sstevel@tonic-gate return (1);
8600Sstevel@tonic-gate }
8610Sstevel@tonic-gate
8620Sstevel@tonic-gate /*
8630Sstevel@tonic-gate * Get the operator for this expression
8640Sstevel@tonic-gate */
8650Sstevel@tonic-gate mode = CHG_MODE_UNDEFINED;
8660Sstevel@tonic-gate switch (sup_gettoken(token)) {
8670Sstevel@tonic-gate case SUP_EQL:
8680Sstevel@tonic-gate mode = CHG_MODE_ABS;
8690Sstevel@tonic-gate break;
8700Sstevel@tonic-gate case SUP_OR:
8710Sstevel@tonic-gate if (sup_gettoken(token) == SUP_EQL)
8720Sstevel@tonic-gate mode = CHG_MODE_SET;
8730Sstevel@tonic-gate break;
8740Sstevel@tonic-gate case SUP_AND:
8750Sstevel@tonic-gate if (sup_gettoken(token) == SUP_EQL)
8760Sstevel@tonic-gate mode = CHG_MODE_CLR;
8770Sstevel@tonic-gate break;
8780Sstevel@tonic-gate }
8790Sstevel@tonic-gate if (mode == CHG_MODE_UNDEFINED) {
8800Sstevel@tonic-gate datafile_error("Unexpected operator: '%s'", token);
8810Sstevel@tonic-gate return (1);
8820Sstevel@tonic-gate }
8830Sstevel@tonic-gate
8840Sstevel@tonic-gate /*
8850Sstevel@tonic-gate * Get right-hand of expression - accept optional tilde
8860Sstevel@tonic-gate */
8870Sstevel@tonic-gate tilde = 0;
8880Sstevel@tonic-gate if ((i = sup_gettoken(token)) == SUP_TILDE) {
8890Sstevel@tonic-gate tilde = 1;
8900Sstevel@tonic-gate i = sup_gettoken(token);
8910Sstevel@tonic-gate }
8920Sstevel@tonic-gate if (i != SUP_STRING) {
8930Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
8940Sstevel@tonic-gate return (1);
8950Sstevel@tonic-gate }
8960Sstevel@tonic-gate clean_token(ident, token);
8970Sstevel@tonic-gate value = (int)strtol(ident, &p, 0);
8980Sstevel@tonic-gate if (*p != 0) {
8990Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
9000Sstevel@tonic-gate return (1);
9010Sstevel@tonic-gate }
9020Sstevel@tonic-gate
9030Sstevel@tonic-gate /*
9040Sstevel@tonic-gate * Apply the tilde operator, if found.
9050Sstevel@tonic-gate * Constrain to a byte value.
9060Sstevel@tonic-gate */
9070Sstevel@tonic-gate if (tilde) {
9080Sstevel@tonic-gate value = ~value;
9090Sstevel@tonic-gate }
9100Sstevel@tonic-gate value &= 0xff;
9110Sstevel@tonic-gate
9120Sstevel@tonic-gate /*
9130Sstevel@tonic-gate * We parsed a successful change specification expression.
9140Sstevel@tonic-gate * Add it to the list for this disk type.
9150Sstevel@tonic-gate */
9160Sstevel@tonic-gate cp = new_chg_list(disk);
9170Sstevel@tonic-gate cp->pageno = pageno;
9180Sstevel@tonic-gate cp->byteno = byteno;
9190Sstevel@tonic-gate cp->mode = mode;
9200Sstevel@tonic-gate cp->value = value;
9210Sstevel@tonic-gate return (1);
9220Sstevel@tonic-gate }
9230Sstevel@tonic-gate
9240Sstevel@tonic-gate
9250Sstevel@tonic-gate /*
9260Sstevel@tonic-gate * This routine processes a 'partition' line in the data file. It defines
9270Sstevel@tonic-gate * a known partition map for a particular disk type on a particular
9280Sstevel@tonic-gate * controller type.
9290Sstevel@tonic-gate */
9300Sstevel@tonic-gate static void
sup_setpart()9310Sstevel@tonic-gate sup_setpart()
9320Sstevel@tonic-gate {
9330Sstevel@tonic-gate TOKEN token, cleaned, disk, ctlr, ident;
9340Sstevel@tonic-gate struct disk_type *dtype = NULL;
9350Sstevel@tonic-gate struct ctlr_type *ctype = NULL;
9360Sstevel@tonic-gate struct partition_info *pinfo, *parts;
9370Sstevel@tonic-gate char *pinfo_name;
9387563SPrasad.Singamsetty@Sun.COM int i, index, status, flags = 0;
9397563SPrasad.Singamsetty@Sun.COM uint_t val1, val2;
9400Sstevel@tonic-gate ushort_t vtoc_tag;
9410Sstevel@tonic-gate ushort_t vtoc_flag;
9420Sstevel@tonic-gate struct mctlr_list *mlp;
9430Sstevel@tonic-gate
9440Sstevel@tonic-gate /*
9450Sstevel@tonic-gate * Pull in some grammar.
9460Sstevel@tonic-gate */
9470Sstevel@tonic-gate status = sup_gettoken(token);
9480Sstevel@tonic-gate if (status != SUP_EQL) {
9490Sstevel@tonic-gate datafile_error("Expecting '=', found '%s'", token);
9500Sstevel@tonic-gate return;
9510Sstevel@tonic-gate }
9520Sstevel@tonic-gate /*
9530Sstevel@tonic-gate * Pull in the name of the map.
9540Sstevel@tonic-gate */
9550Sstevel@tonic-gate status = sup_gettoken(token);
9560Sstevel@tonic-gate if (status != SUP_STRING) {
9570Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
9580Sstevel@tonic-gate return;
9590Sstevel@tonic-gate }
9600Sstevel@tonic-gate clean_token(cleaned, token);
9610Sstevel@tonic-gate /*
9620Sstevel@tonic-gate * Allocate space for the partition map and fill in the name.
9630Sstevel@tonic-gate */
9640Sstevel@tonic-gate pinfo_name = (char *)zalloc(strlen(cleaned) + 1);
9650Sstevel@tonic-gate (void) strcpy(pinfo_name, cleaned);
9660Sstevel@tonic-gate pinfo = (struct partition_info *)zalloc(sizeof (struct partition_info));
9670Sstevel@tonic-gate pinfo->pinfo_name = pinfo_name;
9680Sstevel@tonic-gate /*
9690Sstevel@tonic-gate * Save the filename/linenumber where this partition was defined
9700Sstevel@tonic-gate */
9710Sstevel@tonic-gate pinfo->pinfo_filename = file_name;
9720Sstevel@tonic-gate pinfo->pinfo_lineno = data_lineno;
9730Sstevel@tonic-gate
9740Sstevel@tonic-gate /*
9750Sstevel@tonic-gate * Install default vtoc information into the new partition table
9760Sstevel@tonic-gate */
9770Sstevel@tonic-gate set_vtoc_defaults(pinfo);
9780Sstevel@tonic-gate
9790Sstevel@tonic-gate /*
9800Sstevel@tonic-gate * Loop for each attribute in the line.
9810Sstevel@tonic-gate */
9820Sstevel@tonic-gate for (;;) {
9830Sstevel@tonic-gate /*
9840Sstevel@tonic-gate * Pull in some grammar.
9850Sstevel@tonic-gate */
9860Sstevel@tonic-gate status = sup_gettoken(token);
9870Sstevel@tonic-gate /*
9880Sstevel@tonic-gate * If we hit end of line, we're done.
9890Sstevel@tonic-gate */
9900Sstevel@tonic-gate if (status == SUP_EOL)
9910Sstevel@tonic-gate break;
9920Sstevel@tonic-gate if (status != SUP_COLON) {
9930Sstevel@tonic-gate datafile_error("Expecting ':', found '%s'", token);
9940Sstevel@tonic-gate return;
9950Sstevel@tonic-gate }
9960Sstevel@tonic-gate /*
9970Sstevel@tonic-gate * Pull in the attribute.
9980Sstevel@tonic-gate */
9990Sstevel@tonic-gate status = sup_gettoken(token);
10000Sstevel@tonic-gate /*
10010Sstevel@tonic-gate * If we hit end of line, we're done.
10020Sstevel@tonic-gate */
10030Sstevel@tonic-gate if (status == SUP_EOL)
10040Sstevel@tonic-gate break;
10050Sstevel@tonic-gate if (status != SUP_STRING) {
10060Sstevel@tonic-gate datafile_error("Expecting keyword, found '%s'", token);
10070Sstevel@tonic-gate return;
10080Sstevel@tonic-gate }
10090Sstevel@tonic-gate clean_token(ident, token);
10100Sstevel@tonic-gate /*
10110Sstevel@tonic-gate * Pull in more grammar.
10120Sstevel@tonic-gate */
10130Sstevel@tonic-gate status = sup_gettoken(token);
10140Sstevel@tonic-gate if (status != SUP_EQL) {
10150Sstevel@tonic-gate datafile_error("Expecting '=', found '%s'", token);
10160Sstevel@tonic-gate return;
10170Sstevel@tonic-gate }
10180Sstevel@tonic-gate /*
10190Sstevel@tonic-gate * Pull in the value of the attribute.
10200Sstevel@tonic-gate */
10210Sstevel@tonic-gate status = sup_gettoken(token);
10220Sstevel@tonic-gate /*
10230Sstevel@tonic-gate * If we hit a key character, it's an error.
10240Sstevel@tonic-gate */
10250Sstevel@tonic-gate if (status != SUP_STRING) {
10260Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
10270Sstevel@tonic-gate return;
10280Sstevel@tonic-gate }
10290Sstevel@tonic-gate clean_token(cleaned, token);
10300Sstevel@tonic-gate /*
10310Sstevel@tonic-gate * If the attribute is the ctlr, save the ctlr name and
10320Sstevel@tonic-gate * mark it defined.
10330Sstevel@tonic-gate */
10340Sstevel@tonic-gate if (strcmp(ident, "ctlr") == 0) {
10350Sstevel@tonic-gate (void) strcpy(ctlr, cleaned);
10360Sstevel@tonic-gate flags |= SUP_CTLR;
10370Sstevel@tonic-gate continue;
10380Sstevel@tonic-gate /*
10390Sstevel@tonic-gate * If the attribute is the disk, save the disk name and
10400Sstevel@tonic-gate * mark it defined.
10410Sstevel@tonic-gate */
10420Sstevel@tonic-gate } else if (strcmp(ident, "disk") == 0) {
10430Sstevel@tonic-gate (void) strcpy(disk, cleaned);
10440Sstevel@tonic-gate flags |= SUP_DISK;
10450Sstevel@tonic-gate continue;
10460Sstevel@tonic-gate }
10470Sstevel@tonic-gate /*
10480Sstevel@tonic-gate * If we now know both the controller name and the
10490Sstevel@tonic-gate * disk name, let's see if we can find the controller
10500Sstevel@tonic-gate * and disk type. This will give us the geometry,
10510Sstevel@tonic-gate * which can permit us to accept partitions specs
10520Sstevel@tonic-gate * in cylinders or blocks.
10530Sstevel@tonic-gate */
10540Sstevel@tonic-gate if (((flags & (SUP_DISK|SUP_CTLR)) == (SUP_DISK|SUP_CTLR)) &&
10555084Sjohnlev dtype == NULL && ctype == NULL) {
10560Sstevel@tonic-gate /*
10570Sstevel@tonic-gate * Attempt to match the specified ctlr to a known type.
10580Sstevel@tonic-gate */
10590Sstevel@tonic-gate mlp = controlp;
10600Sstevel@tonic-gate
10610Sstevel@tonic-gate while (mlp != NULL) {
10620Sstevel@tonic-gate if (strcmp(mlp->ctlr_type->ctype_name,
10630Sstevel@tonic-gate ctlr) == 0)
10640Sstevel@tonic-gate break;
10650Sstevel@tonic-gate mlp = mlp->next;
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate /*
10680Sstevel@tonic-gate * If no match is found, it's an error.
10690Sstevel@tonic-gate */
10700Sstevel@tonic-gate if (mlp == NULL) {
10710Sstevel@tonic-gate for (i = 0; i < OTHER_CTLRS; i++) {
10720Sstevel@tonic-gate if (strcmp(other_ctlrs[i], ctlr) == 0) {
10730Sstevel@tonic-gate datafile_error(NULL, NULL);
10740Sstevel@tonic-gate return;
10750Sstevel@tonic-gate }
10760Sstevel@tonic-gate }
10770Sstevel@tonic-gate if (i == OTHER_CTLRS) {
10780Sstevel@tonic-gate datafile_error(
10790Sstevel@tonic-gate "Unknown controller '%s'", ctlr);
10800Sstevel@tonic-gate return;
10810Sstevel@tonic-gate }
10820Sstevel@tonic-gate }
10830Sstevel@tonic-gate ctype = mlp->ctlr_type;
10840Sstevel@tonic-gate /*
10850Sstevel@tonic-gate * Attempt to match the specified disk to a known type.
10860Sstevel@tonic-gate */
10870Sstevel@tonic-gate for (dtype = ctype->ctype_dlist; dtype != NULL;
10885084Sjohnlev dtype = dtype->dtype_next) {
10890Sstevel@tonic-gate if (strcmp(dtype->dtype_asciilabel, disk) == 0)
10900Sstevel@tonic-gate break;
10910Sstevel@tonic-gate }
10920Sstevel@tonic-gate /*
10930Sstevel@tonic-gate * If no match is found, it's an error.
10940Sstevel@tonic-gate */
10950Sstevel@tonic-gate if (dtype == NULL) {
10960Sstevel@tonic-gate datafile_error("Unknown disk '%s'", disk);
10970Sstevel@tonic-gate return;
10980Sstevel@tonic-gate }
10990Sstevel@tonic-gate /*
11000Sstevel@tonic-gate * Now that we know the disk type, set up the
11010Sstevel@tonic-gate * globals that let that magic macro "spc()"
11020Sstevel@tonic-gate * do it's thing. Sorry that this is glued
11030Sstevel@tonic-gate * together so poorly...
11040Sstevel@tonic-gate */
11050Sstevel@tonic-gate nhead = dtype->dtype_nhead;
11060Sstevel@tonic-gate nsect = dtype->dtype_nsect;
11070Sstevel@tonic-gate acyl = dtype->dtype_acyl;
11080Sstevel@tonic-gate ncyl = dtype->dtype_ncyl;
11090Sstevel@tonic-gate }
11100Sstevel@tonic-gate /*
11110Sstevel@tonic-gate * By now, the disk and controller type must be defined
11120Sstevel@tonic-gate */
11130Sstevel@tonic-gate if (dtype == NULL || ctype == NULL) {
11140Sstevel@tonic-gate datafile_error("Incomplete specification", "");
11150Sstevel@tonic-gate return;
11160Sstevel@tonic-gate }
11170Sstevel@tonic-gate /*
11180Sstevel@tonic-gate * The rest of the attributes are all single letters.
11190Sstevel@tonic-gate * Make sure the specified attribute is a single letter.
11200Sstevel@tonic-gate */
11210Sstevel@tonic-gate if (strlen(ident) != 1) {
11220Sstevel@tonic-gate datafile_error("Unknown keyword '%s'", ident);
11230Sstevel@tonic-gate return;
11240Sstevel@tonic-gate }
11250Sstevel@tonic-gate /*
11260Sstevel@tonic-gate * Also make sure it is within the legal range of letters.
11270Sstevel@tonic-gate */
11280Sstevel@tonic-gate if (ident[0] < PARTITION_BASE || ident[0] > PARTITION_BASE+9) {
11290Sstevel@tonic-gate datafile_error("Unknown keyword '%s'", ident);
11300Sstevel@tonic-gate return;
11310Sstevel@tonic-gate }
11320Sstevel@tonic-gate /*
11330Sstevel@tonic-gate * Here's the index of the partition we're dealing with
11340Sstevel@tonic-gate */
11350Sstevel@tonic-gate index = ident[0] - PARTITION_BASE;
11360Sstevel@tonic-gate /*
11370Sstevel@tonic-gate * For SunOS 5.0, we support the additional syntax:
11380Sstevel@tonic-gate * [<tag>, ] [<flag>, ] <start>, <end>
11390Sstevel@tonic-gate * instead of:
11400Sstevel@tonic-gate * <start>, <end>
11410Sstevel@tonic-gate *
11420Sstevel@tonic-gate * <tag> may be one of: boot, root, swap, etc.
11430Sstevel@tonic-gate * <flag> consists of two characters:
11440Sstevel@tonic-gate * W (writable) or R (read-only)
11450Sstevel@tonic-gate * M (mountable) or U (unmountable)
11460Sstevel@tonic-gate *
11470Sstevel@tonic-gate * Start with the defaults assigned above:
11480Sstevel@tonic-gate */
11490Sstevel@tonic-gate vtoc_tag = pinfo->vtoc.v_part[index].p_tag;
11500Sstevel@tonic-gate vtoc_flag = pinfo->vtoc.v_part[index].p_flag;
11510Sstevel@tonic-gate
11520Sstevel@tonic-gate /*
11530Sstevel@tonic-gate * First try to match token against possible tag values
11540Sstevel@tonic-gate */
11550Sstevel@tonic-gate if (find_value(ptag_choices, cleaned, &i) == 1) {
11560Sstevel@tonic-gate /*
11570Sstevel@tonic-gate * Found valid tag. Use it and advance parser
11580Sstevel@tonic-gate */
11590Sstevel@tonic-gate vtoc_tag = (ushort_t)i;
11600Sstevel@tonic-gate status = sup_gettoken(token);
11610Sstevel@tonic-gate if (status != SUP_COMMA) {
11620Sstevel@tonic-gate datafile_error(
11635084Sjohnlev "Expecting ', ', found '%s'", token);
11640Sstevel@tonic-gate return;
11650Sstevel@tonic-gate }
11660Sstevel@tonic-gate status = sup_gettoken(token);
11670Sstevel@tonic-gate if (status != SUP_STRING) {
11680Sstevel@tonic-gate datafile_error("Expecting value, found '%s'",
11695084Sjohnlev token);
11700Sstevel@tonic-gate return;
11710Sstevel@tonic-gate }
11720Sstevel@tonic-gate clean_token(cleaned, token);
11730Sstevel@tonic-gate }
11740Sstevel@tonic-gate
11750Sstevel@tonic-gate /*
11760Sstevel@tonic-gate * Try to match token against possible flag values
11770Sstevel@tonic-gate */
11780Sstevel@tonic-gate if (find_value(pflag_choices, cleaned, &i) == 1) {
11790Sstevel@tonic-gate /*
11800Sstevel@tonic-gate * Found valid flag. Use it and advance parser
11810Sstevel@tonic-gate */
11820Sstevel@tonic-gate vtoc_flag = (ushort_t)i;
11830Sstevel@tonic-gate status = sup_gettoken(token);
11840Sstevel@tonic-gate if (status != SUP_COMMA) {
11850Sstevel@tonic-gate datafile_error("Expecting ', ', found '%s'",
11865084Sjohnlev token);
11870Sstevel@tonic-gate return;
11880Sstevel@tonic-gate }
11890Sstevel@tonic-gate status = sup_gettoken(token);
11900Sstevel@tonic-gate if (status != SUP_STRING) {
11910Sstevel@tonic-gate datafile_error("Expecting value, found '%s'",
11925084Sjohnlev token);
11930Sstevel@tonic-gate return;
11940Sstevel@tonic-gate }
11950Sstevel@tonic-gate clean_token(cleaned, token);
11960Sstevel@tonic-gate }
11970Sstevel@tonic-gate /*
11980Sstevel@tonic-gate * All other attributes have a pair of numeric values.
11990Sstevel@tonic-gate * Convert the first value to a number. This value
12000Sstevel@tonic-gate * is the starting cylinder number of the partition.
12010Sstevel@tonic-gate */
12020Sstevel@tonic-gate val1 = str2cyls(cleaned);
12037563SPrasad.Singamsetty@Sun.COM if (val1 == (uint_t)(-1)) {
12040Sstevel@tonic-gate datafile_error("Expecting an integer, found '%s'",
12055084Sjohnlev cleaned);
12060Sstevel@tonic-gate return;
12070Sstevel@tonic-gate }
12080Sstevel@tonic-gate /*
12090Sstevel@tonic-gate * Pull in some grammar.
12100Sstevel@tonic-gate */
12110Sstevel@tonic-gate status = sup_gettoken(token);
12120Sstevel@tonic-gate if (status != SUP_COMMA) {
12130Sstevel@tonic-gate datafile_error("Expecting ', ', found '%s'", token);
12140Sstevel@tonic-gate return;
12150Sstevel@tonic-gate }
12160Sstevel@tonic-gate /*
12170Sstevel@tonic-gate * Pull in the second value.
12180Sstevel@tonic-gate */
12190Sstevel@tonic-gate status = sup_gettoken(token);
12200Sstevel@tonic-gate if (status != SUP_STRING) {
12210Sstevel@tonic-gate datafile_error("Expecting value, found '%s'", token);
12220Sstevel@tonic-gate return;
12230Sstevel@tonic-gate }
12240Sstevel@tonic-gate clean_token(cleaned, token);
12250Sstevel@tonic-gate /*
12260Sstevel@tonic-gate * Convert the second value to a number. This value
12270Sstevel@tonic-gate * is the number of blocks composing the partition.
12280Sstevel@tonic-gate * If the token is terminated with a 'c', the units
12290Sstevel@tonic-gate * are cylinders, not blocks. Also accept a 'b', if
12300Sstevel@tonic-gate * they choose to be so specific.
12310Sstevel@tonic-gate */
12320Sstevel@tonic-gate val2 = str2blks(cleaned);
12337563SPrasad.Singamsetty@Sun.COM if (val2 == (uint_t)(-1)) {
12340Sstevel@tonic-gate datafile_error("Expecting an integer, found '%s'",
12355084Sjohnlev cleaned);
12360Sstevel@tonic-gate return;
12370Sstevel@tonic-gate }
12380Sstevel@tonic-gate /*
12390Sstevel@tonic-gate * Fill in the appropriate map entry with the values.
12400Sstevel@tonic-gate */
12410Sstevel@tonic-gate pinfo->pinfo_map[index].dkl_cylno = val1;
12420Sstevel@tonic-gate pinfo->pinfo_map[index].dkl_nblk = val2;
12430Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_tag = vtoc_tag;
12440Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_flag = vtoc_flag;
12450Sstevel@tonic-gate
12460Sstevel@tonic-gate #if defined(_SUNOS_VTOC_16)
12470Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_start = val1 * (nhead * nsect);
12480Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_size = val2;
12490Sstevel@tonic-gate
12500Sstevel@tonic-gate if (val2 == 0) {
12510Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_tag = 0;
12520Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_flag = 0;
12530Sstevel@tonic-gate pinfo->vtoc.v_part[index].p_start = 0;
12540Sstevel@tonic-gate pinfo->pinfo_map[index].dkl_cylno = 0;
12550Sstevel@tonic-gate }
12560Sstevel@tonic-gate #endif /* defined(_SUNOS_VTOC_16) */
12570Sstevel@tonic-gate
12580Sstevel@tonic-gate }
12590Sstevel@tonic-gate /*
12600Sstevel@tonic-gate * Check to be sure that all necessary attributes were defined.
12610Sstevel@tonic-gate */
12620Sstevel@tonic-gate if ((flags & SUP_MIN_PART) != SUP_MIN_PART) {
12630Sstevel@tonic-gate datafile_error("Incomplete specification", "");
12640Sstevel@tonic-gate return;
12650Sstevel@tonic-gate }
12660Sstevel@tonic-gate /*
12670Sstevel@tonic-gate * Add this partition map to the list of known maps for the
12680Sstevel@tonic-gate * specified disk/ctlr.
12690Sstevel@tonic-gate */
12700Sstevel@tonic-gate parts = dtype->dtype_plist;
12710Sstevel@tonic-gate if (parts == NULL)
12720Sstevel@tonic-gate dtype->dtype_plist = pinfo;
12730Sstevel@tonic-gate else {
12740Sstevel@tonic-gate while (parts->pinfo_next != NULL)
12750Sstevel@tonic-gate parts = parts->pinfo_next;
12760Sstevel@tonic-gate parts->pinfo_next = pinfo;
12770Sstevel@tonic-gate }
12780Sstevel@tonic-gate }
12790Sstevel@tonic-gate
12800Sstevel@tonic-gate /*
12810Sstevel@tonic-gate * Open the disk device - just a wrapper for open.
12820Sstevel@tonic-gate */
12830Sstevel@tonic-gate int
open_disk(char * diskname,int flags)12840Sstevel@tonic-gate open_disk(char *diskname, int flags)
12850Sstevel@tonic-gate {
12860Sstevel@tonic-gate return (open(diskname, flags));
12870Sstevel@tonic-gate }
12880Sstevel@tonic-gate
12890Sstevel@tonic-gate /*
12900Sstevel@tonic-gate * This routine performs the disk search during startup. It looks for
12910Sstevel@tonic-gate * all the disks in the search path, and creates a list of those that
12920Sstevel@tonic-gate * are found.
12930Sstevel@tonic-gate */
12940Sstevel@tonic-gate void
do_search(char * arglist[])12950Sstevel@tonic-gate do_search(char *arglist[])
12960Sstevel@tonic-gate {
12970Sstevel@tonic-gate char **sp;
12980Sstevel@tonic-gate DIR *dir;
12990Sstevel@tonic-gate struct dirent *dp;
13000Sstevel@tonic-gate char s[MAXPATHLEN];
13010Sstevel@tonic-gate char path[MAXPATHLEN];
13020Sstevel@tonic-gate char curdir[MAXPATHLEN];
13030Sstevel@tonic-gate char *directory = "/dev/rdsk";
13040Sstevel@tonic-gate struct disk_info *disk;
13050Sstevel@tonic-gate int i;
13060Sstevel@tonic-gate
13070Sstevel@tonic-gate /*
13080Sstevel@tonic-gate * Change directory to the device directory. This
13090Sstevel@tonic-gate * gives us the most efficient access to that directory.
13100Sstevel@tonic-gate * Remember where we were, and return there when finished.
13110Sstevel@tonic-gate */
13120Sstevel@tonic-gate if (getcwd(curdir, sizeof (curdir)) == NULL) {
13130Sstevel@tonic-gate err_print("Cannot get current directory - %s\n",
13145084Sjohnlev strerror(errno));
13150Sstevel@tonic-gate fullabort();
13160Sstevel@tonic-gate }
13170Sstevel@tonic-gate if (chdir(directory) == -1) {
13180Sstevel@tonic-gate err_print("Cannot set directory to %s - %s\n",
13195084Sjohnlev directory, strerror(errno));
13200Sstevel@tonic-gate fullabort();
13210Sstevel@tonic-gate }
13220Sstevel@tonic-gate
13230Sstevel@tonic-gate /*
13240Sstevel@tonic-gate * If there were disks specified on the command line,
13250Sstevel@tonic-gate * use those disks, and nothing but those disks.
13260Sstevel@tonic-gate */
13270Sstevel@tonic-gate if (arglist != NULL) {
13280Sstevel@tonic-gate check_for_duplicate_disknames(arglist);
13290Sstevel@tonic-gate for (; *arglist != NULL; arglist++) {
13300Sstevel@tonic-gate search_for_logical_dev(*arglist);
13310Sstevel@tonic-gate }
13320Sstevel@tonic-gate } else {
13330Sstevel@tonic-gate /*
13340Sstevel@tonic-gate * If there were no disks specified on the command line,
13350Sstevel@tonic-gate * search for all disks attached to the system.
13360Sstevel@tonic-gate */
13370Sstevel@tonic-gate fmt_print("Searching for disks...");
13380Sstevel@tonic-gate (void) fflush(stdout);
13390Sstevel@tonic-gate need_newline = 1;
13400Sstevel@tonic-gate
13410Sstevel@tonic-gate /*
13420Sstevel@tonic-gate * Find all disks specified in search_path definitions
13430Sstevel@tonic-gate * in whatever format.dat files were processed.
13440Sstevel@tonic-gate */
13450Sstevel@tonic-gate sp = search_path;
13460Sstevel@tonic-gate if (sp != NULL) {
13470Sstevel@tonic-gate while (*sp != NULL) {
13480Sstevel@tonic-gate search_for_logical_dev(*sp++);
13490Sstevel@tonic-gate }
13500Sstevel@tonic-gate }
13510Sstevel@tonic-gate
13520Sstevel@tonic-gate /*
13530Sstevel@tonic-gate * Open the device directory
13540Sstevel@tonic-gate */
13550Sstevel@tonic-gate if ((dir = opendir(".")) == NULL) {
13560Sstevel@tonic-gate err_print("Cannot open %s - %s\n",
13575084Sjohnlev directory, strerror(errno));
13580Sstevel@tonic-gate fullabort();
13590Sstevel@tonic-gate }
13600Sstevel@tonic-gate
13610Sstevel@tonic-gate /*
13620Sstevel@tonic-gate * Now find all usable nodes in /dev/rdsk (or /dev, if 4.x)
13630Sstevel@tonic-gate * First find all nodes which do not conform to
13640Sstevel@tonic-gate * standard disk naming conventions. This permits
13650Sstevel@tonic-gate * all user-defined names to override the default names.
13660Sstevel@tonic-gate */
13670Sstevel@tonic-gate while ((dp = readdir(dir)) != NULL) {
13680Sstevel@tonic-gate if (strcmp(dp->d_name, ".") == 0 ||
13695084Sjohnlev strcmp(dp->d_name, "..") == 0)
13700Sstevel@tonic-gate continue;
13710Sstevel@tonic-gate if (!conventional_name(dp->d_name)) {
13725084Sjohnlev if (!fdisk_physical_name(dp->d_name)) {
13735084Sjohnlev /*
13745084Sjohnlev * If non-conventional name represents
13755084Sjohnlev * a link to non-s2 slice , ignore it.
13765084Sjohnlev */
13775084Sjohnlev if (!name_represents_wholedisk
13785084Sjohnlev (dp->d_name)) {
13795084Sjohnlev (void) strcpy(path, directory);
13805084Sjohnlev (void) strcat(path, "/");
13815084Sjohnlev (void) strcat(path, dp->d_name);
13825084Sjohnlev add_device_to_disklist(
13835084Sjohnlev dp->d_name, path);
13845084Sjohnlev }
13855084Sjohnlev }
13860Sstevel@tonic-gate }
13870Sstevel@tonic-gate }
13880Sstevel@tonic-gate rewinddir(dir);
13890Sstevel@tonic-gate
13900Sstevel@tonic-gate
13910Sstevel@tonic-gate /*
13920Sstevel@tonic-gate * Now find all nodes corresponding to the standard
13930Sstevel@tonic-gate * device naming conventions.
13940Sstevel@tonic-gate */
13950Sstevel@tonic-gate while ((dp = readdir(dir)) != NULL) {
13960Sstevel@tonic-gate if (strcmp(dp->d_name, ".") == 0 ||
13975084Sjohnlev strcmp(dp->d_name, "..") == 0)
13980Sstevel@tonic-gate continue;
13990Sstevel@tonic-gate if (whole_disk_name(dp->d_name)) {
14000Sstevel@tonic-gate (void) strcpy(path, directory);
14010Sstevel@tonic-gate (void) strcat(path, "/");
14020Sstevel@tonic-gate (void) strcat(path, dp->d_name);
14030Sstevel@tonic-gate canonicalize_name(s, dp->d_name);
14040Sstevel@tonic-gate add_device_to_disklist(s, path);
14050Sstevel@tonic-gate }
14060Sstevel@tonic-gate }
14070Sstevel@tonic-gate /*
14080Sstevel@tonic-gate * Close the directory
14090Sstevel@tonic-gate */
14100Sstevel@tonic-gate if (closedir(dir) == -1) {
14110Sstevel@tonic-gate err_print("Cannot close directory %s - %s\n",
14125084Sjohnlev directory, strerror(errno));
14130Sstevel@tonic-gate fullabort();
14140Sstevel@tonic-gate }
14150Sstevel@tonic-gate
14160Sstevel@tonic-gate need_newline = 0;
14170Sstevel@tonic-gate fmt_print("done\n");
14180Sstevel@tonic-gate }
14190Sstevel@tonic-gate
14200Sstevel@tonic-gate /*
14210Sstevel@tonic-gate * Return to whence we came
14220Sstevel@tonic-gate */
14230Sstevel@tonic-gate if (chdir(curdir) == -1) {
14240Sstevel@tonic-gate err_print("Cannot set directory to %s - %s\n",
14255084Sjohnlev curdir, strerror(errno));
14260Sstevel@tonic-gate fullabort();
14270Sstevel@tonic-gate }
14280Sstevel@tonic-gate
14290Sstevel@tonic-gate /*
14300Sstevel@tonic-gate * If we didn't find any disks, give up.
14310Sstevel@tonic-gate */
14320Sstevel@tonic-gate if (disk_list == NULL) {
14330Sstevel@tonic-gate if (geteuid() == 0) {
14340Sstevel@tonic-gate err_print("No disks found!\n");
14350Sstevel@tonic-gate } else {
14360Sstevel@tonic-gate err_print("No permission (or no disks found)!\n");
14370Sstevel@tonic-gate }
14380Sstevel@tonic-gate (void) fflush(stdout);
14390Sstevel@tonic-gate fullabort();
14400Sstevel@tonic-gate }
14410Sstevel@tonic-gate
14420Sstevel@tonic-gate sort_disk_list();
14430Sstevel@tonic-gate
14440Sstevel@tonic-gate /*
14450Sstevel@tonic-gate * Tell user the results of the auto-configure process
14460Sstevel@tonic-gate */
14470Sstevel@tonic-gate i = 0;
14480Sstevel@tonic-gate for (disk = disk_list; disk != NULL; disk = disk->disk_next) {
14490Sstevel@tonic-gate float scaled;
14507563SPrasad.Singamsetty@Sun.COM diskaddr_t nblks;
14510Sstevel@tonic-gate struct disk_type *type;
14520Sstevel@tonic-gate if (disk->disk_flags & DSK_AUTO_CONFIG) {
14530Sstevel@tonic-gate if (i++ == 0) {
14540Sstevel@tonic-gate fmt_print("\n");
14550Sstevel@tonic-gate }
14560Sstevel@tonic-gate fmt_print("%s: ", disk->disk_name);
14570Sstevel@tonic-gate if (disk->disk_flags & DSK_LABEL_DIRTY) {
14580Sstevel@tonic-gate fmt_print("configured ");
14590Sstevel@tonic-gate } else {
14600Sstevel@tonic-gate fmt_print("configured and labeled ");
14610Sstevel@tonic-gate }
14620Sstevel@tonic-gate type = disk->disk_type;
14630Sstevel@tonic-gate nblks = type->dtype_ncyl * type->dtype_nhead *
14645084Sjohnlev type->dtype_nsect;
14650Sstevel@tonic-gate if (disk->label_type == L_TYPE_SOLARIS)
14665084Sjohnlev scaled = bn2mb(nblks);
14670Sstevel@tonic-gate else
14685084Sjohnlev scaled = bn2mb(type->capacity);
14690Sstevel@tonic-gate fmt_print("with capacity of ");
14700Sstevel@tonic-gate if (scaled > 1024.0) {
14710Sstevel@tonic-gate fmt_print("%1.2fGB\n", scaled/1024.0);
14720Sstevel@tonic-gate } else {
14730Sstevel@tonic-gate fmt_print("%1.2fMB\n", scaled);
14740Sstevel@tonic-gate }
14750Sstevel@tonic-gate }
14760Sstevel@tonic-gate }
14770Sstevel@tonic-gate }
14780Sstevel@tonic-gate
14790Sstevel@tonic-gate
14800Sstevel@tonic-gate /*
14810Sstevel@tonic-gate * For a given "logical" disk name as specified in a format.dat
14820Sstevel@tonic-gate * search path, try to find the device it actually refers to.
14830Sstevel@tonic-gate * Since we are trying to maintain 4.x naming convention
14840Sstevel@tonic-gate * compatibility in 5.0, this involves a little bit of work.
14850Sstevel@tonic-gate * We also want to be able to function under 4.x, if needed.
14860Sstevel@tonic-gate *
14870Sstevel@tonic-gate * canonical: standard name reference. append a partition
14880Sstevel@tonic-gate * reference, and open that file in the device directory.
14890Sstevel@tonic-gate * examples: SVR4: c0t0d0
14900Sstevel@tonic-gate * 4.x: sd0
14910Sstevel@tonic-gate *
14920Sstevel@tonic-gate * absolute: begins with a '/', and is assumed to be an
14930Sstevel@tonic-gate * absolute pathname to some node.
14940Sstevel@tonic-gate *
14950Sstevel@tonic-gate * relative: non-canonical, doesn't begin with a '/'.
14960Sstevel@tonic-gate * assumed to be the name of a file in the appropriate
14970Sstevel@tonic-gate * device directory.
14980Sstevel@tonic-gate */
14990Sstevel@tonic-gate static void
search_for_logical_dev(char * devname)15000Sstevel@tonic-gate search_for_logical_dev(char *devname)
15010Sstevel@tonic-gate {
15020Sstevel@tonic-gate char path[MAXPATHLEN];
15030Sstevel@tonic-gate char *directory = "/dev/rdsk/";
15040Sstevel@tonic-gate char *partition = "s2";
15050Sstevel@tonic-gate
15060Sstevel@tonic-gate /*
15070Sstevel@tonic-gate * If the name is an absolute path name, accept it as is
15080Sstevel@tonic-gate */
15090Sstevel@tonic-gate if (*devname == '/') {
15100Sstevel@tonic-gate (void) strcpy(path, devname);
15110Sstevel@tonic-gate } else if (canonical_name(devname)) {
15120Sstevel@tonic-gate /*
15130Sstevel@tonic-gate * If canonical name, construct a standard path name.
15140Sstevel@tonic-gate */
15150Sstevel@tonic-gate (void) strcpy(path, directory);
15160Sstevel@tonic-gate (void) strcat(path, devname);
15170Sstevel@tonic-gate (void) strcat(path, partition);
15180Sstevel@tonic-gate } else if (canonical4x_name(devname)) {
15190Sstevel@tonic-gate /*
15200Sstevel@tonic-gate * Check to see if it's a 4.x file name in the /dev
15210Sstevel@tonic-gate * directory on 5.0. Here, we only accept the
15220Sstevel@tonic-gate * canonicalized form: sd0.
15230Sstevel@tonic-gate */
15240Sstevel@tonic-gate (void) strcpy(path, "/dev/r");
15250Sstevel@tonic-gate (void) strcat(path, devname);
15260Sstevel@tonic-gate (void) strcat(path, "c");
15270Sstevel@tonic-gate } else {
15280Sstevel@tonic-gate /*
15290Sstevel@tonic-gate * If it's not a canonical name, then it may be a
15300Sstevel@tonic-gate * reference to an actual file name in the device
15310Sstevel@tonic-gate * directory itself.
15320Sstevel@tonic-gate */
15330Sstevel@tonic-gate (void) strcpy(path, directory);
15340Sstevel@tonic-gate (void) strcat(path, devname);
15350Sstevel@tonic-gate }
15360Sstevel@tonic-gate
15370Sstevel@tonic-gate /* now add the device */
15380Sstevel@tonic-gate add_device_to_disklist(devname, path);
15390Sstevel@tonic-gate }
15400Sstevel@tonic-gate
1541*12610SShengliang.Zhang@Sun.COM /*
1542*12610SShengliang.Zhang@Sun.COM * Get the disk name from the inquiry data
1543*12610SShengliang.Zhang@Sun.COM */
1544*12610SShengliang.Zhang@Sun.COM static void
get_disk_name(int fd,char * disk_name)1545*12610SShengliang.Zhang@Sun.COM get_disk_name(int fd, char *disk_name)
1546*12610SShengliang.Zhang@Sun.COM {
1547*12610SShengliang.Zhang@Sun.COM struct scsi_inquiry inquiry;
1548*12610SShengliang.Zhang@Sun.COM char *p;
1549*12610SShengliang.Zhang@Sun.COM
1550*12610SShengliang.Zhang@Sun.COM if (uscsi_inquiry(fd, (char *)&inquiry, sizeof (inquiry))) {
1551*12610SShengliang.Zhang@Sun.COM err_print("Failed to inquiry this logical disk");
1552*12610SShengliang.Zhang@Sun.COM return;
1553*12610SShengliang.Zhang@Sun.COM }
1554*12610SShengliang.Zhang@Sun.COM
1555*12610SShengliang.Zhang@Sun.COM p = disk_name;
1556*12610SShengliang.Zhang@Sun.COM (void) memset(p, 0, MAXNAMELEN);
1557*12610SShengliang.Zhang@Sun.COM
1558*12610SShengliang.Zhang@Sun.COM (void) strncpy(p, inquiry.inq_vid, sizeof (inquiry.inq_vid));
1559*12610SShengliang.Zhang@Sun.COM p += sizeof (inquiry.inq_vid) - 1;
1560*12610SShengliang.Zhang@Sun.COM *p++ = '-';
1561*12610SShengliang.Zhang@Sun.COM p = strncpy(p, inquiry.inq_pid, sizeof (inquiry.inq_pid));
1562*12610SShengliang.Zhang@Sun.COM p += sizeof (inquiry.inq_pid) - 1;
1563*12610SShengliang.Zhang@Sun.COM *p++ = '-';
1564*12610SShengliang.Zhang@Sun.COM p = strncpy(p, inquiry.inq_revision, sizeof (inquiry.inq_revision));
1565*12610SShengliang.Zhang@Sun.COM }
15660Sstevel@tonic-gate
15670Sstevel@tonic-gate /*
15680Sstevel@tonic-gate * Add a device to the disk list, if it appears to be a disk,
15690Sstevel@tonic-gate * and we haven't already found it under some other name.
15700Sstevel@tonic-gate */
15710Sstevel@tonic-gate static void
add_device_to_disklist(char * devname,char * devpath)15720Sstevel@tonic-gate add_device_to_disklist(char *devname, char *devpath)
15730Sstevel@tonic-gate {
15740Sstevel@tonic-gate struct disk_info *search_disk;
15750Sstevel@tonic-gate struct ctlr_info *search_ctlr;
15760Sstevel@tonic-gate struct disk_type *search_dtype, *efi_disk;
15770Sstevel@tonic-gate struct partition_info *search_parts;
15780Sstevel@tonic-gate struct disk_info *dptr;
15790Sstevel@tonic-gate struct ctlr_info *cptr;
15800Sstevel@tonic-gate struct disk_type *type;
15810Sstevel@tonic-gate struct partition_info *parts;
15820Sstevel@tonic-gate struct dk_label search_label;
15830Sstevel@tonic-gate struct dk_cinfo dkinfo;
15840Sstevel@tonic-gate struct stat stbuf;
15850Sstevel@tonic-gate struct ctlr_type *ctlr, *tctlr;
15860Sstevel@tonic-gate struct mctlr_list *mlp;
15870Sstevel@tonic-gate struct efi_info efi_info;
1588768Sphitran struct dk_minfo mediainfo;
15890Sstevel@tonic-gate int search_file;
15900Sstevel@tonic-gate int status;
15910Sstevel@tonic-gate int i;
15920Sstevel@tonic-gate int access_flags = 0;
1593*12610SShengliang.Zhang@Sun.COM char disk_name[MAXNAMELEN];
15940Sstevel@tonic-gate
15950Sstevel@tonic-gate /*
15960Sstevel@tonic-gate * Attempt to open the disk. If it fails, skip it.
15970Sstevel@tonic-gate */
15980Sstevel@tonic-gate if ((search_file = open_disk(devpath, O_RDWR | O_NDELAY)) < 0) {
15990Sstevel@tonic-gate return;
16000Sstevel@tonic-gate }
16010Sstevel@tonic-gate /*
16020Sstevel@tonic-gate * Must be a character device
16030Sstevel@tonic-gate */
16040Sstevel@tonic-gate if (fstat(search_file, &stbuf) == -1 || !S_ISCHR(stbuf.st_mode)) {
16050Sstevel@tonic-gate (void) close(search_file);
16060Sstevel@tonic-gate return;
16070Sstevel@tonic-gate }
16080Sstevel@tonic-gate /*
16090Sstevel@tonic-gate * Attempt to read the configuration info on the disk.
16100Sstevel@tonic-gate * Again, if it fails, we assume the disk's not there.
16110Sstevel@tonic-gate * Note we must close the file for the disk before we
16120Sstevel@tonic-gate * continue.
16130Sstevel@tonic-gate */
16140Sstevel@tonic-gate if (ioctl(search_file, DKIOCINFO, &dkinfo) < 0) {
16150Sstevel@tonic-gate (void) close(search_file);
16160Sstevel@tonic-gate return;
16170Sstevel@tonic-gate }
16180Sstevel@tonic-gate
16190Sstevel@tonic-gate /* If it is a removable media, skip it. */
16200Sstevel@tonic-gate
16210Sstevel@tonic-gate if (!expert_mode) {
16220Sstevel@tonic-gate int isremovable, ret;
16230Sstevel@tonic-gate ret = ioctl(search_file, DKIOCREMOVABLE, &isremovable);
16240Sstevel@tonic-gate if ((ret >= 0) && (isremovable != 0)) {
16250Sstevel@tonic-gate (void) close(search_file);
16260Sstevel@tonic-gate return;
16270Sstevel@tonic-gate }
16280Sstevel@tonic-gate }
16290Sstevel@tonic-gate
16309889SLarry.Liu@Sun.COM if (ioctl(search_file, DKIOCGMEDIAINFO, &mediainfo) == -1) {
16319889SLarry.Liu@Sun.COM cur_blksz = DEV_BSIZE;
16329889SLarry.Liu@Sun.COM } else {
16339889SLarry.Liu@Sun.COM cur_blksz = mediainfo.dki_lbsize;
16349889SLarry.Liu@Sun.COM }
16359889SLarry.Liu@Sun.COM
16360Sstevel@tonic-gate /*
16370Sstevel@tonic-gate * If the type of disk is one we don't know about,
16380Sstevel@tonic-gate * add it to the list.
16390Sstevel@tonic-gate */
16400Sstevel@tonic-gate mlp = controlp;
16410Sstevel@tonic-gate
16420Sstevel@tonic-gate while (mlp != NULL) {
1643*12610SShengliang.Zhang@Sun.COM if (mlp->ctlr_type->ctype_ctype == dkinfo.dki_ctype) {
16440Sstevel@tonic-gate break;
16450Sstevel@tonic-gate }
16460Sstevel@tonic-gate mlp = mlp->next;
16470Sstevel@tonic-gate }
16480Sstevel@tonic-gate
16490Sstevel@tonic-gate if (mlp == NULL) {
1650768Sphitran if (dkinfo.dki_ctype == DKC_CDROM) {
1651768Sphitran if (ioctl(search_file, DKIOCGMEDIAINFO,
1652768Sphitran &mediainfo) < 0) {
1653768Sphitran mediainfo.dki_media_type = DK_UNKNOWN;
1654768Sphitran }
1655768Sphitran }
16560Sstevel@tonic-gate /*
16570Sstevel@tonic-gate * Skip CDROM devices, they are read only.
1658768Sphitran * But not devices like Iomega Rev Drive which
1659768Sphitran * identifies itself as a CDROM, but has a removable
1660768Sphitran * disk.
16610Sstevel@tonic-gate */
166211215Sgdamore@opensolaris.org if ((dkinfo.dki_ctype == DKC_CDROM) &&
166311215Sgdamore@opensolaris.org (mediainfo.dki_media_type != DK_REMOVABLE_DISK)) {
16640Sstevel@tonic-gate (void) close(search_file);
16650Sstevel@tonic-gate return;
16660Sstevel@tonic-gate }
16670Sstevel@tonic-gate /*
16680Sstevel@tonic-gate * create the new ctlr_type structure and fill it in.
16690Sstevel@tonic-gate */
16700Sstevel@tonic-gate tctlr = zalloc(sizeof (struct ctlr_type));
16710Sstevel@tonic-gate tctlr->ctype_ctype = dkinfo.dki_ctype;
16720Sstevel@tonic-gate tctlr->ctype_name = zalloc(DK_DEVLEN);
16730Sstevel@tonic-gate if (strlcpy(tctlr->ctype_name, dkinfo.dki_cname,
16745084Sjohnlev DK_DEVLEN) > DK_DEVLEN) {
16750Sstevel@tonic-gate /*
16760Sstevel@tonic-gate * DKIOCINFO returned a controller name longer
16770Sstevel@tonic-gate * than DK_DEVLEN bytes, which means more of the
16780Sstevel@tonic-gate * dk_cinfo structure may be corrupt. We don't
16790Sstevel@tonic-gate * allow the user to perform any operations on
16800Sstevel@tonic-gate * the device in this case
16810Sstevel@tonic-gate */
16820Sstevel@tonic-gate err_print("\nError: Device %s: controller "
16830Sstevel@tonic-gate "name (%s)\nis invalid. Device will not "
16840Sstevel@tonic-gate "be displayed.\n", devname, dkinfo.dki_cname);
16850Sstevel@tonic-gate (void) close(search_file);
16860Sstevel@tonic-gate destroy_data(tctlr->ctype_name);
16870Sstevel@tonic-gate destroy_data((char *)tctlr);
16880Sstevel@tonic-gate return;
16890Sstevel@tonic-gate } else {
16900Sstevel@tonic-gate tctlr->ctype_ops = zalloc(sizeof (struct ctlr_ops));
16910Sstevel@tonic-gate
16920Sstevel@tonic-gate /*
16930Sstevel@tonic-gate * copy the generic disk ops structure into local copy.
16940Sstevel@tonic-gate */
16950Sstevel@tonic-gate *(tctlr->ctype_ops) = genericops;
16960Sstevel@tonic-gate
16970Sstevel@tonic-gate tctlr->ctype_flags = CF_WLIST;
16980Sstevel@tonic-gate
16990Sstevel@tonic-gate mlp = controlp;
17000Sstevel@tonic-gate
17010Sstevel@tonic-gate while (mlp->next != NULL) {
17020Sstevel@tonic-gate mlp = mlp->next;
17030Sstevel@tonic-gate }
17040Sstevel@tonic-gate
17050Sstevel@tonic-gate mlp->next = zalloc(sizeof (struct mctlr_list));
17060Sstevel@tonic-gate mlp->next->ctlr_type = tctlr;
17070Sstevel@tonic-gate }
17080Sstevel@tonic-gate }
17090Sstevel@tonic-gate
17100Sstevel@tonic-gate /*
17110Sstevel@tonic-gate * Search through all disks known at this time, to
17120Sstevel@tonic-gate * determine if we're already identified this disk.
17130Sstevel@tonic-gate * If so, then there's no need to include it a
17140Sstevel@tonic-gate * second time. This permits the user-defined names
17150Sstevel@tonic-gate * to supercede the standard conventional names.
17160Sstevel@tonic-gate */
17170Sstevel@tonic-gate if (disk_is_known(&dkinfo)) {
17180Sstevel@tonic-gate (void) close(search_file);
17190Sstevel@tonic-gate return;
17200Sstevel@tonic-gate }
17210Sstevel@tonic-gate #if defined(sparc)
17220Sstevel@tonic-gate /*
17230Sstevel@tonic-gate * Because opening id with FNDELAY always succeeds,
17240Sstevel@tonic-gate * read the label early on to see whether the device
17250Sstevel@tonic-gate * really exists. A result of DSK_RESERVED
17260Sstevel@tonic-gate * means the disk may be reserved.
17270Sstevel@tonic-gate * In the future, it will be good
17280Sstevel@tonic-gate * to move these into controller specific files and have a common
17290Sstevel@tonic-gate * generic check for reserved disks here, including intel disks.
17300Sstevel@tonic-gate */
17310Sstevel@tonic-gate if (dkinfo.dki_ctype == DKC_SCSI_CCS) {
17329889SLarry.Liu@Sun.COM char *first_sector;
17339889SLarry.Liu@Sun.COM
17349889SLarry.Liu@Sun.COM first_sector = zalloc(cur_blksz);
17357563SPrasad.Singamsetty@Sun.COM i = scsi_rdwr(DIR_READ, search_file, (diskaddr_t)0,
17369889SLarry.Liu@Sun.COM 1, first_sector, F_SILENT, NULL);
17370Sstevel@tonic-gate switch (i) {
17380Sstevel@tonic-gate case DSK_RESERVED:
17390Sstevel@tonic-gate access_flags |= DSK_RESERVED;
17400Sstevel@tonic-gate break;
17410Sstevel@tonic-gate case DSK_UNAVAILABLE:
17420Sstevel@tonic-gate access_flags |= DSK_UNAVAILABLE;
17430Sstevel@tonic-gate break;
17440Sstevel@tonic-gate default:
17450Sstevel@tonic-gate break;
17460Sstevel@tonic-gate }
17479889SLarry.Liu@Sun.COM free(first_sector);
17480Sstevel@tonic-gate }
17490Sstevel@tonic-gate #endif /* defined(sparc) */
17500Sstevel@tonic-gate
17510Sstevel@tonic-gate /*
17520Sstevel@tonic-gate * The disk appears to be present. Allocate space for the
17530Sstevel@tonic-gate * disk structure and add it to the list of found disks.
17540Sstevel@tonic-gate */
17550Sstevel@tonic-gate search_disk = (struct disk_info *)zalloc(sizeof (struct disk_info));
17560Sstevel@tonic-gate if (disk_list == NULL)
17570Sstevel@tonic-gate disk_list = search_disk;
17580Sstevel@tonic-gate else {
17590Sstevel@tonic-gate for (dptr = disk_list; dptr->disk_next != NULL;
17600Sstevel@tonic-gate dptr = dptr->disk_next)
17610Sstevel@tonic-gate ;
17620Sstevel@tonic-gate dptr->disk_next = search_disk;
17630Sstevel@tonic-gate }
17640Sstevel@tonic-gate /*
17650Sstevel@tonic-gate * Fill in some info from the ioctls.
17660Sstevel@tonic-gate */
17670Sstevel@tonic-gate search_disk->disk_dkinfo = dkinfo;
17680Sstevel@tonic-gate if (is_efi_type(search_file)) {
17690Sstevel@tonic-gate search_disk->label_type = L_TYPE_EFI;
17700Sstevel@tonic-gate } else {
17710Sstevel@tonic-gate search_disk->label_type = L_TYPE_SOLARIS;
17720Sstevel@tonic-gate }
17730Sstevel@tonic-gate /*
17740Sstevel@tonic-gate * Remember the names of the disk
17750Sstevel@tonic-gate */
17760Sstevel@tonic-gate search_disk->disk_name = alloc_string(devname);
17770Sstevel@tonic-gate search_disk->disk_path = alloc_string(devpath);
17780Sstevel@tonic-gate
17799889SLarry.Liu@Sun.COM /*
17809889SLarry.Liu@Sun.COM * Remember the lba size of the disk
17819889SLarry.Liu@Sun.COM */
17829889SLarry.Liu@Sun.COM search_disk->disk_lbasize = cur_blksz;
17839889SLarry.Liu@Sun.COM
17840Sstevel@tonic-gate (void) strcpy(x86_devname, devname);
17850Sstevel@tonic-gate
17860Sstevel@tonic-gate /*
17870Sstevel@tonic-gate * Determine if this device is linked to a physical name.
17880Sstevel@tonic-gate */
17890Sstevel@tonic-gate search_disk->devfs_name = get_physical_name(devpath);
17900Sstevel@tonic-gate
17910Sstevel@tonic-gate /*
17920Sstevel@tonic-gate * Try to match the ctlr for this disk with a ctlr we
17930Sstevel@tonic-gate * have already found. A match is assumed if the ctlrs
17940Sstevel@tonic-gate * are at the same address && ctypes agree
17950Sstevel@tonic-gate */
17960Sstevel@tonic-gate for (search_ctlr = ctlr_list; search_ctlr != NULL;
17970Sstevel@tonic-gate search_ctlr = search_ctlr->ctlr_next)
17980Sstevel@tonic-gate if (search_ctlr->ctlr_addr == dkinfo.dki_addr &&
17990Sstevel@tonic-gate search_ctlr->ctlr_space == dkinfo.dki_space &&
18005084Sjohnlev search_ctlr->ctlr_ctype->ctype_ctype ==
18015084Sjohnlev dkinfo.dki_ctype)
18020Sstevel@tonic-gate break;
18030Sstevel@tonic-gate /*
18040Sstevel@tonic-gate * If no match was found, we need to identify this ctlr.
18050Sstevel@tonic-gate */
18060Sstevel@tonic-gate if (search_ctlr == NULL) {
18070Sstevel@tonic-gate /*
18080Sstevel@tonic-gate * Match the type of the ctlr to a known type.
18090Sstevel@tonic-gate */
18100Sstevel@tonic-gate mlp = controlp;
18110Sstevel@tonic-gate
18120Sstevel@tonic-gate while (mlp != NULL) {
18130Sstevel@tonic-gate if (mlp->ctlr_type->ctype_ctype == dkinfo.dki_ctype)
18140Sstevel@tonic-gate break;
18150Sstevel@tonic-gate mlp = mlp->next;
18160Sstevel@tonic-gate }
18170Sstevel@tonic-gate /*
18180Sstevel@tonic-gate * If no match was found, it's an error.
18190Sstevel@tonic-gate * Close the disk and report the error.
18200Sstevel@tonic-gate */
18210Sstevel@tonic-gate if (mlp == NULL) {
18220Sstevel@tonic-gate err_print("\nError: found disk attached to ");
18230Sstevel@tonic-gate err_print("unsupported controller type '%d'.\n",
18240Sstevel@tonic-gate dkinfo.dki_ctype);
18250Sstevel@tonic-gate (void) close(search_file);
18260Sstevel@tonic-gate return;
18270Sstevel@tonic-gate }
18280Sstevel@tonic-gate /*
18290Sstevel@tonic-gate * Allocate space for the ctlr structure and add it
18300Sstevel@tonic-gate * to the list of found ctlrs.
18310Sstevel@tonic-gate */
18320Sstevel@tonic-gate search_ctlr = (struct ctlr_info *)
18335084Sjohnlev zalloc(sizeof (struct ctlr_info));
18340Sstevel@tonic-gate search_ctlr->ctlr_ctype = mlp->ctlr_type;
18350Sstevel@tonic-gate if (ctlr_list == NULL)
18360Sstevel@tonic-gate ctlr_list = search_ctlr;
18370Sstevel@tonic-gate else {
18380Sstevel@tonic-gate for (cptr = ctlr_list; cptr->ctlr_next != NULL;
18390Sstevel@tonic-gate cptr = cptr->ctlr_next)
18400Sstevel@tonic-gate ;
18410Sstevel@tonic-gate cptr->ctlr_next = search_ctlr;
18420Sstevel@tonic-gate }
18430Sstevel@tonic-gate /*
18440Sstevel@tonic-gate * Fill in info from the ioctl.
18450Sstevel@tonic-gate */
18460Sstevel@tonic-gate for (i = 0; i < DK_DEVLEN; i++) {
18470Sstevel@tonic-gate search_ctlr->ctlr_cname[i] = dkinfo.dki_cname[i];
18480Sstevel@tonic-gate search_ctlr->ctlr_dname[i] = dkinfo.dki_dname[i];
18490Sstevel@tonic-gate }
18500Sstevel@tonic-gate /*
18510Sstevel@tonic-gate * Make sure these can be used as simple strings
18520Sstevel@tonic-gate */
18530Sstevel@tonic-gate search_ctlr->ctlr_cname[i] = 0;
18540Sstevel@tonic-gate search_ctlr->ctlr_dname[i] = 0;
18550Sstevel@tonic-gate
18560Sstevel@tonic-gate search_ctlr->ctlr_flags = dkinfo.dki_flags;
18570Sstevel@tonic-gate search_ctlr->ctlr_num = dkinfo.dki_cnum;
18580Sstevel@tonic-gate search_ctlr->ctlr_addr = dkinfo.dki_addr;
18590Sstevel@tonic-gate search_ctlr->ctlr_space = dkinfo.dki_space;
18600Sstevel@tonic-gate search_ctlr->ctlr_prio = dkinfo.dki_prio;
18610Sstevel@tonic-gate search_ctlr->ctlr_vec = dkinfo.dki_vec;
18620Sstevel@tonic-gate }
18630Sstevel@tonic-gate /*
18640Sstevel@tonic-gate * By this point, we have a known ctlr. Link the disk
18650Sstevel@tonic-gate * to the ctlr.
18660Sstevel@tonic-gate */
18670Sstevel@tonic-gate search_disk->disk_ctlr = search_ctlr;
18680Sstevel@tonic-gate if (access_flags & (DSK_RESERVED | DSK_UNAVAILABLE)) {
18690Sstevel@tonic-gate if (access_flags & DSK_RESERVED)
18700Sstevel@tonic-gate search_disk->disk_flags |= DSK_RESERVED;
18710Sstevel@tonic-gate else
18720Sstevel@tonic-gate search_disk->disk_flags |= DSK_UNAVAILABLE;
18730Sstevel@tonic-gate (void) close(search_file);
18740Sstevel@tonic-gate return;
18750Sstevel@tonic-gate } else {
18760Sstevel@tonic-gate search_disk->disk_flags &= ~(DSK_RESERVED | DSK_UNAVAILABLE);
18770Sstevel@tonic-gate }
18780Sstevel@tonic-gate
18790Sstevel@tonic-gate /*
18800Sstevel@tonic-gate * Attempt to read the primary label.
18810Sstevel@tonic-gate * (Note that this is really through the DKIOCGVTOC
18820Sstevel@tonic-gate * ioctl, then converted from vtoc to label.)
18830Sstevel@tonic-gate */
18840Sstevel@tonic-gate if (search_disk->label_type == L_TYPE_SOLARIS) {
18850Sstevel@tonic-gate status = read_label(search_file, &search_label);
18860Sstevel@tonic-gate } else {
18870Sstevel@tonic-gate status = read_efi_label(search_file, &efi_info);
18880Sstevel@tonic-gate }
18890Sstevel@tonic-gate /*
18900Sstevel@tonic-gate * If reading the label failed, and this is a SCSI
18910Sstevel@tonic-gate * disk, we can attempt to auto-sense the disk
18927563SPrasad.Singamsetty@Sun.COM * Configuration.
18930Sstevel@tonic-gate */
18940Sstevel@tonic-gate ctlr = search_ctlr->ctlr_ctype;
18950Sstevel@tonic-gate if ((status == -1) && (ctlr->ctype_ctype == DKC_SCSI_CCS)) {
18965084Sjohnlev if (option_msg && diag_msg) {
18975084Sjohnlev err_print("%s: attempting auto configuration\n",
18985084Sjohnlev search_disk->disk_name);
18990Sstevel@tonic-gate }
19005084Sjohnlev
19015084Sjohnlev switch (search_disk->label_type) {
19025084Sjohnlev case (L_TYPE_SOLARIS):
19035084Sjohnlev if (auto_sense(search_file, 0, &search_label) != NULL) {
19045084Sjohnlev /*
19055084Sjohnlev * Auto config worked, so we now have
19065084Sjohnlev * a valid label for the disk. Mark
19075084Sjohnlev * the disk as needing the label flushed.
19085084Sjohnlev */
19095084Sjohnlev status = 0;
19105084Sjohnlev search_disk->disk_flags |=
19115084Sjohnlev (DSK_LABEL_DIRTY | DSK_AUTO_CONFIG);
19125084Sjohnlev }
19135084Sjohnlev break;
19145084Sjohnlev case (L_TYPE_EFI):
19155084Sjohnlev efi_disk = auto_efi_sense(search_file, &efi_info);
19165084Sjohnlev if (efi_disk != NULL) {
19175084Sjohnlev /*
19185084Sjohnlev * Auto config worked, so we now have
19195084Sjohnlev * a valid label for the disk.
19205084Sjohnlev */
19215084Sjohnlev status = 0;
19225084Sjohnlev search_disk->disk_flags |=
19235084Sjohnlev (DSK_LABEL_DIRTY | DSK_AUTO_CONFIG);
19245084Sjohnlev }
19255084Sjohnlev break;
19265084Sjohnlev default:
19275084Sjohnlev /* Should never happen */
19285084Sjohnlev break;
19290Sstevel@tonic-gate }
19300Sstevel@tonic-gate }
1931*12610SShengliang.Zhang@Sun.COM
19320Sstevel@tonic-gate /*
19330Sstevel@tonic-gate * If we didn't successfully read the label, or the label
19340Sstevel@tonic-gate * appears corrupt, just leave the disk as an unknown type.
19350Sstevel@tonic-gate */
19360Sstevel@tonic-gate if (status == -1) {
1937*12610SShengliang.Zhang@Sun.COM (void) close(search_file);
19380Sstevel@tonic-gate return;
19390Sstevel@tonic-gate }
19400Sstevel@tonic-gate
19410Sstevel@tonic-gate if (search_disk->label_type == L_TYPE_SOLARIS) {
19420Sstevel@tonic-gate if (!checklabel(&search_label)) {
1943*12610SShengliang.Zhang@Sun.COM (void) close(search_file);
19440Sstevel@tonic-gate return;
19450Sstevel@tonic-gate }
19460Sstevel@tonic-gate if (trim_id(search_label.dkl_asciilabel)) {
1947*12610SShengliang.Zhang@Sun.COM (void) close(search_file);
19480Sstevel@tonic-gate return;
19490Sstevel@tonic-gate }
19500Sstevel@tonic-gate }
19510Sstevel@tonic-gate /*
19520Sstevel@tonic-gate * The label looks ok. Mark the disk as labeled.
19530Sstevel@tonic-gate */
19540Sstevel@tonic-gate search_disk->disk_flags |= DSK_LABEL;
19550Sstevel@tonic-gate
19560Sstevel@tonic-gate if (search_disk->label_type == L_TYPE_EFI) {
19570Sstevel@tonic-gate search_dtype = (struct disk_type *)
19580Sstevel@tonic-gate zalloc(sizeof (struct disk_type));
19590Sstevel@tonic-gate type = search_ctlr->ctlr_ctype->ctype_dlist;
19600Sstevel@tonic-gate if (type == NULL) {
19610Sstevel@tonic-gate search_ctlr->ctlr_ctype->ctype_dlist =
19620Sstevel@tonic-gate search_dtype;
19630Sstevel@tonic-gate } else {
19640Sstevel@tonic-gate while (type->dtype_next != NULL) {
19650Sstevel@tonic-gate type = type->dtype_next;
19660Sstevel@tonic-gate }
19670Sstevel@tonic-gate type->dtype_next = search_dtype;
19680Sstevel@tonic-gate }
19691524Slh195018 search_dtype->dtype_next = NULL;
19700Sstevel@tonic-gate
19710Sstevel@tonic-gate (void) strlcpy(search_dtype->vendor, efi_info.vendor, 9);
19720Sstevel@tonic-gate (void) strlcpy(search_dtype->product, efi_info.product, 17);
19730Sstevel@tonic-gate (void) strlcpy(search_dtype->revision, efi_info.revision, 5);
19740Sstevel@tonic-gate search_dtype->capacity = efi_info.capacity;
19750Sstevel@tonic-gate search_disk->disk_type = search_dtype;
19760Sstevel@tonic-gate
19770Sstevel@tonic-gate search_parts = (struct partition_info *)
19780Sstevel@tonic-gate zalloc(sizeof (struct partition_info));
19790Sstevel@tonic-gate search_dtype->dtype_plist = search_parts;
19800Sstevel@tonic-gate
19810Sstevel@tonic-gate search_parts->pinfo_name = alloc_string("original");
19820Sstevel@tonic-gate search_parts->pinfo_next = NULL;
19830Sstevel@tonic-gate search_parts->etoc = efi_info.e_parts;
19840Sstevel@tonic-gate search_disk->disk_parts = search_parts;
19850Sstevel@tonic-gate
19860Sstevel@tonic-gate /*
19870Sstevel@tonic-gate * Copy the volume name, if present
19880Sstevel@tonic-gate */
19890Sstevel@tonic-gate for (i = 0; i < search_parts->etoc->efi_nparts; i++) {
19905084Sjohnlev if (search_parts->etoc->efi_parts[i].p_tag ==
19915084Sjohnlev V_RESERVED) {
19925084Sjohnlev if (search_parts->etoc->efi_parts[i].p_name) {
19935084Sjohnlev bcopy(search_parts->etoc->efi_parts[i]
19945084Sjohnlev .p_name, search_disk->v_volume,
19955084Sjohnlev LEN_DKL_VVOL);
19965084Sjohnlev } else {
19975084Sjohnlev bzero(search_disk->v_volume,
19985084Sjohnlev LEN_DKL_VVOL);
19995084Sjohnlev }
20005084Sjohnlev break;
20015084Sjohnlev }
20020Sstevel@tonic-gate }
2003*12610SShengliang.Zhang@Sun.COM (void) close(search_file);
20040Sstevel@tonic-gate return;
20050Sstevel@tonic-gate }
20060Sstevel@tonic-gate
20070Sstevel@tonic-gate /*
20080Sstevel@tonic-gate * Attempt to match the disk type in the label with a
20090Sstevel@tonic-gate * known disk type.
20100Sstevel@tonic-gate */
20110Sstevel@tonic-gate for (search_dtype = search_ctlr->ctlr_ctype->ctype_dlist;
20120Sstevel@tonic-gate search_dtype != NULL;
20130Sstevel@tonic-gate search_dtype = search_dtype->dtype_next)
20140Sstevel@tonic-gate if (dtype_match(&search_label, search_dtype))
20150Sstevel@tonic-gate break;
20160Sstevel@tonic-gate /*
20170Sstevel@tonic-gate * If no match was found, we need to create a disk type
20180Sstevel@tonic-gate * for this disk.
20190Sstevel@tonic-gate */
20200Sstevel@tonic-gate if (search_dtype == NULL) {
20210Sstevel@tonic-gate /*
20220Sstevel@tonic-gate * Allocate space for the disk type and add it
20230Sstevel@tonic-gate * to the list of disk types for this ctlr type.
20240Sstevel@tonic-gate */
20250Sstevel@tonic-gate search_dtype = (struct disk_type *)
20260Sstevel@tonic-gate zalloc(sizeof (struct disk_type));
20270Sstevel@tonic-gate type = search_ctlr->ctlr_ctype->ctype_dlist;
20280Sstevel@tonic-gate if (type == NULL)
20290Sstevel@tonic-gate search_ctlr->ctlr_ctype->ctype_dlist =
20300Sstevel@tonic-gate search_dtype;
20310Sstevel@tonic-gate else {
20320Sstevel@tonic-gate while (type->dtype_next != NULL)
20330Sstevel@tonic-gate type = type->dtype_next;
20340Sstevel@tonic-gate type->dtype_next = search_dtype;
20350Sstevel@tonic-gate }
20360Sstevel@tonic-gate /*
20370Sstevel@tonic-gate * Fill in the drive info from the disk label.
20380Sstevel@tonic-gate */
20390Sstevel@tonic-gate search_dtype->dtype_next = NULL;
2040*12610SShengliang.Zhang@Sun.COM if (strncmp(search_label.dkl_asciilabel, "DEFAULT",
2041*12610SShengliang.Zhang@Sun.COM strlen("DEFAULT")) == 0) {
2042*12610SShengliang.Zhang@Sun.COM (void) get_disk_name(search_file, disk_name);
2043*12610SShengliang.Zhang@Sun.COM search_dtype->dtype_asciilabel = (char *)
2044*12610SShengliang.Zhang@Sun.COM zalloc(strlen(disk_name) + 1);
2045*12610SShengliang.Zhang@Sun.COM (void) strcpy(search_dtype->dtype_asciilabel,
2046*12610SShengliang.Zhang@Sun.COM disk_name);
2047*12610SShengliang.Zhang@Sun.COM } else {
2048*12610SShengliang.Zhang@Sun.COM search_dtype->dtype_asciilabel = (char *)
2049*12610SShengliang.Zhang@Sun.COM zalloc(strlen(search_label.dkl_asciilabel) + 1);
2050*12610SShengliang.Zhang@Sun.COM (void) strcpy(search_dtype->dtype_asciilabel,
2051*12610SShengliang.Zhang@Sun.COM search_label.dkl_asciilabel);
2052*12610SShengliang.Zhang@Sun.COM }
20530Sstevel@tonic-gate search_dtype->dtype_pcyl = search_label.dkl_pcyl;
20540Sstevel@tonic-gate search_dtype->dtype_ncyl = search_label.dkl_ncyl;
20550Sstevel@tonic-gate search_dtype->dtype_acyl = search_label.dkl_acyl;
20560Sstevel@tonic-gate search_dtype->dtype_nhead = search_label.dkl_nhead;
20570Sstevel@tonic-gate search_dtype->dtype_nsect = search_label.dkl_nsect;
20580Sstevel@tonic-gate search_dtype->dtype_rpm = search_label.dkl_rpm;
20590Sstevel@tonic-gate /*
20600Sstevel@tonic-gate * Mark the disk as needing specification of
20610Sstevel@tonic-gate * ctlr specific attributes. This is necessary
20620Sstevel@tonic-gate * because the label doesn't contain these attributes,
20630Sstevel@tonic-gate * and they aren't known at this point. They will
20640Sstevel@tonic-gate * be asked for if this disk is ever selected by
20650Sstevel@tonic-gate * the user.
20660Sstevel@tonic-gate * Note: for SCSI, we believe the label.
20670Sstevel@tonic-gate */
20680Sstevel@tonic-gate if ((search_ctlr->ctlr_ctype->ctype_ctype != DKC_SCSI_CCS) &&
20690Sstevel@tonic-gate (search_ctlr->ctlr_ctype->ctype_ctype != DKC_DIRECT) &&
20705084Sjohnlev (search_ctlr->ctlr_ctype->ctype_ctype != DKC_VBD) &&
20710Sstevel@tonic-gate (search_ctlr->ctlr_ctype->ctype_ctype != DKC_PCMCIA_ATA)) {
20720Sstevel@tonic-gate search_dtype->dtype_flags |= DT_NEED_SPEFS;
20730Sstevel@tonic-gate }
20740Sstevel@tonic-gate }
20750Sstevel@tonic-gate /*
20760Sstevel@tonic-gate * By this time we have a known disk type. Link the disk
20770Sstevel@tonic-gate * to the disk type.
20780Sstevel@tonic-gate */
20790Sstevel@tonic-gate search_disk->disk_type = search_dtype;
2080*12610SShengliang.Zhang@Sun.COM
2081*12610SShengliang.Zhang@Sun.COM /*
2082*12610SShengliang.Zhang@Sun.COM * Close the file for this disk
2083*12610SShengliang.Zhang@Sun.COM */
2084*12610SShengliang.Zhang@Sun.COM (void) close(search_file);
2085*12610SShengliang.Zhang@Sun.COM
20860Sstevel@tonic-gate /*
20870Sstevel@tonic-gate * Attempt to match the partition map in the label with
20880Sstevel@tonic-gate * a known partition map for this disk type.
20890Sstevel@tonic-gate */
20900Sstevel@tonic-gate for (search_parts = search_dtype->dtype_plist;
20910Sstevel@tonic-gate search_parts != NULL;
20920Sstevel@tonic-gate search_parts = search_parts->pinfo_next)
20930Sstevel@tonic-gate if (parts_match(&search_label, search_parts)) {
20940Sstevel@tonic-gate break;
20950Sstevel@tonic-gate }
20960Sstevel@tonic-gate /*
20970Sstevel@tonic-gate * If no match was made, we need to create a partition
20980Sstevel@tonic-gate * map for this disk.
20990Sstevel@tonic-gate */
21000Sstevel@tonic-gate if (search_parts == NULL) {
21010Sstevel@tonic-gate /*
21020Sstevel@tonic-gate * Allocate space for the partition map and add
21030Sstevel@tonic-gate * it to the list of maps for this disk type.
21040Sstevel@tonic-gate */
21050Sstevel@tonic-gate search_parts = (struct partition_info *)
21060Sstevel@tonic-gate zalloc(sizeof (struct partition_info));
21070Sstevel@tonic-gate parts = search_dtype->dtype_plist;
21080Sstevel@tonic-gate if (parts == NULL)
21090Sstevel@tonic-gate search_dtype->dtype_plist = search_parts;
21100Sstevel@tonic-gate else {
21110Sstevel@tonic-gate while (parts->pinfo_next != NULL)
21120Sstevel@tonic-gate parts = parts->pinfo_next;
21130Sstevel@tonic-gate parts->pinfo_next = search_parts;
21140Sstevel@tonic-gate }
21150Sstevel@tonic-gate search_parts->pinfo_next = NULL;
21160Sstevel@tonic-gate /*
21170Sstevel@tonic-gate * Fill in the name of the map with a name derived
21180Sstevel@tonic-gate * from the name of this disk. This is necessary
21190Sstevel@tonic-gate * because the label contains no name for the
21200Sstevel@tonic-gate * partition map.
21210Sstevel@tonic-gate */
21220Sstevel@tonic-gate search_parts->pinfo_name = alloc_string("original");
21230Sstevel@tonic-gate /*
21240Sstevel@tonic-gate * Fill in the partition info from the disk label.
21250Sstevel@tonic-gate */
21260Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++) {
21270Sstevel@tonic-gate
21280Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
21290Sstevel@tonic-gate search_parts->pinfo_map[i] =
21300Sstevel@tonic-gate search_label.dkl_map[i];
21310Sstevel@tonic-gate
21320Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
21330Sstevel@tonic-gate search_parts->pinfo_map[i].dkl_cylno =
21340Sstevel@tonic-gate search_label.dkl_vtoc.v_part[i].p_start /
21357563SPrasad.Singamsetty@Sun.COM ((blkaddr32_t)(search_label.dkl_nhead *
21360Sstevel@tonic-gate search_label.dkl_nsect));
21370Sstevel@tonic-gate search_parts->pinfo_map[i].dkl_nblk =
21380Sstevel@tonic-gate search_label.dkl_vtoc.v_part[i].p_size;
21390Sstevel@tonic-gate
21400Sstevel@tonic-gate #else
21410Sstevel@tonic-gate #error No VTOC format defined.
21420Sstevel@tonic-gate #endif
21430Sstevel@tonic-gate }
21440Sstevel@tonic-gate }
21450Sstevel@tonic-gate /*
21460Sstevel@tonic-gate * If the vtoc looks valid, copy the volume name and vtoc
21470Sstevel@tonic-gate * info from the label. Otherwise, install a default vtoc.
21480Sstevel@tonic-gate * This permits vtoc info to automatically appear in the sun
21490Sstevel@tonic-gate * label, without requiring an upgrade procedure.
21500Sstevel@tonic-gate */
21510Sstevel@tonic-gate if (search_label.dkl_vtoc.v_version == V_VERSION) {
21520Sstevel@tonic-gate bcopy(search_label.dkl_vtoc.v_volume,
21535084Sjohnlev search_disk->v_volume, LEN_DKL_VVOL);
21540Sstevel@tonic-gate search_parts->vtoc = search_label.dkl_vtoc;
21550Sstevel@tonic-gate } else {
21560Sstevel@tonic-gate bzero(search_disk->v_volume, LEN_DKL_VVOL);
21570Sstevel@tonic-gate set_vtoc_defaults(search_parts);
21580Sstevel@tonic-gate }
21590Sstevel@tonic-gate /*
21600Sstevel@tonic-gate * By this time we have a known partitition map. Link the
21610Sstevel@tonic-gate * disk to the partition map.
21620Sstevel@tonic-gate */
21630Sstevel@tonic-gate search_disk->disk_parts = search_parts;
21640Sstevel@tonic-gate }
21650Sstevel@tonic-gate
21660Sstevel@tonic-gate
21670Sstevel@tonic-gate /*
21680Sstevel@tonic-gate * Search the disk list for a disk with the identical configuration.
21690Sstevel@tonic-gate * Return true if one is found.
21700Sstevel@tonic-gate */
21710Sstevel@tonic-gate static int
disk_is_known(struct dk_cinfo * dkinfo)21720Sstevel@tonic-gate disk_is_known(struct dk_cinfo *dkinfo)
21730Sstevel@tonic-gate {
21740Sstevel@tonic-gate struct disk_info *dp;
21750Sstevel@tonic-gate
21760Sstevel@tonic-gate dp = disk_list;
21770Sstevel@tonic-gate while (dp != NULL) {
21780Sstevel@tonic-gate if (dp->disk_dkinfo.dki_ctype == dkinfo->dki_ctype &&
21795084Sjohnlev dp->disk_dkinfo.dki_cnum == dkinfo->dki_cnum &&
21805084Sjohnlev dp->disk_dkinfo.dki_unit == dkinfo->dki_unit &&
21815084Sjohnlev strcmp(dp->disk_dkinfo.dki_dname, dkinfo->dki_dname) == 0) {
21820Sstevel@tonic-gate return (1);
21830Sstevel@tonic-gate }
21840Sstevel@tonic-gate dp = dp->disk_next;
21850Sstevel@tonic-gate }
21860Sstevel@tonic-gate return (0);
21870Sstevel@tonic-gate }
21880Sstevel@tonic-gate
21890Sstevel@tonic-gate
21900Sstevel@tonic-gate /*
21910Sstevel@tonic-gate * This routine checks to see if a given disk type matches the type
21920Sstevel@tonic-gate * in the disk label.
21930Sstevel@tonic-gate */
21940Sstevel@tonic-gate int
dtype_match(label,dtype)21950Sstevel@tonic-gate dtype_match(label, dtype)
21960Sstevel@tonic-gate register struct dk_label *label;
21970Sstevel@tonic-gate register struct disk_type *dtype;
21980Sstevel@tonic-gate {
21990Sstevel@tonic-gate
22000Sstevel@tonic-gate if (dtype->dtype_asciilabel == NULL) {
22010Sstevel@tonic-gate return (0);
22020Sstevel@tonic-gate }
22030Sstevel@tonic-gate
22040Sstevel@tonic-gate /*
22050Sstevel@tonic-gate * If the any of the physical characteristics are different, or
22060Sstevel@tonic-gate * the name is different, it doesn't match.
22070Sstevel@tonic-gate */
22080Sstevel@tonic-gate if ((strcmp(label->dkl_asciilabel, dtype->dtype_asciilabel) != 0) ||
22090Sstevel@tonic-gate (label->dkl_ncyl != dtype->dtype_ncyl) ||
22100Sstevel@tonic-gate (label->dkl_acyl != dtype->dtype_acyl) ||
22110Sstevel@tonic-gate (label->dkl_nhead != dtype->dtype_nhead) ||
22120Sstevel@tonic-gate (label->dkl_nsect != dtype->dtype_nsect)) {
22130Sstevel@tonic-gate return (0);
22140Sstevel@tonic-gate }
22150Sstevel@tonic-gate /*
22160Sstevel@tonic-gate * If those are all identical, assume it's a match.
22170Sstevel@tonic-gate */
22180Sstevel@tonic-gate return (1);
22190Sstevel@tonic-gate }
22200Sstevel@tonic-gate
22210Sstevel@tonic-gate /*
22220Sstevel@tonic-gate * This routine checks to see if a given partition map matches the map
22230Sstevel@tonic-gate * in the disk label.
22240Sstevel@tonic-gate */
22250Sstevel@tonic-gate int
parts_match(label,pinfo)22260Sstevel@tonic-gate parts_match(label, pinfo)
22270Sstevel@tonic-gate register struct dk_label *label;
22280Sstevel@tonic-gate register struct partition_info *pinfo;
22290Sstevel@tonic-gate {
22300Sstevel@tonic-gate int i;
22310Sstevel@tonic-gate
22320Sstevel@tonic-gate /*
22330Sstevel@tonic-gate * If any of the partition entries is different, it doesn't match.
22340Sstevel@tonic-gate */
22350Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++)
22360Sstevel@tonic-gate
22370Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
22380Sstevel@tonic-gate if ((label->dkl_map[i].dkl_cylno !=
22390Sstevel@tonic-gate pinfo->pinfo_map[i].dkl_cylno) ||
22400Sstevel@tonic-gate (label->dkl_map[i].dkl_nblk !=
22410Sstevel@tonic-gate pinfo->pinfo_map[i].dkl_nblk))
22420Sstevel@tonic-gate
22430Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
22440Sstevel@tonic-gate if ((pinfo->pinfo_map[i].dkl_cylno !=
22450Sstevel@tonic-gate label->dkl_vtoc.v_part[i].p_start /
22460Sstevel@tonic-gate (label->dkl_nhead * label->dkl_nsect)) ||
22470Sstevel@tonic-gate (pinfo->pinfo_map[i].dkl_nblk !=
22480Sstevel@tonic-gate label->dkl_vtoc.v_part[i].p_size))
22490Sstevel@tonic-gate #else
22500Sstevel@tonic-gate #error No VTOC format defined.
22510Sstevel@tonic-gate #endif
22520Sstevel@tonic-gate return (0);
22530Sstevel@tonic-gate /*
22540Sstevel@tonic-gate * Compare the vtoc information for a match
22550Sstevel@tonic-gate * Do not require the volume name to be equal, for a match!
22560Sstevel@tonic-gate */
22570Sstevel@tonic-gate if (label->dkl_vtoc.v_version != pinfo->vtoc.v_version)
22580Sstevel@tonic-gate return (0);
22590Sstevel@tonic-gate if (label->dkl_vtoc.v_nparts != pinfo->vtoc.v_nparts)
22600Sstevel@tonic-gate return (0);
22610Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++) {
22620Sstevel@tonic-gate if (label->dkl_vtoc.v_part[i].p_tag !=
22630Sstevel@tonic-gate pinfo->vtoc.v_part[i].p_tag)
22640Sstevel@tonic-gate return (0);
22650Sstevel@tonic-gate if (label->dkl_vtoc.v_part[i].p_flag !=
22660Sstevel@tonic-gate pinfo->vtoc.v_part[i].p_flag)
22670Sstevel@tonic-gate return (0);
22680Sstevel@tonic-gate }
22690Sstevel@tonic-gate /*
22700Sstevel@tonic-gate * If they are all identical, it's a match.
22710Sstevel@tonic-gate */
22720Sstevel@tonic-gate return (1);
22730Sstevel@tonic-gate }
22740Sstevel@tonic-gate
22750Sstevel@tonic-gate /*
22760Sstevel@tonic-gate * This routine checks to see if the given disk name refers to the disk
22770Sstevel@tonic-gate * in the given disk structure.
22780Sstevel@tonic-gate */
22790Sstevel@tonic-gate int
diskname_match(char * name,struct disk_info * disk)22800Sstevel@tonic-gate diskname_match(char *name, struct disk_info *disk)
22810Sstevel@tonic-gate {
22820Sstevel@tonic-gate struct dk_cinfo dkinfo;
22830Sstevel@tonic-gate char s[MAXPATHLEN];
22840Sstevel@tonic-gate int fd;
22850Sstevel@tonic-gate
22860Sstevel@tonic-gate /*
22870Sstevel@tonic-gate * Match the name of the disk in the disk_info structure
22880Sstevel@tonic-gate */
22890Sstevel@tonic-gate if (strcmp(name, disk->disk_name) == 0) {
22900Sstevel@tonic-gate return (1);
22910Sstevel@tonic-gate }
22920Sstevel@tonic-gate
22930Sstevel@tonic-gate /*
22940Sstevel@tonic-gate * Check to see if it's a 4.x file name in the /dev
22950Sstevel@tonic-gate * directory on 5.0. Here, we only accept the
22960Sstevel@tonic-gate * canonicalized form: sd0.
22970Sstevel@tonic-gate */
22980Sstevel@tonic-gate if (canonical4x_name(name) == 0) {
22990Sstevel@tonic-gate return (0);
23000Sstevel@tonic-gate }
23010Sstevel@tonic-gate
23020Sstevel@tonic-gate (void) strcpy(s, "/dev/r");
23030Sstevel@tonic-gate (void) strcat(s, name);
23040Sstevel@tonic-gate (void) strcat(s, "c");
23050Sstevel@tonic-gate
23060Sstevel@tonic-gate if ((fd = open_disk(s, O_RDWR | O_NDELAY)) < 0) {
23070Sstevel@tonic-gate return (0);
23080Sstevel@tonic-gate }
23090Sstevel@tonic-gate
23100Sstevel@tonic-gate if (ioctl(fd, DKIOCINFO, &dkinfo) < 0) {
23110Sstevel@tonic-gate (void) close(fd);
23120Sstevel@tonic-gate return (0);
23130Sstevel@tonic-gate }
23140Sstevel@tonic-gate (void) close(fd);
23150Sstevel@tonic-gate
23160Sstevel@tonic-gate if (disk->disk_dkinfo.dki_ctype == dkinfo.dki_ctype &&
23175084Sjohnlev disk->disk_dkinfo.dki_cnum == dkinfo.dki_cnum &&
23185084Sjohnlev disk->disk_dkinfo.dki_unit == dkinfo.dki_unit &&
23195084Sjohnlev strcmp(disk->disk_dkinfo.dki_dname, dkinfo.dki_dname) == 0) {
23200Sstevel@tonic-gate return (1);
23210Sstevel@tonic-gate }
23220Sstevel@tonic-gate return (0);
23230Sstevel@tonic-gate }
23240Sstevel@tonic-gate
23250Sstevel@tonic-gate
23260Sstevel@tonic-gate static void
datafile_error(char * errmsg,char * token)23270Sstevel@tonic-gate datafile_error(char *errmsg, char *token)
23280Sstevel@tonic-gate {
23290Sstevel@tonic-gate int token_type;
23300Sstevel@tonic-gate TOKEN token_buf;
23310Sstevel@tonic-gate
23320Sstevel@tonic-gate /*
23330Sstevel@tonic-gate * Allow us to get by controllers that the other platforms don't
23340Sstevel@tonic-gate * know about.
23350Sstevel@tonic-gate */
23360Sstevel@tonic-gate if (errmsg != NULL) {
23370Sstevel@tonic-gate err_print(errmsg, token);
23380Sstevel@tonic-gate err_print(" - %s (%d)\n", file_name, data_lineno);
23390Sstevel@tonic-gate }
23400Sstevel@tonic-gate
23410Sstevel@tonic-gate /*
23420Sstevel@tonic-gate * Re-sync the parsing at the beginning of the next line
23430Sstevel@tonic-gate * unless of course we're already there.
23440Sstevel@tonic-gate */
23450Sstevel@tonic-gate if (last_token_type != SUP_EOF && last_token_type != SUP_EOL) {
23460Sstevel@tonic-gate do {
23470Sstevel@tonic-gate token_type = sup_gettoken(token_buf);
23480Sstevel@tonic-gate } while (token_type != SUP_EOF && token_type != SUP_EOL);
23490Sstevel@tonic-gate
23500Sstevel@tonic-gate if (token_type == SUP_EOF) {
23510Sstevel@tonic-gate sup_pushtoken(token_buf, token_type);
23520Sstevel@tonic-gate }
23530Sstevel@tonic-gate }
23540Sstevel@tonic-gate }
23550Sstevel@tonic-gate
23560Sstevel@tonic-gate
23570Sstevel@tonic-gate /*
23580Sstevel@tonic-gate * Search through all defined disk types for duplicate entries
23590Sstevel@tonic-gate * that are inconsistent with each other. Disks with different
23600Sstevel@tonic-gate * characteristics should be named differently.
23610Sstevel@tonic-gate * Note that this function only checks for duplicate disks
23620Sstevel@tonic-gate * for the same controller. It's possible to have two disks with
23630Sstevel@tonic-gate * the same name, but defined for different controllers.
23640Sstevel@tonic-gate * That may or may not be a problem...
23650Sstevel@tonic-gate */
23660Sstevel@tonic-gate static void
search_duplicate_dtypes()23670Sstevel@tonic-gate search_duplicate_dtypes()
23680Sstevel@tonic-gate {
23690Sstevel@tonic-gate struct disk_type *dp1;
23700Sstevel@tonic-gate struct disk_type *dp2;
23710Sstevel@tonic-gate struct mctlr_list *mlp;
23720Sstevel@tonic-gate
23730Sstevel@tonic-gate mlp = controlp;
23740Sstevel@tonic-gate
23750Sstevel@tonic-gate while (mlp != NULL) {
23760Sstevel@tonic-gate dp1 = mlp->ctlr_type->ctype_dlist;
23770Sstevel@tonic-gate while (dp1 != NULL) {
23780Sstevel@tonic-gate dp2 = dp1->dtype_next;
23790Sstevel@tonic-gate while (dp2 != NULL) {
23800Sstevel@tonic-gate check_dtypes_for_inconsistency(dp1, dp2);
23810Sstevel@tonic-gate dp2 = dp2->dtype_next;
23820Sstevel@tonic-gate }
23830Sstevel@tonic-gate dp1 = dp1->dtype_next;
23840Sstevel@tonic-gate }
23850Sstevel@tonic-gate mlp = mlp->next;
23860Sstevel@tonic-gate }
23870Sstevel@tonic-gate }
23880Sstevel@tonic-gate
23890Sstevel@tonic-gate
23900Sstevel@tonic-gate /*
23910Sstevel@tonic-gate * Search through all defined partition types for duplicate entries
23920Sstevel@tonic-gate * that are inconsistent with each other. Partitions with different
23930Sstevel@tonic-gate * characteristics should be named differently.
23940Sstevel@tonic-gate * Note that this function only checks for duplicate partitions
23950Sstevel@tonic-gate * for the same disk. It's possible to have two partitions with
23960Sstevel@tonic-gate * the same name, but defined for different disks.
23970Sstevel@tonic-gate * That may or may not be a problem...
23980Sstevel@tonic-gate */
23990Sstevel@tonic-gate static void
search_duplicate_pinfo()24000Sstevel@tonic-gate search_duplicate_pinfo()
24010Sstevel@tonic-gate {
24020Sstevel@tonic-gate struct disk_type *dp;
24030Sstevel@tonic-gate struct partition_info *pp1;
24040Sstevel@tonic-gate struct partition_info *pp2;
24050Sstevel@tonic-gate struct mctlr_list *mlp;
24060Sstevel@tonic-gate
24070Sstevel@tonic-gate mlp = controlp;
24080Sstevel@tonic-gate
24090Sstevel@tonic-gate while (mlp != NULL) {
24100Sstevel@tonic-gate dp = mlp->ctlr_type->ctype_dlist;
24110Sstevel@tonic-gate while (dp != NULL) {
24120Sstevel@tonic-gate pp1 = dp->dtype_plist;
24130Sstevel@tonic-gate while (pp1 != NULL) {
24140Sstevel@tonic-gate pp2 = pp1->pinfo_next;
24150Sstevel@tonic-gate while (pp2 != NULL) {
24160Sstevel@tonic-gate check_pinfo_for_inconsistency(pp1, pp2);
24170Sstevel@tonic-gate pp2 = pp2->pinfo_next;
24180Sstevel@tonic-gate }
24190Sstevel@tonic-gate pp1 = pp1->pinfo_next;
24200Sstevel@tonic-gate }
24210Sstevel@tonic-gate dp = dp->dtype_next;
24220Sstevel@tonic-gate }
24230Sstevel@tonic-gate mlp = mlp->next;
24240Sstevel@tonic-gate }
24250Sstevel@tonic-gate }
24260Sstevel@tonic-gate
24270Sstevel@tonic-gate
24280Sstevel@tonic-gate /*
24290Sstevel@tonic-gate * Determine if two particular disk definitions are inconsistent.
24300Sstevel@tonic-gate * Ie: same name, but different characteristics.
24310Sstevel@tonic-gate * If so, print an error message and abort.
24320Sstevel@tonic-gate */
24330Sstevel@tonic-gate static void
check_dtypes_for_inconsistency(dp1,dp2)24340Sstevel@tonic-gate check_dtypes_for_inconsistency(dp1, dp2)
24350Sstevel@tonic-gate struct disk_type *dp1;
24360Sstevel@tonic-gate struct disk_type *dp2;
24370Sstevel@tonic-gate {
24380Sstevel@tonic-gate int i;
24390Sstevel@tonic-gate int result;
24400Sstevel@tonic-gate struct chg_list *cp1;
24410Sstevel@tonic-gate struct chg_list *cp2;
24420Sstevel@tonic-gate
24430Sstevel@tonic-gate
24440Sstevel@tonic-gate /*
24450Sstevel@tonic-gate * If the name's different, we're ok
24460Sstevel@tonic-gate */
24470Sstevel@tonic-gate if (strcmp(dp1->dtype_asciilabel, dp2->dtype_asciilabel) != 0) {
24480Sstevel@tonic-gate return;
24490Sstevel@tonic-gate }
24500Sstevel@tonic-gate
24510Sstevel@tonic-gate /*
24520Sstevel@tonic-gate * Compare all the disks' characteristics
24530Sstevel@tonic-gate */
24540Sstevel@tonic-gate result = 0;
24550Sstevel@tonic-gate result |= (dp1->dtype_flags != dp2->dtype_flags);
24560Sstevel@tonic-gate result |= (dp1->dtype_options != dp2->dtype_options);
24570Sstevel@tonic-gate result |= (dp1->dtype_fmt_time != dp2->dtype_fmt_time);
24580Sstevel@tonic-gate result |= (dp1->dtype_bpt != dp2->dtype_bpt);
24590Sstevel@tonic-gate result |= (dp1->dtype_ncyl != dp2->dtype_ncyl);
24600Sstevel@tonic-gate result |= (dp1->dtype_acyl != dp2->dtype_acyl);
24610Sstevel@tonic-gate result |= (dp1->dtype_pcyl != dp2->dtype_pcyl);
24620Sstevel@tonic-gate result |= (dp1->dtype_nhead != dp2->dtype_nhead);
24630Sstevel@tonic-gate result |= (dp1->dtype_nsect != dp2->dtype_nsect);
24640Sstevel@tonic-gate result |= (dp1->dtype_rpm != dp2->dtype_rpm);
24650Sstevel@tonic-gate result |= (dp1->dtype_cyl_skew != dp2->dtype_cyl_skew);
24660Sstevel@tonic-gate result |= (dp1->dtype_trk_skew != dp2->dtype_trk_skew);
24670Sstevel@tonic-gate result |= (dp1->dtype_trks_zone != dp2->dtype_trks_zone);
24680Sstevel@tonic-gate result |= (dp1->dtype_atrks != dp2->dtype_atrks);
24690Sstevel@tonic-gate result |= (dp1->dtype_asect != dp2->dtype_asect);
24700Sstevel@tonic-gate result |= (dp1->dtype_cache != dp2->dtype_cache);
24710Sstevel@tonic-gate result |= (dp1->dtype_threshold != dp2->dtype_threshold);
24720Sstevel@tonic-gate result |= (dp1->dtype_read_retries != dp2->dtype_read_retries);
24730Sstevel@tonic-gate result |= (dp1->dtype_write_retries != dp2->dtype_write_retries);
24740Sstevel@tonic-gate result |= (dp1->dtype_prefetch_min != dp2->dtype_prefetch_min);
24750Sstevel@tonic-gate result |= (dp1->dtype_prefetch_max != dp2->dtype_prefetch_max);
24760Sstevel@tonic-gate for (i = 0; i < NSPECIFICS; i++) {
24770Sstevel@tonic-gate result |= (dp1->dtype_specifics[i] != dp2->dtype_specifics[i]);
24780Sstevel@tonic-gate }
24790Sstevel@tonic-gate
24800Sstevel@tonic-gate cp1 = dp1->dtype_chglist;
24810Sstevel@tonic-gate cp2 = dp2->dtype_chglist;
24820Sstevel@tonic-gate while (cp1 != NULL && cp2 != NULL) {
24830Sstevel@tonic-gate if (cp1 == NULL || cp2 == NULL) {
24840Sstevel@tonic-gate result = 1;
24850Sstevel@tonic-gate break;
24860Sstevel@tonic-gate }
24870Sstevel@tonic-gate result |= (cp1->pageno != cp2->pageno);
24880Sstevel@tonic-gate result |= (cp1->byteno != cp2->byteno);
24890Sstevel@tonic-gate result |= (cp1->mode != cp2->mode);
24900Sstevel@tonic-gate result |= (cp1->value != cp2->value);
24910Sstevel@tonic-gate cp1 = cp1->next;
24920Sstevel@tonic-gate cp2 = cp2->next;
24930Sstevel@tonic-gate }
24940Sstevel@tonic-gate
24950Sstevel@tonic-gate if (result) {
24960Sstevel@tonic-gate err_print("Inconsistent definitions for disk type '%s'\n",
24970Sstevel@tonic-gate dp1->dtype_asciilabel);
24980Sstevel@tonic-gate if (dp1->dtype_filename != NULL &&
24990Sstevel@tonic-gate dp2->dtype_filename != NULL) {
25000Sstevel@tonic-gate err_print("%s (%d) - %s (%d)\n",
25010Sstevel@tonic-gate dp1->dtype_filename, dp1->dtype_lineno,
25020Sstevel@tonic-gate dp2->dtype_filename, dp2->dtype_lineno);
25030Sstevel@tonic-gate }
25040Sstevel@tonic-gate fullabort();
25050Sstevel@tonic-gate }
25060Sstevel@tonic-gate }
25070Sstevel@tonic-gate
25080Sstevel@tonic-gate
25090Sstevel@tonic-gate /*
25100Sstevel@tonic-gate * Determine if two particular partition definitions are inconsistent.
25110Sstevel@tonic-gate * Ie: same name, but different characteristics.
25120Sstevel@tonic-gate * If so, print an error message and abort.
25130Sstevel@tonic-gate */
25140Sstevel@tonic-gate static void
check_pinfo_for_inconsistency(pp1,pp2)25150Sstevel@tonic-gate check_pinfo_for_inconsistency(pp1, pp2)
25160Sstevel@tonic-gate struct partition_info *pp1;
25170Sstevel@tonic-gate struct partition_info *pp2;
25180Sstevel@tonic-gate {
25190Sstevel@tonic-gate int i;
25200Sstevel@tonic-gate int result;
25210Sstevel@tonic-gate struct dk_map32 *map1;
25220Sstevel@tonic-gate struct dk_map32 *map2;
25230Sstevel@tonic-gate
25240Sstevel@tonic-gate #if defined(_SUNOS_VTOC_8)
25250Sstevel@tonic-gate struct dk_map2 *vp1;
25260Sstevel@tonic-gate struct dk_map2 *vp2;
25270Sstevel@tonic-gate
25280Sstevel@tonic-gate #elif defined(_SUNOS_VTOC_16)
25290Sstevel@tonic-gate struct dkl_partition *vp1;
25300Sstevel@tonic-gate struct dkl_partition *vp2;
25310Sstevel@tonic-gate #else
25320Sstevel@tonic-gate #error No VTOC layout defined.
25330Sstevel@tonic-gate #endif /* defined(_SUNOS_VTOC_8) */
25340Sstevel@tonic-gate
25350Sstevel@tonic-gate /*
25360Sstevel@tonic-gate * If the name's different, we're ok
25370Sstevel@tonic-gate */
25380Sstevel@tonic-gate if (strcmp(pp1->pinfo_name, pp2->pinfo_name) != 0) {
25390Sstevel@tonic-gate return;
25400Sstevel@tonic-gate }
25410Sstevel@tonic-gate
25420Sstevel@tonic-gate /*
25430Sstevel@tonic-gate * Compare all the partitions' characteristics
25440Sstevel@tonic-gate */
25450Sstevel@tonic-gate result = 0;
25460Sstevel@tonic-gate map1 = pp1->pinfo_map;
25470Sstevel@tonic-gate map2 = pp2->pinfo_map;
25480Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++, map1++, map2++) {
25490Sstevel@tonic-gate result |= (map1->dkl_cylno != map2->dkl_cylno);
25500Sstevel@tonic-gate result |= (map1->dkl_nblk != map2->dkl_nblk);
25510Sstevel@tonic-gate }
25520Sstevel@tonic-gate
25530Sstevel@tonic-gate /*
25540Sstevel@tonic-gate * Compare the significant portions of the vtoc information
25550Sstevel@tonic-gate */
25560Sstevel@tonic-gate vp1 = pp1->vtoc.v_part;
25570Sstevel@tonic-gate vp2 = pp2->vtoc.v_part;
25580Sstevel@tonic-gate for (i = 0; i < NDKMAP; i++, vp1++, vp2++) {
25590Sstevel@tonic-gate result |= (vp1->p_tag != vp2->p_tag);
25600Sstevel@tonic-gate result |= (vp1->p_flag != vp2->p_flag);
25610Sstevel@tonic-gate }
25620Sstevel@tonic-gate
25630Sstevel@tonic-gate if (result) {
25640Sstevel@tonic-gate err_print("Inconsistent definitions for partition type '%s'\n",
25650Sstevel@tonic-gate pp1->pinfo_name);
25660Sstevel@tonic-gate if (pp1->pinfo_filename != NULL &&
25670Sstevel@tonic-gate pp2->pinfo_filename != NULL) {
25680Sstevel@tonic-gate err_print("%s (%d) - %s (%d)\n",
25690Sstevel@tonic-gate pp1->pinfo_filename, pp1->pinfo_lineno,
25700Sstevel@tonic-gate pp2->pinfo_filename, pp2->pinfo_lineno);
25710Sstevel@tonic-gate }
25720Sstevel@tonic-gate fullabort();
25730Sstevel@tonic-gate }
25740Sstevel@tonic-gate }
25750Sstevel@tonic-gate
25760Sstevel@tonic-gate /*
25770Sstevel@tonic-gate * Convert a string of digits into a block number.
25780Sstevel@tonic-gate * The digits are assumed to be a block number unless the
25790Sstevel@tonic-gate * the string is terminated by 'c', in which case it is
25800Sstevel@tonic-gate * assumed to be in units of cylinders. Accept a 'b'
25810Sstevel@tonic-gate * to explictly specify blocks, for consistency.
25820Sstevel@tonic-gate *
25830Sstevel@tonic-gate * NB: uses the macro spc(), which requires that the
25840Sstevel@tonic-gate * globals nhead/nsect/acyl be set up correctly.
25850Sstevel@tonic-gate *
25860Sstevel@tonic-gate * Returns -1 in the case of an error.
25870Sstevel@tonic-gate */
25887563SPrasad.Singamsetty@Sun.COM static uint_t
str2blks(char * str)25890Sstevel@tonic-gate str2blks(char *str)
25900Sstevel@tonic-gate {
25910Sstevel@tonic-gate int blks;
25920Sstevel@tonic-gate char *p;
25930Sstevel@tonic-gate
25940Sstevel@tonic-gate blks = (int)strtol(str, &p, 0);
25950Sstevel@tonic-gate /*
25960Sstevel@tonic-gate * Check what terminated the conversion.
25970Sstevel@tonic-gate */
25980Sstevel@tonic-gate if (*p != 0) {
25990Sstevel@tonic-gate /*
26000Sstevel@tonic-gate * Units specifier of 'c': convert cylinders to blocks
26010Sstevel@tonic-gate */
26020Sstevel@tonic-gate if (*p == 'c') {
26030Sstevel@tonic-gate p++;
26040Sstevel@tonic-gate blks = blks * spc();
26050Sstevel@tonic-gate /*
26060Sstevel@tonic-gate * Ignore a 'b' specifier.
26070Sstevel@tonic-gate */
26080Sstevel@tonic-gate } else if (*p == 'b') {
26090Sstevel@tonic-gate p++;
26100Sstevel@tonic-gate }
26110Sstevel@tonic-gate /*
26120Sstevel@tonic-gate * Anthing left over is an error
26130Sstevel@tonic-gate */
26140Sstevel@tonic-gate if (*p != 0) {
26150Sstevel@tonic-gate blks = -1;
26160Sstevel@tonic-gate }
26170Sstevel@tonic-gate }
26180Sstevel@tonic-gate
26190Sstevel@tonic-gate return (blks);
26200Sstevel@tonic-gate }
26210Sstevel@tonic-gate /*
26220Sstevel@tonic-gate * Convert a string of digits into a cylinder number.
26230Sstevel@tonic-gate * Accept a an optional 'c' specifier, for consistency.
26240Sstevel@tonic-gate *
26250Sstevel@tonic-gate * Returns -1 in the case of an error.
26260Sstevel@tonic-gate */
26270Sstevel@tonic-gate int
str2cyls(char * str)26280Sstevel@tonic-gate str2cyls(char *str)
26290Sstevel@tonic-gate {
26300Sstevel@tonic-gate int cyls;
26310Sstevel@tonic-gate char *p;
26320Sstevel@tonic-gate
26330Sstevel@tonic-gate cyls = (int)strtol(str, &p, 0);
26340Sstevel@tonic-gate /*
26350Sstevel@tonic-gate * Check what terminated the conversion.
26360Sstevel@tonic-gate */
26370Sstevel@tonic-gate if (*p != 0) {
26380Sstevel@tonic-gate /*
26397563SPrasad.Singamsetty@Sun.COM * Units specifier of 'c': accept it.
26400Sstevel@tonic-gate */
26410Sstevel@tonic-gate if (*p == 'c') {
26420Sstevel@tonic-gate p++;
26430Sstevel@tonic-gate }
26440Sstevel@tonic-gate /*
26450Sstevel@tonic-gate * Anthing left over is an error
26460Sstevel@tonic-gate */
26470Sstevel@tonic-gate if (*p != 0) {
26480Sstevel@tonic-gate cyls = -1;
26490Sstevel@tonic-gate }
26500Sstevel@tonic-gate }
26510Sstevel@tonic-gate
26520Sstevel@tonic-gate return (cyls);
26530Sstevel@tonic-gate }
26540Sstevel@tonic-gate
26550Sstevel@tonic-gate
26560Sstevel@tonic-gate /*
26570Sstevel@tonic-gate * Create a new chg_list structure, and append it onto the
26580Sstevel@tonic-gate * end of the current chg_list under construction. By
26590Sstevel@tonic-gate * applying changes in the order in which listed in the
26600Sstevel@tonic-gate * data file, the changes we make are deterministic.
26610Sstevel@tonic-gate * Return a pointer to the new structure, so that the
26620Sstevel@tonic-gate * caller can fill in the appropriate information.
26630Sstevel@tonic-gate */
26640Sstevel@tonic-gate static struct chg_list *
new_chg_list(struct disk_type * disk)26650Sstevel@tonic-gate new_chg_list(struct disk_type *disk)
26660Sstevel@tonic-gate {
26670Sstevel@tonic-gate struct chg_list *cp;
26680Sstevel@tonic-gate struct chg_list *nc;
26690Sstevel@tonic-gate
26700Sstevel@tonic-gate nc = zalloc(sizeof (struct chg_list));
26710Sstevel@tonic-gate
26720Sstevel@tonic-gate if (disk->dtype_chglist == NULL) {
26730Sstevel@tonic-gate disk->dtype_chglist = nc;
26740Sstevel@tonic-gate } else {
26750Sstevel@tonic-gate for (cp = disk->dtype_chglist; cp->next; cp = cp->next)
26760Sstevel@tonic-gate ;
26770Sstevel@tonic-gate cp->next = nc;
26780Sstevel@tonic-gate }
26790Sstevel@tonic-gate nc->next = NULL;
26800Sstevel@tonic-gate return (nc);
26810Sstevel@tonic-gate }
26820Sstevel@tonic-gate
26830Sstevel@tonic-gate
26840Sstevel@tonic-gate /*
26850Sstevel@tonic-gate * Follow symbolic links from the logical device name to
26860Sstevel@tonic-gate * the /devfs physical device name. To be complete, we
26870Sstevel@tonic-gate * handle the case of multiple links. This function
26880Sstevel@tonic-gate * either returns NULL (no links, or some other error),
26890Sstevel@tonic-gate * or the physical device name, alloc'ed on the heap.
26900Sstevel@tonic-gate *
26910Sstevel@tonic-gate * Note that the standard /devices prefix is stripped from
26920Sstevel@tonic-gate * the final pathname, if present. The trailing options
26930Sstevel@tonic-gate * are also removed (":c, raw").
26940Sstevel@tonic-gate */
26950Sstevel@tonic-gate static char *
get_physical_name(char * path)26960Sstevel@tonic-gate get_physical_name(char *path)
26970Sstevel@tonic-gate {
26980Sstevel@tonic-gate struct stat stbuf;
26990Sstevel@tonic-gate int i;
27000Sstevel@tonic-gate int level;
27010Sstevel@tonic-gate char *p;
27020Sstevel@tonic-gate char s[MAXPATHLEN];
27030Sstevel@tonic-gate char buf[MAXPATHLEN];
27040Sstevel@tonic-gate char dir[MAXPATHLEN];
27050Sstevel@tonic-gate char savedir[MAXPATHLEN];
27060Sstevel@tonic-gate char *result = NULL;
27070Sstevel@tonic-gate
27080Sstevel@tonic-gate if (getcwd(savedir, sizeof (savedir)) == NULL) {
27090Sstevel@tonic-gate err_print("getcwd() failed - %s\n", strerror(errno));
27100Sstevel@tonic-gate return (NULL);
27110Sstevel@tonic-gate }
27120Sstevel@tonic-gate
27130Sstevel@tonic-gate (void) strcpy(s, path);
27140Sstevel@tonic-gate if ((p = strrchr(s, '/')) != NULL) {
27150Sstevel@tonic-gate *p = 0;
27160Sstevel@tonic-gate }
27170Sstevel@tonic-gate if (s[0] == 0) {
27180Sstevel@tonic-gate (void) strcpy(s, "/");
27190Sstevel@tonic-gate }
27200Sstevel@tonic-gate if (chdir(s) == -1) {
27210Sstevel@tonic-gate err_print("cannot chdir() to %s - %s\n",
27225084Sjohnlev s, strerror(errno));
27230Sstevel@tonic-gate goto exit;
27240Sstevel@tonic-gate }
27250Sstevel@tonic-gate
27260Sstevel@tonic-gate level = 0;
27270Sstevel@tonic-gate (void) strcpy(s, path);
27280Sstevel@tonic-gate for (;;) {
27290Sstevel@tonic-gate /*
27300Sstevel@tonic-gate * See if there's a real file out there. If not,
27310Sstevel@tonic-gate * we have a dangling link and we ignore it.
27320Sstevel@tonic-gate */
27330Sstevel@tonic-gate if (stat(s, &stbuf) == -1) {
27340Sstevel@tonic-gate goto exit;
27350Sstevel@tonic-gate }
27360Sstevel@tonic-gate if (lstat(s, &stbuf) == -1) {
27370Sstevel@tonic-gate err_print("%s: lstat() failed - %s\n",
27385084Sjohnlev s, strerror(errno));
27390Sstevel@tonic-gate goto exit;
27400Sstevel@tonic-gate }
27410Sstevel@tonic-gate /*
27420Sstevel@tonic-gate * If the file is not a link, we're done one
27430Sstevel@tonic-gate * way or the other. If there were links,
27440Sstevel@tonic-gate * return the full pathname of the resulting
27450Sstevel@tonic-gate * file.
27460Sstevel@tonic-gate */
27470Sstevel@tonic-gate if (!S_ISLNK(stbuf.st_mode)) {
27480Sstevel@tonic-gate if (level > 0) {
27490Sstevel@tonic-gate /*
27500Sstevel@tonic-gate * Strip trailing options from the
27510Sstevel@tonic-gate * physical device name
27520Sstevel@tonic-gate */
27530Sstevel@tonic-gate if ((p = strrchr(s, ':')) != NULL) {
27540Sstevel@tonic-gate *p = 0;
27550Sstevel@tonic-gate }
27560Sstevel@tonic-gate /*
27570Sstevel@tonic-gate * Get the current directory, and
27580Sstevel@tonic-gate * glue the pieces together.
27590Sstevel@tonic-gate */
27600Sstevel@tonic-gate if (getcwd(dir, sizeof (dir)) == NULL) {
27610Sstevel@tonic-gate err_print("getcwd() failed - %s\n",
27625084Sjohnlev strerror(errno));
27630Sstevel@tonic-gate goto exit;
27640Sstevel@tonic-gate }
27650Sstevel@tonic-gate (void) strcat(dir, "/");
27660Sstevel@tonic-gate (void) strcat(dir, s);
27670Sstevel@tonic-gate /*
27680Sstevel@tonic-gate * If we have the standard fixed
27690Sstevel@tonic-gate * /devices prefix, remove it.
27700Sstevel@tonic-gate */
27710Sstevel@tonic-gate p = (strstr(dir, DEVFS_PREFIX) == dir) ?
27725084Sjohnlev dir+strlen(DEVFS_PREFIX) : dir;
27730Sstevel@tonic-gate result = alloc_string(p);
27740Sstevel@tonic-gate }
27750Sstevel@tonic-gate goto exit;
27760Sstevel@tonic-gate }
27770Sstevel@tonic-gate i = readlink(s, buf, sizeof (buf));
27780Sstevel@tonic-gate if (i == -1) {
27790Sstevel@tonic-gate err_print("%s: readlink() failed - %s\n",
27805084Sjohnlev s, strerror(errno));
27810Sstevel@tonic-gate goto exit;
27820Sstevel@tonic-gate }
27830Sstevel@tonic-gate level++;
27840Sstevel@tonic-gate buf[i] = 0;
27850Sstevel@tonic-gate
27860Sstevel@tonic-gate /*
27870Sstevel@tonic-gate * Break up the pathname into the directory
27880Sstevel@tonic-gate * reference, if applicable and simple filename.
27890Sstevel@tonic-gate * chdir()'ing to the directory allows us to
27900Sstevel@tonic-gate * handle links with relative pathnames correctly.
27910Sstevel@tonic-gate */
27920Sstevel@tonic-gate (void) strcpy(dir, buf);
27930Sstevel@tonic-gate if ((p = strrchr(dir, '/')) != NULL) {
27940Sstevel@tonic-gate *p = 0;
27950Sstevel@tonic-gate if (chdir(dir) == -1) {
27960Sstevel@tonic-gate err_print("cannot chdir() to %s - %s\n",
27975084Sjohnlev dir, strerror(errno));
27980Sstevel@tonic-gate goto exit;
27990Sstevel@tonic-gate }
28000Sstevel@tonic-gate (void) strcpy(s, p+1);
28010Sstevel@tonic-gate } else {
28020Sstevel@tonic-gate (void) strcpy(s, buf);
28030Sstevel@tonic-gate }
28040Sstevel@tonic-gate }
28050Sstevel@tonic-gate
28060Sstevel@tonic-gate exit:
28070Sstevel@tonic-gate if (chdir(savedir) == -1) {
28080Sstevel@tonic-gate err_print("cannot chdir() to %s - %s\n",
28095084Sjohnlev savedir, strerror(errno));
28100Sstevel@tonic-gate }
28110Sstevel@tonic-gate
28120Sstevel@tonic-gate return (result);
28130Sstevel@tonic-gate }
28140Sstevel@tonic-gate
28150Sstevel@tonic-gate
28160Sstevel@tonic-gate static void
sort_disk_list()28170Sstevel@tonic-gate sort_disk_list()
28180Sstevel@tonic-gate {
28190Sstevel@tonic-gate int n;
28200Sstevel@tonic-gate struct disk_info **disks;
28210Sstevel@tonic-gate struct disk_info *d;
28220Sstevel@tonic-gate struct disk_info **dp;
28230Sstevel@tonic-gate struct disk_info **dp2;
28240Sstevel@tonic-gate
28250Sstevel@tonic-gate /*
28260Sstevel@tonic-gate * Count the number of disks in the list
28270Sstevel@tonic-gate */
28280Sstevel@tonic-gate n = 0;
28290Sstevel@tonic-gate for (d = disk_list; d != NULL; d = d->disk_next) {
28300Sstevel@tonic-gate n++;
28310Sstevel@tonic-gate }
28320Sstevel@tonic-gate if (n == 0) {
28330Sstevel@tonic-gate return;
28340Sstevel@tonic-gate }
28350Sstevel@tonic-gate
28360Sstevel@tonic-gate /*
28370Sstevel@tonic-gate * Allocate a simple disk list array and fill it in
28380Sstevel@tonic-gate */
28390Sstevel@tonic-gate disks = (struct disk_info **)
28405084Sjohnlev zalloc((n+1) * sizeof (struct disk_info *));
28410Sstevel@tonic-gate
28420Sstevel@tonic-gate dp = disks;
28430Sstevel@tonic-gate for (d = disk_list; d != NULL; d = d->disk_next) {
28440Sstevel@tonic-gate *dp++ = d;
28450Sstevel@tonic-gate }
28460Sstevel@tonic-gate *dp = NULL;
28470Sstevel@tonic-gate
28480Sstevel@tonic-gate /*
28490Sstevel@tonic-gate * Sort the disk list array
28500Sstevel@tonic-gate */
28510Sstevel@tonic-gate qsort((void *) disks, n, sizeof (struct disk_info *),
28525084Sjohnlev disk_name_compare);
28530Sstevel@tonic-gate
28540Sstevel@tonic-gate /*
28550Sstevel@tonic-gate * Rebuild the linked list disk list structure
28560Sstevel@tonic-gate */
28570Sstevel@tonic-gate dp = disks;
28580Sstevel@tonic-gate disk_list = *dp;
28590Sstevel@tonic-gate dp2 = dp + 1;
28600Sstevel@tonic-gate do {
28610Sstevel@tonic-gate (*dp++)->disk_next = *dp2++;
28620Sstevel@tonic-gate } while (*dp != NULL);
28630Sstevel@tonic-gate
28640Sstevel@tonic-gate /*
28650Sstevel@tonic-gate * Clean up
28660Sstevel@tonic-gate */
28670Sstevel@tonic-gate (void) destroy_data((void *)disks);
28680Sstevel@tonic-gate }
28690Sstevel@tonic-gate
28700Sstevel@tonic-gate
28710Sstevel@tonic-gate /*
28720Sstevel@tonic-gate * Compare two disk names
28730Sstevel@tonic-gate */
28740Sstevel@tonic-gate static int
disk_name_compare(const void * arg1,const void * arg2)28750Sstevel@tonic-gate disk_name_compare(
28760Sstevel@tonic-gate const void *arg1,
28770Sstevel@tonic-gate const void *arg2)
28780Sstevel@tonic-gate {
28790Sstevel@tonic-gate char *s1;
28800Sstevel@tonic-gate char *s2;
28810Sstevel@tonic-gate int n1;
28820Sstevel@tonic-gate int n2;
28830Sstevel@tonic-gate char *p1;
28840Sstevel@tonic-gate char *p2;
28850Sstevel@tonic-gate
28860Sstevel@tonic-gate s1 = (*((struct disk_info **)arg1))->disk_name;
28870Sstevel@tonic-gate s2 = (*((struct disk_info **)arg2))->disk_name;
28880Sstevel@tonic-gate
28890Sstevel@tonic-gate for (;;) {
28900Sstevel@tonic-gate if (*s1 == 0 || *s2 == 0)
28910Sstevel@tonic-gate break;
28920Sstevel@tonic-gate if (isdigit(*s1) && isdigit(*s2)) {
28930Sstevel@tonic-gate n1 = strtol(s1, &p1, 10);
28940Sstevel@tonic-gate n2 = strtol(s2, &p2, 10);
28950Sstevel@tonic-gate if (n1 != n2) {
28960Sstevel@tonic-gate return (n1 - n2);
28970Sstevel@tonic-gate }
28980Sstevel@tonic-gate s1 = p1;
28990Sstevel@tonic-gate s2 = p2;
29000Sstevel@tonic-gate } else if (*s1 != *s2) {
29010Sstevel@tonic-gate break;
29020Sstevel@tonic-gate } else {
29030Sstevel@tonic-gate s1++;
29040Sstevel@tonic-gate s2++;
29050Sstevel@tonic-gate }
29060Sstevel@tonic-gate }
29070Sstevel@tonic-gate
29080Sstevel@tonic-gate return (*s1 - *s2);
29090Sstevel@tonic-gate }
29100Sstevel@tonic-gate
29110Sstevel@tonic-gate static void
make_controller_list()29120Sstevel@tonic-gate make_controller_list()
29130Sstevel@tonic-gate {
29140Sstevel@tonic-gate int x;
29150Sstevel@tonic-gate struct mctlr_list *ctlrp;
29160Sstevel@tonic-gate
29170Sstevel@tonic-gate ctlrp = controlp;
29180Sstevel@tonic-gate
29190Sstevel@tonic-gate for (x = nctypes; x != 0; x--) {
29200Sstevel@tonic-gate ctlrp = zalloc(sizeof (struct mctlr_list));
29210Sstevel@tonic-gate ctlrp->next = controlp;
29220Sstevel@tonic-gate ctlrp->ctlr_type = &ctlr_types[x - 1];
29230Sstevel@tonic-gate controlp = ctlrp;
29240Sstevel@tonic-gate
29250Sstevel@tonic-gate }
29260Sstevel@tonic-gate }
29270Sstevel@tonic-gate
29280Sstevel@tonic-gate static void
check_for_duplicate_disknames(arglist)29290Sstevel@tonic-gate check_for_duplicate_disknames(arglist)
29300Sstevel@tonic-gate char *arglist[];
29310Sstevel@tonic-gate {
29320Sstevel@tonic-gate char *directory = "/dev/rdsk/";
29330Sstevel@tonic-gate char **disklist;
29340Sstevel@tonic-gate int len;
29350Sstevel@tonic-gate char s[MAXPATHLEN], t[MAXPATHLEN];
29360Sstevel@tonic-gate int diskno = 0;
29370Sstevel@tonic-gate int i;
29380Sstevel@tonic-gate
29390Sstevel@tonic-gate
29400Sstevel@tonic-gate len = strlen(directory);
29410Sstevel@tonic-gate disklist = arglist;
29420Sstevel@tonic-gate for (; *disklist != NULL; disklist++) {
29430Sstevel@tonic-gate if (strncmp(directory, *disklist, len) == 0) {
29440Sstevel@tonic-gate /* Disk is in conventional format */
29450Sstevel@tonic-gate canonicalize_name(s, *disklist);
29460Sstevel@tonic-gate /*
29470Sstevel@tonic-gate * check if the disk is already present in
29480Sstevel@tonic-gate * disk list.
29490Sstevel@tonic-gate */
29500Sstevel@tonic-gate for (i = 0; i < diskno; i++) {
29510Sstevel@tonic-gate canonicalize_name(t, arglist[i]);
29520Sstevel@tonic-gate if (strncmp(s, t, strlen(t)) == 0)
29530Sstevel@tonic-gate break;
29540Sstevel@tonic-gate }
29550Sstevel@tonic-gate if (i != diskno)
29560Sstevel@tonic-gate continue;
29570Sstevel@tonic-gate }
29580Sstevel@tonic-gate (void) strcpy(arglist[diskno], *disklist);
29590Sstevel@tonic-gate diskno++;
29600Sstevel@tonic-gate }
29610Sstevel@tonic-gate arglist[diskno] = NULL;
29620Sstevel@tonic-gate }
29630Sstevel@tonic-gate
29640Sstevel@tonic-gate #define DISK_PREFIX "/dev/rdsk/"
29650Sstevel@tonic-gate
29660Sstevel@tonic-gate /*
29670Sstevel@tonic-gate * This Function checks if the non-conventional name is a a link to
29680Sstevel@tonic-gate * one of the conventional whole disk name.
29690Sstevel@tonic-gate */
29700Sstevel@tonic-gate static int
name_represents_wholedisk(name)29710Sstevel@tonic-gate name_represents_wholedisk(name)
29720Sstevel@tonic-gate char *name;
29730Sstevel@tonic-gate {
29740Sstevel@tonic-gate char symname[MAXPATHLEN];
29750Sstevel@tonic-gate char localname[MAXPATHLEN];
29760Sstevel@tonic-gate char *nameptr;
29770Sstevel@tonic-gate
29780Sstevel@tonic-gate
29790Sstevel@tonic-gate (void) memset(symname, 0, MAXPATHLEN);
29800Sstevel@tonic-gate (void) memset(localname, 0, MAXPATHLEN);
29810Sstevel@tonic-gate (void) strcpy(localname, name);
29820Sstevel@tonic-gate
29830Sstevel@tonic-gate while (readlink(localname, symname, MAXPATHLEN) != -1) {
29840Sstevel@tonic-gate nameptr = symname;
29850Sstevel@tonic-gate if (strncmp(symname, DISK_PREFIX, strlen(DISK_PREFIX)) == 0)
29860Sstevel@tonic-gate nameptr += strlen(DISK_PREFIX);
29870Sstevel@tonic-gate if (conventional_name(nameptr)) {
29880Sstevel@tonic-gate if (whole_disk_name(nameptr))
29890Sstevel@tonic-gate return (0);
29900Sstevel@tonic-gate else
29910Sstevel@tonic-gate return (1);
29920Sstevel@tonic-gate }
29930Sstevel@tonic-gate (void) strcpy(localname, symname);
29940Sstevel@tonic-gate (void) memset(symname, 0, MAXPATHLEN);
29950Sstevel@tonic-gate }
29960Sstevel@tonic-gate return (0);
29970Sstevel@tonic-gate }
2998