FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
ciopfs.hpp
Go to the documentation of this file.
1
17
18#pragma once
19
20#include <filesystem>
21#include <unistd.h>
22
23#include "../lib/subprocess.hpp"
24#include "../lib/env.hpp"
25#include "../std/filesystem.hpp"
26#include "filesystem.hpp"
27
36{
37
38
39namespace
40{
41
42namespace fs = std::filesystem;
43
44} // namespace
45
62{
63 private:
70 fs::path m_path_dir_upper;
71
78 fs::path m_path_dir_lower;
79
80 public:
81 Ciopfs(pid_t pid_to_die_for
82 , fs::path const& path_dir_lower
83 , fs::path const& path_dir_upper
84 , fs::path const& path_file_log);
85 Value<void> mount() override;
86};
87
101inline Ciopfs::Ciopfs(pid_t pid_to_die_for
102 , fs::path const& path_dir_lower
103 , fs::path const& path_dir_upper
104 , fs::path const& path_file_log
105)
106 : ns_filesystem::Filesystem(pid_to_die_for, path_dir_upper, path_file_log)
107 , m_path_dir_upper(path_dir_upper)
108 , m_path_dir_lower(path_dir_lower)
109{
110 this->mount().discard("E::Could not mount ciopfs filesystem from '{}' to '{}'", path_dir_lower, path_dir_upper);
111}
112
130{
131 // Validate directories
132 Pop(ns_fs::create_directories(m_path_dir_lower), "E::Failed to create lower directory");
133 Pop(ns_fs::create_directories(m_path_dir_upper), "E::Failed to create upper directory");
134 // Find Ciopfs
135 auto path_file_ciopfs = Pop(ns_env::search_path("ciopfs"), "E::Could not find ciopfs in PATH");
136 // Include arguments and spawn process
137 m_child = ns_subprocess::Subprocess(path_file_ciopfs)
138 .with_args(m_path_dir_lower, m_path_dir_upper)
139 .with_die_on_pid(m_pid_to_die_for)
140 .with_stdio(ns_subprocess::Stream::Pipe)
141 .with_log_file(m_path_file_log)
142 .spawn();
143 // Wait for mount
144 ns_fuse::wait_fuse(m_path_dir_upper);
145 return {};
146}
147
148} // namespace ns_filesystems::ns_ciopfs
149
150/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Filesystem(pid_t pid_to_die_for, std::filesystem::path const &path_dir_mount, std::filesystem::path const &path_file_log)
Construct a new Filesystem object.
Value< void > mount() override
Mounts the CIOPFS filesystem.
Definition ciopfs.hpp:129
Ciopfs(pid_t pid_to_die_for, fs::path const &path_dir_lower, fs::path const &path_dir_upper, fs::path const &path_file_log)
Constructs and mounts a CIOPFS filesystem.
Definition ciopfs.hpp:101
Subprocess & with_die_on_pid(pid_t pid)
Configures the child process to die when the specified PID dies.
std::unique_ptr< Child > spawn()
Spawns (forks) the child process and begins execution.
Subprocess & with_stdio(Stream mode)
Sets the stdio redirection mode for the child process.
Subprocess & with_log_file(std::filesystem::path const &path)
Configures logging output for child process stdout/stderr.
Subprocess & with_args(Args &&... args)
Arguments forwarded as the process' arguments.
The base class for filesystems.
A library for manipulating environment variables.
Value< fs::path > search_path(std::string const &query)
Search the directories in the PATH variable for the given input file name.
Definition env.hpp:150
Base filesystem interface and abstraction.
Case-insensitive filesystem implementation.
Value< fs::path > create_directories(fs::path const &p)
Creates directories recursively.
void wait_fuse(fs::path const &path_dir_filesystem)
Waits for the given directory to not be fuse.
Definition fuse.hpp:68
Filesystem helpers.
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44
A library to spawn sub-processes in linux.