blob: 3ad68667d0bf0b4663e8eee799591857514647af [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();
François Degrosa28315e2020-07-13 00:24:48 +100026 virtual ~Mounter();
Ben Chane31d2aa2011-06-15 13:52:59 -070027
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110028 // Mounts the filesystem. On failure returns nullptr and |error| is
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110029 // set accordingly. Both |source| and |params| are just some strings
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110030 // 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 Datsenkoe8faba52020-10-06 21:45:22 +110033 std::vector<std::string> params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110034 MountErrorType* error) const = 0;
35
36 // Whether this mounter is able to mount given |source| with provided
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110037 // |params|. If so - it may suggest a directory name for the mount point
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110038 // 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 Datsenkoe8faba52020-10-06 21:45:22 +110042 const std::vector<std::string>& params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110043 base::FilePath* suggested_dir_name) const = 0;
Ben Chane31d2aa2011-06-15 13:52:59 -070044
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110045 private:
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110046 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.
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 = {});
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110056 ~MounterCompat() override;
57
Anand K Mistry9f4611e2019-12-19 16:06:39 +110058 // Mounter overrides.
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110059 std::unique_ptr<MountPoint> Mount(const std::string& source,
60 const base::FilePath& target_path,
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110061 std::vector<std::string> params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110062 MountErrorType* error) const override;
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110063 // Always returns true.
64 bool CanMount(const std::string& source,
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110065 const std::vector<std::string>& params,
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110066 base::FilePath* suggested_dir_name) const override;
Ben Chane31d2aa2011-06-15 13:52:59 -070067
Sergei Datsenkoe8faba52020-10-06 21:45:22 +110068 const Mounter* mounter() const { return mounter_.get(); }
Anand K Mistry9f4611e2019-12-19 16:06:39 +110069 const MountOptions& mount_options() const { return mount_options_; }
70
Ben Chane31d2aa2011-06-15 13:52:59 -070071 private:
Sergei Datsenko85a18332019-04-08 14:25:03 +100072 const std::unique_ptr<Mounter> mounter_;
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110073 const MountOptions mount_options_;
Ben Chane31d2aa2011-06-15 13:52:59 -070074
Sergei Datsenko3cf72cb2019-04-01 11:27:50 +110075 DISALLOW_COPY_AND_ASSIGN(MounterCompat);
Ben Chane31d2aa2011-06-15 13:52:59 -070076};
77
78} // namespace cros_disks
79
80#endif // CROS_DISKS_MOUNTER_H_