blob: 502786259d2cbcbf21906c4effa388bd7c023fd8 [file] [log] [blame]
Ben Chancb517732012-04-11 17:00:00 -07001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Ben Chan8dcede82011-07-25 20:56:13 -07002// 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_ARCHIVE_MANAGER_H_
6#define CROS_DISKS_ARCHIVE_MANAGER_H_
7
Ben Chancb517732012-04-11 17:00:00 -07008#include <map>
Anand K Mistry29fee842020-01-15 15:49:48 +11009#include <memory>
Ben Chan8dcede82011-07-25 20:56:13 -070010#include <string>
11#include <vector>
12
François Degrosf76886e2020-07-24 18:13:40 +100013#include <brillo/scoped_mount_namespace.h>
Ben Chan8dcede82011-07-25 20:56:13 -070014#include <gtest/gtest_prod.h>
15
Ben Chan5ccd9fe2013-11-13 18:28:27 -080016#include "cros-disks/mount_manager.h"
François Degrosf76886e2020-07-24 18:13:40 +100017#include "cros-disks/mount_options.h"
Ben Chan8dcede82011-07-25 20:56:13 -070018
19namespace cros_disks {
20
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110021class ArchiveMounter;
22
Ben Chan8dcede82011-07-25 20:56:13 -070023// A derived class of MountManager for mounting archive files as a virtual
24// filesystem.
25class ArchiveManager : public MountManager {
26 public:
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110027 ArchiveManager(const std::string& mount_root,
28 Platform* platform,
29 Metrics* metrics,
30 brillo::ProcessReaper* process_reaper);
31 ArchiveManager(const ArchiveManager&) = delete;
32 ArchiveManager& operator=(const ArchiveManager&) = delete;
33
34 ~ArchiveManager() override;
Ben Chan8dcede82011-07-25 20:56:13 -070035
François Degros7f7a4162020-06-13 00:13:00 +100036 // MountManager overrides
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110037 bool Initialize() override;
38
François Degros7f7a4162020-06-13 00:13:00 +100039 MountSourceType GetMountSourceType() const final {
Ben Chan6d0b2722011-11-18 08:24:14 -080040 return MOUNT_SOURCE_ARCHIVE;
Ben Chan8dcede82011-07-25 20:56:13 -070041 }
42
François Degrosf76886e2020-07-24 18:13:40 +100043 bool ResolvePath(const std::string& path, std::string* real_path) final;
44
45 std::string SuggestMountPath(const std::string& source_path) const final;
46
François Degros7f7a4162020-06-13 00:13:00 +100047 // Checks if the given file path is in an allowed location to be mounted as an
48 // archive. The following paths can be mounted:
49 //
50 // /home/chronos/u-<user-id>/MyFiles/...<file>
51 // /media/archive/<dir>/...<file>
52 // /media/fuse/<dir>/...<file>
53 // /media/removable/<dir>/...<file>
54 // /run/arc/sdcard/write/emulated/0/<dir>/...<file>
55 static bool IsInAllowedFolder(const std::string& source_path);
François Degros853c7d92020-02-17 10:32:21 +110056
François Degrosf76886e2020-07-24 18:13:40 +100057 // Gets a list of supplementary group IDs the FUSE mounter program should run
58 // with in order to access files in all the required locations.
59 std::vector<gid_t> GetSupplementaryGroups() const;
Ben Chan8dcede82011-07-25 20:56:13 -070060
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110061 bool CanMount(const std::string& source_path) const override;
François Degrosf76886e2020-07-24 18:13:40 +100062
Sergei Datsenkoc9904bb2020-12-11 12:46:02 +110063 protected:
64 std::unique_ptr<MountPoint> DoMount(const std::string& source_path,
65 const std::string& filesystem_type,
66 const std::vector<std::string>& options,
67 const base::FilePath& mount_path,
68 bool* mounted_as_read_only,
69 MountErrorType* error) override;
70
71 private:
72 std::vector<std::unique_ptr<ArchiveMounter>> mounters_;
Ben Chan8dcede82011-07-25 20:56:13 -070073};
74
75} // namespace cros_disks
76
77#endif // CROS_DISKS_ARCHIVE_MANAGER_H_