io.c revision 65908c77dfc02644236ba18bffe67b5ed6f23135
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file contains I/O related functions.
*/
#include "global.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <stdarg.h>
#include "startup.h"
#include "misc.h"
#include "menu_partition.h"
#include "param.h"
#include "menu.h"
extern int data_lineno;
extern char *space2str();
extern long strtol();
/*
* This variable is used to determine whether a token is present in the pipe
* already.
*/
static char token_present = 0;
/*
* This variable always gives us access to the most recent token type
*/
int last_token_type = 0;
#ifdef __STDC__
/*
* Prototypes for ANSI C compilers
*/
static int sup_get_token(char *);
static void pushchar(int c);
static int checkeof(void);
static void flushline(void);
static int sup_inputchar(void);
static void sup_pushchar(int c);
#else /* __STDC__ */
/*
* Prototypes for non-ANSI C compilers
*/
static int sup_get_token();
static void pushchar(int c);
static int checkeof(void);
static void flushline(void);
static int sup_inputchar(void);
static void sup_pushchar(int c);
#endif /* __STDC__ */
/*
* This routine pushes the given character back onto the input stream.
*/
static void
pushchar(c)
int c;
{
}
/*
* This routine checks the input stream for an eof condition.
*/
static int
checkeof()
{
}
/*
* This routine gets the next token off the input stream. A token is
* basically any consecutive non-white characters.
*/
char *
char *inbuf;
{
int c, quoted = 0;
/*
* Remove any leading white-space.
*/
;
/*
* If we are at the beginning of a line and hit the comment character,
* flush the line and start again.
*/
if (!token_present && c == COMMENT_CHAR) {
token_present = 1;
flushline();
goto retoke;
}
/*
* Loop on each character until we hit unquoted white-space.
*/
/*
* If we hit eof, get out.
*/
if (checkeof())
return (NULL);
/*
* If we hit a double quote, change the state of quotedness.
*/
if (c == '"')
/*
* If there's room in the buffer, add the character to the end.
*/
*ptr++ = (char)c;
/*
* Get the next character.
*/
c = getchar();
}
/*
* Null terminate the token.
*/
*ptr = '\0';
/*
* Peel off white-space still in the pipe.
*/
while (isspace(c) && (c != '\n'))
c = getchar();
/*
* If we hit another token, push it back and set state.
*/
if (c != '\n') {
pushchar(c);
token_present = 1;
} else
token_present = 0;
/*
* Return the token.
*/
return (inbuf);
}
/*
* This routine removes the leading and trailing spaces from a token.
*/
void
char *cleantoken, *token;
{
char *ptr;
/*
* Strip off leading white-space.
*/
;
/*
* Copy it into the clean buffer.
*/
/*
* Strip off trailing white-space.
*/
*ptr = '\0';
}
}
/*
* This routine checks if a token is already present on the input line
*/
int
{
return (token_present);
}
/*
* This routine flushes the rest of an input line if there is known
* to be data in it. The flush has to be qualified because the newline
* may have already been swallowed by the last gettoken.
*/
static void
{
if (token_present) {
/*
* Flush the pipe to eol or eof.
*/
;
/*
* Mark the pipe empty.
*/
token_present = 0;
}
}
/*
* This routine returns the number of characters that are identical
* between s1 and s2, stopping as soon as a mismatch is found.
*/
static int
{
int i = 0;
i++;
return (i);
}
/*
* This routine converts the given token into an integer. The token
* must convert cleanly into an integer with no unknown characters.
* If the token is the wildcard string, and the wildcard parameter
* is present, the wildcard value will be returned.
*/
int
char *str;
{
char *str2;
/*
* If there's a wildcard value and the string is wild, return the
* wildcard value.
*/
else {
/*
* Conver the string to an integer.
*/
/*
* If any characters didn't convert, it's an error.
*/
if (*str2 != '\0') {
return (-1);
}
}
return (0);
}
/*
* This routine converts the given token into a long long. The token
* must convert cleanly into a 64-bit integer with no unknown characters.
* If the token is the wildcard string, and the wildcard parameter
* is present, the wildcard value will be returned.
*/
static int
char *str;
{
char *str2;
/*
* If there's a wildcard value and the string is wild, return the
* wildcard value.
*/
} else {
/*
* Conver the string to an integer.
*/
/*
* If any characters didn't convert, it's an error.
*/
if (*str2 != '\0') {
return (-1);
}
}
return (0);
}
/*
* This routine converts the given string into a block number on the
* current disk. The format of a block number is either a self-based
* number, or a series of self-based numbers separated by slashes.
* Any number preceeding the first slash is considered a cylinder value.
* Any number succeeding the first slash but preceeding the second is
* considered a head value. Any number succeeding the second slash is
* considered a sector value. Any of these numbers can be wildcarded
* to the highest possible legal value.
*/
static int
char *str;
{
int wild;
/*
* Set cylinder pointer to beginning of string.
*/
/*
* Look for the first slash.
*/
str++;
/*
* If there wasn't one, convert string to an integer and return it.
*/
if (*str == '\0') {
return (-1);
return (0);
}
/*
* Null out the slash and set head pointer just beyond it.
*/
*str++ = '\0';
/*
* Look for the second slash.
*/
str++;
/*
* If there wasn't one, sector pointer points to a .
*/
if (*str == '\0')
/*
* If there was, null it out and set sector point just beyond it.
*/
else {
*str++ = '\0';
}
/*
* Convert the cylinder part to an integer and store it.
*/
return (-1);
return (-1);
}
/*
* Convert the head part to an integer and store it.
*/
return (-1);
return (-1);
}
/*
* Convert the sector part to an integer and store it.
*/
return (-1);
return (-1);
}
/*
* Combine the pieces into a block number and return it.
*/
return (0);
}
/*
* This routine is the basis for all input into the program. It
* understands the semantics of a set of input types, and provides
* consistent error messages for all input. It allows for default
* values and prompt strings.
*/
int type;
char *promptstr;
int delim;
int *deflt;
int cmdflag;
{
char *arg;
char *s;
int value;
float nmegs;
float ngigs;
char shell_argv[MAXPATHLEN];
/*
* Optional integer input has been added as a hack.
* Function result is 1 if user typed anything.
* Whatever they typed is returned in *deflt.
* This permits us to distinguish between "no value",
* and actually entering in some value, for instance.
*/
}
help = interactive = 0;
/*
* If we are inputting a command, flush any current input in the pipe.
*/
flushline();
/*
* Note whether the token is already present.
*/
if (!token_present)
interactive = 1;
/*
* Print the prompt.
*/
/*
* If there is a default value, print it in a format appropriate
* for the input type.
*/
switch (type) {
case FIO_BN:
#if !defined(lint) /* caller has aligned the pointer specifying FIO_BN */
fmt_print("]");
#endif
break;
case FIO_INT:
break;
case FIO_INT64:
#if defined(lint)
/* caller is longlong aligned specifying FIO_INT64 */
#else
#endif
break;
case FIO_CSTR:
case FIO_MSTR:
;
break;
case FIO_OSTR:
break;
case FIO_SLIST:
/*
* Search for a string matching the default
* value. If found, use it. Otherwise
* assume the default value is actually
* an illegal choice, and default to
* the first item in the list.
*/
if (s == (char *)NULL) {
}
fmt_print("[%s]", s);
break;
case FIO_CYL:
/*
* Old-style partition size input, used to
* modify complete partition tables
*/
break;
case FIO_ECYL:
/*
* set up pointer to partition defaults
* structure
*/
/*
* Build print format specifier. We use the
* starting cylinder number which was entered
* before this call to input(), in case the
* user has changed it from the value in the
* cur_parts->pinfo_map[].dkl_cylno
* field for the current parition
*/
/*
* Determine the proper default end cylinder:
* Start Cyl Default Size End Cylinder
* 0 0 0
* >0 0 Start Cyl
* 0 >0 Default Size
* (Cyls) - 1
* >0 >0 (Start +
* Default Size
* (Cyls)) -1
*/
if (part_deflt->deflt_size == 0) {
} else if (part_deflt->start_cyl == 0) {
} else {
}
fmt_print("[%ub, %uc, %de, %1.2fmb, %1.2fgb]",
break;
case FIO_EFI:
#if defined(lint)
/* caller is longlong aligned when specifying FIO_EFI */
#else
#endif
fmt_print("[%llub, %llue, %llumb, %llugb, %llutb]",
(1024 * 1024),
(1024 * 1024 * 1024),
break;
case FIO_OPINT:
/* no default value for optional input type */
fmt_print("[default]");
break;
default:
err_print("Error: unknown input type.\n");
fullabort();
}
}
/*
* Print the delimiter character.
*/
/*
* Get the token. If we hit eof, exit the program gracefully.
*/
fullabort();
/*
* check if the user has issued (!) , escape to shell
*/
/* get the list of arguments to shell command */
/* initialize to the first token... */
/*
* ... and then collect all tokens until the end of
* the line as arguments
*/
do {
/* skip empty tokens. */
if (*arg == '\0')
continue;
/*
* If either of the following two strlcat()
* operations overflows, report an error and
* exit gracefully.
*/
sizeof (shell_argv)) ||
sizeof (shell_argv))) {
err_print("Error: Command line too long.\n");
fullabort();
}
/* execute the shell command */
if (interactive) {
goto reprompt;
}
}
/*
* Certain commands accept up to two tokens
* Unfortunately, this is kind of a hack.
*/
token2[0] = 0;
cleantoken2[0] = 0;
if (token_present) {
fullabort();
}
}
/*
* Echo the token back to the user if it was in the pipe or we
* are running out of a command file.
*/
if (!interactive || option_f) {
if (token2[0] == 0) {
} else {
}
}
/*
* If we are logging, echo the token to the log file. The else
* is necessary here because the above printf will also put the
* token in the log file.
*/
else if (log_file) {
}
/*
* If the token was not in the pipe and it wasn't a command, flush
* the rest of the line to keep things in sync.
*/
flushline();
/*
* Scrub off the white-space.
*/
/*
* If the input was a blank line and we weren't prompting
* specifically for a blank line...
*/
/*
* If there's a default, return it.
*/
/*
* Duplicate and return the default string
*/
return ((int)alloc_string((char *)deflt));
/*
* If we can find a match for the default
* value in the list, return the default
* value. If there's no match for the
* default value, it's an illegal
* choice. Return the first value in
* the list.
*/
if ((cur_label == L_TYPE_EFI) &&
(s == (char *)NULL)) {
return (*deflt);
}
if (s == (char *)NULL) {
} else {
return (*deflt);
}
/*
* The user didn't enter anything
*/
return (0);
return (part_deflt->deflt_size);
return (efi_deflt->start_sector);
return (efi_deflt->end_sector);
} else {
return (*deflt);
}
}
/*
* If the blank was not in the pipe, just reprompt.
*/
if (interactive) {
goto reprompt;
}
/*
* If the blank was in the pipe, it's an error.
*/
err_print("No default for this entry.\n");
}
/*
* If token is a '?' or a 'h', it is a request for help.
*/
help = 1;
}
/*
* Switch on the type of input expected.
*/
switch (type) {
/*
* Expecting a disk block number.
*/
case FIO_BN:
/*
* Parameter is the bounds of legal block numbers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting a block number from %llu (",
fmt_print(")\n");
break;
}
/*
* Convert token to a disk block number.
*/
if (cur_label == L_TYPE_EFI) {
break;
} else {
break;
}
/*
* Check to be sure it is within the legal bounds.
*/
err_print("`");
err_print("' is out of range.\n");
break;
}
/*
* It's ok, return it.
*/
return (bn64);
/*
* Expecting an integer.
*/
case FIO_INT:
/*
* Parameter is the bounds of legal integers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting an integer from %llu",
break;
}
/*
* Convert the token into an integer.
*/
break;
/*
* Check to be sure it is within the legal bounds.
*/
break;
}
/*
* If it's ok, return it.
*/
return (bn);
case FIO_INT64:
/*
* Parameter is the bounds of legal integers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting an integer from %llu",
break;
}
/*
* Convert the token into an integer.
*/
break;
}
/*
* Check to be sure it is within the legal bounds.
*/
break;
}
/*
* If it's ok, return it.
*/
return (bn64);
/*
* Expecting an integer, or no input.
*/
case FIO_OPINT:
/*
* Parameter is the bounds of legal integers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting an integer from %llu",
break;
}
/*
* Convert the token into an integer.
*/
break;
/*
* Check to be sure it is within the legal bounds.
*/
break;
}
/*
* For optional case, return 1 indicating that
* the user actually did enter something.
*/
if (!deflt)
return (1);
/*
* Expecting a closed string. This means that the input
* string must exactly match one of the strings passed in
* as the parameter.
*/
case FIO_CSTR:
/*
* The parameter is a null terminated array of character
* pointers, each one pointing to a legal input string.
*/
/*
* Walk through the legal strings, seeing if any of them
* match the token. If a match is made, return the index
* of the string that was matched.
*/
/*
* Print help message if required.
*/
if (help) {
} else {
}
break;
/*
* Expecting a matched string. This means that the input
* string must either match one of the strings passed in,
* or be a unique abbreviation of one of them.
*/
case FIO_MSTR:
/*
* The parameter is a null terminated array of character
* pointers, each one pointing to a legal input string.
*/
/*
* Loop through the legal input strings.
*/
/*
* See how many characters of the token match
* this legal string.
*/
/*
* If it's not the whole token, then it's not a match.
*/
continue;
/*
* If it ties with another input, remember that.
*/
if (i == length)
tied = 1;
/*
* If it matches the most so far, record that.
*/
if (i > length) {
tied = 0;
length = i;
}
}
/*
* Print help message if required.
*/
if (length == 0) {
if (help) {
} else {
err_print("`%s' is not expected.\n",
}
break;
}
/*
* If the abbreviation was non-unique, it's an error.
*/
if (tied) {
break;
}
/*
* We matched one. Return the index of the string we matched.
*/
return (index);
/*
* Expecting an open string. This means that any string is legal.
*/
case FIO_OSTR:
/*
* Print a help message if required.
*/
if (help) {
fmt_print("Expecting a string\n");
break;
}
/*
* alloc a copy of the string and return it
*/
return ((int)alloc_string(token));
/*
* Expecting a blank line.
*/
case FIO_BLNK:
/*
* We are always in non-echo mode when we are inputting
* this type. We echo the newline as a carriage return
* only so the prompt string will be covered over.
*/
nolog_print("\015");
/*
* If we are logging, send a newline to the log file.
*/
if (log_file)
log_print("\n");
/*
* There is no value returned for this type.
*/
return (0);
/*
* Expecting one of the entries in a string list.
* Accept unique abbreviations.
* Return the value associated with the matched string.
*/
case FIO_SLIST:
cleantoken, &value);
if (i == 1) {
return (value);
} else {
/*
* Print help message if required.
*/
if (help) {
} else {
if (i == 0)
err_print("`%s' not expected.\n",
else
err_print("`%s' is ambiguous.\n",
}
}
break;
/*
* Cylinder size input when modifying a complete partition map
*/
case FIO_CYL:
/*
* Parameter is the bounds of legal block numbers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting up to %llu blocks,",
break;
}
/*
* Parse the first token: try to find 'b', 'c' or 'm'
*/
s = cleantoken;
s++;
}
/*
* If we found a conversion specifier, second token is unused
* Otherwise, the second token should supply it.
*/
if (*s != 0) {
value = *s;
*s = 0;
} else {
value = cleantoken2[0];
}
/*
* If the token is the wild card, simply supply the max
* This order allows the user to specify the maximum in
*/
}
/*
* Allow the user to specify zero with no units,
* by just defaulting to cylinders.
*/
value = 'c';
}
/*
* If there's a decimal point, but no unit specification,
* let's assume megabytes.
*/
value = 'm';
}
/*
* Handle each unit type we support
*/
switch (value) {
case 'b':
/*
* Convert token to a disk block number.
*/
break;
/*
* Check to be sure it is within the legal bounds.
*/
"`%llub' is out of the range %llu "
"to %llu\n",
break;
}
/*
* Verify the block lies on a cylinder boundary
*/
"partition size must be a multiple of "
"%u blocks to lie on a cylinder boundary\n",
spc());
"%llu blocks is approximately %u cylinders,"
" %1.2f megabytes or %1.2f gigabytes\n",
break;
}
return (bn64);
case 'c':
/*
* Convert token from a number of cylinders to
* a number of blocks.
*/
break;
/*
* Check the bounds - cyls is number of cylinders
*/
break;
}
/*
* Convert cylinders to blocks and return
*/
case 'm':
/*
* Convert token from megabytes to a block number.
*/
err_print("`%s' is not recognized\n",
break;
}
/*
* Check the bounds
*/
break;
}
/*
* Convert to blocks
*/
/*
* Round value up to nearest cylinder
*/
i = spc();
return (bn64);
case 'g':
/*
* Convert token from gigabytes to a block number.
*/
err_print("`%s' is not recognized\n",
break;
}
/*
* Check the bounds
*/
break;
}
/*
* Convert to blocks
*/
/*
* Round value up to nearest cylinder
*/
i = spc();
return (bn64);
default:
"Please specify units in either b(blocks), c(cylinders), m(megabytes) \
or g(gigabytes)\n");
break;
}
break;
case FIO_ECYL:
/*
* Parameter is the bounds of legal block numbers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting up to %llu blocks,",
fmt_print(" %u cylinders, ",
fmt_print(" %u end cylinder, ",
fmt_print(" %1.2f megabytes, ",
fmt_print("or %1.2f gigabytes\n",
break;
}
/*
* Parse the first token: try to find 'b', 'c', 'e'
* or 'm'
*/
s = cleantoken;
s++;
}
/*
* If we found a conversion specifier, second token is
* unused Otherwise, the second token should supply it.
*/
if (*s != 0) {
value = *s;
*s = 0;
} else {
value = cleantoken2[0];
}
/*
* If the token is the wild card, simply supply the max
* This order allows the user to specify the maximum in
*/
}
/*
* Allow the user to specify zero with no units,
* by just defaulting to cylinders.
*/
value = 'c';
}
/*
* If there's a decimal point, but no unit
* specification, let's assume megabytes.
*/
value = 'm';
}
/*
* Handle each unit type we support
*/
switch (value) {
case 'b':
/*
* Convert token to a disk block number.
*/
break;
/*
* Check to be sure it is within the
* legal bounds.
*/
"`%llub' is out of the range %llu to %llu\n",
break;
}
/*
* Verify the block lies on a cylinder
* boundary
*/
"partition size must be a multiple of %u "
"blocks to lie on a cylinder boundary\n",
spc());
"%llu blocks is approximately %u cylinders,"
" %1.2f megabytes or %1.2f gigabytes\n",
break;
}
return (bn64);
case 'e':
/*
* Token is ending cylinder
*/
/* convert token to integer */
break;
}
/*
* check that input cylno isn't before the current
* starting cylinder number. Note that we are NOT
* using the starting cylinder from
* cur_parts->pinfo_map[].dkl_cylno!
*/
"End cylinder must fall on or after start cylinder %u\n",
break;
}
/*
* calculate cylinder number of upper boundary, and
* verify that our input is within range
*/
if (cylno > i) {
"End cylinder %d is beyond max cylinder %d\n",
cylno, i);
break;
}
/*
* calculate number of cylinders based on input
*/
case 'c':
/*
* Convert token from a number of
* cylinders to a number of blocks.
*/
break;
/*
* Check the bounds - cyls is number of
* cylinders
*/
break;
}
/*
* Convert cylinders to blocks and
* return
*/
case 'm':
/*
* Convert token from megabytes to a
* block number.
*/
err_print("`%s' is not recognized\n",
break;
}
/*
* Check the bounds
*/
break;
}
/*
* Convert to blocks
*/
/*
* Round value up to nearest cylinder
*/
i = spc();
return (bn64);
case 'g':
/*
* Convert token from gigabytes to a
* block number.
*/
err_print("`%s' is not recognized\n",
break;
}
/*
* Check the bounds
*/
break;
}
/*
* Convert to blocks
*/
/*
* Round value up to nearest cylinder
*/
i = spc();
return (bn64);
default:
"Please specify units in either b(blocks), c(cylinders), e(end cylinder),\n");
err_print("m(megabytes) or g(gigabytes)\n");
break;
}
break;
case FIO_EFI:
/*
* Parameter is the bounds of legal block numbers.
*/
/*
* Print help message if required.
*/
if (help) {
fmt_print("Expecting up to %llu sectors,",
fmt_print("or %llu megabytes,",
(1024 * 1024));
fmt_print("or %llu gigabytes\n",
(1024 * 1024 * 1024));
fmt_print("or %llu terabytes\n",
break;
}
/*
* Parse the first token: try to find 'b', 'c', 'e'
* or 'm'
*/
s = cleantoken;
s++;
}
/*
* If we found a conversion specifier, second token is
* unused Otherwise, the second token should supply it.
*/
if (*s != 0) {
value = *s;
*s = 0;
} else {
value = cleantoken2[0];
}
/*
* If the token is the wild card, simply supply the max
* This order allows the user to specify the maximum in
*/
}
/*
* Allow the user to specify zero with no units,
* by just defaulting to sectors.
*/
value = 'm';
}
/*
* If there's a decimal point, but no unit
* specification, let's assume megabytes.
*/
value = 'm';
}
/*
* Handle each unit type we support
*/
switch (value) {
case 'b':
/*
* Token is number of blocks
*/
break;
}
"Number of blocks must be less that the total available blocks.\n");
break;
}
return (blokno);
case 'e':
/*
* Token is ending block number
*/
/* convert token to integer */
break;
}
/*
* Some sanity check
*/
"End Sector must fall on or after start sector %llu\n",
break;
}
/*
* verify that our input is within range
*/
"End Sector %llu is beyond max Sector %llu\n",
break;
}
/*
* calculate number of blocks based on input
*/
case 'm':
/*
* Convert token from megabytes to a
* block number.
*/
err_print("`%s' is not recognized\n",
break;
}
/*
* Check the bounds
*/
break;
}
case 'g':
err_print("`%s' is not recognized\n",
break;
}
break;
}
case 't':
err_print("`%s' is not recognized\n",
break;
}
break;
}
default:
"Please specify units in either b(number of blocks), e(end sector),\n");
err_print(" g(gigabytes), m(megabytes)");
err_print(" or t(terabytes)\n");
break;
}
break;
/*
* If we don't recognize the input type, it's bad news.
*/
default:
err_print("Error: unknown input type.\n");
fullabort();
}
/*
* If we get here, it's because some error kept us from accepting
* the token. If we are running out of a command file, gracefully
* leave the program. If we are interacting with the user, simply
* reprompt. If the token was in the pipe, abort the current command.
*/
if (option_f)
fullabort();
else if (interactive)
goto reprompt;
else
/*
* Never actually reached.
*/
return (-1);
}
/*
* Print input choices
*/
static void
int type;
{
char **sp;
int width;
int col;
int ncols;
switch (type) {
case FIO_CSTR:
fmt_print("Expecting one of the following:\n");
goto common;
case FIO_MSTR:
fmt_print("Expecting one of the following: ");
fmt_print("(abbreviations ok):\n");
}
break;
case FIO_SLIST:
fmt_print("Expecting one of the following: ");
fmt_print("(abbreviations ok):\n");
/*
* Figure out the width of the widest string
*/
width += 4;
/*
* If the help messages are empty, print the
* possible choices in left-justified columns
*/
col = 0;
if (col == 0)
fmt_print("\t");
col = 0;
fmt_print("\n");
}
}
if (col != 0)
fmt_print("\n");
} else {
/*
* With help messages, print each choice,
* and help message, on its own line.
*/
fmt_print("\t");
}
}
break;
default:
err_print("Error: unknown input type.\n");
fullabort();
}
fmt_print("\n");
}
/*
* Search a string list for a particular string.
* Use minimum recognition, to accept unique abbreviations
* Return the number of possible matches found.
* If only one match was found, return the arbitrary value
* associated with the matched string in match_value.
*/
int
char *match_str;
int *match_value;
{
int i;
int nmatches;
int length;
int match_length;
nmatches = 0;
length = 0;
/*
* See how many characters of the token match
*/
/*
* If it's not the whole token, then it's not a match.
*/
if (i < match_length)
continue;
/*
* If it ties with another input, remember that.
*/
if (i == length)
nmatches++;
/*
* If it matches the most so far, record that.
*/
if (i > length) {
nmatches = 1;
length = i;
}
}
return (nmatches);
}
/*
* Search a string list for a particular value.
* Return the string associated with that value.
*/
char *
int match_value;
{
}
}
return ((char *)NULL);
}
/*
* Return the width of the widest string in an slist
*/
static int
{
int i;
int width;
width = 0;
width = i;
}
return (width);
}
/*
* Print a string left-justified to a fixed width.
*/
static void
char *str;
int width;
{
int i;
fmt_print(" ");
}
}
/*
* This routine is a modified version of printf. It handles the cases
* of silent mode and logging; other than that it is identical to the
* library version.
*/
/*PRINTFLIKE1*/
void
{
/*
* If we are running silent, skip it.
*/
if (option_s == 0) {
/*
* Do the print to standard out.
*/
if (need_newline) {
(void) printf("\n");
}
/*
* If we are logging, also print to the log file.
*/
if (log_file) {
if (need_newline) {
}
}
}
need_newline = 0;
}
/*
* This routine is a modified version of printf. It handles the cases
* of silent mode; other than that it is identical to the
* library version. It differs from the above printf in that it does
* not print the message to a log file.
*/
/*PRINTFLIKE1*/
void
nolog_print(char *format, ...)
{
/*
* If we are running silent, skip it.
*/
if (option_s == 0) {
/*
* Do the print to standard out.
*/
if (need_newline) {
(void) printf("\n");
}
}
need_newline = 0;
}
/*
* This routine is a modified version of printf. It handles the cases
* of silent mode, and only prints the message to the log file, not
* stdout. Other than that is identical to the library version.
*/
/*PRINTFLIKE1*/
void
{
/*
* If we are running silent, skip it.
*/
if (option_s == 0) {
/*
* Do the print to the log file.
*/
if (need_newline) {
}
}
need_newline = 0;
}
/*
* This routine is a modified version of printf. It prints the message
* to stderr, and to the log file is appropriate.
* Other than that is identical to the library version.
*/
/*PRINTFLIKE1*/
void
{
/*
* Flush anything pending to stdout
*/
if (need_newline) {
(void) printf("\n");
}
/*
* Do the print to stderr.
*/
/*
* If we are logging, also print to the log file.
*/
if (log_file) {
if (need_newline) {
}
}
need_newline = 0;
}
/*
* Print a number of characters from a buffer. The buffer
* does not need to be null-terminated. Since the data
* may be coming from a device, we cannot be sure the
* data is not crud, so be rather defensive.
*/
void
char *buf;
int nbytes;
{
int c;
while (nbytes-- > 0) {
c = *buf++;
fmt_print("%c", c);
} else
break;
}
}
#ifdef not
/*
* This routine prints out a message describing the given ctlr.
* The message is identical to the one printed by the kernel during
* booting.
*/
void
{
fmt_print(" %s%d at %s 0x%x ",
else
fmt_print("\n");
}
#endif /* not */
/*
* This routine prints out a message describing the given disk.
* The message is identical to the one printed by the kernel during
* booting.
*/
void
int num;
{
fmt_print("<%s cyl %u alt %u hd %u sec %u>",
type->dtype_nsect);
fmt_print("<drive not available: reserved>");
fmt_print("<drive not available>");
} else {
fmt_print("<drive type unknown>");
}
if (chk_volname(disk)) {
fmt_print(" ");
}
fmt_print("\n");
} else {
fmt_print(" %s%d at %s%d slave %d\n",
}
#ifdef OLD
if (chk_volname(disk)) {
fmt_print(": ");
}
fmt_print("\n");
" %s%d: <%s cyl %u alt %u hd %u sec %u>\n",
type->dtype_nsect);
} else {
fmt_print(" %s%d: <drive type unknown>\n",
}
#endif /* OLD */
}
/*
* format. It uses the printing routine passed in to do the actual output.
*/
void
{
if (cur_label == L_TYPE_SOLARIS) {
} else {
}
}
/*
* This routine inputs a character from the data file. It understands
* the use of '\' to prevent interpretation of a newline. It also keeps
* track of the current line in the data file via a global variable.
*/
static int
{
int c;
/*
* Input the character.
*/
/*
* If it's not a backslash, return it.
*/
if (c != '\\')
return (c);
/*
* It was a backslash. Get the next character.
*/
/*
* If it was a newline, update the line counter and get the next
* character.
*/
if (c == '\n') {
data_lineno++;
}
/*
* Return the character.
*/
return (c);
}
/*
* This routine pushes a character back onto the input pipe for the data file.
*/
static void
sup_pushchar(c)
int c;
{
}
/*
* Variables to support pushing back tokens
*/
static int have_pushed_token = 0;
static TOKEN pushed_buf;
static int pushed_token;
/*
* This routine inputs a token from the data file. A token is a series
* of contiguous non-white characters or a recognized special delimiter
* character. Use of the wrapper lets us always have the value of the
* last token around, which is useful for error recovery.
*/
int
char *buf;
{
return (last_token_type);
}
static int
char *buf;
{
int c, quoted = 0;
/*
* First check for presence of push-backed token.
* If so, return it.
*/
if (have_pushed_token) {
have_pushed_token = 0;
return (pushed_token);
}
/*
* Zero out the returned token buffer
*/
/*
* Strip off leading white-space.
*/
;
/*
* Read in characters until we hit unquoted white-space.
*/
/*
* If we hit eof, that's a token.
*/
return (SUP_EOF);
/*
* If we hit a double quote, change the state of quoting.
*/
if (c == '"') {
continue;
}
/*
* If we hit a newline, that delimits a token.
*/
if (c == '\n')
break;
/*
* If we hit any nonquoted special delimiters, that delimits
* a token.
*/
c == '#' || c == '|' || c == '&' || c == '~'))
break;
/*
* Store the character if there's room left.
*/
*ptr++ = (char)c;
}
/*
* If we stored characters in the buffer, then we inputted a string.
* Push the delimiter back into the pipe and return the string.
*/
sup_pushchar(c);
return (SUP_STRING);
}
/*
* We didn't input a string, so we must have inputted a known delimiter.
* store the delimiter in the buffer, so it will get returned.
*/
buf[0] = c;
/*
* Switch on the delimiter. Return the appropriate value for each one.
*/
switch (c) {
case '=':
return (SUP_EQL);
case ':':
return (SUP_COLON);
case ',':
return (SUP_COMMA);
case '\n':
return (SUP_EOL);
case '|':
return (SUP_OR);
case '&':
return (SUP_AND);
case '~':
return (SUP_TILDE);
case '#':
/*
* For comments, we flush out the rest of the line and return
* an EOL.
*/
;
return (SUP_EOF);
else
return (SUP_EOL);
/*
* Shouldn't ever get here.
*/
default:
return (SUP_STRING);
}
}
/*
* Push back a token
*/
void
char *token_buf;
int token_type;
{
/*
* We can only push one token back at a time
*/
assert(have_pushed_token == 0);
have_pushed_token = 1;
}
/*
* Get an entire line of input. Handles logging, comments,
* and EOF.
*/
void
char *line;
int nbytes;
{
char *p = line;
int c;
/*
* Remove any leading white-space and comments
*/
do {
;
} while (c == COMMENT_CHAR);
/*
* Loop on each character until end of line
*/
while (c != '\n') {
/*
* If we hit eof, get out.
*/
if (checkeof()) {
fullabort();
}
/*
* Add the character to the buffer.
*/
if (nbytes > 1) {
*p++ = (char)c;
nbytes --;
}
/*
* Get the next character.
*/
c = getchar();
}
/*
* Null terminate the token.
*/
*p = 0;
/*
* Indicate that we've emptied the pipe
*/
token_present = 0;
/*
* If we're running out of a file, echo the line to
* the user, otherwise if we're logging, copy the
* input to the log file.
*/
if (option_f) {
} else if (log_file) {
}
}
/*
* execute the shell escape command
*/
int
char *s;
{
int tty_flag, i, j;
char *shell_name;
static char *default_shell = "/bin/sh";
tty_flag = -1;
if (*s == NULL) {
if (shell_name == NULL) {
}
buff_size) {
err_print("Error: Shell command ($SHELL) too long.\n");
fullabort();
}
}
/* save tty information */
if (isatty(0)) {
tty_flag = 1;
else {
tty_flag = 0;
for (i = 0; i < NCC; i++)
}
}
}
/* close the current file descriptor */
}
/* execute the shell escape */
(void) system(s);
/* reopen file descriptor if one was open before */
err_print("Error: can't reopen selected disk '%s'. \n",
fullabort();
}
}
/* Restore tty information */
if (isatty(0)) {
if (tty_flag > 0)
else if (tty_flag == 0) {
for (j = 0; j < NCC; j++)
}
if (isatty(1)) {
fmt_print("\n[Hit Return to continue] \n");
fullabort();
}
}
return (0);
}
void
{
char new_vendor[9];
char new_product[17];
char new_revision[5];
char capacity_string[10];
float scaled;
int i;
/* Strip whitespace from the end of inquiry strings */
if (new_vendor[i] != 0x20) {
break;
}
}
if (new_product[i] != 0x20) {
break;
}
}
if (new_revision[i] != 0x20) {
break;
}
}
/* Now build size string */
} else if (scaled >= (float)1024.0) {
} else {
"%.2fMB", scaled);
}
fmt_print("<%s-%s-%s-%s>",
}