1
0
mirror of https://github.com/falk-werner/webfused synced 2026-03-02 04:09:19 +00:00

allow to specify mount options

This commit is contained in:
Falk Werner
2020-11-13 19:29:03 +01:00
parent 3c14ba1cae
commit d8879cf1d9
24 changed files with 377 additions and 136 deletions

View File

@@ -112,8 +112,8 @@ wfd_config_add_auth_provider(
if (result)
{
wf_server_config_add_authenticator(
config->server,
wfd_authenticator_get_type(config->authenticator),
config->server,
wfd_authenticator_get_type(config->authenticator),
config->authenticator.vtable->authenticate,
config->authenticator.data);
@@ -128,10 +128,11 @@ bool
wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point)
char const * mount_point,
struct wfd_string_list const * mount_options)
{
return wfd_mountpoint_factory_add_filesystem(
config->mountpoint_factory, name, mount_point);
config->mountpoint_factory, name, mount_point, mount_options);
}
bool
@@ -174,4 +175,3 @@ wfd_config_get_group(
{
return config->group;
}

View File

@@ -13,6 +13,12 @@ extern "C"
{
#endif
#define WFD_CONFIG_VERSION_MAJOR 1
#define WFD_CONFIG_VERSION_MINOR 1
#define WFD_CONFIG_VERSION_STR_MAJOR "1"
#define WFD_CONFIG_VERSION_STR_MINOR "1"
struct wfd_config;
struct wf_server_config;

View File

@@ -12,6 +12,7 @@ extern "C"
struct wfd_settings;
struct wfd_config;
struct wfd_string_list;
extern struct wfd_config *
wfd_config_create(void);
@@ -51,7 +52,8 @@ extern bool
wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point);
char const * mount_point,
struct wfd_string_list const * mount_options);
extern bool
wfd_config_set_logger(

View File

@@ -3,6 +3,7 @@
#include "webfused/config/config.h"
#include "webfused/config/settings_intern.h"
#include "webfused/log/log.h"
#include "webfused/util/string_list.h"
#include <libconfig.h>
#include <stdlib.h>
@@ -13,10 +14,6 @@
#error "libconfig 1.5 or higher needed"
#endif
#define WFD_CONFIG_VERSION_MAJOR 1
#define WFD_CONFIG_VERSION_MINOR 0
static bool
wfd_config_check_version(
config_t * config)
@@ -217,6 +214,26 @@ wfd_config_read_authentication(
return result;
}
static void
wfd_config_read_mountoptions(
config_setting_t * filesystem,
struct wfd_string_list * mount_options)
{
config_setting_t * list = config_setting_get_member(filesystem, "mountpoint_options");
if ((NULL != list) && (CONFIG_TRUE == config_setting_is_list(list)))
{
int length = config_setting_length(list);
for (int i = 0; i < length; i++)
{
char const * option = config_setting_get_string_elem(list, i);
if (NULL != option)
{
wfd_string_list_add(mount_options, option);
}
}
}
}
static bool
wfd_config_read_filesystems(
config_t * config,
@@ -255,7 +272,12 @@ wfd_config_read_filesystems(
break;
}
result = wfd_config_add_filesystem(builder, name, mount_point);
struct wfd_string_list mount_options;
wfd_string_list_init(&mount_options);
wfd_config_read_mountoptions(fs, &mount_options);
result = wfd_config_add_filesystem(builder, name, mount_point, &mount_options);
wfd_string_list_cleanup(&mount_options);
if (!result)
{
break;

View File

@@ -118,6 +118,7 @@ wfd_syslog_logger_init(
}
else
{
free(ident);
WFD_ERROR("failed to init syslog logger: invalid log facility: \'%s\'", facility_str);
}

View File

@@ -1,4 +1,5 @@
#include "webfused/mountpoint_factory.h"
#include "webfused/util/string_list.h"
#include "webfused/log/log.h"
#include <webfuse/mountpoint.h>
@@ -13,6 +14,7 @@ struct wfd_filesystem
{
char * name;
char * mount_point;
struct wfd_string_list mount_options;
bool in_use;
};
@@ -40,7 +42,7 @@ wfd_mountpoint_factory_find(
return NULL;
}
static void
static void
wfd_mountpoint_factory_release_mountpoint(
void * user_data)
{
@@ -68,6 +70,7 @@ wfd_mountpoint_factory_dispose(
struct wfd_filesystem * filesystem = &(factory->filesystems[i]);
free(filesystem->name);
free(filesystem->mount_point);
wfd_string_list_cleanup(&filesystem->mount_options);
}
free(factory->filesystems);
@@ -78,7 +81,8 @@ bool
wfd_mountpoint_factory_add_filesystem(
struct wfd_mountpoint_factory * factory,
char const * name,
char const * mount_point)
char const * mount_point,
struct wfd_string_list const * mount_options)
{
bool result = (NULL == wfd_mountpoint_factory_find(factory, name));
if (!result)
@@ -103,13 +107,14 @@ wfd_mountpoint_factory_add_filesystem(
if (factory->count >= factory->capacity)
{
factory->capacity *= 2;
factory->filesystems = realloc(factory->filesystems,
factory->filesystems = realloc(factory->filesystems,
sizeof(struct wfd_filesystem) * factory->capacity);
}
struct wfd_filesystem * actual = &(factory->filesystems[factory->count]);
actual->name = strdup(name);
actual->mount_point = path;
wfd_string_list_init_copy(&actual->mount_options, mount_options);
actual->in_use = false;
factory->count++;
}
@@ -140,6 +145,10 @@ wfd_mountpoint_factory_create_mountpoint(
struct wf_mountpoint * result = wf_mountpoint_create(fs->mount_point);
wf_mountpoint_set_userdata(result,
&fs->in_use, &wfd_mountpoint_factory_release_mountpoint);
for (size_t i = 0; i < fs->mount_options.size; i++)
{
wf_mountpoint_add_mountoption(result, fs->mount_options.items[i]);
}
WFD_INFO("created mountpoint \'%s\' at path \'%s\'", filesystem, fs->mount_point);
return result;

View File

@@ -13,6 +13,7 @@ extern "C"
#endif
struct wfd_mountpoint_factory;
struct wfd_string_list;
extern struct wfd_mountpoint_factory *
wfd_mountpoint_factory_create(void);
@@ -25,7 +26,8 @@ extern bool
wfd_mountpoint_factory_add_filesystem(
struct wfd_mountpoint_factory * factory,
char const * name,
char const * mount_point);
char const * mount_point,
struct wfd_string_list const * mount_options);
extern struct wf_mountpoint *
wfd_mountpoint_factory_create_mountpoint(

View File

@@ -0,0 +1,59 @@
#include "webfused/util/string_list.h"
#include <stdlib.h>
#include <string.h>
#define WFD_STRING_LIST_INITIAL_CAPACITY 8
void
wfd_string_list_init(
struct wfd_string_list * list)
{
list->size = 0;
list->capacity = WFD_STRING_LIST_INITIAL_CAPACITY;
list->items = malloc(sizeof(char *) * list->capacity);
}
void
wfd_string_list_init_copy(
struct wfd_string_list * list,
struct wfd_string_list const * other)
{
if (0 < other->size)
{
list->size = other->size;
list->capacity = other->capacity;
list->items = malloc(sizeof(char *) * list->capacity);
memcpy(list->items, other->items, (sizeof(char*) * list->size));
}
else
{
wfd_string_list_init(list);
}
}
void
wfd_string_list_cleanup(
struct wfd_string_list * list)
{
for (size_t i = 0; i < list->size; i++)
{
free(list->items[i]);
}
free(list->items);
}
void
wfd_string_list_add(
struct wfd_string_list * list,
char const * item)
{
if (list->size >= list->capacity)
{
list->capacity *= 2;
list->items = realloc(list->items, sizeof(char *) * list->capacity);
}
list->items[list->size] = strdup(item);
list->size++;
}

View File

@@ -0,0 +1,44 @@
#ifndef WFD_UTIL_STRING_LIST_H
#define WFD_UTIL_STRING_LIST_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_string_list
{
size_t size;
size_t capacity;
char * * items;
};
extern void
wfd_string_list_init(
struct wfd_string_list * list);
extern void
wfd_string_list_init_copy(
struct wfd_string_list * list,
struct wfd_string_list const * other);
extern void
wfd_string_list_cleanup(
struct wfd_string_list * list);
extern void
wfd_string_list_add(
struct wfd_string_list * list,
char const * item);
#ifdef __cplusplus
}
#endif
#endif