xref: /titanic_51/usr/src/cmd/format/misc.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1991-2002 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_MISC_H
28*7c478bd9Sstevel@tonic-gate #define	_MISC_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate /*
37*7c478bd9Sstevel@tonic-gate  * This file contains declarations pertaining to the miscellaneous routines.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate #include <setjmp.h>
40*7c478bd9Sstevel@tonic-gate #include <termios.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * Define macros bzero and bcopy for convenience
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate #ifndef	bzero
46*7c478bd9Sstevel@tonic-gate #define	bzero(p, n)		(void) memset((p), 0, (n))
47*7c478bd9Sstevel@tonic-gate #endif
48*7c478bd9Sstevel@tonic-gate #ifndef	bcopy
49*7c478bd9Sstevel@tonic-gate #define	bcopy(src, dst, n)	(void) memcpy((dst), (src), (n))
50*7c478bd9Sstevel@tonic-gate #endif
51*7c478bd9Sstevel@tonic-gate #ifndef	bcmp
52*7c478bd9Sstevel@tonic-gate #define	bcmp(p1, p2, n)		memcmp((p1), (p2), (n))
53*7c478bd9Sstevel@tonic-gate #endif
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate /*
56*7c478bd9Sstevel@tonic-gate  * Minimum and maximum macros
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate #ifndef min
59*7c478bd9Sstevel@tonic-gate #define	min(x, y)	((x) < (y) ? (x) : (y))
60*7c478bd9Sstevel@tonic-gate #endif	/* min */
61*7c478bd9Sstevel@tonic-gate #ifndef max
62*7c478bd9Sstevel@tonic-gate #define	max(x, y)	((x) > (y) ? (x) : (y))
63*7c478bd9Sstevel@tonic-gate #endif	/* max */
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate  * This defines the structure of a saved environment.  It consists of the
67*7c478bd9Sstevel@tonic-gate  * environment itself, a pointer to the next environment on the stack, and
68*7c478bd9Sstevel@tonic-gate  * flags to tell whether the environment is active, etc.
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate struct env {
71*7c478bd9Sstevel@tonic-gate 	jmp_buf env;				/* environment buf */
72*7c478bd9Sstevel@tonic-gate 	struct	env *ptr;			/* ptr to next on list */
73*7c478bd9Sstevel@tonic-gate 	char	flags;				/* flags */
74*7c478bd9Sstevel@tonic-gate };
75*7c478bd9Sstevel@tonic-gate extern	struct env *current_env;
76*7c478bd9Sstevel@tonic-gate /*
77*7c478bd9Sstevel@tonic-gate  * This macro saves the current environment in the given structure and
78*7c478bd9Sstevel@tonic-gate  * pushes the structure onto our enivornment stack.  It initializes the
79*7c478bd9Sstevel@tonic-gate  * flags to zero (inactive).
80*7c478bd9Sstevel@tonic-gate  */
81*7c478bd9Sstevel@tonic-gate #define	saveenv(x)	{ \
82*7c478bd9Sstevel@tonic-gate 			x.ptr = current_env; \
83*7c478bd9Sstevel@tonic-gate 			current_env = &x; \
84*7c478bd9Sstevel@tonic-gate 			(void) setjmp(x.env); \
85*7c478bd9Sstevel@tonic-gate 			x.flags = 0; \
86*7c478bd9Sstevel@tonic-gate 			}
87*7c478bd9Sstevel@tonic-gate /*
88*7c478bd9Sstevel@tonic-gate  * This macro marks the environment on the top of the stack active.  It
89*7c478bd9Sstevel@tonic-gate  * assumes that there is an environment on the stack.
90*7c478bd9Sstevel@tonic-gate  */
91*7c478bd9Sstevel@tonic-gate #define	useenv()	(current_env->flags |= ENV_USE)
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * This macro marks the environment on the top of the stack inactive.  It
94*7c478bd9Sstevel@tonic-gate  * assumes that there is an environment on the stack.
95*7c478bd9Sstevel@tonic-gate  */
96*7c478bd9Sstevel@tonic-gate #define	unuseenv()	(current_env->flags &= ~ENV_USE)
97*7c478bd9Sstevel@tonic-gate /*
98*7c478bd9Sstevel@tonic-gate  * This macro pops an environment off the top of the stack.  It
99*7c478bd9Sstevel@tonic-gate  * assumes that there is an environment on the stack.
100*7c478bd9Sstevel@tonic-gate  */
101*7c478bd9Sstevel@tonic-gate #define	clearenv()	(current_env = current_env->ptr)
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  * These are the flags for the environment struct.
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate #define	ENV_USE		0x01			/* active */
106*7c478bd9Sstevel@tonic-gate #define	ENV_CRITICAL	0x02			/* in critical zone */
107*7c478bd9Sstevel@tonic-gate #define	ENV_ABORT	0x04			/* abort pending */
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate /*
110*7c478bd9Sstevel@tonic-gate  * This structure is used to keep track of the state of the tty.  This
111*7c478bd9Sstevel@tonic-gate  * is necessary because some of the commands turn off echoing.
112*7c478bd9Sstevel@tonic-gate  */
113*7c478bd9Sstevel@tonic-gate struct ttystate {
114*7c478bd9Sstevel@tonic-gate 	struct termios	ttystate;		/* buffer for ioctls */
115*7c478bd9Sstevel@tonic-gate 	int		ttyflags;		/* changes to tty state */
116*7c478bd9Sstevel@tonic-gate 	int		ttyfile;		/* file for ioctls */
117*7c478bd9Sstevel@tonic-gate 	int		vmin;			/* min read satisfier */
118*7c478bd9Sstevel@tonic-gate 	int		vtime;			/* read timing */
119*7c478bd9Sstevel@tonic-gate };
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /*
122*7c478bd9Sstevel@tonic-gate  * ttyflags - changes we can make to the tty state.
123*7c478bd9Sstevel@tonic-gate  */
124*7c478bd9Sstevel@tonic-gate #define	TTY_ECHO_OFF	0x01			/* turned echo off */
125*7c478bd9Sstevel@tonic-gate #define	TTY_CBREAK_ON	0x02			/* turned cbreak on */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate  * This is the number lines assumed for the tty.  It is designed to work
129*7c478bd9Sstevel@tonic-gate  * on terminals as well as sun monitors.
130*7c478bd9Sstevel@tonic-gate  */
131*7c478bd9Sstevel@tonic-gate #define	TTY_LINES	24
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate /*
134*7c478bd9Sstevel@tonic-gate  * format parameter to dump()
135*7c478bd9Sstevel@tonic-gate  */
136*7c478bd9Sstevel@tonic-gate #define	HEX_ONLY	0			/* print hex only */
137*7c478bd9Sstevel@tonic-gate #define	HEX_ASCII	1			/* hex and ascii */
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate /*
141*7c478bd9Sstevel@tonic-gate  *	Prototypes for ANSI C
142*7c478bd9Sstevel@tonic-gate  */
143*7c478bd9Sstevel@tonic-gate void	*zalloc(int count);
144*7c478bd9Sstevel@tonic-gate void	*rezalloc(void *ptr, int count);
145*7c478bd9Sstevel@tonic-gate void	destroy_data(char *data);
146*7c478bd9Sstevel@tonic-gate int	check(char *question);
147*7c478bd9Sstevel@tonic-gate void	cmdabort(int sig);
148*7c478bd9Sstevel@tonic-gate void	onsusp(int sig);
149*7c478bd9Sstevel@tonic-gate void	onalarm(int sig);
150*7c478bd9Sstevel@tonic-gate void	fullabort(void);
151*7c478bd9Sstevel@tonic-gate void	enter_critical(void);
152*7c478bd9Sstevel@tonic-gate void	exit_critical(void);
153*7c478bd9Sstevel@tonic-gate void	echo_off(void);
154*7c478bd9Sstevel@tonic-gate void	echo_on(void);
155*7c478bd9Sstevel@tonic-gate void	charmode_on(void);
156*7c478bd9Sstevel@tonic-gate void	charmode_off(void);
157*7c478bd9Sstevel@tonic-gate char	*alloc_string(char *s);
158*7c478bd9Sstevel@tonic-gate char	**build_argvlist(char **, int *, int *, char *);
159*7c478bd9Sstevel@tonic-gate int	conventional_name(char *name);
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate #if defined(_FIRMWARE_NEEDS_FDISK)
162*7c478bd9Sstevel@tonic-gate int	fdisk_physical_name(char *name);
163*7c478bd9Sstevel@tonic-gate #endif	/* defined(_FIRMWARE_NEEDS_FDISK) */
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate int	whole_disk_name(char *name);
166*7c478bd9Sstevel@tonic-gate int	canonical_name(char *name);
167*7c478bd9Sstevel@tonic-gate int	canonical4x_name(char *name);
168*7c478bd9Sstevel@tonic-gate void	canonicalize_name(char *dst, char *src);
169*7c478bd9Sstevel@tonic-gate int	match_substr(char *s1, char *s2);
170*7c478bd9Sstevel@tonic-gate void	dump(char *, caddr_t, int, int);
171*7c478bd9Sstevel@tonic-gate float	bn2mb(uint64_t);
172*7c478bd9Sstevel@tonic-gate uint_t	mb2bn(float);
173*7c478bd9Sstevel@tonic-gate float	bn2gb(uint64_t);
174*7c478bd9Sstevel@tonic-gate float	bn2tb(uint64_t);
175*7c478bd9Sstevel@tonic-gate uint_t	gb2bn(float);
176*7c478bd9Sstevel@tonic-gate int	get_tty_lines();
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate /*
180*7c478bd9Sstevel@tonic-gate  * Macro to handle internal programming errors that
181*7c478bd9Sstevel@tonic-gate  * should "never happen".
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate #define	impossible(msg)	{err_print("Internal error: file %s, line %d: %s\n", \
184*7c478bd9Sstevel@tonic-gate 				__FILE__, __LINE__, msg); \
185*7c478bd9Sstevel@tonic-gate 			fullabort(); }
186*7c478bd9Sstevel@tonic-gate 
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate extern	char	*confirm_list[];
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate /*
191*7c478bd9Sstevel@tonic-gate  * This defines the size of the blind selection verfication prompt
192*7c478bd9Sstevel@tonic-gate  */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate #define	BLIND_SELECT_VER_PROMPT	(43 + MAXNAMELEN)
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
197*7c478bd9Sstevel@tonic-gate }
198*7c478bd9Sstevel@tonic-gate #endif
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate #endif	/* _MISC_H */
201