Debian Codegraph @

libsrc/os/unix/osu.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2012 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 .TYPE Module
30 .NAME osu
31 .LANGUAGE C
32 .AUTHOR Francois Ochsenbein [ESO]
33 .CATEGORY Interface to i/o on devices like tapes / OD / etc
34 .ENVIRONMENT VAX / VMS or Unix
35 .COMMENTS
36 The functions of this module perform basic i/o to/from magnetic tape
37 and optical disks
38 on VAX/VMS environment. The maximum number of available special
39 units is assumed to be MAXDEV (defined here)
40 \begin{TeX}
41 \\
42 {\bf Some Troubleshooting}: With TD interface, the error
43 ``Invalid Buffer Length"
44 arises when the read/write buffer is not aligned at a 4-byte
45 address...
46
47 {\bf Restrictions}: read/write on (optical) disks is limited to
48 multiple of sectors.
49
50 A file, called DEVCAPFILE, is used to describe the various parameters of the
51 device(s). Each device is described in this file,
52 as {\tt node\_name{\bf!}device\_name} where {\tt device\_name}
53 is the {\em physical} name of the device.
54 Properties are described as {\tt pp}$=${value}, where {\tt pp} is
55 a 2-letter code specifying the item.
56 The most important items in this file are:
57 \begin{itemize}
58 \item {\tt bs}$=$ blocksize (in bytes)
59 \item {\tt ss}$=$ sector size (in bytes)
60 \item {\tt us}$=$ Unit size in sectors
61 \item {\tt ds}$=$ density (concerns tapes only)
62 \item {\tt dc}$=$ Reference to another device in the DEVCAPFILE
63 \item {\tt cl}$=$ Device Class Name. This Name specifies the iodev class
64 which must be used to access the lower-level io functions.
65 \item {\tt bw}$=$ 0 if Backwards Movements are NOT available.
66
67 \end{itemize}
68
69 \end{TeX}
70 .VERSION 1.0 10-Mar-1986: Creation
71 .VERSION 1.1 21-Mar-1986 : Modified io1 and io2 for direct-access
72 devices.
73 .VERSION 1.2 17-Dec-1986: New FCB definition
74 .VERSION 1.3 21-May-1987: Suppress warning message
75 .VERSION 2.0 24-Feb-1988: Integrated as osu routines.
76 Tested on Gigadisk, Maxtor
77 .VERSION 3.0 03-Agu-1988: Implementation in mVAX-Ultrix. C Guirao.
78 .VERSION 3.1 28-Nov-1988: Implementation in VAX/VMS. C Guirao.
79 .VERSION 3.2 28-Nov-1988: Using MAXIO1 record. C Guirao.
80 .VERSION 3.3 05-May-1989: Forcing "tmove()" reading to check double
81 file mark. Translating WRITE in READ_WRITE in open mode,
82 and checking the proper mode in osuread. C Guirao.
83 .VERSION 3.4 18-Jul-1989: Devices are described in a file named $DEVCAPFILE
84 Added osubsize to get blocksize
85 .VERSION 4.0 891012: Use of external functions.
86 .VERSION 4.1 891027: Be sure that DEVCAPFILE exists.
87 Added tm (number of tm for End of Tape)
88 .VERSION 5.0 910919: When an error writing, the keep osermsg and oserror
89 .VERSION 6.0 920217: Separator between hostname & devicename also ':'
90 .VERSION 7.0 920625: Allowing multi-skip operations tmove() & bmove().CG
91 .VERSION 7.1 920821: osuopen and block_no == 0, we are after a FM. CG.
92
93 120420 last modif
94 -----------------------------------------------------------------------------*/
95
96 #define NO_TAPE_REMOTE
97 #ifdef NO_TAPE_REMOTE /* IODEV0: First "iodevg" in the list */
98 #define IODEV0 iodevg
99 #else
100 #define IODEV0 iodevr
101 #endif
102
103 #define MAXDEV 4 /* Maximal number of opened devices */
104
105 #include <osdefos.h> /* Keywords definitions */
106 #include <osudef.h> /* Internal to osu / iodev */
107 #include <osnull.h> /* Contains NULL_DEV definition */
108 #include <devstat.h> /* Contains devstat structure */
109 #include <filedef.h> /* Contains READ, WRITE, etc... */
110 #include <stdlib.h> /* Function definitions */
111 #include <errno.h> /* System error definitions */
112 #include <oserror.h> /* Midas error definitions */
113 #include <atype.h>
114 #include <proto_os.h> /* ANSI-C prototyping */
115
116 typedef int (*FCT)();
117
118 #define MAX(x,y) ((x) >= (y) ? (x):(y) ) /* Maximum */
119 #define MIN(x,y) ((x) <= (y) ? (x):(y) ) /* Minimum */
120 #define NULL_PTR(x) (x *)0
121
122 #define BUFTEST 30*1024 /* The size of a test buffer */
123 #define DEFAULT_DENSITY 1600 /* Density by default */
124 #define DEFAULT_SECTORSIZE 512 /* Size of one disk sector */
125 #define START_DEV 100 /* First Number */
126
127 /* Definition of Functions */
128
129 #define ioinfo(f,b,fn,bn) (*fcb->ops[U_INFO])(f,b,fn,bn)
130 #define ioopen(f,m,d) (*fcb->ops[U_OPEN])(f,m,d)
131 #define ioclose(f,o) (*fcb->ops[U_CLOSE])(f,o)
132 #define ioread(f,b,l) (*fcb->ops[U_READ])(f,b,l)
133 #define iowrite(f,b,l) (*fcb->ops[U_WRITE])(f,b,l)
134 #define iorew(f) (*fcb->ops[U_REWIND])(f)
135 #define ioeom(f) (*fcb->ops[U_EOM])(f)
136 #define ioweof(f) (*fcb->ops[U_WEOF])(f,1)
137 #define iofsf(f,n) (*fcb->ops[U_FMF])(f,n)
138 #define iobsf(f,n) (*fcb->ops[U_FMB])(f,n)
139 #define iofsr(f,n) (*fcb->ops[U_BMF])(f,n)
140 #define iobsr(f,n) (*fcb->ops[U_BMB])(f,n)
141 #define iosread(f,s,ss,b,l) (*fcb->ops[U_SREAD])(f,s,ss,b,l)
142 #define ioswrite(f,s,ss,b,l) (*fcb->ops[U_SWRITE])(f,s,ss,b,l)
143
144
145 /* This structure, created for each device, allows to know
146 the current position on any device
147 */
148 typedef int (*FCT_PTR)(); /* Pointer to function */
149
150 typedef struct { /* File Control Block */
151 char *name; /* PHYSICAL Device Name */
152 char *klass; /* Device Class Name */
153 unsigned char access; /* Access mode 0/1/2/3 */
154 #define FCB_AM 16 /* Append Mode available */
155 #define FCB_BW 32 /* Backwards available */
156 #define FCB_DA 64 /* Direct Access (Seek) */
157 #define FCB_TM 128 /* Tape Mode (erase's end) */
158 unsigned char status; /* status flags */
159 #define FCB_EOM 16 /* Tape in EOM */
160 #define FCB_NOCOUNT 32 /* Unknown block number */
161 /*#define FCB_NOFEET 64*/ /* Unknown feet count */
162 unsigned char last_op; /* Last operation performed */
163 int eotm; /* Number of TM to write at end */
164 /* long feet;*/ /* used tape length in feet/1000*/
165 long usize; /* bytes of file / total blocks */
166 long block_no; /* block position within file */
167 int tape_marks; /* Number of CONSECUTIVE TM */
168 int block_max; /* Maximum blocksize (tape) */
169 int block_min; /* Minimum blocksize (tape) */
170 int blocksize; /* Size of one block */
171 int sectorsize; /* Size of one sector */
172 int density; /* Density (Tapes), sector size */
173 int file_no; /* number of file (for MT) */
174 FCT_PTR ops[U_MAX+1]; /* Available Operations */
175 /* --- System-dependant Part----*/
176 int pfd; /* Tape file descriptor in UNIX */
177 } FCB;
178
179 #define tgap (fcb->density == 6250? (1500/12) : (3000/12)) \
180 /* Gap on tape due to the Tape-Mark */
181
182 #define BADCLASSmsg "Class of Device unknown:"
183 static FCB *Units[MAXDEV] = {0,0,0,0};
184 static FCB *fcb;
185 static int ncb = START_DEV; /* Number of opened units */
186 static char hasbw; /* 1 if Backward available */
187 static char hasam; /* 1 if Append Mode available */
188 static struct {
189 char msg[sizeof(BADCLASSmsg)];
190 char klass[20];
191 } theclass = { BADCLASSmsg, "generic" };
192 static struct osustat stbuf;
193 static int findclass_loop = 0;
194 static char *test_buffer;
195
196 #define MAX_findclass 50 /* Recursivity limit to find a device class */
197
198 long osufseek();
199
200 /*=====================================================================
201 Internal Routines
202 *=====================================================================*/
203
204 static int osuerror(op)
205 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
206 .PURPOSE Set Error Message
207 .RETURNS -1
208 ----------------------------------------------------------------------*/
209 int op; /* IN: The operation to execute */
210 {
211 static char msg[60] = "Function not available: ";
212 register char *pm, *pl;
213 static char *text[] = {
214 /* U_INFO */ "info",
215 /* U_OPEN */ "open",
216 /* U_CLOSE */ "close",
217 /* U_READ */ "read",
218 /* U_WRITE */ "write",
219 /* U_REWIND*/ "rewind",
220 /* U_SREAD */ "sector_read",
221 /* U_SWRITE*/ "sector_write",
222 /* U_WEOF */ "write_EOF",
223 /* U_FMF */ "file_move_forward",
224 /* U_FMB */ "file_move_backwards",
225 /* U_BMF */ "block_move_forward",
226 /* U_BMB */ "block_move_backwards",
227 /* U_EOM */ "to_EOMedia"
228 };
229
230 oserror = -1;
231 oserrmsg = msg;
232 pm = &msg[24];
233
234 /* Append the signification of the function */
235 for(pl = text[op]; *pl; pl++) *(pm++) = *pl;
236 *pm = '\0';
237
238 return(-1);
239 }
240 /* Declare here the various error functions */
241 static int err0() { return(osuerror(0));}
242 static int err1() { return(osuerror(1));}
243 static int err2() { return(osuerror(2));}
244 static int err3() { return(osuerror(3));}
245 static int err4() { return(osuerror(4));}
246 static int err5() { return(osuerror(5));}
247 static int err6() { return(osuerror(6));}
248 static int err7() { return(osuerror(7));}
249 static int err8() { return(osuerror(8));}
250 static int err9() { return(osuerror(9));}
251 static int err10() { return(osuerror(10));}
252 static int err11() { return(osuerror(11));}
253 static int err12() { return(osuerror(12));}
254 static int err13() { return(osuerror(13));}
255
256 static FCT err_fct[1+U_MAX] = {
257 err0, err1, err2, err3, err4, err5, err6, err7, err8, err9,
258 err10, err11, err12, err13};
259
260 static int uget(f)
261 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
262 .PURPOSE Retrieve the FCB structure
263 .RETURNS 0 (success) / -1 (failure)
264 .REMARKS
265 ----------------------------------------------------------------------*/
266 int f; /* IN: Unit number */
267 {
268
269 oserrmsg = NULL_PTR(char);
270 oserror = 0;
271 fcb = NULL_PTR(FCB);
272
273 if ((f >= START_DEV) && (f <= ncb))
274 fcb = Units[f-START_DEV];
275
276 if (fcb == NULL_PTR(FCB)) {
277 oserror = -1;
278 oserrmsg = "Bad Unit Number";
279 }
280
281 return(oserror);
282 }
283
284 static int newfile()
285 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
286 .PURPOSE Update fcb information when a new file starts
287 .RETURNS 0
288 .REMARKS For disks, should be called only at open...
289 ----------------------------------------------------------------------*/
290 {
291 fcb->status &= ~(FCB_NOCOUNT); /* count number is correct */
292
293 if (fcb->file_no < 0) { /* Beginning of Tape */
294 fcb->file_no = 0; /* First File */
295 }
296 /* Increment the file counter */
297 else fcb->file_no += fcb->tape_marks;
298
299 fcb->tape_marks= 0; /* No tape-mark encountered */
300 fcb->block_no = 0; /* block position within file */
301 fcb->block_max = 0; /* Maximum blocksize */
302 fcb->block_min = 0; /* Minimum blocksize */
303 fcb->status &= ~FCB_EOM;
304
305 return(0);
306 }
307
308 static int newpos(bytes)
309 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
310 .PURPOSE Computes the new position on the device
311 .RETURNS 0
312 .REMARKS
313 ----------------------------------------------------------------------*/
314 int bytes; /* IN: number of bytes read/ written */
315 {
316 if (fcb->tape_marks) newfile();
317
318 if (fcb->access & FCB_DA) /* Direct Access */
319 { fcb->block_no += (bytes/fcb->sectorsize);
320 if (bytes%fcb->sectorsize) fcb->block_no += 1;
321 }
322 else if (fcb->access & FCB_TM) (fcb->block_no)++;
323
324
325 fcb->block_max = MAX(fcb->block_max, bytes);
326 fcb->block_min = MIN(fcb->block_min, bytes);
327 if (fcb->block_min <= 0) fcb->block_min = bytes;
328
329 fcb->status &= ~FCB_EOM;
330 return(0);
331 }
332
333 static int rewind_dev ()
334 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
335 .PURPOSE Rewind the tape
336 .RETURNS 0 (success) / -1 (failure)
337 .REMARKS fcb updated.
338 ----------------------------------------------------------------------*/
339 {
340 iorew(fcb->pfd);
341 if (oserror) return(-1);
342
343 fcb->last_op = U_REWIND;
344 fcb->file_no = -1;
345 newfile();
346 return(0);
347 }
348
349 static int tfclose()
350 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
351 .PURPOSE Write EOF (Single TM)
352 .RETURNS 0 (success) / -1 (failure)
353 .REMARKS
354 ----------------------------------------------------------------------*/
355 {
356 ioweof(fcb->pfd);
357 if (oserror == 0) {
358 (fcb->tape_marks)++;
359 fcb->last_op = U_WEOF;
360 fcb->status |= FCB_EOM;
361 }
362
363 return(oserror ? -1 : 0);
364 }
365
366 static int bmove(num)
367 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
368 .PURPOSE Move Backwards num TM.
369 .RETURNS 0 (success) / -1 (failure)
370 .REMARKS After move, the tape is positionned just before a tape-mark.
371 ----------------------------------------------------------------------*/
372 int num; /* IN: Number of TM to move backward */
373 {
374 if (fcb->tape_marks < num ) {
375 fcb->file_no -= (num - fcb->tape_marks);
376 fcb->tape_marks = 0;
377 fcb->status |= (FCB_NOCOUNT);
378 }
379 else fcb->tape_marks -= num;
380
381 if (fcb->file_no < 0)
382 rewind_dev();
383 else
384 iobsf(fcb->pfd,num), fcb->last_op = U_FMB;
385
386 fcb->status &= ~FCB_EOM;
387 return(oserror ? -1 : 0);
388 }
389
390 static int tmove(num)
391 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
392 .PURPOSE Move Forwards num TM.
393 .RETURNS 0 (success) / -1 (failure)
394 .REMARKS After move, the tape is positionned after a tape-mark.
395 ----------------------------------------------------------------------*/
396 int num; /* IN: Number of TM to move forward */
397 {
398 register int l, lbuf;
399 int w_error; char *w_msg;
400
401 oserror = 0;
402 if (num <= 0 || fcb->status & FCB_EOM) return(0);
403 /* If a TM was previously detected, ensure a physical */
404 /* reading to force the move */
405 if (fcb->tape_marks) {
406 lbuf = BUFTEST - (BUFTEST % fcb->blocksize);
407 l = ioread(fcb->pfd, test_buffer, lbuf);
408 oserror = 0;
409 fcb->last_op = U_FMF;
410 if (l == -1 || l == 0) { /* Generally End Of Media */
411 if (fcb->eotm > 1) {
412 (fcb->tape_marks)++;
413 bmove(1);
414 }
415 fcb->status |= FCB_EOM;
416 return(0);
417 }
418 newfile(); /* Tape_marks reset to zero */
419 }
420
421 if (iofsf(fcb->pfd, num) == -1) {
422 w_error= oserror; w_msg = oserrmsg;
423 rewind_dev();
424 oserror = w_error; oserrmsg = w_msg;
425 return(-1);
426 }
427 fcb->file_no += (num - 1);
428 fcb->last_op = U_FMF;
429 fcb->status |= (FCB_NOCOUNT);
430 fcb->tape_marks = 1;
431 return(0);
432 }
433
434 static struct iolist *findclass(aclass)
435 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
436 .PURPOSE Retrieve the class name
437 .RETURNS Pointer to found class / NULL
438 .REMARKS
439 ----------------------------------------------------------------------*/
440 char *aclass; /* IN: Class to look for */
441 {
442 struct iolist *plist, *IODEV0();
443 struct iolist *(*def)();
444 char *p, *q;
445
446 /* Follow the linked list of iolist's */
447
448 if (++findclass_loop > MAX_findclass)
449 return (NULL_PTR(struct iolist));
450
451 plist = (*IODEV0)();
452 for (def = IODEV0; def; def = plist->next)
453 {
454 plist = (*def)();
455 for(q=aclass, p=plist->klass; (*p == *q) && (*p); p++, q++) ;
456 if ((*q == '\0') && (*p == '\0')) break;
457 }
458 if (!def) /* Class Not Found */
459 plist = NULL_PTR(struct iolist);
460
461 return(plist);
462 }
463
464 static int getclass()
465 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
466 .PURPOSE Retrieve the class name, to retrieve operators.
467 .RETURNS 0 / -1 (class doesn't exist)
468 .REMARKS Functions added in FCB
469 ----------------------------------------------------------------------*/
470 {
471 struct iolist *plist;
472 int i;
473 OPITEM *pop;
474
475 findclass_loop = 0;
476
477 plist = findclass(theclass.klass);
478 if (!plist) {
479 oserror = -1, oserrmsg = (char *)&theclass;
480 theclass.msg[sizeof(theclass.msg)-1] = ' ';
481 return(-1);
482 }
483
484 fcb->klass = plist->klass;
485
486 /*
487 ** We have just to insert the functions in the list
488 */
489
490 for (pop = plist->oplist, i = plist->nop; --i >= 0; pop++)
491 fcb->ops[pop->opid] = pop->opf;
492
493 return(0);
494 }
495
496 static int scandev(fd, dev)
497 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
498 .PURPOSE Get Capabilities in opened DEVCAPFILE
499 .RETURNS 0 / -1
500 .REMARKS Recursive call if `dc=' is found.
501 ----------------------------------------------------------------------*/
502 int fd; /* IN: DEVCAPFILE file descriptor */
503 char *dev; /* IN: Device name */
504 {
505 int i;
506 char buf[133]; /* One line of DEVCAPFILE */
507 char *p, *q;
508
509 /* Be sure dev is terminated with Null */
510
511 for (p = dev; isgraph(*p); p++) ;
512 *p = '\0';
513
514 osaseek(fd, 0L, FILE_START);
515 while (osaread(fd, buf, sizeof(buf)) >= 0)
516 {
517 if (buf[0] == '#') continue;
518 for (p = buf, q = dev; *q && (*p == *q); p++, q++) ;
519 if (*q == '\0' && (*p == ' ' || *p == '\t')) goto found_dev;
520 }
521 return(-1);
522
523
524 found_dev:
525 /* Here when device is found. Get interesting items, i.e.
526 * bs= blocksize
527 * us= unit size
528 * ss= sector size
529 * ds= density
530 * cl= class_name
531 * dc= Synonym
532 */
533 while(*p)
534 {
535 while (isspace(*p)) p++; /* Skip blanks */
536 if(!*p) continue; /* Empty line */
537
538 if (*p == '\\') /* There is a continuation. Read Next record */
539 {
540 next_record:
541 if (osaread(fd, buf, sizeof(buf)) < 0) buf[0] = '\0';
542 if (buf[0] == '#') /* It's a comment */
543 goto next_record;
544 p = buf;
545 if (isspace(buf[0])) continue;
546 goto terminated;
547 }
548 if (oscomp(p, "dc=", 3) == 0) /* Fetch another name */
549 return(scandev(fd, p+3));
550 if (oscomp(p, "bs=", 3) == 0) /* Blocksize */
551 { if (!fcb->blocksize) fcb->blocksize = atoi(p+3); }
552 else if (oscomp(p, "us=", 3) == 0) /* Unit Size */
553 { if (!fcb->usize) fcb->usize = atoi(p+3); }
554 else if (oscomp(p, "ss=", 3) == 0) /* Sector Size */
555 { if (!fcb->sectorsize) fcb->sectorsize = atoi(p+3); }
556 else if (oscomp(p, "ds=", 3) == 0) /* Density */
557 { if (!fcb->density) fcb->density = atoi(p+3); }
558 else if (oscomp(p, "tm=", 3) == 0) /* Number of tm */
559 { if (!fcb->eotm) fcb->eotm = atoi(p+3); }
560 else if (oscomp(p, "am=", 3) == 0) /* BackWard */
561 { if (hasam == 2) hasam = atoi(p+3); }
562 else if (oscomp(p, "bw=", 3) == 0) /* BackWard */
563 { if (hasbw == 2) hasbw = atoi(p+3); }
564 else if (oscomp(p, "cl=", 3) == 0) /* Class */
565 { for (i=0, p+=3; (i<sizeof(theclass.klass)-1)
566 &&(isgraph(*p)); i++, p++) theclass.klass[i] = *p;
567 theclass.klass[i] = '\0';
568 }
569 while (isgraph(*p)) p++; /* Look for space */
570 }
571
572 terminated:
573 return(0);
574 }
575
576
577 static int getdev(dev)
578 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
579 .PURPOSE Get Capabilities from DEVCAPFILE.
580 .RETURNS 0 / -1
581 .REMARKS Relevant Cap's are used to update the current fcb
582 ----------------------------------------------------------------------*/
583 char *dev; /* IN: Device name */
584 {
585 char *devcapfile; /* DEVCAPFILE name */
586 int fd;
587 char *oshenv();
588
589 /* Check if a DEVCAPFILE does exist */
590
591 devcapfile = oshenv("DEVCAPFILE", NULL_PTR(char));
592 if(!devcapfile){
593 oserror = -1; oserrmsg = "DEVCAPFILE is unknown...";
594 return(-1);
595 }
596
597 /* It does. Open in read_only mode */
598
599 fd = osaopen(devcapfile, READ);
600 if (fd < 0){
601 oserror = -1; oserrmsg = "Cannot open file DEVCAPFILE";
602 return(-1);
603 }
604
605 /* Scan the file for the device name, expand dc= references */
606
607 if (scandev(fd, dev) < 0) {
608 oserror = -1; oserrmsg = "Entry unknown in DEVCAPFILE";
609 return(-1);
610 }
611
612 /* Finally Close DEVCAPFILE */
613
614 osaclose(fd);
615 return(0);
616 }
617
618 /*=====================================================================
619 Callable Routines
620 *=====================================================================*/
621
622 int osugrep (class_name, item)
623 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
624 .PURPOSE Get the item function in a class of devices
625 .RETURNS 0 / -1
626 ----------------------------------------------------------------------*/
627 char *class_name; /* IN: Class of Devices (NULL for any) */
628 OPITEM *item; /* OUT: op_code + Function Pointer */
629 {
630 struct iolist *plist, *IODEV0();
631 struct iolist *(*def)();
632 int i;
633 OPITEM *pop;
634
635
636 plist = (*IODEV0)();
637 for (def = IODEV0; def; def = plist->next)
638 {
639 if (!class_name) /* Class not specified: look to next one */
640 plist = (*def)();
641 else plist = findclass(class_name);
642 if (!plist) return(-1);
643
644 /* Retrieve the item in list */
645
646 for (pop = plist->oplist, i = plist->nop;
647 (--i >= 0) && (pop->opid != item->opid); pop++) ;
648
649 if (i >= 0) /* I found the relevant item... */
650 { item->opf = pop->opf;
651 return(0);
652 }
653 if (class_name) break;
654
655 }
656 return(-1);
657 }
658
659 char *osuname(f)
660 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
661 .PURPOSE Retrieve name of an opened unit (current when f = -1)
662 .RETURNS Name / NULL pointer if failed
663 ----------------------------------------------------------------------*/
664 int f; /* IN: The unit number */
665 {
666 if (f != -1)
667 if (uget(f))
668 return((char *)0); /* Bad unit number... */
669
670 return(fcb ? fcb->name : NULL_PTR(char));
671 }
672
673 int osumode(f)
674 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
675 .PURPOSE Retrieve opening mode
676 .RETURNS Mode / -1 when error
677 ----------------------------------------------------------------------*/
678 int f; /* IN: The unit number */
679 {
680 if (f != -1)
681 if (uget(f))
682 return(-1); /* Bad unit number... */
683
684 return(fcb ? fcb->access & 3 : -1);
685 }
686
687 int osubsize(f)
688 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
689 .PURPOSE Get the block size of the unit.
690 .RETURNS The size of blocks for block devices (1 for tapes)
691 ----------------------------------------------------------------------*/
692 int f; /* IN: The unit number */
693 {
694 if (f != -1)
695 if (uget(f))
696 return(-1); /* Bad unit number... */
697
698 return(fcb ? fcb->blocksize : -1);
699 }
700
701 int osustatus(f, stat)
702 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
703 .PURPOSE Get the status of the device
704 .RETURNS 0 / -1
705 ----------------------------------------------------------------------*/
706 int f; /* IN: The unit number */
707 struct devstat *stat; /* OUT: Filled with known info */
708 {
709 if (uget(f))
710 return(-1); /* Bad unit number... */
711
712 stat->name = fcb->name;
713 stat->klass = fcb->klass;
714 stat->density = fcb->density;
715 stat->sectorsize = fcb->sectorsize;
716 stat->usize = fcb->usize;
717 stat->blocksize = fcb->blocksize;
718 stat->file_no = fcb->file_no;
719 stat->block_no = fcb->block_no;
720 stat->block_max = fcb->block_max;
721 stat->block_min = fcb->block_min;
722 stat->tape_marks = fcb->tape_marks;
723
724 return(0);
725 }
726
727 int osuopen (device, mode, den)
728 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
729 .PURPOSE Assign (mount) a tape with a specified density
730 .RETURNS The device number / -1 on error
731 .REMARKS The default device class is "generic".
732 The mount is performed here.
733 If density is not specified or is zero, use DEFAULT_DENSITY
734 for write-only; get the density otherwise.
735 .REMARKS Open the device in APPEND mode does not work properly (it is
736 like READ mode instead). It has been implemented changing the
737 open mode to READ_WRITE and positioning the tape between the last
738 two file marks.
739 ----------------------------------------------------------------------*/
740 char *device; /* IN: The unit name, blank or NULL for null device */
741 int mode; /* IN: open mode: READ, WRITE, READ_WRITE, APPEND */
742 int den; /* IN: The density or sector size; 0 if default */
743 {
744 register int l, i, no_host;
745 register char *p, *q;
746 char *devname, isnulldev;
747 static char devhost[64], localhost[64];
748 static char host_dev[128];
749
750 /* Convert NULL device name if necessary */
751 devname = device;
752 if (!devname) devname = "";
753 isnulldev = !*devname; /* Is zero for NULL device */
754 if (isnulldev) devname = NULL_DEV;
755
756 oserror = 0;
757 oserrmsg = NULL_PTR(char);
758 fcb = NULL_PTR(FCB);
759 hasam = 2; /* Unknown Parameter */
760 hasbw = 2; /* Unknown Parameter */
761
762
763 /* Check if there are not too many devices */
764
765 for (i = 0; i < MAXDEV; i++)
766 if (!Units[i]) break;
767
768 if (i >= MAXDEV) {
769 oserror = -1;
770 oserrmsg = "Too many opened osu Units" ;
771 return(-1);
772 }
773
774 /* Allocate FCB, and Try to guess the device class from name:
775 if device name contains a D, assume "disk" class
776 */
777
778 l = strlen(devname);
779 fcb = (FCB *)osmmget(sizeof(FCB) + l + 2);
780 /* Note: 2 for EOS and ':' */
781 if (!fcb)
782 return(-1);
783
784 if (isnulldev) p = "dumb";
785 else { /* Look for a `d' for Disk, eitherwise Tape */
786 q = devname + oscbloc(devname, l, '/') + 1;
787 l -= (q - devname); /* Keep filename */
788 if ((oscbloc(q, l, 'd') >= 0 ) || (oscbloc(q, l, 'D') >= 0))
789 p = "disk";
790 else p = "generic";
791 }
792 oscopy(theclass.klass, p, 1+strlen(p));
793
794 /* Initialize the structure, and copy device name */
795
796 fcb->name = (char *)(fcb+1);
797 fcb->access = mode;
798 fcb->status = 0;
799 fcb->eotm = 0;
800 fcb->usize = 0;
801 fcb->tape_marks = 0;
802 fcb->block_max = 0; /* Maximum blocksize */
803 fcb->block_min = 0; /* Minimum blocksize */
804 fcb->blocksize = 0;
805 fcb->sectorsize = 0;
806 fcb->density = den;
807 fcb->file_no = -1;
808 for (l = 0; l < sizeof(fcb->ops)/sizeof(fcb->ops[0]); l++)
809 fcb->ops[l] = err_fct[l];
810
811 no_host=0;
812 for (q = devhost, p = devname; (*p) && (*p != '!') && (*p != ':'); p++, q++) *q= *p;
813 if (*p == '!' || *p == ':' ) p++;
814 else { p = devname; no_host=1; }
815 for (q = fcb->name; *p; p++, q++) *q = *p;
816 *q = '\0';
817
818 gethostname(localhost,64);
819
820 /*
821 * Fill fcb with Info from DEVCAPFILE
822 * Copy device name to fcp->name , but strip hostname info.
823 * If hostname not indicated and not found, then add localhost and
824 * try again.
825 */
826 if (no_host) {
827 if ( getdev(devname) < 0 ) {
828 for (q = host_dev, p = localhost; (*p); p++, q++) *q= *p;
829 *q = ':';
830 for (q++, p = devname; (*p); p++, q++) *q= *p;
831 *q = '\0';
832 /* In OSF/1 and Solaris the DAT device behaves like a 2 tm's for End of Tape */
833 #if !defined(__osf__) && !defined(__SVR4) && !defined(__svr4__)
834 if ( getdev(host_dev) < 0 ) fcb->eotm = 1;
835 #else
836 getdev(host_dev);
837 #endif
838 }
839 }
840 else
841 #if !defined(__osf__) && !defined(__SVR4)
842 if ( getdev(devname) < 0 ) fcb->eotm = 1;
843 #else
844 getdev(devname);
845 #endif
846
847 /* Check if it is a remote host, so class="remote" */
848 if ( !no_host && osccomp(localhost,devhost,strlen(localhost)) ) {
849 p = "remote";
850 oscopy(theclass.klass, p, 1+strlen(p));
851 oscopy(fcb->name, devname, 1+strlen(devname));
852 }
853
854 if (fcb->eotm == 0) /* Default = 2 TM */
855 fcb->eotm = 2;
856 if (hasam == 2)
857 hasam = (fcb->eotm < 2);
858 if (fcb->density <= 0)
859 fcb->density = DEFAULT_DENSITY;
860 if (fcb->blocksize <= 0)
861 fcb->blocksize = 1; /* Tapes have this blocksize... */
862
863 /* Find to which Class the Device belongs to. */
864
865 if (getclass() < 0) goto error_found;
866
867 /* Open the device. DON'T REWIND ! */
868
869 fcb->pfd = ioopen(fcb->name,
870 ((mode == WRITE) ? READ_WRITE : mode),
871 fcb->density);
872 if (oserror) goto error_found;
873
874 Units[i] = fcb;
875 i += START_DEV; /* Actual returned unit number */
876 if (i >= ncb) ncb = i;
877 fcb->last_op = U_OPEN; /* Last Operation */
878
879 /* Get Other Info about Device */
880 /* If ioinfo does not work drop eom jumps */
881 ioinfo(fcb->pfd, &stbuf, &fcb->file_no, &fcb->block_no);
882 if (fcb->file_no == -1) hasam=0;
883 /* If 2 FM drop the FCB_AM. It does not work properly */
884 /*if (fcb->eotm > 1) hasam=0;*/
885 if (isnulldev) oserror = 0; /* This can't be a problem */
886
887 /* Fill the missing items with final info */
888
889 if (fcb->ops[U_EOM] == osuerror) hasam = 0;
890 if (stbuf.density) fcb->density = stbuf.density;
891 if (hasbw) fcb->access |= FCB_BW;
892 if (hasam) fcb->access |= FCB_AM;
893
894 /* Take defaults for DA devices */
895 if (stbuf.isda)
896 { fcb->access |= FCB_DA;
897 if (stbuf.blocksize == 0)
898 stbuf.blocksize = DEFAULT_SECTORSIZE;
899 if (fcb->sectorsize == 0)
900 fcb->sectorsize = den;
901 if (fcb->sectorsize < stbuf.blocksize)
902 fcb->sectorsize = stbuf.blocksize;
903 if (fcb->usize == 0) fcb->usize =
904 stbuf.usize/(fcb->sectorsize/stbuf.blocksize);
905 if (fcb->usize == 0) fcb->usize = 0x7fffffff/fcb->sectorsize;
906 if (fcb->blocksize <= 1)
907 fcb->blocksize = fcb->sectorsize;
908 }
909 if (fcb->usize == 0) fcb->usize = stbuf.usize;
910 if (stbuf.istm) fcb->access |= FCB_TM;
911
912 /*
913 * If the system doesn't know the position, rewind anyway.
914 */
915 if (fcb->file_no < 0) {
916 iorew(fcb->pfd);
917 newfile();
918 }
919
920 /*
921 * Allocate test buffer
922 */
923 if (!(test_buffer=(char *)osmmget(BUFTEST))) return(-1);
924
925 /* block_no == 0, we are at the beggining of a file */
926 if (fcb->block_no == 0) {
927 fcb->file_no -= 1;
928 fcb->tape_marks = 1;
929 }
930 /*
931 * Check position. To be sure we are not between 2 TM
932 * or End_Of_Media, jump backwards 2 TM if possible.
933 if (fcb->file_no > 0 && fcb->access & FCB_BW) bmove(2);
934 */
935 oserror=0;
936
937 /* Position to EOF if Append */
938
939 fcb->last_op = U_OPEN; /* Last Operation */
940 if ((mode&3) == APPEND) osufseek(i, 0, FILE_END);
941
942 if (oserror) {
943 Units[i-START_DEV] = NULL_PTR(FCB);
944 goto error_found;
945 }
946 return(i);
947
948 error_found:
949 osmmfree((char *)fcb);
950 osmmfree(test_buffer);
951 return(-1);
952 }
953
954 int osuclose (f, option)
955 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
956 .PURPOSE Close (dismount) a tape / optical disk
957 .RETURNS 0 / -1
958 .REMARKS Tape is not rewinded...
959 ----------------------------------------------------------------------*/
960 int f; /* IN: The unit to dismount */
961 int option; /* IN: option 1 to dismount the device (e.g. spin-down) */
962 {
963 if (uget(f))
964 return(-1); /* Bad unit number... */
965
966 /* Perform necessary checks. Write tape marks if previous operation
967 ** was write or fclose.
968 */
969
970 if (fcb->access & FCB_DA) ;
971 else {
972 if (fcb->last_op == U_WRITE) tfclose();
973 if (fcb->last_op == U_WEOF)
974 while (fcb->tape_marks < fcb->eotm) tfclose();
975 }
976
977 if(oserror) return(-1);
978
979 if (ioclose(fcb->pfd, (option == 1 ? OPU_DISMOUNT : 0)))
980 return(-1);
981
982 osmmfree((char *)fcb);
983 osmmfree(test_buffer);
984 Units[f-START_DEV] = NULL_PTR(FCB);
985
986 return(0);
987 }
988
989 int osuread (f, buffer, length)
990 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
991 .PURPOSE Read a block from magnetic tape / optical disk.
992 .RETURNS Bytes read (>length if buffer too small) / 0 for EOF / -1 for
993 error; omsg provides an explanation.
994 .REMARKS The length MUST be a multiple of a sector size for
995 optical disks.
996 The returned length may be zero for virgin sectors.
997 .REMARKS Reading consecutive file marks, it is posible to go further
998 than two file marks.
999 ----------------------------------------------------------------------*/
1000 int f; /* IN: The file control block */
1001 char *buffer; /* OUT: The buffer */
1002 int length; /* IN: The length of the buffer */
1003 {
1004 register int l;
1005
1006 /* Check Buffer Length */
1007 if (length < sizeof(long)) {
1008 oserror = -1;
1009 oserrmsg = "Too small buffer";
1010 }
1011
1012 if (uget(f)) /* Bad unit number... */
1013 return(-1);
1014
1015 /*
1016 ** If device was opened in only_write mode, return error
1017 ** if trying to read something
1018 */
1019
1020 if ((fcb->access & 3) == WRITE) {
1021 oserror=EACCES;
1022 return(-1);
1023 }
1024 /*
1025 ** Check if some required blocksize MUST be used.
1026 */
1027
1028 if (length%fcb->blocksize)
1029 { oserror = -1, oserrmsg = "Length not a multiple of Blocksize";
1030 return(-1);
1031 }
1032
1033 /*
1034 ** For Tapes, check for illegal read
1035 */
1036
1037 if (fcb->access & FCB_TM)
1038 { if ((fcb->last_op == U_WRITE) || (fcb->last_op == U_WEOF))
1039 { oserror = -1;
1040 oserrmsg = "Can't read after write";
1041 return(-1);
1042 }
1043 }
1044
1045 /*
1046 ** For Direct-Access devices, use iosread (0 means "virgin sector")
1047 ** For Tapes, use ioread (0 means "tape-mark" )
1048 */
1049 if (fcb->access & FCB_DA)
1050 l = iosread(fcb->pfd, fcb->block_no, fcb->sectorsize,
1051 buffer, length);
1052 else {
1053 l = ioread(fcb->pfd,buffer,length);
1054 if (l == 0) {
1055 if (fcb->tape_marks && fcb->eotm > 1) {
1056 (fcb->tape_marks)++;
1057 bmove(1);
1058 fcb->status |= FCB_EOM;
1059 oserror = -1;
1060 oserrmsg = "End Of Data.";
1061 return(-1);
1062 }
1063 else (fcb->tape_marks)++;
1064 }
1065 }
1066
1067 /* Check special case oserror = -2, means TOO SHORT BUFFER */
1068 if (oserror == -2) {
1069 oserror = -1;
1070 oserrmsg = "Too short buffer";
1071 newpos(length);
1072 return(-1);
1073 }
1074 /*
1075 ** If error, but last read was a FileMark then
1076 ** set EOM flag (End Of Media) and return -1.
1077 */
1078 if (oserror) {
1079 if (fcb->tape_marks) {
1080 fcb->status |= FCB_EOM;
1081 oserror = -1;
1082 oserrmsg = "End Of Data.";
1083 }
1084 return(-1);
1085 }
1086
1087 fcb->last_op = U_READ;
1088
1089 if (l > 0) /* Something was read, update fcb contents */
1090 newpos(l);
1091
1092 return(l);
1093 }
1094
1095 int osuwrite (f, buffer, length)
1096 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1097 .PURPOSE Write a block on magnetic tape / optical disk.
1098 .RETURNS Length written / -1 (error)
1099 .REMARKS
1100 ----------------------------------------------------------------------*/
1101 int f; /* IN: The file control block */
1102 char *buffer; /* IN: The buffer */
1103 int length; /* IN: The length of the buffer */
1104 {
1105 register int l;
1106 char *w_msg;
1107 int w_error;
1108
1109 /* Check Buffer Length */
1110 if (length < sizeof(long)) {
1111 oserror = -1;
1112 oserrmsg = "Too small buffer";
1113 }
1114
1115 if (uget(f)) /* Bad unit number... */
1116 return(-1);
1117
1118 /* Check if Write is Allowed */
1119
1120 if ((fcb->access & 3) == READ) {
1121 oserror = EACCES;
1122 return(-1);
1123 }
1124
1125 /*
1126 ** Check if some required blocksize MUST be used.
1127 */
1128
1129 if (length%fcb->blocksize)
1130 { oserror = -1, oserrmsg = "Length not a multiple of Blocksize";
1131 return(-1);
1132 }
1133
1134 /*
1135 ** For Tapes, check if 2 TM were previously written;
1136 ** if yes, the data will not be accessible...
1137 */
1138 if (fcb->access & FCB_TM)
1139 { if (fcb->tape_marks >= 2) {
1140 oserror = -1, oserrmsg = "Attempt to write beyond EOF";
1141 return(-1);
1142 }
1143 }
1144
1145 /*
1146 ** For Direct-Access devices, use ioswrite .
1147 */
1148 if (fcb->access & FCB_DA)
1149 l = ioswrite(fcb->pfd, fcb->block_no, fcb->sectorsize,
1150 buffer, length);
1151 else l = iowrite(fcb->pfd,buffer,length);
1152
1153 /*
1154 ** If Error when writing, the tape is positioned at the
1155 ** beginning of the file, where it was opened.
1156 */
1157 if (l == -1) {
1158 w_error= oserror; w_msg = oserrmsg;
1159 if (fcb->access & FCB_BW) {
1160 bmove(1);
1161 tmove(1);
1162 }
1163 oserror = w_error; oserrmsg = w_msg;
1164 return(-1);
1165 }
1166
1167 if (l > 0)
1168 newpos(l);
1169 fcb->last_op = U_WRITE;
1170 return(l);
1171 }
1172
1173 int osufclose (f)
1174 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1175 .PURPOSE Close a File (Write a Tape-Mark on the tape)
1176 .RETURNS 0 / -1
1177 .REMARKS Tape mouvements are optimized.
1178 Does nothing if file opened for read-only (returns
1179 wihout error)
1180 ----------------------------------------------------------------------*/
1181 int f; /* IN: The file control block */
1182 {
1183
1184 if (uget(f)) /* Bad unit number... */
1185 return(-1);
1186
1187 /* Check if Write is Allowed */
1188
1189 if ((fcb->access & 3) == READ)
1190 return(0);
1191
1192 if (fcb->last_op == U_WRITE) return(tfclose());
1193 return(0);
1194 }
1195
1196 long osufseek (f, offset, mode)
1197 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1198 .PURPOSE File seek (Move the tape, i.e. find tape-marks).
1199 Identical to osubseek for disks.
1200 .RETURNS New file number
1201 .REMARKS On return, the tape is always positioned at a
1202 file beginning. The tape move is always stopped
1203 when two consecutive tape-marks are encountered.
1204 ----------------------------------------------------------------------*/
1205 int f; /* IN: Unit Number */
1206 long offset; /* IN : Offset for displacement */
1207 int mode; /* IN : mode of addressing */
1208 {
1209 register long fn;
1210 register int n, an, s1, s2;
1211
1212 if (uget(f)) /* Bad unit number... */
1213 return(-1);
1214
1215 /*
1216 ** Perform necessary checks. Can't move tape after write...
1217 */
1218
1219 if (fcb->access & FCB_TM)
1220 { if (fcb->last_op == U_WRITE) {
1221 oserror = -1, oserrmsg = "Can't move after write";
1222 return(-1);
1223 }
1224 }
1225
1226 n = offset;
1227 fn = 0;
1228
1229 switch(mode) {
1230 case FILE_END:
1231 if (n > 0) { oserror = ESPIPE; return(-1); }
1232
1233 if (fcb->last_op == U_WEOF) { /* I just wrote a TM */
1234 if ( (n == 0) && (fcb->tape_marks == 1)) break;
1235 while (fcb->tape_marks < fcb->eotm) tfclose();
1236 }
1237
1238 /*
1239 * Use fast EOM function if we can know where we are.
1240 * If ioeom ERROR, rewind and drops the FCB_AM flag
1241 */
1242 if ( !(fcb->status & FCB_EOM) &&
1243 (((n == 0 ) && (fcb->access & FCB_AM)) ||
1244 ((fcb->access & FCB_AM) && (fcb->access & FCB_BW))) ) {
1245 s1=ioeom(fcb->pfd);
1246 s2=ioinfo(fcb->pfd,&stbuf,&fcb->file_no,&fcb->block_no);
1247 if (s1 == -1 || s2 == -1) {
1248 oserror = 0;
1249 rewind_dev();
1250 fcb->access &= ~FCB_AM;
1251 }
1252 else {
1253 if (fcb->file_no == 0) rewind_dev();
1254 else {
1255 fcb->file_no -= 1;
1256 fcb->tape_marks = 1;
1257 fcb->block_no = 0;
1258 fcb->status |= FCB_EOM;
1259 fcb->status &= ~FCB_NOCOUNT;
1260 if (n == 0) break;
1261 }
1262 }
1263 }
1264
1265 while ( !(fcb->status & FCB_EOM) && (oserror == 0))
1266 tmove(1); /* Find EOTape */
1267
1268 if ( n == 0 ) break;
1269
1270 n += fcb->file_no + 1;
1271 /* n is now Absolute File Number where to go */
1272 case FILE_START:
1273 if (n <= 0) {
1274 if (fcb->last_op == U_WEOF) /* I just wrote a TM */
1275 while (fcb->tape_marks < fcb->eotm) tfclose();
1276 rewind_dev();
1277 break;
1278 }
1279 n -= (fcb->file_no + fcb->tape_marks); /* n is now Relative */
1280 case FILE_CURRENT:
1281 an = n + fcb->file_no + fcb->tape_marks; /* Absolute File */
1282 if (an <= 0) {
1283 if (fcb->last_op == U_WEOF) /* I just wrote a TM */
1284 while (fcb->tape_marks < fcb->eotm) tfclose();
1285 rewind_dev();
1286 break;
1287 }
1288 if ( (n == 0) && (fcb->tape_marks)) /* I'm on a file beginning*/
1289 break;
1290
1291 if (fcb->last_op == U_WEOF) /* I just wrote a TM */
1292 while (fcb->tape_marks < fcb->eotm) { tfclose(); n--;}
1293
1294 if (n <= 0) { /* Move -n+1 backwards, 1 time forwards */
1295 if (fcb->access & FCB_BW) {
1296 bmove(-n+1);
1297 tmove(1);
1298 n = 0; /* We're OK */
1299 }
1300 else { /* First Rewind, then Move Forw. */
1301 n = an; /* Where to go */
1302 rewind_dev();
1303 }
1304 }
1305 /* Move n tape-marks forwards */
1306 /*
1307 * CG. The idea to position one by one in devices with 2 FM was
1308 * to avoid to jump after the last FileMark, something very
1309 * annoying particularly with 1/2" tapes. However this limit a
1310 * lot the fast positioning of DAT devices.
1311 if (fcb->eotm > 1) {
1312 while ((--n >= 0) && !(fcb->status & FCB_EOM)) tmove(1);
1313 if (n > 0) oserrmsg="File positioning error", oserror = -1;
1314 }
1315 else (tmove(n));
1316 */
1317 tmove(n);
1318 break;
1319 default:
1320 oserror = -1;
1321 oserrmsg = "Bad skip mode";
1322 return(-1);
1323 }
1324
1325 fn = fcb->file_no + fcb->tape_marks;
1326
1327 return(oserror ? -1 : fn);
1328 }
1329
1330 long osuftell (f)
1331 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1332 .PURPOSE Compute current file number
1333 .RETURNS Current file number
1334 ----------------------------------------------------------------------*/
1335 int f; /* IN: Unit Number */
1336 {
1337 register long fn;
1338
1339 if (uget(f)) /* Bad unit number... */
1340 return(-1);
1341
1342 fn = fcb->file_no + fcb->tape_marks;
1343
1344 return(fn);
1345 }