xref: /titanic_50/usr/src/cmd/format/misc.h (revision 9b902bdefd2b455e3a0a235f279879c5a30eb1d5)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_MISC_H
26 #define	_MISC_H
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * This file contains declarations pertaining to the miscellaneous routines.
34  */
35 #include <setjmp.h>
36 #include <termios.h>
37 
38 /*
39  * Define macros bzero and bcopy for convenience
40  */
41 #ifndef	bzero
42 #define	bzero(p, n)		(void) memset((p), 0, (n))
43 #endif
44 #ifndef	bcopy
45 #define	bcopy(src, dst, n)	(void) memcpy((dst), (src), (n))
46 #endif
47 #ifndef	bcmp
48 #define	bcmp(p1, p2, n)		memcmp((p1), (p2), (n))
49 #endif
50 
51 /*
52  * Minimum and maximum macros
53  */
54 #ifndef min
55 #define	min(x, y)	((x) < (y) ? (x) : (y))
56 #endif	/* min */
57 #ifndef max
58 #define	max(x, y)	((x) > (y) ? (x) : (y))
59 #endif	/* max */
60 
61 /*
62  * This defines the structure of a saved environment.  It consists of the
63  * environment itself, a pointer to the next environment on the stack, and
64  * flags to tell whether the environment is active, etc.
65  */
66 struct env {
67 	jmp_buf env;				/* environment buf */
68 	struct	env *ptr;			/* ptr to next on list */
69 	char	flags;				/* flags */
70 };
71 extern	struct env *current_env;
72 /*
73  * This macro saves the current environment in the given structure and
74  * pushes the structure onto our enivornment stack.  It initializes the
75  * flags to zero (inactive).
76  */
77 #define	saveenv(x)	{ \
78 			x.ptr = current_env; \
79 			current_env = &x; \
80 			(void) setjmp(x.env); \
81 			x.flags = 0; \
82 			}
83 /*
84  * This macro marks the environment on the top of the stack active.  It
85  * assumes that there is an environment on the stack.
86  */
87 #define	useenv()	(current_env->flags |= ENV_USE)
88 /*
89  * This macro marks the environment on the top of the stack inactive.  It
90  * assumes that there is an environment on the stack.
91  */
92 #define	unuseenv()	(current_env->flags &= ~ENV_USE)
93 /*
94  * This macro pops an environment off the top of the stack.  It
95  * assumes that there is an environment on the stack.
96  */
97 #define	clearenv()	(current_env = current_env->ptr)
98 /*
99  * These are the flags for the environment struct.
100  */
101 #define	ENV_USE		0x01			/* active */
102 #define	ENV_CRITICAL	0x02			/* in critical zone */
103 #define	ENV_ABORT	0x04			/* abort pending */
104 
105 /*
106  * This structure is used to keep track of the state of the tty.  This
107  * is necessary because some of the commands turn off echoing.
108  */
109 struct ttystate {
110 	struct termios	ttystate;		/* buffer for ioctls */
111 	int		ttyflags;		/* changes to tty state */
112 	int		ttyfile;		/* file for ioctls */
113 	int		vmin;			/* min read satisfier */
114 	int		vtime;			/* read timing */
115 };
116 
117 /*
118  * ttyflags - changes we can make to the tty state.
119  */
120 #define	TTY_ECHO_OFF	0x01			/* turned echo off */
121 #define	TTY_CBREAK_ON	0x02			/* turned cbreak on */
122 
123 /*
124  * This is the number lines assumed for the tty.  It is designed to work
125  * on terminals as well as sun monitors.
126  */
127 #define	TTY_LINES	24
128 
129 /*
130  * format parameter to dump()
131  */
132 #define	HEX_ONLY	0			/* print hex only */
133 #define	HEX_ASCII	1			/* hex and ascii */
134 
135 
136 /*
137  *	Prototypes for ANSI C
138  */
139 void	*zalloc(int count);
140 void	*rezalloc(void *ptr, int count);
141 void	destroy_data(char *data);
142 int	check(char *question);
143 void	cmdabort(int sig);
144 void	onsusp(int sig);
145 void	onalarm(int sig);
146 void	fullabort(void) __NORETURN;
147 void	enter_critical(void);
148 void	exit_critical(void);
149 void	echo_off(void);
150 void	echo_on(void);
151 void	charmode_on(void);
152 void	charmode_off(void);
153 char	*alloc_string(char *s);
154 char	**build_argvlist(char **, int *, int *, char *);
155 int	conventional_name(char *name);
156 #ifdef i386
157 int	emcpower_name(char *name);
158 #endif
159 
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 diskaddr_t	mb2bn(float);
173 float	bn2gb(uint64_t);
174 float	bn2tb(uint64_t);
175 diskaddr_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