all repos — xrxs @ 28775d390edcbfcf1e27d596d3da124714eeeadb

experimental networked application/game server with 9p

trying to write to ctl file
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmDaQTcACgkQO3+8IhRO
Y5h43w/+PQ9a8TUvpDpSUCrcUvQOmX4a0n3YO+kbRhAD0LljcY+KLSTTecrErIxI
whZvLensBNrWkv0whOvBMKwGqkomBLkzr2vwN9aIpqcGIVG0+/ahroQ+Ly+KfaVT
RusRNmRv2QxtD2oyuFk0/qk/4rTRyjdkQXhuO8N7Fhj8Jn5jLpRcCmILVqDzUwPr
weKtknUwynEmm9ClBBVGiV2eMwq7PwcVuBN89P4az1UGdF3gMyZ38pqV7269R3f1
43yg2Ys3K4Pq6oFX/slegqpdh12vEej6TjUCvLWy3pptKmM1+vs0W6YPrqyf9ACD
hSkf2mpmJozjcj5Ws4xoNYRQIglLBTpf0ypucH9bmI0v+k1BdANkMRUGLTq9lr7G
9FQA7Jayw6euBUCa9b3zuggiIt6MN7sZD6r62ft0UXzsmW0qF0HtExorROv03Qaw
qDYeboaQXV4/uOx9yUuY3sk6RzCc0nxYXN7d8R1vuDcmC+Ypa9q9yuFsfwf8CJG2
KThrXPzWQpaB6xt9ZFX7MnRnhj0ReRN6Ax4/9WZ3n3wVJV7qJCJGMuwkKPLo1MfV
R37V3frZtxDkGfwERyuNr1HrGDzrtWMaPTjLG1DimABgnIVLv8q5kAHyA2h4hMOs
k5JVL4Ji0zUNk7Tht+3MrNtKoMuk0uDdMDDYVGzbpPGYCaw7Mts=
=Bk1J
-----END PGP SIGNATURE-----
commit

28775d390edcbfcf1e27d596d3da124714eeeadb

parent

d7466c73b29a8a28dbebdfb69c132c39546e5442

1 files changed, 87 insertions(+), 12 deletions(-)

jump to
M xrxs.cxrxs.c

@@ -6,9 +6,12 @@ #include <9p.h>

#include <stdio.h> #include <dirent.h> #include <libString.h> +#include <mp.h> +#include <libsec.h> #define CARTSLOC "./carts/" - +#define CTL_HASHV 139931 +#define SHUTDOWN_HASHV 11192337284248 /* clang-format off */ char clca(char c) { return c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c; } /* char to lowercase */

@@ -25,6 +28,8 @@ int ssin(char *s, char *ss) { int a = 0, b = 0; while(s[a]) { if(s[a] == ss[b]) { if(!ss[b + 1]) return a - b; b++; } else b = 0; a++; } return -1; } /* string substring index */

char *ccat(char *dst, char c) { int len = slen(dst); dst[len] = c; dst[len + 1] = '\0'; return dst; } /* clang-format on */ +int chatty9p = 1; +static int serving = 1; static char Ebad[] = "something bad happened"; static char Enomem[] = "no memory";

@@ -59,6 +64,16 @@ r->ofcall.count = count;

respond(r, nil); } +unsigned long long hash(char* str) { + unsigned long long h; + unsigned char* p; + + h = 0; + for (p = (unsigned char*)str; *p != '\0'; p++) + h = 37 * h + *p; + return h; // or, h % ARRAY_SIZE; +} + void fswrite(Req* r) { void* v; Ramfile* rf;

@@ -84,10 +99,45 @@ r->ofcall.count = count;

respond(r, nil); } +void handlectl(Req* r) { + char cmd[16]; + char* c = r->ifcall.data; + + while (*c && *c != ' ') { + ccat(cmd, *c); + } + + unsigned long long const cmd_hashv = hash(cmd); + + switch (cmd_hashv) { + case SHUTDOWN_HASHV: + serving = 0; + break; + default: + break; + } + r->ofcall.count = 16; + r->fid->file->dir.length = 16; + respond(r, nil); +} + +void xrxswrite(Req* r) { + unsigned int filename_hashv = hash(r->ifcall.name); + printf(r->ifcall.name); + switch (filename_hashv) { + case CTL_HASHV: + handlectl(r); + break; + default: + fswrite(r); + break; + } +} + void fscreate(Req* r) { Ramfile* rf; File* f; - + printf("eee"); if (f = createfile(r->fid->file, r->ifcall.name, nil, r->ifcall.perm, nil)) { rf = emalloc9p(sizeof *rf); f->aux = rf;

@@ -99,9 +149,22 @@ }

respond(r, Ebad); } +void xrxscreate(Req* r) { + unsigned int filename_hashv = hash(r->ifcall.name); + printf("fff"); + switch (filename_hashv) { + case CTL_HASHV: + handlectl(r); + break; + default: + fscreate(r); + break; + } +} + void fsopen(Req* r) { Ramfile* rf; - + printf("ooo"); rf = r->fid->file->aux; if (rf && (r->ifcall.mode & OTRUNC)) {

@@ -166,11 +229,17 @@ rf->ndata = slen(data);

f->aux = rf; } +void xrxswstat(Req* r) { + r->fid->omode = OWRITE; + respond(r, nil); +} + Srv fs = { .open = fsopen, .read = fsread, - .write = fswrite, - .create = fscreate, + .write = xrxswrite, + .create = xrxscreate, + .wstat = xrxswstat }; int threadmaybackground(void) { return 1; }

@@ -182,6 +251,8 @@ char* usocket = nil;

int i; String** cart; char cartsloc[256] = "./carts/"; + char ctlbuf[128] = "some data"; + Ramfile ctlfile = {ctlbuf, 128}; /* if -m PATH is supplied, mount on PATH */ /* if -s NAME is supplied, create a socket for the namespace */

@@ -202,6 +273,8 @@

fs.tree = alloctree(nil, nil, DMDIR | 0777, fsdestroyfile); tree = fs.tree; createfile(tree->root, "carts", nil, DMDIR | 0555, nil); + createfile(tree->root, "ctl", nil, 0600, &ctlfile); + String** carts = listdir("carts/"); cart = carts; while (*cart) {

@@ -210,13 +283,15 @@ cart++;

} fs.foreground = 1; - if (argc >= 3) { - if (mtpt != nil && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0) - sysfatal("mountpoint %s does not exist", mtpt); + while (serving) { + if (argc >= 3) { + if (mtpt != nil && access(mtpt, AEXIST) < 0 && access(mtpt, AEXIST) < 0) + sysfatal("mountpoint %s does not exist", mtpt); - threadpostmountsrv(&fs, usocket, mtpt, MREPL | MCREATE); - threadexits(0); - } else { - srv(&fs); + threadpostmountsrv(&fs, usocket, mtpt, MREPL | MCREATE); + threadexits(0); + } else { + srv(&fs); + } } }