1
/* @(#)testtape.c 19.1 (ES0-DMD) 02/25/03 14:33:06 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
37
int opentape(), closetape(), rewtape(), rstatape(), skiptape(), skbctape();
38
int wfmtape(), readtape(), writetape(), skipeom(), quit(), nothing();
39
int forwblk(), backblk(), infodev();
43
/* Definition of Functions */
45
#define ioinfo(f,b,fn,bn) (ops[U_INFO])(f,b,fn,bn)
46
#define ioopen(f,m,d) (ops[U_OPEN])(f,m,d)
47
#define ioclose(f) (ops[U_CLOSE])(f)
48
#define ioread(f,b,l) (ops[U_READ])(f,b,l)
49
#define iowrite(f,b,l) (ops[U_WRITE])(f,b,l)
50
#define iorew(f) (ops[U_REWIND])(f)
51
#define ioeom(f) (ops[U_EOM])(f)
52
#define ioweof(f) (ops[U_WEOF])(f)
53
#define iofsf(f,n) (ops[U_FMF])(f,n)
54
#define iobsf(f,n) (ops[U_FMB])(f,n)
55
#define iofsr(f,n) (ops[U_BMF])(f,n)
56
#define iobsr(f,n) (ops[U_BMB])(f,n)
57
#define iosread(f,s,ss,b,l) (ops[U_SREAD])(f,s,ss,b,l)
58
#define ioswrite(f,s,ss,b,l) (ops[U_SWRITE])(f,s,ss,b,l)
61
/* This structure, created for each device, allows to know
62
the current position on any device
64
typedef int (*FCT_PTR)(); /* Pointer to function */
65
FCT_PTR ops[U_MAX+1]; /* Available Operations */
66
#define NULL_PTR(x) (x *)0
68
#define READ_WRITE 2 /* as in osparms.h */
70
static char name[80] = "ip1:/dev/nrst1";
71
static char class[20] = "remote";
74
static int mode=0xffff;
81
"\n0- ***** MENU *****\n", nothing,
82
"1- Open a tape device\n", opentape,
83
"2- Close a tape device\n", closetape,
84
"3- Rewind the tape\n", rewtape,
85
"4- Skip forward tape marks\n", skiptape,
86
"5- Skip backward tape marks\n", skbctape,
87
"6- Write a tape mark\n", wfmtape,
88
"7- Read a buffer\n", readtape,
89
"8- Write a buffer\n", writetape,
90
"9- Skip forward block\n", forwblk,
91
"10- Skip backward block\n", backblk,
92
"11- Retrieve device info\n", infodev,
93
"12- Skip end of media\n", skipeom,
104
signal(SIGINT,returnhere);
107
while(m_c->msg != (char *)0)
109
printf("\nOption: ");
110
if ((opt=atoi(gets(buff))) >= (sizeof(msg_cmd)/sizeof(struct msg_cmd)))
111
printf("Bad option\n");
113
(*msg_cmd[opt].cmd)();
114
/* printf("\nPress RETURN to continue"); */
121
char aname[80], aclass[20], input[80];
125
printf("\nOPEN TAPE\n");
127
printf("Enter name of device (%s): ",name);
130
if (strlen(aname) != 0)
133
printf("Enter open mode (2:READ_WRITE): ");
134
mode=atoi(gets(input));
135
if (strlen(input) == 0)
138
printf("Enter class for this device (%s): ",class);
142
if (strlen(aclass) != 0)
143
strcpy(class,aclass);
145
if (getclass() < 0) {
146
printf("Error finding class %s, %s\n",
151
pfd = ioopen(name,mode,0);
154
printf("Error opening %s, %s\n",
160
printf("OPEN %s succeded.\n",name);
165
printf("\nCLOSE TAPE\n");
166
if (ioclose(fd) == -1) {
167
printf("Error closing device, %s\n",osmsg());
170
printf("CLOSE succeded\n");
175
printf("\nREWIND TAPE\n");
176
if (iorew(fd) == -1) {
177
printf("Error rewinding device, %s\n",
181
printf("REWIND succeded.\n");
189
printf("Enter number of tape marks to be skipped (1): ");
192
if ( strlen(name) == 0)
197
printf("\nSKIP FORWARD %d TAPE MARKS\n",ntm);
198
if ((ret = iofsf(fd,ntm)) == -1) {
199
printf("Error skipping %d tape marks, %s\n",
203
printf("SKIP succeded\n");
210
printf("Enter number of tape marks to be skipped (1): ");
213
if ( strlen(name) == 0)
218
printf("\nSKIP BACKWARD %d TAPE MARKS\n",ntm);
219
if (iobsf(fd,ntm) == -1) {
220
printf("Error skipping %d tape marks, %s\n",
224
printf("SKIP succeded\n");
229
printf("\nWRITE A TAPE MARK\n");
230
if (ioweof(fd) == -1) {
231
printf("Error writting a tape mark, %s\n", osmsg());
234
printf("WRITE A TAPE MARK succeded.\n");
246
printf("\nWRITE A BUFFER\n");
247
printf("Enter number of bytes to be written (1024): ");
248
n_bytes = atoi(gets(name));
249
if ( strlen(name) == 0)
252
if ((pbuf = malloc(n_bytes)) == (char *)0 ) {
253
printf("Max. memory allocation: %d bytes\n",n_bytes);
257
printf("Buffer allocated\n");
258
printf("Enter pattern for buffer ('A'): ");
259
if (strlen(gets(name)) == 0)
264
printf("Pattern=%c\n",pattern);
266
for (i=0; i<n_bytes; i++)
269
/* for(i=0; i<n_bytes; i++)
270
/* printf("%c ",pbuf[i]);
273
if (iowrite(fd,pbuf,n_bytes) == -1) {
274
printf("Error writting %d bytes, %s\n",
278
printf("WRITE %d bytes succeded.\n",n_bytes);
291
printf("\nREAD A BUFFER\n");
292
printf("Enter number of bytes to be read (1024): ");
293
n_bytes = atoi(gets(name));
294
if ( strlen(name) == 0)
297
/* if ((pbuf = malloc(8192)) == (char *)0 ) { */
298
if ((pbuf = malloc(n_bytes)) == (char *)0 ) {
299
printf("Max. memory allocation: %d bytes\n",n_bytes);
303
printf("Buffer allocated\n");
305
/* for (i=0; i<n_bytes; i++)
307
/* for(i=0; i<n_bytes; i++)
308
/* printf("%c ",pbuf[i]);
312
if ((length = ioread(fd,pbuf,n_bytes)) == -1) {
313
printf("Error reading %d bytes, %s\n",
318
/* for(i=0; i<length; i++)
319
/* printf("%c ",pbuf[i]);
322
printf("\nREAD %d bytes succeded.\n",length);
324
printf("Pattern=%c\n",pbuf[0]);
326
for(i=0; i<length; i++)
327
if (pattern != pbuf[i])
328
fprintf(stderr,"Byte %d (%c) differs of pattern(%c)\n",
338
printf("Enter number of blocks to be skipped backward (1): ");
341
if ( strlen(name) == 0)
346
printf("\nSKIP BACKWARD %d BLOCKS\n",ntm);
347
if (iobsr(fd,ntm) == -1) {
348
printf("Error skipping backward %d blocks, %s\n",
352
printf("SKIP succeded\n");
359
printf("Enter number of blocks to be skipped forward (1): ");
362
if ( strlen(name) == 0)
367
printf("\nSKIP FORWARD %d BLOCKS\n",ntm);
368
if (iofsr(fd,ntm) == -1) {
369
printf("Error skipping forward %d blocks, %s\n",
373
printf("SKIP succeded.\n");
381
printf("\nRETRIEVE INFO FROM OPENED TAPE\n");
382
if ( ioinfo(fd,&s, &filenum, &blkno) == -1) {
383
printf("Error getting status from device, %s\n",
387
printf("RETRIEVE INFO succeded\n");
388
printf("s.usize= %d\n", s.usize);
389
printf("s.blocksize= %d\n", s.blocksize);
390
printf("s.density= %d\n", s.density);
391
printf("s.isda= %d\n", s.isda);
392
printf("s.istm= %d\n", s.istm);
393
printf("filenum= %d\n", filenum);
394
printf("blkno= %d\n", blkno);
399
printf("\nSKIP TO END OF MEDIA\n");
400
if (ioeom(fd) == -1) {
401
printf("Error skipping to end of media, %s\n",
405
printf("SKIP EOM succeded\n");
422
struct iolist *findclass(aclass)
423
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
424
.PURPOSE Retrieve the class name
425
.RETURNS Pointer to found class / NULL
427
----------------------------------------------------------------------*/
428
char *aclass; /* IN: Class to look for */
430
struct iolist *plist, *iodevr();
431
struct iolist *(*def)();
434
/* Follow the linked list of iolist's */
436
for (def = iodevr; def; def = plist->next)
439
for(q=aclass, p=plist->klass; (*p == *q) && (*p); p++, q++) ;
440
if ((*q == '\0') && (*p == '\0')) break;
442
if (!def) /* Class Not Found */
443
plist = NULL_PTR(struct iolist);
449
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
450
.PURPOSE Retrieve the class name, to retrieve operators.
451
.RETURNS 0 / -1 (class doesn't exist)
452
.REMARKS Functions added in FCB
453
----------------------------------------------------------------------*/
455
struct iolist *plist;
459
plist = findclass(class);
463
oserrmsg = "Bad DEVCAP cl=";
468
** We have just to insert the functions in the list
471
for (pop = plist->oplist, i = plist->nop; --i >= 0; pop++)
472
ops[pop->opid] = pop->opf;
477
/*=====================================================================
479
*=====================================================================*/
482
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
483
.PURPOSE Retrieve name of current unit (when f = -1)
484
.RETURNS Name / NULL pointer if failed
485
----------------------------------------------------------------------*/
486
int f; /* IN: The unit number */
489
return((char *)0); /* Bad unit number... */
495
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
496
.PURPOSE Retrieve opening mode of current unit (when f = -1)
497
.RETURNS Mode / -1 when error
498
----------------------------------------------------------------------*/
499
int f; /* IN: The unit number */
502
return(-1); /* Bad unit number... */
507
int osugrep (class_name, item)
508
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
509
.PURPOSE Get the item function in a class of devices
511
----------------------------------------------------------------------*/
512
char *class_name; /* IN: Class of Devices (NULL for any) */
513
OPITEM *item; /* OUT: op_code + Function Pointer */
515
struct iolist *plist, *iodevr();
516
struct iolist *(*def)();
521
for (def = iodevr; def; def = plist->next)
523
if (!class_name) /* Class not specified: look to next one */
525
else plist = findclass(class_name);
526
if (!plist) return(-1);
528
/* Retrieve the item in list */
530
for (pop = plist->oplist, i = plist->nop;
531
(--i >= 0) && (pop->opid != item->opid); pop++) ;
533
if (i >= 0) /* I found the relevant item... */
534
{ item->opf = pop->opf;
537
if (class_name) break;