Commit | Line | Data |
---|---|---|
f70ab843 RH |
1 | /* |
2 | * Copyright (c) 1982 Regents of the University of California | |
3 | */ | |
4 | #ifndef lint | |
5 | static char sccsid[] = "@(#)asio.c 4.4 %G%"; | |
6 | #endif not lint | |
7 | ||
8ad3c13d | 8 | #include <stdio.h> |
8ad3c13d BJ |
9 | #include "as.h" |
10 | /* | |
11 | * Block I/O routines for logical I/O concurrently in | |
12 | * more than one place in the same file. | |
13 | */ | |
14 | int biofd; /* file descriptor for block I/O file */ | |
15 | off_t boffset; /* physical position in logical file */ | |
16 | BFILE *biobufs; /* the block I/O buffers */ | |
17 | ||
18 | #define error(severity, message) \ | |
19 | {yyerror(message); if (severity) delexit();} | |
20 | ||
21 | Flushfield(n) | |
22 | register int n; | |
23 | { | |
24 | while (n>0) { | |
25 | outb(bitfield); | |
26 | bitfield >>= 8; | |
27 | n -= 8; | |
28 | } | |
29 | bitoff=0; | |
30 | bitfield=0; | |
31 | } | |
32 | ||
8ad3c13d | 33 | /* |
bef6dadc | 34 | * Block I/O Routines |
8ad3c13d | 35 | */ |
8ad3c13d BJ |
36 | bopen(bp, off) |
37 | struct biobuf *bp; | |
38 | off_t off; | |
39 | { | |
40 | ||
41 | bp->b_ptr = bp->b_buf; | |
42 | bp->b_nleft = BUFSIZ - off % BUFSIZ; | |
43 | bp->b_off = off; | |
44 | bp->b_link = biobufs; | |
45 | biobufs = bp; | |
46 | } | |
47 | ||
48 | int bwrerror; | |
49 | ||
50 | bwrite(p, cnt, bp) | |
51 | register char *p; | |
52 | register int cnt; | |
53 | register struct biobuf *bp; | |
54 | { | |
55 | register int put; | |
56 | register char *to; | |
57 | ||
58 | top: | |
59 | if (cnt == 0) | |
60 | return; | |
61 | if (bp->b_nleft) { | |
62 | put = bp->b_nleft; | |
63 | if (put > cnt) | |
64 | put = cnt; | |
65 | bp->b_nleft -= put; | |
66 | to = bp->b_ptr; | |
f70ab843 RH |
67 | #ifdef lint |
68 | *to = *to; | |
69 | #endif lint | |
8ad3c13d BJ |
70 | asm("movc3 r8,(r11),(r7)"); |
71 | bp->b_ptr += put; | |
72 | p += put; | |
73 | cnt -= put; | |
74 | goto top; | |
75 | } | |
76 | if (cnt >= BUFSIZ) { | |
77 | if (bp->b_ptr != bp->b_buf) | |
78 | bflush1(bp); | |
79 | put = cnt - cnt % BUFSIZ; | |
80 | if (boffset != bp->b_off) | |
f70ab843 | 81 | (void)lseek(biofd, (long)bp->b_off, 0); |
8ad3c13d BJ |
82 | if (write(biofd, p, put) != put) { |
83 | bwrerror = 1; | |
84 | error(1, "Output write error"); | |
85 | } | |
86 | bp->b_off += put; | |
87 | boffset = bp->b_off; | |
88 | p += put; | |
89 | cnt -= put; | |
90 | goto top; | |
91 | } | |
92 | bflush1(bp); | |
93 | goto top; | |
94 | } | |
95 | ||
96 | bflush() | |
97 | { | |
98 | register struct biobuf *bp; | |
99 | ||
100 | if (bwrerror) | |
101 | return; | |
102 | for (bp = biobufs; bp; bp = bp->b_link) | |
103 | bflush1(bp); | |
104 | } | |
105 | ||
106 | bflush1(bp) | |
107 | register struct biobuf *bp; | |
108 | { | |
109 | register int cnt = bp->b_ptr - bp->b_buf; | |
110 | ||
111 | if (cnt == 0) | |
112 | return; | |
113 | if (boffset != bp->b_off) | |
f70ab843 | 114 | (void)lseek(biofd, (long)bp->b_off, 0); |
8ad3c13d BJ |
115 | if (write(biofd, bp->b_buf, cnt) != cnt) { |
116 | bwrerror = 1; | |
117 | error(1, "Output write error"); | |
118 | } | |
119 | bp->b_off += cnt; | |
120 | boffset = bp->b_off; | |
121 | bp->b_ptr = bp->b_buf; | |
122 | bp->b_nleft = BUFSIZ; | |
123 | } | |
124 | ||
125 | bflushc(bp, c) | |
126 | register struct biobuf *bp; | |
127 | char c; | |
128 | { | |
8ad3c13d BJ |
129 | bflush1(bp); |
130 | bputc(c, bp); | |
131 | } |