From bb10b4d5406d09ff3afb476e0d251c6569e36844 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sun, 19 Oct 2025 16:48:19 -0500 Subject: [PATCH] option_parser.cpp --- src/config.cpp | 14 ++++++++++ src/config.hpp | 8 ++++-- src/option_parser.cpp | 65 +++++++++++++++---------------------------- 3 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index ae9039e3..554d3685 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -251,6 +251,20 @@ Config::Config() _map["umask"] = &umask; _map["version"] = &version; _map["xattr"] = &xattr; + + _map["atomic_o_trunc"] = + _map["big_writes"] = + _map["cache.open"] = + _map["defaults"] = + _map["hard_remove"] = + _map["no_splice_move"] = + _map["no_split_write"] = + _map["nonempty"] = + _map["splice_move"] = + _map["splice_read"] = + _map["splice_write"] = + _map["use_ino"] = + &_dummy; } Config& diff --git a/src/config.hpp b/src/config.hpp index ee171bb6..9e2b9d75 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -16,11 +16,10 @@ #pragma once -#include "fuse_cfg.hpp" -#include "tofrom_ref.hpp" #include "branches.hpp" #include "category.hpp" #include "config_cachefiles.hpp" +#include "config_dummy.hpp" #include "config_flushonclose.hpp" #include "config_follow_symlinks.hpp" #include "config_gidcache.hpp" @@ -42,9 +41,11 @@ #include "errno.hpp" #include "fs_path.hpp" #include "funcs.hpp" +#include "fuse_cfg.hpp" #include "fuse_readdir.hpp" #include "policy.hpp" #include "rwlock.hpp" +#include "tofrom_ref.hpp" #include "tofrom_wrapper.hpp" #include "fuse.h" @@ -160,6 +161,9 @@ public: ConfigROSTR version; XAttr xattr; +private: + CfgDummy _dummy; + private: bool _initialized; diff --git a/src/option_parser.cpp b/src/option_parser.cpp index ee21fd6c..9450c153 100644 --- a/src/option_parser.cpp +++ b/src/option_parser.cpp @@ -52,6 +52,17 @@ enum MERGERFS_OPT_VERSION }; +struct KV +{ + std::string key; + std::string val; +}; + +struct OptData +{ + std::vector opts; + Config::ErrVec *errs; +}; static void @@ -113,39 +124,9 @@ _set_default_options(fuse_args *args_) SysLog::notice("not auto setting allow_other since not running as root"); } -static -bool -_should_ignore(const std::string &key_) -{ - constexpr const std::array ignored_keys = - { - "atomic_o_trunc", - "big_writes", - "cache.open", - "defaults", - "hard_remove", - "no_splice_move", - "no_splice_read", - "no_splice_write", - "nonempty", - "splice_move", - "splice_read", - "splice_write", - "use_ino", - }; - - for(const auto &key : ignored_keys) - { - if(key == key_) - return true; - } - - return false; -} - static int -_parse_and_process_kv_arg(Config::ErrVec *errs_, +_parse_and_process_kv_arg(OptData *optdata_, const std::string &key_, const std::string &val_) { @@ -155,7 +136,7 @@ _parse_and_process_kv_arg(Config::ErrVec *errs_, rv = 0; if(key == "config") - return ((cfg.from_file(val_,errs_) < 0) ? 1 : 0); + return ((cfg.from_file(val_,optdata_->errs) < 0) ? 1 : 0); ef(key == "attr_timeout") key = "cache.attr"; ef(key == "entry_timeout") @@ -174,22 +155,20 @@ _parse_and_process_kv_arg(Config::ErrVec *errs_, {key = "async_read", val = "false";} ef(key == "noforget" && val.empty()) {key = "remember-nodes", val = "-1";} - ef(::_should_ignore(key_)) - return 0; if(cfg.has_key(key) == false) return 1; rv = cfg.set(key,val); if(rv) - errs_->push_back({rv,key+'='+val}); + optdata_->errs->push_back({rv,key+'='+val}); return 0; } static int -_process_opt(Config::ErrVec *errs_, +_process_opt(OptData *optdata_, const std::string &arg_) { std::string key; @@ -199,7 +178,7 @@ _process_opt(Config::ErrVec *errs_, key = str::trim(key); val = str::trim(val); - return ::_parse_and_process_kv_arg(errs_,key,val); + return ::_parse_and_process_kv_arg(optdata_,key,val); } static @@ -277,18 +256,18 @@ _option_processor(void *data_, int key_, fuse_args *outargs_) { - Config::ErrVec *errs = (Config::ErrVec*)data_; + OptData &optdata = *(OptData*)data_; switch(key_) { case FUSE_OPT_KEY_OPT: - return ::_process_opt(errs,arg_); + return ::_process_opt(&optdata,arg_); case FUSE_OPT_KEY_NONOPT: if(cfg.branches->empty()) - return ::_process_branches(errs,arg_); + return ::_process_branches(optdata.errs,arg_); else - return ::_process_mount(errs,arg_); + return ::_process_mount(optdata.errs,arg_); case MERGERFS_OPT_HELP: ::_usage(); @@ -398,6 +377,7 @@ namespace options parse(fuse_args *args_, Config::ErrVec *errs_) { + OptData optdata; const struct fuse_opt opts[] = { FUSE_OPT_KEY("-h",MERGERFS_OPT_HELP), @@ -408,8 +388,9 @@ namespace options {NULL,-1U,0} }; + optdata.errs = errs_; fuse_opt_parse(args_, - errs_, + &optdata, opts, ::_option_processor);