| 1 |
/* @(#)iodev1.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 iodev1 |
| 32 |
.LANGUAGE C |
| 33 |
.AUTHOR IPG-ESO Garching |
| 34 |
.CATEGORY Basic disk i/o |
| 35 |
.COMMENTS Class is made for Disks / OD |
| 36 |
.VERSION 0.0 12-Oct-1989: Design, F. Ochsenbein, C. Guirao |
| 37 |
.VERSION 1.0 11-Jan-1990: Implementation. |
| 38 |
.VERSION 1.1 18-May-1990: 2 parameterse for ioclose |
| 39 |
.VERSION 1.2 17-Aug-1990: Correct order: 1) Mount 2) Assign |
| 40 |
.VERSION 1.3 17-Oct-1990: Removed GNU-nonunderstandable code... |
| 41 |
.VERSION 1.4 20-Aug-1992: variant_struct not known for GNU. CG. |
| 42 |
.ENVIRONMENT VMS |
| 43 |
------------------------------------------------------------*/ |
| 44 |
static char class_name[] = "disk"; |
| 45 |
|
| 46 |
#include <osdefos.h> |
| 47 |
#include <osudef.h> |
| 48 |
#include <filedef.h> /* Contains definitions of READ / WRITE, etc... */ |
| 49 |
|
| 50 |
struct iolist *iodev2(); /* Next io routines in list */ |
| 51 |
|
| 52 |
|
| 53 |
#ifndef variant_struct |
| 54 |
#define variant_struct struct |
| 55 |
#endif |
| 56 |
#include <mntdef.h> /* VMS MOUNT definitions */ |
| 57 |
|
| 58 |
#define DMT$M_NOUNLOAD 1 /* take it from <dmtdef> */ |
| 59 |
#include <iodef.h> /* VMS QIO function codes */ |
| 60 |
#include <ssdef.h> /* VMS status code definitions */ |
| 61 |
#include <descrip.h> /* VMS descriptor macro */ |
| 62 |
#include <dvidef.h> /* VMS for GetDVI */ |
| 63 |
#include <dcdef.h> /* VMS classes of devices */ |
| 64 |
#include <errno.h> |
| 65 |
|
| 66 |
#define SECTOR_SIZE 512 /* The VMS standard */ |
| 67 |
|
| 68 |
MID_EXTERN int oserror; |
| 69 |
MID_EXTERN int vmserror; /* translated by osmsg() */ |
| 70 |
|
| 71 |
typedef struct dsc$descriptor_s SDV; |
| 72 |
|
| 73 |
/* Set address & length of a string */ |
| 74 |
|
| 75 |
static short chan; |
| 76 |
static struct { |
| 77 |
unsigned short iostatus; |
| 78 |
unsigned short length; |
| 79 |
unsigned long info; |
| 80 |
} iosb = {0, 0, 0}; /* The i/o status block */ |
| 81 |
|
| 82 |
typedef struct item { /* Specification for System Services */ |
| 83 |
unsigned short len; |
| 84 |
unsigned short item_code; |
| 85 |
char *addr; |
| 86 |
long *return_len; |
| 87 |
} ITEM; |
| 88 |
|
| 89 |
#define if_VMSerror if (!(vmserror&1)) |
| 90 |
|
| 91 |
/*======================================================================*/ |
| 92 |
static SDV *devname(name) |
| 93 |
/*+++++++++++++ |
| 94 |
.PURPOSE Set sdv with device name |
| 95 |
.RETURNS Nothing |
| 96 |
.REMARK Add colon if missing |
| 97 |
--------------*/ |
| 98 |
char *name; /* IN: Device name */ |
| 99 |
{ |
| 100 |
static SDV sdv = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0}; |
| 101 |
static char aName[20]; |
| 102 |
int len; |
| 103 |
|
| 104 |
len = strlen(name); |
| 105 |
/* Add the : if necessary */ |
| 106 |
if ((name[len-1] != ':') && (len < sizeof(aName))) |
| 107 |
{ oscopy (aName, name, len); |
| 108 |
aName[len++] = ':'; |
| 109 |
sdv.dsc$a_pointer = aName; |
| 110 |
} |
| 111 |
else sdv.dsc$a_pointer = name; |
| 112 |
|
| 113 |
sdv.dsc$w_length = len; |
| 114 |
return (&sdv); |
| 115 |
} |
| 116 |
|
| 117 |
/*======================================================================*/ |
| 118 |
static int io1 (op, buffer, length, block) |
| 119 |
/*+++++++++++++ |
| 120 |
.PURPOSE Interface to SYS$QIOW, with test of main returned status |
| 121 |
.RETURNS Byte count / -1 |
| 122 |
.REMARK No tracing in this routine, only called from other osu routines |
| 123 |
--------------*/ |
| 124 |
int op; /* IN: The operation to perform */ |
| 125 |
char *buffer; /* OUT: Buffer address */ |
| 126 |
int length; /* IN: Buffer length */ |
| 127 |
int block; /* IN: Sector number */ |
| 128 |
{ |
| 129 |
register int l; |
| 130 |
|
| 131 |
if (oserror) return(-1); |
| 132 |
|
| 133 |
iosb.iostatus = 0, iosb.length = 0; |
| 134 |
vmserror = SYS$QIOW (0,chan,op,&iosb,0,0,buffer,length,block,0,0,0); |
| 135 |
l = iosb.length; |
| 136 |
|
| 137 |
if (!(vmserror & 1)) oserror = EIO, l = -1; |
| 138 |
|
| 139 |
return(l); |
| 140 |
} |
| 141 |
|
| 142 |
/*======================================================================*/ |
| 143 |
static int io2 (op, buffer, length, block) |
| 144 |
/*+++++++++++++ |
| 145 |
.PURPOSE Interface to SYS$QIOW, with test of 2 returned codes |
| 146 |
.RETURNS Length / -1 if error / 0 for EOF or Virgin Sectors |
| 147 |
.REMARK |
| 148 |
--------------*/ |
| 149 |
int op; /* IN: The operation to perform */ |
| 150 |
char *buffer; /* OUT: Buffer address */ |
| 151 |
int length; /* IN: Buffer length */ |
| 152 |
int block; /* IN: Sector number */ |
| 153 |
{ |
| 154 |
register int l; |
| 155 |
|
| 156 |
l = io1(op, buffer, length, block); |
| 157 |
|
| 158 |
if (oserror == 0) |
| 159 |
{ switch(iosb.iostatus) |
| 160 |
{ case SS$_NORMAL: break; |
| 161 |
#if 0 /* Following cases ignored here */ |
| 162 |
case SS$_DATAOVERUN: if (l == length) l++; |
| 163 |
break; |
| 164 |
case SS$_ENDOFTAPE: oserrmsg = "Physical End reached"; |
| 165 |
oserror = -1; |
| 166 |
break; |
| 167 |
#endif |
| 168 |
case SS$_FORCEDERROR: |
| 169 |
case SS$_FORMAT: /* This happens with virgin sectors on ODs. */ |
| 170 |
break; |
| 171 |
case SS$_ENDOFVOLUME: |
| 172 |
case SS$_ENDOFFILE: l = 0; break; /* No error */ |
| 173 |
|
| 174 |
|
| 175 |
default: oserror = EIO; |
| 176 |
vmserror = iosb.iostatus; |
| 177 |
break; |
| 178 |
} |
| 179 |
} |
| 180 |
return (oserror ? -1 : l); |
| 181 |
} |
| 182 |
|
| 183 |
/*======================================================================*/ |
| 184 |
static int iorew(fd) |
| 185 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 186 |
.PURPOSE Go to sector #0 |
| 187 |
.RETURNS 0 (success) / -1 (error) |
| 188 |
------------------------------------------------------------*/ |
| 189 |
int fd; /* IN: File Descriptor */ |
| 190 |
{ |
| 191 |
return(0); |
| 192 |
} |
| 193 |
|
| 194 |
static int ioinfo(fd, s, fileno, blkno) |
| 195 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 196 |
.PURPOSE Retrieve Info concerning an opened device |
| 197 |
.RETURNS 0 (success) / -1 (error) |
| 198 |
------------------------------------------------------------*/ |
| 199 |
int fd; /* IN: File Descriptor */ |
| 200 |
struct osustat *s; /* OUT: The filled components */ |
| 201 |
int *fileno; /* OUT: Where we are */ |
| 202 |
long *blkno; /* OUT: Where we are */ |
| 203 |
{ |
| 204 |
SDV *sdv; /* Need the device name to get info */ |
| 205 |
static int dev_class; /* The VMS device class */ |
| 206 |
static struct { struct item item_1; |
| 207 |
long end;} getdvi = { |
| 208 |
{ sizeof(dev_class),DVI$_DEVCLASS,(char *)&dev_class,(long *)0}, |
| 209 |
0}; |
| 210 |
|
| 211 |
oserror = 0; |
| 212 |
if (fileno) *fileno = *blkno = -1; /* Unknown ... */ |
| 213 |
s->usize = 0; |
| 214 |
s->blocksize = 0; |
| 215 |
s->density = 0; |
| 216 |
|
| 217 |
|
| 218 |
sdv = devname(osuname(-1)); |
| 219 |
|
| 220 |
/* Check if Tape or Disk via GETDVI */ |
| 221 |
getdvi.item_1.item_code = DVI$_DEVCLASS; |
| 222 |
vmserror = SYS$GETDVIW(0,0,sdv, &getdvi, &iosb,0,0,0); |
| 223 |
if_VMSerror { oserror = EIO; return(-1);} |
| 224 |
s->isda = (dev_class == DC$_DISK); |
| 225 |
|
| 226 |
/* For Disks, get relevant device info */ |
| 227 |
if (s->isda){ |
| 228 |
getdvi.item_1.item_code = DVI$_MAXBLOCK; |
| 229 |
vmserror = SYS$GETDVIW(0,0, sdv,&getdvi,&iosb,0,0,0); |
| 230 |
if_VMSerror { oserror = EIO; return(-1);} |
| 231 |
s->blocksize = SECTOR_SIZE; /* Unit used for usize */ |
| 232 |
s->usize = dev_class; /* Number of sectors in 512-bytes */ |
| 233 |
} |
| 234 |
return(0); |
| 235 |
} |
| 236 |
|
| 237 |
static int ioopen(name, mode, den) |
| 238 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 239 |
.PURPOSE Open Raw Disk Tape |
| 240 |
.RETURNS File descriptor / -1 (error) |
| 241 |
.REMARKS |
| 242 |
------------------------------------------------------------*/ |
| 243 |
char *name; /* IN: Physical name of tape device */ |
| 244 |
int mode; /* IN: Open mode */ |
| 245 |
int den; /* IN: Density. Not used */ |
| 246 |
{ |
| 247 |
SDV *sdv; /* Device name to get info */ |
| 248 |
int l; |
| 249 |
static unsigned long mount_option = |
| 250 |
/* MNT$M_NOASSIST|MNT$M_FOREIGN|MNT$M_MESSAGE; */ |
| 251 |
MNT$M_NOASSIST|MNT$M_FOREIGN; |
| 252 |
static struct { /* Mount service */ |
| 253 |
ITEM item_1; |
| 254 |
ITEM item_2; |
| 255 |
long end;} mount = { |
| 256 |
{ 0, MNT$_DEVNAM, 0, 0}, /* Device Name */ |
| 257 |
{ sizeof(mount_option),MNT$_FLAGS, (char *)&mount_option,(long *)0}, |
| 258 |
0}; |
| 259 |
|
| 260 |
oserror = 0; |
| 261 |
|
| 262 |
/* Mount the Disk */ |
| 263 |
|
| 264 |
sdv = devname(name); |
| 265 |
mount.item_1.len = sdv->dsc$w_length; |
| 266 |
mount.item_1.addr = sdv->dsc$a_pointer; |
| 267 |
|
| 268 |
vmserror = SYS$MOUNT(&mount); |
| 269 |
if_VMSerror /* Some error, but take only 16 bits */ |
| 270 |
switch(vmserror&0xffff) { |
| 271 |
case SS$_DEVMOUNT: break; /* Already mounted, not an error */ |
| 272 |
default: oserror = EINTR; |
| 273 |
return(-1); |
| 274 |
} |
| 275 |
|
| 276 |
/* Assign the device */ |
| 277 |
vmserror = SYS$ASSIGN(sdv, &chan, 0,0); |
| 278 |
if_VMSerror { oserror = EIO; return(-1);} |
| 279 |
|
| 280 |
return(chan); |
| 281 |
} |
| 282 |
|
| 283 |
static int ioclose(fd, option) |
| 284 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 285 |
.PURPOSE Close the Device |
| 286 |
.RETURNS 0 (success) / -1 (failure) |
| 287 |
------------------------------------------------------------*/ |
| 288 |
int fd; /* IN: Tape file descriptor */ |
| 289 |
int option; /* IN: Option OPU_DISMOUNT */ |
| 290 |
{ |
| 291 |
SDV *sdv; |
| 292 |
|
| 293 |
oserror=0; |
| 294 |
vmserror = SYS$DASSGN(fd); |
| 295 |
if_VMSerror { oserror = EIO; return(-1);} |
| 296 |
|
| 297 |
sdv = devname(osuname(-1)); |
| 298 |
vmserror = SYS$DISMOU(sdv, (option & OPU_DISMOUNT ? 0 :DMT$M_NOUNLOAD)); |
| 299 |
if_VMSerror { oserror = EIO; return(-1);} |
| 300 |
|
| 301 |
return(0); |
| 302 |
} |
| 303 |
|
| 304 |
static int iosread(fd, sno, ssize, buffer, size) |
| 305 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 306 |
.PURPOSE Read a buffer from a DA device |
| 307 |
.RETURNS Bytes read / -1 if error |
| 308 |
.REMARKS 0 Bytes read, means ??? |
| 309 |
------------------------------------------------------------*/ |
| 310 |
int fd; /* IN: Tape device file descriptor */ |
| 311 |
long sno; /* IN: Starting sector to read */ |
| 312 |
int ssize; /* IN: Size on one sector */ |
| 313 |
char *buffer; /* OUT: Buffer for reading */ |
| 314 |
int size; /* IN: Length of bytes to be read */ |
| 315 |
{ |
| 316 |
long block; |
| 317 |
|
| 318 |
oserror = 0, chan = fd; |
| 319 |
block = sno*(ssize/SECTOR_SIZE); |
| 320 |
return (io2(IO$_READLBLK, buffer, size, block)); |
| 321 |
} |
| 322 |
|
| 323 |
static int ioswrite(fd, sno, ssize, buffer, size) |
| 324 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 325 |
.PURPOSE Write a block to a DA device |
| 326 |
.RETURNS Bytes written / -1 if error |
| 327 |
.REMARKS 0 Bytes read, means ??? |
| 328 |
------------------------------------------------------------*/ |
| 329 |
int fd; /* IN: Tape device file descriptor */ |
| 330 |
long sno; /* IN: Starting sector to write */ |
| 331 |
int ssize; /* IN: Size on one sector */ |
| 332 |
char *buffer; /* IN: Buffer to write */ |
| 333 |
int size; /* IN: Numberof bytes to write */ |
| 334 |
{ |
| 335 |
long block; |
| 336 |
|
| 337 |
oserror = 0, chan = fd; |
| 338 |
block = sno*(ssize/SECTOR_SIZE); |
| 339 |
|
| 340 |
return (io2(IO$_WRITELBLK, buffer, size, block)); |
| 341 |
} |
| 342 |
|
| 343 |
/*===================================================================== |
| 344 |
* Definition of the structure returned to osu |
| 345 |
*=====================================================================*/ |
| 346 |
|
| 347 |
static OPITEM list_of_functions[] = { |
| 348 |
{ U_OPEN, ioopen}, /* Open (name, mode) */ |
| 349 |
{ U_CLOSE, ioclose}, |
| 350 |
{ U_INFO, ioinfo}, |
| 351 |
{ U_SREAD, iosread}, /* Sector Read (fd,sno,ssize,buf,bsize)*/ |
| 352 |
{ U_SWRITE, ioswrite}, /* Sector Write(fd,sno,ssize,buf,bsize)*/ |
| 353 |
{ U_REWIND, iorew} |
| 354 |
}; |
| 355 |
|
| 356 |
|
| 357 |
static struct iolist this_dev = { |
| 358 |
iodev2, /* Next iodev in List */ |
| 359 |
class_name, /* How it's written in DEVCAPFILE */ |
| 360 |
sizeof(list_of_functions)/sizeof(list_of_functions[0]), |
| 361 |
list_of_functions |
| 362 |
}; |
| 363 |
|
| 364 |
struct iolist *iodev1() |
| 365 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 366 |
.PURPOSE Get All definitions concerning this class of Devices |
| 367 |
.RETURNS The iolist |
| 368 |
.REMARKS |
| 369 |
------------------------------------------------------------*/ |
| 370 |
{ |
| 371 |
return(&this_dev); |
| 372 |
} |