Skip to content

Commit

Permalink
Wire everything together for format 4
Browse files Browse the repository at this point in the history
  • Loading branch information
netheril96 committed Mar 9, 2024
1 parent 1411096 commit f6c172e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
46 changes: 35 additions & 11 deletions sources/commands.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "commands.h"
#include "crypto.h"
#include "exceptions.h"
#include "fuse_high_level_ops_base.h"
#include "git-version.h"
#include "lite_format.h"
#include "lite_operations.h"
Expand Down Expand Up @@ -1055,8 +1056,6 @@ class MountCommand : public _SinglePasswordCommandBase
false};

FSConfig config{};
bool skip_dot_dot_value, skip_verification_value;
std::unique_ptr<OSService> os;

private:
std::vector<const char*> to_c_style_args(const std::vector<std::string>& args)
Expand Down Expand Up @@ -1121,15 +1120,12 @@ class MountCommand : public _SinglePasswordCommandBase
}
name_norm_flags->supports_long_name = config.long_name_component;

if (!os)
os = std::make_unique<OSService>(data_dir.getValue());
skip_dot_dot_value = skip_dot_dot.getValue();
skip_verification_value = insecure.getValue();

return fruit::createComponent()
.bind<FuseHighLevelOpsBase, lite_format::FuseHighLevelOps>()
.bindInstance(*this)
.install(::securefs::lite_format::get_name_translator_component, name_norm_flags)
.bindInstance<fruit::Annotated<tSkipVerification, bool>>(skip_verification_value)
.registerProvider<fruit::Annotated<tSkipVerification, bool>(const MountCommand&)>(
[](const MountCommand& cmd) { return cmd.insecure.getValue(); })
.bindInstance<fruit::Annotated<tMaxPaddingSize, unsigned>>(config.max_padding)
.bindInstance<fruit::Annotated<tIvSize, unsigned>>(config.iv_size)
.bindInstance<fruit::Annotated<tBlockSize, unsigned>>(config.block_size)
Expand Down Expand Up @@ -1180,7 +1176,8 @@ class MountCommand : public _SinglePasswordCommandBase
}
return key_type(master_key.data() + 3 * key_type::size(), key_type::size());
})
.bindInstance(*os);
.registerProvider([](const MountCommand& cmd)
{ return new OSService(cmd.data_dir.getValue()); });
}

public:
Expand Down Expand Up @@ -1408,9 +1405,36 @@ class MountCommand : public _SinglePasswordCommandBase
{
VERBOSE_LOG("Master key: %s", hexify(config.master_key));
}
fruit::Injector<FuseHighLevelOpsBase> injector(
+[](MountCommand* cmd) { return cmd->get_fuse_high_ops_component(); }, this);
if (config.version == 4)
{
fruit::Injector<FuseHighLevelOpsBase> injector(
+[](MountCommand* cmd) { return cmd->get_fuse_high_ops_component(); }, this);
FuseHighLevelOpsBase::InitialDataType init
= [&]() { return injector.get<FuseHighLevelOpsBase*>(); };

bool native_xattr = !noxattr.getValue();
#ifdef __APPLE__
if (native_xattr)
{
auto rc = fsopt.root->listxattr(".", nullptr, 0);
if (rc < 0)
{
absl::FPrintF(
stderr,
"Warning: %s has no extended attribute support.\nXattr is disabled\n",
data_dir.getValue());
native_xattr = false;
}
}
#endif
auto op = FuseHighLevelOpsBase::build_ops(native_xattr);
VERBOSE_LOG("Calling fuse_main with arguments: %s", escape_args(fuse_args));
recreate_logger();
return fuse_main(static_cast<int>(fuse_args.size()),
const_cast<char**>(to_c_style_args(fuse_args).data()),
&op,
&init);
}
operations::MountOptions fsopt;
fsopt.root = std::make_shared<OSService>(data_dir.getValue());
fsopt.block_size = config.block_size;
Expand Down
4 changes: 1 addition & 3 deletions sources/fuse_high_level_ops_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
#include "object.h"
#include "platform.h" // IWYU pragma: keep

#include <absl/functional/function_ref.h>

namespace securefs
{
class FuseHighLevelOpsBase : public Object
{
public:
// The initial data should be lazy initializing a class of this type.
// The owner of the class should extend beyond `destroy`.
using InitialDataType = absl::FunctionRef<FuseHighLevelOpsBase*()>;
using InitialDataType = std::function<FuseHighLevelOpsBase*()>;

static fuse_operations build_ops(bool enable_xattr);

Expand Down

0 comments on commit f6c172e

Please sign in to comment.