summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/init/driver/tmpfs.c27
-rw-r--r--src/user/bootstrap/tar.c15
-rw-r--r--src/user/lib/fs/misc.c2
3 files changed, 24 insertions, 20 deletions
diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c
index d9f73ab..e4c079c 100644
--- a/src/user/app/init/driver/tmpfs.c
+++ b/src/user/app/init/driver/tmpfs.c
@@ -1,3 +1,4 @@
+#include <camellia/fsutil.h>
#include <camellia/syscalls.h>
#include <shared/mem.h>
#include <stddef.h>
@@ -64,6 +65,7 @@ void tmpfs_drv(void) {
case VFSOP_READ:
ptr = (void*)res.id;
if (ptr == &special_root) {
+ // TODO directory offset handling
size_t buf_pos = 0;
size_t to_skip = res.offset;
@@ -85,11 +87,8 @@ void tmpfs_drv(void) {
}
_syscall_fs_respond(buf, buf_pos, 0);
} else {
- // TODO offset
- if (res.offset)
- _syscall_fs_respond(NULL, 0, 0);
- else
- _syscall_fs_respond(ptr->buf, ptr->size, 0);
+ fs_normslice(&res.offset, &res.len, ptr->size, false);
+ _syscall_fs_respond(ptr->buf + res.offset, res.len, 0);
break;
}
break;
@@ -114,13 +113,17 @@ void tmpfs_drv(void) {
ptr->capacity = 256;
}
- size_t len = res.len;
- if (len > ptr->capacity - res.offset)
- len = ptr->capacity - res.offset;
- memcpy(ptr->buf + res.offset, buf, len);
- if (ptr->size < res.offset + len)
- ptr->size = res.offset + len;
- _syscall_fs_respond(NULL, len, 0);
+ fs_normslice(&res.offset, &res.len, ptr->size, true);
+ if (res.offset + res.len >= ptr->capacity) {
+ // TODO
+ _syscall_fs_respond(NULL, -1, 0);
+ break;
+ }
+
+ memcpy(ptr->buf + res.offset, buf, res.len);
+ if (ptr->size < res.offset + res.len)
+ ptr->size = res.offset + res.len;
+ _syscall_fs_respond(NULL, res.len, 0);
break;
default:
diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c
index 75883e6..c690f2c 100644
--- a/src/user/bootstrap/tar.c
+++ b/src/user/bootstrap/tar.c
@@ -1,5 +1,6 @@
#include "tar.h"
#include <camellia/flags.h>
+#include <camellia/fsutil.h>
#include <camellia/syscalls.h>
#include <shared/mem.h>
#include <stdint.h>
@@ -68,17 +69,17 @@ static void tar_read(struct fs_wait_response *res, void *base, size_t base_len)
case '\0':
case '0': /* normal files */
size = tar_size(meta);
- if (res->offset < 0 || res->offset > size) {
- // TODO support negative offsets
- _syscall_fs_respond(NULL, -1, 0);
- } else {
- _syscall_fs_respond(meta + 512 + res->offset, size - res->offset, 0);
- }
+ fs_normslice(&res->offset, &res->len, size, false);
+ _syscall_fs_respond(meta + 512 + res->offset, res->len, 0);
break;
case '5': /* directory */
- meta_len = strlen(meta);
+ if (res->offset < 0) {
+ _syscall_fs_respond(NULL, -1, 0);
+ break;
+ }
size_t to_skip = res->offset;
+ meta_len = strlen(meta);
/* find files in dir */
for (size_t off = 0; off < base_len;) {
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index 3a732af..32464b3 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -132,7 +132,7 @@ void fs_dir_inject(const char *path) {
break;
case VFSOP_READ:
- if (res.offset > 0) _syscall_fs_respond(NULL, 0, 0); // TODO working offsets
+ if (res.offset != 0) _syscall_fs_respond(NULL, -1, 0); // TODO working offsets
int out_len = data->inject_len;
memcpy(buf, data->inject, out_len);