Debian Codegraph @

libsrc/os/vms/iodev.c

raw
1 /* @(#)iodev.c 19.1 (ES0-DMD) 02/25/03 13:56:10 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
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.
9
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.
14
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,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30 .COPYRIGHT (c) 1988 European Southern Observatory
31 .IDENT iodev.c
32 .LANGUAGE C
33 .AUTHOR P.Grosbol ESO/IPG
34 .KEYWORDS VMS QIO, tape I/O
35 .ENVIRON VAX/VMS
36 .COMMENT Ref. to VAX/VMS I/O User's Guide Vol.1, Chap.7 for
37 status codes etc.
38 .VERSION 1.0 1988-Nov-28 : Creation, PJG
39 .VERSION 1.1 1988-Dec-08 : Set EOF-status to 0, CGS
40 .VERSION 1.2 1989-Mar-11 : Do not dismount tape, PJG
41 .VERSION 1.3 1989-Oct-11 : Hide everything, FO
42 Also errors correctly retrieved via osmsg()
43 .VERSION 1.4 1989-Dec-20 : 4 parameters for ioinfo
44 .VERSION 1.5 21-May-1990 : 2 parameters for ioclose.
45 Added IO$M_NOASSIST option in MOUNT, such that
46 a clear error message is displayed if the
47 tape unit is not ready ...
48 .VERSION 1.6 17-Aug-1990 : Check (open AND close) that the colon is
49 present...
50 .VERSION 1.7 14-Nov-1990 : Modified oserror values (cf errno.h)
51 .VERSION 1.8 23-Apr-1991 : Check ALL statuses...
52 .VERSION 1.9 20-Aug-1992 : variant_struct not known for GNU. CG.
53 --------------------------------------------------------------------*/
54 static char class_name[] = "mt"; /* MAgnetic Tape Class */
55
56 #include <osdefos.h>
57 #include <osudef.h>
58 #include <descrip.h> /* VMS descriptor macro */
59 #include <iodef.h> /* VMS QIO function codes */
60
61 #ifndef variant_struct
62 #define variant_struct struct
63 #endif
64 #include <mntdef.h> /* VMS MOUNT definitions */
65
66 #include <ssdef.h> /* VMS status code definitions */
67 #include <errno.h> /* Standard Unix error codes */
68
69 MID_EXTERN int oserror; /* MIDAS os-error status */
70 MID_EXTERN int vmserror; /* translated by osmsg() */
71
72 #define DMT$M_NOUNLOAD 1 /* take it from <dmtdef> */
73 #define MT$M_DENSITY 7936 /* Density mask (0x1f00) */
74 #define MT$S_DENSITY 5 /* Length in bits of den. field */
75 #define MT$V_DENSITY 8 /* Offset in bits of den. field */
76 #define MT$K_NRZI_800 3 /* Value for 800 bpi */
77 #define MT$K_PE_1600 4 /* Value for 1600 bpi */
78 #define MT$K_GCR_6250 5 /* Value for 6250 bpi */
79
80 #define MAXDN 64 /* max. length of device name */
81 static char dname[MAXDN]; /* device name */
82 static $DESCRIPTOR(src,dname);
83
84 typedef struct {
85 unsigned short int iostatus;
86 unsigned short int length;
87 unsigned long int info;
88 } IOSB;
89
90 /*======================================================================*/
91 static void devname(name)
92 /*+++++++++++++
93 .PURPOSE Set decriptor with device name
94 .RETURNS Nothing
95 .REMARK Add colon if missing
96 --------------*/
97 char *name; /* IN: Device name */
98 {
99 int len;
100
101 len = strlen(name);
102 /* Add the : if necessary */
103 if ((name[len-1] != ':') && (len < sizeof(dname)))
104 { oscopy (dname, name, len);
105 dname[len++] = ':';
106 src.dsc$a_pointer = dname;
107 }
108 else src.dsc$a_pointer = name;
109
110 src.dsc$w_length = len;
111 return;
112 }
113
114 static int ioinfo(fd, s, fileno, blkno)
115 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
116 .PURPOSE Retrieve Info concerning an opened device
117 .RETURNS 0 (success) / -1 (error)
118 .REMARKS File position and Block position could be set in SCSI tapes ?
119 Here, these numbers are just set to -1 (unknown)
120 --------------------------------------------------------------------*/
121 int fd; /* IN: File Descriptor */
122 struct osustat *s; /* OUT: The filled components */
123 int *fileno; /* OUT: File position (-1) */
124 long *blkno; /* OUT: Block position */
125 {
126 short qio_chan;
127 IOSB iosb;
128
129 if (fileno) *fileno = -1;
130 if (blkno) *blkno = -1;
131 qio_chan = fd;
132 s->usize = 0;
133 s->blocksize = 0;
134 vmserror = sys$qiow(0,qio_chan,IO$_SENSEMODE,&iosb,0,0,0,0,0,0,0,0);
135 if (vmserror!= SS$_NORMAL) {
136 oserror = EIO;
137 return -1;
138 }
139
140 s->density = (iosb.info & MT$M_DENSITY)>> MT$V_DENSITY;
141 if (s->density == MT$K_GCR_6250) s->density = 6250;
142 else if (s->density == MT$K_NRZI_800) s->density = 800;
143 else s->density = 1600;
144
145 s->isda = 0; /* Note: should use getdvi... */
146 s->istm = 1; /* Note: should use getdvi... */
147
148 return 0;
149 }
150
151 static int ioopen(device,mode,den)
152 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153 .PURPOSE Assign I/O channel to device
154 .RETURN I/O channel of OK else -1 if assign error
155 --------------------------------------------------------------------*/
156 char *device; /* IN: pointer to device name */
157 int mode; /* IN: open mode - NOT used! */
158 int den; /* IN: tape density */
159 {
160 int sys$assign();
161 int sys$mount();
162 int tden,flag,siz;
163 short qio_chan;
164 struct MNTL {
165 short length;
166 short func;
167 char *buf;
168 int term;
169 } mntl[6];
170
171 devname(device);
172
173 siz = 32000; tden = den; /* setup MOUNT parameters */
174 flag = MNT$M_FOREIGN | MNT$M_NOLABEL | MNT$M_NOASSIST;
175
176 mntl[0].length = src.dsc$w_length; mntl[0].func = MNT$_DEVNAM;
177 mntl[0].buf = src.dsc$a_pointer; mntl[0].term = 0;
178 mntl[1].length = 4; mntl[1].func = MNT$_FLAGS;
179 mntl[1].buf = (char *) &flag; mntl[1].term = 0;
180 mntl[2].length = 4; mntl[2].func = MNT$_DENSITY;
181 mntl[2].buf = (char *) &tden; mntl[2].term = 0;
182 mntl[3].length = 4; mntl[3].func = MNT$_BLOCKSIZE;
183 mntl[3].buf = (char *) &siz; mntl[3].term = 0;
184 mntl[4].length = 4; mntl[4].func = MNT$_RECORDSIZ;
185 mntl[4].buf = (char *) &siz; mntl[4].term = 0;
186 mntl[5].length = 0; mntl[5].func = 0;
187 mntl[5].buf = (char *) 0; mntl[5].term = 0;
188
189 vmserror = sys$mount(mntl);
190 vmserror &= 0xFFFF; /* blank out status level */
191 if (vmserror != SS$_NORMAL && vmserror != SS$_DEVMOUNT) {
192 oserror = ENXIO;
193 return -1;
194 }
195 /* if (vmserror == SS$_DEVMOUNT)
196 printf("Warning: Device already mounted\n"); */
197
198 vmserror = sys$assign(&src,&qio_chan,0,0);
199 if (vmserror != SS$_NORMAL) {
200 oserror = ENXIO;
201 return -1;
202 }
203 return qio_chan;
204 }
205
206 static int ioclose(fd, option)
207 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
208 .PURPOSE Deassign or close I/O channel to device
209 .RETURN 0: OK ,else -1: error
210 --------------------------------------------------------------------*/
211 int fd; /* IN: file desc. - I/O-channel */
212 int option; /* IN: Option OPU_DISMOUNT */
213 {
214 int sys$dassgn();
215 int sys$dismou();
216 short qio_chan;
217 IOSB iosb;
218 char *device;
219
220 qio_chan = fd;
221 vmserror = sys$qiow(0,qio_chan,IO$_REWIND|IO$M_NOWAIT,&iosb,0,0,0,0,0,0,0,0);
222 vmserror = sys$dassgn(qio_chan);
223 if (vmserror != SS$_NORMAL) {
224 oserror = ENXIO;
225 return -1;
226 }
227 /* Need to get back device name */
228 device = osuname(-1);
229 devname(device);
230
231 vmserror = sys$dismou(&src, (option & OPU_DISMOUNT ? 0 :DMT$M_NOUNLOAD));
232 return 0;
233 }
234
235 static int ioread(fd,buf,no)
236 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
237 .PURPOSE Read data from a VMS I/O-channel
238 .RETURN no. of bytes read if OK
239 else 0: EOF, -2: QIO error
240 --------------------------------------------------------------------*/
241 int fd; /* IN: I/O-channel no. */
242 char *buf; /* IN: pointer to data buffer */
243 int no; /* IN: no. of bytes to read */
244 {
245 int sys$qiow();
246 short qio_chan;
247 IOSB iosb;
248
249 qio_chan = fd;
250 vmserror = sys$qiow(0,qio_chan,IO$_READLBLK,&iosb,0,0,buf,no,0,0,0,0);
251 if (vmserror != SS$_NORMAL) {
252 oserror = EIO;
253 return -1;
254 }
255 vmserror = iosb.iostatus;
256 if (vmserror & 1) return (iosb.length);
257 if (vmserror == SS$_ENDOFFILE) return (0);
258 oserror = EIO;
259 return(-1);
260 }
261
262 static int iowrite(fd,buf,no)
263 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
264 .PURPOSE Write data to a VMS I/O-channel
265 .RETURN no. of bytes written if OK
266 else -1: EOT, -2: QIO error, -3: Timeout
267 --------------------------------------------------------------------*/
268 int fd; /* IN: I/O-channel no. */
269 char *buf; /* IN: pointer to data buffer */
270 int no; /* IN: no. of bytes to read */
271 {
272 int sys$qiow();
273 short qio_chan;
274 IOSB iosb;
275
276 qio_chan = fd;
277 vmserror = sys$qiow(0,qio_chan,IO$_WRITELBLK,&iosb,0,0,buf,no,0,0,0,0);
278 if (vmserror != SS$_NORMAL) {
279 oserror = EIO;
280 return -1;
281 }
282 vmserror = iosb.iostatus;
283 if (vmserror & 1) return (iosb.length);
284 if (vmserror == SS$_ENDOFFILE) return (0);
285 oserror = EIO;
286 return(-1);
287 }
288
289 static int ioweof(fd)
290 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
291 .PURPOSE Write EOF's on tape assigned to a VMS I/O-channel
292 .RETURN 0: OK ,else -1: QIO error, -2: EOT
293 --------------------------------------------------------------------*/
294 int fd; /* IN: I/O-channel no. */
295 {
296 int sys$qiow();
297 int i;
298 short qio_chan;
299 IOSB iosb;
300
301 qio_chan = fd;
302 vmserror = sys$qiow(0,qio_chan,IO$_WRITEOF,&iosb,0,0,0,0,0,0,0,0);
303 if (vmserror != SS$_NORMAL) {
304 oserror = EIO;
305 return -1;
306 }
307 vmserror = iosb.iostatus;
308 if (vmserror & 1) return (iosb.length);
309 if (vmserror == SS$_ENDOFFILE) return (0);
310 oserror = EIO;
311 return(-1);
312 }
313
314 static int iorew(fd)
315 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
316 .PURPOSE Rewind tape assigned to a VMS I/O-channel.
317 .RETURN 0: OK , -1: QIO error
318 --------------------------------------------------------------------*/
319 int fd; /* IN: I/O-channel no. */
320 {
321 int sys$qiow();
322 short qio_chan;
323 IOSB iosb;
324
325 qio_chan = fd;
326 vmserror = sys$qiow(0,qio_chan,IO$_REWIND,&iosb,0,0,0,0,0,0,0,0);
327 if (vmserror != SS$_NORMAL) {
328 oserror = EIO;
329 return -1;
330 }
331 vmserror = iosb.iostatus;
332 if (vmserror & 1) return (iosb.length);
333 if (vmserror == SS$_ENDOFFILE) return (0);
334 oserror = EIO;
335 return(-1);
336 }
337
338 static int iosf(fd,no)
339 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
340 .PURPOSE Skip files on tape assigned to a VMS I/O-channel
341 .RETURN 0: OK , -1: QIO error
342 --------------------------------------------------------------------*/
343 int fd; /* IN: I/O-channel no. */
344 int no; /* IN: no. of files to skip */
345 {
346 int sys$qiow();
347 short qio_chan;
348 IOSB iosb;
349
350 qio_chan = fd;
351 vmserror = sys$qiow(0,qio_chan,IO$_SKIPFILE,&iosb,0,0,no,0,0,0,0,0);
352 if (vmserror != SS$_NORMAL) {
353 oserror = EIO;
354 return -1;
355 }
356 vmserror = iosb.iostatus;
357 if (vmserror & 1) return (iosb.length);
358 if (vmserror == SS$_ENDOFFILE) return (0);
359 oserror = EIO;
360 return(-1);
361 }
362
363 static int iosr(fd,no)
364 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
365 .PURPOSE Skip files on tape assigned to a VMS I/O-channel
366 .RETURN 0: OK , -1: QIO error
367 --------------------------------------------------------------------*/
368 int fd; /* IN: I/O-channel no. */
369 int no; /* IN: no. of files to skip */
370 {
371 int sys$qiow();
372 short qio_chan;
373 IOSB iosb;
374
375 qio_chan = fd;
376 vmserror = sys$qiow(0,qio_chan,IO$_SKIPRECORD,&iosb,0,0,no,0,0,0,0,0);
377 if (vmserror != SS$_NORMAL) {
378 oserror = EIO;
379 return -1;
380 }
381 vmserror = iosb.iostatus;
382 if (vmserror & 1) return (iosb.length);
383 if (vmserror == SS$_ENDOFFILE) return (0);
384 oserror = EIO;
385 return(-1);
386 }
387
388 static int iofsf(fd,no)
389 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
390 .PURPOSE Forward Skip Files on tape assigned to a VMS I/O-channel
391 .RETURN 0: OK , -1: QIO error
392 --------------------------------------------------------------------*/
393 int fd; /* IN: I/O-channel no. */
394 int no; /* IN: no. of files to skip */
395 {
396 return iosf(fd,no);
397 }
398
399 static int iobsf(fd,no)
400 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
401 .PURPOSE Backward Skip Files on tape assigned to a VMS I/O-channel
402 .RETURN 0: OK , -1: QIO error
403 --------------------------------------------------------------------*/
404 int fd; /* IN: I/O-channel no. */
405 int no; /* IN: no. of files to skip */
406 {
407 return iosf(fd,-no);
408 }
409
410 static int iofsr(fd,no)
411 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
412 .PURPOSE Forward Skip Files on tape assigned to a VMS I/O-channel
413 .RETURN 0: OK , -1: QIO error
414 --------------------------------------------------------------------*/
415 int fd; /* IN: I/O-channel no. */
416 int no; /* IN: no. of records to skip */
417 {
418 return iosr(fd,no);
419 }
420
421 static int iobsr(fd,no)
422 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
423 .PURPOSE Bachward Skip Record on tape assigned to a VMS I/O-channel
424 .RETURN 0: OK , -1: QIO error
425 --------------------------------------------------------------------*/
426 int fd; /* IN: I/O-channel no. */
427 int no; /* IN: no. of records to skip */
428 {
429 return iosr(fd,-no);
430 }
431
432 /*=====================================================================
433 * Definition of the structure returned to osu
434 *=====================================================================*/
435
436 struct iolist *iodev0();
437
438 static OPITEM list_of_functions[] = {
439 { U_INFO, ioinfo},
440 { U_OPEN, ioopen},
441 { U_CLOSE, ioclose},
442 { U_READ, ioread},
443 { U_WRITE, iowrite},
444 { U_REWIND, iorew},
445 { U_WEOF, ioweof},
446 { U_FMF, iofsf}, /* File Move Forward */
447 { U_FMB, iobsf}, /* File Move Backward */
448 { U_BMF, iofsr}, /* Block Move Forward */
449 { U_BMB, iobsr} /* Block Move Backward */
450 };
451
452 static struct iolist this_dev = {
453 iodev0, /* Next iodev in List */
454 class_name, /* How it's written in DEVCAPFILE */
455 sizeof(list_of_functions)/sizeof(list_of_functions[0]),
456 list_of_functions
457 };
458
459 struct iolist *iodev()
460 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
461 .PURPOSE Get All definitions concerning this class of Devices
462 .RETURNS The iolist
463 .REMARKS Simply returns the local iolist address...
464 ------------------------------------------------------------*/
465 {
466 return(&this_dev);
467 }