serve simple file directories over 9p
This commit is contained in:
parent
6688673fd6
commit
d7466c73b2
4 changed files with 47 additions and 2 deletions
0
carts/another
Normal file
0
carts/another
Normal file
0
carts/other
Normal file
0
carts/other
Normal file
0
carts/test
Normal file
0
carts/test
Normal file
49
xrxs.c
49
xrxs.c
|
@ -4,6 +4,10 @@
|
||||||
#include <thread.h>
|
#include <thread.h>
|
||||||
#include <9p.h>
|
#include <9p.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <libString.h>
|
||||||
|
|
||||||
|
#define CARTSLOC "./carts/"
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
|
@ -119,6 +123,40 @@ void fsdestroyfile(File* f) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
void writerf(Tree* t, char* path, char* data) {
|
||||||
Ramfile* rf;
|
Ramfile* rf;
|
||||||
File* f = walkfile(t->root, path);
|
File* f = walkfile(t->root, path);
|
||||||
|
@ -142,6 +180,8 @@ void threadmain(int argc, char* argv[]) {
|
||||||
char* mtpt = nil;
|
char* mtpt = nil;
|
||||||
char* usocket = nil;
|
char* usocket = nil;
|
||||||
int i;
|
int i;
|
||||||
|
String** cart;
|
||||||
|
char cartsloc[256] = "./carts/";
|
||||||
|
|
||||||
/* if -m PATH is supplied, mount on PATH */
|
/* if -m PATH is supplied, mount on PATH */
|
||||||
/* if -s NAME is supplied, create a socket for the namespace */
|
/* if -s NAME is supplied, create a socket for the namespace */
|
||||||
|
@ -161,8 +201,13 @@ void threadmain(int argc, char* argv[]) {
|
||||||
|
|
||||||
fs.tree = alloctree(nil, nil, DMDIR | 0777, fsdestroyfile);
|
fs.tree = alloctree(nil, nil, DMDIR | 0777, fsdestroyfile);
|
||||||
tree = fs.tree;
|
tree = fs.tree;
|
||||||
createfile(tree->root, "carts", nil, 0444, nil);
|
createfile(tree->root, "carts", nil, DMDIR | 0555, nil);
|
||||||
writerf(tree, "carts", "uStrat\nkatbug\nSoulGrind\n");
|
String** carts = listdir("carts/");
|
||||||
|
cart = carts;
|
||||||
|
while (*cart) {
|
||||||
|
createfile(walkfile(tree->root, "carts"), (*cart)->base, nil, 0444, nil);
|
||||||
|
cart++;
|
||||||
|
}
|
||||||
fs.foreground = 1;
|
fs.foreground = 1;
|
||||||
|
|
||||||
if (argc >= 3) {
|
if (argc >= 3) {
|
||||||
|
|
Loading…
Reference in a new issue