blob: 43fe9c1869b4c1b2c20ae6f2268f227da8f6667d [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_MOUNTER_H_
6#define CROS_DISKS_MOUNTER_H_
7
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +11008#include <memory>
Ben Chane31d2aa2011-06-15 13:52:59 -07009#include <string>
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110010#include <vector>
Ben Chane31d2aa2011-06-15 13:52:59 -070011
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110012#include <base/files/file_path.h>
Ben Chan3b832b92014-09-02 19:39:57 -070013#include <base/macros.h>
Ben Chanfcb2fc02011-11-21 09:44:07 -080014#include <chromeos/dbus/service_constants.h>
Ben Chane31d2aa2011-06-15 13:52:59 -070015
Ben Chan5ccd9fe2013-11-13 18:28:27 -080016#include "cros-disks/mount_options.h"
Ben Chane31d2aa2011-06-15 13:52:59 -070017
18namespace cros_disks {
19
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110020class MountPoint;
21
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110022// Interface for mounting a given filesystem.
Ben Chane31d2aa2011-06-15 13:52:59 -070023class Mounter {
24 public:
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110025 Mounter();
Qijiang Fan6bc59e12020-11-11 02:51:06 +090026 Mounter(const Mounter&) = delete;
27 Mounter& operator=(const Mounter&) = delete;
28
François Degrosa28315e2020-07-13 00:24:48 +100029 virtual ~Mounter();
Ben Chane31d2aa2011-06-15 13:52:59 -070030
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110031 // Mounts the filesystem. On failure returns nullptr and |error| is
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110032 // set accordingly. Both |source| and |params| are just some strings
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110033 // 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 Datsenkoe8faba52020-10-06 21:45:22 +110036 std::vector<std::string> params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110037 MountErrorType* error) const = 0;
38
39 // Whether this mounter is able to mount given |source| with provided
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110040 // |params|. If so - it may suggest a directory name for the mount point
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110041 // 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 Datsenkoe8faba52020-10-06 21:45:22 +110045 const std::vector<std::string>& params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110046 base::FilePath* suggested_dir_name) const = 0;
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110047};
48
49// Temporary adaptor to keep some signatures compatible with old implementation
50// and minimize churn.
51// TODO(crbug.com/933018): Remove when done.
52class MounterCompat : public Mounter {
53 public:
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110054 explicit MounterCompat(MountOptions mount_options,
55 std::unique_ptr<Mounter> mounter = {});
Qijiang Fan6bc59e12020-11-11 02:51:06 +090056 MounterCompat(const MounterCompat&) = delete;
57 MounterCompat& operator=(const MounterCompat&) = delete;
58
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110059 ~MounterCompat() override;
60
Anand K Mistry9f4611e2019-12-19 16:06:39 +110061 // Mounter overrides.
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110062 std::unique_ptr<MountPoint> Mount(const std::string& source,
63 const base::FilePath& target_path,
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110064 std::vector<std::string> params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110065 MountErrorType* error) const override;
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110066 // Always returns true.
67 bool CanMount(const std::string& source,
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110068 const std::vector<std::string>& params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110069 base::FilePath* suggested_dir_name) const override;
Ben Chane31d2aa2011-06-15 13:52:59 -070070
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110071 const Mounter* mounter() const { return mounter_.get(); }
Anand K Mistry9f4611e2019-12-19 16:06:39 +110072 const MountOptions& mount_options() const { return mount_options_; }
73
Ben Chane31d2aa2011-06-15 13:52:59 -070074 private:
Sergei Datsenko85a18332019-04-08 14:25:03 +100075 const std::unique_ptr<Mounter> mounter_;
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110076 const MountOptions mount_options_;
Ben Chane31d2aa2011-06-15 13:52:59 -070077};
78
79} // namespace cros_disks
80
81#endif // CROS_DISKS_MOUNTER_H_