mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-20 23:16:27 -05:00
Rework of runtime interface (#1498)
Also have special error handling for when branches are invalid and ENOENT would be returned for getattr and readdir so users understand what is going on and the runtime interface can still be used to fix the problem.
This commit is contained in:
parent
e87867cd2a
commit
2b500f194a
37 changed files with 3376 additions and 822 deletions
|
|
@ -1,68 +1,71 @@
|
|||
#include "mergerfs_api.hpp"
|
||||
|
||||
#include "fs_close.hpp"
|
||||
#include "fs_ioctl.hpp"
|
||||
#include "fs_open.hpp"
|
||||
#include "mergerfs_ioctl.hpp"
|
||||
#include "fs_lgetxattr.hpp"
|
||||
|
||||
#include "str.hpp"
|
||||
|
||||
#include "scope_guard.hpp"
|
||||
|
||||
#include <string.h>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
|
||||
|
||||
int
|
||||
mergerfs::api::allpaths(const std::string &input_path_,
|
||||
std::vector<std::string> &output_paths_)
|
||||
{
|
||||
int rv;
|
||||
IOCTL_BUF buf;
|
||||
|
||||
rv = fs::lgetxattr(input_path_,"user.mergerfs.allpaths",buf,sizeof(buf));
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
str::split_on_null(buf,rv,&output_paths_);
|
||||
|
||||
return 0;
|
||||
}
|
||||
typedef std::array<char,64*1024> mfs_api_buf_t;
|
||||
|
||||
static
|
||||
int
|
||||
_lgetxattr(const std::string &input_path_,
|
||||
const std::string &key_,
|
||||
std::string &value_)
|
||||
{
|
||||
int rv;
|
||||
IOCTL_BUF buf;
|
||||
std::string key;
|
||||
mfs_api_buf_t buf;
|
||||
|
||||
rv = fs::lgetxattr(input_path_,key_,buf,sizeof(buf));
|
||||
key = "user.mergerfs." + key_;
|
||||
rv = fs::lgetxattr(input_path_,key,buf.data(),buf.size());
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
value_ = buf;
|
||||
value_.clear();
|
||||
value_.reserve(rv);
|
||||
value_.append(buf.data(),(size_t)rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
mergerfs::api::allpaths(const std::string &input_path_,
|
||||
std::vector<std::string> &output_paths_)
|
||||
{
|
||||
int rv;
|
||||
std::string val;
|
||||
|
||||
rv = ::_lgetxattr(input_path_,"allpaths",val);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
str::split_on_null(val.data(),val.size(),&output_paths_);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mergerfs::api::basepath(const std::string &input_path_,
|
||||
std::string &basepath_)
|
||||
{
|
||||
return ::_lgetxattr(input_path_,"user.mergerfs.basepath",basepath_);
|
||||
return ::_lgetxattr(input_path_,"basepath",basepath_);
|
||||
}
|
||||
|
||||
int
|
||||
mergerfs::api::relpath(const std::string &input_path_,
|
||||
std::string &relpath_)
|
||||
{
|
||||
return ::_lgetxattr(input_path_,"user.mergerfs.relpath",relpath_);
|
||||
return ::_lgetxattr(input_path_,"relpath",relpath_);
|
||||
}
|
||||
|
||||
int
|
||||
mergerfs::api::fullpath(const std::string &input_path_,
|
||||
std::string &fullpath_)
|
||||
{
|
||||
return ::_lgetxattr(input_path_,"user.mergerfs.fullpath",fullpath_);
|
||||
return ::_lgetxattr(input_path_,"fullpath",fullpath_);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue