libuutil: move under bmake
[unleashed.git] / usr / src / cmd / format / prompts.c
blobf42a2434f746d4aa2334eb2d410876945bd116bf
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * This file contains functions to prompt the user for various
28 * disk characteristics. By isolating these into functions,
29 * we can guarantee that prompts, defaults, etc are identical.
31 #include "global.h"
32 #include "prompts.h"
33 #include "io.h"
34 #include "param.h"
35 #include "startup.h"
37 #ifdef sparc
38 #include <sys/hdio.h>
39 #endif
43 * Prompt for max number of LBA
45 uint64_t
46 get_mlba()
48 u_ioparam_t ioparam;
50 ioparam.io_bounds.lower = (1024 * 16) + 68;
51 ioparam.io_bounds.upper = UINT_MAX64;
53 return (input(FIO_INT64, "Enter maximum number of LBAs",
54 ':', &ioparam, NULL, DATA_INPUT));
58 * Prompt for number of cylinders
60 int
61 get_ncyl()
63 u_ioparam_t ioparam;
65 ioparam.io_bounds.lower = 1;
66 ioparam.io_bounds.upper = MAX_CYLS;
67 return (input(FIO_INT, "Enter number of data cylinders",
68 ':', &ioparam, NULL, DATA_INPUT));
72 * Prompt for number of alternate cylinders
74 int
75 get_acyl(n_cyls)
76 int n_cyls;
78 u_ioparam_t ioparam;
79 int deflt;
81 ioparam.io_bounds.lower = 2;
82 ioparam.io_bounds.upper = MAX_CYLS - n_cyls;
83 deflt = 2;
84 return (input(FIO_INT, "Enter number of alternate cylinders", ':',
85 &ioparam, &deflt, DATA_INPUT));
89 * Prompt for number of physical cylinders
91 int
92 get_pcyl(n_cyls, a_cyls)
93 int n_cyls;
94 int a_cyls;
96 u_ioparam_t ioparam;
97 int deflt;
99 ioparam.io_bounds.lower = n_cyls + a_cyls;
100 ioparam.io_bounds.upper = MAX_CYLS;
101 deflt = n_cyls + a_cyls;
102 return (input(FIO_INT, "Enter number of physical cylinders", ':',
103 &ioparam, &deflt, DATA_INPUT));
107 * Prompt for number of heads
110 get_nhead()
112 u_ioparam_t ioparam;
114 ioparam.io_bounds.lower = 1;
115 ioparam.io_bounds.upper = MAX_HEADS;
116 return (input(FIO_INT, "Enter number of heads", ':',
117 &ioparam, NULL, DATA_INPUT));
121 * Prompt for number of physical heads
124 get_phead(n_heads, options)
125 int n_heads;
126 ulong_t *options;
128 u_ioparam_t ioparam;
129 int deflt;
131 if (SCSI) {
132 ioparam.io_bounds.lower = n_heads;
133 ioparam.io_bounds.upper = INFINITY;
134 if (input(FIO_OPINT, "Enter physical number of heads",
135 ':', &ioparam, &deflt, DATA_INPUT)) {
136 *options |= SUP_PHEAD;
137 return (deflt);
140 return (0);
145 * Prompt for number of sectors per track
148 get_nsect()
150 u_ioparam_t ioparam;
152 ioparam.io_bounds.lower = 1;
153 ioparam.io_bounds.upper = MAX_SECTS;
154 return (input(FIO_INT,
155 "Enter number of data sectors/track", ':',
156 &ioparam, NULL, DATA_INPUT));
160 * Prompt for number of physical sectors per track
163 get_psect(options)
164 ulong_t *options;
166 u_ioparam_t ioparam;
167 int deflt;
169 if (SCSI) {
170 ioparam.io_bounds.lower = 0;
171 ioparam.io_bounds.upper = INFINITY;
172 if (input(FIO_OPINT, "Enter number of physical sectors/track",
173 ':', &ioparam, &deflt, DATA_INPUT)) {
174 *options |= SUP_PSECT;
175 return (deflt);
178 return (0);
182 * Prompt for bytes per track
185 get_bpt(n_sects, options)
186 int n_sects;
187 ulong_t *options;
189 u_ioparam_t ioparam;
190 int deflt;
192 if (SMD) {
193 *options |= SUP_BPT;
194 ioparam.io_bounds.lower = 1;
195 ioparam.io_bounds.upper = INFINITY;
196 deflt = n_sects * cur_blksz;
197 return (input(FIO_INT, "Enter number of bytes/track",
198 ':', &ioparam, &deflt, DATA_INPUT));
201 return (0);
205 * Prompt for rpm
208 get_rpm()
210 u_ioparam_t ioparam;
211 int deflt;
213 ioparam.io_bounds.lower = MIN_RPM;
214 ioparam.io_bounds.upper = MAX_RPM;
215 deflt = AVG_RPM;
216 return (input(FIO_INT, "Enter rpm of drive", ':',
217 &ioparam, &deflt, DATA_INPUT));
221 * Prompt for formatting time
224 get_fmt_time(options)
225 ulong_t *options;
227 u_ioparam_t ioparam;
228 int deflt;
230 ioparam.io_bounds.lower = 0;
231 ioparam.io_bounds.upper = INFINITY;
232 if (input(FIO_OPINT, "Enter format time", ':',
233 &ioparam, &deflt, DATA_INPUT)) {
234 *options |= SUP_FMTTIME;
235 return (deflt);
237 return (0);
241 * Prompt for cylinder skew
244 get_cyl_skew(options)
245 ulong_t *options;
247 u_ioparam_t ioparam;
248 int deflt;
250 ioparam.io_bounds.lower = 0;
251 ioparam.io_bounds.upper = INFINITY;
252 if (input(FIO_OPINT, "Enter cylinder skew", ':',
253 &ioparam, &deflt, DATA_INPUT)) {
254 *options |= SUP_CYLSKEW;
255 return (deflt);
257 return (0);
261 * Prompt for track skew
264 get_trk_skew(options)
265 ulong_t *options;
267 u_ioparam_t ioparam;
268 int deflt;
270 ioparam.io_bounds.lower = 0;
271 ioparam.io_bounds.upper = INFINITY;
272 if (input(FIO_OPINT, "Enter track skew", ':',
273 &ioparam, &deflt, DATA_INPUT)) {
274 *options |= SUP_TRKSKEW;
275 return (deflt);
277 return (0);
281 * Prompt for tracks per zone
284 get_trks_zone(options)
285 ulong_t *options;
287 u_ioparam_t ioparam;
288 int deflt;
290 ioparam.io_bounds.lower = 0;
291 ioparam.io_bounds.upper = INFINITY;
292 if (input(FIO_OPINT, "Enter tracks per zone", ':',
293 &ioparam, &deflt, DATA_INPUT)) {
294 *options |= SUP_TRKS_ZONE;
295 return (deflt);
297 return (0);
301 * Prompt for alternate tracks
304 get_atrks(options)
305 ulong_t *options;
307 u_ioparam_t ioparam;
308 int deflt;
310 ioparam.io_bounds.lower = 0;
311 ioparam.io_bounds.upper = INFINITY;
312 if (input(FIO_OPINT, "Enter alternate tracks", ':',
313 &ioparam, &deflt, DATA_INPUT)) {
314 *options |= SUP_ATRKS;
315 return (deflt);
317 return (0);
321 * Prompt for alternate sectors
324 get_asect(options)
325 ulong_t *options;
327 u_ioparam_t ioparam;
328 int deflt;
330 ioparam.io_bounds.lower = 0;
331 ioparam.io_bounds.upper = INFINITY;
332 if (input(FIO_OPINT, "Enter alternate sectors", ':',
333 &ioparam, &deflt, DATA_INPUT)) {
334 *options |= SUP_ASECT;
335 return (deflt);
337 return (0);
341 * Prompt for cache setting
344 get_cache(options)
345 ulong_t *options;
347 u_ioparam_t ioparam;
348 int deflt;
350 ioparam.io_bounds.lower = 0;
351 ioparam.io_bounds.upper = 0xff;
352 if (input(FIO_OPINT, "Enter cache control", ':',
353 &ioparam, &deflt, DATA_INPUT)) {
354 *options |= SUP_CACHE;
355 return (deflt);
357 return (0);
361 * Prompt for prefetch threshold
364 get_threshold(options)
365 ulong_t *options;
367 u_ioparam_t ioparam;
368 int deflt;
370 ioparam.io_bounds.lower = 0;
371 ioparam.io_bounds.upper = INFINITY;
372 if (input(FIO_OPINT, "Enter prefetch threshold",
373 ':', &ioparam, &deflt, DATA_INPUT)) {
374 *options |= SUP_PREFETCH;
375 return (deflt);
377 return (0);
381 * Prompt for minimum prefetch
384 get_min_prefetch(options)
385 ulong_t *options;
387 u_ioparam_t ioparam;
388 int deflt;
390 ioparam.io_bounds.lower = 0;
391 ioparam.io_bounds.upper = INFINITY;
392 if (input(FIO_OPINT, "Enter minimum prefetch",
393 ':', &ioparam, &deflt, DATA_INPUT)) {
394 *options |= SUP_CACHE_MIN;
395 return (deflt);
397 return (0);
401 * Prompt for maximum prefetch
404 get_max_prefetch(min_prefetch, options)
405 int min_prefetch;
406 ulong_t *options;
408 u_ioparam_t ioparam;
409 int deflt;
411 ioparam.io_bounds.lower = min_prefetch;
412 ioparam.io_bounds.upper = INFINITY;
413 if (input(FIO_OPINT, "Enter maximum prefetch",
414 ':', &ioparam, &deflt, DATA_INPUT)) {
415 *options |= SUP_CACHE_MAX;
416 return (deflt);
418 return (0);
422 * Prompt for bytes per sector
425 get_bps()
427 u_ioparam_t ioparam;
428 int deflt;
430 if (cur_ctype->ctype_flags & CF_SMD_DEFS) {
431 ioparam.io_bounds.lower = MIN_BPS;
432 ioparam.io_bounds.upper = MAX_BPS;
433 deflt = AVG_BPS;
434 return (input(FIO_INT, "Enter bytes per sector",
435 ':', &ioparam, &deflt, DATA_INPUT));
438 return (0);
442 * Prompt for ascii label
444 char *
445 get_asciilabel()
447 return ((char *)(uintptr_t)input(FIO_OSTR,
448 "Enter disk type name (remember quotes)", ':',
449 (u_ioparam_t *)NULL, NULL, DATA_INPUT));