Pass optional additonal user data to mount syscall

This commit is contained in:
Simon Fels 2017-07-12 09:27:08 +02:00
commit aecf88fb2d
2 changed files with 11 additions and 6 deletions

View file

@ -17,18 +17,23 @@
#include "anbox/common/mount_entry.h"
#include "anbox/common/loop_device.h"
#include "anbox/logger.h"
#include <sys/mount.h>
namespace anbox {
namespace common {
std::shared_ptr<MountEntry> MountEntry::create(const boost::filesystem::path &src, const boost::filesystem::path &target,
const std::string &fs_type, unsigned long flags) {
const std::string &fs_type, unsigned long flags, const std::string &data) {
auto entry = std::shared_ptr<MountEntry>(new MountEntry(target));
if (!entry)
return nullptr;
if (::mount(src.c_str(), target.c_str(), !fs_type.empty() ? fs_type.c_str() : nullptr, flags, nullptr) != 0)
const void *mount_data = nullptr;
if (!data.empty())
mount_data = reinterpret_cast<const void*>(data.c_str());
if (::mount(src.c_str(), target.c_str(), !fs_type.empty() ? fs_type.c_str() : nullptr, flags, mount_data) != 0)
return nullptr;
entry->active_ = true;
@ -37,8 +42,8 @@ std::shared_ptr<MountEntry> MountEntry::create(const boost::filesystem::path &sr
}
std::shared_ptr<MountEntry> MountEntry::create(const std::shared_ptr<LoopDevice> &loop, const boost::filesystem::path &target,
const std::string &fs_type, unsigned long flags) {
auto entry = create(loop->path(), target, fs_type, flags);
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;

View file

@ -26,10 +26,10 @@ class LoopDevice;
class MountEntry {
public:
static std::shared_ptr<MountEntry> create(const boost::filesystem::path &src, const boost::filesystem::path &target,
const std::string &fs_type = "", unsigned long flags = 0);
const std::string &fs_type = "", unsigned long flags = 0, const std::string &data = "");
static std::shared_ptr<MountEntry> create(const std::shared_ptr<LoopDevice> &loop, const boost::filesystem::path &target,
const std::string &fs_type = "", unsigned long flags = 0);
const std::string &fs_type = "", unsigned long flags = 0, const std::string &data = "");
static std::shared_ptr<MountEntry> create(const boost::filesystem::path &target);