2
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
.AUTHOR IPG-ESO Garching
7
.CATEGORY Host operating system interfaces. Tape management.
8
.COMMENTS Tape management.
9
The functions of this module perform basic i/o to
10
magnetic tapes on AIX enviroments
11
.VERSION [1.1] mhl obs lyon mars 1991
14
------------------------------------------------------------*/
15
#include <sys/types.h>
21
#include <sys/ioctl.h>
22
#include <sys/devinfo.h> /* 3 include IBM rs6000 */
29
/*----------------------------------------------------------
30
fichier sys/tape.h , contient:
32
#define STIOCTOP 0x01 * tape commands *
33
#define STIOCMD 0x02 * diagnostic commands *
35
* Structures and definitions for magnetic tape io control commands
36
structure for STIOCTOP - streaming tape op command :
38
short st_op; * operations defined below *
39
daddr_t st_count; * how many of them *
43
#define STREW 6 * rewind *
44
#define STERASE 7 * erase tape, leave at load point *
45
#define STRETEN 8 * retension tape, leave at load point *
46
#define STWEOF 10 * write an end-of-file record *
47
#define STFSF 11 * forward space file *
48
#define STRSF 12 * reverse space file *
49
#define STFSR 13 * forward space record *
50
#define STRSR 14 * reverse space record *
52
------------------------------------------------------------*/
54
/* ----------- pour interfac avec les codes operations habituels sur bande --*/
56
#define MTIOWEOF STWEOF
63
/*#define TAPE_BLK 10240 */
64
#define TAPE_BLK 20480
67
static char class_name[] = "mt"; /* MAgnetic Tape Class */
71
extern char *oserrmsg;
73
#define M_ST_SUCC 0x00
74
/* #define M_ST_DATA 0x34 */
77
/* #define M_ST_TAPEM 0x1C */
80
/*char inv[] = "Invalid tape status\n"; */
81
/*char *tape_msg[M_ST_MASK] = { */
82
/* "Success\n", */ /* 001 */
83
/* "Invalid command\n", */ /* 002 */
84
/* "Command aborted\n", */ /* 003 */
85
/* "Unit offline\n", */ /* 004 */
86
/* "Unit available\n", */ /* 005 */
87
/* "Write protected\n", */ /* 006 */
88
/* "Compare error\n", */ /* 007 */
89
/* "Data error\n", */ /* 010 */
90
/* "Host buffer access error\n", */ /* 011 */
91
/* "Controller error\n", */ /* 012 */
92
/* "Drive error\n", */ /* 013 */
93
/* "Formatter error\n", */ /* 014 */
94
/* "BOT encountered\n", */ /* 015 */
95
/* "Tape mark encountered\n", */ /* 016 */
97
/* "Record data truncated\n", */ /* 020 */
98
/* "Position lost\n", */ /* 021 */
99
/* "Serious exception\n", */ /* 022 */
100
/* "LEOT detected\n", */ /* 023 */
101
/* inv,inv,inv,inv,inv,inv,inv,inv,inv,inv,inv, */ /* 024-036 */
102
/* "Message from an internal diagnostic\n" */ /* 037 */
105
int ioctop(fd,op,count)
106
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107
.PURPOSE Skip forward space file on a tape.
108
.RETURNS 0 / -1 (error)
109
.REMARKS System dependencies:
110
-- UNIX: open(2), ioctl(2)
111
------------------------------------------------------------*/
112
int fd; /* IN: Tape device file descriptor */
113
int op; /* IN: Operation */
114
int count; /* IN: How many of them */
117
struct stop mtoperation ; /* structure pour ioctl ibm */
125
** First try to execute the command.
126
** Even if fails, try to read the status
128
/* en cas de weof, l'argument est le nombre de tape marks a ecrire */
130
printf ("mh ioctl:%d count=%d ",op,count);
133
/* initialisation de la structure */
135
mtoperation.st_op=op;
136
mtoperation.st_count=count;
142
printf (" ioctl-weof ");
144
if ((ret = ioctl(fd,STIOCTOP,&mtoperation)) == -1) oserror = errno; break;
147
printf (" ioctl-fsf ");
149
if ((ret = ioctl(fd,STIOCTOP,&mtoperation)) == -1) oserror = errno; break;
152
printf (" ioctl-bsf ");
154
if ((ret = ioctl(fd,STIOCTOP,&mtoperation)) == -1)
156
if (errno == EIO ) /* on doit etre en debut de bande */
160
else oserror = errno;
164
printf (" ioctl-fsr ");
166
if ((ret = ioctl(fd,STIOCTOP,&mtoperation)) == -1) oserror = errno; break;
169
printf (" ioctl-bsr ");
171
if ((ret = ioctl(fd,STIOCTOP,&mtoperation)) == -1) oserror = errno; break;
174
printf (" ioctl-rewind op=%d ",op);
176
if ((ret = ioctl(fd,STIOCTOP,&mtoperation)) == -1)
183
printf (" ioctl-default op=%d ",op);
185
printf ("code operation inconnu");
190
** If there was an error,
191
** the error condition must be cleared before continue
196
printf (" ret=%d oserror=%d\n",ret,oserror);
198
return(oserror ? -1 : stat);
201
static int ioinfo(fd, s, fileno, blkno)
202
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
203
.PURPOSE Retrieve Info concerning an opened device
204
.RETURNS 0 (success) / -1 (error)
205
------------------------------------------------------------*/
206
int fd; /* IN: File Descriptor */
207
struct osustat *s; /* OUT: The filled components */
208
int *fileno; /* OUT: Where we are */
209
long *blkno; /* OUT: Where we are */
211
struct devinfo info_bande;
217
if ((ret = ioctl(fd,IOCINFO,&info_bande)) == -1 ) oserror = errno;
220
printf (" ioinfo , devtype %c \n",info_bande.devtype);
221
printf ("ioinfo , scmt type %d blksize=%d\n",info_bande.un.scmt.type,info_bande.un.scmt.blksize);
226
s->isda = 0; /* Not direct access */
227
if ( info_bande.devtype == DD_SCTAPE ) s->istm = 1;
232
oserrmsg = "Device can't be a tape...";
241
static int ioopen(name,mode,den)
242
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
243
.PURPOSE Open a tape device
244
.RETURNS File descriptor / -1 (error)
245
.REMARKS System dependencies:
246
-- UNIX: open(2), fstat(2)
247
------------------------------------------------------------*/
248
char *name; /* IN: Physical name of tape device */
249
int mode; /* IN: Open mode */
250
int den; /* IN: Density. Not used */
260
** First try to open device READ/WRITE.
261
** If fail, try READ_ONLY
265
case READ : t = O_RDONLY; break;
266
case WRITE : t = O_WRONLY; break;
267
case READ_WRITE : t = O_RDWR; break;
268
case APPEND : t = O_RDWR; break;
269
default : oserror = EINVAL; return(-1);
272
if ( (fd = open(name,t)) == -1) {
274
printf (" mh IOopen fd=%d errno=%d\n",fd,errno);
280
if ( fstat(fd,&buf) == -1) {
282
printf (" mh IOopen fstat=%d errno=%d\n",fstat,errno);
288
if ( (buf.st_mode & S_IFMT) != S_IFCHR) {
290
oserrmsg = "Osuopen: Not a character device";
297
static int ioclose(fd)
298
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
301
.REMARKS System dependencies:
303
------------------------------------------------------------*/
304
int fd; /* IN: Tape file descriptor */
307
printf ("ioclose\n");
309
if (close(fd) == -1) {
317
static int ioread(fd,buffer,size)
318
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
319
.PURPOSE Read a block from a magnetic tape.
320
.RETURNS Bytes read / -1 if error
321
.REMARKS 0 Bytes read, means a File Mark was detected.
322
.REMARKS System dependencies:
323
-- UNIX: read(2), ioctl(2)
324
------------------------------------------------------------*/
325
int fd; /* IN: Tape device file descriptor */
326
char *buffer; /* IN: Buffer for reading */
327
int size; /* IN: Length of bytes to be read */
332
printf ("ioread fd=%d size=%d ",fd,size);
334
if (size > TAPE_BLK ) size = TAPE_BLK;
335
if ((length = read(fd,buffer,size)) == -1)
341
static int iowrite(fd,buffer,size)
342
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
343
.PURPOSE Write a block on a magnetic tape.
344
.RETURNS Bytes written / -1 (error)
345
.REMARKS System dependencies:
346
-- UNIX: write(2), ioctl(2)
347
------------------------------------------------------------*/
348
int fd; /* IN: Tape device file descriptor */
349
char *buffer; /* IN: Buffer for reading */
350
int size; /* IN: Length of bytes to be read */
356
if ((length = write(fd,buffer,size)) == -1)
359
printf("iowrite %d to buffer of %d bytes\n", length, size);
364
static int ioweof(fd,ntm)
365
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
366
.PURPOSE Write end-of-file record (tape_mark) on the tape.
367
.RETURNS Tape marks written/ -1 (error)
368
.REMARKS System dependencies:
370
------------------------------------------------------------*/
371
int fd; /* IN: Tape device file descriptor */
372
int ntm; /* IN: Number of tape marks */
376
printf ("ioweof ntm=%d\n",ntm);
378
if (ioctop(fd,MTIOWEOF,ntm) == -1)
385
static int iofsf(fd,ntm)
386
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
387
.PURPOSE Skip forward space file on a tape.
388
.RETURNS Tape marks skipped/ -1 (error)
389
.REMARKS System dependencies:
391
------------------------------------------------------------*/
392
int fd; /* IN: Tape device file descriptor */
393
int ntm; /* IN: Number of tape marks */
399
printf("lyon iofsf entered fd=%d ntm=%d\n",fd,ntm);
401
stat = ioctop(fd,MTIOFSF,ntm);
403
printf("lyon iofsf stat = %d oserror=%d\n",stat,oserror);
407
case M_ST_SUCC: /* Command OK */
408
/*oserror = 0; */ /* mh 9.8.90 */
411
case M_ST_DATA: /* End of data */
424
static int iobsf(fd,ntm)
425
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
426
.PURPOSE Skip backward space file on a tape.
427
.RETURNS Tape marks skipped/ -1 (error)
428
.REMARKS System dependencies:
430
------------------------------------------------------------*/
431
int fd; /* IN: Tape device file descriptor */
432
int ntm; /* IN: Number of tape marks */
439
/* je recule de ntm+1 file mark et je re avance de 1 file mark, sauf si
440
en reculant j'ai atteint le debut de bande */
441
stat = ioctop(fd,MTIOBSF,ntm+1);
444
case M_ST_SUCC: /* Command OK je ravance de 1 file mark*/
445
stat=ioctop(fd,MTIOFSF,1);
455
case M_ST_BOT: /* Beggining of tape */
470
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
472
.RETURNS 0 / -1 (error)
473
.REMARKS System dependencies:
475
------------------------------------------------------------*/
476
int fd; /* IN: Tape device file descriptor */
481
if (ioctop(fd,MTIOREW,1) == -1)
488
static int iofsr(fd,count)
489
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
490
.PURPOSE Forward space record on tape
491
.RETURNS records skipped/ -1 (error)
492
.REMARKS System dependencies:
494
------------------------------------------------------------*/
495
int fd; /* IN: Tape device file descriptor */
496
int count; /* IN: Number of records */
504
stat = ioctop(fd,MTIOFSR,count);
507
case M_ST_SUCC: /* Command OK */
510
case M_ST_DATA: /* End of records */
523
static int iobsr(fd,count)
524
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
525
.PURPOSE Backward space record on tape
526
.RETURNS records skipped/ -1 (error)
527
.REMARKS System dependencies:
529
------------------------------------------------------------*/
530
int fd; /* IN: Tape device file descriptor */
531
int count; /* IN: Number of records */
538
stat = ioctop(fd,MTIOBSR,count);
541
case M_ST_SUCC: /* Command OK */
559
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
560
.PURPOSE Clear a serious exception.
561
.RETURNS 0 / -1 (error)
562
.REMARKS System dependencies:
564
------------------------------------------------------------*/
565
int fd; /* IN: Tape device file descriptor */
571
return(-1); /* MTCSE does not exit */
575
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
576
.PURPOSE Move to EOMedia
577
.RETURNS 0 (OK) / -1 (not done, error)
578
------------------------------------------------------------*/
579
int fd; /* IN: Tape device file descriptor */
587
static int iosread(fd, spos, ssize, buffer, size)
588
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
589
.PURPOSE Read a block from a unit
590
.RETURNS Bytes read / -1 if error
591
------------------------------------------------------------*/
592
int fd; /* IN: File descriptor */
593
long spos; /* IN: Sector Number */
594
int ssize; /* IN: Size of one sector */
595
char *buffer; /* IN: Buffer for reading */
596
int size; /* IN: Length of bytes to be read */
599
printf ("iosread\n");
604
static int ioswrite(fd, spos, ssize, buffer, size)
605
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
606
.PURPOSE Read a block from a unit
607
.RETURNS Bytes read / -1 if error
608
------------------------------------------------------------*/
609
int fd; /* IN: File descriptor */
610
long spos; /* IN: Sector Number */
611
int ssize; /* IN: Size of one sector */
612
char *buffer; /* IN: Buffer for reading */
613
int size; /* IN: Length of bytes to be read */
616
printf ("ioswrite\n");
622
/*=====================================================================
623
* Definition of the structure returned to osu
624
*=====================================================================*/
626
/* struct iolist *iodev1();*/ /* Next iodev in List */
629
static OPITEM list_of_functions[] = {
638
{ U_SWRITE, ioswrite},
645
static struct iolist this_dev = {
646
(IODEV)0, /* No Next iodev in List */
647
class_name, /* How it's written in DEVCAPFILE */
648
sizeof(list_of_functions)/sizeof(list_of_functions[0]),
652
struct iolist *iodev()
653
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
654
.PURPOSE Get All definitions concerning this class of Devices
656
.REMARKS Simply returns the local iolist address...
657
------------------------------------------------------------*/