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