blob: 3d55ddd682eeb45813baccc4e68e2e3549f99064 [file] [log] [blame]
Sergei Datsenko0f014d22018-04-04 16:37:22 +10001// Copyright 2018 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CROS_DISKS_FUSE_MOUNT_MANAGER_H_
6#define CROS_DISKS_FUSE_MOUNT_MANAGER_H_
7
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
13#include <gtest/gtest_prod.h>
14
15#include "cros-disks/mount_manager.h"
16
17namespace cros_disks {
18
Sergei Datsenko25898b12020-11-26 08:07:15 +110019class Mounter;
Sergei Datsenko0f014d22018-04-04 16:37:22 +100020
21// Implementation of MountManager for mounting arbitrary FUSE-based filesystems.
22// It essentially does dispatching of mount requests to individual FUSE helpers.
23class FUSEMountManager : public MountManager {
24 public:
Sergei Datsenkobcd8e462018-04-20 15:44:56 +100025 // |mount_root| - where mount points go.
26 // |working_dirs_root| - where temporary working directories go.
Sergei Datsenko0f014d22018-04-04 16:37:22 +100027 FUSEMountManager(const std::string& mount_root,
Sergei Datsenkobcd8e462018-04-20 15:44:56 +100028 const std::string& working_dirs_root,
Sergei Datsenko0f014d22018-04-04 16:37:22 +100029 Platform* platform,
Sergei Datsenkoa910bba2019-06-18 13:31:59 +100030 Metrics* metrics,
31 brillo::ProcessReaper* process_reaper);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090032 FUSEMountManager(const FUSEMountManager&) = delete;
33 FUSEMountManager& operator=(const FUSEMountManager&) = delete;
34
Sergei Datsenko0f014d22018-04-04 16:37:22 +100035 ~FUSEMountManager() override;
36
37 bool Initialize() override;
38
39 // Whether we know about FUSE driver able to handle this source. Note that
40 // source doesn't have to be an actual file or path, it could be anything
41 // identifying FUSE module and what instance to mount.
42 bool CanMount(const std::string& source) const override;
43
44 // Returns the type of mount sources supported by the manager.
45 MountSourceType GetMountSourceType() const override {
46 // TODO(crbug.com/831491): Introduce generic "FUSE" storage.
47 return MOUNT_SOURCE_NETWORK_STORAGE;
48 }
49
50 protected:
51 // Mounts |source| to |mount_path| as |fuse_type| with |options|.
52 // |fuse_type| can be used to specify the type of |source|.
53 // If |fuse_type| is an empty string, the type is determined based on the
Nigel Taoca7a4ef2021-05-14 11:44:25 +100054 // format of the |source|. The underlying mounter may append their own mount
55 // options to |options|.
Anand K Mistryd0a05232020-01-24 14:04:18 +110056 std::unique_ptr<MountPoint> DoMount(const std::string& source,
57 const std::string& fuse_type,
58 const std::vector<std::string>& options,
59 const base::FilePath& mount_path,
Anand K Mistryd0a05232020-01-24 14:04:18 +110060 MountErrorType* error) override;
Sergei Datsenko0f014d22018-04-04 16:37:22 +100061
Sergei Datsenko0f014d22018-04-04 16:37:22 +100062 // Returns a suggested mount path for a source.
63 std::string SuggestMountPath(const std::string& source) const override;
64
Sergei Datsenko25898b12020-11-26 08:07:15 +110065 void RegisterHelper(std::unique_ptr<Mounter> mounter);
Sergei Datsenko0f014d22018-04-04 16:37:22 +100066
67 private:
Sergei Datsenko0f014d22018-04-04 16:37:22 +100068 FRIEND_TEST(FUSEMountManagerTest, SuggestMountPath);
69 friend class FUSEMountManagerTest;
70
Sergei Datsenko25898b12020-11-26 08:07:15 +110071 std::vector<std::unique_ptr<Mounter>> helpers_;
Sergei Datsenkobcd8e462018-04-20 15:44:56 +100072 const std::string working_dirs_root_;
Sergei Datsenko0f014d22018-04-04 16:37:22 +100073};
74
75} // namespace cros_disks
76
77#endif // CROS_DISKS_FUSE_MOUNT_MANAGER_H_