commit 592f67e38171a4bec4b94377d3fcc2faf820e0e8
parent c7f0010c64a4b3fcff032bbd102707948aef1935
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Mon, 13 May 2024 23:52:55 +0000
fs: add threadplumb
Diffstat:
M | fs.c | | | 31 | +++++++++++++++++++++++++++++++ |
1 file changed, 31 insertions(+), 0 deletions(-)
diff --git a/fs.c b/fs.c
@@ -3,6 +3,7 @@
#include <fcall.h>
#include <thread.h>
#include <9p.h>
+#include <plumb.h>
#include "pages.h"
@@ -28,6 +29,8 @@ void fcut_write(Req *r);
void normalize_sel(void);
void update_selstr(void);
+void threadplumb(void *);
+
Srv ampsrv = {
.read = fs_read,
.write = fs_write,
@@ -37,6 +40,11 @@ Srv ampsrv = {
File *fdata, *fcut, *fctl;
char *service, *mountpath = "/mnt/amp";
+struct {
+ int send, recv;
+ char *port;
+} plumb = {.port = "amp"};
+
void
usage(void)
{
@@ -60,6 +68,7 @@ threadmain(int argc, char **argv)
default: usage();
} ARGEND
if (argc != 0) usage();
+ proccreate(threadplumb, nil, 1024);
update_selstr();
ampsrv.tree = alloctree("amp", "amp", DMDIR|0555, nil);
fdata = createfile(ampsrv.tree->root, "data", "amp", 0666, nil);
@@ -69,6 +78,28 @@ threadmain(int argc, char **argv)
}
void
+threadplumb(void *)
+{
+ Plumbmsg *m;
+ long s, e;
+ if (plumb.recv < 0) return;
+ threadsetname("plumb");
+ for (;;) {
+ m = plumbrecv(plumb.recv);
+ if (m->ndata < 24) fprint(2, "plumb message too short\n");
+ else if (strcmp(m->src, "amp") != 0){
+ s = strtol(m->data, nil, 10);
+ e = strtol(m->data + 12, nil, 10);
+ sel.max = s, sel.min = e;
+ normalize_sel();
+ update_selstr();
+ fcut->length = (sel.max - sel.min) * FrameSize;
+ }
+ plumbfree(m);
+ }
+}
+
+void
fs_open(Req *r)
{
char *rstr = nil;