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