ref: dbd54342fd66fd372f5c2edd1597019814f41c9c
parent: b5086c1863fe10faf48ab675f503e562ec8dfcf0
author: Ori Bernstein <[email protected]>
date: Sun Nov 1 06:42:54 EST 2020
libbio: add aux pointer to bio This allows us to attach additional context to the biobuf so can read from some sort of data structure without a global variable.
--- a/sys/include/bio.h
+++ b/sys/include/bio.h
@@ -34,6 +34,7 @@
uchar* gbuf; /* pointer to good data in buf */
void (*errorf)(char *); /* called on error if not nil */
int (*iof)(Biobufhdr*, void *, long); /* called to do i/o */
+ void *aux; /* user data */
};
struct Biobuf
--- a/sys/man/2/bio
+++ b/sys/man/2/bio
@@ -1,6 +1,6 @@
.TH BIO 2
.SH NAME
-Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal \- buffered input/output
+Bopen, Bfdopen, Binit, Binits, Brdline, Brdstr, Bgetc, Bgetrune, Bgetd, Bungetc, Bungetrune, Bread, Bseek, Boffset, Bfildes, Blinelen, Bputc, Bputrune, Bprint, Bvprint, Bwrite, Bflush, Bterm, Bbuffered, Blethal, Biofn \- buffered input/output
.SH SYNOPSIS
.ta \w'Biobuf* 'u
.B #include <u.h>
@@ -8,6 +8,16 @@
.B #include <libc.h>
.br
.B #include <bio.h>
+.PP
+.ft L
+.nf
+.ta \w' 'u +\w' 'u +\w' 'u +\w' 'u +\w' 'u
+typedef struct Biobufhdr Biobufhdr;
+struct Biobufhdr {
+ void *aux; /* user data */
+ ... /* internals */
+};
+.fi
.PP
.B
Biobuf* Bopen(char *file, int mode)