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_SYSTEM_MOUNTER_H_ |
| 6 | #define CROS_DISKS_SYSTEM_MOUNTER_H_ |
| 7 | |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 8 | #include <memory> |
Ben Chan | 190d3cf | 2011-07-07 09:38:48 -0700 | [diff] [blame] | 9 | #include <string> |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 10 | #include <vector> |
Ben Chan | 190d3cf | 2011-07-07 09:38:48 -0700 | [diff] [blame] | 11 | |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 12 | #include "cros-disks/mount_point.h" |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 13 | #include "cros-disks/mounter.h" |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 14 | #include "cros-disks/platform.h" |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 15 | |
| 16 | namespace cros_disks { |
| 17 | |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 18 | // A class for mounting a device file using the system mount() call. |
| 19 | class SystemMounter : public Mounter { |
| 20 | public: |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 21 | SystemMounter(const Platform* platform, |
| 22 | std::string filesystem_type, |
| 23 | bool read_only, |
| 24 | std::vector<std::string> options); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 25 | SystemMounter(const SystemMounter&) = delete; |
| 26 | SystemMounter& operator=(const SystemMounter&) = delete; |
| 27 | |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 28 | ~SystemMounter() override; |
| 29 | |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 30 | const std::string& filesystem_type() const { return filesystem_type_; } |
| 31 | bool read_only() const { return (flags_ & MS_RDONLY) == MS_RDONLY; } |
| 32 | const std::vector<std::string>& options() const { return options_; } |
| 33 | |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 34 | // Mounts a device file using the system mount() call. |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 35 | std::unique_ptr<MountPoint> Mount(const std::string& source, |
| 36 | const base::FilePath& target_path, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 37 | std::vector<std::string> params, |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 38 | MountErrorType* error) const override; |
| 39 | |
| 40 | // As there is no way to figure out beforehand if that would work, always |
| 41 | // returns true, so this mounter is a "catch-all". |
| 42 | bool CanMount(const std::string& source, |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 43 | const std::vector<std::string>& params, |
Sergei Datsenko | 85a1833 | 2019-04-08 14:25:03 +1000 | [diff] [blame] | 44 | base::FilePath* suggested_dir_name) const override; |
Sam McNally | c56ae31 | 2018-05-22 13:14:27 +1000 | [diff] [blame] | 45 | |
Sergei Datsenko | 68cd43a | 2020-11-16 22:57:16 +1100 | [diff] [blame] | 46 | protected: |
| 47 | virtual MountErrorType ParseParams( |
| 48 | std::vector<std::string> params, |
| 49 | std::vector<std::string>* mount_options) const; |
| 50 | |
Sam McNally | c56ae31 | 2018-05-22 13:14:27 +1000 | [diff] [blame] | 51 | private: |
| 52 | const Platform* const platform_; |
Sergei Datsenko | e8faba5 | 2020-10-06 21:45:22 +1100 | [diff] [blame] | 53 | const std::string filesystem_type_; |
| 54 | const int flags_; |
| 55 | const std::vector<std::string> options_; |
Ben Chan | e31d2aa | 2011-06-15 13:52:59 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | } // namespace cros_disks |
| 59 | |
| 60 | #endif // CROS_DISKS_SYSTEM_MOUNTER_H_ |