xref: /illumos-gate/usr/src/cmd/format/io.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_IO_H
28*7c478bd9Sstevel@tonic-gate #define	_IO_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate /*
38*7c478bd9Sstevel@tonic-gate  * Bounds structure for integer and disk input.
39*7c478bd9Sstevel@tonic-gate  */
40*7c478bd9Sstevel@tonic-gate struct bounds {
41*7c478bd9Sstevel@tonic-gate 	diskaddr_t	lower;
42*7c478bd9Sstevel@tonic-gate 	diskaddr_t	upper;
43*7c478bd9Sstevel@tonic-gate };
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * List of strings with arbitrary matching values
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate typedef struct slist {
49*7c478bd9Sstevel@tonic-gate 	char	*str;
50*7c478bd9Sstevel@tonic-gate 	char	*help;
51*7c478bd9Sstevel@tonic-gate 	int	value;
52*7c478bd9Sstevel@tonic-gate } slist_t;
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate /*
55*7c478bd9Sstevel@tonic-gate  * Input structure for current partition information
56*7c478bd9Sstevel@tonic-gate  */
57*7c478bd9Sstevel@tonic-gate typedef struct partition_defaults {
58*7c478bd9Sstevel@tonic-gate 	int start_cyl;
59*7c478bd9Sstevel@tonic-gate 	int deflt_size;
60*7c478bd9Sstevel@tonic-gate } part_deflt_t;
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate typedef struct efi_defaults {
63*7c478bd9Sstevel@tonic-gate 	uint64_t	start_sector;
64*7c478bd9Sstevel@tonic-gate 	uint64_t	end_sector;
65*7c478bd9Sstevel@tonic-gate } efi_deflt_t;
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate  * Input parameter can be any one of these types.
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate typedef union input_param {
71*7c478bd9Sstevel@tonic-gate 	struct slist	*io_slist;
72*7c478bd9Sstevel@tonic-gate 	char		**io_charlist;
73*7c478bd9Sstevel@tonic-gate 	struct bounds	io_bounds;
74*7c478bd9Sstevel@tonic-gate } u_ioparam_t;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate /*
77*7c478bd9Sstevel@tonic-gate  * These declarations define the legal input types.
78*7c478bd9Sstevel@tonic-gate  */
79*7c478bd9Sstevel@tonic-gate #define	FIO_BN		0		/* block number */
80*7c478bd9Sstevel@tonic-gate #define	FIO_INT		1		/* integer input */
81*7c478bd9Sstevel@tonic-gate #define	FIO_CSTR	2		/* closed string - exact match */
82*7c478bd9Sstevel@tonic-gate #define	FIO_MSTR	3		/* matched string, with abbreviations */
83*7c478bd9Sstevel@tonic-gate #define	FIO_OSTR	4		/* open string - anything's legal */
84*7c478bd9Sstevel@tonic-gate #define	FIO_BLNK	5		/* blank line */
85*7c478bd9Sstevel@tonic-gate #define	FIO_SLIST	6		/* one string out of a list, abbr. */
86*7c478bd9Sstevel@tonic-gate #define	FIO_CYL		7		/* nblocks, on cylinder boundary */
87*7c478bd9Sstevel@tonic-gate #define	FIO_OPINT	8		/* optional integer input */
88*7c478bd9Sstevel@tonic-gate #define	FIO_ECYL	9		/* allows end cylinder input */
89*7c478bd9Sstevel@tonic-gate #define	FIO_INT64	10		/* Input for EFI partitions */
90*7c478bd9Sstevel@tonic-gate #define	FIO_EFI		11		/* Input EFI part size	*/
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * Miscellaneous definitions.
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate #define	TOKEN_SIZE	36			/* max length of a token */
96*7c478bd9Sstevel@tonic-gate typedef	char TOKEN[TOKEN_SIZE+1];		/* token type */
97*7c478bd9Sstevel@tonic-gate #define	DATA_INPUT	0			/* 2 modes of input */
98*7c478bd9Sstevel@tonic-gate #define	CMD_INPUT	1
99*7c478bd9Sstevel@tonic-gate #define	WILD_STRING	"$"			/* wildcard character */
100*7c478bd9Sstevel@tonic-gate #define	COMMENT_CHAR	'#'			/* comment character */
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate /*
104*7c478bd9Sstevel@tonic-gate  *	Prototypes for ANSI C
105*7c478bd9Sstevel@tonic-gate  */
106*7c478bd9Sstevel@tonic-gate char	*gettoken(char *inbuf);
107*7c478bd9Sstevel@tonic-gate void	clean_token(char *cleantoken, char *token);
108*7c478bd9Sstevel@tonic-gate int	geti(char *str, int *iptr, int *wild);
109*7c478bd9Sstevel@tonic-gate uint64_t	input(int, char *, int, u_ioparam_t *, int *, int);
110*7c478bd9Sstevel@tonic-gate int	find_value(slist_t *slist, char *match_str, int *match_value);
111*7c478bd9Sstevel@tonic-gate char	*find_string(slist_t *slist, int match_value);
112*7c478bd9Sstevel@tonic-gate void	fmt_print(char *format, ...);
113*7c478bd9Sstevel@tonic-gate void	nolog_print(char *format, ...);
114*7c478bd9Sstevel@tonic-gate void	log_print(char *format, ...);
115*7c478bd9Sstevel@tonic-gate void	err_print(char *format, ...);
116*7c478bd9Sstevel@tonic-gate void	print_buf(char *buf, int nbytes);
117*7c478bd9Sstevel@tonic-gate void	pr_diskline(struct disk_info *disk, int num);
118*7c478bd9Sstevel@tonic-gate void	pr_dblock(void (*func)(char *, ...), diskaddr_t bn);
119*7c478bd9Sstevel@tonic-gate int	sup_gettoken(char *buf);
120*7c478bd9Sstevel@tonic-gate void	sup_pushtoken(char *token_buf, int token_type);
121*7c478bd9Sstevel@tonic-gate void	get_inputline(char *, int);
122*7c478bd9Sstevel@tonic-gate int	istokenpresent(void);
123*7c478bd9Sstevel@tonic-gate int	execute_shell(char *);
124*7c478bd9Sstevel@tonic-gate void	print_efi_string(char *vendor, char *product, char *revision,
125*7c478bd9Sstevel@tonic-gate     uint64_t capacity);
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate  * Most recent token type
129*7c478bd9Sstevel@tonic-gate  */
130*7c478bd9Sstevel@tonic-gate extern	int	last_token_type;
131*7c478bd9Sstevel@tonic-gate 
132*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
133*7c478bd9Sstevel@tonic-gate }
134*7c478bd9Sstevel@tonic-gate #endif
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate #endif	/* _IO_H */
137