xref: /illumos-gate/usr/src/cmd/format/misc.h (revision 589271a4)
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 /*
22*589271a4SSheng-Liang Eric Zhang  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_MISC_H
267c478bd9Sstevel@tonic-gate #define	_MISC_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * This file contains declarations pertaining to the miscellaneous routines.
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate #include <setjmp.h>
367c478bd9Sstevel@tonic-gate #include <termios.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Define macros bzero and bcopy for convenience
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate #ifndef	bzero
427c478bd9Sstevel@tonic-gate #define	bzero(p, n)		(void) memset((p), 0, (n))
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate #ifndef	bcopy
457c478bd9Sstevel@tonic-gate #define	bcopy(src, dst, n)	(void) memcpy((dst), (src), (n))
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate #ifndef	bcmp
487c478bd9Sstevel@tonic-gate #define	bcmp(p1, p2, n)		memcmp((p1), (p2), (n))
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Minimum and maximum macros
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #ifndef min
557c478bd9Sstevel@tonic-gate #define	min(x, y)	((x) < (y) ? (x) : (y))
567c478bd9Sstevel@tonic-gate #endif	/* min */
577c478bd9Sstevel@tonic-gate #ifndef max
587c478bd9Sstevel@tonic-gate #define	max(x, y)	((x) > (y) ? (x) : (y))
597c478bd9Sstevel@tonic-gate #endif	/* max */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * This defines the structure of a saved environment.  It consists of the
637c478bd9Sstevel@tonic-gate  * environment itself, a pointer to the next environment on the stack, and
647c478bd9Sstevel@tonic-gate  * flags to tell whether the environment is active, etc.
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate struct env {
677c478bd9Sstevel@tonic-gate 	jmp_buf env;				/* environment buf */
687c478bd9Sstevel@tonic-gate 	struct	env *ptr;			/* ptr to next on list */
697c478bd9Sstevel@tonic-gate 	char	flags;				/* flags */
707c478bd9Sstevel@tonic-gate };
717c478bd9Sstevel@tonic-gate extern	struct env *current_env;
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * This macro saves the current environment in the given structure and
747c478bd9Sstevel@tonic-gate  * pushes the structure onto our enivornment stack.  It initializes the
757c478bd9Sstevel@tonic-gate  * flags to zero (inactive).
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	saveenv(x)	{ \
787c478bd9Sstevel@tonic-gate 			x.ptr = current_env; \
797c478bd9Sstevel@tonic-gate 			current_env = &x; \
807c478bd9Sstevel@tonic-gate 			(void) setjmp(x.env); \
817c478bd9Sstevel@tonic-gate 			x.flags = 0; \
827c478bd9Sstevel@tonic-gate 			}
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * This macro marks the environment on the top of the stack active.  It
857c478bd9Sstevel@tonic-gate  * assumes that there is an environment on the stack.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate #define	useenv()	(current_env->flags |= ENV_USE)
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * This macro marks the environment on the top of the stack inactive.  It
907c478bd9Sstevel@tonic-gate  * assumes that there is an environment on the stack.
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	unuseenv()	(current_env->flags &= ~ENV_USE)
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * This macro pops an environment off the top of the stack.  It
957c478bd9Sstevel@tonic-gate  * assumes that there is an environment on the stack.
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	clearenv()	(current_env = current_env->ptr)
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate  * These are the flags for the environment struct.
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate #define	ENV_USE		0x01			/* active */
1027c478bd9Sstevel@tonic-gate #define	ENV_CRITICAL	0x02			/* in critical zone */
1037c478bd9Sstevel@tonic-gate #define	ENV_ABORT	0x04			/* abort pending */
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * This structure is used to keep track of the state of the tty.  This
1077c478bd9Sstevel@tonic-gate  * is necessary because some of the commands turn off echoing.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate struct ttystate {
1107c478bd9Sstevel@tonic-gate 	struct termios	ttystate;		/* buffer for ioctls */
1117c478bd9Sstevel@tonic-gate 	int		ttyflags;		/* changes to tty state */
1127c478bd9Sstevel@tonic-gate 	int		ttyfile;		/* file for ioctls */
1137c478bd9Sstevel@tonic-gate 	int		vmin;			/* min read satisfier */
1147c478bd9Sstevel@tonic-gate 	int		vtime;			/* read timing */
1157c478bd9Sstevel@tonic-gate };
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * ttyflags - changes we can make to the tty state.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate #define	TTY_ECHO_OFF	0x01			/* turned echo off */
1217c478bd9Sstevel@tonic-gate #define	TTY_CBREAK_ON	0x02			/* turned cbreak on */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * This is the number lines assumed for the tty.  It is designed to work
1257c478bd9Sstevel@tonic-gate  * on terminals as well as sun monitors.
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate #define	TTY_LINES	24
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * format parameter to dump()
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate #define	HEX_ONLY	0			/* print hex only */
1337c478bd9Sstevel@tonic-gate #define	HEX_ASCII	1			/* hex and ascii */
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  *	Prototypes for ANSI C
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate void	*zalloc(int count);
1407c478bd9Sstevel@tonic-gate void	*rezalloc(void *ptr, int count);
1417c478bd9Sstevel@tonic-gate void	destroy_data(char *data);
1427c478bd9Sstevel@tonic-gate int	check(char *question);
1437c478bd9Sstevel@tonic-gate void	cmdabort(int sig);
1447c478bd9Sstevel@tonic-gate void	onsusp(int sig);
1457c478bd9Sstevel@tonic-gate void	onalarm(int sig);
14637106d55Smike_s void	fullabort(void) __NORETURN;
1477c478bd9Sstevel@tonic-gate void	enter_critical(void);
1487c478bd9Sstevel@tonic-gate void	exit_critical(void);
1497c478bd9Sstevel@tonic-gate void	echo_off(void);
1507c478bd9Sstevel@tonic-gate void	echo_on(void);
1517c478bd9Sstevel@tonic-gate void	charmode_on(void);
1527c478bd9Sstevel@tonic-gate void	charmode_off(void);
1537c478bd9Sstevel@tonic-gate char	*alloc_string(char *s);
1547c478bd9Sstevel@tonic-gate char	**build_argvlist(char **, int *, int *, char *);
1557c478bd9Sstevel@tonic-gate int	conventional_name(char *name);
156*589271a4SSheng-Liang Eric Zhang #ifdef i386
157*589271a4SSheng-Liang Eric Zhang int	emcpower_name(char *name);
158*589271a4SSheng-Liang Eric Zhang #endif
159*589271a4SSheng-Liang Eric Zhang 
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #if defined(_FIRMWARE_NEEDS_FDISK)
1627c478bd9Sstevel@tonic-gate int	fdisk_physical_name(char *name);
1637c478bd9Sstevel@tonic-gate #endif	/* defined(_FIRMWARE_NEEDS_FDISK) */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate int	whole_disk_name(char *name);
1667c478bd9Sstevel@tonic-gate int	canonical_name(char *name);
1677c478bd9Sstevel@tonic-gate int	canonical4x_name(char *name);
1687c478bd9Sstevel@tonic-gate void	canonicalize_name(char *dst, char *src);
1697c478bd9Sstevel@tonic-gate int	match_substr(char *s1, char *s2);
1707c478bd9Sstevel@tonic-gate void	dump(char *, caddr_t, int, int);
1717c478bd9Sstevel@tonic-gate float	bn2mb(uint64_t);
172342440ecSPrasad Singamsetty diskaddr_t	mb2bn(float);
1737c478bd9Sstevel@tonic-gate float	bn2gb(uint64_t);
1747c478bd9Sstevel@tonic-gate float	bn2tb(uint64_t);
175342440ecSPrasad Singamsetty diskaddr_t	gb2bn(float);
1767c478bd9Sstevel@tonic-gate int	get_tty_lines();
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * Macro to handle internal programming errors that
1817c478bd9Sstevel@tonic-gate  * should "never happen".
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate #define	impossible(msg)	{err_print("Internal error: file %s, line %d: %s\n", \
1847c478bd9Sstevel@tonic-gate 				__FILE__, __LINE__, msg); \
1857c478bd9Sstevel@tonic-gate 			fullabort(); }
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate extern	char	*confirm_list[];
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  * This defines the size of the blind selection verfication prompt
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #define	BLIND_SELECT_VER_PROMPT	(43 + MAXNAMELEN)
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate #endif
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate #endif	/* _MISC_H */
201