move setting of fuse options to Fuse class

This commit is contained in:
Francis Banyikwa 2016-06-02 12:51:44 +03:00
parent 183d6a9d06
commit 92d8f939ac
4 changed files with 22 additions and 19 deletions

View File

@ -227,7 +227,7 @@ namespace cryfs {
CryDevice device(std::move(config), std::move(blockStore)); CryDevice device(std::move(config), std::move(blockStore));
_sanityCheckFilesystem(&device); _sanityCheckFilesystem(&device);
fspp::FilesystemImpl fsimpl(&device); fspp::FilesystemImpl fsimpl(&device);
fspp::fuse::Fuse fuse(&fsimpl, "cryfs"); fspp::fuse::Fuse fuse(&fsimpl, "cryfs", "cryfs@"+options.baseDir().native());
_initLogfile(options); _initLogfile(options);

View File

@ -16,20 +16,6 @@ ProgramOptions::ProgramOptions(const bf::path &baseDir, const bf::path &mountDir
:_baseDir(baseDir), _mountDir(mountDir), _configFile(configFile), _foreground(foreground), :_baseDir(baseDir), _mountDir(mountDir), _configFile(configFile), _foreground(foreground),
_cipher(cipher), _blocksizeBytes(blocksizeBytes), _unmountAfterIdleMinutes(unmountAfterIdleMinutes), _cipher(cipher), _blocksizeBytes(blocksizeBytes), _unmountAfterIdleMinutes(unmountAfterIdleMinutes),
_logFile(logFile), _fuseOptions(fuseOptions) { _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 { const bf::path &ProgramOptions::baseDir() const {

View File

@ -217,8 +217,8 @@ Fuse::~Fuse() {
_argv.clear(); _argv.clear();
} }
Fuse::Fuse(Filesystem *fs, const std::string &fsname) Fuse::Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname)
:_fs(fs), _mountdir(), _running(false), _fsname(fsname) { :_fs(fs), _mountdir(), _running(false), _fstype(fstype), _fsname(fsname) {
} }
void Fuse::_logException(const std::exception &e) { void Fuse::_logException(const std::exception &e) {
@ -235,11 +235,27 @@ void Fuse::run(const bf::path &mountdir, const vector<string> &fuseOptions) {
ASSERT(_argv.size() == 0, "Filesystem already started"); ASSERT(_argv.size() == 0, "Filesystem already started");
_argv.reserve(2 + fuseOptions.size()); _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 _argv.push_back(_create_c_string(mountdir.native())); // The second argument is the mountdir
for (const string &option : fuseOptions) { for (const string &option : fuseOptions) {
_argv.push_back(_create_c_string(option)); _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); fuse_main(_argv.size(), _argv.data(), operations(), (void*)this);
} }

View File

@ -18,7 +18,7 @@ class Filesystem;
class Fuse final { class Fuse final {
public: public:
explicit Fuse(Filesystem *fs, const std::string &fsname); explicit Fuse(Filesystem *fs, const std::string &fstype, const std::string &fsname=std::string());
~Fuse(); ~Fuse();
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions); void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
@ -65,6 +65,7 @@ private:
boost::filesystem::path _mountdir; boost::filesystem::path _mountdir;
std::vector<char*> _argv; std::vector<char*> _argv;
bool _running; bool _running;
std::string _fstype;
std::string _fsname; std::string _fsname;
DISALLOW_COPY_AND_ASSIGN(Fuse); DISALLOW_COPY_AND_ASSIGN(Fuse);