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