From c6424fbc55298399f133ca1ede11e1f0b4a5c824 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 29 Jul 2022 16:16:24 +0200 Subject: use a shared fs_normslice() function to handle offsets --- src/user/bootstrap/tar.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/user/bootstrap') 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 +#include #include #include #include @@ -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;) { -- cgit v1.2.3