Add a synth_buf to chan
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 22 Dec 2016 20:29:11 +0000 (15:29 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 10 Jan 2017 00:01:40 +0000 (19:01 -0500)
As a general rule, let's use synth_buf instead of c->aux when making
per-chan readable buffers.  Some devices need to use aux for something
else.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/drivers/dev/mem.c
kern/include/ns.h

index 9687a82..a93b45b 100644 (file)
@@ -378,16 +378,16 @@ static struct chan *mem_open(struct chan *c, int omode)
        }
        switch (c->qid.path) {
        case Qarena_stats:
-               c->aux = build_arena_stats();
+               c->synth_buf = build_arena_stats();
                break;
        case Qslab_stats:
-               c->aux = build_slab_stats();
+               c->synth_buf = build_slab_stats();
                break;
        case Qfree:
-               c->aux = build_free();
+               c->synth_buf = build_free();
                break;
        case Qkmemstat:
-               c->aux = build_kmemstat();
+               c->synth_buf = build_kmemstat();
                break;
        }
        c->mode = openmode(omode);
@@ -405,7 +405,7 @@ static void mem_close(struct chan *c)
        case Qslab_stats:
        case Qfree:
        case Qkmemstat:
-               kfree(c->aux);
+               kfree(c->synth_buf);
                break;
        }
 }
@@ -422,7 +422,7 @@ static long mem_read(struct chan *c, void *ubuf, long n, int64_t offset)
        case Qslab_stats:
        case Qfree:
        case Qkmemstat:
-               sza = c->aux;
+               sza = c->synth_buf;
                return readmem(offset, ubuf, n, sza->buf, sza->size);
        default:
                panic("Bad Qid %p!", c->qid.path);
index 2861392..8e94995 100644 (file)
@@ -431,6 +431,10 @@ struct chan {
        int ateof;
        void *buf;
        int bufused;
+       /* A lot of synthetic files need something generated at open time, which the
+        * user can read from (including offsets) while the underlying file changes.
+        * Hang that buffer here. */
+       void *synth_buf;
 };
 
 struct cname {