1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4
5 long
Bwrite(Biobufhdr * bp,void * ap,long count)6 Bwrite(Biobufhdr *bp, void *ap, long count)
7 {
8 long c;
9 uchar *p;
10 int i, n, oc;
11 char errbuf[ERRMAX];
12
13 p = ap;
14 c = count;
15 oc = bp->ocount;
16
17 while(c > 0) {
18 n = -oc;
19 if(n > c)
20 n = c;
21 if(n == 0) {
22 if(bp->state != Bwactive)
23 return Beof;
24 i = write(bp->fid, bp->bbuf, bp->bsize);
25 if(i != bp->bsize) {
26 errstr(errbuf, sizeof errbuf);
27 if(strstr(errbuf, "interrupt") == nil)
28 bp->state = Binactive;
29 errstr(errbuf, sizeof errbuf);
30 return Beof;
31 }
32 bp->offset += i;
33 oc = -bp->bsize;
34 continue;
35 }
36 memmove(bp->ebuf+oc, p, n);
37 oc += n;
38 c -= n;
39 p += n;
40 }
41 bp->ocount = oc;
42 return count-c;
43 }
44