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