summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib')
-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
3 files changed, 26 insertions, 35 deletions
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);