blob: bb7776e22ac4adf0d3190a73fdb76550e729de78 [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <functional>
#include <memory>
#include <string>
#include <vector>
#include <gtest/gtest_prod.h>
#include "cros-disks/mount_manager.h"
namespace cros_disks {
class Mounter;
// Implementation of MountManager for mounting arbitrary FUSE-based filesystems.
// It essentially does dispatching of mount requests to individual FUSE helpers.
class FUSEMountManager : public MountManager {
// |mount_root| - where mount points go.
// |working_dirs_root| - where temporary working directories go.
FUSEMountManager(const std::string& mount_root,
const std::string& working_dirs_root,
Platform* platform,
Metrics* metrics,
brillo::ProcessReaper* process_reaper);
FUSEMountManager(const FUSEMountManager&) = delete;
FUSEMountManager& operator=(const FUSEMountManager&) = delete;
~FUSEMountManager() override;
bool Initialize() override;
// Whether we know about FUSE driver able to handle this source. Note that
// source doesn't have to be an actual file or path, it could be anything
// identifying FUSE module and what instance to mount.
bool CanMount(const std::string& source) const override;
// Returns the type of mount sources supported by the manager.
MountSourceType GetMountSourceType() const override {
// TODO( Introduce generic "FUSE" storage.
// Mounts |source| to |mount_path| as |fuse_type| with |options|.
// |fuse_type| can be used to specify the type of |source|.
// If |fuse_type| is an empty string, the type is determined based on the
// format of the |source|. The underlying mounter may decide to apply mount
// options different than |options|. |applied_options| is used to return
// the mount options applied by the mounter.
std::unique_ptr<MountPoint> DoMount(const std::string& source,
const std::string& fuse_type,
const std::vector<std::string>& options,
const base::FilePath& mount_path,
MountOptions* applied_options,
MountErrorType* error) override;
// Returns a suggested mount path for a source.
std::string SuggestMountPath(const std::string& source) const override;
void RegisterHelper(std::unique_ptr<Mounter> mounter);
FRIEND_TEST(FUSEMountManagerTest, SuggestMountPath);
friend class FUSEMountManagerTest;
std::vector<std::unique_ptr<Mounter>> helpers_;
const std::string working_dirs_root_;
} // namespace cros_disks