serve simple file directories over 9p
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAmDUMY4ACgkQO3+8IhRO Y5gpFw/5AXsOhSO1bIDkx8mtv4ge+tG4yPAMYTO5u741fkHT90gZ312k5WQC88wX g7wPYaOnMnm5twDBv46HdcnJ41pDjzOAWvVA8dGZuF+wELE/9ztlMo73XMG/M4qv +e5hHdyyACqdVvihQbLi0RE3KrbGMCw8br1ZrG/FBt4wuRqU3clXijICcidatscq dSfAlTPgL1tE5YsFYE8Wz7MYu0Sg6AfyeTtP86Ogn6EH+jP+lpMeQzQ9D7udeC4D F9GZb0Vi2xUKzhqP6IRKhzmPTvTOMHE/ID9PFvJctOP7TPyF0Y/U5UALzOi63ovN whStPdPEjSXRxQ1hVP2qZdy+xi6Zwpw+L2uD9wmyLbsOFVjQEwqLJCJuJhlEUImP 8SiW3ONGY8GiKwGDAfyoz/3qnC1oyJJTshgImdMPkWzZy3ofNu4iLiaQAfpLDcLs t0MSXczU5RcYy9+d0ad+7uO7l+Os+6BImlxSZLwmSOSo7kr5mkbI1/jjXdL+ceDM TUs28Rdu9aE7vWWRUeQFOs4F+1uVCLlTLb6EpjWJSlwP2IrOqgoyhXYCJk7SvmG9 5zMVGiRGm8XpQL8gumsPjy9j8/ZB3qFEpNjKeY+CXCpCVzI6/WmCRVS0d9ou3T68 KV2WIcotN52DBFlCRzfLM1BrZQlD+X9hp9m7ELdd0EYWhHyuoXs= =398x -----END PGP SIGNATURE-----
4 files changed,
47 insertions(+),
2 deletions(-)
M
xrxs.c
→
xrxs.c
@@ -4,6 +4,10 @@ #include <fcall.h>
#include <thread.h> #include <9p.h> #include <stdio.h> +#include <dirent.h> +#include <libString.h> + +#define CARTSLOC "./carts/" /* clang-format off */@@ -119,6 +123,40 @@ free(rf);
} } +String** listdir(char* path) { + String** self = malloc(128 * sizeof(String*)); + DIR* dir; + struct dirent* ent; + int i = 0; + char* c; + if ((dir = opendir(path)) != NULL) { + while ((ent = readdir(dir)) != NULL) { + c = ent->d_name; + if (scmp(c, ".") || scmp(c, "..")) { + continue; + } + self[i] = s_new(); + + while (*c) { + s_putc(self[i], *c++); + } + s_terminate(self[i++]); + } + closedir(dir); + } + self[i] = nil; + return self; +} + +Ramfile* createrf(Tree* t, char* path, char* filename, int perm) { + Ramfile* rf; + File* f = walkfile(t->root, path); + createfile(f, filename, nil, perm, nil); + rf = (Ramfile*)emalloc9p(sizeof *rf); + f->aux = rf; + return rf; +} + void writerf(Tree* t, char* path, char* data) { Ramfile* rf; File* f = walkfile(t->root, path);@@ -142,6 +180,8 @@ Tree* tree;
char* mtpt = nil; char* usocket = nil; int i; + String** cart; + char cartsloc[256] = "./carts/"; /* if -m PATH is supplied, mount on PATH */ /* if -s NAME is supplied, create a socket for the namespace */@@ -161,8 +201,13 @@ }
fs.tree = alloctree(nil, nil, DMDIR | 0777, fsdestroyfile); tree = fs.tree; - createfile(tree->root, "carts", nil, 0444, nil); - writerf(tree, "carts", "uStrat\nkatbug\nSoulGrind\n"); + createfile(tree->root, "carts", nil, DMDIR | 0555, nil); + String** carts = listdir("carts/"); + cart = carts; + while (*cart) { + createfile(walkfile(tree->root, "carts"), (*cart)->base, nil, 0444, nil); + cart++; + } fs.foreground = 1; if (argc >= 3) {