mirror of https://github.com/trapexit/mergerfs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
2.3 KiB
112 lines
2.3 KiB
#include "mergerfs_api.hpp"
|
|
|
|
#include "fs_xattr.hpp"
|
|
#include "fs_exists.hpp"
|
|
#include "fs_xattr.hpp"
|
|
#include "str.hpp"
|
|
|
|
#include "scope_guard.hpp"
|
|
|
|
#include <array>
|
|
#include <cstring>
|
|
|
|
|
|
static
|
|
std::string
|
|
_mergerfs_config_file(const fs::path &mount_)
|
|
{
|
|
return mount_ / ".mergerfs";
|
|
}
|
|
|
|
bool
|
|
mergerfs::api::is_mergerfs(const fs::path &mountpoint_)
|
|
{
|
|
fs::path cfgfile;
|
|
|
|
cfgfile = ::_mergerfs_config_file(mountpoint_);
|
|
|
|
return fs::exists(cfgfile);
|
|
}
|
|
|
|
int
|
|
mergerfs::api::get_kvs(const fs::path &mountpoint_,
|
|
std::map<std::string,std::string> *kvs_)
|
|
{
|
|
int rv;
|
|
fs::path cfgfile;
|
|
|
|
cfgfile = ::_mergerfs_config_file(mountpoint_);
|
|
|
|
rv = fs::xattr::get(cfgfile,kvs_);
|
|
if(rv < 0)
|
|
return rv;
|
|
|
|
for(auto &[k,v] : *kvs_)
|
|
{
|
|
constexpr size_t offset = (sizeof("user.mergerfs.") - 1);
|
|
|
|
if(offset < k.size())
|
|
k = k.substr(offset);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
mergerfs::api::set_kv(const fs::path &mountpoint_,
|
|
const std::string &key_,
|
|
const std::string &val_)
|
|
{
|
|
fs::path cfgfile;
|
|
std::string xattr_key;
|
|
|
|
cfgfile = ::_mergerfs_config_file(mountpoint_);
|
|
xattr_key = "user.mergerfs." + key_;
|
|
|
|
return fs::xattr::set(cfgfile,xattr_key,val_,0);
|
|
}
|
|
|
|
int
|
|
mergerfs::api::allpaths(const std::string &input_path_,
|
|
std::vector<std::string> *output_paths_)
|
|
{
|
|
int rv;
|
|
std::string val;
|
|
|
|
rv = fs::xattr::get(input_path_,
|
|
"user.mergerfs.allpaths",
|
|
&val);
|
|
if(rv < 0)
|
|
return rv;
|
|
|
|
str::split_on_null(val,output_paths_);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
mergerfs::api::basepath(const std::string &input_path_,
|
|
std::string *basepath_)
|
|
{
|
|
return fs::xattr::get(input_path_,
|
|
"user.mergerfs.basepath",
|
|
basepath_);
|
|
}
|
|
|
|
int
|
|
mergerfs::api::relpath(const std::string &input_path_,
|
|
std::string *relpath_)
|
|
{
|
|
return fs::xattr::get(input_path_,
|
|
"user.mergerfs.relpath",
|
|
relpath_);
|
|
}
|
|
|
|
int
|
|
mergerfs::api::fullpath(const std::string &input_path_,
|
|
std::string *fullpath_)
|
|
{
|
|
return fs::xattr::get(input_path_,
|
|
"user.mergerfs.fullpath",
|
|
fullpath_);
|
|
}
|