vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / mttn / test / mtttest.c
blobd083fc16b821ce35296b538176d9d8520248ce1a
1 /**************************************************************************/
2 /* Mtt test */
3 /* Julian Lewis 21st Sept 2006 */
4 /**************************************************************************/
6 #include <unistd.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <fcntl.h>
11 #include <sys/ioctl.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <errno.h> /* Error numbers */
15 #include <sys/file.h>
16 #include <a.out.h>
17 #include <ctype.h>
19 #include <mttdrvr.h>
21 #include <tgm/tgm.h>
23 /**************************************************************************/
24 /* Code section from here on */
25 /**************************************************************************/
27 /* Print news on startup if not zero */
29 #define NEWS 1
31 #define HISTORIES 24
32 #define CMD_BUF_SIZE 128
34 static char history[HISTORIES][CMD_BUF_SIZE];
35 static char *cmdbuf = &(history[0][0]);
36 static int cmdindx = 0;
37 static char prompt[32];
38 static char *pname = NULL;
39 static int mtt;
41 #include <asm.h>
42 #include "Cmds.h"
43 #include "GetAtoms.h"
44 #include "PrintAtoms.h"
45 #include "DoCmd.h"
46 #include "Cmds.inc.h"
47 #include "MttOpen.h"
48 #include "MttCmds.h"
50 /**************************************************************************/
51 /* Prompt and do commands in a loop */
52 /**************************************************************************/
54 int main(int argc,char *argv[]) {
56 char *cp, *ep;
57 char host[49];
58 char tmpb[CMD_BUF_SIZE];
59 int i;
61 pname = argv[0];
62 printf("%s: Compiled %s %s\n",pname,__DATE__,__TIME__);
64 mtt = MttOpen();
65 if (mtt == 0) {
66 printf("\nWARNING: Could not open driver");
67 printf("\n\n");
68 } else {
69 printf("Driver opened OK: Using MTT module: 1\n\n");
72 umask(0);
74 SetupGroupNames();
76 bzero((void *) host,49);
77 gethostname(host,48);
79 while (True) {
81 cmdbuf = &(history[cmdindx][0]);
82 if (strlen(cmdbuf)) printf("{%s} ",cmdbuf);
83 fflush(stdout);
85 if (mtt) sprintf(prompt,"%s:Mtt[%02d]",host,cmdindx+1);
86 else sprintf(prompt,"%s:NoDriver:Mtt[%02d]",host,cmdindx+1);
87 printf("%s",prompt);
89 bzero((void *) tmpb,CMD_BUF_SIZE);
90 if (fgets(tmpb,CMD_BUF_SIZE,stdin)==NULL) exit(1);
91 if ((i = strlen(tmpb)) == 0) continue;
92 tmpb[i - 1] = 0;
94 cp = &(tmpb[0]);
96 if (*cp == '!') {
97 ep = cp; cmdindx = strtoul(++cp,&ep,0) -1;
98 if (cmdindx >= HISTORIES) cmdindx = 0;
99 cmdbuf = &(history[cmdindx][0]);
100 continue;
101 } else if (*cp == '.') {
102 printf("Execute:%s\n",cmdbuf); fflush(stdout);
103 } else if ((*cp == '\n') || (*cp == '\0')) {
104 cmdindx++;
105 if (cmdindx >= HISTORIES) { printf("\n"); cmdindx = 0; }
106 cmdbuf = &(history[cmdindx][0]);
107 continue;
108 } else if (*cp == '?') {
109 printf("History:\n");
110 printf("\t!<1..24> Goto command\n");
111 printf("\tCR Goto next command\n");
112 printf("\t. Execute current command\n");
113 printf("\this Show command history\n");
114 continue;
115 } else {
116 cmdindx++; if (cmdindx >= HISTORIES) { printf("\n"); cmdindx = 0; }
117 strcpy(cmdbuf,tmpb);
119 bzero((void *) val_bufs,sizeof(val_bufs));
120 GetAtoms(cmdbuf);
121 DoCmd(0);