Debian Codegraph @

libsrc/os/vms/iodev0.c

raw
1 /* @(#)iodev0.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 .TYPE Module
31 .NAME iodev0.c
32 .LANGUAGE C
33 .AUTHOR IPG-ESO Garching
34 .CATEGORY Host operating system interfaces. TBD
35 .COMMENTS Dumb Devices
36 .VERSION 1.0 10-Jan-1990: Creation
37 .VERSION 1.1 18-May-1990: 2 parametesr for ioclose
38 .ENVIRONMENT VAX/VMS
39 ------------------------------------------------------------*/
40 static char class_name[] = "dumb"; /* e.g. null device */
41
42 #include <osdefos.h>
43 #include <osudef.h>
44 #include <filedef.h> /* Contains definitions of READ / WRITE, etc... */
45
46 #include <iodef.h> /* VMS QIO function codes */
47 #include <ssdef.h> /* VMS status code definitions */
48 #include <descrip.h> /* VMS descriptor macro */
49 #include <errno.h>
50
51 struct iolist *iodev1(); /* Next io routines in list */
52
53 MID_EXTERN int oserror; /* MIDAS os-error status */
54 MID_EXTERN int vmserror; /* translated by osmsg() */
55
56 #define L dsc$w_length
57 #define S dsc$a_pointer
58 #define SET_STRING(dsc,str,l) dsc.S = str, dsc.L = l \
59 /* Set address & length of a string */
60
61 static short chan;
62 static struct dsc$descriptor_s sdv = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
63 struct IOSB {
64 unsigned short int iostatus;
65 unsigned short int length;
66 unsigned long int info;
67 };
68 static struct IOSB iosb; /* The i/o status block */
69
70 #define CheckVMS if (!(vmserror&1)) { oserror = EIO; return(-1);}
71
72 /*======================================================================*/
73 static int io1 (op, buffer, length)
74 /*+++++++++++++
75 .PURPOSE Interface to SYS$QIOW, with test of main returned status
76 .RETURNS Byte count / -1
77 .REMARK
78 --------------*/
79 int op; /* IN: The operation to perform */
80 char *buffer; /* OUT: Buffer address */
81 int length; /* IN: Buffer length */
82 {
83 register int l;
84
85 if (oserror) return(-1);
86
87 iosb.iostatus = 0, iosb.length = 0;
88 vmserror = SYS$QIOW (0,chan,op,&iosb,0,0,buffer,length,0,0,0,0);
89 l = iosb.length;
90
91 if (!(vmserror & 1)) oserror = EIO, l = -1;
92
93 return(l);
94 }
95
96 /*======================================================================*/
97 static int io2 (op, buffer, length)
98 /*+++++++++++++
99 .PURPOSE Interface to SYS$QIOW, with test of 2 returned codes
100 .RETURNS Length / -1 if error / 0 for EOF
101 .REMARK
102 --------------*/
103 int op; /* IN: The operation to perform */
104 char *buffer; /* OUT: Buffer address */
105 int length; /* IN: Buffer length */
106 {
107 register int l;
108
109 l = io1(op, buffer, length);
110
111 if (oserror == 0)
112 { switch(iosb.iostatus)
113 { case SS$_NORMAL: break;
114 #if 0 /* Following cases ignored here */
115 case SS$_DATAOVERUN: if (l == length) l++;
116 break;
117 case SS$_ENDOFTAPE: oserrmsg = "Physical End reached";
118 oserror = -1;
119 break;
120 case SS$_FORMAT: /* This happens with virgin sectors on ODs. */
121 break;
122 #endif
123 case SS$_ENDOFVOLUME:
124 case SS$_ENDOFFILE: l = 0; break; /* No error */
125
126
127 default: oserror = EIO;
128 vmserror = iosb.iostatus;
129 break;
130 }
131 }
132 return (oserror ? -1 : l);
133 }
134
135 static int iorew(fd)
136 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
137 .PURPOSE Go to sector #0
138 .RETURNS 0 (success) / -1 (error)
139 ------------------------------------------------------------*/
140 int fd; /* IN: File Descriptor */
141 {
142 return(0);
143 }
144
145 static int ioinfo(fd, s, fileno, blkno)
146 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
147 .PURPOSE Retrieve Info concerning an opened device
148 .RETURNS 0 (success) / -1 (error)
149 ------------------------------------------------------------*/
150 int fd; /* IN: File Descriptor */
151 struct osustat *s; /* OUT: The filled components */
152 int *fileno; /* OUT: Where we are */
153 long *blkno; /* OUT: Where we are */
154 {
155 oserror = 0;
156 if (fileno) {
157 *fileno = -1;
158 *blkno = -1; /* Unknown ... */
159 }
160
161 s->usize = 0;
162 s->blocksize = 0;
163 s->density = 0;
164 s->isda = 0;
165
166 return(0);
167 }
168
169 static int ioopen(name, mode, den)
170 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 .PURPOSE Open Raw Disk Tape
172 .RETURNS File descriptor / -1 (error)
173 .REMARKS
174 ------------------------------------------------------------*/
175 char *name; /* IN: Physical name of tape device */
176 int mode; /* IN: Open mode */
177 int den; /* IN: Density. Not used */
178 {
179 int l;
180
181 oserror = 0;
182 /* Add the : if necessary */
183 sdv.S = name;
184 sdv.L = l = strlen(name);
185 if (name[l-1] != ':') name[l] = ':', sdv.L += 1;
186
187 /* Assign the device */
188 vmserror = SYS$ASSIGN(&sdv,&chan,0,0);
189 name[l] = '\0';
190 CheckVMS
191
192 return(chan);
193 }
194
195 static int ioclose(fd, option)
196 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
197 .PURPOSE Close the Device
198 .RETURNS 0 (success) / -1 (failure)
199 ------------------------------------------------------------*/
200 int fd; /* IN: Tape file descriptor */
201 int option; /* IN: Option OPU_DISMOUNT */
202 {
203 oserror=0;
204 vmserror = SYS$DASSGN(fd);
205 CheckVMS
206
207 return(oserror ? -1 : 0);
208 }
209
210 static int ioread(fd, buffer, size)
211 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
212 .PURPOSE Read a buffer from a dumb device
213 .RETURNS Bytes read / -1 if error
214 .REMARKS 0 Bytes read, means EOF
215 ------------------------------------------------------------*/
216 int fd; /* IN: Tape device file descriptor */
217 char *buffer; /* OUT: Buffer for reading */
218 int size; /* IN: Length of bytes to be read */
219 {
220 int stat;
221
222 oserror = 0, chan = fd;
223
224 return (io2(IO$_READLBLK, buffer, size));
225 }
226
227 static int iowrite(fd, buffer, size)
228 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
229 .PURPOSE Write a block to a DA device
230 .RETURNS Bytes written / -1 if error
231 .REMARKS 0 Bytes read, means ???
232 ------------------------------------------------------------*/
233 int fd; /* IN: Tape device file descriptor */
234 char *buffer; /* IN: Buffer for reading */
235 int size; /* IN: Length of bytes to be read */
236 {
237 int stat;
238
239 oserror = 0, chan = fd;
240
241 return (io2(IO$_WRITELBLK, buffer, size));
242 }
243
244 /*=====================================================================
245 * Definition of the structure returned to osu
246 *=====================================================================*/
247
248 static OPITEM list_of_functions[] = {
249 { U_OPEN, ioopen}, /* Open (name, mode) */
250 { U_CLOSE, ioclose},
251 { U_INFO, ioinfo},
252 { U_READ, ioread},
253 { U_WRITE, iowrite},
254 { U_REWIND, iorew}
255 };
256
257
258 static struct iolist this_dev = {
259 iodev1, /* Next iodev in List */
260 class_name, /* How it's written in DEVCAPFILE */
261 sizeof(list_of_functions)/sizeof(list_of_functions[0]),
262 list_of_functions
263 };
264
265 struct iolist *iodev0()
266 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
267 .PURPOSE Get All definitions concerning this class of Devices
268 .RETURNS The iolist
269 .REMARKS
270 ------------------------------------------------------------*/
271 {
272 return(&this_dev);
273 }