mirror of
				https://github.com/falk-werner/webfuse
				synced 2025-06-13 12:54:15 +00:00 
			
		
		
		
	Merge pull request #94 from falk-werner/allow_mount_options
Allow to pass mount options
This commit is contained in:
		
						commit
						2f233a45ed
					
				| @ -1,6 +1,9 @@ | ||||
| # webfuse changelog | ||||
| 
 | ||||
| ## 0.7.0 _(unknown)_ | ||||
| ## 0.7.0 _(Sat Nov 14 2020)_ | ||||
| 
 | ||||
| *   __Feature:__ Allow to pass mount options to fuse | ||||
| *   __Fix:__ Set C/C++ compiler version | ||||
| 
 | ||||
| ## 0.6.0 _(Wed Nov 11 2020)_ | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 * | ||||
|  | ||||
| @ -47,7 +47,6 @@ static void wf_impl_filesystem_cleanup( | ||||
| 	free(filesystem->user_data.name); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| static bool wf_impl_filesystem_init( | ||||
|     struct wf_impl_filesystem * filesystem, | ||||
|     struct lws * session_wsi, | ||||
| @ -57,9 +56,8 @@ static bool wf_impl_filesystem_init( | ||||
| { | ||||
| 	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; | ||||
|  | ||||
| @ -3,12 +3,7 @@ | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| 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,6 +13,11 @@ 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; | ||||
| } | ||||
| @ -31,6 +31,12 @@ 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); | ||||
| } | ||||
| @ -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++; | ||||
| } | ||||
|  | ||||
| @ -3,11 +3,32 @@ | ||||
| 
 | ||||
| #include "webfuse/mountpoint.h" | ||||
| 
 | ||||
| #ifndef __cplusplus | ||||
| #include <stddef.h> | ||||
| #else | ||||
| #include <cstddef> | ||||
| #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); | ||||
| @ -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 | ||||
|  | ||||
| @ -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') | ||||
| 
 | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| #include <gtest/gtest.h> | ||||
| #include <gmock/gmock.h> | ||||
| #include "webfuse/mountpoint.h" | ||||
| #include "webfuse/impl/mountpoint.h" | ||||
| 
 | ||||
| namespace | ||||
| { | ||||
| @ -45,3 +46,48 @@ TEST(mountpoint, ondispose) | ||||
| 
 | ||||
|     wf_mountpoint_dispose(mountpoint); | ||||
| } | ||||
| 
 | ||||
| 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); | ||||
| } | ||||
|  | ||||
| @ -364,14 +364,14 @@ private: | ||||
|     { | ||||
|         std::unique_lock<std::mutex> 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_; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user