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