summaryrefslogtreecommitdiff
path: root/sys/src/libbio/binit.c
diff options
context:
space:
mode:
authoraiju <devnull@localhost>2017-05-04 17:42:12 +0000
committeraiju <devnull@localhost>2017-05-04 17:42:12 +0000
commitf681cf835af1e5c9e016e5245c24165b029a5e38 (patch)
tree43453c10a803a5e64b47dc3474e603715cd76bcc /sys/src/libbio/binit.c
parent414d29e98f8d5242cc68161e61b66b7171e96634 (diff)
bio: add support for custom I/O handler via Biofn
Diffstat (limited to 'sys/src/libbio/binit.c')
-rw-r--r--sys/src/libbio/binit.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/sys/src/libbio/binit.c b/sys/src/libbio/binit.c
index 9afae5b34..13fd0f4ce 100644
--- a/sys/src/libbio/binit.c
+++ b/sys/src/libbio/binit.c
@@ -50,6 +50,18 @@ install(Biobufhdr *bp)
}
}
+static int
+bioread(Biobufhdr *bp, void *v, long n)
+{
+ return read(bp->fid, v, n);
+}
+
+static int
+biowrite(Biobufhdr *bp, void *v, long n)
+{
+ return write(bp->fid, v, n);
+}
+
int
Binits(Biobufhdr *bp, int f, int mode, uchar *p, int size)
{
@@ -64,12 +76,14 @@ Binits(Biobufhdr *bp, int f, int mode, uchar *p, int size)
case OREAD:
bp->state = Bractive;
bp->ocount = 0;
+ bp->iof = bioread;
break;
case OWRITE:
install(bp);
bp->state = Bwactive;
bp->ocount = -size;
+ bp->iof = biowrite;
break;
}
bp->bbuf = p;
@@ -154,3 +168,15 @@ Bterm(Biobufhdr *bp)
/* otherwise opened with Binit(s) */
return r;
}
+
+void
+Biofn(Biobufhdr *bp, int (*f)(Biobufhdr *, void *, long))
+{
+ if(f == nil)
+ if(bp->state == Bwactive)
+ bp->iof = biowrite;
+ else
+ bp->iof = bioread;
+ else
+ bp->iof = f;
+}