summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
authordzwdz2022-08-04 23:06:57 +0200
committerdzwdz2022-08-04 23:06:57 +0200
commitce00d1677d7a419b427e7f11963eee982a55a231 (patch)
tree2662c3861226f6909b83d57ff8b6ac3b2ba5ec8d /src/user
parent26dc784103914b9d6ba36e0a96fa4b3af977626f (diff)
do some simple TODOs, organize the rest; general code maintainance
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/find/find.c5
-rw-r--r--src/user/app/init/driver/tmpfs.c10
-rw-r--r--src/user/app/shell/builtins.c2
-rw-r--r--src/user/bootstrap/tar.c3
-rw-r--r--src/user/lib/file.c5
-rw-r--r--src/user/lib/fs/dir.c7
-rw-r--r--src/user/lib/fs/misc.c49
7 files changed, 37 insertions, 44 deletions
diff --git a/src/user/app/find/find.c b/src/user/app/find/find.c
index 502a190..6c5d31a 100644
--- a/src/user/app/find/find.c
+++ b/src/user/app/find/find.c
@@ -1,3 +1,4 @@
+#include <camellia/path.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -48,8 +49,8 @@ void recurse(char *path) {
}
void find(const char *path) {
- // TODO export PATH_MAX
- char *buf = malloc(4096);
+ // TODO bound checking
+ char *buf = malloc(PATH_MAX);
memcpy(buf, path, strlen(path)+1);
recurse(buf);
free(buf);
diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c
index 5db78f1..96fdf39 100644
--- a/src/user/app/init/driver/tmpfs.c
+++ b/src/user/app/init/driver/tmpfs.c
@@ -53,11 +53,11 @@ static struct node *tmpfs_open(const char *path, struct fs_wait_response *res) {
}
void tmpfs_drv(void) {
- // TODO replace all the static allocations in drivers with mallocs
- static char buf[512];
+ const size_t buflen = 4096;
+ char *buf = malloc(buflen);
struct fs_wait_response res;
struct node *ptr;
- while (!_syscall_fs_wait(buf, sizeof buf, &res)) {
+ while (!_syscall_fs_wait(buf, buflen, &res)) {
switch (res.op) {
case VFSOP_OPEN:
ptr = tmpfs_open(buf, &res);
@@ -68,7 +68,7 @@ void tmpfs_drv(void) {
ptr = (void*)res.id;
if (ptr == &special_root) {
struct dirbuild db;
- dir_start(&db, res.offset, buf, sizeof buf);
+ dir_start(&db, res.offset, buf, buflen);
for (struct node *iter = root; iter; iter = iter->next)
dir_append(&db, iter->name);
_syscall_fs_respond(buf, dir_finish(&db), 0);
@@ -97,7 +97,7 @@ void tmpfs_drv(void) {
fs_normslice(&res.offset, &res.len, ptr->size, true);
if (res.offset + res.len >= ptr->capacity) {
- // TODO
+ // TODO expanding files
_syscall_fs_respond(NULL, -1, 0);
break;
}
diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c
index d4de354..d409bfd 100644
--- a/src/user/app/shell/builtins.c
+++ b/src/user/app/shell/builtins.c
@@ -89,7 +89,7 @@ static void cmd_ls(int argc, char **argv) {
const size_t buflen = 4096;
char *buf = malloc(buflen);
- DEFAULT_ARGV("!stdin");
+ DEFAULT_ARGV("/");
for (int i = 1; i < argc; i++) {
char *path = (void*)argv[i];
int pathlen = strlen(path);
diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c
index 2025ed1..150a993 100644
--- a/src/user/bootstrap/tar.c
+++ b/src/user/bootstrap/tar.c
@@ -61,7 +61,8 @@ static void tar_read(struct fs_wait_response *res, void *base, size_t base_len)
size_t meta_len;
int size;
- static char buf[BUF_SIZE]; // TODO reuse a single buffer
+ static char buf[BUF_SIZE];
+ // TODO reuse a single buffer for both tar_driver and tar_read
if (meta == root_fakemeta) type = '5'; /* see comment in tar_open() */
diff --git a/src/user/lib/file.c b/src/user/lib/file.c
index ffea99b..84242b2 100644
--- a/src/user/lib/file.c
+++ b/src/user/lib/file.c
@@ -115,7 +115,6 @@ size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict f) {
return 0;
while (pos < total) {
- // TODO shouldn't repeat reads
long res = _syscall_read(f->fd, buf + pos, total - pos, f->pos);
if (res < 0) {
f->error = true;
@@ -184,7 +183,6 @@ int fseek(FILE *f, long offset, int whence) {
break;
case SEEK_END:
f->pos = -1;
- // TODO doesn't -1 put the cursor before the last byte? i need to fix up the drivers
break;
default:
errno = EINVAL;
@@ -194,7 +192,8 @@ int fseek(FILE *f, long offset, int whence) {
bool pos_neg = f->pos < 0;
f->pos += offset;
if (pos_neg && f->pos >= 0) {
- errno = ENOSYS; // TODO
+ // TODO getting the file size
+ errno = ENOSYS;
return -1;
}
f->eof = false;
diff --git a/src/user/lib/fs/dir.c b/src/user/lib/fs/dir.c
index 35028bd..802dd61 100644
--- a/src/user/lib/fs/dir.c
+++ b/src/user/lib/fs/dir.c
@@ -11,8 +11,8 @@ void dir_start(struct dirbuild *db, long offset, char *buf, size_t buflen) {
db->blen = buflen;
db->error = 0;
- if (offset < 0)
- db->error = -ENOSYS; // TODO
+ // TODO decide how negative directory offsets should be handled
+ if (offset < 0) db->error = -ENOSYS;
}
bool dir_append(struct dirbuild *db, const char *name) {
@@ -56,11 +56,12 @@ bool dir_append_from(struct dirbuild *db, handle_t h) {
}
if (ret == 0) {
// TODO no idea how much we've overread
+ // this messes up reading bind mounts of multiple directories
db->error = -ENOSYS;
return true;
}
- // TODO deduplicate
+ // TODO deduplicate entries
db->offset = 0;
db->bpos += ret;
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index e47d930..1fb5c3b 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -19,6 +19,21 @@ bool fork2_n_mount(const char *path) {
return false;
}
+static int dir_seglen(const char *path) {
+ /* in human terms:
+ * if path contains /, return its position + 1
+ * otherwise, return strlen */
+ int len = 0;
+ while (path[len]) {
+ if (path[len] == '/') {
+ len++;
+ break;
+ }
+ len++;
+ }
+ return len;
+}
+
void fs_passthru(const char *prefix) {
struct fs_wait_response res;
const size_t buf_len = 1024;
@@ -102,19 +117,7 @@ void fs_whitelist(const char **list) {
// TODO could be precomputed too
size_t len = strlen(*iter); // inefficient, whatever
if (blen < len && !memcmp(ipath, *iter, blen))
- {
- /* inject up to the next slash */
- // TODO separate out into its own function
- int ilen = 0;
- while ((*iter)[blen + ilen]) {
- if ((*iter)[blen + ilen] == '/') {
- ilen++;
- break;
- }
- ilen++;
- }
- dir_appendl(&db, (*iter) + blen, ilen);
- }
+ dir_appendl(&db, *iter + blen, dir_seglen(*iter + blen));
}
_syscall_fs_respond(buf, dir_finish(&db), 0);
break;
@@ -144,7 +147,6 @@ void fs_dir_inject(const char *path) {
struct fs_dir_handle *data;
const size_t buf_len = 1024;
char *buf = malloc(buf_len);
- int inject_len;
struct dirbuild db;
if (!buf) exit(1);
@@ -157,22 +159,10 @@ void fs_dir_inject(const char *path) {
res.len < path_len && !memcmp(path, buf, res.len))
{
/* opening a directory that we're injecting into */
-
data = malloc(sizeof *data);
data->delegate = _syscall_open(buf, res.len, res.flags);
data->inject = path + res.len;
-
- /* inject up to the next slash */
- inject_len = 0;
- while (data->inject[inject_len]) {
- if (data->inject[inject_len] == '/') {
- inject_len++; // include the slash
- break;
- }
- inject_len++;
- }
- data->inject_len = inject_len;
-
+ data->inject_len = dir_seglen(data->inject);
_syscall_fs_respond(data, 0, 0);
} else {
_syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
@@ -187,8 +177,9 @@ void fs_dir_inject(const char *path) {
break;
case VFSOP_READ:
- // TODO optimization - min(buf_len, res.capacity)
- dir_start(&db, res.offset, buf, buf_len);
+ if (res.capacity > buf_len)
+ res.capacity = buf_len;
+ dir_start(&db, res.offset, buf, res.capacity);
dir_appendl(&db, data->inject, data->inject_len);
if (data->delegate >= 0)
dir_append_from(&db, data->delegate);