33namespace fs = std::filesystem;
40 fs::path m_path_file_image;
42 uint64_t m_size_image;
44 Dwarfs(pid_t pid_to_die_for
45 , fs::path
const& path_dir_mount
46 , fs::path
const& path_file_image
47 , fs::path
const& path_file_log
49 , uint64_t size_image);
63 , fs::path
const& path_dir_mount
64 , fs::path
const& path_file_image
65 , fs::path
const& path_file_log
70 , m_path_file_image(path_file_image)
72 , m_size_image(size_image)
74 this->
mount().discard(
"E::Could not mount dwarfs filesystem '{}' to '{}'", path_file_image, path_dir_mount);
85 return_if(not Try(fs::is_regular_file(m_path_file_image))
86 , Error(
"E::'{}' does not exist or is not a regular file", m_path_file_image.string())
89 return_if(not Try(fs::is_directory(m_path_dir_mount))
90 , Error(
"E::'{}' does not exist or is not a directory", m_path_dir_mount.string())
93 auto path_file_dwarfs = Pop(
ns_env::search_path(
"dwarfs"),
"E::Could not find dwarfs in PATH");
96 .
with_args(m_path_file_image, m_path_dir_mount)
97 .
with_args(
"-f",
"-o", std::format(
"uid={},gid={},auto_unmount,offset={},imagesize={}", getuid(), getgid(), m_offset, m_size_image))
114inline bool is_dwarfs(fs::path
const& path_file_dwarfs, uint64_t offset = 0)
117 std::ifstream file_dwarfs(path_file_dwarfs, std::ios::binary | std::ios::in);
118 return_if(not file_dwarfs.is_open(),
false,
"E::Could not open file '{}'", path_file_dwarfs.string());
120 file_dwarfs.seekg(offset);
121 return_if(not file_dwarfs,
false,
"E::Failed to seek offset '{}' in file '{}'", offset, path_file_dwarfs.string());
123 std::array<char,6> header;
124 return_if(not file_dwarfs.read(header.data(), header.size()),
false,
"E::Could not read bytes from file '{}'", path_file_dwarfs.string());
126 return_if(file_dwarfs.gcount() != header.size(),
false,
"E::Short read for file '{}'", path_file_dwarfs.string());
128 return std::ranges::equal(header, std::string_view(
"DWARFS"));
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 filesystem.
Dwarfs(pid_t pid_to_die_for, fs::path const &path_dir_mount, fs::path const &path_file_image, fs::path const &path_file_log, uint64_t offset, uint64_t size_image)
Construct a new Dwarfs:: Dwarfs object.
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.
Simplified macros for common control flow patterns with optional logging.
Value< fs::path > search_path(std::string const &query)
Search the directories in the PATH variable for the given input file name.
Base filesystem interface and abstraction.
DwarFS compressed read-only filesystem wrapper.
bool is_dwarfs(fs::path const &path_file_dwarfs, uint64_t offset=0)
Checks if the filesystem is a Dwarfs filesystem with a given offset.
void wait_fuse(fs::path const &path_dir_filesystem)
Waits for the given directory to not be fuse.
Enhanced expected type with integrated logging capabilities.
A library to spawn sub-processes in linux.