2020-06-28 13:51:34 +00:00
|
|
|
#include "webfuse/impl/mountpoint.h"
|
2020-02-15 14:11:35 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-11-13 03:43:46 +00:00
|
|
|
#define WF_MOUNTOPTIONS_INITIAL_CAPACITY 8
|
2020-02-15 14:11:35 +00:00
|
|
|
|
|
|
|
struct wf_mountpoint *
|
|
|
|
wf_impl_mountpoint_create(
|
|
|
|
char const * path)
|
|
|
|
{
|
|
|
|
struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint));
|
|
|
|
mountpoint->path = strdup(path);
|
2020-02-16 03:02:23 +00:00
|
|
|
mountpoint->user_data = NULL;
|
|
|
|
mountpoint->dispose = NULL;
|
2020-11-13 03:43:46 +00:00
|
|
|
mountpoint->options.size = 1;
|
|
|
|
mountpoint->options.capacity = WF_MOUNTOPTIONS_INITIAL_CAPACITY;
|
|
|
|
mountpoint->options.items = malloc(sizeof(char*) * mountpoint->options.capacity);
|
|
|
|
mountpoint->options.items[0] = strdup("");
|
|
|
|
mountpoint->options.items[1] = NULL;
|
2020-02-15 14:11:35 +00:00
|
|
|
|
|
|
|
return mountpoint;
|
|
|
|
}
|
|
|
|
|
2020-11-13 03:43:46 +00:00
|
|
|
void
|
2020-02-15 14:11:35 +00:00
|
|
|
wf_impl_mountpoint_dispose(
|
|
|
|
struct wf_mountpoint * mountpoint)
|
|
|
|
{
|
2020-02-16 03:02:23 +00:00
|
|
|
if (NULL != mountpoint->dispose)
|
|
|
|
{
|
|
|
|
mountpoint->dispose(mountpoint->user_data);
|
|
|
|
}
|
2020-02-15 14:50:32 +00:00
|
|
|
|
2020-11-13 03:43:46 +00:00
|
|
|
for(size_t i = 0; i < mountpoint->options.size; i++)
|
|
|
|
{
|
|
|
|
free(mountpoint->options.items[i]);
|
|
|
|
}
|
|
|
|
free(mountpoint->options.items);
|
|
|
|
|
2020-02-15 14:11:35 +00:00
|
|
|
free(mountpoint->path);
|
|
|
|
free(mountpoint);
|
|
|
|
}
|
|
|
|
|
2020-11-13 03:43:46 +00:00
|
|
|
char const *
|
2020-02-15 14:11:35 +00:00
|
|
|
wf_impl_mountpoint_get_path(
|
|
|
|
struct wf_mountpoint const * mountpoint)
|
|
|
|
{
|
|
|
|
return mountpoint->path;
|
|
|
|
}
|
2020-02-15 14:50:32 +00:00
|
|
|
|
2020-02-16 03:02:23 +00:00
|
|
|
extern void
|
|
|
|
wf_impl_mountpoint_set_userdata(
|
2020-02-15 14:50:32 +00:00
|
|
|
struct wf_mountpoint * mountpoint,
|
2020-02-16 03:02:23 +00:00
|
|
|
void * user_data,
|
|
|
|
wf_mountpoint_userdata_dispose_fn * dispose)
|
2020-02-15 14:50:32 +00:00
|
|
|
{
|
2020-02-16 03:02:23 +00:00
|
|
|
mountpoint->user_data = user_data;
|
|
|
|
mountpoint->dispose = dispose;
|
2020-02-15 14:50:32 +00:00
|
|
|
}
|
2020-11-13 03:43:46 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
wf_impl_mountpoint_add_mountoption(
|
|
|
|
struct wf_mountpoint * mountpoint,
|
|
|
|
char const * option)
|
|
|
|
{
|
|
|
|
if ((mountpoint->options.size + 1) >= mountpoint->options.capacity)
|
|
|
|
{
|
|
|
|
mountpoint->options.capacity *= 2;
|
|
|
|
mountpoint->options.items = realloc(mountpoint->options.items,
|
|
|
|
sizeof(char*) * mountpoint->options.capacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
mountpoint->options.items[mountpoint->options.size] = strdup(option);
|
|
|
|
mountpoint->options.items[mountpoint->options.size + 1] = NULL;
|
|
|
|
mountpoint->options.size++;
|
|
|
|
}
|