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 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
28 * This file contains I/O related functions.
39 #include <sys/termio.h>
40 #include <sys/termios.h>
44 #include "menu_partition.h"
49 extern int data_lineno
;
50 extern char *space2str();
54 * This variable is used to determine whether a token is present in the pipe
57 static char token_present
= 0;
60 * This variable always gives us access to the most recent token type
62 int last_token_type
= 0;
66 * Prototypes for ANSI C compilers
68 static int sup_get_token(char *);
69 static void pushchar(int c
);
70 static int checkeof(void);
71 static void flushline(void);
72 static int strcnt(char *s1
, char *s2
);
73 static int getbn(char *str
, diskaddr_t
*iptr
);
74 static void print_input_choices(int type
, u_ioparam_t
*param
);
75 static int slist_widest_str(slist_t
*slist
);
76 static void ljust_print(char *str
, int width
);
77 static int sup_inputchar(void);
78 static void sup_pushchar(int c
);
79 static int geti64(char *str
, uint64_t *iptr
, uint64_t *wild
);
83 * Prototypes for non-ANSI C compilers
86 static int sup_get_token();
87 static void pushchar(int c
);
88 static int checkeof(void);
89 static void flushline(void);
90 static int strcnt(char *s1
, char *s2
);
91 static int getbn(char *str
, diskaddr_t
*iptr
);
92 static void print_input_choices(int type
, u_ioparam_t
*param
);
93 static int slist_widest_str(slist_t
*slist
);
94 static void ljust_print(char *str
, int width
);
95 static int sup_inputchar(void);
96 static void sup_pushchar(int c
);
97 static int geti64(char *str
, uint64_t *iptr
, uint64_t *wild
);
103 * This routine pushes the given character back onto the input stream.
109 (void) ungetc(c
, stdin
);
113 * This routine checks the input stream for an eof condition.
118 return (feof(stdin
));
122 * This routine gets the next token off the input stream. A token is
123 * basically any consecutive non-white characters.
134 * Remove any leading white-space.
136 while ((isspace(c
= getchar())) && (c
!= '\n'))
139 * If we are at the beginning of a line and hit the comment character,
140 * flush the line and start again.
142 if (!token_present
&& c
== COMMENT_CHAR
) {
148 * Loop on each character until we hit unquoted white-space.
150 while (!isspace(c
) || quoted
&& (c
!= '\n')) {
152 * If we hit eof, get out.
157 * If we hit a double quote, change the state of quotedness.
162 * If there's room in the buffer, add the character to the end.
164 else if (ptr
- inbuf
< TOKEN_SIZE
)
167 * Get the next character.
172 * Null terminate the token.
176 * Peel off white-space still in the pipe.
178 while (isspace(c
) && (c
!= '\n'))
181 * If we hit another token, push it back and set state.
195 * This routine removes the leading and trailing spaces from a token.
198 clean_token(cleantoken
, token
)
199 char *cleantoken
, *token
;
204 * Strip off leading white-space.
206 for (ptr
= token
; isspace(*ptr
); ptr
++)
209 * Copy it into the clean buffer.
211 (void) strcpy(cleantoken
, ptr
);
213 * Strip off trailing white-space.
215 for (ptr
= cleantoken
+ strlen(cleantoken
) - 1;
216 isspace(*ptr
) && (ptr
>= cleantoken
); ptr
--) {
222 * This routine checks if a token is already present on the input line
227 return (token_present
);
231 * This routine flushes the rest of an input line if there is known
232 * to be data in it. The flush has to be qualified because the newline
233 * may have already been swallowed by the last gettoken.
240 * Flush the pipe to eol or eof.
242 while ((getchar() != '\n') && !checkeof())
245 * Mark the pipe empty.
252 * This routine returns the number of characters that are identical
253 * between s1 and s2, stopping as soon as a mismatch is found.
261 while ((*s1
!= '\0') && (*s1
++ == *s2
++))
267 * This routine converts the given token into an integer. The token
268 * must convert cleanly into an integer with no unknown characters.
269 * If the token is the wildcard string, and the wildcard parameter
270 * is present, the wildcard value will be returned.
273 geti(str
, iptr
, wild
)
280 * If there's a wildcard value and the string is wild, return the
283 if (wild
!= NULL
&& strcmp(str
, WILD_STRING
) == 0)
287 * Conver the string to an integer.
289 *iptr
= (int)strtol(str
, &str2
, 0);
291 * If any characters didn't convert, it's an error.
294 err_print("`%s' is not an integer.\n", str
);
302 * This routine converts the given token into a long long. The token
303 * must convert cleanly into a 64-bit integer with no unknown characters.
304 * If the token is the wildcard string, and the wildcard parameter
305 * is present, the wildcard value will be returned.
308 geti64(str
, iptr
, wild
)
310 uint64_t *iptr
, *wild
;
315 * If there's a wildcard value and the string is wild, return the
318 if ((wild
!= NULL
) && (strcmp(str
, WILD_STRING
)) == 0) {
322 * Conver the string to an integer.
324 *iptr
= (uint64_t)strtoll(str
, &str2
, 0);
326 * If any characters didn't convert, it's an error.
329 err_print("`%s' is not an integer.\n", str
);
337 * This routine converts the given string into a block number on the
338 * current disk. The format of a block number is either a self-based
339 * number, or a series of self-based numbers separated by slashes.
340 * Any number preceeding the first slash is considered a cylinder value.
341 * Any number succeeding the first slash but preceeding the second is
342 * considered a head value. Any number succeeding the second slash is
343 * considered a sector value. Any of these numbers can be wildcarded
344 * to the highest possible legal value.
351 char *cptr
, *hptr
, *sptr
;
358 * Set cylinder pointer to beginning of string.
362 * Look for the first slash.
364 while ((*str
!= '\0') && (*str
!= '/'))
367 * If there wasn't one, convert string to an integer and return it.
370 wild64
= physsects() - 1;
371 if (geti64(cptr
, iptr
, &wild64
))
376 * Null out the slash and set head pointer just beyond it.
381 * Look for the second slash.
383 while ((*str
!= '\0') && (*str
!= '/'))
386 * If there wasn't one, sector pointer points to a .
391 * If there was, null it out and set sector point just beyond it.
398 * Convert the cylinder part to an integer and store it.
400 clean_token(buf
, cptr
);
401 wild
= ncyl
+ acyl
- 1;
402 if (geti(buf
, &cyl
, &wild
))
404 if ((cyl
< 0) || (cyl
>= (ncyl
+ acyl
))) {
405 err_print("`%d' is out of range.\n", cyl
);
409 * Convert the head part to an integer and store it.
411 clean_token(buf
, hptr
);
413 if (geti(buf
, &head
, &wild
))
415 if ((head
< 0) || (head
>= nhead
)) {
416 err_print("`%d' is out of range.\n", head
);
420 * Convert the sector part to an integer and store it.
422 clean_token(buf
, sptr
);
423 wild
= sectors(head
) - 1;
424 if (geti(buf
, §
, &wild
))
426 if ((sect
< 0) || (sect
>= sectors(head
))) {
427 err_print("`%d' is out of range.\n", sect
);
431 * Combine the pieces into a block number and return it.
433 *iptr
= chs2bn(cyl
, head
, sect
);
438 * This routine is the basis for all input into the program. It
439 * understands the semantics of a set of input types, and provides
440 * consistent error messages for all input. It allows for default
441 * values and prompt strings.
444 input(type
, promptstr
, delim
, param
, deflt
, cmdflag
)
452 int interactive
, help
, i
, length
, index
, tied
;
455 char **str
, **strings
;
456 TOKEN token
, cleantoken
;
457 TOKEN token2
, cleantoken2
;
459 struct bounds
*bounds
;
466 char shell_argv
[MAXPATHLEN
];
467 part_deflt_t
*part_deflt
;
468 efi_deflt_t
*efi_deflt
;
471 * Optional integer input has been added as a hack.
472 * Function result is 1 if user typed anything.
473 * Whatever they typed is returned in *deflt.
474 * This permits us to distinguish between "no value",
475 * and actually entering in some value, for instance.
477 if (type
== FIO_OPINT
) {
478 assert(deflt
!= NULL
);
481 help
= interactive
= 0;
483 * If we are inputting a command, flush any current input in the pipe.
485 if (cmdflag
== CMD_INPUT
)
488 * Note whether the token is already present.
495 fmt_print(promptstr
);
497 * If there is a default value, print it in a format appropriate
498 * for the input type.
503 fmt_print("[%llu, ", *(diskaddr_t
*)deflt
);
504 pr_dblock(fmt_print
, *(diskaddr_t
*)deflt
);
508 fmt_print("[%d]", *deflt
);
511 efi_deflt
= (efi_deflt_t
*)deflt
;
512 fmt_print("[%llu]", efi_deflt
->start_sector
);
516 strings
= (char **)param
->io_charlist
;
517 for (i
= 0, str
= strings
; i
< *deflt
; i
++, str
++)
519 fmt_print("[%s]", *str
);
522 fmt_print("[\"%s\"]", (char *)deflt
);
526 * Search for a string matching the default
527 * value. If found, use it. Otherwise
528 * assume the default value is actually
529 * an illegal choice, and default to
530 * the first item in the list.
532 s
= find_string(param
->io_slist
, *deflt
);
534 s
= (param
->io_slist
)->str
;
536 fmt_print("[%s]", s
);
540 * Old-style partition size input, used to
541 * modify complete partition tables
543 blokno
= *(blkaddr32_t
*)deflt
;
544 fmt_print("[%llub, %uc, %1.2fmb, %1.2fgb]", blokno
,
545 bn2c(blokno
), bn2mb(blokno
), bn2gb(blokno
));
549 * set up pointer to partition defaults
552 part_deflt
= (part_deflt_t
*)deflt
;
555 * Build print format specifier. We use the
556 * starting cylinder number which was entered
557 * before this call to input(), in case the
558 * user has changed it from the value in the
559 * cur_parts->pinfo_map[].dkl_cylno
560 * field for the current parition
564 * Determine the proper default end cylinder:
565 * Start Cyl Default Size End Cylinder
575 if (part_deflt
->deflt_size
== 0) {
576 cylno
= part_deflt
->start_cyl
;
577 } else if (part_deflt
->start_cyl
== 0) {
578 cylno
= bn2c(part_deflt
->deflt_size
) - 1;
580 cylno
= (bn2c(part_deflt
->deflt_size
) +
581 part_deflt
->start_cyl
) - 1;
584 fmt_print("[%ub, %uc, %de, %1.2fmb, %1.2fgb]",
585 part_deflt
->deflt_size
,
586 bn2c(part_deflt
->deflt_size
),
588 bn2mb(part_deflt
->deflt_size
),
589 bn2gb(part_deflt
->deflt_size
));
593 efi_deflt
= (efi_deflt_t
*)deflt
;
595 fmt_print("[%llub, %llue, %llumb, %llugb, %llutb]",
596 efi_deflt
->end_sector
,
597 efi_deflt
->start_sector
+ efi_deflt
->end_sector
- 1,
598 (efi_deflt
->end_sector
* cur_blksz
) /
600 (efi_deflt
->end_sector
* cur_blksz
) /
601 (1024 * 1024 * 1024),
602 (efi_deflt
->end_sector
* cur_blksz
) /
603 ((uint64_t)1024 * 1024 * 1024 * 1024));
606 /* no default value for optional input type */
607 fmt_print("[default]");
610 err_print("Error: unknown input type.\n");
615 * Print the delimiter character.
617 fmt_print("%c ", delim
);
619 * Get the token. If we hit eof, exit the program gracefully.
621 if (gettoken(token
) == NULL
)
625 * check if the user has issued (!) , escape to shell
627 if ((cmdflag
== CMD_INPUT
) && (token
[0] == '!')) {
629 /* get the list of arguments to shell command */
630 (void) memset(shell_argv
, 0, sizeof (shell_argv
));
632 /* initialize to the first token... */
636 * ... and then collect all tokens until the end of
637 * the line as arguments
640 /* skip empty tokens. */
644 * If either of the following two strlcat()
645 * operations overflows, report an error and
648 if ((strlcat(shell_argv
, arg
, sizeof (shell_argv
)) >=
649 sizeof (shell_argv
)) ||
650 (strlcat(shell_argv
, " ", sizeof (shell_argv
)) >=
651 sizeof (shell_argv
))) {
652 err_print("Error: Command line too long.\n");
655 } while (token_present
&& (arg
= gettoken(token
)) != NULL
);
657 /* execute the shell command */
658 (void) execute_shell(shell_argv
, sizeof (shell_argv
));
659 redisplay_menu_list((char **)param
->io_charlist
);
666 * Certain commands accept up to two tokens
667 * Unfortunately, this is kind of a hack.
671 if (type
== FIO_CYL
|| type
== FIO_ECYL
) {
673 if (gettoken(token2
) == NULL
)
675 clean_token(cleantoken2
, token2
);
679 * Echo the token back to the user if it was in the pipe or we
680 * are running out of a command file.
682 if (!interactive
|| option_f
) {
683 if (token2
[0] == 0) {
684 fmt_print("%s\n", token
);
686 fmt_print("%s %s\n", token
, token2
);
690 * If we are logging, echo the token to the log file. The else
691 * is necessary here because the above printf will also put the
692 * token in the log file.
695 log_print("%s %s\n", token
, token2
);
698 * If the token was not in the pipe and it wasn't a command, flush
699 * the rest of the line to keep things in sync.
701 if (interactive
&& cmdflag
!= CMD_INPUT
)
704 * Scrub off the white-space.
706 clean_token(cleantoken
, token
);
708 * If the input was a blank line and we weren't prompting
709 * specifically for a blank line...
711 if ((strcmp(cleantoken
, "") == 0) && (type
!= FIO_BLNK
)) {
713 * If there's a default, return it.
716 if (type
== FIO_OSTR
) {
718 * Duplicate and return the default string
720 return ((int)alloc_string((char *)deflt
));
721 } else if (type
== FIO_SLIST
) {
723 * If we can find a match for the default
724 * value in the list, return the default
725 * value. If there's no match for the
726 * default value, it's an illegal
727 * choice. Return the first value in
730 s
= find_string(param
->io_slist
, *deflt
);
731 if ((cur_label
== L_TYPE_EFI
) &&
736 return ((param
->io_slist
)->value
);
740 } else if (type
== FIO_OPINT
) {
742 * The user didn't enter anything
745 } else if (type
== FIO_ECYL
) {
746 return (part_deflt
->deflt_size
);
747 } else if (type
== FIO_INT64
) {
748 return (efi_deflt
->start_sector
);
749 } else if (type
== FIO_EFI
) {
750 return (efi_deflt
->end_sector
);
756 * If the blank was not in the pipe, just reprompt.
762 * If the blank was in the pipe, it's an error.
764 err_print("No default for this entry.\n");
768 * If token is a '?' or a 'h', it is a request for help.
770 if ((strcmp(cleantoken
, "?") == 0) ||
771 (strcmp(cleantoken
, "h") == 0) ||
772 (strcmp(cleantoken
, "help") == 0)) {
776 * Switch on the type of input expected.
780 * Expecting a disk block number.
784 * Parameter is the bounds of legal block numbers.
786 bounds
= (struct bounds
*)¶m
->io_bounds
;
788 * Print help message if required.
791 fmt_print("Expecting a block number from %llu (",
793 pr_dblock(fmt_print
, bounds
->lower
);
794 fmt_print(") to %llu (", bounds
->upper
);
795 pr_dblock(fmt_print
, bounds
->upper
);
800 * Convert token to a disk block number.
802 if (cur_label
== L_TYPE_EFI
) {
803 if (geti64(cleantoken
, (uint64_t *)&bn64
,
807 if (getbn(cleantoken
, &bn64
))
811 * Check to be sure it is within the legal bounds.
813 if ((bn64
< bounds
->lower
) || (bn64
> bounds
->upper
)) {
815 pr_dblock(err_print
, bn64
);
816 err_print("' is out of range.\n");
820 * It's ok, return it.
824 * Expecting an integer.
828 * Parameter is the bounds of legal integers.
830 bounds
= (struct bounds
*)¶m
->io_bounds
;
832 * Print help message if required.
835 fmt_print("Expecting an integer from %llu",
837 fmt_print(" to %llu\n", bounds
->upper
);
841 * Convert the token into an integer.
843 if (geti(cleantoken
, (int *)&bn
, NULL
))
846 * Check to be sure it is within the legal bounds.
848 if ((bn
< bounds
->lower
) || (bn
> bounds
->upper
)) {
849 err_print("`%lu' is out of range.\n", bn
);
853 * If it's ok, return it.
858 * Parameter is the bounds of legal integers.
860 bounds
= (struct bounds
*)¶m
->io_bounds
;
862 * Print help message if required.
865 fmt_print("Expecting an integer from %llu",
867 fmt_print(" to %llu\n", bounds
->upper
);
871 * Convert the token into an integer.
873 if (geti64(cleantoken
, (uint64_t *)&bn64
, (uint64_t *)NULL
)) {
877 * Check to be sure it is within the legal bounds.
879 if ((bn64
< bounds
->lower
) || (bn64
> bounds
->upper
)) {
880 err_print("`%llu' is out of range.\n", bn64
);
884 * If it's ok, return it.
888 * Expecting an integer, or no input.
892 * Parameter is the bounds of legal integers.
894 bounds
= (struct bounds
*)¶m
->io_bounds
;
896 * Print help message if required.
899 fmt_print("Expecting an integer from %llu",
901 fmt_print(" to %llu, or no input\n", bounds
->upper
);
905 * Convert the token into an integer.
907 if (geti(cleantoken
, (int *)&bn
, NULL
))
910 * Check to be sure it is within the legal bounds.
912 if ((bn
< bounds
->lower
) || (bn
> bounds
->upper
)) {
913 err_print("`%lu' is out of range.\n", bn
);
917 * For optional case, return 1 indicating that
918 * the user actually did enter something.
924 * Expecting a closed string. This means that the input
925 * string must exactly match one of the strings passed in
930 * The parameter is a null terminated array of character
931 * pointers, each one pointing to a legal input string.
933 strings
= (char **)param
->io_charlist
;
935 * Walk through the legal strings, seeing if any of them
936 * match the token. If a match is made, return the index
937 * of the string that was matched.
939 for (str
= strings
; *str
!= NULL
; str
++)
940 if (strcmp(cleantoken
, *str
) == 0)
941 return (str
- strings
);
943 * Print help message if required.
946 print_input_choices(type
, param
);
948 err_print("`%s' is not expected.\n", cleantoken
);
952 * Expecting a matched string. This means that the input
953 * string must either match one of the strings passed in,
954 * or be a unique abbreviation of one of them.
958 * The parameter is a null terminated array of character
959 * pointers, each one pointing to a legal input string.
961 strings
= (char **)param
->io_charlist
;
962 length
= index
= tied
= 0;
964 * Loop through the legal input strings.
966 for (str
= strings
; *str
!= NULL
; str
++) {
968 * See how many characters of the token match
971 i
= strcnt(cleantoken
, *str
);
973 * If it's not the whole token, then it's not a match.
975 if ((uint_t
)i
< strlen(cleantoken
))
978 * If it ties with another input, remember that.
983 * If it matches the most so far, record that.
986 index
= str
- strings
;
992 * Print help message if required.
996 print_input_choices(type
, param
);
998 err_print("`%s' is not expected.\n",
1004 * If the abbreviation was non-unique, it's an error.
1007 err_print("`%s' is ambiguous.\n", cleantoken
);
1011 * We matched one. Return the index of the string we matched.
1015 * Expecting an open string. This means that any string is legal.
1019 * Print a help message if required.
1022 fmt_print("Expecting a string\n");
1026 * alloc a copy of the string and return it
1028 return ((int)alloc_string(token
));
1031 * Expecting a blank line.
1035 * We are always in non-echo mode when we are inputting
1036 * this type. We echo the newline as a carriage return
1037 * only so the prompt string will be covered over.
1039 nolog_print("\015");
1041 * If we are logging, send a newline to the log file.
1046 * There is no value returned for this type.
1051 * Expecting one of the entries in a string list.
1052 * Accept unique abbreviations.
1053 * Return the value associated with the matched string.
1056 i
= find_value((slist_t
*)param
->io_slist
,
1057 cleantoken
, &value
);
1062 * Print help message if required.
1066 print_input_choices(type
, param
);
1069 err_print("`%s' not expected.\n",
1072 err_print("`%s' is ambiguous.\n",
1079 * Cylinder size input when modifying a complete partition map
1083 * Parameter is the bounds of legal block numbers.
1085 bounds
= (struct bounds
*)¶m
->io_bounds
;
1086 assert(bounds
->lower
== 0);
1088 * Print help message if required.
1091 fmt_print("Expecting up to %llu blocks,",
1093 fmt_print(" %u cylinders, ", bn2c(bounds
->upper
));
1094 fmt_print(" %1.2f megabytes, ", bn2mb(bounds
->upper
));
1095 fmt_print("or %1.2f gigabytes\n", bn2gb(bounds
->upper
));
1099 * Parse the first token: try to find 'b', 'c' or 'm'
1102 while (*s
&& (isdigit(*s
) || (*s
== '.') || (*s
== '$'))) {
1106 * If we found a conversion specifier, second token is unused
1107 * Otherwise, the second token should supply it.
1113 value
= cleantoken2
[0];
1116 * If the token is the wild card, simply supply the max
1117 * This order allows the user to specify the maximum in
1118 * either blocks/cyls/megabytes - a convenient fiction.
1120 if (strcmp(cleantoken
, WILD_STRING
) == 0) {
1121 return (bounds
->upper
);
1124 * Allow the user to specify zero with no units,
1125 * by just defaulting to cylinders.
1127 if (strcmp(cleantoken
, "0") == 0) {
1131 * If there's a decimal point, but no unit specification,
1132 * let's assume megabytes.
1134 if ((value
== 0) && (strchr(cleantoken
, '.') != NULL
)) {
1138 * Handle each unit type we support
1143 * Convert token to a disk block number.
1145 if (geti64(cleantoken
, &bn64
, &bounds
->upper
))
1148 * Check to be sure it is within the legal bounds.
1150 if ((bn64
< bounds
->lower
) || (bn64
> bounds
->upper
)) {
1152 "`%llub' is out of the range %llu "
1154 bn64
, bounds
->lower
, bounds
->upper
);
1158 * Verify the block lies on a cylinder boundary
1160 if ((bn64
% spc()) != 0) {
1162 "partition size must be a multiple of "
1163 "%u blocks to lie on a cylinder boundary\n",
1166 "%llu blocks is approximately %u cylinders,"
1167 " %1.2f megabytes or %1.2f gigabytes\n",
1168 bn64
, bn2c(bn64
), bn2mb(bn64
), bn2gb(bn64
));
1174 * Convert token from a number of cylinders to
1175 * a number of blocks.
1177 i
= bn2c(bounds
->upper
);
1178 if (geti(cleantoken
, &cyls
, &i
))
1181 * Check the bounds - cyls is number of cylinders
1183 if (cyls
> (bounds
->upper
/spc())) {
1184 err_print("`%dc' is out of range\n", cyls
);
1188 * Convert cylinders to blocks and return
1190 return (cyls
* spc());
1193 * Convert token from megabytes to a block number.
1195 if (sscanf(cleantoken
, "%f2", &nmegs
) != 1) {
1196 err_print("`%s' is not recognized\n",
1203 if (nmegs
> bn2mb(bounds
->upper
)) {
1204 err_print("`%1.2fmb' is out of range\n", nmegs
);
1210 bn64
= mb2bn(nmegs
);
1212 * Round value up to nearest cylinder
1215 bn64
= ((bn64
+ (i
-1)) / i
) * i
;
1219 * Convert token from gigabytes to a block number.
1221 if (sscanf(cleantoken
, "%f2", &ngigs
) != 1) {
1222 err_print("`%s' is not recognized\n",
1229 if (ngigs
> bn2gb(bounds
->upper
)) {
1230 err_print("`%1.2fgb' is out of range\n", ngigs
);
1236 bn64
= gb2bn(ngigs
);
1238 * Round value up to nearest cylinder
1241 bn64
= ((bn64
+ (i
-1)) / i
) * i
;
1245 "Please specify units in either b(blocks), c(cylinders), m(megabytes) \
1246 or g(gigabytes)\n");
1253 * Parameter is the bounds of legal block numbers.
1255 bounds
= (struct bounds
*)¶m
->io_bounds
;
1256 assert(bounds
->lower
== 0);
1259 * Print help message if required.
1262 fmt_print("Expecting up to %llu blocks,",
1264 fmt_print(" %u cylinders, ",
1265 bn2c(bounds
->upper
));
1266 fmt_print(" %u end cylinder, ",
1267 (uint_t
)(bounds
->upper
/ spc()));
1268 fmt_print(" %1.2f megabytes, ",
1269 bn2mb(bounds
->upper
));
1270 fmt_print("or %1.2f gigabytes\n",
1271 bn2gb(bounds
->upper
));
1276 * Parse the first token: try to find 'b', 'c', 'e'
1280 while (*s
&& (isdigit(*s
) || (*s
== '.') || (*s
== '$'))) {
1285 * If we found a conversion specifier, second token is
1286 * unused Otherwise, the second token should supply it.
1292 value
= cleantoken2
[0];
1296 * If the token is the wild card, simply supply the max
1297 * This order allows the user to specify the maximum in
1298 * either blocks/cyls/megabytes - a convenient fiction.
1300 if (strcmp(cleantoken
, WILD_STRING
) == 0) {
1301 return (bounds
->upper
);
1305 * Allow the user to specify zero with no units,
1306 * by just defaulting to cylinders.
1309 if (value
!= 'e' && strcmp(cleantoken
, "0") == 0) {
1315 * If there's a decimal point, but no unit
1316 * specification, let's assume megabytes.
1318 if ((value
== 0) && (strchr(cleantoken
, '.') != NULL
)) {
1323 * Handle each unit type we support
1328 * Convert token to a disk block number.
1330 if (geti64(cleantoken
, &bn64
, &bounds
->upper
))
1333 * Check to be sure it is within the
1336 if ((bn64
< bounds
->lower
) || (bn64
> bounds
->upper
)) {
1338 "`%llub' is out of the range %llu to %llu\n",
1339 bn64
, bounds
->lower
, bounds
->upper
);
1344 * Verify the block lies on a cylinder
1347 if ((bn64
% spc()) != 0) {
1349 "partition size must be a multiple of %u "
1350 "blocks to lie on a cylinder boundary\n",
1353 "%llu blocks is approximately %u cylinders,"
1354 " %1.2f megabytes or %1.2f gigabytes\n",
1355 bn64
, bn2c(bn64
), bn2mb(bn64
), bn2gb(bn64
));
1363 * Token is ending cylinder
1366 /* convert token to integer */
1367 if (geti(cleantoken
, &cylno
, NULL
)) {
1372 * check that input cylno isn't before the current
1373 * starting cylinder number. Note that we are NOT
1374 * using the starting cylinder from
1375 * cur_parts->pinfo_map[].dkl_cylno!
1377 if (cylno
< part_deflt
->start_cyl
) {
1379 "End cylinder must fall on or after start cylinder %u\n",
1380 part_deflt
->start_cyl
);
1385 * calculate cylinder number of upper boundary, and
1386 * verify that our input is within range
1388 i
= (bn2c(bounds
->upper
) + part_deflt
->start_cyl
- 1);
1392 "End cylinder %d is beyond max cylinder %d\n",
1398 * calculate number of cylinders based on input
1400 cyls
= ((cylno
- part_deflt
->start_cyl
) + 1);
1402 return (cyls
* spc());
1406 * Convert token from a number of
1407 * cylinders to a number of blocks.
1409 i
= bn2c(bounds
->upper
);
1410 if (geti(cleantoken
, &cyls
, &i
))
1414 * Check the bounds - cyls is number of
1417 if (cyls
> (bounds
->upper
/spc())) {
1418 err_print("`%dc' is out of range\n", cyls
);
1423 * Convert cylinders to blocks and
1426 return (cyls
* spc());
1430 * Convert token from megabytes to a
1433 if (sscanf(cleantoken
, "%f2", &nmegs
) != 1) {
1434 err_print("`%s' is not recognized\n",
1442 if (nmegs
> bn2mb(bounds
->upper
)) {
1443 err_print("`%1.2fmb' is out of range\n", nmegs
);
1450 bn64
= mb2bn(nmegs
);
1453 * Round value up to nearest cylinder
1456 bn64
= ((bn64
+ (i
-1)) / i
) * i
;
1461 * Convert token from gigabytes to a
1464 if (sscanf(cleantoken
, "%f2", &ngigs
) != 1) {
1465 err_print("`%s' is not recognized\n",
1473 if (ngigs
> bn2gb(bounds
->upper
)) {
1474 err_print("`%1.2fgb' is out of range\n", ngigs
);
1481 bn64
= gb2bn(ngigs
);
1484 * Round value up to nearest cylinder
1487 bn64
= ((bn64
+ (i
-1)) / i
) * i
;
1492 "Please specify units in either b(blocks), c(cylinders), e(end cylinder),\n");
1493 err_print("m(megabytes) or g(gigabytes)\n");
1499 * Parameter is the bounds of legal block numbers.
1501 bounds
= (struct bounds
*)¶m
->io_bounds
;
1504 * Print help message if required.
1507 fmt_print("Expecting up to %llu sectors,",
1508 cur_parts
->etoc
->efi_last_u_lba
);
1509 fmt_print("or %llu megabytes,",
1510 (cur_parts
->etoc
->efi_last_u_lba
* cur_blksz
)/
1512 fmt_print("or %llu gigabytes\n",
1513 (cur_parts
->etoc
->efi_last_u_lba
* cur_blksz
)/
1514 (1024 * 1024 * 1024));
1515 fmt_print("or %llu terabytes\n",
1516 (cur_parts
->etoc
->efi_last_u_lba
* cur_blksz
)/
1517 ((uint64_t)1024 * 1024 * 1024 * 1024));
1522 * Parse the first token: try to find 'b', 'c', 'e'
1526 while (*s
&& (isdigit(*s
) || (*s
== '.') || (*s
== '$'))) {
1531 * If we found a conversion specifier, second token is
1532 * unused Otherwise, the second token should supply it.
1538 value
= cleantoken2
[0];
1542 * If the token is the wild card, simply supply the max
1543 * This order allows the user to specify the maximum in
1544 * either blocks/cyls/megabytes - a convenient fiction.
1546 if (strcmp(cleantoken
, WILD_STRING
) == 0) {
1547 return (bounds
->upper
- EFI_MIN_RESV_SIZE
-
1548 efi_deflt
->start_sector
);
1552 * Allow the user to specify zero with no units,
1553 * by just defaulting to sectors.
1556 if (value
!= 'e' && strcmp(cleantoken
, "0") == 0) {
1562 * If there's a decimal point, but no unit
1563 * specification, let's assume megabytes.
1565 if ((value
== 0) && (strchr(cleantoken
, '.') != NULL
)) {
1570 * Handle each unit type we support
1575 * Token is number of blocks
1577 if (geti64(cleantoken
, &blokno
, (uint64_t *)NULL
)) {
1580 if (blokno
> bounds
->upper
) {
1582 "Number of blocks must be less that the total available blocks.\n");
1589 * Token is ending block number
1592 /* convert token to integer */
1593 if (geti64(cleantoken
, &blokno
, (uint64_t *)NULL
)) {
1600 if (blokno
< efi_deflt
->start_sector
) {
1602 "End Sector must fall on or after start sector %llu\n",
1603 efi_deflt
->start_sector
);
1608 * verify that our input is within range
1610 if (blokno
> cur_parts
->etoc
->efi_last_u_lba
) {
1612 "End Sector %llu is beyond max Sector %llu\n",
1613 blokno
, cur_parts
->etoc
->efi_last_u_lba
);
1618 * calculate number of blocks based on input
1621 return (blokno
- efi_deflt
->start_sector
+ 1);
1625 * Convert token from megabytes to a
1628 if (sscanf(cleantoken
, "%f2", &nmegs
) != 1) {
1629 err_print("`%s' is not recognized\n",
1637 if (nmegs
> bn2mb(bounds
->upper
- bounds
->lower
)) {
1638 err_print("`%1.2fmb' is out of range\n", nmegs
);
1642 return (mb2bn(nmegs
));
1645 if (sscanf(cleantoken
, "%f2", &nmegs
) != 1) {
1646 err_print("`%s' is not recognized\n",
1650 if (nmegs
> bn2gb(bounds
->upper
- bounds
->lower
)) {
1651 err_print("`%1.2fgb' is out of range\n", nmegs
);
1655 return (gb2bn(nmegs
));
1658 if (sscanf(cleantoken
, "%f2", &nmegs
) != 1) {
1659 err_print("`%s' is not recognized\n",
1663 if (nmegs
> bn2tb(bounds
->upper
- bounds
->lower
)) {
1664 err_print("`%1.2ftb' is out of range\n", nmegs
);
1667 return (uint64_t)((float)nmegs
* 1024.0 *
1668 1024.0 * 1024.0 * 1024.0 / cur_blksz
);
1672 "Please specify units in either b(number of blocks), e(end sector),\n");
1673 err_print(" g(gigabytes), m(megabytes)");
1674 err_print(" or t(terabytes)\n");
1680 * If we don't recognize the input type, it's bad news.
1683 err_print("Error: unknown input type.\n");
1687 * If we get here, it's because some error kept us from accepting
1688 * the token. If we are running out of a command file, gracefully
1689 * leave the program. If we are interacting with the user, simply
1690 * reprompt. If the token was in the pipe, abort the current command.
1694 else if (interactive
)
1699 * Never actually reached.
1705 * Print input choices
1708 print_input_choices(type
, param
)
1720 fmt_print("Expecting one of the following:\n");
1724 fmt_print("Expecting one of the following: ");
1725 fmt_print("(abbreviations ok):\n");
1727 for (sp
= (char **)param
->io_charlist
; *sp
!= NULL
; sp
++) {
1728 fmt_print("\t%s\n", *sp
);
1733 fmt_print("Expecting one of the following: ");
1734 fmt_print("(abbreviations ok):\n");
1736 * Figure out the width of the widest string
1738 width
= slist_widest_str((slist_t
*)param
->io_slist
);
1741 * If the help messages are empty, print the
1742 * possible choices in left-justified columns
1744 lp
= (slist_t
*)param
->io_slist
;
1745 if (*lp
->help
== 0) {
1748 for (; lp
->str
!= NULL
; lp
++) {
1751 ljust_print(lp
->str
,
1752 (++col
== ncols
) ? 0 : width
);
1762 * With help messages, print each choice,
1763 * and help message, on its own line.
1765 for (; lp
->str
!= NULL
; lp
++) {
1767 ljust_print(lp
->str
, width
);
1768 fmt_print("- %s\n", lp
->help
);
1774 err_print("Error: unknown input type.\n");
1783 * Search a string list for a particular string.
1784 * Use minimum recognition, to accept unique abbreviations
1785 * Return the number of possible matches found.
1786 * If only one match was found, return the arbitrary value
1787 * associated with the matched string in match_value.
1790 find_value(slist
, match_str
, match_value
)
1803 match_length
= strlen(match_str
);
1805 for (; slist
->str
!= NULL
; slist
++) {
1807 * See how many characters of the token match
1809 i
= strcnt(match_str
, slist
->str
);
1811 * If it's not the whole token, then it's not a match.
1813 if (i
< match_length
)
1816 * If it ties with another input, remember that.
1821 * If it matches the most so far, record that.
1824 *match_value
= slist
->value
;
1834 * Search a string list for a particular value.
1835 * Return the string associated with that value.
1838 find_string(slist
, match_value
)
1842 for (; slist
->str
!= NULL
; slist
++) {
1843 if (slist
->value
== match_value
) {
1844 return (slist
->str
);
1852 * Return the width of the widest string in an slist
1855 slist_widest_str(slist
)
1862 for (; slist
->str
!= NULL
; slist
++) {
1863 if ((i
= strlen(slist
->str
)) > width
)
1871 * Print a string left-justified to a fixed width.
1874 ljust_print(str
, width
)
1880 fmt_print("%s", str
);
1881 for (i
= width
- strlen(str
); i
> 0; i
--) {
1887 * This routine is a modified version of printf. It handles the cases
1888 * of silent mode and logging; other than that it is identical to the
1893 fmt_print(char *format
, ...)
1897 va_start(ap
, format
);
1900 * If we are running silent, skip it.
1902 if (option_s
== 0) {
1904 * Do the print to standard out.
1907 (void) printf("\n");
1909 (void) vprintf(format
, ap
);
1911 * If we are logging, also print to the log file.
1915 (void) fprintf(log_file
, "\n");
1917 (void) vfprintf(log_file
, format
, ap
);
1918 (void) fflush(log_file
);
1928 * This routine is a modified version of printf. It handles the cases
1929 * of silent mode; other than that it is identical to the
1930 * library version. It differs from the above printf in that it does
1931 * not print the message to a log file.
1935 nolog_print(char *format
, ...)
1939 va_start(ap
, format
);
1942 * If we are running silent, skip it.
1944 if (option_s
== 0) {
1946 * Do the print to standard out.
1949 (void) printf("\n");
1951 (void) vprintf(format
, ap
);
1960 * This routine is a modified version of printf. It handles the cases
1961 * of silent mode, and only prints the message to the log file, not
1962 * stdout. Other than that is identical to the library version.
1966 log_print(char *format
, ...)
1970 va_start(ap
, format
);
1973 * If we are running silent, skip it.
1975 if (option_s
== 0) {
1977 * Do the print to the log file.
1980 (void) fprintf(log_file
, "\n");
1982 (void) vfprintf(log_file
, format
, ap
);
1983 (void) fflush(log_file
);
1992 * This routine is a modified version of printf. It prints the message
1993 * to stderr, and to the log file is appropriate.
1994 * Other than that is identical to the library version.
1998 err_print(char *format
, ...)
2002 va_start(ap
, format
);
2005 * Flush anything pending to stdout
2008 (void) printf("\n");
2010 (void) fflush(stdout
);
2012 * Do the print to stderr.
2014 (void) vfprintf(stderr
, format
, ap
);
2016 * If we are logging, also print to the log file.
2020 (void) fprintf(log_file
, "\n");
2022 (void) vfprintf(log_file
, format
, ap
);
2023 (void) fflush(log_file
);
2031 * Print a number of characters from a buffer. The buffer
2032 * does not need to be null-terminated. Since the data
2033 * may be coming from a device, we cannot be sure the
2034 * data is not crud, so be rather defensive.
2037 print_buf(buf
, nbytes
)
2043 while (nbytes
-- > 0) {
2045 if (isascii(c
) && isprint(c
)) {
2054 * This routine prints out a message describing the given ctlr.
2055 * The message is identical to the one printed by the kernel during
2060 register struct ctlr_info
*ctlr
;
2063 fmt_print(" %s%d at %s 0x%x ",
2064 ctlr
->ctlr_cname
, ctlr
->ctlr_num
,
2065 space2str(ctlr
->ctlr_space
), ctlr
->ctlr_addr
);
2066 if (ctlr
->ctlr_vec
!= 0)
2067 fmt_print("vec 0x%x ", ctlr
->ctlr_vec
);
2069 fmt_print("pri %d ", ctlr
->ctlr_prio
);
2075 * This routine prints out a message describing the given disk.
2076 * The message is identical to the one printed by the kernel during
2080 pr_diskline(disk
, num
)
2081 register struct disk_info
*disk
;
2084 struct ctlr_info
*ctlr
= disk
->disk_ctlr
;
2085 struct disk_type
*type
= disk
->disk_type
;
2087 fmt_print(" %4d. %s ", num
, disk
->disk_name
);
2088 if ((type
!= NULL
) && (disk
->label_type
== L_TYPE_SOLARIS
)) {
2089 fmt_print("<%s cyl %u alt %u hd %u sec %u>",
2090 type
->dtype_asciilabel
, type
->dtype_ncyl
,
2091 type
->dtype_acyl
, type
->dtype_nhead
,
2093 } else if ((type
!= NULL
) && (disk
->label_type
== L_TYPE_EFI
)) {
2094 cur_blksz
= disk
->disk_lbasize
;
2095 print_efi_string(type
->vendor
, type
->product
,
2096 type
->revision
, type
->capacity
);
2097 } else if (disk
->disk_flags
& DSK_RESERVED
) {
2098 fmt_print("<drive not available: reserved>");
2099 } else if (disk
->disk_flags
& DSK_UNAVAILABLE
) {
2100 fmt_print("<drive not available>");
2102 fmt_print("<drive type unknown>");
2104 if (chk_volname(disk
)) {
2106 print_volname(disk
);
2110 if (disk
->devfs_name
!= NULL
) {
2111 fmt_print(" %s\n", disk
->devfs_name
);
2113 fmt_print(" %s%d at %s%d slave %d\n",
2114 ctlr
->ctlr_dname
, disk
->disk_dkinfo
.dki_unit
,
2115 ctlr
->ctlr_cname
, ctlr
->ctlr_num
,
2116 disk
->disk_dkinfo
.dki_slave
);
2120 fmt_print(" %4d. %s at %s%d slave %d", num
, disk
->disk_name
,
2121 ctlr
->ctlr_cname
, ctlr
->ctlr_num
, disk
->disk_dkinfo
.dki_slave
);
2122 if (chk_volname(disk
)) {
2124 print_volname(disk
);
2129 " %s%d: <%s cyl %u alt %u hd %u sec %u>\n",
2130 ctlr
->ctlr_dname
, disk
->disk_dkinfo
.dki_unit
,
2131 type
->dtype_asciilabel
, type
->dtype_ncyl
,
2132 type
->dtype_acyl
, type
->dtype_nhead
,
2135 fmt_print(" %s%d: <drive type unknown>\n",
2136 ctlr
->ctlr_dname
, disk
->disk_dkinfo
.dki_unit
);
2142 * This routine prints out a given disk block number in cylinder/head/sector
2143 * format. It uses the printing routine passed in to do the actual output.
2146 pr_dblock(void (*func
)(char *, ...), diskaddr_t bn
)
2148 if (cur_label
== L_TYPE_SOLARIS
) {
2149 (*func
)("%u/%u/%u", bn2c(bn
),
2150 bn2h(bn
), bn2s(bn
));
2152 (*func
)("%llu", bn
);
2157 * This routine inputs a character from the data file. It understands
2158 * the use of '\' to prevent interpretation of a newline. It also keeps
2159 * track of the current line in the data file via a global variable.
2167 * Input the character.
2169 c
= getc(data_file
);
2171 * If it's not a backslash, return it.
2176 * It was a backslash. Get the next character.
2178 c
= getc(data_file
);
2180 * If it was a newline, update the line counter and get the next
2185 c
= getc(data_file
);
2188 * Return the character.
2194 * This routine pushes a character back onto the input pipe for the data file.
2200 (void) ungetc(c
, data_file
);
2204 * Variables to support pushing back tokens
2206 static int have_pushed_token
= 0;
2207 static TOKEN pushed_buf
;
2208 static int pushed_token
;
2211 * This routine inputs a token from the data file. A token is a series
2212 * of contiguous non-white characters or a recognized special delimiter
2213 * character. Use of the wrapper lets us always have the value of the
2214 * last token around, which is useful for error recovery.
2220 last_token_type
= sup_get_token(buf
);
2221 return (last_token_type
);
2232 * First check for presence of push-backed token.
2235 if (have_pushed_token
) {
2236 have_pushed_token
= 0;
2237 bcopy(pushed_buf
, buf
, TOKEN_SIZE
+1);
2238 return (pushed_token
);
2241 * Zero out the returned token buffer
2243 bzero(buf
, TOKEN_SIZE
+ 1);
2245 * Strip off leading white-space.
2247 while ((isspace(c
= sup_inputchar())) && (c
!= '\n'))
2250 * Read in characters until we hit unquoted white-space.
2252 for (; !isspace(c
) || quoted
; c
= sup_inputchar()) {
2254 * If we hit eof, that's a token.
2256 if (feof(data_file
))
2259 * If we hit a double quote, change the state of quoting.
2266 * If we hit a newline, that delimits a token.
2271 * If we hit any nonquoted special delimiters, that delimits
2274 if (!quoted
&& (c
== '=' || c
== ',' || c
== ':' ||
2275 c
== '#' || c
== '|' || c
== '&' || c
== '~'))
2278 * Store the character if there's room left.
2280 if (ptr
- buf
< TOKEN_SIZE
)
2284 * If we stored characters in the buffer, then we inputted a string.
2285 * Push the delimiter back into the pipe and return the string.
2287 if (ptr
- buf
> 0) {
2289 return (SUP_STRING
);
2292 * We didn't input a string, so we must have inputted a known delimiter.
2293 * store the delimiter in the buffer, so it will get returned.
2297 * Switch on the delimiter. Return the appropriate value for each one.
2316 * For comments, we flush out the rest of the line and return
2319 while ((c
= sup_inputchar()) != '\n' && !feof(data_file
))
2321 if (feof(data_file
))
2326 * Shouldn't ever get here.
2329 return (SUP_STRING
);
2337 sup_pushtoken(token_buf
, token_type
)
2342 * We can only push one token back at a time
2344 assert(have_pushed_token
== 0);
2346 have_pushed_token
= 1;
2347 bcopy(token_buf
, pushed_buf
, TOKEN_SIZE
+1);
2348 pushed_token
= token_type
;
2352 * Get an entire line of input. Handles logging, comments,
2356 get_inputline(line
, nbytes
)
2364 * Remove any leading white-space and comments
2367 while ((isspace(c
= getchar())) && (c
!= '\n'))
2369 } while (c
== COMMENT_CHAR
);
2371 * Loop on each character until end of line
2375 * If we hit eof, get out.
2381 * Add the character to the buffer.
2388 * Get the next character.
2393 * Null terminate the token.
2397 * Indicate that we've emptied the pipe
2401 * If we're running out of a file, echo the line to
2402 * the user, otherwise if we're logging, copy the
2403 * input to the log file.
2406 fmt_print("%s\n", line
);
2407 } else if (log_file
) {
2408 log_print("%s\n", line
);
2413 * execute the shell escape command
2416 execute_shell(s
, buff_size
)
2420 struct termio termio
;
2424 static char *default_shell
= "/bin/sh";
2429 shell_name
= getenv("SHELL");
2431 if (shell_name
== NULL
) {
2432 shell_name
= default_shell
;
2434 if (strlcpy(s
, shell_name
, buff_size
) >=
2436 err_print("Error: Shell command ($SHELL) too long.\n");
2441 /* save tty information */
2444 if (ioctl(0, TCGETS
, &tty
) == 0)
2447 if (ioctl(0, TCGETA
, &termio
) == 0) {
2449 tty
.c_iflag
= termio
.c_iflag
;
2450 tty
.c_oflag
= termio
.c_oflag
;
2451 tty
.c_cflag
= termio
.c_cflag
;
2452 tty
.c_lflag
= termio
.c_lflag
;
2453 for (i
= 0; i
< NCC
; i
++)
2454 tty
.c_cc
[i
] = termio
.c_cc
[i
];
2459 /* close the current file descriptor */
2460 if (cur_disk
!= NULL
) {
2461 (void) close(cur_file
);
2464 /* execute the shell escape */
2467 /* reopen file descriptor if one was open before */
2468 if (cur_disk
!= NULL
) {
2469 if ((cur_file
= open_disk(cur_disk
->disk_path
,
2470 O_RDWR
| O_NDELAY
)) < 0) {
2471 err_print("Error: can't reopen selected disk '%s'. \n",
2472 cur_disk
->disk_name
);
2477 /* Restore tty information */
2481 (void) ioctl(0, TCSETSW
, &tty
);
2482 else if (tty_flag
== 0) {
2483 termio
.c_iflag
= tty
.c_iflag
;
2484 termio
.c_oflag
= tty
.c_oflag
;
2485 termio
.c_cflag
= tty
.c_cflag
;
2486 termio
.c_lflag
= tty
.c_lflag
;
2487 for (j
= 0; j
< NCC
; j
++)
2488 termio
.c_cc
[j
] = tty
.c_cc
[j
];
2489 (void) ioctl(0, TCSETAW
, &termio
);
2493 fmt_print("\n[Hit Return to continue] \n");
2494 (void) fflush(stdin
);
2495 if (getchar() == EOF
)
2503 print_efi_string(char *vendor
, char *product
, char *revision
,
2509 char capacity_string
[10];
2513 /* Strip whitespace from the end of inquiry strings */
2514 new_vendor
= strdup(vendor
);
2515 if (new_vendor
== NULL
)
2518 for (i
= (strlen(new_vendor
) - 1); i
>= 0; i
--) {
2519 if (new_vendor
[i
] != 0x20) {
2520 new_vendor
[i
+1] = '\0';
2525 new_product
= strdup(product
);
2526 if (new_product
== NULL
) {
2531 for (i
= (strlen(new_product
) - 1); i
>= 0; i
--) {
2532 if (new_product
[i
] != 0x20) {
2533 new_product
[i
+1] = '\0';
2538 new_revision
= strdup(revision
);
2539 if (new_product
== NULL
) {
2545 for (i
= (strlen(new_revision
) - 1); i
>= 0; i
--) {
2546 if (new_revision
[i
] != 0x20) {
2547 new_revision
[i
+1] = '\0';
2552 /* Now build size string */
2553 scaled
= bn2mb(capacity
);
2554 if (scaled
>= (float)1024.0 * 1024) {
2555 (void) snprintf(capacity_string
, sizeof (capacity_string
),
2556 "%.2fTB", scaled
/((float)1024.0 * 1024));
2557 } else if (scaled
>= (float)1024.0) {
2558 (void) snprintf(capacity_string
, sizeof (capacity_string
),
2559 "%.2fGB", scaled
/(float)1024.0);
2561 (void) snprintf(capacity_string
, sizeof (capacity_string
),
2565 fmt_print("<%s-%s-%s-%s>",
2566 new_vendor
, new_product
, new_revision
, capacity_string
);