From 92d8f939acc5f2c4c8a58437ced67b479216b373 Mon Sep 17 00:00:00 2001 From: Francis Banyikwa Date: Thu, 2 Jun 2016 12:51:44 +0300 Subject: [PATCH] move setting of fuse options to Fuse class --- src/cryfs-cli/Cli.cpp | 2 +- .../program_options/ProgramOptions.cpp | 14 ------------ src/fspp/fuse/Fuse.cpp | 22 ++++++++++++++++--- src/fspp/fuse/Fuse.h | 3 ++- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/cryfs-cli/Cli.cpp b/src/cryfs-cli/Cli.cpp index dedd2e9c..1a027f9c 100644 --- a/src/cryfs-cli/Cli.cpp +++ b/src/cryfs-cli/Cli.cpp @@ -227,7 +227,7 @@ namespace cryfs { CryDevice device(std::move(config), std::move(blockStore)); _sanityCheckFilesystem(&device); fspp::FilesystemImpl fsimpl(&device); - fspp::fuse::Fuse fuse(&fsimpl, "cryfs"); + fspp::fuse::Fuse fuse(&fsimpl, "cryfs", "cryfs@"+options.baseDir().native()); _initLogfile(options); diff --git a/src/cryfs-cli/program_options/ProgramOptions.cpp b/src/cryfs-cli/program_options/ProgramOptions.cpp index dc8466d7..83d7cd84 100644 --- a/src/cryfs-cli/program_options/ProgramOptions.cpp +++ b/src/cryfs-cli/program_options/ProgramOptions.cpp @@ -16,20 +16,6 @@ ProgramOptions::ProgramOptions(const bf::path &baseDir, const bf::path &mountDir :_baseDir(baseDir), _mountDir(mountDir), _configFile(configFile), _foreground(foreground), _cipher(cipher), _blocksizeBytes(blocksizeBytes), _unmountAfterIdleMinutes(unmountAfterIdleMinutes), _logFile(logFile), _fuseOptions(fuseOptions) { - - auto hasNoOption = [&](const char *opt) { - for (const string& it : _fuseOptions) { - if (std::strncmp(it.c_str(), opt, std::strlen(opt))) { - return false; - } - } - return true; - }; - - if (hasNoOption("subtype=cryfs") && hasNoOption("fsname=cryfs@")) { - _fuseOptions.push_back("-ofsname=cryfs@"+baseDir.native()); - _fuseOptions.push_back("-osubtype=cryfs"); - } } const bf::path &ProgramOptions::baseDir() const { diff --git a/src/fspp/fuse/Fuse.cpp b/src/fspp/fuse/Fuse.cpp index 9a12e83a..04644b8f 100644 --- a/src/fspp/fuse/Fuse.cpp +++ b/src/fspp/fuse/Fuse.cpp @@ -217,8 +217,8 @@ Fuse::~Fuse() { _argv.clear(); } -Fuse::Fuse(Filesystem *fs, const std::string &fsname) - :_fs(fs), _mountdir(), _running(false), _fsname(fsname) { +Fuse::Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname) + :_fs(fs), _mountdir(), _running(false), _fstype(fstype), _fsname(fsname) { } void Fuse::_logException(const std::exception &e) { @@ -235,11 +235,27 @@ void Fuse::run(const bf::path &mountdir, const vector &fuseOptions) { ASSERT(_argv.size() == 0, "Filesystem already started"); _argv.reserve(2 + fuseOptions.size()); - _argv.push_back(_create_c_string(_fsname)); // The first argument is the file system name + _argv.push_back(_create_c_string(_fstype)); // The first argument is the file system name _argv.push_back(_create_c_string(mountdir.native())); // The second argument is the mountdir for (const string &option : fuseOptions) { _argv.push_back(_create_c_string(option)); } + if(!_fsname.empty()) { + auto hasNoOption = [&](const char *opt) { + for (const string& it : fuseOptions) { + if (std::strncmp(it.c_str(), opt, std::strlen(opt))) { + return false; + } + } + return true; + }; + if (hasNoOption("subtype=") && hasNoOption("fsname=")) { + _argv.push_back(_create_c_string("-o")); + _argv.push_back(_create_c_string("fsname="+_fsname)); + _argv.push_back(_create_c_string("-o")); + _argv.push_back(_create_c_string("subtype="+_fstype)); + } + } fuse_main(_argv.size(), _argv.data(), operations(), (void*)this); } diff --git a/src/fspp/fuse/Fuse.h b/src/fspp/fuse/Fuse.h index c94feb25..db132d02 100644 --- a/src/fspp/fuse/Fuse.h +++ b/src/fspp/fuse/Fuse.h @@ -18,7 +18,7 @@ class Filesystem; class Fuse final { public: - explicit Fuse(Filesystem *fs, const std::string &fsname); + explicit Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname=std::string()); ~Fuse(); void run(const boost::filesystem::path &mountdir, const std::vector &fuseOptions); @@ -65,6 +65,7 @@ private: boost::filesystem::path _mountdir; std::vector _argv; bool _running; + std::string _fstype; std::string _fsname; DISALLOW_COPY_AND_ASSIGN(Fuse);