octree

octree tools and accessories
git clone git://nsmpr.xyz/octree.git
Log | Files | Refs

commit 6142a381e0c04c703bfa75a25a1807dcc2aa37cc
parent b75a414686da42330f0c7951203c9be52ff66928
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Mon,  8 Mar 2021 20:46:19 +0000

fs.c: preliminary stream writing code

Diffstat:
Mfs.c | 37++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/fs.c b/fs.c @@ -4,11 +4,17 @@ #include <thread.h> #include <9p.h> -/* TODO: possible replace these with enum in file->aux and switch +/* TODO: possibly replace these with enum in file->aux and switch statement instead of if/else in fsread/fswrite */ -File *Fdata; -File *Fstream; +struct Nmsg { + u64int id; + u64int size; + char data; +}; + +File *data; +File *stream; Channel *c; void @@ -19,7 +25,6 @@ procrespond(void*) while (recv(c, &r) == 1) { assert(r != nil); respond(r, nil); - sleep(5000); } } @@ -28,10 +33,10 @@ fsread(Req *r) { File *f; f = r->fid->file; - if (f == Fdata) { + if (f == data) { readstr(r, "data\n"); respond(r, nil); - } else if (f == Fstream) { + } else if (f == stream) { fprint(2, "stream read\n"); readstr(r, "stream\n"); send(c, &r); @@ -44,7 +49,19 @@ fsread(Req *r) void fswrite(Req *r) { - respond(r, nil); + File *f; + f = r->fid->file; + if (f == stream) { + struct Nmsg *msg; + msg = malloc(r->ifcall.count); + memcpy(r->ifcall.data, msg, r->ifcall.count); + r->ofcall.count = r->ifcall.count; + free(msg); + respond(r, nil); + } + else { + respond(r, "not implemented"); + } } void @@ -88,11 +105,13 @@ threadmain (int argc, char **argv) default: usage(); }ARGEND + if (argc > 0) usage(); + c = chancreate(sizeof(Req*), 1024); fs.tree = alloctree("octree", "octree", 0777|DMDIR, nil), - Fdata = createfile(fs.tree->root, "data", "octree", 0666, nil); - Fstream = createfile(fs.tree->root, "stream", "octree", 0666, nil); + data = createfile(fs.tree->root, "data", "octree", 0666, nil); + stream = createfile(fs.tree->root, "stream", "octree", 0666, nil); fprint(2, "launching threadpostmountsrv\n"); proccreate(procrespond, nil, 1024 * 8); threadpostmountsrv(&fs, srv, mtpt, MREPL);