2025-07-03 20:18:05 -05:00
|
|
|
#include "mergerfs_api.hpp"
|
|
|
|
|
|
|
|
|
|
#include "fs_lgetxattr.hpp"
|
|
|
|
|
#include "str.hpp"
|
|
|
|
|
|
|
|
|
|
#include "scope_guard.hpp"
|
|
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
#include <array>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
2025-07-03 20:18:05 -05:00
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
typedef std::array<char,64*1024> mfs_api_buf_t;
|
2025-07-03 20:18:05 -05:00
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
static
|
2025-07-03 20:18:05 -05:00
|
|
|
int
|
2025-07-21 18:18:59 -05:00
|
|
|
_lgetxattr(const std::string &input_path_,
|
|
|
|
|
const std::string &key_,
|
|
|
|
|
std::string &value_)
|
2025-07-03 20:18:05 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
2025-07-21 18:18:59 -05:00
|
|
|
std::string key;
|
|
|
|
|
mfs_api_buf_t buf;
|
2025-07-03 20:18:05 -05:00
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
key = "user.mergerfs." + key_;
|
|
|
|
|
rv = fs::lgetxattr(input_path_,key,buf.data(),buf.size());
|
2025-07-03 20:18:05 -05:00
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
|
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
value_.clear();
|
|
|
|
|
value_.reserve(rv);
|
|
|
|
|
value_.append(buf.data(),(size_t)rv);
|
2025-07-03 20:18:05 -05:00
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
return rv;
|
2025-07-03 20:18:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-07-21 18:18:59 -05:00
|
|
|
mergerfs::api::allpaths(const std::string &input_path_,
|
|
|
|
|
std::vector<std::string> &output_paths_)
|
2025-07-03 20:18:05 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
2025-07-21 18:18:59 -05:00
|
|
|
std::string val;
|
2025-07-03 20:18:05 -05:00
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
rv = ::_lgetxattr(input_path_,"allpaths",val);
|
2025-07-03 20:18:05 -05:00
|
|
|
if(rv < 0)
|
|
|
|
|
return rv;
|
|
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
str::split_on_null(val.data(),val.size(),&output_paths_);
|
2025-07-03 20:18:05 -05:00
|
|
|
|
2025-07-21 18:18:59 -05:00
|
|
|
return 0;
|
2025-07-03 20:18:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
mergerfs::api::basepath(const std::string &input_path_,
|
|
|
|
|
std::string &basepath_)
|
|
|
|
|
{
|
2025-07-21 18:18:59 -05:00
|
|
|
return ::_lgetxattr(input_path_,"basepath",basepath_);
|
2025-07-03 20:18:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
mergerfs::api::relpath(const std::string &input_path_,
|
|
|
|
|
std::string &relpath_)
|
|
|
|
|
{
|
2025-07-21 18:18:59 -05:00
|
|
|
return ::_lgetxattr(input_path_,"relpath",relpath_);
|
2025-07-03 20:18:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
mergerfs::api::fullpath(const std::string &input_path_,
|
|
|
|
|
std::string &fullpath_)
|
|
|
|
|
{
|
2025-07-21 18:18:59 -05:00
|
|
|
return ::_lgetxattr(input_path_,"fullpath",fullpath_);
|
2025-07-03 20:18:05 -05:00
|
|
|
}
|