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(); |
François Degros | a28315e | 2020-07-13 00:24:48 +1000 | [diff] [blame] | 26 | virtual ~Mounter(); |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 27 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 28 | // Mounts the filesystem. On failure returns nullptr and |error| is |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 29 | // set accordingly. Both |source| and |params| are just some strings |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 30 | // that can be interpreted by this mounter. |
| 31 | virtual std::unique_ptr<MountPoint> Mount(const std::string& source, |
| 32 | const base::FilePath& target_path, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 33 | std::vector<std::string> params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 34 | MountErrorType* error) const = 0; |
| 35 | |
| 36 | // Whether this mounter is able to mount given |source| with provided |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 37 | // |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] | 38 | // to be created. Note that in many cases it's impossible to tell beforehand |
| 39 | // if the particular source is mountable so it may blanketly return true for |
| 40 | // any arguments. |
| 41 | virtual bool CanMount(const std::string& source, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 42 | const std::vector<std::string>& params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 43 | base::FilePath* suggested_dir_name) const = 0; |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 44 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 45 | private: |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 46 | DISALLOW_COPY_AND_ASSIGN(Mounter); |
| 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 = {}); |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 56 | ~MounterCompat() override; |
| 57 | |
Anand K Mistry | 9f4611e | 2019-12-19 16:06:39 +1100 | [diff] [blame] | 58 | // Mounter overrides. |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 59 | std::unique_ptr<MountPoint> Mount(const std::string& source, |
| 60 | const base::FilePath& target_path, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 61 | std::vector<std::string> params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 62 | MountErrorType* error) const override; |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 63 | // Always returns true. |
| 64 | bool CanMount(const std::string& source, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 65 | const std::vector<std::string>& params, |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 66 | base::FilePath* suggested_dir_name) const override; |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 67 | |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 68 | const Mounter* mounter() const { return mounter_.get(); } |
Anand K Mistry | 9f4611e | 2019-12-19 16:06:39 +1100 | [diff] [blame] | 69 | const MountOptions& mount_options() const { return mount_options_; } |
| 70 | |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 71 | private: |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 72 | const std::unique_ptr<Mounter> mounter_; |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 73 | const MountOptions mount_options_; |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 74 | |
Sergei Datsenko | 3cf72cb | 2019-04-01 11:27:50 +1100 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(MounterCompat); |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace cros_disks |
| 79 | |
| 80 | #endif // CROS_DISKS_MOUNTER_H_ |