1*29534Ssam #ifndef lint
2*29534Ssam static char sccsid[] = "@(#)proc_cmd.c	1.1 (Berkeley/CCI) 07/05/86";
3*29534Ssam #endif
4*29534Ssam 
5*29534Ssam #include	"vdfmt.h"
6*29534Ssam #include	"cmd.h"
7*29534Ssam 
8*29534Ssam #define	RESET		1
9*29534Ssam #define	LIST		2
10*29534Ssam #define	DELETE		3
11*29534Ssam #define	FORMAT		4
12*29534Ssam #define	VERIFY		5
13*29534Ssam #define	RELOCATE	6
14*29534Ssam #define	CORRECT		7
15*29534Ssam #define	INFO		8
16*29534Ssam #define	PROFILE		9
17*29534Ssam #define	EXERCISE	10
18*29534Ssam #define	START		11
19*29534Ssam 
20*29534Ssam static cmd_text_element	commands[] = {
21*29534Ssam 	{ RESET,     "RESET",	  "Reinitialize VDFORMAT, and start over" },
22*29534Ssam 	{ LIST,	     "List",	  "List operations specified so far" },
23*29534Ssam 	{ DELETE,    "Delete",	  "Delete specific operations" },
24*29534Ssam 	{ FORMAT,    "Format",	  "Format and verify disk surface" },
25*29534Ssam 	{ VERIFY,    "Verify",	  "Destructively verify disk surface" },
26*29534Ssam 	{ RELOCATE,  "Relocate",  "Add known flaws to bad sector map" },
27*29534Ssam 	{ CORRECT,   "Correct",	  "Correct erroneous relocations or drive ID" },
28*29534Ssam 	{ INFO,	     "Info",	  "Display known disk information" },
29*29534Ssam 	{ PROFILE,   "Profile",   "Display seek profile graph of disk" },
30*29534Ssam 	{ EXERCISE,  "Exercise",  "Perform seek exercises on disk" },
31*29534Ssam 	{ START,     "STARt",	  "Start operations" },
32*29534Ssam 	{ 0,	     "",	  "" }
33*29534Ssam };
34*29534Ssam 
35*29534Ssam static cmd_text_element	drive_types[20];
36*29534Ssam 
37*29534Ssam 
38*29534Ssam /*
39*29534Ssam **
40*29534Ssam */
41*29534Ssam 
42*29534Ssam process_commands()
43*29534Ssam {
44*29534Ssam 	int	type, tokens[20];
45*29534Ssam 	int	*tok_ptr, count;
46*29534Ssam 	int	op_mask = 0;
47*29534Ssam 	char	*cptr;
48*29534Ssam 	boolean	should_start = false;
49*29534Ssam 
50*29534Ssam 	for(type=0; type<ndrives; type++) {
51*29534Ssam 		drive_types[type].cmd_token = (int)&vdconfig[type];
52*29534Ssam 		drive_types[type].cmd_text = vdconfig[type].vc_name;
53*29534Ssam 		drive_types[type].cmd_help = vdconfig[type].vc_type;
54*29534Ssam 	}
55*29534Ssam 	drive_types[type].cmd_token = 0;
56*29534Ssam 	for(;;) {
57*29534Ssam 		cur.state = cmd;
58*29534Ssam 		kill_processes = false;
59*29534Ssam 		exdent(-1);
60*29534Ssam 		op_mask = 0;
61*29534Ssam 		printf("vdformat> ");
62*29534Ssam 		count = get_text_cmd(commands, tokens);
63*29534Ssam 		if(kill_processes == true)
64*29534Ssam 			_longjmp(quit_environ, 1);
65*29534Ssam 		tok_ptr = tokens;
66*29534Ssam 		if((*tok_ptr == 0) || !count)
67*29534Ssam 			continue;
68*29534Ssam 		while(*tok_ptr) {
69*29534Ssam 			switch (*tok_ptr) {
70*29534Ssam 			case RESET :
71*29534Ssam 				reset();
72*29534Ssam 				break;
73*29534Ssam 			case LIST :
74*29534Ssam 				list();
75*29534Ssam 				break;
76*29534Ssam 			case DELETE :
77*29534Ssam 				delete();
78*29534Ssam 				break;
79*29534Ssam 			case FORMAT :
80*29534Ssam 				op_mask |= FORMAT_OP;
81*29534Ssam 				break;
82*29534Ssam 			case VERIFY :
83*29534Ssam 				op_mask |= VERIFY_OP;
84*29534Ssam 				break;
85*29534Ssam 			case RELOCATE :
86*29534Ssam 				op_mask |= RELOCATE_OP;
87*29534Ssam 				break;
88*29534Ssam 			case CORRECT :
89*29534Ssam 				op_mask |= CORRECT_OP;
90*29534Ssam 				break;
91*29534Ssam 			case INFO :
92*29534Ssam 				op_mask |= INFO_OP;
93*29534Ssam 				break;
94*29534Ssam 			case PROFILE :
95*29534Ssam 				op_mask |= PROFILE_OP;
96*29534Ssam 				break;
97*29534Ssam 			case EXERCISE :
98*29534Ssam 				op_mask |= EXERCISE_OP;
99*29534Ssam 				break;
100*29534Ssam 			case START :
101*29534Ssam 				should_start = true;
102*29534Ssam 				break;
103*29534Ssam 			default:		/* ignore */
104*29534Ssam 				break;
105*29534Ssam 			}
106*29534Ssam 		tok_ptr++;
107*29534Ssam 		}
108*29534Ssam 		if(op_mask) {
109*29534Ssam 			get_drive_parameters(op_mask);
110*29534Ssam 		}
111*29534Ssam 		if(should_start) {
112*29534Ssam 			start_commands();
113*29534Ssam 			should_start = false;
114*29534Ssam 		}
115*29534Ssam 	}
116*29534Ssam }
117*29534Ssam 
118*29534Ssam 
119*29534Ssam /*
120*29534Ssam **
121*29534Ssam */
122*29534Ssam 
123*29534Ssam static boolean	header_printed = false;
124*29534Ssam 
125*29534Ssam get_drive_parameters(op_mask)
126*29534Ssam int	op_mask;
127*29534Ssam {
128*29534Ssam 	int	c_list[20], i, num_pat;
129*29534Ssam 
130*29534Ssam 	indent();
131*29534Ssam 	header_printed = false;
132*29534Ssam 	get_ctlr_list(c_list, op_mask);
133*29534Ssam 	if(kill_processes == true) {
134*29534Ssam 		kill_processes = false;
135*29534Ssam 		c_list[0]= -1;
136*29534Ssam 	}
137*29534Ssam 	for(i=0; c_list[i] != -1; i++) {
138*29534Ssam 		int	d_list[40], j;
139*29534Ssam 
140*29534Ssam 		indent();
141*29534Ssam 		get_drive_list(c_list[i], d_list, op_mask);
142*29534Ssam 		if(kill_processes == true) {
143*29534Ssam 			kill_processes = false;
144*29534Ssam 			break;
145*29534Ssam 		}
146*29534Ssam 		indent();
147*29534Ssam 		if(op_mask & (FORMAT_OP | VERIFY_OP)) {
148*29534Ssam 			num_pat = get_num_pat();
149*29534Ssam 			if(kill_processes == true) {
150*29534Ssam 				kill_processes = false;
151*29534Ssam 				break;
152*29534Ssam 			}
153*29534Ssam 		}
154*29534Ssam 		for(j=0; d_list[j] != -1; j++) {
155*29534Ssam 			get_drive_type(c_list[i], d_list[j]);
156*29534Ssam 			if(kill_processes == true) {
157*29534Ssam 				kill_processes = false;
158*29534Ssam 				break;
159*29534Ssam 			}
160*29534Ssam 			if(op_mask & ~INFO_OP) {
161*29534Ssam 				indent();
162*29534Ssam 				get_drive_id(c_list[i], d_list[j]);
163*29534Ssam 				if(kill_processes == true) {
164*29534Ssam 					kill_processes = false;
165*29534Ssam 					break;
166*29534Ssam 				}
167*29534Ssam 				exdent(1);
168*29534Ssam 			}
169*29534Ssam 			ops_to_do[c_list[i]][d_list[j]].op |= op_mask;
170*29534Ssam 			if(op_mask & (FORMAT_OP | VERIFY_OP))
171*29534Ssam 				ops_to_do[c_list[i]][d_list[j]].numpat=num_pat;
172*29534Ssam 		}
173*29534Ssam 		exdent(1);
174*29534Ssam 	}
175*29534Ssam 	exdent(2);
176*29534Ssam }
177*29534Ssam 
178*29534Ssam /*
179*29534Ssam **
180*29534Ssam */
181*29534Ssam 
182*29534Ssam get_ctlr_list(c_list, op_mask)
183*29534Ssam int	*c_list, op_mask;
184*29534Ssam {
185*29534Ssam 	extern int	ctlr_help();
186*29534Ssam 	register int	i, ctlr;
187*29534Ssam 	int		table[MAXCTLR+10];
188*29534Ssam 
189*29534Ssam 	i = 0;
190*29534Ssam 	for(ctlr=0; ctlr<MAXCTLR; ctlr++)
191*29534Ssam 		if(c_info[ctlr].alive == u_true)
192*29534Ssam 			table[i++] = ctlr;
193*29534Ssam 	table[i] = -1;
194*29534Ssam 	/* If only one controller is possible don't ask */
195*29534Ssam 	if(table[1] == -1) {
196*29534Ssam 		*c_list++ = table[0];
197*29534Ssam 		*c_list = -1;
198*29534Ssam 		return;
199*29534Ssam 	}
200*29534Ssam 	for(;;) {
201*29534Ssam 		header_printed = true;
202*29534Ssam 		print("");  /* Force indent */
203*29534Ssam 		print_op_list(op_mask);
204*29534Ssam 		printf(" on which controllers? ");
205*29534Ssam 		get_digit_list(c_list, table, ctlr_help);
206*29534Ssam 		if(kill_processes == true)
207*29534Ssam 			return;
208*29534Ssam 		if(*c_list != -1)
209*29534Ssam 			break;
210*29534Ssam 	}
211*29534Ssam }
212*29534Ssam 
213*29534Ssam 
214*29534Ssam /*
215*29534Ssam **
216*29534Ssam */
217*29534Ssam 
218*29534Ssam ctlr_help()
219*29534Ssam {
220*29534Ssam 	register int	ctlr;
221*29534Ssam 
222*29534Ssam 	indent();
223*29534Ssam 	print("The following controllers are attached to the system:\n");
224*29534Ssam 	indent();
225*29534Ssam 	for(ctlr=0; ctlr<MAXCTLR; ctlr++)
226*29534Ssam 		if(c_info[ctlr].alive == u_true) {
227*29534Ssam 			print("Controller %d, which is a%s %s controller.\n",
228*29534Ssam 			    ctlr, (c_info[ctlr].name[0] == 'S') ? "n" : "",
229*29534Ssam 			    c_info[ctlr].name);
230*29534Ssam 		}
231*29534Ssam 	print("\n");
232*29534Ssam 	exdent(2);
233*29534Ssam }
234*29534Ssam 
235*29534Ssam static int	max_drive = 0;
236*29534Ssam 
237*29534Ssam /*
238*29534Ssam **
239*29534Ssam */
240*29534Ssam 
241*29534Ssam get_drive_list(ctlr, d_list, op_mask)
242*29534Ssam int	ctlr, *d_list, op_mask;
243*29534Ssam {
244*29534Ssam 	extern int	drive_help();
245*29534Ssam 	int		table[MAXDRIVE+10];
246*29534Ssam 	int		i;
247*29534Ssam 
248*29534Ssam 	max_drive = (c_info[ctlr].type == SMDCTLR) ? 4 : 16;
249*29534Ssam 	for(i=0; i<max_drive; i++)
250*29534Ssam 		table[i] = i;
251*29534Ssam 	table[i] = -1;
252*29534Ssam 	for(;;) {
253*29534Ssam 		if(header_printed == true)
254*29534Ssam 			print("Drives on controller %d? ", ctlr);
255*29534Ssam 		else {
256*29534Ssam 			header_printed = true;
257*29534Ssam 			print("");  /* Force indent */
258*29534Ssam 			print_op_list(op_mask);
259*29534Ssam 			printf(" on which drives? ");
260*29534Ssam 		}
261*29534Ssam 		get_digit_list(d_list, table, drive_help);
262*29534Ssam 		if(kill_processes == true)
263*29534Ssam 			return;
264*29534Ssam 		if(*d_list != -1)
265*29534Ssam 			break;
266*29534Ssam 	}
267*29534Ssam }
268*29534Ssam 
269*29534Ssam 
270*29534Ssam /*
271*29534Ssam **
272*29534Ssam */
273*29534Ssam 
274*29534Ssam get_drive_type(ctlr, drive)
275*29534Ssam int	ctlr, drive;
276*29534Ssam {
277*29534Ssam 	int	tokens[20];
278*29534Ssam 	int	count;
279*29534Ssam 
280*29534Ssam 	for(;;) {
281*29534Ssam 		print("Drive type for controller %d, drive %d? ", ctlr, drive);
282*29534Ssam 		if(d_info[ctlr][drive].info != 0)
283*29534Ssam 			printf("(%s) ", d_info[ctlr][drive].info->vc_name);
284*29534Ssam 		if(c_info[ctlr].type == SMDCTLR)
285*29534Ssam 			count = get_text_cmd(drive_types+2, tokens);
286*29534Ssam 		else
287*29534Ssam 			count = get_text_cmd(drive_types, tokens);
288*29534Ssam 		if(kill_processes == true)
289*29534Ssam 			return;
290*29534Ssam 		if(!*tokens && (d_info[ctlr][drive].info != 0) && !count)
291*29534Ssam 			break;
292*29534Ssam 		if(d_info[ctlr][drive].info = (struct vdconfig *)*tokens)
293*29534Ssam 			break;
294*29534Ssam 	}
295*29534Ssam }
296*29534Ssam 
297*29534Ssam 
298*29534Ssam 
299*29534Ssam /*
300*29534Ssam **
301*29534Ssam */
302*29534Ssam 
303*29534Ssam id_help()
304*29534Ssam {
305*29534Ssam 	indent();
306*29534Ssam 	print("The following commands are available:\n");
307*29534Ssam 	indent();
308*29534Ssam 	print("STATus - Display formatter state.\n");
309*29534Ssam 	print("QUIT   - Terminate current operation.\n");
310*29534Ssam 	print("");
311*29534Ssam 	print("A module serial can be any number greater than zero.\n");
312*29534Ssam 	exdent(2);
313*29534Ssam }
314*29534Ssam 
315*29534Ssam 
316*29534Ssam /*
317*29534Ssam **
318*29534Ssam */
319*29534Ssam 
320*29534Ssam get_drive_id(ctlr, drive)
321*29534Ssam int	ctlr, drive;
322*29534Ssam {
323*29534Ssam 	int	new_id;
324*29534Ssam 
325*29534Ssam 	for(;;) {
326*29534Ssam 		print("Module serial number for controller %d, drive %d? ",
327*29534Ssam 		    ctlr, drive);
328*29534Ssam 		if(d_info[ctlr][drive].id != -1)
329*29534Ssam 			printf("(%d) ", d_info[ctlr][drive].id);
330*29534Ssam 		new_id = get_digit_cmd(id_help);
331*29534Ssam 		if(new_id > 0) {
332*29534Ssam 			d_info[ctlr][drive].id = new_id;
333*29534Ssam 			break;
334*29534Ssam 		}
335*29534Ssam 		else if(d_info[ctlr][drive].id != -1)
336*29534Ssam 			break;
337*29534Ssam 	}
338*29534Ssam }
339*29534Ssam 
340*29534Ssam 
341*29534Ssam /*
342*29534Ssam **
343*29534Ssam */
344*29534Ssam 
345*29534Ssam drive_help()
346*29534Ssam {
347*29534Ssam 	indent();
348*29534Ssam 	print("Drive numbers 0 through %d may be entered.\n", max_drive-1);
349*29534Ssam 	exdent(1);
350*29534Ssam }
351*29534Ssam 
352*29534Ssam 
353*29534Ssam /*
354*29534Ssam **
355*29534Ssam */
356*29534Ssam 
357*29534Ssam pat_help()
358*29534Ssam {
359*29534Ssam 	indent();
360*29534Ssam 	print("Between 0 and 16 patterns may be used while verifying.\n");
361*29534Ssam 	exdent(1);
362*29534Ssam }
363*29534Ssam 
364*29534Ssam 
365*29534Ssam /*
366*29534Ssam **
367*29534Ssam */
368*29534Ssam 
369*29534Ssam get_num_pat()
370*29534Ssam {
371*29534Ssam 	int	table[17+10];
372*29534Ssam 	int	results[17+10];
373*29534Ssam 	int	i;
374*29534Ssam 
375*29534Ssam 	for(i=0; i<=16; i++)
376*29534Ssam 		table[i] = i;
377*29534Ssam 	table[i] = -1;
378*29534Ssam 	for(;;) {
379*29534Ssam 		print("Number of patterns to use while verifying? ");
380*29534Ssam 		get_digit_list(results, table, pat_help);
381*29534Ssam 		if(kill_processes == true)
382*29534Ssam 			return 0;
383*29534Ssam 		if(results[0] != -1)
384*29534Ssam 			break;
385*29534Ssam 	}
386*29534Ssam 	return results[0];
387*29534Ssam }
388*29534Ssam 
389