129534Ssam #ifndef lint
2*32662Skarels static char sccsid[] = "@(#)proc_cmd.c	1.4 (Berkeley/CCI) 11/23/87";
329534Ssam #endif
429534Ssam 
529534Ssam #include	"vdfmt.h"
629534Ssam #include	"cmd.h"
729534Ssam 
829534Ssam #define	RESET		1
929534Ssam #define	LIST		2
1029534Ssam #define	DELETE		3
1129534Ssam #define	FORMAT		4
1229534Ssam #define	VERIFY		5
1329534Ssam #define	RELOCATE	6
1429534Ssam #define	CORRECT		7
1529534Ssam #define	INFO		8
1629534Ssam #define	PROFILE		9
1729534Ssam #define	EXERCISE	10
1829534Ssam #define	START		11
1929981Skarels #define	EXIT		12
2029534Ssam 
2129534Ssam static cmd_text_element	commands[] = {
2229534Ssam 	{ RESET,     "RESET",	  "Reinitialize VDFORMAT, and start over" },
2329981Skarels 	{ EXIT,      "EXIT",	  "Terminate program" },
2429534Ssam 	{ LIST,	     "List",	  "List operations specified so far" },
2529534Ssam 	{ DELETE,    "Delete",	  "Delete specific operations" },
2629534Ssam 	{ FORMAT,    "Format",	  "Format and verify disk surface" },
2729534Ssam 	{ VERIFY,    "Verify",	  "Destructively verify disk surface" },
2829534Ssam 	{ RELOCATE,  "Relocate",  "Add known flaws to bad sector map" },
2929534Ssam 	{ CORRECT,   "Correct",	  "Correct erroneous relocations or drive ID" },
3029534Ssam 	{ INFO,	     "Info",	  "Display known disk information" },
3129534Ssam 	{ PROFILE,   "Profile",   "Display seek profile graph of disk" },
3229534Ssam 	{ EXERCISE,  "Exercise",  "Perform seek exercises on disk" },
3329534Ssam 	{ START,     "STARt",	  "Start operations" },
3429534Ssam 	{ 0,	     "",	  "" }
3529534Ssam };
3629534Ssam 
3729534Ssam 
3829534Ssam /*
3929534Ssam **
4029534Ssam */
4129534Ssam 
process_commands()4229534Ssam process_commands()
4329534Ssam {
44*32662Skarels 	int	tokens[20];
4529534Ssam 	int	*tok_ptr, count;
4629534Ssam 	int	op_mask = 0;
4729534Ssam 	char	*cptr;
4829534Ssam 	boolean	should_start = false;
4929534Ssam 
5029534Ssam 	for(;;) {
51*32662Skarels 		(void)_setjmp(abort_environ);
5229534Ssam 		cur.state = cmd;
5329534Ssam 		kill_processes = false;
5429534Ssam 		exdent(-1);
5529534Ssam 		op_mask = 0;
5629534Ssam 		printf("vdformat> ");
5729534Ssam 		count = get_text_cmd(commands, tokens);
5829534Ssam 		if(kill_processes == true)
5929534Ssam 			_longjmp(quit_environ, 1);
6029534Ssam 		tok_ptr = tokens;
6129534Ssam 		if((*tok_ptr == 0) || !count)
6229534Ssam 			continue;
6329534Ssam 		while(*tok_ptr) {
6429534Ssam 			switch (*tok_ptr) {
6529534Ssam 			case RESET :
6629534Ssam 				reset();
6729534Ssam 				break;
6829534Ssam 			case LIST :
6929534Ssam 				list();
7029534Ssam 				break;
7129534Ssam 			case DELETE :
7229534Ssam 				delete();
7329534Ssam 				break;
7429534Ssam 			case FORMAT :
7529534Ssam 				op_mask |= FORMAT_OP;
7629534Ssam 				break;
7729534Ssam 			case VERIFY :
7829534Ssam 				op_mask |= VERIFY_OP;
7929534Ssam 				break;
8029534Ssam 			case RELOCATE :
8129534Ssam 				op_mask |= RELOCATE_OP;
8229534Ssam 				break;
8329534Ssam 			case CORRECT :
8429534Ssam 				op_mask |= CORRECT_OP;
8529534Ssam 				break;
8629534Ssam 			case INFO :
8729534Ssam 				op_mask |= INFO_OP;
8829534Ssam 				break;
8929534Ssam 			case PROFILE :
9029534Ssam 				op_mask |= PROFILE_OP;
9129534Ssam 				break;
9229534Ssam 			case EXERCISE :
9329534Ssam 				op_mask |= EXERCISE_OP;
9429534Ssam 				break;
9529534Ssam 			case START :
9629534Ssam 				should_start = true;
9729534Ssam 				break;
9829981Skarels 			case EXIT:
9929981Skarels 				exit(0);
10029981Skarels 				/*NOTREACHED*/
10129534Ssam 			default:		/* ignore */
10229534Ssam 				break;
10329534Ssam 			}
10429534Ssam 		tok_ptr++;
10529534Ssam 		}
10629534Ssam 		if(op_mask) {
10729534Ssam 			get_drive_parameters(op_mask);
10829534Ssam 		}
10929534Ssam 		if(should_start) {
11029534Ssam 			start_commands();
11129534Ssam 			should_start = false;
11229534Ssam 		}
11329534Ssam 	}
11429534Ssam }
11529534Ssam 
11629534Ssam 
11729534Ssam /*
11829534Ssam **
11929534Ssam */
12029534Ssam 
12129534Ssam static boolean	header_printed = false;
12229534Ssam 
get_drive_parameters(op_mask)12329534Ssam get_drive_parameters(op_mask)
12429534Ssam int	op_mask;
12529534Ssam {
12629534Ssam 	int	c_list[20], i, num_pat;
12729534Ssam 
12829534Ssam 	indent();
12929534Ssam 	header_printed = false;
13029534Ssam 	get_ctlr_list(c_list, op_mask);
13129534Ssam 	if(kill_processes == true) {
13229534Ssam 		kill_processes = false;
13329534Ssam 		c_list[0]= -1;
13429534Ssam 	}
13529534Ssam 	for(i=0; c_list[i] != -1; i++) {
13629534Ssam 		int	d_list[40], j;
13729534Ssam 
13829534Ssam 		indent();
13929534Ssam 		get_drive_list(c_list[i], d_list, op_mask);
14029534Ssam 		if(kill_processes == true) {
14129534Ssam 			kill_processes = false;
14229534Ssam 			break;
14329534Ssam 		}
14429534Ssam 		indent();
14529534Ssam 		if(op_mask & (FORMAT_OP | VERIFY_OP)) {
14629534Ssam 			num_pat = get_num_pat();
14729534Ssam 			if(kill_processes == true) {
14829534Ssam 				kill_processes = false;
14929534Ssam 				break;
15029534Ssam 			}
15129534Ssam 		}
15229534Ssam 		for(j=0; d_list[j] != -1; j++) {
153*32662Skarels 			cur.controller = c_list[i];
154*32662Skarels 			cur.drive = d_list[j];
155*32662Skarels 			C_INFO = &c_info[cur.controller];
156*32662Skarels 			D_INFO = &d_info[cur.controller][cur.drive];
157*32662Skarels 			lab = &D_INFO->label;
158*32662Skarels 			get_drive_type(cur.controller, cur.drive, op_mask);
15929534Ssam 			if(kill_processes == true) {
16029534Ssam 				kill_processes = false;
16129534Ssam 				break;
16229534Ssam 			}
16329534Ssam 			if(op_mask & ~INFO_OP) {
16429534Ssam 				indent();
16529534Ssam 				get_drive_id(c_list[i], d_list[j]);
16629534Ssam 				if(kill_processes == true) {
16729534Ssam 					kill_processes = false;
16829534Ssam 					break;
16929534Ssam 				}
17029534Ssam 				exdent(1);
17129534Ssam 			}
17229534Ssam 			ops_to_do[c_list[i]][d_list[j]].op |= op_mask;
17329534Ssam 			if(op_mask & (FORMAT_OP | VERIFY_OP))
17429534Ssam 				ops_to_do[c_list[i]][d_list[j]].numpat=num_pat;
17529534Ssam 		}
17629534Ssam 		exdent(1);
17729534Ssam 	}
17829534Ssam 	exdent(2);
17929534Ssam }
18029534Ssam 
18129534Ssam /*
18229534Ssam **
18329534Ssam */
18429534Ssam 
get_ctlr_list(c_list,op_mask)18529534Ssam get_ctlr_list(c_list, op_mask)
18629534Ssam int	*c_list, op_mask;
18729534Ssam {
18829534Ssam 	extern int	ctlr_help();
18929534Ssam 	register int	i, ctlr;
19029534Ssam 	int		table[MAXCTLR+10];
19129534Ssam 
19229534Ssam 	i = 0;
19329534Ssam 	for(ctlr=0; ctlr<MAXCTLR; ctlr++)
19429534Ssam 		if(c_info[ctlr].alive == u_true)
19529534Ssam 			table[i++] = ctlr;
19629534Ssam 	table[i] = -1;
19729534Ssam 	/* If only one controller is possible don't ask */
19829534Ssam 	if(table[1] == -1) {
19929534Ssam 		*c_list++ = table[0];
20029534Ssam 		*c_list = -1;
20129534Ssam 		return;
20229534Ssam 	}
20329534Ssam 	for(;;) {
20429534Ssam 		header_printed = true;
20529534Ssam 		print("");  /* Force indent */
20629534Ssam 		print_op_list(op_mask);
20729534Ssam 		printf(" on which controllers? ");
20829534Ssam 		get_digit_list(c_list, table, ctlr_help);
20929534Ssam 		if(kill_processes == true)
21029534Ssam 			return;
21129534Ssam 		if(*c_list != -1)
21229534Ssam 			break;
21329534Ssam 	}
21429534Ssam }
21529534Ssam 
21629534Ssam 
21729534Ssam /*
21829534Ssam **
21929534Ssam */
22029534Ssam 
ctlr_help()22129534Ssam ctlr_help()
22229534Ssam {
22329534Ssam 	register int	ctlr;
22429534Ssam 
22529534Ssam 	indent();
22629534Ssam 	print("The following controllers are attached to the system:\n");
22729534Ssam 	indent();
22829534Ssam 	for(ctlr=0; ctlr<MAXCTLR; ctlr++)
22929534Ssam 		if(c_info[ctlr].alive == u_true) {
23029534Ssam 			print("Controller %d, which is a%s %s controller.\n",
23129534Ssam 			    ctlr, (c_info[ctlr].name[0] == 'S') ? "n" : "",
23229534Ssam 			    c_info[ctlr].name);
23329534Ssam 		}
23429534Ssam 	print("\n");
23529534Ssam 	exdent(2);
23629534Ssam }
23729534Ssam 
23829534Ssam static int	max_drive = 0;
23929534Ssam 
24029534Ssam /*
24129534Ssam **
24229534Ssam */
24329534Ssam 
get_drive_list(ctlr,d_list,op_mask)24429534Ssam get_drive_list(ctlr, d_list, op_mask)
24529534Ssam int	ctlr, *d_list, op_mask;
24629534Ssam {
24729534Ssam 	extern int	drive_help();
24829534Ssam 	int		table[MAXDRIVE+10];
24929534Ssam 	int		i;
25029534Ssam 
25131318Ssam 	max_drive = (c_info[ctlr].type == VDTYPE_VDDC) ? 4 : 16;
25229534Ssam 	for(i=0; i<max_drive; i++)
25329534Ssam 		table[i] = i;
25429534Ssam 	table[i] = -1;
25529534Ssam 	for(;;) {
25629534Ssam 		if(header_printed == true)
25729534Ssam 			print("Drives on controller %d? ", ctlr);
25829534Ssam 		else {
25929534Ssam 			header_printed = true;
26029534Ssam 			print("");  /* Force indent */
26129534Ssam 			print_op_list(op_mask);
26229534Ssam 			printf(" on which drives? ");
26329534Ssam 		}
26429534Ssam 		get_digit_list(d_list, table, drive_help);
26529534Ssam 		if(kill_processes == true)
26629534Ssam 			return;
26729534Ssam 		if(*d_list != -1)
26829534Ssam 			break;
26929534Ssam 	}
27029534Ssam }
27129534Ssam 
27229534Ssam /*
27329534Ssam **
27429534Ssam */
27529534Ssam 
id_help()27629534Ssam id_help()
27729534Ssam {
27829534Ssam 	indent();
27929534Ssam 	print("The following commands are available:\n");
28029534Ssam 	indent();
28129534Ssam 	print("STATus - Display formatter state.\n");
28229534Ssam 	print("QUIT   - Terminate current operation.\n");
28329534Ssam 	print("");
28429534Ssam 	print("A module serial can be any number greater than zero.\n");
28529534Ssam 	exdent(2);
28629534Ssam }
28729534Ssam 
28829534Ssam 
28929534Ssam /*
29029534Ssam **
29129534Ssam */
29229534Ssam 
get_drive_id(ctlr,drive)29329534Ssam get_drive_id(ctlr, drive)
29429534Ssam int	ctlr, drive;
29529534Ssam {
29629534Ssam 	int	new_id;
29729534Ssam 
29829534Ssam 	for(;;) {
29929534Ssam 		print("Module serial number for controller %d, drive %d? ",
30029534Ssam 		    ctlr, drive);
30129534Ssam 		if(d_info[ctlr][drive].id != -1)
30229534Ssam 			printf("(%d) ", d_info[ctlr][drive].id);
30329534Ssam 		new_id = get_digit_cmd(id_help);
30429534Ssam 		if(new_id > 0) {
30529534Ssam 			d_info[ctlr][drive].id = new_id;
30629534Ssam 			break;
30729534Ssam 		}
30829534Ssam 		else if(d_info[ctlr][drive].id != -1)
30929534Ssam 			break;
31029534Ssam 	}
31129534Ssam }
31229534Ssam 
31329534Ssam 
31429534Ssam /*
31529534Ssam **
31629534Ssam */
31729534Ssam 
drive_help()31829534Ssam drive_help()
31929534Ssam {
32029534Ssam 	indent();
32129534Ssam 	print("Drive numbers 0 through %d may be entered.\n", max_drive-1);
32229534Ssam 	exdent(1);
32329534Ssam }
32429534Ssam 
32529534Ssam 
32629534Ssam /*
32729534Ssam **
32829534Ssam */
32929534Ssam 
pat_help()33029534Ssam pat_help()
33129534Ssam {
33229534Ssam 	indent();
33329534Ssam 	print("Between 0 and 16 patterns may be used while verifying.\n");
33429534Ssam 	exdent(1);
33529534Ssam }
33629534Ssam 
33729534Ssam 
33829534Ssam /*
33929534Ssam **
34029534Ssam */
34129534Ssam 
get_num_pat()34229534Ssam get_num_pat()
34329534Ssam {
34429534Ssam 	int	table[17+10];
34529534Ssam 	int	results[17+10];
34629534Ssam 	int	i;
34729534Ssam 
34829534Ssam 	for(i=0; i<=16; i++)
34929534Ssam 		table[i] = i;
35029534Ssam 	table[i] = -1;
35129534Ssam 	for(;;) {
35229534Ssam 		print("Number of patterns to use while verifying? ");
35329534Ssam 		get_digit_list(results, table, pat_help);
35429534Ssam 		if(kill_processes == true)
35529534Ssam 			return 0;
35629534Ssam 		if(results[0] != -1)
35729534Ssam 			break;
35829534Ssam 	}
35929534Ssam 	return results[0];
36029534Ssam }
36129534Ssam 
362