X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fcommon%2Fmount_entry.cpp;fp=src%2Ftype3_AndroidCloud%2Fanbox-master%2Fsrc%2Fanbox%2Fcommon%2Fmount_entry.cpp;h=4ee7eb977034341c6ef24cbdfc2aab106ae91f34;hb=e26c1ec581be598521517829adba8c8dd23a768f;hp=0000000000000000000000000000000000000000;hpb=6699c1aea74eeb0eb400e6299079f0c7576f716f;p=iec.git diff --git a/src/type3_AndroidCloud/anbox-master/src/anbox/common/mount_entry.cpp b/src/type3_AndroidCloud/anbox-master/src/anbox/common/mount_entry.cpp new file mode 100644 index 0000000..4ee7eb9 --- /dev/null +++ b/src/type3_AndroidCloud/anbox-master/src/anbox/common/mount_entry.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2017 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include "anbox/common/mount_entry.h" +#include "anbox/common/loop_device.h" +#include "anbox/logger.h" + +#include + +namespace anbox { +namespace common { +std::shared_ptr MountEntry::create(const boost::filesystem::path &src, const boost::filesystem::path &target, + const std::string &fs_type, unsigned long flags, const std::string &data) { + auto entry = std::shared_ptr(new MountEntry(target)); + if (!entry) + return nullptr; + + const void *mount_data = nullptr; + if (!data.empty()) + mount_data = reinterpret_cast(data.c_str()); + + DEBUG("Mounting %s on %s ...", src, target); + + if (::mount(src.c_str(), target.c_str(), !fs_type.empty() ? fs_type.c_str() : nullptr, flags, mount_data) < 0) { + ERROR("Failed to mount %s: %s", target, strerror(errno)); + return nullptr; + } + + entry->active_ = true; + + return entry; +} + +std::shared_ptr MountEntry::create(const std::shared_ptr &loop, const boost::filesystem::path &target, + const std::string &fs_type, unsigned long flags, const std::string &data) { + auto entry = create(loop->path(), target, fs_type, flags, data); + if (!entry) + return nullptr; + + entry->loop_ = loop; + return entry; +} + +std::shared_ptr MountEntry::create(const boost::filesystem::path &target) { + auto entry = std::shared_ptr(new MountEntry(target)); + if (!entry) + return nullptr; + + entry->active_ = true; + + return entry; +} + +MountEntry::MountEntry(const boost::filesystem::path &target) : + active_{false}, target_{target} {} + +MountEntry::~MountEntry() { + if (!active_) + return; + + ::umount(target_.c_str()); +} +} // namespace common +} // namespace anbox