From 287d76fe313093f6d25fb82da4beda6174e7d5c6 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 7 Aug 2022 17:20:15 +0200 Subject: user/tmpfs: expand files on the fly --- src/user/app/init/driver/tmpfs.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c index 7414320..c7abf50 100644 --- a/src/user/app/init/driver/tmpfs.c +++ b/src/user/app/init/driver/tmpfs.c @@ -98,10 +98,16 @@ void tmpfs_drv(void) { } fs_normslice(&res.offset, &res.len, ptr->size, true); - if (res.offset + res.len >= ptr->capacity) { - // TODO expanding files - _syscall_fs_respond(NULL, -1, 0); - break; + if (ptr->capacity <= res.offset + res.len) { + size_t newcap = 1; + while (newcap && newcap <= res.offset + res.len) + newcap *= 2; + if (!newcap) { /* overflow */ + _syscall_fs_respond(NULL, -1, 0); + break; + } + ptr->capacity = newcap; + ptr->buf = realloc(ptr->buf, ptr->capacity); } memcpy(ptr->buf + res.offset, buf, res.len); -- cgit v1.2.3