xref: /titanic_50/usr/src/cmd/format/prompts.c (revision 355d6bb5e62a215a9bcf820ac85c1fc62bed2f3f)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * This file contains functions to prompt the user for various
31  * disk characteristics.  By isolating these into functions,
32  * we can guarantee that prompts, defaults, etc are identical.
33  */
34 #include "global.h"
35 #include "prompts.h"
36 #include "io.h"
37 #include "param.h"
38 #include "startup.h"
39 
40 #ifdef sparc
41 #include <sys/hdio.h>
42 #endif
43 
44 
45 /*
46  * Prompt for max number of LBA
47  */
48 uint64_t
49 get_mlba()
50 {
51 	u_ioparam_t	ioparam;
52 
53 	ioparam.io_bounds.lower = (1024 * 16) + 68;
54 	ioparam.io_bounds.upper = UINT_MAX64;
55 
56 	return (input(FIO_INT64, "Enter maximum number of LBAs",
57 	    ':', &ioparam, (int *)NULL, DATA_INPUT));
58 }
59 
60 /*
61  * Prompt for number of cylinders
62  */
63 int
64 get_ncyl()
65 {
66 	u_ioparam_t	ioparam;
67 
68 	ioparam.io_bounds.lower = 1;
69 	ioparam.io_bounds.upper = MAX_CYLS;
70 	return (input(FIO_INT, "Enter number of data cylinders",
71 	    ':', &ioparam, (int *)NULL, DATA_INPUT));
72 }
73 
74 /*
75  * Prompt for number of alternate cylinders
76  */
77 int
78 get_acyl(n_cyls)
79 	int		n_cyls;
80 {
81 	u_ioparam_t	ioparam;
82 	int		deflt;
83 
84 	ioparam.io_bounds.lower = 2;
85 	ioparam.io_bounds.upper = MAX_CYLS - n_cyls;
86 	deflt = 2;
87 	return (input(FIO_INT, "Enter number of alternate cylinders", ':',
88 	    &ioparam, &deflt, DATA_INPUT));
89 }
90 
91 /*
92  * Prompt for number of physical cylinders
93  */
94 int
95 get_pcyl(n_cyls, a_cyls)
96 	int		n_cyls;
97 	int		a_cyls;
98 {
99 	u_ioparam_t	ioparam;
100 	int		deflt;
101 
102 	ioparam.io_bounds.lower = n_cyls + a_cyls;
103 	ioparam.io_bounds.upper = MAX_CYLS;
104 	deflt = n_cyls + a_cyls;
105 	return (input(FIO_INT, "Enter number of physical cylinders", ':',
106 	    &ioparam, &deflt, DATA_INPUT));
107 }
108 
109 /*
110  * Prompt for number of heads
111  */
112 int
113 get_nhead()
114 {
115 	u_ioparam_t	ioparam;
116 
117 	ioparam.io_bounds.lower = 1;
118 	ioparam.io_bounds.upper = MAX_HEADS;
119 	return (input(FIO_INT, "Enter number of heads", ':',
120 	    &ioparam, (int *)NULL, DATA_INPUT));
121 }
122 
123 /*
124  * Prompt for number of physical heads
125  */
126 int
127 get_phead(n_heads, options)
128 	int		n_heads;
129 	ulong_t		*options;
130 {
131 	u_ioparam_t	ioparam;
132 	int		deflt;
133 
134 	if (SCSI) {
135 		ioparam.io_bounds.lower = n_heads;
136 		ioparam.io_bounds.upper = INFINITY;
137 		if (input(FIO_OPINT, "Enter physical number of heads",
138 				':', &ioparam, &deflt, DATA_INPUT)) {
139 			*options |= SUP_PHEAD;
140 			return (deflt);
141 		}
142 	}
143 	return (0);
144 }
145 
146 
147 /*
148  * Prompt for number of sectors per track
149  */
150 int
151 get_nsect()
152 {
153 	u_ioparam_t	ioparam;
154 
155 	ioparam.io_bounds.lower = 1;
156 	ioparam.io_bounds.upper = MAX_SECTS;
157 	return (input(FIO_INT,
158 	    "Enter number of data sectors/track", ':',
159 	    &ioparam, (int *)NULL, DATA_INPUT));
160 }
161 
162 /*
163  * Prompt for number of physical sectors per track
164  */
165 int
166 get_psect(options)
167 	ulong_t		*options;
168 {
169 	u_ioparam_t	ioparam;
170 	int		deflt;
171 
172 	if (SCSI) {
173 		ioparam.io_bounds.lower = 0;
174 		ioparam.io_bounds.upper = INFINITY;
175 		if (input(FIO_OPINT, "Enter number of physical sectors/track",
176 				':', &ioparam, &deflt, DATA_INPUT)) {
177 			*options |= SUP_PSECT;
178 			return (deflt);
179 		}
180 	}
181 	return (0);
182 }
183 
184 /*
185  * Prompt for bytes per track
186  */
187 int
188 get_bpt(n_sects, options)
189 	int		n_sects;
190 	ulong_t		*options;
191 {
192 	u_ioparam_t	ioparam;
193 	int		deflt;
194 
195 	if (SMD) {
196 		*options |= SUP_BPT;
197 		ioparam.io_bounds.lower = 1;
198 		ioparam.io_bounds.upper = INFINITY;
199 		deflt = n_sects * SECSIZE;
200 		return (input(FIO_INT, "Enter number of bytes/track",
201 				':', &ioparam, &deflt, DATA_INPUT));
202 	}
203 
204 	return (0);
205 }
206 
207 /*
208  * Prompt for rpm
209  */
210 int
211 get_rpm()
212 {
213 	u_ioparam_t	ioparam;
214 	int		deflt;
215 
216 	ioparam.io_bounds.lower = MIN_RPM;
217 	ioparam.io_bounds.upper = MAX_RPM;
218 	deflt = AVG_RPM;
219 	return (input(FIO_INT, "Enter rpm of drive", ':',
220 	    &ioparam, &deflt, DATA_INPUT));
221 }
222 
223 /*
224  * Prompt for formatting time
225  */
226 int
227 get_fmt_time(options)
228 	ulong_t		*options;
229 {
230 	u_ioparam_t	ioparam;
231 	int		deflt;
232 
233 	ioparam.io_bounds.lower = 0;
234 	ioparam.io_bounds.upper = INFINITY;
235 	if (input(FIO_OPINT, "Enter format time", ':',
236 			&ioparam, &deflt, DATA_INPUT)) {
237 		*options |= SUP_FMTTIME;
238 		return (deflt);
239 	}
240 	return (0);
241 }
242 
243 /*
244  * Prompt for cylinder skew
245  */
246 int
247 get_cyl_skew(options)
248 	ulong_t		*options;
249 {
250 	u_ioparam_t	ioparam;
251 	int		deflt;
252 
253 	ioparam.io_bounds.lower = 0;
254 	ioparam.io_bounds.upper = INFINITY;
255 	if (input(FIO_OPINT, "Enter cylinder skew", ':',
256 			&ioparam, &deflt, DATA_INPUT)) {
257 		*options |= SUP_CYLSKEW;
258 		return (deflt);
259 	}
260 	return (0);
261 }
262 
263 /*
264  * Prompt for track skew
265  */
266 int
267 get_trk_skew(options)
268 	ulong_t		*options;
269 {
270 	u_ioparam_t	ioparam;
271 	int		deflt;
272 
273 	ioparam.io_bounds.lower = 0;
274 	ioparam.io_bounds.upper = INFINITY;
275 	if (input(FIO_OPINT, "Enter track skew", ':',
276 			&ioparam, &deflt, DATA_INPUT)) {
277 		*options |= SUP_TRKSKEW;
278 		return (deflt);
279 	}
280 	return (0);
281 }
282 
283 /*
284  * Prompt for tracks per zone
285  */
286 int
287 get_trks_zone(options)
288 	ulong_t		*options;
289 {
290 	u_ioparam_t	ioparam;
291 	int		deflt;
292 
293 	ioparam.io_bounds.lower = 0;
294 	ioparam.io_bounds.upper = INFINITY;
295 	if (input(FIO_OPINT, "Enter tracks per zone", ':',
296 			&ioparam, &deflt, DATA_INPUT)) {
297 		*options |= SUP_TRKS_ZONE;
298 		return (deflt);
299 	}
300 	return (0);
301 }
302 
303 /*
304  * Prompt for alternate tracks
305  */
306 int
307 get_atrks(options)
308 	ulong_t		*options;
309 {
310 	u_ioparam_t	ioparam;
311 	int		deflt;
312 
313 	ioparam.io_bounds.lower = 0;
314 	ioparam.io_bounds.upper = INFINITY;
315 	if (input(FIO_OPINT, "Enter alternate tracks", ':',
316 			&ioparam, &deflt, DATA_INPUT)) {
317 		*options |= SUP_ATRKS;
318 		return (deflt);
319 	}
320 	return (0);
321 }
322 
323 /*
324  * Prompt for alternate sectors
325  */
326 int
327 get_asect(options)
328 	ulong_t		*options;
329 {
330 	u_ioparam_t	ioparam;
331 	int		deflt;
332 
333 	ioparam.io_bounds.lower = 0;
334 	ioparam.io_bounds.upper = INFINITY;
335 	if (input(FIO_OPINT, "Enter alternate sectors", ':',
336 			&ioparam, &deflt, DATA_INPUT)) {
337 		*options |= SUP_ASECT;
338 		return (deflt);
339 	}
340 	return (0);
341 }
342 
343 /*
344  * Prompt for cache setting
345  */
346 int
347 get_cache(options)
348 	ulong_t		*options;
349 {
350 	u_ioparam_t	ioparam;
351 	int		deflt;
352 
353 	ioparam.io_bounds.lower = 0;
354 	ioparam.io_bounds.upper = 0xff;
355 	if (input(FIO_OPINT, "Enter cache control", ':',
356 			&ioparam, &deflt, DATA_INPUT)) {
357 		*options |= SUP_CACHE;
358 		return (deflt);
359 	}
360 	return (0);
361 }
362 
363 /*
364  * Prompt for prefetch threshold
365  */
366 int
367 get_threshold(options)
368 	ulong_t		*options;
369 {
370 	u_ioparam_t	ioparam;
371 	int		deflt;
372 
373 	ioparam.io_bounds.lower = 0;
374 	ioparam.io_bounds.upper = INFINITY;
375 	if (input(FIO_OPINT, "Enter prefetch threshold",
376 			':', &ioparam, &deflt, DATA_INPUT)) {
377 		*options |= SUP_PREFETCH;
378 		return (deflt);
379 	}
380 	return (0);
381 }
382 
383 /*
384  * Prompt for minimum prefetch
385  */
386 int
387 get_min_prefetch(options)
388 	ulong_t		*options;
389 {
390 	u_ioparam_t	ioparam;
391 	int		deflt;
392 
393 	ioparam.io_bounds.lower = 0;
394 	ioparam.io_bounds.upper = INFINITY;
395 	if (input(FIO_OPINT, "Enter minimum prefetch",
396 			':', &ioparam, &deflt, DATA_INPUT)) {
397 		*options |= SUP_CACHE_MIN;
398 		return (deflt);
399 	}
400 	return (0);
401 }
402 
403 /*
404  * Prompt for maximum prefetch
405  */
406 int
407 get_max_prefetch(min_prefetch, options)
408 	int		min_prefetch;
409 	ulong_t		*options;
410 {
411 	u_ioparam_t	ioparam;
412 	int		deflt;
413 
414 	ioparam.io_bounds.lower = min_prefetch;
415 	ioparam.io_bounds.upper = INFINITY;
416 	if (input(FIO_OPINT, "Enter maximum prefetch",
417 			':', &ioparam, &deflt, DATA_INPUT)) {
418 		*options |= SUP_CACHE_MAX;
419 		return (deflt);
420 	}
421 	return (0);
422 }
423 
424 /*
425  * Prompt for bytes per sector
426  */
427 int
428 get_bps()
429 {
430 	u_ioparam_t	ioparam;
431 	int		deflt;
432 
433 	if (cur_ctype->ctype_flags & CF_SMD_DEFS) {
434 		ioparam.io_bounds.lower = MIN_BPS;
435 		ioparam.io_bounds.upper = MAX_BPS;
436 		deflt = AVG_BPS;
437 		return (input(FIO_INT, "Enter bytes per sector",
438 			':', &ioparam, &deflt, DATA_INPUT));
439 	}
440 
441 	return (0);
442 }
443 
444 /*
445  * Prompt for ascii label
446  */
447 char *
448 get_asciilabel()
449 {
450 	return ((char *)(uintptr_t)input(FIO_OSTR,
451 	    "Enter disk type name (remember quotes)", ':',
452 	    (u_ioparam_t *)NULL, (int *)NULL, DATA_INPUT));
453 }
454