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