From 77ede52c9237e526217bc28a9674b1d7a44d8b18 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 13 Nov 2020 04:03:05 +0100 Subject: [PATCH 1/6] fix: set C/C++ versions to make unit tests compile on systems where gnu++11 (or higher) is not default --- meson.build | 5 +++-- test/webfuse/test_util/ws_client.cc | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index 7672adb..b2d8545 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,5 @@ -project('webfuse', 'c', 'cpp', version: '0.7.0', license: 'LGPL-3.0+') +project('webfuse', 'c', 'cpp', version: '0.7.0', license: 'LGPL-3.0+', + default_options: ['c_std=gnu99', 'cpp_std=gnu++14']) without_tests = get_option('without_tests') @@ -96,7 +97,7 @@ pkg_config.generate( if not without_tests -gtest_dep = dependency('gtest', version: '>=1.10.0', fallback: ['gtest', 'gtest_dep']) +gtest_dep = dependency('gtest', version: '>=1.10.0', fallback: ['gtest', 'gtest_dep']) gmock_main_dep = dependency('gmock_main', version: '>=1.10.0', fallback: ['gtest', 'gmock_main_dep']) fscheck = executable('fs_check', diff --git a/test/webfuse/test_util/ws_client.cc b/test/webfuse/test_util/ws_client.cc index af9cda2..9f5c7c3 100644 --- a/test/webfuse/test_util/ws_client.cc +++ b/test/webfuse/test_util/ws_client.cc @@ -145,7 +145,7 @@ public: lws_cancel_service(context); lock.lock(); - convar.wait_for(lock, TIMEOUT, [&]() { + convar.wait_for(lock, TIMEOUT, [&]() { return (conn_state != connection_state::connecting); }); @@ -162,7 +162,7 @@ public: lws_cancel_service(context); lock.lock(); - convar.wait_for(lock, TIMEOUT, [&]() { + convar.wait_for(lock, TIMEOUT, [&]() { return (conn_state != connection_state::disconnecting); }); @@ -239,7 +239,7 @@ public: { std::string result_text = handler_.Invoke(wf_impl_json_string_get(method), params); if (result_text.empty()) { throw std::runtime_error("empty"); } - response << "\"result\": " << result_text; + response << "\"result\": " << result_text; } catch (...) { @@ -351,7 +351,7 @@ private: if (nullptr != wsi) { lws_callback_on_writable(wsi); - } + } } break; default: @@ -364,14 +364,14 @@ private: { std::unique_lock lock(mutex); - command command = command::run; + command actual_command = command::run; if (!commands.empty()) { - command = commands.front(); + actual_command = commands.front(); commands.pop(); } - return command; + return actual_command; } lws * wsi_; @@ -424,4 +424,4 @@ std::string WsClient::Invoke(std::string const & message) } -} \ No newline at end of file +} From 9f08154af98ad75138ddbd5282d9e39d16ebe56e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 13 Nov 2020 04:43:46 +0100 Subject: [PATCH 2/6] feature: allow to specify mount options --- include/webfuse/mountpoint.h | 18 ++++++++++++++-- lib/webfuse/api.c | 14 ++++++++++--- lib/webfuse/impl/filesystem.c | 14 ++++++------- lib/webfuse/impl/mountpoint.c | 39 ++++++++++++++++++++++++++++------- lib/webfuse/impl/mountpoint.h | 30 +++++++++++++++++++++++++-- 5 files changed, 92 insertions(+), 23 deletions(-) diff --git a/include/webfuse/mountpoint.h b/include/webfuse/mountpoint.h index 041e50a..d30f99a 100644 --- a/include/webfuse/mountpoint.h +++ b/include/webfuse/mountpoint.h @@ -45,7 +45,7 @@ wf_mountpoint_create( /// /// \param mountpoint pointer to the mountpoint //------------------------------------------------------------------------------ -extern WF_API void +extern WF_API void wf_mountpoint_dispose( struct wf_mountpoint * mountpoint); @@ -55,7 +55,7 @@ wf_mountpoint_dispose( /// \param mountpoint pointer to the mountpoint /// \return local path of the mountpoint //------------------------------------------------------------------------------ -extern WF_API char const * +extern WF_API char const * wf_mountpoint_get_path( struct wf_mountpoint const * mountpoint); @@ -76,6 +76,20 @@ wf_mountpoint_set_userdata( void * user_data, wf_mountpoint_userdata_dispose_fn * dispose); +//------------------------------------------------------------------------------ +/// \brief Adds a mount option. +/// +/// Mount options are passed to libfuse when a filesystem is mounted. +/// See libfuse documenation for allowed values. +/// +/// \param mountpoint pointer to the mountpooint +/// \param option value of the mount option +//------------------------------------------------------------------------------ +extern WF_API void +wf_mountpoint_add_mountoption( + struct wf_mountpoint * mountpoint, + char const * option); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/api.c b/lib/webfuse/api.c index 20a04bf..dea6449 100644 --- a/lib/webfuse/api.c +++ b/lib/webfuse/api.c @@ -140,7 +140,7 @@ void wf_server_config_add_authenticator( wf_impl_server_config_add_authenticator(config, type, authenticate, user_data); } -// credentials +// credentials char const * wf_credentials_type( struct wf_credentials const * credentials) @@ -179,14 +179,14 @@ wf_mountpoint_create( return wf_impl_mountpoint_create(path); } -void +void wf_mountpoint_dispose( struct wf_mountpoint * mountpoint) { wf_impl_mountpoint_dispose(mountpoint); } -char const * +char const * wf_mountpoint_get_path( struct wf_mountpoint const * mountpoint) { @@ -202,6 +202,14 @@ wf_mountpoint_set_userdata( wf_impl_mountpoint_set_userdata(mountpoint, user_data, dispose); } +void +wf_mountpoint_add_mountoption( + struct wf_mountpoint * mountpoint, + char const * option) +{ + wf_impl_mountpoint_add_mountoption(mountpoint, option); +} + // client struct wf_client * diff --git a/lib/webfuse/impl/filesystem.c b/lib/webfuse/impl/filesystem.c index ccb3ecd..4dabd55 100644 --- a/lib/webfuse/impl/filesystem.c +++ b/lib/webfuse/impl/filesystem.c @@ -37,17 +37,16 @@ static void wf_impl_filesystem_cleanup( fuse_session_reset(filesystem->session); fuse_session_unmount(filesystem->session); fuse_session_destroy(filesystem->session); - filesystem->session = NULL; + filesystem->session = NULL; free(filesystem->buffer.mem); - fuse_opt_free_args(&filesystem->args); + fuse_opt_free_args(&filesystem->args); wf_mountpoint_dispose(filesystem->mountpoint); free(filesystem->user_data.name); } - static bool wf_impl_filesystem_init( struct wf_impl_filesystem * filesystem, struct lws * session_wsi, @@ -56,10 +55,9 @@ static bool wf_impl_filesystem_init( struct wf_mountpoint * mountpoint) { bool result = false; - - char * argv[] = {"", NULL}; - filesystem->args.argc = 1; - filesystem->args.argv = argv; + + filesystem->args.argc = mountpoint->options.size; + filesystem->args.argv = mountpoint->options.items; filesystem->args.allocated = 0; filesystem->user_data.proxy = proxy; @@ -90,7 +88,7 @@ static bool wf_impl_filesystem_init( if (NULL == filesystem->wsi) { wf_impl_filesystem_cleanup(filesystem); - result = false; + result = false; } } diff --git a/lib/webfuse/impl/mountpoint.c b/lib/webfuse/impl/mountpoint.c index d11a116..5b98e1d 100644 --- a/lib/webfuse/impl/mountpoint.c +++ b/lib/webfuse/impl/mountpoint.c @@ -3,12 +3,7 @@ #include #include -struct wf_mountpoint -{ - char * path; - void * user_data; - wf_mountpoint_userdata_dispose_fn * dispose; -}; +#define WF_MOUNTOPTIONS_INITIAL_CAPACITY 8 struct wf_mountpoint * wf_impl_mountpoint_create( @@ -18,11 +13,16 @@ wf_impl_mountpoint_create( mountpoint->path = strdup(path); mountpoint->user_data = NULL; mountpoint->dispose = NULL; + 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; return mountpoint; } -void +void wf_impl_mountpoint_dispose( struct wf_mountpoint * mountpoint) { @@ -31,11 +31,17 @@ wf_impl_mountpoint_dispose( mountpoint->dispose(mountpoint->user_data); } + for(size_t i = 0; i < mountpoint->options.size; i++) + { + free(mountpoint->options.items[i]); + } + free(mountpoint->options.items); + free(mountpoint->path); free(mountpoint); } -char const * +char const * wf_impl_mountpoint_get_path( struct wf_mountpoint const * mountpoint) { @@ -51,3 +57,20 @@ wf_impl_mountpoint_set_userdata( mountpoint->user_data = user_data; mountpoint->dispose = dispose; } + +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++; +} diff --git a/lib/webfuse/impl/mountpoint.h b/lib/webfuse/impl/mountpoint.h index 5461284..2e311b2 100644 --- a/lib/webfuse/impl/mountpoint.h +++ b/lib/webfuse/impl/mountpoint.h @@ -3,20 +3,41 @@ #include "webfuse/mountpoint.h" +#ifndef __cplusplus +#include +#else +#include +#endif + #ifdef __cplusplus extern "C" { #endif +struct wf_mountoptions +{ + char * * items; + size_t size; + size_t capacity; +}; + +struct wf_mountpoint +{ + char * path; + void * user_data; + wf_mountpoint_userdata_dispose_fn * dispose; + struct wf_mountoptions options; +}; + extern struct wf_mountpoint * wf_impl_mountpoint_create( char const * path); -extern void +extern void wf_impl_mountpoint_dispose( struct wf_mountpoint * mountpoint); -extern char const * +extern char const * wf_impl_mountpoint_get_path( struct wf_mountpoint const * mountpoint); @@ -26,6 +47,11 @@ wf_impl_mountpoint_set_userdata( void * user_data, wf_mountpoint_userdata_dispose_fn * dispose); +extern void +wf_impl_mountpoint_add_mountoption( + struct wf_mountpoint * mountpoint, + char const * option); + #ifdef __cplusplus } #endif From 52c69dfb4dd1b9de0678d477fdd6558354ea03a4 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 13 Nov 2020 11:08:40 +0100 Subject: [PATCH 3/6] chore: allow to pass mount options --- changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index eb2d665..6b58c88 100644 --- a/changelog.md +++ b/changelog.md @@ -2,10 +2,13 @@ ## 0.7.0 _(unknown)_ +* __Feature:__ Allow to pass mount options to fuse +* __Fix:__ Set C/C++ compiler version + ## 0.6.0 _(Wed Nov 11 2020)_ * __Feature:__ Reduce version numbers of dependencies to required minimum -* __Fix:__ Remove obsolete ping_pong interval (compatibility with newer versions of libwebsockets) +* __Fix:__ Remove obsolete ping_pong interval (compatibility with newer versions of libwebsockets) ## 0.5.0 _(Sun Jul 19 2020)_ From db10f944beb6f5765ed1ea5ba039da0bd618523e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 13 Nov 2020 11:09:03 +0100 Subject: [PATCH 4/6] chore: added unit tests for mount options --- test/webfuse/test_mountpoint.cc | 48 ++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/test/webfuse/test_mountpoint.cc b/test/webfuse/test_mountpoint.cc index 381c236..ac42410 100644 --- a/test/webfuse/test_mountpoint.cc +++ b/test/webfuse/test_mountpoint.cc @@ -1,6 +1,7 @@ #include #include #include "webfuse/mountpoint.h" +#include "webfuse/impl/mountpoint.h" namespace { @@ -44,4 +45,49 @@ TEST(mountpoint, ondispose) EXPECT_CALL(disposer, dispose(user_data)).Times(1); wf_mountpoint_dispose(mountpoint); -} \ No newline at end of file +} + +TEST(mountpoint, default_options) +{ + wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); + ASSERT_EQ(1, mountpoint->options.size); + ASSERT_STREQ("", mountpoint->options.items[0]); + ASSERT_EQ(nullptr, mountpoint->options.items[1]); + + wf_mountpoint_dispose(mountpoint); +} + +TEST(mountpoint, add_mountoption) +{ + wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); + wf_mountpoint_add_mountoption(mountpoint, "-o"); + wf_mountpoint_add_mountoption(mountpoint, "allow_other"); + + ASSERT_EQ(3, mountpoint->options.size); + ASSERT_STREQ("", mountpoint->options.items[0]); + ASSERT_STREQ("-o", mountpoint->options.items[1]); + ASSERT_STREQ("allow_other", mountpoint->options.items[2]); + ASSERT_EQ(nullptr, mountpoint->options.items[3]); + + wf_mountpoint_dispose(mountpoint); +} + +TEST(mountpoint, add_many_mountoption) +{ + wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path"); + constexpr size_t count = 256; + for (size_t i = 0; i < count; i++) + { + wf_mountpoint_add_mountoption(mountpoint, "any option"); + } + + ASSERT_EQ(count + 1, mountpoint->options.size); + ASSERT_STREQ("", mountpoint->options.items[0]); + for (size_t i = 0; i < count; i++) + { + ASSERT_STREQ("any option", mountpoint->options.items[i + 1]); + } + ASSERT_EQ(nullptr, mountpoint->options.items[count + 1]); + + wf_mountpoint_dispose(mountpoint); +} From bbb1eec9e8b0c116712823767ed7a9d0b718d341 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 13 Nov 2020 21:54:21 +0100 Subject: [PATCH 5/6] updated changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 6b58c88..2d10875 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ # webfuse changelog -## 0.7.0 _(unknown)_ +## 0.7.0 _(Fri Nov 13 2020)_ * __Feature:__ Allow to pass mount options to fuse * __Fix:__ Set C/C++ compiler version From 19bd4077617b1c159846c6ef0cf4c0dca54dbc9a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 14 Nov 2020 09:16:56 +0100 Subject: [PATCH 6/6] updated changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 2d10875..8fde872 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,6 @@ # webfuse changelog -## 0.7.0 _(Fri Nov 13 2020)_ +## 0.7.0 _(Sat Nov 14 2020)_ * __Feature:__ Allow to pass mount options to fuse * __Fix:__ Set C/C++ compiler version