4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2011 Gary Mills
26 * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
30 * This file contains the code to perform program startup. This
31 * includes reading the data file and the search for disks.
44 #include <sys/fcntl.h>
45 #include <sys/param.h>
52 #include "menu_command.h"
53 #include "partition.h"
54 #include "ctlr_scsi.h"
56 #include "auto_sense.h"
58 extern struct ctlr_type ctlr_types
[];
60 extern struct ctlr_ops genericops
;
67 /* Function prototypes for ANSI C Compilers */
68 static void usage(void);
69 static int sup_prxfile(void);
70 static void sup_setpath(void);
71 static void sup_setdtype(void);
72 static int sup_change_spec(struct disk_type
*, char *);
73 static void sup_setpart(void);
74 static void search_for_logical_dev(char *devname
);
75 static void add_device_to_disklist(char *devname
, char *devpath
);
76 static int disk_is_known(struct dk_cinfo
*dkinfo
);
77 static void datafile_error(char *errmsg
, char *token
);
78 static void search_duplicate_dtypes(void);
79 static void search_duplicate_pinfo(void);
80 static void check_dtypes_for_inconsistency(struct disk_type
*dp1
,
81 struct disk_type
*dp2
);
82 static void check_pinfo_for_inconsistency(struct partition_info
*pp1
,
83 struct partition_info
*pp2
);
84 static uint_t
str2blks(char *str
);
85 static int str2cyls(char *str
);
86 static struct chg_list
*new_chg_list(struct disk_type
*);
87 static char *get_physical_name(char *);
88 static void sort_disk_list(void);
89 static int disk_name_compare(const void *, const void *);
90 static void make_controller_list(void);
91 static void check_for_duplicate_disknames(char *arglist
[]);
95 /* Function prototypes for non-ANSI C Compilers */
97 static int sup_prxfile();
98 static void sup_setpath();
99 static void sup_setdtype();
100 static int sup_change_spec();
101 static void sup_setpart();
102 static void search_for_logical_dev();
103 static void add_device_to_disklist();
104 static int disk_is_known();
105 static void datafile_error();
106 static void search_duplicate_dtypes();
107 static void search_duplicate_pinfo();
108 static void check_dtypes_for_inconsistency();
109 static void check_pinfo_for_inconsistency();
110 static uint_t
str2blks();
111 static int str2cyls();
112 static struct chg_list
*new_chg_list();
113 static char *get_physical_name();
114 static void sort_disk_list();
115 static int disk_name_compare();
116 static void make_controller_list();
117 static void check_for_duplicate_disknames();
119 #endif /* __STDC__ */
122 static char *other_ctlrs
[] = {
125 #define OTHER_CTLRS 1
128 static char *other_ctlrs
[] = {
131 #define OTHER_CTLRS 2
134 #error No Platform defined.
139 * This global is used to store the current line # in the data file.
140 * It must be global because the I/O routines are allowed to side
141 * effect it to keep track of backslashed newlines.
143 int data_lineno
; /* current line # in data file */
146 * Search path as defined in the format.dat files
148 static char **search_path
= NULL
;
151 static int name_represents_wholedisk(char *name
);
153 static void get_disk_name(int fd
, char *disk_name
, struct disk_info
*disk_info
);
156 * This routine digests the options on the command line. It returns
157 * the index into argv of the first string that is not an option. If
158 * there are none, it returns -1.
161 do_options(int argc
, char *argv
[])
168 * Default is no extended messages. Can be enabled manually.
177 * Loop through the argument list, incrementing each time by
178 * an amount determined by the options found.
180 for (i
= 1; i
< argc
; i
= next
) {
182 * Start out assuming an increment of 1.
186 * As soon as we hit a non-option, we're done.
191 * Loop through all the characters in this option string.
193 for (ptr
= argv
[i
] + 1; *ptr
!= '\0'; ptr
++) {
195 * Determine each option represented. For options
196 * that use a second string, increase the increment
197 * of the main loop so they aren't re-interpreted.
206 option_f
= argv
[next
++];
212 option_l
= argv
[next
++];
218 option_x
= argv
[next
++];
224 option_d
= argv
[next
++];
230 option_t
= argv
[next
++];
236 option_p
= argv
[next
++];
263 * All the command line strings were options. Return that fact.
272 err_print("Usage: format [-s][-d disk_name]");
273 err_print("[-t disk_type][-p partition_name]\n");
274 err_print("\t[-f cmd_file][-l log_file]");
275 err_print("[-x data_file] [-m] [-M] [-e] disk_list\n");
281 * This routine reads in and digests the data file. The data file contains
282 * definitions for the search path, known disk types, and known partition
285 * Note: for each file being processed, file_name is a pointer to that
286 * file's name. We are careful to make sure that file_name points to
287 * globally-accessible data, not data on the stack, because each
288 * disk/partition/controller definition now keeps a pointer to the
289 * filename in which it was defined. In the case of duplicate,
290 * conflicting definitions, we can thus tell the user exactly where
291 * the problem is occurring.
296 int nopened_files
= 0;
297 char fname
[MAXPATHLEN
];
304 * Create a singly-linked list of controller types so that we may
305 * dynamically add unknown controllers to this for 3'rd
306 * party disk support.
309 make_controller_list();
312 * If a data file was specified on the command line, use it first
313 * If the file cannot be opened, fail. We want to guarantee
314 * that, if the user explicitly names a file, they can
317 * option_x is already global, no need to dup it on the heap.
320 file_name
= option_x
;
324 err_print("Unable to open data file '%s' - %s.\n",
325 file_name
, strerror(errno
));
331 * Now look for an environment variable FORMAT_PATH.
332 * If found, we use it as a colon-separated list
333 * of directories. If no such environment variable
334 * is defined, use a default path of "/etc".
336 path
= getenv("FORMAT_PATH");
341 * Traverse the path one file at a time. Pick off
342 * the file name, and append the name "format.dat"
343 * at the end of the pathname.
344 * Whatever string we construct, duplicate it on the
345 * heap, so that file_name is globally accessible.
349 while (*path
!= 0 && *path
!= ':')
357 * If the path we have so far is a directory,
358 * look for a format.dat file in that directory,
359 * otherwise try using the path name specified.
360 * This permits arbitrary file names in the
361 * path specification, if this proves useful.
363 if (stat(fname
, &stbuf
) == -1) {
364 err_print("Unable to access '%s' - %s.\n",
365 fname
, strerror(errno
));
367 if (S_ISDIR(stbuf
.st_mode
)) {
370 (void) strcpy(p
, "format.dat");
372 file_name
= alloc_string(fname
);
380 * Check for duplicate disk or partitions definitions
381 * that are inconsistent - this would be very confusing.
383 search_duplicate_dtypes();
384 search_duplicate_pinfo();
389 * Open and process a format data file. Unfortunately, we use
390 * globals: file_name for the file name, and data_file
391 * for the descriptor. Return true if able to open the file.
401 * Open the data file. Return 0 if unable to do so.
403 data_file
= fopen(file_name
, "r");
404 if (data_file
== NULL
) {
408 * Step through the data file a meta-line at a time. There are
409 * typically several backslashed newlines in each meta-line,
410 * so data_lineno will be getting side effected along the way.
418 status
= sup_gettoken(token
);
420 * If we hit the end of the data file, we're done.
422 if (status
== SUP_EOF
)
425 * If the line is blank, skip it.
427 if (status
== SUP_EOL
)
430 * If the line starts with some key character, it's an error.
432 if (status
!= SUP_STRING
) {
433 datafile_error("Expecting keyword, found '%s'", token
);
437 * Clean up the token and see which keyword it is. Call
438 * the appropriate routine to process the rest of the line.
440 clean_token(cleaned
, token
);
441 if (strcmp(cleaned
, "search_path") == 0)
443 else if (strcmp(cleaned
, "disk_type") == 0)
445 else if (strcmp(cleaned
, "partition") == 0)
448 datafile_error("Unknown keyword '%s'", cleaned
);
452 * Close the data file.
454 (void) fclose(data_file
);
460 * This routine processes a 'search_path' line in the data file. The
461 * search path is a list of disk names that will be searched for by the
464 * The static path_size and path_alloc are used to build up the
465 * list of files comprising the search path. The static definitions
466 * enable supporting multiple search path definitions.
474 static int path_size
;
475 static int path_alloc
;
478 * Pull in some grammar.
480 status
= sup_gettoken(token
);
481 if (status
!= SUP_EQL
) {
482 datafile_error("Expecting '=', found '%s'", token
);
486 * Loop through the entries.
490 * Pull in the disk name.
492 status
= sup_gettoken(token
);
494 * If we hit end of line, we're done.
496 if (status
== SUP_EOL
)
499 * If we hit some key character, it's an error.
501 if (status
!= SUP_STRING
) {
502 datafile_error("Expecting value, found '%s'", token
);
505 clean_token(cleaned
, token
);
507 * Build the string into an argvlist. This array
508 * is dynamically sized, as necessary, and terminated
509 * with a null. Each name is alloc'ed on the heap,
510 * so no dangling references.
512 search_path
= build_argvlist(search_path
, &path_size
,
513 &path_alloc
, cleaned
);
515 * Pull in some grammar.
517 status
= sup_gettoken(token
);
518 if (status
== SUP_EOL
)
520 if (status
!= SUP_COMMA
) {
521 datafile_error("Expecting ', ', found '%s'", token
);
528 * This routine processes a 'disk_type' line in the data file. It defines
529 * the physical attributes of a brand of disk when connected to a specific
535 TOKEN token
, cleaned
, ident
;
538 struct disk_type
*dtype
, *type
;
539 struct ctlr_type
*ctype
;
540 char *dtype_name
, *ptr
;
541 struct mctlr_list
*mlp
;
544 * Pull in some grammar.
546 status
= sup_gettoken(token
);
547 if (status
!= SUP_EQL
) {
548 datafile_error("Expecting '=', found '%s'", token
);
552 * Pull in the name of the disk type.
554 status
= sup_gettoken(token
);
555 if (status
!= SUP_STRING
) {
556 datafile_error("Expecting value, found '%s'", token
);
559 clean_token(cleaned
, token
);
561 * Allocate space for the disk type and copy in the name.
563 dtype_name
= (char *)zalloc(strlen(cleaned
) + 1);
564 (void) strcpy(dtype_name
, cleaned
);
565 dtype
= (struct disk_type
*)zalloc(sizeof (struct disk_type
));
566 dtype
->dtype_asciilabel
= dtype_name
;
568 * Save the filename/linenumber where this disk was defined
570 dtype
->dtype_filename
= file_name
;
571 dtype
->dtype_lineno
= data_lineno
;
573 * Loop for each attribute.
577 * Pull in some grammar.
579 status
= sup_gettoken(token
);
581 * If we hit end of line, we're done.
583 if (status
== SUP_EOL
)
585 if (status
!= SUP_COLON
) {
586 datafile_error("Expecting ':', found '%s'", token
);
590 * Pull in the attribute.
592 status
= sup_gettoken(token
);
594 * If we hit end of line, we're done.
596 if (status
== SUP_EOL
)
599 * If we hit a key character, it's an error.
601 if (status
!= SUP_STRING
) {
602 datafile_error("Expecting keyword, found '%s'", token
);
605 clean_token(ident
, token
);
607 * Check to see if we've got a change specification
608 * If so, this routine will parse the entire
609 * specification, so just restart at top of loop
611 if (sup_change_spec(dtype
, ident
)) {
615 * Pull in more grammar.
617 status
= sup_gettoken(token
);
618 if (status
!= SUP_EQL
) {
619 datafile_error("Expecting '=', found '%s'", token
);
623 * Pull in the value of the attribute.
625 status
= sup_gettoken(token
);
626 if (status
!= SUP_STRING
) {
627 datafile_error("Expecting value, found '%s'", token
);
630 clean_token(cleaned
, token
);
632 * If the attribute defined the ctlr...
634 if (strcmp(ident
, "ctlr") == 0) {
636 * Match the value with a ctlr type.
640 while (mlp
!= NULL
) {
641 if (strcmp(mlp
->ctlr_type
->ctype_name
,
647 * If we couldn't match it, it's an error.
650 for (i
= 0; i
< OTHER_CTLRS
; i
++) {
651 if (strcmp(other_ctlrs
[i
], cleaned
)
653 datafile_error(NULL
, NULL
);
657 if (i
== OTHER_CTLRS
) {
659 "Unknown controller '%s'",
665 * Found a match. Add this disk type to the list
666 * for the ctlr type if we can complete the
667 * disk specification correctly.
669 ctype
= mlp
->ctlr_type
;
674 * All other attributes require a numeric value. Convert
675 * the value to a number.
677 val
= (int)strtol(cleaned
, &ptr
, 0);
679 datafile_error("Expecting an integer, found '%s'",
684 * Figure out which attribute it was and fill in the
685 * appropriate value. Also note that the attribute
688 if (strcmp(ident
, "ncyl") == 0) {
689 dtype
->dtype_ncyl
= val
;
691 } else if (strcmp(ident
, "acyl") == 0) {
692 dtype
->dtype_acyl
= val
;
694 } else if (strcmp(ident
, "pcyl") == 0) {
695 dtype
->dtype_pcyl
= val
;
697 } else if (strcmp(ident
, "nhead") == 0) {
698 dtype
->dtype_nhead
= val
;
700 } else if (strcmp(ident
, "nsect") == 0) {
701 dtype
->dtype_nsect
= val
;
703 } else if (strcmp(ident
, "rpm") == 0) {
704 dtype
->dtype_rpm
= val
;
706 } else if (strcmp(ident
, "bpt") == 0) {
707 dtype
->dtype_bpt
= val
;
709 } else if (strcmp(ident
, "bps") == 0) {
710 dtype
->dtype_bps
= val
;
712 } else if (strcmp(ident
, "drive_type") == 0) {
713 dtype
->dtype_dr_type
= val
;
715 } else if (strcmp(ident
, "cache") == 0) {
716 dtype
->dtype_cache
= val
;
718 } else if (strcmp(ident
, "prefetch") == 0) {
719 dtype
->dtype_threshold
= val
;
720 flags
|= SUP_PREFETCH
;
721 } else if (strcmp(ident
, "read_retries") == 0) {
722 dtype
->dtype_read_retries
= val
;
723 flags
|= SUP_READ_RETRIES
;
724 } else if (strcmp(ident
, "write_retries") == 0) {
725 dtype
->dtype_write_retries
= val
;
726 flags
|= SUP_WRITE_RETRIES
;
727 } else if (strcmp(ident
, "min_prefetch") == 0) {
728 dtype
->dtype_prefetch_min
= val
;
729 flags
|= SUP_CACHE_MIN
;
730 } else if (strcmp(ident
, "max_prefetch") == 0) {
731 dtype
->dtype_prefetch_max
= val
;
732 flags
|= SUP_CACHE_MAX
;
733 } else if (strcmp(ident
, "trks_zone") == 0) {
734 dtype
->dtype_trks_zone
= val
;
735 flags
|= SUP_TRKS_ZONE
;
736 } else if (strcmp(ident
, "atrks") == 0) {
737 dtype
->dtype_atrks
= val
;
739 } else if (strcmp(ident
, "asect") == 0) {
740 dtype
->dtype_asect
= val
;
742 } else if (strcmp(ident
, "psect") == 0) {
743 dtype
->dtype_psect
= val
;
745 } else if (strcmp(ident
, "phead") == 0) {
746 dtype
->dtype_phead
= val
;
748 } else if (strcmp(ident
, "fmt_time") == 0) {
749 dtype
->dtype_fmt_time
= val
;
750 flags
|= SUP_FMTTIME
;
751 } else if (strcmp(ident
, "cyl_skew") == 0) {
752 dtype
->dtype_cyl_skew
= val
;
753 flags
|= SUP_CYLSKEW
;
754 } else if (strcmp(ident
, "trk_skew") == 0) {
755 dtype
->dtype_trk_skew
= val
;
756 flags
|= SUP_TRKSKEW
;
758 datafile_error("Unknown keyword '%s'", ident
);
762 * Check to be sure all the necessary attributes have been defined.
763 * If any are missing, it's an error. Also, log options for later
764 * use by specific driver.
766 dtype
->dtype_options
= flags
;
767 if ((flags
& SUP_MIN_DRIVE
) != SUP_MIN_DRIVE
) {
768 datafile_error("Incomplete specification", "");
771 if ((!(ctype
->ctype_flags
& CF_SCSI
)) && (!(flags
& SUP_BPT
)) &&
772 (!(ctype
->ctype_flags
& CF_NOFORMAT
))) {
773 datafile_error("Incomplete specification", "");
776 if ((ctype
->ctype_flags
& CF_SMD_DEFS
) && (!(flags
& SUP_BPS
))) {
777 datafile_error("Incomplete specification", "");
781 * Add this disk type to the list for the ctlr type
783 assert(flags
& SUP_CTLR
);
784 type
= ctype
->ctype_dlist
;
786 ctype
->ctype_dlist
= dtype
;
788 while (type
->dtype_next
!= NULL
)
789 type
= type
->dtype_next
;
790 type
->dtype_next
= dtype
;
796 * Parse a SCSI mode page change specification.
799 * 0: not change specification, continue parsing
800 * 1: was change specification, it was ok,
801 * or we already handled the error.
804 sup_change_spec(struct disk_type
*disk
, char *id
)
819 * Syntax: p[<nn>|0x<xx>]
824 pageno
= (int)strtol(id
+1, &p2
, 0);
829 * Once we get this far, we know we have the
830 * beginnings of a change specification.
831 * If there's a problem now, report the problem,
832 * and return 1, so that the caller can restart
833 * parsing at the next expression.
835 if (!scsi_supported_page(pageno
)) {
836 datafile_error("Unsupported mode page '%s'", id
);
840 * Next token should be the byte offset
842 if (sup_gettoken(token
) != SUP_STRING
) {
843 datafile_error("Unexpected value '%s'", token
);
846 clean_token(ident
, token
);
849 * Syntax: b[<nn>|0x<xx>]
853 datafile_error("Unknown keyword '%s'", ident
);
856 byteno
= (int)strtol(p
, &p2
, 10);
858 datafile_error("Unknown keyword '%s'", ident
);
861 if (byteno
== 0 || byteno
== 1) {
862 datafile_error("Unsupported byte offset '%s'", ident
);
867 * Get the operator for this expression
869 mode
= CHG_MODE_UNDEFINED
;
870 switch (sup_gettoken(token
)) {
875 if (sup_gettoken(token
) == SUP_EQL
)
879 if (sup_gettoken(token
) == SUP_EQL
)
883 if (mode
== CHG_MODE_UNDEFINED
) {
884 datafile_error("Unexpected operator: '%s'", token
);
889 * Get right-hand of expression - accept optional tilde
892 if ((i
= sup_gettoken(token
)) == SUP_TILDE
) {
894 i
= sup_gettoken(token
);
896 if (i
!= SUP_STRING
) {
897 datafile_error("Expecting value, found '%s'", token
);
900 clean_token(ident
, token
);
901 value
= (int)strtol(ident
, &p
, 0);
903 datafile_error("Expecting value, found '%s'", token
);
908 * Apply the tilde operator, if found.
909 * Constrain to a byte value.
917 * We parsed a successful change specification expression.
918 * Add it to the list for this disk type.
920 cp
= new_chg_list(disk
);
930 * This routine processes a 'partition' line in the data file. It defines
931 * a known partition map for a particular disk type on a particular
937 TOKEN token
, cleaned
, disk
, ctlr
, ident
;
938 struct disk_type
*dtype
= NULL
;
939 struct ctlr_type
*ctype
= NULL
;
940 struct partition_info
*pinfo
, *parts
;
942 int i
, index
, status
, flags
= 0;
946 struct mctlr_list
*mlp
;
949 * Pull in some grammar.
951 status
= sup_gettoken(token
);
952 if (status
!= SUP_EQL
) {
953 datafile_error("Expecting '=', found '%s'", token
);
957 * Pull in the name of the map.
959 status
= sup_gettoken(token
);
960 if (status
!= SUP_STRING
) {
961 datafile_error("Expecting value, found '%s'", token
);
964 clean_token(cleaned
, token
);
966 * Allocate space for the partition map and fill in the name.
968 pinfo_name
= (char *)zalloc(strlen(cleaned
) + 1);
969 (void) strcpy(pinfo_name
, cleaned
);
970 pinfo
= (struct partition_info
*)zalloc(sizeof (struct partition_info
));
971 pinfo
->pinfo_name
= pinfo_name
;
973 * Save the filename/linenumber where this partition was defined
975 pinfo
->pinfo_filename
= file_name
;
976 pinfo
->pinfo_lineno
= data_lineno
;
979 * Install default vtoc information into the new partition table
981 set_vtoc_defaults(pinfo
);
984 * Loop for each attribute in the line.
988 * Pull in some grammar.
990 status
= sup_gettoken(token
);
992 * If we hit end of line, we're done.
994 if (status
== SUP_EOL
)
996 if (status
!= SUP_COLON
) {
997 datafile_error("Expecting ':', found '%s'", token
);
1001 * Pull in the attribute.
1003 status
= sup_gettoken(token
);
1005 * If we hit end of line, we're done.
1007 if (status
== SUP_EOL
)
1009 if (status
!= SUP_STRING
) {
1010 datafile_error("Expecting keyword, found '%s'", token
);
1013 clean_token(ident
, token
);
1015 * Pull in more grammar.
1017 status
= sup_gettoken(token
);
1018 if (status
!= SUP_EQL
) {
1019 datafile_error("Expecting '=', found '%s'", token
);
1023 * Pull in the value of the attribute.
1025 status
= sup_gettoken(token
);
1027 * If we hit a key character, it's an error.
1029 if (status
!= SUP_STRING
) {
1030 datafile_error("Expecting value, found '%s'", token
);
1033 clean_token(cleaned
, token
);
1035 * If the attribute is the ctlr, save the ctlr name and
1038 if (strcmp(ident
, "ctlr") == 0) {
1039 (void) strcpy(ctlr
, cleaned
);
1043 * If the attribute is the disk, save the disk name and
1046 } else if (strcmp(ident
, "disk") == 0) {
1047 (void) strcpy(disk
, cleaned
);
1052 * If we now know both the controller name and the
1053 * disk name, let's see if we can find the controller
1054 * and disk type. This will give us the geometry,
1055 * which can permit us to accept partitions specs
1056 * in cylinders or blocks.
1058 if (((flags
& (SUP_DISK
|SUP_CTLR
)) == (SUP_DISK
|SUP_CTLR
)) &&
1059 dtype
== NULL
&& ctype
== NULL
) {
1061 * Attempt to match the specified ctlr to a known type.
1065 while (mlp
!= NULL
) {
1066 if (strcmp(mlp
->ctlr_type
->ctype_name
,
1072 * If no match is found, it's an error.
1075 for (i
= 0; i
< OTHER_CTLRS
; i
++) {
1076 if (strcmp(other_ctlrs
[i
], ctlr
) == 0) {
1077 datafile_error(NULL
, NULL
);
1081 if (i
== OTHER_CTLRS
) {
1083 "Unknown controller '%s'", ctlr
);
1087 ctype
= mlp
->ctlr_type
;
1089 * Attempt to match the specified disk to a known type.
1091 for (dtype
= ctype
->ctype_dlist
; dtype
!= NULL
;
1092 dtype
= dtype
->dtype_next
) {
1093 if (strcmp(dtype
->dtype_asciilabel
, disk
) == 0)
1097 * If no match is found, it's an error.
1099 if (dtype
== NULL
) {
1100 datafile_error("Unknown disk '%s'", disk
);
1104 * Now that we know the disk type, set up the
1105 * globals that let that magic macro "spc()"
1106 * do it's thing. Sorry that this is glued
1107 * together so poorly...
1109 nhead
= dtype
->dtype_nhead
;
1110 nsect
= dtype
->dtype_nsect
;
1111 acyl
= dtype
->dtype_acyl
;
1112 ncyl
= dtype
->dtype_ncyl
;
1115 * By now, the disk and controller type must be defined
1117 if (dtype
== NULL
|| ctype
== NULL
) {
1118 datafile_error("Incomplete specification", "");
1122 * The rest of the attributes are all single letters.
1123 * Make sure the specified attribute is a single letter.
1125 if (strlen(ident
) != 1) {
1126 datafile_error("Unknown keyword '%s'", ident
);
1130 * Also make sure it is within the legal range of letters.
1132 if (ident
[0] < PARTITION_BASE
|| ident
[0] > PARTITION_BASE
+9) {
1133 datafile_error("Unknown keyword '%s'", ident
);
1137 * Here's the index of the partition we're dealing with
1139 index
= ident
[0] - PARTITION_BASE
;
1141 * For SunOS 5.0, we support the additional syntax:
1142 * [<tag>, ] [<flag>, ] <start>, <end>
1146 * <tag> may be one of: boot, root, swap, etc.
1147 * <flag> consists of two characters:
1148 * W (writable) or R (read-only)
1149 * M (mountable) or U (unmountable)
1151 * Start with the defaults assigned above:
1153 vtoc_tag
= pinfo
->vtoc
.v_part
[index
].p_tag
;
1154 vtoc_flag
= pinfo
->vtoc
.v_part
[index
].p_flag
;
1157 * First try to match token against possible tag values
1159 if (find_value(ptag_choices
, cleaned
, &i
) == 1) {
1161 * Found valid tag. Use it and advance parser
1163 vtoc_tag
= (ushort_t
)i
;
1164 status
= sup_gettoken(token
);
1165 if (status
!= SUP_COMMA
) {
1167 "Expecting ', ', found '%s'", token
);
1170 status
= sup_gettoken(token
);
1171 if (status
!= SUP_STRING
) {
1172 datafile_error("Expecting value, found '%s'",
1176 clean_token(cleaned
, token
);
1180 * Try to match token against possible flag values
1182 if (find_value(pflag_choices
, cleaned
, &i
) == 1) {
1184 * Found valid flag. Use it and advance parser
1186 vtoc_flag
= (ushort_t
)i
;
1187 status
= sup_gettoken(token
);
1188 if (status
!= SUP_COMMA
) {
1189 datafile_error("Expecting ', ', found '%s'",
1193 status
= sup_gettoken(token
);
1194 if (status
!= SUP_STRING
) {
1195 datafile_error("Expecting value, found '%s'",
1199 clean_token(cleaned
, token
);
1202 * All other attributes have a pair of numeric values.
1203 * Convert the first value to a number. This value
1204 * is the starting cylinder number of the partition.
1206 val1
= str2cyls(cleaned
);
1207 if (val1
== (uint_t
)(-1)) {
1208 datafile_error("Expecting an integer, found '%s'",
1213 * Pull in some grammar.
1215 status
= sup_gettoken(token
);
1216 if (status
!= SUP_COMMA
) {
1217 datafile_error("Expecting ', ', found '%s'", token
);
1221 * Pull in the second value.
1223 status
= sup_gettoken(token
);
1224 if (status
!= SUP_STRING
) {
1225 datafile_error("Expecting value, found '%s'", token
);
1228 clean_token(cleaned
, token
);
1230 * Convert the second value to a number. This value
1231 * is the number of blocks composing the partition.
1232 * If the token is terminated with a 'c', the units
1233 * are cylinders, not blocks. Also accept a 'b', if
1234 * they choose to be so specific.
1236 val2
= str2blks(cleaned
);
1237 if (val2
== (uint_t
)(-1)) {
1238 datafile_error("Expecting an integer, found '%s'",
1243 * Fill in the appropriate map entry with the values.
1245 pinfo
->pinfo_map
[index
].dkl_cylno
= val1
;
1246 pinfo
->pinfo_map
[index
].dkl_nblk
= val2
;
1247 pinfo
->vtoc
.v_part
[index
].p_tag
= vtoc_tag
;
1248 pinfo
->vtoc
.v_part
[index
].p_flag
= vtoc_flag
;
1250 #if defined(_SUNOS_VTOC_16)
1251 pinfo
->vtoc
.v_part
[index
].p_start
= val1
* (nhead
* nsect
);
1252 pinfo
->vtoc
.v_part
[index
].p_size
= val2
;
1255 pinfo
->vtoc
.v_part
[index
].p_tag
= 0;
1256 pinfo
->vtoc
.v_part
[index
].p_flag
= 0;
1257 pinfo
->vtoc
.v_part
[index
].p_start
= 0;
1258 pinfo
->pinfo_map
[index
].dkl_cylno
= 0;
1260 #endif /* defined(_SUNOS_VTOC_16) */
1264 * Check to be sure that all necessary attributes were defined.
1266 if ((flags
& SUP_MIN_PART
) != SUP_MIN_PART
) {
1267 datafile_error("Incomplete specification", "");
1271 * Add this partition map to the list of known maps for the
1272 * specified disk/ctlr.
1274 parts
= dtype
->dtype_plist
;
1276 dtype
->dtype_plist
= pinfo
;
1278 while (parts
->pinfo_next
!= NULL
)
1279 parts
= parts
->pinfo_next
;
1280 parts
->pinfo_next
= pinfo
;
1285 * Open the disk device - just a wrapper for open.
1288 open_disk(char *diskname
, int flags
)
1290 return (open(diskname
, flags
));
1294 * This routine performs the disk search during startup. It looks for
1295 * all the disks in the search path, and creates a list of those that
1299 do_search(char *arglist
[])
1305 char path
[MAXPATHLEN
];
1306 char curdir
[MAXPATHLEN
];
1307 char *directory
= "/dev/rdsk";
1308 struct disk_info
*disk
;
1312 * Change directory to the device directory. This
1313 * gives us the most efficient access to that directory.
1314 * Remember where we were, and return there when finished.
1316 if (getcwd(curdir
, sizeof (curdir
)) == NULL
) {
1317 err_print("Cannot get current directory - %s\n",
1321 if (chdir(directory
) == -1) {
1322 err_print("Cannot set directory to %s - %s\n",
1323 directory
, strerror(errno
));
1328 * If there were disks specified on the command line,
1329 * use those disks, and nothing but those disks.
1331 if (arglist
!= NULL
) {
1332 check_for_duplicate_disknames(arglist
);
1333 for (; *arglist
!= NULL
; arglist
++) {
1334 search_for_logical_dev(*arglist
);
1338 * If there were no disks specified on the command line,
1339 * search for all disks attached to the system.
1341 fmt_print("Searching for disks...");
1342 (void) fflush(stdout
);
1346 * Find all disks specified in search_path definitions
1347 * in whatever format.dat files were processed.
1351 while (*sp
!= NULL
) {
1352 search_for_logical_dev(*sp
++);
1357 * Open the device directory
1359 if ((dir
= opendir(".")) == NULL
) {
1360 err_print("Cannot open %s - %s\n",
1361 directory
, strerror(errno
));
1366 * Now find all usable nodes in /dev/rdsk (or /dev, if 4.x)
1367 * First find all nodes which do not conform to
1368 * standard disk naming conventions. This permits
1369 * all user-defined names to override the default names.
1371 while ((dp
= readdir(dir
)) != NULL
) {
1372 if (strcmp(dp
->d_name
, ".") == 0 ||
1373 strcmp(dp
->d_name
, "..") == 0)
1375 if (!conventional_name(dp
->d_name
)) {
1376 if (!fdisk_physical_name(dp
->d_name
)) {
1378 * If non-conventional name represents
1379 * a link to non-s2 slice , ignore it.
1381 if (!name_represents_wholedisk
1383 (void) strcpy(path
, directory
);
1384 (void) strcat(path
, "/");
1385 (void) strcat(path
, dp
->d_name
);
1386 add_device_to_disklist(
1396 * Now find all nodes corresponding to the standard
1397 * device naming conventions.
1399 while ((dp
= readdir(dir
)) != NULL
) {
1400 if (strcmp(dp
->d_name
, ".") == 0 ||
1401 strcmp(dp
->d_name
, "..") == 0)
1403 if (whole_disk_name(dp
->d_name
)) {
1404 (void) strcpy(path
, directory
);
1405 (void) strcat(path
, "/");
1406 (void) strcat(path
, dp
->d_name
);
1407 canonicalize_name(s
, dp
->d_name
);
1408 add_device_to_disklist(s
, path
);
1412 * Close the directory
1414 if (closedir(dir
) == -1) {
1415 err_print("Cannot close directory %s - %s\n",
1416 directory
, strerror(errno
));
1421 fmt_print("done\n");
1425 * Return to whence we came
1427 if (chdir(curdir
) == -1) {
1428 err_print("Cannot set directory to %s - %s\n",
1429 curdir
, strerror(errno
));
1434 * If we didn't find any disks, give up.
1436 if (disk_list
== NULL
) {
1437 if (geteuid() == 0) {
1438 err_print("No disks found!\n");
1440 err_print("No permission (or no disks found)!\n");
1442 (void) fflush(stdout
);
1449 * Tell user the results of the auto-configure process
1452 for (disk
= disk_list
; disk
!= NULL
; disk
= disk
->disk_next
) {
1455 struct disk_type
*type
;
1456 if (disk
->disk_flags
& DSK_AUTO_CONFIG
) {
1460 fmt_print("%s: ", disk
->disk_name
);
1461 if (disk
->disk_flags
& DSK_LABEL_DIRTY
) {
1462 fmt_print("configured ");
1464 fmt_print("configured and labeled ");
1466 type
= disk
->disk_type
;
1467 nblks
= type
->dtype_ncyl
* type
->dtype_nhead
*
1469 if (disk
->label_type
== L_TYPE_SOLARIS
)
1470 scaled
= bn2mb(nblks
);
1472 scaled
= bn2mb(type
->capacity
);
1473 fmt_print("with capacity of ");
1474 if (scaled
> 1024.0) {
1475 fmt_print("%1.2fGB\n", scaled
/1024.0);
1477 fmt_print("%1.2fMB\n", scaled
);
1485 * For a given "logical" disk name as specified in a format.dat
1486 * search path, try to find the device it actually refers to.
1487 * Since we are trying to maintain 4.x naming convention
1488 * compatibility in 5.0, this involves a little bit of work.
1489 * We also want to be able to function under 4.x, if needed.
1491 * canonical: standard name reference. append a partition
1492 * reference, and open that file in the device directory.
1493 * examples: SVR4: c0t0d0
1496 * absolute: begins with a '/', and is assumed to be an
1497 * absolute pathname to some node.
1499 * relative: non-canonical, doesn't begin with a '/'.
1500 * assumed to be the name of a file in the appropriate
1504 search_for_logical_dev(char *devname
)
1506 char path
[MAXPATHLEN
];
1507 char *directory
= "/dev/rdsk/";
1508 char *partition
= "s2";
1511 * If the name is an absolute path name, accept it as is
1513 if (*devname
== '/') {
1514 (void) strcpy(path
, devname
);
1515 } else if (canonical_name(devname
)) {
1517 * If canonical name, construct a standard path name.
1519 (void) strcpy(path
, directory
);
1520 (void) strcat(path
, devname
);
1521 (void) strcat(path
, partition
);
1522 } else if (canonical4x_name(devname
)) {
1524 * Check to see if it's a 4.x file name in the /dev
1525 * directory on 5.0. Here, we only accept the
1526 * canonicalized form: sd0.
1528 (void) strcpy(path
, "/dev/r");
1529 (void) strcat(path
, devname
);
1530 (void) strcat(path
, "c");
1533 * If it's not a canonical name, then it may be a
1534 * reference to an actual file name in the device
1537 (void) strcpy(path
, directory
);
1538 (void) strcat(path
, devname
);
1541 /* now add the device */
1542 add_device_to_disklist(devname
, path
);
1546 * Get the disk name from the inquiry data
1549 get_disk_name(int fd
, char *disk_name
, struct disk_info
*disk_info
)
1551 struct scsi_inquiry inquiry
;
1552 char *vid
, *pid
, *rid
;
1554 if (get_disk_inquiry_prop(disk_info
->devfs_name
, &vid
, &pid
, &rid
)
1556 (void) snprintf(disk_name
, MAXNAMELEN
- 1, "%s-%s-%s",
1565 if (uscsi_inquiry(fd
, (char *)&inquiry
, sizeof (inquiry
))) {
1567 err_print("\nInquiry failed - %s\n", strerror(errno
));
1568 (void) strcpy(disk_name
, "Unknown-Unknown-0001");
1572 (void) get_generic_disk_name(disk_name
, &inquiry
);
1576 * Add a device to the disk list, if it appears to be a disk,
1577 * and we haven't already found it under some other name.
1580 add_device_to_disklist(char *devname
, char *devpath
)
1582 struct disk_info
*search_disk
;
1583 struct ctlr_info
*search_ctlr
;
1584 struct disk_type
*search_dtype
, *efi_disk
;
1585 struct partition_info
*search_parts
;
1586 struct disk_info
*dptr
;
1587 struct ctlr_info
*cptr
;
1588 struct disk_type
*type
;
1589 struct partition_info
*parts
;
1590 struct dk_label search_label
;
1591 struct dk_cinfo dkinfo
;
1593 struct ctlr_type
*ctlr
, *tctlr
;
1594 struct mctlr_list
*mlp
;
1595 struct efi_info efi_info
;
1596 struct dk_minfo mediainfo
;
1600 int access_flags
= 0;
1601 char disk_name
[MAXNAMELEN
];
1604 * Attempt to open the disk. If it fails, skip it.
1606 if ((search_file
= open_disk(devpath
, O_RDWR
| O_NDELAY
)) < 0) {
1610 * Must be a character device
1612 if (fstat(search_file
, &stbuf
) == -1 || !S_ISCHR(stbuf
.st_mode
)) {
1613 (void) close(search_file
);
1617 * Attempt to read the configuration info on the disk.
1618 * Again, if it fails, we assume the disk's not there.
1619 * Note we must close the file for the disk before we
1622 if (ioctl(search_file
, DKIOCINFO
, &dkinfo
) < 0) {
1623 (void) close(search_file
);
1627 /* If it is a removable media, skip it. */
1630 int isremovable
, ret
;
1631 ret
= ioctl(search_file
, DKIOCREMOVABLE
, &isremovable
);
1632 if ((ret
>= 0) && (isremovable
!= 0)) {
1633 (void) close(search_file
);
1638 if (ioctl(search_file
, DKIOCGMEDIAINFO
, &mediainfo
) == -1) {
1639 cur_blksz
= DEV_BSIZE
;
1641 cur_blksz
= mediainfo
.dki_lbsize
;
1645 * If the type of disk is one we don't know about,
1646 * add it to the list.
1650 while (mlp
!= NULL
) {
1651 if (mlp
->ctlr_type
->ctype_ctype
== dkinfo
.dki_ctype
) {
1658 if (dkinfo
.dki_ctype
== DKC_CDROM
) {
1659 if (ioctl(search_file
, DKIOCGMEDIAINFO
,
1661 mediainfo
.dki_media_type
= DK_UNKNOWN
;
1665 * Skip CDROM devices, they are read only.
1666 * But not devices like Iomega Rev Drive which
1667 * identifies itself as a CDROM, but has a removable
1670 if ((dkinfo
.dki_ctype
== DKC_CDROM
) &&
1671 (mediainfo
.dki_media_type
!= DK_REMOVABLE_DISK
)) {
1672 (void) close(search_file
);
1676 * create the new ctlr_type structure and fill it in.
1678 tctlr
= zalloc(sizeof (struct ctlr_type
));
1679 tctlr
->ctype_ctype
= dkinfo
.dki_ctype
;
1680 tctlr
->ctype_name
= zalloc(DK_DEVLEN
);
1681 if (strlcpy(tctlr
->ctype_name
, dkinfo
.dki_cname
,
1682 DK_DEVLEN
) > DK_DEVLEN
) {
1684 * DKIOCINFO returned a controller name longer
1685 * than DK_DEVLEN bytes, which means more of the
1686 * dk_cinfo structure may be corrupt. We don't
1687 * allow the user to perform any operations on
1688 * the device in this case
1690 err_print("\nError: Device %s: controller "
1691 "name (%s)\nis invalid. Device will not "
1692 "be displayed.\n", devname
, dkinfo
.dki_cname
);
1693 (void) close(search_file
);
1694 destroy_data(tctlr
->ctype_name
);
1695 destroy_data((char *)tctlr
);
1698 tctlr
->ctype_ops
= zalloc(sizeof (struct ctlr_ops
));
1701 * copy the generic disk ops structure into local copy.
1703 *(tctlr
->ctype_ops
) = genericops
;
1705 tctlr
->ctype_flags
= CF_WLIST
;
1709 while (mlp
->next
!= NULL
) {
1713 mlp
->next
= zalloc(sizeof (struct mctlr_list
));
1714 mlp
->next
->ctlr_type
= tctlr
;
1719 * Search through all disks known at this time, to
1720 * determine if we're already identified this disk.
1721 * If so, then there's no need to include it a
1722 * second time. This permits the user-defined names
1723 * to supercede the standard conventional names.
1725 if (disk_is_known(&dkinfo
)) {
1726 (void) close(search_file
);
1731 * Because opening id with FNDELAY always succeeds,
1732 * read the label early on to see whether the device
1733 * really exists. A result of DSK_RESERVED
1734 * means the disk may be reserved.
1735 * In the future, it will be good
1736 * to move these into controller specific files and have a common
1737 * generic check for reserved disks here, including intel disks.
1739 if (dkinfo
.dki_ctype
== DKC_SCSI_CCS
) {
1742 first_sector
= zalloc(cur_blksz
);
1743 i
= scsi_rdwr(DIR_READ
, search_file
, (diskaddr_t
)0,
1744 1, first_sector
, F_SILENT
, NULL
);
1747 access_flags
|= DSK_RESERVED
;
1749 case DSK_UNAVAILABLE
:
1750 access_flags
|= DSK_UNAVAILABLE
;
1757 #endif /* defined(sparc) */
1760 * The disk appears to be present. Allocate space for the
1761 * disk structure and add it to the list of found disks.
1763 search_disk
= (struct disk_info
*)zalloc(sizeof (struct disk_info
));
1764 if (disk_list
== NULL
)
1765 disk_list
= search_disk
;
1767 for (dptr
= disk_list
; dptr
->disk_next
!= NULL
;
1768 dptr
= dptr
->disk_next
)
1770 dptr
->disk_next
= search_disk
;
1773 * Fill in some info from the ioctls.
1775 search_disk
->disk_dkinfo
= dkinfo
;
1776 if (is_efi_type(search_file
)) {
1777 search_disk
->label_type
= L_TYPE_EFI
;
1779 search_disk
->label_type
= L_TYPE_SOLARIS
;
1782 * Remember the names of the disk
1784 search_disk
->disk_name
= alloc_string(devname
);
1785 search_disk
->disk_path
= alloc_string(devpath
);
1788 * Remember the lba size of the disk
1790 search_disk
->disk_lbasize
= cur_blksz
;
1792 (void) strcpy(x86_devname
, devname
);
1795 * Determine if this device is linked to a physical name.
1797 search_disk
->devfs_name
= get_physical_name(devpath
);
1800 * Try to match the ctlr for this disk with a ctlr we
1801 * have already found. A match is assumed if the ctlrs
1802 * are at the same address && ctypes agree
1804 for (search_ctlr
= ctlr_list
; search_ctlr
!= NULL
;
1805 search_ctlr
= search_ctlr
->ctlr_next
)
1806 if (search_ctlr
->ctlr_addr
== dkinfo
.dki_addr
&&
1807 search_ctlr
->ctlr_space
== dkinfo
.dki_space
&&
1808 search_ctlr
->ctlr_ctype
->ctype_ctype
==
1812 * If no match was found, we need to identify this ctlr.
1814 if (search_ctlr
== NULL
) {
1816 * Match the type of the ctlr to a known type.
1820 while (mlp
!= NULL
) {
1821 if (mlp
->ctlr_type
->ctype_ctype
== dkinfo
.dki_ctype
)
1826 * If no match was found, it's an error.
1827 * Close the disk and report the error.
1830 err_print("\nError: found disk attached to ");
1831 err_print("unsupported controller type '%d'.\n",
1833 (void) close(search_file
);
1837 * Allocate space for the ctlr structure and add it
1838 * to the list of found ctlrs.
1840 search_ctlr
= (struct ctlr_info
*)
1841 zalloc(sizeof (struct ctlr_info
));
1842 search_ctlr
->ctlr_ctype
= mlp
->ctlr_type
;
1843 if (ctlr_list
== NULL
)
1844 ctlr_list
= search_ctlr
;
1846 for (cptr
= ctlr_list
; cptr
->ctlr_next
!= NULL
;
1847 cptr
= cptr
->ctlr_next
)
1849 cptr
->ctlr_next
= search_ctlr
;
1852 * Fill in info from the ioctl.
1854 for (i
= 0; i
< DK_DEVLEN
; i
++) {
1855 search_ctlr
->ctlr_cname
[i
] = dkinfo
.dki_cname
[i
];
1856 search_ctlr
->ctlr_dname
[i
] = dkinfo
.dki_dname
[i
];
1859 * Make sure these can be used as simple strings
1861 search_ctlr
->ctlr_cname
[i
] = 0;
1862 search_ctlr
->ctlr_dname
[i
] = 0;
1864 search_ctlr
->ctlr_flags
= dkinfo
.dki_flags
;
1865 search_ctlr
->ctlr_num
= dkinfo
.dki_cnum
;
1866 search_ctlr
->ctlr_addr
= dkinfo
.dki_addr
;
1867 search_ctlr
->ctlr_space
= dkinfo
.dki_space
;
1868 search_ctlr
->ctlr_prio
= dkinfo
.dki_prio
;
1869 search_ctlr
->ctlr_vec
= dkinfo
.dki_vec
;
1872 * By this point, we have a known ctlr. Link the disk
1875 search_disk
->disk_ctlr
= search_ctlr
;
1876 if (access_flags
& (DSK_RESERVED
| DSK_UNAVAILABLE
)) {
1877 if (access_flags
& DSK_RESERVED
)
1878 search_disk
->disk_flags
|= DSK_RESERVED
;
1880 search_disk
->disk_flags
|= DSK_UNAVAILABLE
;
1881 (void) close(search_file
);
1884 search_disk
->disk_flags
&= ~(DSK_RESERVED
| DSK_UNAVAILABLE
);
1888 * Attempt to read the primary label.
1889 * (Note that this is really through the DKIOCGVTOC
1890 * ioctl, then converted from vtoc to label.)
1892 if (search_disk
->label_type
== L_TYPE_SOLARIS
) {
1893 status
= read_label(search_file
, &search_label
);
1895 status
= read_efi_label(search_file
, &efi_info
, search_disk
);
1898 * If reading the label failed, and this is a SCSI
1899 * disk, we can attempt to auto-sense the disk
1902 ctlr
= search_ctlr
->ctlr_ctype
;
1903 if ((status
== -1) && (ctlr
->ctype_ctype
== DKC_SCSI_CCS
)) {
1904 if (option_msg
&& diag_msg
) {
1905 err_print("%s: attempting auto configuration\n",
1906 search_disk
->disk_name
);
1909 switch (search_disk
->label_type
) {
1910 case (L_TYPE_SOLARIS
):
1911 if (auto_sense(search_file
, 0, &search_label
) != NULL
) {
1913 * Auto config worked, so we now have
1914 * a valid label for the disk. Mark
1915 * the disk as needing the label flushed.
1918 search_disk
->disk_flags
|=
1919 (DSK_LABEL_DIRTY
| DSK_AUTO_CONFIG
);
1923 efi_disk
= auto_efi_sense(search_file
, &efi_info
);
1924 if (efi_disk
!= NULL
) {
1926 * Auto config worked, so we now have
1927 * a valid label for the disk.
1930 search_disk
->disk_flags
|=
1931 (DSK_LABEL_DIRTY
| DSK_AUTO_CONFIG
);
1935 /* Should never happen */
1941 * If we didn't successfully read the label, or the label
1942 * appears corrupt, just leave the disk as an unknown type.
1945 (void) close(search_file
);
1949 if (search_disk
->label_type
== L_TYPE_SOLARIS
) {
1950 if (!checklabel(&search_label
)) {
1951 (void) close(search_file
);
1954 if (trim_id(search_label
.dkl_asciilabel
)) {
1955 (void) close(search_file
);
1960 * The label looks ok. Mark the disk as labeled.
1962 search_disk
->disk_flags
|= DSK_LABEL
;
1964 if (search_disk
->label_type
== L_TYPE_EFI
) {
1965 search_dtype
= (struct disk_type
*)
1966 zalloc(sizeof (struct disk_type
));
1967 type
= search_ctlr
->ctlr_ctype
->ctype_dlist
;
1969 search_ctlr
->ctlr_ctype
->ctype_dlist
=
1972 while (type
->dtype_next
!= NULL
) {
1973 type
= type
->dtype_next
;
1975 type
->dtype_next
= search_dtype
;
1977 search_dtype
->dtype_next
= NULL
;
1979 search_dtype
->vendor
= strdup(efi_info
.vendor
);
1980 search_dtype
->product
= strdup(efi_info
.product
);
1981 search_dtype
->revision
= strdup(efi_info
.revision
);
1983 if (search_dtype
->vendor
== NULL
||
1984 search_dtype
->product
== NULL
||
1985 search_dtype
->revision
== NULL
) {
1986 free(search_dtype
->vendor
);
1987 free(search_dtype
->product
);
1988 free(search_dtype
->revision
);
1993 search_dtype
->capacity
= efi_info
.capacity
;
1994 search_disk
->disk_type
= search_dtype
;
1996 search_parts
= (struct partition_info
*)
1997 zalloc(sizeof (struct partition_info
));
1998 search_dtype
->dtype_plist
= search_parts
;
2000 search_parts
->pinfo_name
= alloc_string("original");
2001 search_parts
->pinfo_next
= NULL
;
2002 search_parts
->etoc
= efi_info
.e_parts
;
2003 search_disk
->disk_parts
= search_parts
;
2006 * Copy the volume name, if present
2008 for (i
= 0; i
< search_parts
->etoc
->efi_nparts
; i
++) {
2009 if (search_parts
->etoc
->efi_parts
[i
].p_tag
==
2011 if (search_parts
->etoc
->efi_parts
[i
].p_name
) {
2012 bcopy(search_parts
->etoc
->efi_parts
[i
]
2013 .p_name
, search_disk
->v_volume
,
2016 bzero(search_disk
->v_volume
,
2023 (void) close(search_file
);
2025 free(efi_info
.vendor
);
2026 free(efi_info
.product
);
2027 free(efi_info
.revision
);
2032 * Attempt to match the disk type in the label with a
2035 for (search_dtype
= search_ctlr
->ctlr_ctype
->ctype_dlist
;
2036 search_dtype
!= NULL
;
2037 search_dtype
= search_dtype
->dtype_next
)
2038 if (dtype_match(&search_label
, search_dtype
))
2041 * If no match was found, we need to create a disk type
2044 if (search_dtype
== NULL
) {
2046 * Allocate space for the disk type and add it
2047 * to the list of disk types for this ctlr type.
2049 search_dtype
= (struct disk_type
*)
2050 zalloc(sizeof (struct disk_type
));
2051 type
= search_ctlr
->ctlr_ctype
->ctype_dlist
;
2053 search_ctlr
->ctlr_ctype
->ctype_dlist
=
2056 while (type
->dtype_next
!= NULL
)
2057 type
= type
->dtype_next
;
2058 type
->dtype_next
= search_dtype
;
2061 * Fill in the drive info from the disk label.
2063 search_dtype
->dtype_next
= NULL
;
2064 if (strncmp(search_label
.dkl_asciilabel
, "DEFAULT",
2065 strlen("DEFAULT")) == 0) {
2066 (void) get_disk_name(search_file
, disk_name
,
2068 search_dtype
->dtype_asciilabel
= (char *)
2069 zalloc(strlen(disk_name
) + 1);
2070 (void) strcpy(search_dtype
->dtype_asciilabel
,
2073 search_dtype
->dtype_asciilabel
= (char *)
2074 zalloc(strlen(search_label
.dkl_asciilabel
) + 1);
2075 (void) strcpy(search_dtype
->dtype_asciilabel
,
2076 search_label
.dkl_asciilabel
);
2078 search_dtype
->dtype_pcyl
= search_label
.dkl_pcyl
;
2079 search_dtype
->dtype_ncyl
= search_label
.dkl_ncyl
;
2080 search_dtype
->dtype_acyl
= search_label
.dkl_acyl
;
2081 search_dtype
->dtype_nhead
= search_label
.dkl_nhead
;
2082 search_dtype
->dtype_nsect
= search_label
.dkl_nsect
;
2083 search_dtype
->dtype_rpm
= search_label
.dkl_rpm
;
2085 * Mark the disk as needing specification of
2086 * ctlr specific attributes. This is necessary
2087 * because the label doesn't contain these attributes,
2088 * and they aren't known at this point. They will
2089 * be asked for if this disk is ever selected by
2091 * Note: for SCSI, we believe the label.
2093 if ((search_ctlr
->ctlr_ctype
->ctype_ctype
!= DKC_SCSI_CCS
) &&
2094 (search_ctlr
->ctlr_ctype
->ctype_ctype
!= DKC_DIRECT
) &&
2095 (search_ctlr
->ctlr_ctype
->ctype_ctype
!= DKC_VBD
) &&
2096 (search_ctlr
->ctlr_ctype
->ctype_ctype
!= DKC_PCMCIA_ATA
) &&
2097 (search_ctlr
->ctlr_ctype
->ctype_ctype
!= DKC_BLKDEV
)) {
2098 search_dtype
->dtype_flags
|= DT_NEED_SPEFS
;
2102 * By this time we have a known disk type. Link the disk
2105 search_disk
->disk_type
= search_dtype
;
2108 * Close the file for this disk
2110 (void) close(search_file
);
2113 * Attempt to match the partition map in the label with
2114 * a known partition map for this disk type.
2116 for (search_parts
= search_dtype
->dtype_plist
;
2117 search_parts
!= NULL
;
2118 search_parts
= search_parts
->pinfo_next
)
2119 if (parts_match(&search_label
, search_parts
)) {
2123 * If no match was made, we need to create a partition
2124 * map for this disk.
2126 if (search_parts
== NULL
) {
2128 * Allocate space for the partition map and add
2129 * it to the list of maps for this disk type.
2131 search_parts
= (struct partition_info
*)
2132 zalloc(sizeof (struct partition_info
));
2133 parts
= search_dtype
->dtype_plist
;
2135 search_dtype
->dtype_plist
= search_parts
;
2137 while (parts
->pinfo_next
!= NULL
)
2138 parts
= parts
->pinfo_next
;
2139 parts
->pinfo_next
= search_parts
;
2141 search_parts
->pinfo_next
= NULL
;
2143 * Fill in the name of the map with a name derived
2144 * from the name of this disk. This is necessary
2145 * because the label contains no name for the
2148 search_parts
->pinfo_name
= alloc_string("original");
2150 * Fill in the partition info from the disk label.
2152 for (i
= 0; i
< NDKMAP
; i
++) {
2154 #if defined(_SUNOS_VTOC_8)
2155 search_parts
->pinfo_map
[i
] =
2156 search_label
.dkl_map
[i
];
2158 #elif defined(_SUNOS_VTOC_16)
2159 search_parts
->pinfo_map
[i
].dkl_cylno
=
2160 search_label
.dkl_vtoc
.v_part
[i
].p_start
/
2161 ((blkaddr32_t
)(search_label
.dkl_nhead
*
2162 search_label
.dkl_nsect
));
2163 search_parts
->pinfo_map
[i
].dkl_nblk
=
2164 search_label
.dkl_vtoc
.v_part
[i
].p_size
;
2167 #error No VTOC format defined.
2172 * If the vtoc looks valid, copy the volume name and vtoc
2173 * info from the label. Otherwise, install a default vtoc.
2174 * This permits vtoc info to automatically appear in the sun
2175 * label, without requiring an upgrade procedure.
2177 if (search_label
.dkl_vtoc
.v_version
== V_VERSION
) {
2178 bcopy(search_label
.dkl_vtoc
.v_volume
,
2179 search_disk
->v_volume
, LEN_DKL_VVOL
);
2180 search_parts
->vtoc
= search_label
.dkl_vtoc
;
2182 bzero(search_disk
->v_volume
, LEN_DKL_VVOL
);
2183 set_vtoc_defaults(search_parts
);
2186 * By this time we have a known partitition map. Link the
2187 * disk to the partition map.
2189 search_disk
->disk_parts
= search_parts
;
2194 * Search the disk list for a disk with the identical configuration.
2195 * Return true if one is found.
2198 disk_is_known(struct dk_cinfo
*dkinfo
)
2200 struct disk_info
*dp
;
2203 while (dp
!= NULL
) {
2204 if (dp
->disk_dkinfo
.dki_ctype
== dkinfo
->dki_ctype
&&
2205 dp
->disk_dkinfo
.dki_cnum
== dkinfo
->dki_cnum
&&
2206 dp
->disk_dkinfo
.dki_unit
== dkinfo
->dki_unit
&&
2207 strcmp(dp
->disk_dkinfo
.dki_dname
, dkinfo
->dki_dname
) == 0) {
2217 * This routine checks to see if a given disk type matches the type
2218 * in the disk label.
2221 dtype_match(label
, dtype
)
2222 register struct dk_label
*label
;
2223 register struct disk_type
*dtype
;
2226 if (dtype
->dtype_asciilabel
== NULL
) {
2231 * If the any of the physical characteristics are different, or
2232 * the name is different, it doesn't match.
2234 if ((strcmp(label
->dkl_asciilabel
, dtype
->dtype_asciilabel
) != 0) ||
2235 (label
->dkl_ncyl
!= dtype
->dtype_ncyl
) ||
2236 (label
->dkl_acyl
!= dtype
->dtype_acyl
) ||
2237 (label
->dkl_nhead
!= dtype
->dtype_nhead
) ||
2238 (label
->dkl_nsect
!= dtype
->dtype_nsect
)) {
2242 * If those are all identical, assume it's a match.
2248 * This routine checks to see if a given partition map matches the map
2249 * in the disk label.
2252 parts_match(label
, pinfo
)
2253 register struct dk_label
*label
;
2254 register struct partition_info
*pinfo
;
2259 * If any of the partition entries is different, it doesn't match.
2261 for (i
= 0; i
< NDKMAP
; i
++)
2263 #if defined(_SUNOS_VTOC_8)
2264 if ((label
->dkl_map
[i
].dkl_cylno
!=
2265 pinfo
->pinfo_map
[i
].dkl_cylno
) ||
2266 (label
->dkl_map
[i
].dkl_nblk
!=
2267 pinfo
->pinfo_map
[i
].dkl_nblk
))
2269 #elif defined(_SUNOS_VTOC_16)
2270 if ((pinfo
->pinfo_map
[i
].dkl_cylno
!=
2271 label
->dkl_vtoc
.v_part
[i
].p_start
/
2272 (label
->dkl_nhead
* label
->dkl_nsect
)) ||
2273 (pinfo
->pinfo_map
[i
].dkl_nblk
!=
2274 label
->dkl_vtoc
.v_part
[i
].p_size
))
2276 #error No VTOC format defined.
2280 * Compare the vtoc information for a match
2281 * Do not require the volume name to be equal, for a match!
2283 if (label
->dkl_vtoc
.v_version
!= pinfo
->vtoc
.v_version
)
2285 if (label
->dkl_vtoc
.v_nparts
!= pinfo
->vtoc
.v_nparts
)
2287 for (i
= 0; i
< NDKMAP
; i
++) {
2288 if (label
->dkl_vtoc
.v_part
[i
].p_tag
!=
2289 pinfo
->vtoc
.v_part
[i
].p_tag
)
2291 if (label
->dkl_vtoc
.v_part
[i
].p_flag
!=
2292 pinfo
->vtoc
.v_part
[i
].p_flag
)
2296 * If they are all identical, it's a match.
2302 * This routine checks to see if the given disk name refers to the disk
2303 * in the given disk structure.
2306 diskname_match(char *name
, struct disk_info
*disk
)
2308 struct dk_cinfo dkinfo
;
2313 * Match the name of the disk in the disk_info structure
2315 if (strcmp(name
, disk
->disk_name
) == 0) {
2320 * Check to see if it's a 4.x file name in the /dev
2321 * directory on 5.0. Here, we only accept the
2322 * canonicalized form: sd0.
2324 if (canonical4x_name(name
) == 0) {
2328 (void) strcpy(s
, "/dev/r");
2329 (void) strcat(s
, name
);
2330 (void) strcat(s
, "c");
2332 if ((fd
= open_disk(s
, O_RDWR
| O_NDELAY
)) < 0) {
2336 if (ioctl(fd
, DKIOCINFO
, &dkinfo
) < 0) {
2342 if (disk
->disk_dkinfo
.dki_ctype
== dkinfo
.dki_ctype
&&
2343 disk
->disk_dkinfo
.dki_cnum
== dkinfo
.dki_cnum
&&
2344 disk
->disk_dkinfo
.dki_unit
== dkinfo
.dki_unit
&&
2345 strcmp(disk
->disk_dkinfo
.dki_dname
, dkinfo
.dki_dname
) == 0) {
2353 datafile_error(char *errmsg
, char *token
)
2359 * Allow us to get by controllers that the other platforms don't
2362 if (errmsg
!= NULL
) {
2363 err_print(errmsg
, token
);
2364 err_print(" - %s (%d)\n", file_name
, data_lineno
);
2368 * Re-sync the parsing at the beginning of the next line
2369 * unless of course we're already there.
2371 if (last_token_type
!= SUP_EOF
&& last_token_type
!= SUP_EOL
) {
2373 token_type
= sup_gettoken(token_buf
);
2374 } while (token_type
!= SUP_EOF
&& token_type
!= SUP_EOL
);
2376 if (token_type
== SUP_EOF
) {
2377 sup_pushtoken(token_buf
, token_type
);
2384 * Search through all defined disk types for duplicate entries
2385 * that are inconsistent with each other. Disks with different
2386 * characteristics should be named differently.
2387 * Note that this function only checks for duplicate disks
2388 * for the same controller. It's possible to have two disks with
2389 * the same name, but defined for different controllers.
2390 * That may or may not be a problem...
2393 search_duplicate_dtypes()
2395 struct disk_type
*dp1
;
2396 struct disk_type
*dp2
;
2397 struct mctlr_list
*mlp
;
2401 while (mlp
!= NULL
) {
2402 dp1
= mlp
->ctlr_type
->ctype_dlist
;
2403 while (dp1
!= NULL
) {
2404 dp2
= dp1
->dtype_next
;
2405 while (dp2
!= NULL
) {
2406 check_dtypes_for_inconsistency(dp1
, dp2
);
2407 dp2
= dp2
->dtype_next
;
2409 dp1
= dp1
->dtype_next
;
2417 * Search through all defined partition types for duplicate entries
2418 * that are inconsistent with each other. Partitions with different
2419 * characteristics should be named differently.
2420 * Note that this function only checks for duplicate partitions
2421 * for the same disk. It's possible to have two partitions with
2422 * the same name, but defined for different disks.
2423 * That may or may not be a problem...
2426 search_duplicate_pinfo()
2428 struct disk_type
*dp
;
2429 struct partition_info
*pp1
;
2430 struct partition_info
*pp2
;
2431 struct mctlr_list
*mlp
;
2435 while (mlp
!= NULL
) {
2436 dp
= mlp
->ctlr_type
->ctype_dlist
;
2437 while (dp
!= NULL
) {
2438 pp1
= dp
->dtype_plist
;
2439 while (pp1
!= NULL
) {
2440 pp2
= pp1
->pinfo_next
;
2441 while (pp2
!= NULL
) {
2442 check_pinfo_for_inconsistency(pp1
, pp2
);
2443 pp2
= pp2
->pinfo_next
;
2445 pp1
= pp1
->pinfo_next
;
2447 dp
= dp
->dtype_next
;
2455 * Determine if two particular disk definitions are inconsistent.
2456 * Ie: same name, but different characteristics.
2457 * If so, print an error message and abort.
2460 check_dtypes_for_inconsistency(dp1
, dp2
)
2461 struct disk_type
*dp1
;
2462 struct disk_type
*dp2
;
2466 struct chg_list
*cp1
;
2467 struct chg_list
*cp2
;
2471 * If the name's different, we're ok
2473 if (strcmp(dp1
->dtype_asciilabel
, dp2
->dtype_asciilabel
) != 0) {
2478 * Compare all the disks' characteristics
2481 result
|= (dp1
->dtype_flags
!= dp2
->dtype_flags
);
2482 result
|= (dp1
->dtype_options
!= dp2
->dtype_options
);
2483 result
|= (dp1
->dtype_fmt_time
!= dp2
->dtype_fmt_time
);
2484 result
|= (dp1
->dtype_bpt
!= dp2
->dtype_bpt
);
2485 result
|= (dp1
->dtype_ncyl
!= dp2
->dtype_ncyl
);
2486 result
|= (dp1
->dtype_acyl
!= dp2
->dtype_acyl
);
2487 result
|= (dp1
->dtype_pcyl
!= dp2
->dtype_pcyl
);
2488 result
|= (dp1
->dtype_nhead
!= dp2
->dtype_nhead
);
2489 result
|= (dp1
->dtype_nsect
!= dp2
->dtype_nsect
);
2490 result
|= (dp1
->dtype_rpm
!= dp2
->dtype_rpm
);
2491 result
|= (dp1
->dtype_cyl_skew
!= dp2
->dtype_cyl_skew
);
2492 result
|= (dp1
->dtype_trk_skew
!= dp2
->dtype_trk_skew
);
2493 result
|= (dp1
->dtype_trks_zone
!= dp2
->dtype_trks_zone
);
2494 result
|= (dp1
->dtype_atrks
!= dp2
->dtype_atrks
);
2495 result
|= (dp1
->dtype_asect
!= dp2
->dtype_asect
);
2496 result
|= (dp1
->dtype_cache
!= dp2
->dtype_cache
);
2497 result
|= (dp1
->dtype_threshold
!= dp2
->dtype_threshold
);
2498 result
|= (dp1
->dtype_read_retries
!= dp2
->dtype_read_retries
);
2499 result
|= (dp1
->dtype_write_retries
!= dp2
->dtype_write_retries
);
2500 result
|= (dp1
->dtype_prefetch_min
!= dp2
->dtype_prefetch_min
);
2501 result
|= (dp1
->dtype_prefetch_max
!= dp2
->dtype_prefetch_max
);
2502 for (i
= 0; i
< NSPECIFICS
; i
++) {
2503 result
|= (dp1
->dtype_specifics
[i
] != dp2
->dtype_specifics
[i
]);
2506 cp1
= dp1
->dtype_chglist
;
2507 cp2
= dp2
->dtype_chglist
;
2508 while (cp1
!= NULL
&& cp2
!= NULL
) {
2509 if (cp1
== NULL
|| cp2
== NULL
) {
2513 result
|= (cp1
->pageno
!= cp2
->pageno
);
2514 result
|= (cp1
->byteno
!= cp2
->byteno
);
2515 result
|= (cp1
->mode
!= cp2
->mode
);
2516 result
|= (cp1
->value
!= cp2
->value
);
2522 err_print("Inconsistent definitions for disk type '%s'\n",
2523 dp1
->dtype_asciilabel
);
2524 if (dp1
->dtype_filename
!= NULL
&&
2525 dp2
->dtype_filename
!= NULL
) {
2526 err_print("%s (%d) - %s (%d)\n",
2527 dp1
->dtype_filename
, dp1
->dtype_lineno
,
2528 dp2
->dtype_filename
, dp2
->dtype_lineno
);
2536 * Determine if two particular partition definitions are inconsistent.
2537 * Ie: same name, but different characteristics.
2538 * If so, print an error message and abort.
2541 check_pinfo_for_inconsistency(pp1
, pp2
)
2542 struct partition_info
*pp1
;
2543 struct partition_info
*pp2
;
2547 struct dk_map32
*map1
;
2548 struct dk_map32
*map2
;
2550 #if defined(_SUNOS_VTOC_8)
2551 struct dk_map2
*vp1
;
2552 struct dk_map2
*vp2
;
2554 #elif defined(_SUNOS_VTOC_16)
2555 struct dkl_partition
*vp1
;
2556 struct dkl_partition
*vp2
;
2558 #error No VTOC layout defined.
2559 #endif /* defined(_SUNOS_VTOC_8) */
2562 * If the name's different, we're ok
2564 if (strcmp(pp1
->pinfo_name
, pp2
->pinfo_name
) != 0) {
2569 * Compare all the partitions' characteristics
2572 map1
= pp1
->pinfo_map
;
2573 map2
= pp2
->pinfo_map
;
2574 for (i
= 0; i
< NDKMAP
; i
++, map1
++, map2
++) {
2575 result
|= (map1
->dkl_cylno
!= map2
->dkl_cylno
);
2576 result
|= (map1
->dkl_nblk
!= map2
->dkl_nblk
);
2580 * Compare the significant portions of the vtoc information
2582 vp1
= pp1
->vtoc
.v_part
;
2583 vp2
= pp2
->vtoc
.v_part
;
2584 for (i
= 0; i
< NDKMAP
; i
++, vp1
++, vp2
++) {
2585 result
|= (vp1
->p_tag
!= vp2
->p_tag
);
2586 result
|= (vp1
->p_flag
!= vp2
->p_flag
);
2590 err_print("Inconsistent definitions for partition type '%s'\n",
2592 if (pp1
->pinfo_filename
!= NULL
&&
2593 pp2
->pinfo_filename
!= NULL
) {
2594 err_print("%s (%d) - %s (%d)\n",
2595 pp1
->pinfo_filename
, pp1
->pinfo_lineno
,
2596 pp2
->pinfo_filename
, pp2
->pinfo_lineno
);
2603 * Convert a string of digits into a block number.
2604 * The digits are assumed to be a block number unless the
2605 * the string is terminated by 'c', in which case it is
2606 * assumed to be in units of cylinders. Accept a 'b'
2607 * to explictly specify blocks, for consistency.
2609 * NB: uses the macro spc(), which requires that the
2610 * globals nhead/nsect/acyl be set up correctly.
2612 * Returns -1 in the case of an error.
2620 blks
= (int)strtol(str
, &p
, 0);
2622 * Check what terminated the conversion.
2626 * Units specifier of 'c': convert cylinders to blocks
2630 blks
= blks
* spc();
2632 * Ignore a 'b' specifier.
2634 } else if (*p
== 'b') {
2638 * Anthing left over is an error
2648 * Convert a string of digits into a cylinder number.
2649 * Accept a an optional 'c' specifier, for consistency.
2651 * Returns -1 in the case of an error.
2659 cyls
= (int)strtol(str
, &p
, 0);
2661 * Check what terminated the conversion.
2665 * Units specifier of 'c': accept it.
2671 * Anthing left over is an error
2683 * Create a new chg_list structure, and append it onto the
2684 * end of the current chg_list under construction. By
2685 * applying changes in the order in which listed in the
2686 * data file, the changes we make are deterministic.
2687 * Return a pointer to the new structure, so that the
2688 * caller can fill in the appropriate information.
2690 static struct chg_list
*
2691 new_chg_list(struct disk_type
*disk
)
2693 struct chg_list
*cp
;
2694 struct chg_list
*nc
;
2696 nc
= zalloc(sizeof (struct chg_list
));
2698 if (disk
->dtype_chglist
== NULL
) {
2699 disk
->dtype_chglist
= nc
;
2701 for (cp
= disk
->dtype_chglist
; cp
->next
; cp
= cp
->next
)
2711 * Follow symbolic links from the logical device name to
2712 * the /devfs physical device name. To be complete, we
2713 * handle the case of multiple links. This function
2714 * either returns NULL (no links, or some other error),
2715 * or the physical device name, alloc'ed on the heap.
2717 * Note that the standard /devices prefix is stripped from
2718 * the final pathname, if present. The trailing options
2719 * are also removed (":c, raw").
2722 get_physical_name(char *path
)
2729 char buf
[MAXPATHLEN
];
2730 char dir
[MAXPATHLEN
];
2731 char savedir
[MAXPATHLEN
];
2732 char *result
= NULL
;
2734 if (getcwd(savedir
, sizeof (savedir
)) == NULL
) {
2735 err_print("getcwd() failed - %s\n", strerror(errno
));
2739 (void) strcpy(s
, path
);
2740 if ((p
= strrchr(s
, '/')) != NULL
) {
2744 (void) strcpy(s
, "/");
2746 if (chdir(s
) == -1) {
2747 err_print("cannot chdir() to %s - %s\n",
2748 s
, strerror(errno
));
2753 (void) strcpy(s
, path
);
2756 * See if there's a real file out there. If not,
2757 * we have a dangling link and we ignore it.
2759 if (stat(s
, &stbuf
) == -1) {
2762 if (lstat(s
, &stbuf
) == -1) {
2763 err_print("%s: lstat() failed - %s\n",
2764 s
, strerror(errno
));
2768 * If the file is not a link, we're done one
2769 * way or the other. If there were links,
2770 * return the full pathname of the resulting
2773 if (!S_ISLNK(stbuf
.st_mode
)) {
2776 * Strip trailing options from the
2777 * physical device name
2779 if ((p
= strrchr(s
, ':')) != NULL
) {
2783 * Get the current directory, and
2784 * glue the pieces together.
2786 if (getcwd(dir
, sizeof (dir
)) == NULL
) {
2787 err_print("getcwd() failed - %s\n",
2791 (void) strcat(dir
, "/");
2792 (void) strcat(dir
, s
);
2794 * If we have the standard fixed
2795 * /devices prefix, remove it.
2797 p
= (strstr(dir
, DEVFS_PREFIX
) == dir
) ?
2798 dir
+strlen(DEVFS_PREFIX
) : dir
;
2799 result
= alloc_string(p
);
2803 i
= readlink(s
, buf
, sizeof (buf
));
2805 err_print("%s: readlink() failed - %s\n",
2806 s
, strerror(errno
));
2813 * Break up the pathname into the directory
2814 * reference, if applicable and simple filename.
2815 * chdir()'ing to the directory allows us to
2816 * handle links with relative pathnames correctly.
2818 (void) strcpy(dir
, buf
);
2819 if ((p
= strrchr(dir
, '/')) != NULL
) {
2821 if (chdir(dir
) == -1) {
2822 err_print("cannot chdir() to %s - %s\n",
2823 dir
, strerror(errno
));
2826 (void) strcpy(s
, p
+1);
2828 (void) strcpy(s
, buf
);
2833 if (chdir(savedir
) == -1) {
2834 err_print("cannot chdir() to %s - %s\n",
2835 savedir
, strerror(errno
));
2846 struct disk_info
**disks
;
2847 struct disk_info
*d
;
2848 struct disk_info
**dp
;
2849 struct disk_info
**dp2
;
2852 * Count the number of disks in the list
2855 for (d
= disk_list
; d
!= NULL
; d
= d
->disk_next
) {
2863 * Allocate a simple disk list array and fill it in
2865 disks
= (struct disk_info
**)
2866 zalloc((n
+1) * sizeof (struct disk_info
*));
2869 for (d
= disk_list
; d
!= NULL
; d
= d
->disk_next
) {
2875 * Sort the disk list array
2877 qsort((void *) disks
, n
, sizeof (struct disk_info
*),
2881 * Rebuild the linked list disk list structure
2887 (*dp
++)->disk_next
= *dp2
++;
2888 } while (*dp
!= NULL
);
2893 (void) destroy_data((void *)disks
);
2898 * Compare two disk names
2912 s1
= (*((struct disk_info
**)arg1
))->disk_name
;
2913 s2
= (*((struct disk_info
**)arg2
))->disk_name
;
2916 if (*s1
== 0 || *s2
== 0)
2918 if (isdigit(*s1
) && isdigit(*s2
)) {
2919 n1
= strtol(s1
, &p1
, 10);
2920 n2
= strtol(s2
, &p2
, 10);
2926 } else if (*s1
!= *s2
) {
2938 make_controller_list()
2941 struct mctlr_list
*ctlrp
;
2945 for (x
= nctypes
; x
!= 0; x
--) {
2946 ctlrp
= zalloc(sizeof (struct mctlr_list
));
2947 ctlrp
->next
= controlp
;
2948 ctlrp
->ctlr_type
= &ctlr_types
[x
- 1];
2955 check_for_duplicate_disknames(arglist
)
2958 char *directory
= "/dev/rdsk/";
2961 char s
[MAXPATHLEN
], t
[MAXPATHLEN
];
2966 len
= strlen(directory
);
2968 for (; *disklist
!= NULL
; disklist
++) {
2969 if (strncmp(directory
, *disklist
, len
) == 0) {
2970 /* Disk is in conventional format */
2971 canonicalize_name(s
, *disklist
);
2973 * check if the disk is already present in
2976 for (i
= 0; i
< diskno
; i
++) {
2977 canonicalize_name(t
, arglist
[i
]);
2978 if (strncmp(s
, t
, strlen(t
)) == 0)
2984 (void) strcpy(arglist
[diskno
], *disklist
);
2987 arglist
[diskno
] = NULL
;
2990 #define DISK_PREFIX "/dev/rdsk/"
2993 * This Function checks if the non-conventional name is a a link to
2994 * one of the conventional whole disk name.
2997 name_represents_wholedisk(char *name
)
2999 char symname
[MAXPATHLEN
];
3000 char localname
[MAXPATHLEN
];
3002 ssize_t symname_size
;
3004 if (strlcpy(localname
, name
, MAXPATHLEN
) >= MAXPATHLEN
)
3005 return (1); /* buffer overflow, reject this name */
3007 while ((symname_size
= readlink(
3008 localname
, symname
, MAXPATHLEN
- 1)) != -1) {
3009 symname
[symname_size
] = '\0';
3011 if (strncmp(symname
, DISK_PREFIX
,
3012 (sizeof (DISK_PREFIX
) - 1)) == 0)
3013 nameptr
+= (sizeof (DISK_PREFIX
) - 1);
3015 if (conventional_name(nameptr
)) {
3016 if (whole_disk_name(nameptr
))
3022 (void) strcpy(localname
, symname
);