diff options
author | dzwdz | 2022-08-07 17:20:15 +0200 |
---|---|---|
committer | dzwdz | 2022-08-07 17:20:15 +0200 |
commit | 287d76fe313093f6d25fb82da4beda6174e7d5c6 (patch) | |
tree | dc6dcdd06c7662186dc26af73da54793c0af572e /src | |
parent | 9592773ed84caae01bd23150c52f083c1200092f (diff) |
user/tmpfs: expand files on the fly
Diffstat (limited to 'src')
-rw-r--r-- | src/user/app/init/driver/tmpfs.c | 14 |
1 files changed, 10 insertions, 4 deletions
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); |