xref: /illumos-gate/usr/src/cmd/format/io.h (revision ecc39deb)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5342440ecSPrasad Singamsetty  * Common Development and Distribution License (the "License").
6342440ecSPrasad Singamsetty  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22342440ecSPrasad Singamsetty  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_IO_H
277c478bd9Sstevel@tonic-gate #define	_IO_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Bounds structure for integer and disk input.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate struct bounds {
387c478bd9Sstevel@tonic-gate 	diskaddr_t	lower;
397c478bd9Sstevel@tonic-gate 	diskaddr_t	upper;
407c478bd9Sstevel@tonic-gate };
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * List of strings with arbitrary matching values
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate typedef struct slist {
467c478bd9Sstevel@tonic-gate 	char	*str;
477c478bd9Sstevel@tonic-gate 	char	*help;
487c478bd9Sstevel@tonic-gate 	int	value;
497c478bd9Sstevel@tonic-gate } slist_t;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Input structure for current partition information
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate typedef struct partition_defaults {
55342440ecSPrasad Singamsetty 	uint_t start_cyl;
56342440ecSPrasad Singamsetty 	uint_t deflt_size;
577c478bd9Sstevel@tonic-gate } part_deflt_t;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef struct efi_defaults {
607c478bd9Sstevel@tonic-gate 	uint64_t	start_sector;
617c478bd9Sstevel@tonic-gate 	uint64_t	end_sector;
627c478bd9Sstevel@tonic-gate } efi_deflt_t;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Input parameter can be any one of these types.
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate typedef union input_param {
687c478bd9Sstevel@tonic-gate 	struct slist	*io_slist;
697c478bd9Sstevel@tonic-gate 	char		**io_charlist;
707c478bd9Sstevel@tonic-gate 	struct bounds	io_bounds;
717c478bd9Sstevel@tonic-gate } u_ioparam_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * These declarations define the legal input types.
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate #define	FIO_BN		0		/* block number */
777c478bd9Sstevel@tonic-gate #define	FIO_INT		1		/* integer input */
787c478bd9Sstevel@tonic-gate #define	FIO_CSTR	2		/* closed string - exact match */
797c478bd9Sstevel@tonic-gate #define	FIO_MSTR	3		/* matched string, with abbreviations */
807c478bd9Sstevel@tonic-gate #define	FIO_OSTR	4		/* open string - anything's legal */
817c478bd9Sstevel@tonic-gate #define	FIO_BLNK	5		/* blank line */
827c478bd9Sstevel@tonic-gate #define	FIO_SLIST	6		/* one string out of a list, abbr. */
837c478bd9Sstevel@tonic-gate #define	FIO_CYL		7		/* nblocks, on cylinder boundary */
847c478bd9Sstevel@tonic-gate #define	FIO_OPINT	8		/* optional integer input */
857c478bd9Sstevel@tonic-gate #define	FIO_ECYL	9		/* allows end cylinder input */
867c478bd9Sstevel@tonic-gate #define	FIO_INT64	10		/* Input for EFI partitions */
877c478bd9Sstevel@tonic-gate #define	FIO_EFI		11		/* Input EFI part size	*/
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * Miscellaneous definitions.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	TOKEN_SIZE	36			/* max length of a token */
937c478bd9Sstevel@tonic-gate typedef	char TOKEN[TOKEN_SIZE+1];		/* token type */
947c478bd9Sstevel@tonic-gate #define	DATA_INPUT	0			/* 2 modes of input */
957c478bd9Sstevel@tonic-gate #define	CMD_INPUT	1
967c478bd9Sstevel@tonic-gate #define	WILD_STRING	"$"			/* wildcard character */
977c478bd9Sstevel@tonic-gate #define	COMMENT_CHAR	'#'			/* comment character */
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate /*
1017c478bd9Sstevel@tonic-gate  *	Prototypes for ANSI C
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate char	*gettoken(char *inbuf);
1047c478bd9Sstevel@tonic-gate void	clean_token(char *cleantoken, char *token);
1057c478bd9Sstevel@tonic-gate int	geti(char *str, int *iptr, int *wild);
1067c478bd9Sstevel@tonic-gate uint64_t	input(int, char *, int, u_ioparam_t *, int *, int);
1077c478bd9Sstevel@tonic-gate int	find_value(slist_t *slist, char *match_str, int *match_value);
1087c478bd9Sstevel@tonic-gate char	*find_string(slist_t *slist, int match_value);
109*ecc39debSToomas Soome void	fmt_print(char *format, ...) __PRINTFLIKE(1);
110*ecc39debSToomas Soome void	nolog_print(char *format, ...) __PRINTFLIKE(1);
111*ecc39debSToomas Soome void	log_print(char *format, ...) __PRINTFLIKE(1);
112*ecc39debSToomas Soome void	err_print(char *format, ...) __PRINTFLIKE(1);
1137c478bd9Sstevel@tonic-gate void	print_buf(char *buf, int nbytes);
1147c478bd9Sstevel@tonic-gate void	pr_diskline(struct disk_info *disk, int num);
1157c478bd9Sstevel@tonic-gate void	pr_dblock(void (*func)(char *, ...), diskaddr_t bn);
1167c478bd9Sstevel@tonic-gate int	sup_gettoken(char *buf);
1177c478bd9Sstevel@tonic-gate void	sup_pushtoken(char *token_buf, int token_type);
1187c478bd9Sstevel@tonic-gate void	get_inputline(char *, int);
1197c478bd9Sstevel@tonic-gate int	istokenpresent(void);
120f1c60556Spr int	execute_shell(char *, size_t);
1217c478bd9Sstevel@tonic-gate void	print_efi_string(char *vendor, char *product, char *revision,
1227c478bd9Sstevel@tonic-gate     uint64_t capacity);
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * Most recent token type
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate extern	int	last_token_type;
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate #endif
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #endif	/* _IO_H */
134