2 * Copyright (C) 2017 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "anbox/common/mount_entry.h"
19 #include "anbox/common/loop_device.h"
20 #include "anbox/logger.h"
22 #include <sys/mount.h>
26 std::shared_ptr<MountEntry> MountEntry::create(const boost::filesystem::path &src, const boost::filesystem::path &target,
27 const std::string &fs_type, unsigned long flags, const std::string &data) {
28 auto entry = std::shared_ptr<MountEntry>(new MountEntry(target));
32 const void *mount_data = nullptr;
34 mount_data = reinterpret_cast<const void*>(data.c_str());
36 DEBUG("Mounting %s on %s ...", src, target);
38 if (::mount(src.c_str(), target.c_str(), !fs_type.empty() ? fs_type.c_str() : nullptr, flags, mount_data) < 0) {
39 ERROR("Failed to mount %s: %s", target, strerror(errno));
43 entry->active_ = true;
48 std::shared_ptr<MountEntry> MountEntry::create(const std::shared_ptr<LoopDevice> &loop, const boost::filesystem::path &target,
49 const std::string &fs_type, unsigned long flags, const std::string &data) {
50 auto entry = create(loop->path(), target, fs_type, flags, data);
58 std::shared_ptr<MountEntry> MountEntry::create(const boost::filesystem::path &target) {
59 auto entry = std::shared_ptr<MountEntry>(new MountEntry(target));
63 entry->active_ = true;
68 MountEntry::MountEntry(const boost::filesystem::path &target) :
69 active_{false}, target_{target} {}
71 MountEntry::~MountEntry() {
75 ::umount(target_.c_str());