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