Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 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_MOUNTER_H_ |
| 6 | #define CROS_DISKS_MOUNTER_H_ |
| 7 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 8 | #include <memory> |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 9 | #include <string> |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 10 | #include <vector> |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 11 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 12 | #include <base/files/file_path.h> |
Ben Chan | 3b832b9 | 2014-09-02 19:39:57 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
Ben Chan | fcb2fc0 | 2011-11-21 09:44:07 -0800 | [diff] [blame] | 14 | #include <chromeos/dbus/service_constants.h> |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 15 | |
Ben Chan | 5ccd9fe | 2013-11-13 18:28:27 -0800 | [diff] [blame] | 16 | #include "cros-disks/mount_options.h" |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 17 | |
| 18 | namespace cros_disks { |
| 19 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 20 | class MountPoint; |
| 21 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 22 | // Interface for mounting a given filesystem. |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 23 | class Mounter { |
| 24 | public: |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 25 | Mounter(); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame^] | 26 | Mounter(const Mounter&) = delete; |
| 27 | Mounter& operator=(const Mounter&) = delete; |
| 28 | |
François Degros | a28315e | 2020-07-13 00:24:48 +1000 | [diff] [blame] | 29 | virtual ~Mounter(); |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 30 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 31 | // Mounts the filesystem. On failure returns nullptr and |error| is |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 32 | // set accordingly. Both |source| and |params| are just some strings |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 33 | // that can be interpreted by this mounter. |
| 34 | virtual std::unique_ptr<MountPoint> Mount(const std::string& source, |
| 35 | const base::FilePath& target_path, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 36 | std::vector<std::string> params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 37 | MountErrorType* error) const = 0; |
| 38 | |
| 39 | // Whether this mounter is able to mount given |source| with provided |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 40 | // |params|. If so - it may suggest a directory name for the mount point |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 41 | // to be created. Note that in many cases it's impossible to tell beforehand |
| 42 | // if the particular source is mountable so it may blanketly return true for |
| 43 | // any arguments. |
| 44 | virtual bool CanMount(const std::string& source, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 45 | const std::vector<std::string>& params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 46 | base::FilePath* suggested_dir_name) const = 0; |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | // Temporary adaptor to keep some signatures compatible with old implementation |
| 50 | // and minimize churn. |
| 51 | // TODO(crbug.com/933018): Remove when done. |
| 52 | class MounterCompat : public Mounter { |
| 53 | public: |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 54 | explicit MounterCompat(MountOptions mount_options, |
| 55 | std::unique_ptr<Mounter> mounter = {}); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame^] | 56 | MounterCompat(const MounterCompat&) = delete; |
| 57 | MounterCompat& operator=(const MounterCompat&) = delete; |
| 58 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 59 | ~MounterCompat() override; |
| 60 | |
Anand K Mistry | 9f4611e | 2019-12-19 16:06:39 +1100 | [diff] [blame] | 61 | // Mounter overrides. |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 62 | std::unique_ptr<MountPoint> Mount(const std::string& source, |
| 63 | const base::FilePath& target_path, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 64 | std::vector<std::string> params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 65 | MountErrorType* error) const override; |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 66 | // Always returns true. |
| 67 | bool CanMount(const std::string& source, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 68 | const std::vector<std::string>& params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 69 | base::FilePath* suggested_dir_name) const override; |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 70 | |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 71 | const Mounter* mounter() const { return mounter_.get(); } |
Anand K Mistry | 9f4611e | 2019-12-19 16:06:39 +1100 | [diff] [blame] | 72 | const MountOptions& mount_options() const { return mount_options_; } |
| 73 | |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 74 | private: |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 75 | const std::unique_ptr<Mounter> mounter_; |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 76 | const MountOptions mount_options_; |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace cros_disks |
| 80 | |
| 81 | #endif // CROS_DISKS_MOUNTER_H_ |