1
0
mirror of https://github.com/falk-werner/webfuse synced 2025-06-13 12:54:15 +00:00

resize filesystem if necessary

This commit is contained in:
Falk Werner 2019-04-19 20:02:38 +02:00
parent 579820c21f
commit 060461a704

View File

@ -3,7 +3,6 @@
#include "webfuse/provider/dirbuffer.h" #include "webfuse/provider/dirbuffer.h"
#include "webfuse/provider/operation/error.h" #include "webfuse/provider/operation/error.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
@ -72,18 +71,27 @@ wfp_static_filesystem_add_entry(
{ {
struct wfp_static_filesystem_entry * entry = NULL; struct wfp_static_filesystem_entry * entry = NULL;
if (filesystem->size >= filesystem->capacity)
{
struct wfp_static_filesystem_entry * entries;
size_t new_capacity = 2 * filesystem->capacity;
size_t new_size = new_capacity * sizeof(struct wfp_static_filesystem_entry);
entries = realloc(filesystem->entries, new_size);
if (NULL != entries)
{
filesystem->entries = entries;
filesystem->capacity = new_capacity;
}
}
if (filesystem->size < filesystem->capacity) if (filesystem->size < filesystem->capacity)
{ {
entry = &filesystem->entries[filesystem->size]; entry = &filesystem->entries[filesystem->size];
entry->inode = filesystem->size + 1; entry->inode = filesystem->size + 1;
filesystem->size++; filesystem->size++;
} }
else
{
fprintf(stderr, "fatal: static filessystem: unable to add entry\n");
exit(EXIT_FAILURE);
}
return entry; return entry;
} }