diff options
author | dzwdz | 2022-07-29 16:16:24 +0200 |
---|---|---|
committer | dzwdz | 2022-07-29 16:16:24 +0200 |
commit | c6424fbc55298399f133ca1ede11e1f0b4a5c824 (patch) | |
tree | d8dd1c160a7184a99ea3c72779dce95b4bbee692 /src/user/app/init | |
parent | a0b16620e1699504e8d21a481e019dec40d7ee1b (diff) |
use a shared fs_normslice() function to handle offsets
Diffstat (limited to 'src/user/app/init')
-rw-r--r-- | src/user/app/init/driver/tmpfs.c | 27 |
1 files changed, 15 insertions, 12 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: |