blob: f17836763c66fbf9e2b6df982afaf1fd3d86397f [file] [log] [blame]
Ben Chane31d2aa2011-06-15 13:52:59 -07001// 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 Datsenko85a18332019-04-08 14:25:03 +10008#include <memory>
Ben Chan190d3cf2011-07-07 09:38:48 -07009#include <string>
Sergei Datsenko85a18332019-04-08 14:25:03 +100010#include <vector>
Ben Chan190d3cf2011-07-07 09:38:48 -070011
Sergei Datsenko85a18332019-04-08 14:25:03 +100012#include "cros-disks/mount_point.h"
Ben Chane31d2aa2011-06-15 13:52:59 -070013#include "cros-disks/mounter.h"
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110014#include "cros-disks/platform.h"
Ben Chane31d2aa2011-06-15 13:52:59 -070015
16namespace cros_disks {
17
Sergei Datsenko85a18332019-04-08 14:25:03 +100018// A class for mounting a device file using the system mount() call.
19class SystemMounter : public Mounter {
20 public:
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110021 SystemMounter(const Platform* platform,
22 std::string filesystem_type,
23 bool read_only,
24 std::vector<std::string> options);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090025 SystemMounter(const SystemMounter&) = delete;
26 SystemMounter& operator=(const SystemMounter&) = delete;
27
Sergei Datsenko85a18332019-04-08 14:25:03 +100028 ~SystemMounter() override;
29
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110030 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 Chane31d2aa2011-06-15 13:52:59 -070034 // Mounts a device file using the system mount() call.
Sergei Datsenko85a18332019-04-08 14:25:03 +100035 std::unique_ptr<MountPoint> Mount(const std::string& source,
36 const base::FilePath& target_path,
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110037 std::vector<std::string> params,
Sergei Datsenko85a18332019-04-08 14:25:03 +100038 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 Datsenkoe8faba52020-10-06 21:45:22 +110043 const std::vector<std::string>& params,
Sergei Datsenko85a18332019-04-08 14:25:03 +100044 base::FilePath* suggested_dir_name) const override;
Sam McNallyc56ae312018-05-22 13:14:27 +100045
Sergei Datsenko68cd43a2020-11-16 22:57:16 +110046 protected:
47 virtual MountErrorType ParseParams(
48 std::vector<std::string> params,
49 std::vector<std::string>* mount_options) const;
50
Sam McNallyc56ae312018-05-22 13:14:27 +100051 private:
52 const Platform* const platform_;
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110053 const std::string filesystem_type_;
54 const int flags_;
55 const std::vector<std::string> options_;
Ben Chane31d2aa2011-06-15 13:52:59 -070056};
57
58} // namespace cros_disks
59
60#endif // CROS_DISKS_SYSTEM_MOUNTER_H_