xref: /titanic_52/usr/src/cmd/format/prompts.c (revision 75d94465dbafa487b716482dc36d5150a4ec9853)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
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.
30  */
31 #include "global.h"
32 #include "prompts.h"
33 #include "io.h"
34 #include "param.h"
35 #include "startup.h"
36 
37 #ifdef sparc
38 #include <sys/hdio.h>
39 #endif
40 
41 
42 /*
43  * Prompt for max number of LBA
44  */
45 uint64_t
46 get_mlba()
47 {
48 	u_ioparam_t	ioparam;
49 
50 	ioparam.io_bounds.lower = (1024 * 16) + 68;
51 	ioparam.io_bounds.upper = UINT_MAX64;
52 
53 	return (input(FIO_INT64, "Enter maximum number of LBAs",
54 	    ':', &ioparam, (int *)NULL, DATA_INPUT));
55 }
56 
57 /*
58  * Prompt for number of cylinders
59  */
60 int
61 get_ncyl()
62 {
63 	u_ioparam_t	ioparam;
64 
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, (int *)NULL, DATA_INPUT));
69 }
70 
71 /*
72  * Prompt for number of alternate cylinders
73  */
74 int
75 get_acyl(n_cyls)
76 	int		n_cyls;
77 {
78 	u_ioparam_t	ioparam;
79 	int		deflt;
80 
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));
86 }
87 
88 /*
89  * Prompt for number of physical cylinders
90  */
91 int
92 get_pcyl(n_cyls, a_cyls)
93 	int		n_cyls;
94 	int		a_cyls;
95 {
96 	u_ioparam_t	ioparam;
97 	int		deflt;
98 
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));
104 }
105 
106 /*
107  * Prompt for number of heads
108  */
109 int
110 get_nhead()
111 {
112 	u_ioparam_t	ioparam;
113 
114 	ioparam.io_bounds.lower = 1;
115 	ioparam.io_bounds.upper = MAX_HEADS;
116 	return (input(FIO_INT, "Enter number of heads", ':',
117 	    &ioparam, (int *)NULL, DATA_INPUT));
118 }
119 
120 /*
121  * Prompt for number of physical heads
122  */
123 int
124 get_phead(n_heads, options)
125 	int		n_heads;
126 	ulong_t		*options;
127 {
128 	u_ioparam_t	ioparam;
129 	int		deflt;
130 
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);
138 		}
139 	}
140 	return (0);
141 }
142 
143 
144 /*
145  * Prompt for number of sectors per track
146  */
147 int
148 get_nsect()
149 {
150 	u_ioparam_t	ioparam;
151 
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, (int *)NULL, DATA_INPUT));
157 }
158 
159 /*
160  * Prompt for number of physical sectors per track
161  */
162 int
163 get_psect(options)
164 	ulong_t		*options;
165 {
166 	u_ioparam_t	ioparam;
167 	int		deflt;
168 
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);
176 		}
177 	}
178 	return (0);
179 }
180 
181 /*
182  * Prompt for bytes per track
183  */
184 int
185 get_bpt(n_sects, options)
186 	int		n_sects;
187 	ulong_t		*options;
188 {
189 	u_ioparam_t	ioparam;
190 	int		deflt;
191 
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));
199 	}
200 
201 	return (0);
202 }
203 
204 /*
205  * Prompt for rpm
206  */
207 int
208 get_rpm()
209 {
210 	u_ioparam_t	ioparam;
211 	int		deflt;
212 
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));
218 }
219 
220 /*
221  * Prompt for formatting time
222  */
223 int
224 get_fmt_time(options)
225 	ulong_t		*options;
226 {
227 	u_ioparam_t	ioparam;
228 	int		deflt;
229 
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);
236 	}
237 	return (0);
238 }
239 
240 /*
241  * Prompt for cylinder skew
242  */
243 int
244 get_cyl_skew(options)
245 	ulong_t		*options;
246 {
247 	u_ioparam_t	ioparam;
248 	int		deflt;
249 
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);
256 	}
257 	return (0);
258 }
259 
260 /*
261  * Prompt for track skew
262  */
263 int
264 get_trk_skew(options)
265 	ulong_t		*options;
266 {
267 	u_ioparam_t	ioparam;
268 	int		deflt;
269 
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);
276 	}
277 	return (0);
278 }
279 
280 /*
281  * Prompt for tracks per zone
282  */
283 int
284 get_trks_zone(options)
285 	ulong_t		*options;
286 {
287 	u_ioparam_t	ioparam;
288 	int		deflt;
289 
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);
296 	}
297 	return (0);
298 }
299 
300 /*
301  * Prompt for alternate tracks
302  */
303 int
304 get_atrks(options)
305 	ulong_t		*options;
306 {
307 	u_ioparam_t	ioparam;
308 	int		deflt;
309 
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);
316 	}
317 	return (0);
318 }
319 
320 /*
321  * Prompt for alternate sectors
322  */
323 int
324 get_asect(options)
325 	ulong_t		*options;
326 {
327 	u_ioparam_t	ioparam;
328 	int		deflt;
329 
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);
336 	}
337 	return (0);
338 }
339 
340 /*
341  * Prompt for cache setting
342  */
343 int
344 get_cache(options)
345 	ulong_t		*options;
346 {
347 	u_ioparam_t	ioparam;
348 	int		deflt;
349 
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);
356 	}
357 	return (0);
358 }
359 
360 /*
361  * Prompt for prefetch threshold
362  */
363 int
364 get_threshold(options)
365 	ulong_t		*options;
366 {
367 	u_ioparam_t	ioparam;
368 	int		deflt;
369 
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);
376 	}
377 	return (0);
378 }
379 
380 /*
381  * Prompt for minimum prefetch
382  */
383 int
384 get_min_prefetch(options)
385 	ulong_t		*options;
386 {
387 	u_ioparam_t	ioparam;
388 	int		deflt;
389 
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);
396 	}
397 	return (0);
398 }
399 
400 /*
401  * Prompt for maximum prefetch
402  */
403 int
404 get_max_prefetch(min_prefetch, options)
405 	int		min_prefetch;
406 	ulong_t		*options;
407 {
408 	u_ioparam_t	ioparam;
409 	int		deflt;
410 
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);
417 	}
418 	return (0);
419 }
420 
421 /*
422  * Prompt for bytes per sector
423  */
424 int
425 get_bps()
426 {
427 	u_ioparam_t	ioparam;
428 	int		deflt;
429 
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));
436 	}
437 
438 	return (0);
439 }
440 
441 /*
442  * Prompt for ascii label
443  */
444 char *
445 get_asciilabel()
446 {
447 	return ((char *)(uintptr_t)input(FIO_OSTR,
448 	    "Enter disk type name (remember quotes)", ':',
449 	    (u_ioparam_t *)NULL, (int *)NULL, DATA_INPUT));
450 }
451