mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-25 18:40:18 -04:00
Replace std::filesystem::path with custom fs::relpath
std::filesystem::path is wrong for mergerfs's hot path:
- `branch->path / fusepath_` heap-allocates per FUSE op (3 allocs each
on libstdc++; the SSO buffer is 15 bytes and any joined path exceeds it).
- The implicit `operator string_type()` adds another std::string when
passing to `fs::*` wrappers that take `const std::string&`.
- Per-branch loops rebuild fullpath from scratch every iteration.
The new fs::relpath is a fixed 8192-byte (2 * PATH_MAX) inline buffer,
NUL-terminated, never heap-allocates. The rel data is anchored at offset
REL_OFFSET = 4096; the 4096 bytes before the anchor form the "prefix
area" so a long base/prefix can be written there in place via
set_prefix() without disturbing the rel. The remaining ~4096 bytes
after the rel are available for trailing append (filenames in
readdir-style loops, etc.).
set_prefix's cost is O(prefix size) -- only the actually-used bytes
are touched -- so the buffer size is a stack-footprint question, not a
hot-path cost. FUSE worker threads use the pthread default stack
(~8 MB on Linux); a 4-relpath frame in fuse_link/fuse_rename is 32 KB,
~0.4% of the stack budget.
The per-branch hot loop:
fs::relpath fullpath = fusepath_; // one copy of the rel
for (auto branch : branches) {
fullpath.set_prefix(branch->path); // writes only [start, 4096)
fs::syscall(fullpath);
}
set_prefix only rewrites the prefix area; the rel stays anchored. A
cached _rel_size means no recomputation across iterations.
Microbenchmark (8 branches, 30-char fusepath, -O3, 4 M path builds):
variant ns/build allocs/build
-------------------------------------- -------- ------------
origin/master (std::filesystem::path) 158 3.00
fs::relpath assign_concat (single-shot) 9.1 0
fs::relpath set_prefix (loop-optimized) 4.5 0
35x faster, zero allocations in the hot path.
Contract: paths flow through fs::relpath in canonical form -- prefix
without trailing '/', rel without leading '/'. No sanitization;
violations yield double slashes. Mergerfs satisfies this by
construction:
- libfuse's try_get_path() walks leaf-to-root via prepend(), then
calls consolidate_to_rel(strip=true) which drops the leading '/'
that prepend produces.
- branch paths are realpath-canonicalized at config load so they
never have a trailing slash.
Mergerfs has exactly one path-manipulation type: a relative fusepath.
Branch paths and other absolute paths are stored as std::string -- they
are spliced into the prefix area of an fs::relpath at syscall time but
are never themselves mutated as path objects.
Major changes:
- vendored/libfuse/{include/fs_path.hpp,lib/fs_path.cpp}: new
fs::relpath class (8 KB inline, REL anchor at 4096, set_prefix /
clear_prefix / consolidate_to_rel, _rel_size cache, self-aliasing-
safe assign_concat, sticky ENAMETOOLONG via errnum()).
- 30+ FUSE-op call sites converted from `fullpath = branch / fusepath`
to the `set_prefix` loop pattern (fuse_unlink, fuse_chmod,
fuse_chown, fuse_listxattr, fuse_truncate, fuse_utimens,
fuse_setxattr, fuse_rmdir, fuse_removexattr, fuse_link's
preserve-path and create-path loops, fuse_rename's create-path
and preserve-path loops, fuse_statfs FULL mode, fs::findallfiles,
fs::findonfs).
- fs::* syscall wrappers that previously only took
`const std::string&` got `const char*` overloads so fs::relpath's
implicit `operator const char*()` lands cleanly (fs::link,
fs::lutimens, fs::umount_lazy, fs::open_dir_ro, fs::readlink,
fs::lremovexattr, fs::lstatvfs, fs::info, fs::statvfs_cache).
- fs::exists gained a (fs::relpath&, basepath, ...) overload that
calls set_prefix internally so per-branch policy fan-out loops
share a single fullpath, rewriting only the prefix area on each
iteration.
- All policies (epall, epff, eplfs, eplus, epmfs, eppfrd, ff, lup,
msplfs, msplus, mspmfs, msppfrd, newest) refactored to hoist the
fs::relpath fullpath construction out of the per-branch loop and
use the set_prefix-based fs::exists overload.
- fs::inode::ReaddirCalc::_fusepath migrated from std::string to
fs::relpath with the same resize/append API.
- std::filesystem removed entirely from the project: branches.cpp
and option_parser.cpp's exists/is_directory/equivalent calls now
use direct ::stat(); mergerfs_fsck.cpp's recursive_directory_iterator
was replaced with an opendir-based walk.
Tests (tests/tests.cpp): 27 new fs::relpath test cases covering
construction, set_prefix in/out of REL anchor, prefix()/rel()
accessors, clear_prefix, concat canonical form, self-aliasing
(`p /= "x"`), operator/=, resize zero-fill, swap, copy/move,
equality, implicit conversions, lexically_relative, remove_filename,
_rel_size invariant across every mutator, capacity bounds.
Full suite: 213/213 pass.
This commit is contained in:
parent
7ec6f8e2f2
commit
947024914a
187 changed files with 3596 additions and 1510 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -31,3 +31,6 @@ rpmbuild/
|
|||
# mkdocs files
|
||||
mkdocs/venv
|
||||
__pycache__/
|
||||
|
||||
# Claude Code session state
|
||||
.claude/
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "base_types.h"
|
||||
#include "strvec.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
|
@ -43,7 +42,7 @@ public:
|
|||
public:
|
||||
std::variant<u64,const u64*> _minfreespace;
|
||||
Mode mode;
|
||||
fs::path path;
|
||||
std::string path;
|
||||
|
||||
public:
|
||||
Branch();
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@
|
|||
#include <shared_mutex>
|
||||
#include <string>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <fnmatch.h>
|
||||
|
||||
|
||||
|
|
@ -225,13 +228,24 @@ namespace l
|
|||
fs::realpathize(&paths);
|
||||
for(auto &path : paths)
|
||||
{
|
||||
std::error_code ec;
|
||||
struct stat st;
|
||||
int rv;
|
||||
|
||||
if(!std::filesystem::exists(path,ec))
|
||||
rv = ::stat(path.c_str(),&st);
|
||||
if(rv < 0)
|
||||
{
|
||||
SysLog::notice("branch `{}` does not currently exist",path);
|
||||
// Distinguish "doesn't exist" (the common case where the
|
||||
// backing storage isn't mounted yet) from harder errors
|
||||
// like permission, name-too-long, ELOOP, etc., which
|
||||
// suggest a config problem rather than transient absence.
|
||||
if(errno == ENOENT)
|
||||
SysLog::notice("branch `{}` does not currently exist",path);
|
||||
else
|
||||
SysLog::warning("branch `{}` could not be stat'd: {}",
|
||||
path,
|
||||
strerror(errno));
|
||||
}
|
||||
else if(!std::filesystem::is_directory(path,ec))
|
||||
else if(!S_ISDIR(st.st_mode))
|
||||
{
|
||||
SysLog::warning("branch `{}` is not a directory, skipping",path);
|
||||
continue;
|
||||
|
|
@ -417,14 +431,14 @@ Branches::Impl::to_paths(StrVec &paths_) const
|
|||
{
|
||||
for(auto &branch : *this)
|
||||
{
|
||||
paths_.push_back(branch.path);
|
||||
paths_.emplace_back(branch.path);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<fs::path>
|
||||
std::vector<std::string>
|
||||
Branches::Impl::to_paths() const
|
||||
{
|
||||
std::vector<fs::path> vp;
|
||||
std::vector<std::string> vp;
|
||||
|
||||
for(const auto &branch : *this)
|
||||
vp.emplace_back(branch.path);
|
||||
|
|
@ -484,7 +498,7 @@ Branches::find_and_set_mode_ro()
|
|||
{
|
||||
Branches::Ptr impl;
|
||||
Branches::Ptr new_impl;
|
||||
std::vector<fs::path> ro_paths;
|
||||
std::vector<std::string> ro_paths;
|
||||
|
||||
new_impl = std::make_shared<Branches::Impl>(&minfreespace);
|
||||
|
||||
|
|
@ -524,7 +538,7 @@ Branches::find_and_set_mode_ro()
|
|||
|
||||
for(const auto &path : ro_paths)
|
||||
SysLog::warning("branch `{}` found to be readonly - setting its mode=RO",
|
||||
path.string());
|
||||
path);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "branch.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "strvec.hpp"
|
||||
#include "tofrom_string.hpp"
|
||||
|
||||
|
|
@ -54,7 +53,7 @@ public:
|
|||
public:
|
||||
const u64 &minfreespace(void) const;
|
||||
void to_paths(StrVec &strvec) const;
|
||||
std::vector<fs::path> to_paths() const;
|
||||
std::vector<std::string> to_paths() const;
|
||||
|
||||
public:
|
||||
Impl& operator=(Impl &impl_);
|
||||
|
|
|
|||
|
|
@ -46,16 +46,16 @@ int
|
|||
Config::CfgConfigFile::from_string(const std::string_view s_)
|
||||
{
|
||||
int rv;
|
||||
fs::path cfg_file;
|
||||
std::string cfg_file;
|
||||
|
||||
if(_depth > 5)
|
||||
return -ELOOP;
|
||||
_depth++;
|
||||
struct DepthGuard { int &d; ~DepthGuard() { --d; } } guard{_depth};
|
||||
|
||||
cfg_file = (s_.empty() ? _cfg_file : s_);
|
||||
cfg_file = (s_.empty() ? std::string_view(_cfg_file) : s_);
|
||||
|
||||
rv = cfg.from_file(cfg_file);
|
||||
rv = cfg.from_file(cfg_file.c_str());
|
||||
if(rv == 0)
|
||||
_cfg_file = cfg_file;
|
||||
|
||||
|
|
@ -426,7 +426,7 @@ Config::from_stream(std::istream &istrm_)
|
|||
}
|
||||
|
||||
int
|
||||
Config::from_file(const std::string &filepath_)
|
||||
Config::from_file(const char *filepath_)
|
||||
{
|
||||
std::ifstream ifstrm;
|
||||
|
||||
|
|
@ -449,13 +449,13 @@ Config::finish_initializing()
|
|||
}
|
||||
|
||||
bool
|
||||
Config::is_rootdir(const fs::path &fusepath_)
|
||||
Config::is_rootdir(const fs::relpath &fusepath_)
|
||||
{
|
||||
return fusepath_.empty();
|
||||
}
|
||||
|
||||
bool
|
||||
Config::is_ctrl_file(const fs::path &fusepath_)
|
||||
Config::is_ctrl_file(const fs::relpath &fusepath_)
|
||||
{
|
||||
return (fusepath_ == ".mergerfs");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ typedef ToFromWrapper<u64> ConfigU64;
|
|||
typedef ToFromWrapper<s64> ConfigS64;
|
||||
typedef ToFromWrapper<int> ConfigINT;
|
||||
typedef ToFromWrapper<std::string> ConfigSTR;
|
||||
typedef ToFromWrapper<fs::path> ConfigPath;
|
||||
typedef ToFromWrapper<std::string> ConfigPath;
|
||||
typedef std::map<std::string,ToFromString*> Str2TFStrMap;
|
||||
typedef ROToFromWrapper<std::string> ConfigROSTR;
|
||||
|
||||
|
|
@ -92,7 +92,7 @@ public:
|
|||
class CfgConfigFile : public ToFromString
|
||||
{
|
||||
private:
|
||||
fs::path _cfg_file;
|
||||
std::string _cfg_file;
|
||||
static thread_local int _depth;
|
||||
|
||||
public:
|
||||
|
|
@ -141,7 +141,7 @@ public:
|
|||
LinkEXDEV link_exdev;
|
||||
LogFile log_file;
|
||||
TFSRef<u64> minfreespace;
|
||||
fs::path mountpoint;
|
||||
std::string mountpoint;
|
||||
MoveOnENOSPC moveonenospc;
|
||||
NFSOpenHack nfsopenhack;
|
||||
ConfigBOOL nullrw;
|
||||
|
|
@ -172,8 +172,8 @@ private:
|
|||
CfgDummy _dummy;
|
||||
TFSRef<s64> _gid;
|
||||
TFSRef<int> _max_background;
|
||||
TFSRef<fs::path> _mount;
|
||||
TFSRef<fs::path> _mountpoint;
|
||||
TFSRef<std::string> _mount;
|
||||
TFSRef<std::string> _mountpoint;
|
||||
CfgNoforget _never_forget_nodes;
|
||||
CfgNoforget _noforget;
|
||||
CfgNoforget _remember;
|
||||
|
|
@ -207,11 +207,11 @@ public:
|
|||
|
||||
public:
|
||||
int from_stream(std::istream &istrm);
|
||||
int from_file(const std::string &filepath);
|
||||
int from_file(const char *filepath);
|
||||
|
||||
public:
|
||||
static bool is_rootdir(const fs::path &fusepath);
|
||||
static bool is_ctrl_file(const fs::path &fusepath);
|
||||
static bool is_rootdir(const fs::relpath &fusepath);
|
||||
static bool is_ctrl_file(const fs::relpath &fusepath);
|
||||
static bool is_mergerfs_xattr(const char *attrname);
|
||||
static bool is_cmd_xattr(const std::string_view &attrname);
|
||||
static std::string_view prune_ctrl_xattr(const std::string_view s);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public:
|
|||
u64 to_fh() const;
|
||||
|
||||
public:
|
||||
DirInfo(const fs::path &fusepath_)
|
||||
DirInfo(const fs::relpath &fusepath_)
|
||||
: FH(fusepath_)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@
|
|||
class FH
|
||||
{
|
||||
public:
|
||||
FH(const fs::path &fusepath_)
|
||||
FH(const fs::relpath &fusepath_)
|
||||
: fusepath(fusepath_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public:
|
||||
fs::path fusepath;
|
||||
fs::relpath fusepath;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public:
|
|||
public:
|
||||
FileInfo(const int fd_,
|
||||
const Branch *branch_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const bool direct_io_)
|
||||
: FH(fusepath_),
|
||||
fd(fd_),
|
||||
|
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
FileInfo(const int fd_,
|
||||
const Branch &branch_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const bool direct_io_)
|
||||
: FH(fusepath_),
|
||||
fd(fd_),
|
||||
|
|
|
|||
|
|
@ -206,12 +206,3 @@ str::from(const std::string_view value_,
|
|||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
int
|
||||
str::from(const std::string_view value_,
|
||||
fs::path *path_)
|
||||
{
|
||||
*path_ = value_;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "base_types.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
|
@ -33,5 +32,4 @@ namespace str
|
|||
int from(const std::string_view, s64 *);
|
||||
int from(const std::string_view, std::string *);
|
||||
int from(const std::string_view, const std::string *);
|
||||
int from(const std::string_view, fs::path *);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,16 +21,15 @@
|
|||
#include "fs_lgetxattr.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
constexpr const char POSIX_ACL_DEFAULT_XATTR[] = "system.posix_acl_default";
|
||||
|
||||
|
||||
bool
|
||||
fs::acl::dir_has_defaults(const fs::path &fullpath_)
|
||||
fs::acl::dir_has_defaults(const fs::relpath &fullpath_)
|
||||
{
|
||||
int rv;
|
||||
fs::path dirpath;
|
||||
fs::relpath dirpath;
|
||||
|
||||
dirpath = fullpath_.parent_path();
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,6 @@ namespace fs
|
|||
namespace acl
|
||||
{
|
||||
bool
|
||||
dir_has_defaults(const fs::path &fullpath);
|
||||
dir_has_defaults(const fs::relpath &fullpath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ _get_fs_ioc_flags(const int fd,
|
|||
|
||||
static
|
||||
int
|
||||
_get_fs_ioc_flags(const string &file,
|
||||
int &flags)
|
||||
_get_fs_ioc_flags(const char *file,
|
||||
int &flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
|
|
@ -81,8 +81,8 @@ _set_fs_ioc_flags(const int fd,
|
|||
|
||||
static
|
||||
int
|
||||
_set_fs_ioc_flags(const string &file,
|
||||
const int flags)
|
||||
_set_fs_ioc_flags(const char *file,
|
||||
const int flags)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
|
|
@ -121,15 +121,15 @@ fs::attr::copy(const int fdin,
|
|||
}
|
||||
|
||||
int
|
||||
fs::attr::copy(const string &from,
|
||||
const string &to)
|
||||
fs::attr::copy(const std::string &from_,
|
||||
const std::string &to_)
|
||||
{
|
||||
int rv;
|
||||
int flags;
|
||||
|
||||
rv = ::_get_fs_ioc_flags(from,flags);
|
||||
rv = ::_get_fs_ioc_flags(from_.c_str(),flags);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
return ::_set_fs_ioc_flags(to,flags);
|
||||
return ::_set_fs_ioc_flags(to_.c_str(),flags);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,37 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_cleanpath.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
void
|
||||
fs::cleanpath(std::string *path_)
|
||||
{
|
||||
std::string &s = *path_;
|
||||
std::size_t w = 0;
|
||||
bool prev_slash = false;
|
||||
|
||||
for(std::size_t r = 0; r < s.size(); r++)
|
||||
{
|
||||
const char c = s[r];
|
||||
if(c == '/')
|
||||
{
|
||||
if(prev_slash)
|
||||
continue;
|
||||
prev_slash = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
prev_slash = false;
|
||||
}
|
||||
s[w++] = c;
|
||||
}
|
||||
|
||||
// Strip trailing '/' but leave a bare "/" intact.
|
||||
if(w > 1 && s[w - 1] == '/')
|
||||
w--;
|
||||
|
||||
s.resize(w);
|
||||
}
|
||||
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
using path = std::filesystem::path;
|
||||
void cleanpath(std::string *path);
|
||||
}
|
||||
|
|
@ -61,60 +61,84 @@ _ignorable_error(const int err_)
|
|||
The directories which already exist are left alone.
|
||||
The new directories have metadata set to match the original if
|
||||
possible. Optionally ignore errors on metadata copies.
|
||||
|
||||
Iterative root-to-leaf walk. Stack usage is O(1) in component count.
|
||||
*/
|
||||
int
|
||||
fs::clonepath(const fs::path &srcpath_,
|
||||
const fs::path &dstpath_,
|
||||
const fs::path &relpath_,
|
||||
const bool return_metadata_errors_)
|
||||
fs::clonepath(const std::string_view srcpath_,
|
||||
const std::string_view dstpath_,
|
||||
const fs::relpath &relpath_,
|
||||
const bool return_metadata_errors_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
fs::path dstpath;
|
||||
fs::path srcpath;
|
||||
fs::path dirname;
|
||||
|
||||
if(relpath_.empty())
|
||||
return 0;
|
||||
|
||||
dirname = relpath_.parent_path();
|
||||
if(!dirname.empty())
|
||||
std::string srcpath;
|
||||
std::string dstpath;
|
||||
srcpath.reserve(srcpath_.size() + relpath_.size() + 1);
|
||||
dstpath.reserve(dstpath_.size() + relpath_.size() + 1);
|
||||
srcpath = srcpath_;
|
||||
dstpath = dstpath_;
|
||||
|
||||
std::string_view rel = relpath_.native();
|
||||
std::size_t pos = 0;
|
||||
while(pos < rel.size())
|
||||
{
|
||||
rv = fs::clonepath(srcpath_,dstpath_,dirname,return_metadata_errors_);
|
||||
std::size_t next = rel.find('/',pos);
|
||||
if(next == std::string_view::npos)
|
||||
next = rel.size();
|
||||
|
||||
std::string_view component = rel.substr(pos,next - pos);
|
||||
pos = next + 1;
|
||||
// Defensive: canonical rel form should not produce empty
|
||||
// segments, but skip them if the input is malformed (e.g. a
|
||||
// double slash) rather than appending nothing and re-stat'ing
|
||||
// the same path.
|
||||
if(component.empty())
|
||||
continue;
|
||||
|
||||
srcpath += '/';
|
||||
srcpath.append(component);
|
||||
dstpath += '/';
|
||||
dstpath.append(component);
|
||||
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
||||
rv = fs::lstat(srcpath,&st);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
if(!S_ISDIR(st.st_mode))
|
||||
return -ENOTDIR;
|
||||
|
||||
rv = fs::mkdir(dstpath,st.st_mode);
|
||||
if(rv < 0 && rv != -EEXIST)
|
||||
return rv;
|
||||
// EEXIST: directory already there (could be from a prior clone
|
||||
// or a race). Leave it alone, do NOT re-copy metadata, matching
|
||||
// the recursive version's behavior when its mkdir hit EEXIST.
|
||||
if(rv == -EEXIST)
|
||||
continue;
|
||||
|
||||
// it may not support it... it's fine...
|
||||
rv = fs::attr::copy(srcpath,dstpath);
|
||||
if(return_metadata_errors_ && (rv < 0) && !::_ignorable_error(-rv))
|
||||
return rv;
|
||||
|
||||
// it may not support it... it's fine...
|
||||
rv = fs::xattr::copy(srcpath,dstpath);
|
||||
if(return_metadata_errors_ && (rv < 0) && !::_ignorable_error(-rv))
|
||||
return rv;
|
||||
|
||||
rv = fs::lchown_check_on_error(dstpath,st);
|
||||
if(return_metadata_errors_ && (rv < 0))
|
||||
return rv;
|
||||
|
||||
rv = fs::lutimens(dstpath,st);
|
||||
if(return_metadata_errors_ && (rv < 0))
|
||||
return rv;
|
||||
}
|
||||
|
||||
srcpath = srcpath_ / relpath_;
|
||||
rv = fs::lstat(srcpath,&st);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
else if(!S_ISDIR(st.st_mode))
|
||||
return -ENOTDIR;
|
||||
|
||||
dstpath = dstpath_ / relpath_;
|
||||
rv = fs::mkdir(dstpath,st.st_mode);
|
||||
if(rv < 0)
|
||||
return ((rv == -EEXIST) ? 0 : rv);
|
||||
|
||||
// it may not support it... it's fine...
|
||||
rv = fs::attr::copy(srcpath,dstpath);
|
||||
if(return_metadata_errors_ && (rv < 0) && !::_ignorable_error(-rv))
|
||||
return rv;
|
||||
|
||||
// it may not support it... it's fine...
|
||||
rv = fs::xattr::copy(srcpath,dstpath);
|
||||
if(return_metadata_errors_ && (rv < 0) && !::_ignorable_error(-rv))
|
||||
return rv;
|
||||
|
||||
rv = fs::lchown_check_on_error(dstpath,st);
|
||||
if(return_metadata_errors_ && (rv < 0))
|
||||
return rv;
|
||||
|
||||
rv = fs::lutimens(dstpath,st);
|
||||
if(return_metadata_errors_ && (rv < 0))
|
||||
return rv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -122,10 +146,10 @@ fs::clonepath(const fs::path &srcpath_,
|
|||
// WORK IN PROGRESS
|
||||
static
|
||||
int
|
||||
_clonepath2(const int srcfd_,
|
||||
const int dstfd_,
|
||||
const fs::path &dirname_,
|
||||
const bool return_metadata_errors_)
|
||||
_clonepath2(const int srcfd_,
|
||||
const int dstfd_,
|
||||
const fs::relpath &dirname_,
|
||||
const bool return_metadata_errors_)
|
||||
{
|
||||
int rv;
|
||||
int srcdirfd;
|
||||
|
|
|
|||
|
|
@ -20,11 +20,16 @@
|
|||
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int clonepath(const fs::path &srcpath,
|
||||
const fs::path &dstpath,
|
||||
const fs::path &relpath,
|
||||
const bool return_metadata_errors = false);
|
||||
// srcpath / dstpath are absolute base paths; relpath is the rel-form
|
||||
// chain to walk and create. Accepts string_view so an fs::relpath
|
||||
// holding an absolute fullpath also works without conversion.
|
||||
int clonepath(const std::string_view srcpath,
|
||||
const std::string_view dstpath,
|
||||
const fs::relpath &relpath,
|
||||
const bool return_metadata_errors = false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ fs::copyfile(const int src_fd_,
|
|||
|
||||
s64
|
||||
fs::copyfile(const int src_fd_,
|
||||
const fs::path &dst_filepath_,
|
||||
const char *dst_filepath_,
|
||||
const fs::CopyFileFlags &flags_)
|
||||
{
|
||||
s64 rv;
|
||||
|
|
@ -155,7 +155,7 @@ fs::copyfile(const int src_fd_,
|
|||
continue;
|
||||
}
|
||||
|
||||
rv = fs::rename(dst_tmppath,dst_filepath_);
|
||||
rv = fs::rename(dst_tmppath.c_str(),dst_filepath_);
|
||||
if((rv < 0) && (flags_.cleanup_failure))
|
||||
fs::unlink(dst_tmppath);
|
||||
break;
|
||||
|
|
@ -170,8 +170,8 @@ fs::copyfile(const int src_fd_,
|
|||
#endif
|
||||
|
||||
s64
|
||||
fs::copyfile(const fs::path &src_filepath_,
|
||||
const fs::path &dst_filepath_,
|
||||
fs::copyfile(const char *src_filepath_,
|
||||
const char *dst_filepath_,
|
||||
const fs::CopyFileFlags &flags_)
|
||||
{
|
||||
int src_fd;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "base_types.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
|
@ -40,11 +41,21 @@ namespace fs
|
|||
|
||||
s64
|
||||
copyfile(const int src_fd,
|
||||
const fs::path &dst_filepath,
|
||||
const char *dst_filepath,
|
||||
const CopyFileFlags &flags);
|
||||
|
||||
s64
|
||||
copyfile(const fs::path &src_filepath,
|
||||
const fs::path &dst_filepath,
|
||||
copyfile(const char *src_filepath,
|
||||
const char *dst_filepath,
|
||||
const CopyFileFlags &flags);
|
||||
|
||||
static
|
||||
inline
|
||||
s64
|
||||
copyfile(const std::string &src_filepath,
|
||||
const std::string &dst_filepath,
|
||||
const CopyFileFlags &flags)
|
||||
{
|
||||
return fs::copyfile(src_filepath.c_str(),dst_filepath.c_str(),flags);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ fs::cow::is_eligible(const int flags_,
|
|||
}
|
||||
|
||||
bool
|
||||
fs::cow::is_eligible(const fs::path &fullpath_,
|
||||
const int flags_)
|
||||
fs::cow::is_eligible(const std::string &fullpath_,
|
||||
const int flags_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
|
@ -70,7 +70,7 @@ fs::cow::is_eligible(const fs::path &fullpath_,
|
|||
}
|
||||
|
||||
int
|
||||
fs::cow::break_link(const fs::path &src_filepath_)
|
||||
fs::cow::break_link(const std::string &src_filepath_)
|
||||
{
|
||||
return fs::copyfile(src_filepath_,
|
||||
src_filepath_,
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
|
@ -32,8 +31,8 @@ namespace fs
|
|||
bool is_eligible(const struct stat &st);
|
||||
bool is_eligible(const int flags, const struct stat &st);
|
||||
|
||||
bool is_eligible(const fs::path &fullpath, const int flags);
|
||||
bool is_eligible(const std::string &fullpath, const int flags);
|
||||
|
||||
int break_link(const fs::path &fullpath);
|
||||
int break_link(const std::string &fullpath);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
eaccess(const fs::path &path_,
|
||||
eaccess(const fs::relpath &path_,
|
||||
const int mode_)
|
||||
{
|
||||
return fs::eaccess(path_.c_str(),mode_);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::path &path_,
|
||||
struct stat *st_)
|
||||
exists(const char *path_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::path &path_)
|
||||
exists(const char *path_)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
|
|
@ -50,13 +50,49 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::path &basepath_,
|
||||
const char *relpath_,
|
||||
struct stat *st_)
|
||||
exists(const std::string &path_,
|
||||
struct stat *st_)
|
||||
{
|
||||
fs::path fullpath;
|
||||
return fs::exists(path_.c_str(),st_);
|
||||
}
|
||||
|
||||
fullpath = basepath_ / relpath_;
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const std::string &path_)
|
||||
{
|
||||
return fs::exists(path_.c_str());
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::relpath &path_,
|
||||
struct stat *st_)
|
||||
{
|
||||
return fs::exists(path_.c_str(),st_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::relpath &path_)
|
||||
{
|
||||
return fs::exists(path_.c_str());
|
||||
}
|
||||
|
||||
// Two-arg helpers for the per-branch loop pattern: build
|
||||
// basepath/'/'/relpath into an fs::relpath and stat it.
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const std::string &basepath_,
|
||||
const fs::relpath &relpath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
fs::relpath fullpath;
|
||||
|
||||
fullpath.assign_concat(basepath_,relpath_);
|
||||
|
||||
return fs::exists(fullpath,st_);
|
||||
}
|
||||
|
|
@ -64,36 +100,37 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::path &basepath_,
|
||||
const fs::path &relpath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
fs::path fullpath;
|
||||
|
||||
fullpath = basepath_ / relpath_;
|
||||
|
||||
return fs::exists(fullpath,st_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::path &basepath_,
|
||||
const char *relpath_)
|
||||
exists(const std::string &basepath_,
|
||||
const fs::relpath &relpath_)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
return fs::exists(basepath_,relpath_,&st);
|
||||
}
|
||||
|
||||
// Hot-path variant for per-branch fan-out loops. The caller builds
|
||||
// the fullpath once (with the rel portion set) outside the loop, and
|
||||
// each iteration only rewrites the prefix area via set_prefix --
|
||||
// skipping the per-iteration rel memmove that the (basepath,
|
||||
// relpath) overload incurs.
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(const fs::path &basepath_,
|
||||
const fs::path &relpath_)
|
||||
exists(fs::relpath &fullpath_,
|
||||
const std::string &basepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
struct stat st;
|
||||
fullpath_.set_prefix(basepath_);
|
||||
return fs::exists(fullpath_.c_str(),st_);
|
||||
}
|
||||
|
||||
return fs::exists(basepath_,relpath_,&st);
|
||||
static
|
||||
inline
|
||||
bool
|
||||
exists(fs::relpath &fullpath_,
|
||||
const std::string &basepath_)
|
||||
{
|
||||
fullpath_.set_prefix(basepath_);
|
||||
return fs::exists(fullpath_.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
faccessat(const int dirfd_,
|
||||
const fs::path &path_,
|
||||
const fs::relpath &path_,
|
||||
const int mode_,
|
||||
const int flags_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
fchmodat(const int dirfd_,
|
||||
const fs::path &pathname_,
|
||||
const fs::relpath &pathname_,
|
||||
const mode_t mode_,
|
||||
const int flags_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#include "to_neg_errno.hpp"
|
||||
#include "xattr.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
|
|
|||
|
|
@ -27,18 +27,18 @@
|
|||
|
||||
void
|
||||
fs::findallfiles(const std::vector<std::string> &basepaths_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
std::vector<std::string> *paths_)
|
||||
{
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath = fusepath_;
|
||||
|
||||
for(const auto &basepath : basepaths_)
|
||||
{
|
||||
fullpath = basepath / fusepath_;
|
||||
fullpath.set_prefix(basepath);
|
||||
|
||||
if(!fs::exists(fullpath))
|
||||
continue;
|
||||
|
||||
paths_->push_back(fullpath);
|
||||
paths_->emplace_back(fullpath.native());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,6 @@ namespace fs
|
|||
{
|
||||
void
|
||||
findallfiles(const std::vector<std::string> &basepaths,
|
||||
const fs::path &fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
std::vector<std::string> *paths);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@
|
|||
static
|
||||
int
|
||||
_findonfs(const Branches::Ptr &branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const int fd_,
|
||||
std::string *basepath_)
|
||||
{
|
||||
int rv;
|
||||
dev_t dev;
|
||||
struct stat st;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath = fusepath_;
|
||||
|
||||
rv = fs::fstat(fd_,&st);
|
||||
if(rv < 0)
|
||||
|
|
@ -46,7 +46,7 @@ _findonfs(const Branches::Ptr &branches_,
|
|||
dev = st.st_dev;
|
||||
for(const auto &branch : *branches_)
|
||||
{
|
||||
fullpath = branch.path / fusepath_;
|
||||
fullpath.set_prefix(branch.path);
|
||||
|
||||
rv = fs::lstat(fullpath,&st);
|
||||
if(rv < 0)
|
||||
|
|
@ -70,5 +70,15 @@ fs::findonfs(const Branches::Ptr &branches_,
|
|||
const int fd_,
|
||||
std::string *basepath_)
|
||||
{
|
||||
return ::_findonfs(branches_,fusepath_,fd_,basepath_);
|
||||
// The public API accepts std::string for caller convenience.
|
||||
// Internally we need a canonical-rel fusepath (no leading '/') so
|
||||
// the per-branch loop's set_prefix() produces a single separator.
|
||||
// Strip the leading '/' by hand if present.
|
||||
std::string_view sv(fusepath_);
|
||||
if(!sv.empty() && sv.front() == '/')
|
||||
sv.remove_prefix(1);
|
||||
|
||||
fs::relpath fusepath(sv);
|
||||
|
||||
return ::_findonfs(branches_,fusepath,fd_,basepath_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@
|
|||
|
||||
namespace fs
|
||||
{
|
||||
// Public API takes std::string for caller convenience. Internally
|
||||
// we strip any leading '/' so the per-branch loop's set_prefix()
|
||||
// produces a single separator; this entry point handles the
|
||||
// conversion.
|
||||
int
|
||||
findonfs(const Branches::Ptr &branches,
|
||||
const std::string &fusepath,
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
fstatat(const int dirfd_,
|
||||
const fs::path &pathname_,
|
||||
const fs::relpath &pathname_,
|
||||
struct stat *statbuf_,
|
||||
const int flags_)
|
||||
{
|
||||
|
|
@ -75,7 +75,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
fstatat_nofollow(const int dirfd_,
|
||||
const fs::path &pathname_,
|
||||
const fs::relpath &pathname_,
|
||||
struct stat *statbuf_)
|
||||
{
|
||||
return fs::fstatat(dirfd_,
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@
|
|||
static
|
||||
inline
|
||||
bool
|
||||
_can_call_lutimes(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const int flags_)
|
||||
_can_call_lutimes(const int dirfd_,
|
||||
const char *path_,
|
||||
const int flags_)
|
||||
{
|
||||
return ((flags_ == AT_SYMLINK_NOFOLLOW) &&
|
||||
((dirfd_ == AT_FDCWD) ||
|
||||
|
|
@ -117,7 +117,7 @@ static
|
|||
inline
|
||||
int
|
||||
_set_utime_omit_to_current_value(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const char *path_,
|
||||
const struct timespec ts_[2],
|
||||
struct timeval tv_[2],
|
||||
const int flags_)
|
||||
|
|
@ -203,7 +203,7 @@ static
|
|||
inline
|
||||
int
|
||||
_convert_timespec_to_timeval(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const char *path_,
|
||||
const struct timespec ts_[2],
|
||||
struct timeval tv_[2],
|
||||
struct timeval **tvp_,
|
||||
|
|
|
|||
|
|
@ -21,12 +21,10 @@
|
|||
#include "fs_statvfs.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
bool
|
||||
fs::has_space(const std::string &str_,
|
||||
cs64 size_)
|
||||
fs::has_space(const char *str_,
|
||||
cs64 size_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
|
|
|||
|
|
@ -26,6 +26,15 @@
|
|||
namespace fs
|
||||
{
|
||||
bool
|
||||
has_space(const std::string &str,
|
||||
cs64 size);
|
||||
has_space(const char *str,
|
||||
cs64 size);
|
||||
|
||||
static
|
||||
inline
|
||||
bool
|
||||
has_space(const std::string &path,
|
||||
cs64 size)
|
||||
{
|
||||
return fs::has_space(path.c_str(),size);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@ using std::string;
|
|||
|
||||
|
||||
int
|
||||
fs::info(const string &path_,
|
||||
fs::info_t *info_)
|
||||
fs::info(const char *path_,
|
||||
fs::info_t *info_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
||||
rv = fs::statvfs_cache(path_.c_str(),&st);
|
||||
rv = fs::statvfs_cache(path_,&st);
|
||||
if(rv == 0)
|
||||
{
|
||||
info_->readonly = StatVFS::readonly(st);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,15 @@
|
|||
namespace fs
|
||||
{
|
||||
int
|
||||
info(const std::string &path,
|
||||
fs::info_t *info);
|
||||
info(const char *path,
|
||||
fs::info_t *info);
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
info(const std::string &path_,
|
||||
fs::info_t *info_)
|
||||
{
|
||||
return fs::info(path_.c_str(),info_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -289,11 +289,11 @@ fs::inode::get_algo(void)
|
|||
return {};
|
||||
}
|
||||
|
||||
fs::inode::ReaddirCalc::ReaddirCalc(const fs::path &branch_path_,
|
||||
const fs::path &dirpath_)
|
||||
fs::inode::ReaddirCalc::ReaddirCalc(const std::string &branch_path_,
|
||||
const fs::relpath &dirpath_)
|
||||
: _algo(::_algo_from_func(g_func.load())),
|
||||
_branch_seed(::_branch_seed(branch_path_.native())),
|
||||
_fusepath((dirpath_ / "__mergerfs__").native()),
|
||||
_branch_seed(::_branch_seed(branch_path_)),
|
||||
_fusepath(fs::relpath::concat(dirpath_,"__mergerfs__")),
|
||||
_filename_offset(_fusepath.size() - std::string_view("__mergerfs__").size())
|
||||
{
|
||||
}
|
||||
|
|
@ -337,23 +337,11 @@ fs::inode::ReaddirCalc::calc(const char *name_,
|
|||
|
||||
u64
|
||||
fs::inode::calc(const std::string &branch_path_,
|
||||
const std::string &fusepath_,
|
||||
const mode_t mode_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
return g_func.load()(branch_path_,
|
||||
fusepath_,
|
||||
mode_,
|
||||
ino_);
|
||||
}
|
||||
|
||||
u64
|
||||
fs::inode::calc(const fs::path &branch_path_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
return g_func.load()(branch_path_.native(),
|
||||
return g_func.load()(branch_path_,
|
||||
fusepath_.native(),
|
||||
mode_,
|
||||
ino_);
|
||||
|
|
@ -361,18 +349,7 @@ fs::inode::calc(const fs::path &branch_path_,
|
|||
|
||||
void
|
||||
fs::inode::calc(const std::string &branch_path_,
|
||||
const std::string &fusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
st_->st_ino = calc(branch_path_,
|
||||
fusepath_,
|
||||
st_->st_mode,
|
||||
st_->st_ino);
|
||||
}
|
||||
|
||||
void
|
||||
fs::inode::calc(const fs::path &branch_path_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
st_->st_ino = calc(branch_path_,
|
||||
|
|
@ -382,19 +359,8 @@ fs::inode::calc(const fs::path &branch_path_,
|
|||
}
|
||||
|
||||
void
|
||||
fs::inode::calc(const std::string &branch_path_,
|
||||
const std::string &fusepath_,
|
||||
struct fuse_statx *st_)
|
||||
{
|
||||
st_->ino = calc(branch_path_,
|
||||
fusepath_,
|
||||
st_->mode,
|
||||
st_->ino);
|
||||
}
|
||||
|
||||
void
|
||||
fs::inode::calc(const fs::path &branch_path_,
|
||||
const fs::path &fusepath_,
|
||||
fs::inode::calc(const std::string &branch_path_,
|
||||
const fs::relpath &fusepath_,
|
||||
struct fuse_statx *st_)
|
||||
{
|
||||
st_->ino = calc(branch_path_,
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ namespace fs
|
|||
class ReaddirCalc
|
||||
{
|
||||
public:
|
||||
ReaddirCalc(const fs::path &branch_path,
|
||||
const fs::path &dirpath);
|
||||
ReaddirCalc(const std::string &branch_path,
|
||||
const fs::relpath &dirpath);
|
||||
|
||||
public:
|
||||
u64 calc(const char *name,
|
||||
|
|
@ -59,7 +59,7 @@ namespace fs
|
|||
private:
|
||||
Algo _algo;
|
||||
u64 _branch_seed;
|
||||
std::string _fusepath;
|
||||
fs::relpath _fusepath;
|
||||
std::size_t _filename_offset;
|
||||
};
|
||||
|
||||
|
|
@ -67,25 +67,15 @@ namespace fs
|
|||
std::string get_algo(void);
|
||||
|
||||
u64 calc(const std::string &basepath,
|
||||
const std::string &fusepath,
|
||||
const mode_t mode,
|
||||
const ino_t ino);
|
||||
u64 calc(const fs::path &basepath,
|
||||
const fs::path &fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
const mode_t mode,
|
||||
const ino_t ino);
|
||||
|
||||
void calc(const std::string &basepath,
|
||||
const std::string &fusepath,
|
||||
struct stat *st);
|
||||
void calc(const fs::path &basepath,
|
||||
const fs::path &fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
struct stat *st);
|
||||
void calc(const std::string &basepath,
|
||||
const std::string &fusepath,
|
||||
struct fuse_statx *st);
|
||||
void calc(const fs::path &basepath,
|
||||
const fs::path &fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
struct fuse_statx *st);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,12 @@
|
|||
|
||||
#include "fs_close.hpp"
|
||||
#include "fs_mktemp.hpp"
|
||||
#include "fs_path.hpp"
|
||||
#include "fs_statvfs.hpp"
|
||||
#include "fs_unlink.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
is_mounted_rofs(const fs::path &path_)
|
||||
is_mounted_rofs(const std::string &path_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
|
@ -46,7 +47,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
is_rofs(const fs::path &path_)
|
||||
is_rofs(const std::string &path_)
|
||||
{
|
||||
int fd;
|
||||
std::string tmp_filepath;
|
||||
|
|
@ -64,7 +65,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
bool
|
||||
is_rofs_but_not_mounted_ro(const fs::path &path_)
|
||||
is_rofs_but_not_mounted_ro(const std::string &path_)
|
||||
{
|
||||
if(fs::is_mounted_rofs(path_))
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
lchown_check_on_error(const std::string &path_,
|
||||
lchown_check_on_error(const char *path_,
|
||||
const struct stat &st_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -94,4 +94,13 @@ namespace fs
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lchown_check_on_error(const std::string &path_,
|
||||
const struct stat &st_)
|
||||
{
|
||||
return fs::lchown_check_on_error(path_.c_str(),st_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,22 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
link(const std::string &oldpath_,
|
||||
const std::string &newpath_)
|
||||
link(const char *oldpath_,
|
||||
const char *newpath_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::link(oldpath_.c_str(),
|
||||
newpath_.c_str());
|
||||
rv = ::link(oldpath_,newpath_);
|
||||
|
||||
return ::to_neg_errno(rv);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
link(const std::string &oldpath_,
|
||||
const std::string &newpath_)
|
||||
{
|
||||
return fs::link(oldpath_.c_str(),newpath_.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,26 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
lremovexattr(const std::string &path_,
|
||||
const char *attrname_)
|
||||
lremovexattr(const char *path_,
|
||||
const char *attrname_)
|
||||
{
|
||||
#ifdef USE_XATTR
|
||||
int rv;
|
||||
|
||||
rv = ::lremovexattr(path_.c_str(),attrname_);
|
||||
rv = ::lremovexattr(path_,attrname_);
|
||||
|
||||
return ::to_neg_errno(rv);
|
||||
#else
|
||||
return -ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lremovexattr(const std::string &path_,
|
||||
const char *attrname_)
|
||||
{
|
||||
return fs::lremovexattr(path_.c_str(),attrname_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
lstatvfs(const std::string &path_,
|
||||
struct statvfs *st_)
|
||||
lstatvfs(const char *path_,
|
||||
struct statvfs *st_)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
|
|
@ -52,4 +52,13 @@ namespace fs
|
|||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lstatvfs(const std::string &path_,
|
||||
struct statvfs *st_)
|
||||
{
|
||||
return fs::lstatvfs(path_.c_str(),st_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
lutimens(const std::string &path_,
|
||||
lutimens(const char *path_,
|
||||
const struct timespec ts_[2])
|
||||
{
|
||||
return fs::utimensat(AT_FDCWD,path_,ts_,AT_SYMLINK_NOFOLLOW);
|
||||
|
|
@ -36,7 +36,16 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
lutimens(const std::string &path_,
|
||||
lutimens(const std::string &path_,
|
||||
const struct timespec ts_[2])
|
||||
{
|
||||
return fs::lutimens(path_.c_str(),ts_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lutimens(const char *path_,
|
||||
const struct stat &st_)
|
||||
{
|
||||
struct timespec ts[2];
|
||||
|
|
@ -46,4 +55,13 @@ namespace fs
|
|||
|
||||
return fs::lutimens(path_,ts);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
lutimens(const std::string &path_,
|
||||
const struct stat &st_)
|
||||
{
|
||||
return fs::lutimens(path_.c_str(),st_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
mkdir(const fs::path &path_,
|
||||
mkdir(const fs::relpath &path_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
return fs::mkdir(path_.c_str(),
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
mkdirat(const int dirfd_,
|
||||
const fs::path &pathname_,
|
||||
const fs::relpath &pathname_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
return fs::mkdirat(dirfd_,
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
|
|
@ -39,9 +38,9 @@ static char const CHARS[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmno
|
|||
static size_t const CHARS_SIZE = (sizeof(CHARS) - 1);
|
||||
|
||||
static
|
||||
fs::path
|
||||
_generate_tmp_path(const fs::path &dirpath_,
|
||||
const std::string &src_filename_)
|
||||
std::string
|
||||
_generate_tmp_path(const std::string &dirpath_,
|
||||
const std::string_view src_filename_)
|
||||
{
|
||||
long name_max;
|
||||
size_t substr_len;
|
||||
|
|
@ -54,24 +53,25 @@ _generate_tmp_path(const fs::path &dirpath_,
|
|||
substr_len = std::min(src_filename_.size(),
|
||||
(size_t)(name_max - PAD_LEN - 2ULL));
|
||||
|
||||
tmp_filename = '.';
|
||||
tmp_filename += src_filename_.substr(0,substr_len);
|
||||
tmp_filename = dirpath_;
|
||||
tmp_filename += "/.";
|
||||
tmp_filename.append(src_filename_.substr(0,substr_len));
|
||||
tmp_filename += '_';
|
||||
for(size_t i = 0; i < PAD_LEN; i++)
|
||||
tmp_filename += CHARS[RND::rand64(CHARS_SIZE)];
|
||||
|
||||
return dirpath_ / tmp_filename;
|
||||
return tmp_filename;
|
||||
}
|
||||
|
||||
std::tuple<int,fs::path>
|
||||
fs::mktemp_in_dir(const fs::path &dirpath_,
|
||||
const fs::path &filename_,
|
||||
const int flags_)
|
||||
std::tuple<int,std::string>
|
||||
fs::mktemp_in_dir(const std::string &dirpath_,
|
||||
const std::string_view filename_,
|
||||
const int flags_)
|
||||
{
|
||||
int fd;
|
||||
int count;
|
||||
int flags;
|
||||
fs::path tmp_filepath;
|
||||
std::string tmp_filepath;
|
||||
|
||||
count = MAX_ATTEMPTS;
|
||||
flags = (flags_ | O_EXCL | O_CREAT);
|
||||
|
|
@ -83,19 +83,29 @@ fs::mktemp_in_dir(const fs::path &dirpath_,
|
|||
if(fd == -EEXIST)
|
||||
continue;
|
||||
if(fd < 0)
|
||||
return std::make_tuple(fd,fs::path());
|
||||
return std::make_tuple(fd,std::string());
|
||||
|
||||
return std::make_tuple(fd,tmp_filepath);
|
||||
return std::make_tuple(fd,std::move(tmp_filepath));
|
||||
}
|
||||
|
||||
return std::make_tuple(-EEXIST,fs::path());
|
||||
return std::make_tuple(-EEXIST,std::string());
|
||||
}
|
||||
|
||||
std::tuple<int,fs::path>
|
||||
fs::mktemp(const fs::path &filepath_,
|
||||
const int flags_)
|
||||
std::tuple<int,std::string>
|
||||
fs::mktemp(const std::string &filepath_,
|
||||
const int flags_)
|
||||
{
|
||||
return fs::mktemp_in_dir(filepath_.parent_path(),
|
||||
filepath_.filename(),
|
||||
flags_);
|
||||
// Split filepath_ into dirpath and filename without an allocation:
|
||||
// the dirpath is referenced as a substring; mktemp_in_dir copies
|
||||
// it into the result. filename_view aliases the suffix.
|
||||
auto slash = filepath_.rfind('/');
|
||||
std::string dirpath = (slash == std::string::npos)
|
||||
? std::string(".")
|
||||
: filepath_.substr(0,slash);
|
||||
std::string_view filename_view =
|
||||
(slash == std::string::npos)
|
||||
? std::string_view(filepath_)
|
||||
: std::string_view(filepath_).substr(slash + 1);
|
||||
|
||||
return fs::mktemp_in_dir(dirpath,filename_view,flags_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,20 +18,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
|
||||
std::tuple<int,fs::path>
|
||||
mktemp_in_dir(const fs::path &dirpath,
|
||||
const fs::path &filename,
|
||||
int const flags);
|
||||
std::tuple<int,std::string>
|
||||
mktemp_in_dir(const std::string &dirpath,
|
||||
const std::string_view filename,
|
||||
int const flags);
|
||||
|
||||
std::tuple<int,fs::path>
|
||||
mktemp(const fs::path &filepath,
|
||||
const int flags);
|
||||
std::tuple<int,std::string>
|
||||
mktemp(const std::string &filepath,
|
||||
const int flags);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
int
|
||||
fs::mount(const std::string &tgt_)
|
||||
fs::mount(const char *tgt_)
|
||||
{
|
||||
return subprocess::call({"mount",tgt_});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,16 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int mount(const std::string &tgt);
|
||||
int mount(const char *tgt);
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
mount(const std::string &tgt_)
|
||||
{
|
||||
return fs::mount(tgt_.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
|
|
@ -27,7 +26,7 @@ namespace fs
|
|||
{
|
||||
struct Mount
|
||||
{
|
||||
fs::path dir;
|
||||
std::string dir;
|
||||
std::string fsname;
|
||||
std::string type;
|
||||
std::string opts;
|
||||
|
|
|
|||
|
|
@ -63,22 +63,19 @@ static
|
|||
int
|
||||
_movefile_and_open(const Policy::Create &createFunc_,
|
||||
const Branches::Ptr &branches_,
|
||||
const fs::path &branchpath_,
|
||||
const fs::path &fusepath_,
|
||||
const std::string &branchpath_,
|
||||
const fs::relpath &fusepath_,
|
||||
int origfd_)
|
||||
{
|
||||
int rv;
|
||||
int dstfd_flags;
|
||||
int origfd_flags;
|
||||
s64 src_size;
|
||||
fs::path fusedir;
|
||||
fs::path src_branch;
|
||||
fs::path src_filepath;
|
||||
fs::path dst_filepath;
|
||||
fs::relpath fusedir;
|
||||
fs::relpath src_filepath;
|
||||
fs::relpath dst_filepath;
|
||||
std::vector<Branch*> dst_branch;
|
||||
|
||||
src_branch = branchpath_;
|
||||
|
||||
rv = createFunc_(branches_,fusepath_,dst_branch);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
|
|
@ -98,12 +95,17 @@ _movefile_and_open(const Policy::Create &createFunc_,
|
|||
|
||||
fusedir = fusepath_.parent_path();
|
||||
|
||||
rv = fs::clonepath(src_branch,dst_branch[0]->path,fusedir);
|
||||
rv = fs::clonepath(branchpath_,dst_branch[0]->path,fusedir);
|
||||
if(rv < 0)
|
||||
return -ENOSPC;
|
||||
|
||||
src_filepath = src_branch / fusepath_;
|
||||
dst_filepath = dst_branch[0]->path / fusepath_;
|
||||
// src_filepath / dst_filepath are fs::relpath in the per-branch
|
||||
// splice form: rel anchored, prefix written via set_prefix() so the
|
||||
// syscall sees branch + '/' + fusepath as a single string.
|
||||
src_filepath = fusepath_;
|
||||
src_filepath.set_prefix(branchpath_);
|
||||
dst_filepath = fusepath_;
|
||||
dst_filepath.set_prefix(dst_branch[0]->path);
|
||||
|
||||
rv = fs::copyfile(src_filepath,dst_filepath,{.cleanup_failure = true});
|
||||
if(rv < 0)
|
||||
|
|
@ -122,8 +124,8 @@ _movefile_and_open(const Policy::Create &createFunc_,
|
|||
int
|
||||
fs::movefile_and_open(const Policy::Create &policy_,
|
||||
const Branches::Ptr &branches_,
|
||||
const fs::path &branchpath_,
|
||||
const fs::path &fusepath_,
|
||||
const std::string &branchpath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const int origfd_)
|
||||
{
|
||||
return ::_movefile_and_open(policy_,
|
||||
|
|
@ -136,8 +138,8 @@ fs::movefile_and_open(const Policy::Create &policy_,
|
|||
int
|
||||
fs::movefile_and_open_as_root(const Policy::Create &policy_,
|
||||
const Branches::Ptr &branches_,
|
||||
const fs::path &branchpath_,
|
||||
const fs::path &fusepath_,
|
||||
const std::string &branchpath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const int origfd_)
|
||||
{
|
||||
return fs::movefile_and_open(policy_,
|
||||
|
|
|
|||
|
|
@ -30,14 +30,14 @@ namespace fs
|
|||
int
|
||||
movefile_and_open(const Policy::Create &policy,
|
||||
const Branches::Ptr &branches_,
|
||||
const fs::path &branchpath,
|
||||
const fs::path &fusepath,
|
||||
const std::string &branchpath,
|
||||
const fs::relpath &fusepath,
|
||||
const int origfd);
|
||||
|
||||
int
|
||||
movefile_and_open_as_root(const Policy::Create &policy,
|
||||
const Branches::Ptr &branches_,
|
||||
const fs::path &branchpath,
|
||||
const fs::path &fusepath,
|
||||
const std::string &branchpath,
|
||||
const fs::relpath &fusepath,
|
||||
int origfd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,16 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
open_dir_ro(const std::string &path_)
|
||||
open_dir_ro(const char *path_)
|
||||
{
|
||||
return fs::open(path_,O_RDONLY|O_DIRECTORY);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
open_dir_ro(const std::string &path_)
|
||||
{
|
||||
return fs::open(path_.c_str(),O_RDONLY|O_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
open_as(const ugid_t ugid_,
|
||||
const fs::path &path_,
|
||||
const fs::relpath &path_,
|
||||
const int flags_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
open_as(const ugid_t ugid_,
|
||||
const fs::path &path_,
|
||||
const fs::relpath &path_,
|
||||
const int flags_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
openat(const int dirfd_,
|
||||
const fs::path &pathname_,
|
||||
const fs::relpath &pathname_,
|
||||
const int flags_,
|
||||
const mode_t mode_ = 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ fs::readahead(cu64 dev_,
|
|||
}
|
||||
|
||||
int
|
||||
fs::readahead(const std::string path_,
|
||||
cu64 size_in_kb_)
|
||||
fs::readahead(const char *path_,
|
||||
cu64 size_in_kb_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
#include "base_types.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
|
|
@ -35,6 +33,6 @@ namespace fs
|
|||
cu64 size_in_kb);
|
||||
|
||||
int
|
||||
readahead(const std::string path,
|
||||
cu64 size_in_kb);
|
||||
readahead(const char *path,
|
||||
cu64 size_in_kb);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,20 @@
|
|||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
readlink(const char *path_,
|
||||
char *buf_,
|
||||
const size_t bufsiz_)
|
||||
{
|
||||
ssize_t rv;
|
||||
|
||||
rv = ::readlink(path_,buf_,bufsiz_);
|
||||
|
||||
return ::to_neg_errno(rv);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
ssize_t
|
||||
|
|
@ -34,10 +48,6 @@ namespace fs
|
|||
char *buf_,
|
||||
const size_t bufsiz_)
|
||||
{
|
||||
ssize_t rv;
|
||||
|
||||
rv = ::readlink(path_.c_str(),buf_,bufsiz_);
|
||||
|
||||
return ::to_neg_errno(rv);
|
||||
return fs::readlink(path_.c_str(),buf_,bufsiz_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
|
@ -29,16 +26,16 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
char *
|
||||
realpath(const std::string &path_,
|
||||
char *resolved_path_)
|
||||
realpath(const char *path_,
|
||||
char *resolved_path_)
|
||||
{
|
||||
return ::realpath(path_.c_str(),resolved_path_);
|
||||
return ::realpath(path_,resolved_path_);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
char *
|
||||
realpath(const std::string &path_)
|
||||
realpath(const char *path_)
|
||||
{
|
||||
return fs::realpath(path_,NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
void
|
||||
fs::realpathize(std::vector<std::string> *strs_)
|
||||
|
|
@ -32,10 +34,8 @@ fs::realpathize(std::vector<std::string> *strs_)
|
|||
|
||||
for(size_t i = 0; i < strs_->size(); i++)
|
||||
{
|
||||
rv = fs::realpath((*strs_)[i],resolved_path);
|
||||
if(rv == NULL)
|
||||
continue;
|
||||
|
||||
(*strs_)[i] = rv;
|
||||
rv = fs::realpath((*strs_)[i].c_str(),resolved_path);
|
||||
if(rv != NULL)
|
||||
(*strs_)[i] = rv;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,26 @@ struct Element
|
|||
struct statvfs st;
|
||||
};
|
||||
|
||||
typedef std::unordered_map<std::string,Element> statvfs_cache;
|
||||
// Transparent hash / equality so we can look up by std::string_view
|
||||
// (or const char*) without constructing a std::string. Requires
|
||||
// unordered_map's Hash and KeyEqual to be transparent (C++20). The
|
||||
// insert path still constructs a string for the key when missing,
|
||||
// but the hot read path is alloc-free.
|
||||
struct string_hash
|
||||
{
|
||||
using is_transparent = void;
|
||||
std::size_t operator()(const std::string &s) const noexcept { return std::hash<std::string_view>{}(s); }
|
||||
std::size_t operator()(std::string_view s) const noexcept { return std::hash<std::string_view>{}(s); }
|
||||
std::size_t operator()(const char *s) const noexcept { return std::hash<std::string_view>{}(s); }
|
||||
};
|
||||
|
||||
struct string_eq
|
||||
{
|
||||
using is_transparent = void;
|
||||
bool operator()(std::string_view a, std::string_view b) const noexcept { return a == b; }
|
||||
};
|
||||
|
||||
typedef std::unordered_map<std::string,Element,string_hash,string_eq> statvfs_cache;
|
||||
|
||||
// Cache is read heavy. Use a shared mutex so concurrent reads can
|
||||
// work in parallel and only inserts or refreshes take a unique lock.
|
||||
|
|
@ -69,8 +88,8 @@ fs::statvfs_cache_timeout(cu64 timeout_)
|
|||
}
|
||||
|
||||
int
|
||||
fs::statvfs_cache(const std::string &path_,
|
||||
struct statvfs *st_)
|
||||
fs::statvfs_cache(const char *path_,
|
||||
struct statvfs *st_)
|
||||
{
|
||||
u64 now;
|
||||
|
||||
|
|
@ -79,10 +98,11 @@ fs::statvfs_cache(const std::string &path_,
|
|||
|
||||
now = ::_get_time();
|
||||
|
||||
std::string_view key(path_);
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lk(g_cache_mutex);
|
||||
|
||||
auto it = g_cache.find(path_);
|
||||
auto it = g_cache.find(key);
|
||||
if((it != g_cache.end()) && ((now - it->second.time) <= g_timeout))
|
||||
{
|
||||
*st_ = it->second.st;
|
||||
|
|
@ -93,7 +113,10 @@ fs::statvfs_cache(const std::string &path_,
|
|||
int rv = 0;
|
||||
std::unique_lock<std::shared_mutex> lk(g_cache_mutex);
|
||||
|
||||
Element &e = g_cache[path_];
|
||||
// operator[] requires a string key (no transparent insert overload),
|
||||
// so this path does construct a std::string. Only happens on insert /
|
||||
// refresh -- the read-only fast path above is alloc-free.
|
||||
Element &e = g_cache[std::string(key)];
|
||||
if((now - e.time) > g_timeout)
|
||||
{
|
||||
e.time = now;
|
||||
|
|
@ -106,8 +129,8 @@ fs::statvfs_cache(const std::string &path_,
|
|||
}
|
||||
|
||||
int
|
||||
fs::statvfs_cache_readonly(const std::string &path_,
|
||||
bool *readonly_)
|
||||
fs::statvfs_cache_readonly(const char *path_,
|
||||
bool *readonly_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
|
@ -120,8 +143,8 @@ fs::statvfs_cache_readonly(const std::string &path_,
|
|||
}
|
||||
|
||||
int
|
||||
fs::statvfs_cache_spaceavail(const std::string &path_,
|
||||
u64 *spaceavail_)
|
||||
fs::statvfs_cache_spaceavail(const char *path_,
|
||||
u64 *spaceavail_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
|
@ -134,8 +157,8 @@ fs::statvfs_cache_spaceavail(const std::string &path_,
|
|||
}
|
||||
|
||||
int
|
||||
fs::statvfs_cache_spaceused(const std::string &path_,
|
||||
u64 *spaceused_)
|
||||
fs::statvfs_cache_spaceused(const char *path_,
|
||||
u64 *spaceused_)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs st;
|
||||
|
|
|
|||
|
|
@ -33,18 +33,54 @@ namespace fs
|
|||
statvfs_cache_timeout(cu64 timeout);
|
||||
|
||||
int
|
||||
statvfs_cache(const std::string &path,
|
||||
struct statvfs *st);
|
||||
statvfs_cache(const char *path,
|
||||
struct statvfs *st);
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
statvfs_cache(const std::string &path_,
|
||||
struct statvfs *st_)
|
||||
{
|
||||
return fs::statvfs_cache(path_.c_str(),st_);
|
||||
}
|
||||
|
||||
int
|
||||
statvfs_cache_readonly(const std::string &path,
|
||||
bool *readonly);
|
||||
statvfs_cache_readonly(const char *path,
|
||||
bool *readonly);
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
statvfs_cache_readonly(const std::string &path_,
|
||||
bool *readonly_)
|
||||
{
|
||||
return fs::statvfs_cache_readonly(path_.c_str(),readonly_);
|
||||
}
|
||||
|
||||
int
|
||||
statvfs_cache_spaceavail(const std::string &path,
|
||||
u64 *spaceavail);
|
||||
statvfs_cache_spaceavail(const char *path,
|
||||
u64 *spaceavail);
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
statvfs_cache_spaceavail(const std::string &path_,
|
||||
u64 *spaceavail_)
|
||||
{
|
||||
return fs::statvfs_cache_spaceavail(path_.c_str(),spaceavail_);
|
||||
}
|
||||
|
||||
int
|
||||
statvfs_cache_spaceused(const std::string &path,
|
||||
u64 *spaceused);
|
||||
statvfs_cache_spaceused(const char *path,
|
||||
u64 *spaceused);
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
statvfs_cache_spaceused(const std::string &path_,
|
||||
u64 *spaceused_)
|
||||
{
|
||||
return fs::statvfs_cache_spaceused(path_.c_str(),spaceused_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@
|
|||
#include "errno.hpp"
|
||||
#include "to_neg_errno.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
# include <sys/param.h>
|
||||
# include <sys/mount.h>
|
||||
|
|
@ -30,19 +32,18 @@
|
|||
# include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace fs
|
||||
{
|
||||
static
|
||||
inline
|
||||
int
|
||||
umount2(const std::string target_,
|
||||
const int flags_)
|
||||
umount2(const char *target_,
|
||||
const int flags_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = ::umount2(target_.c_str(),
|
||||
rv = ::umount2(target_,
|
||||
flags_);
|
||||
|
||||
return ::to_neg_errno(rv);
|
||||
|
|
@ -51,8 +52,16 @@ namespace fs
|
|||
static
|
||||
inline
|
||||
int
|
||||
umount_lazy(const std::string target_)
|
||||
umount_lazy(const char *target_)
|
||||
{
|
||||
return fs::umount2(target_,MNT_DETACH);
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
umount_lazy(const std::string &target_)
|
||||
{
|
||||
return fs::umount_lazy(target_.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@
|
|||
static
|
||||
inline
|
||||
bool
|
||||
_can_call_lutimes(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const int flags_)
|
||||
_can_call_lutimes(const int dirfd_,
|
||||
const char *path_,
|
||||
const int flags_)
|
||||
{
|
||||
return ((flags_ == AT_SYMLINK_NOFOLLOW) &&
|
||||
((dirfd_ == AT_FDCWD) ||
|
||||
|
|
@ -120,7 +120,7 @@ static
|
|||
inline
|
||||
int
|
||||
_set_utime_omit_to_current_value(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const char *path_,
|
||||
const struct timespec ts_[2],
|
||||
struct timeval tv_[2],
|
||||
const int flags_)
|
||||
|
|
@ -206,7 +206,7 @@ static
|
|||
inline
|
||||
int
|
||||
_convert_timespec_to_timeval(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const char *path_,
|
||||
const struct timespec ts_[2],
|
||||
struct timeval tv_[2],
|
||||
struct timeval **tvp_,
|
||||
|
|
@ -265,7 +265,7 @@ namespace fs
|
|||
inline
|
||||
int
|
||||
utimensat(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const char *path_,
|
||||
const struct timespec ts_[2],
|
||||
const int flags_)
|
||||
{
|
||||
|
|
@ -291,4 +291,15 @@ namespace fs
|
|||
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
static
|
||||
inline
|
||||
int
|
||||
utimensat(const int dirfd_,
|
||||
const std::string &path_,
|
||||
const struct timespec ts_[2],
|
||||
const int flags_)
|
||||
{
|
||||
return fs::utimensat(dirfd_,path_.c_str(),ts_,flags_);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,17 +36,17 @@ constexpr std::chrono::milliseconds SLEEP_DURATION = std::chrono::milliseconds(3
|
|||
static
|
||||
bool
|
||||
_branch_is_mounted(const struct stat &src_st_,
|
||||
const fs::path &branch_path_)
|
||||
const std::string &branch_path_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
fs::path filepath;
|
||||
std::string filepath;
|
||||
|
||||
rv = fs::lgetxattr(branch_path_,"user.mergerfs.branch",NULL,0);
|
||||
if(rv >= 0)
|
||||
return true;
|
||||
|
||||
filepath = branch_path_ / ".mergerfs.branch";
|
||||
filepath = branch_path_ + "/.mergerfs.branch";
|
||||
rv = fs::exists(filepath);
|
||||
if(rv)
|
||||
return true;
|
||||
|
|
@ -55,7 +55,7 @@ _branch_is_mounted(const struct stat &src_st_,
|
|||
if(rv >= 0)
|
||||
return false;
|
||||
|
||||
filepath = branch_path_ / ".mergerfs.branch_mounts_here";
|
||||
filepath = branch_path_ + "/.mergerfs.branch_mounts_here";
|
||||
rv = fs::exists(filepath);
|
||||
if(rv)
|
||||
return false;
|
||||
|
|
@ -69,13 +69,13 @@ _branch_is_mounted(const struct stat &src_st_,
|
|||
|
||||
static
|
||||
void
|
||||
_check_mounted(const struct stat &src_st_,
|
||||
const std::set<fs::path> &tgt_paths_,
|
||||
std::vector<fs::path> *successes_,
|
||||
std::vector<fs::path> *failures_)
|
||||
_check_mounted(const struct stat &src_st_,
|
||||
const std::set<std::string> &tgt_paths_,
|
||||
std::vector<std::string> *successes_,
|
||||
std::vector<std::string> *failures_)
|
||||
{
|
||||
std::vector<fs::path> &successes = *successes_;
|
||||
std::vector<fs::path> &failures = *failures_;
|
||||
std::vector<std::string> &successes = *successes_;
|
||||
std::vector<std::string> &failures = *failures_;
|
||||
|
||||
for(auto const &tgt_path : tgt_paths_)
|
||||
{
|
||||
|
|
@ -92,13 +92,13 @@ _check_mounted(const struct stat &src_st_,
|
|||
static
|
||||
int
|
||||
_wait_for_mount(const struct stat &src_st_,
|
||||
const std::vector<fs::path> &tgt_paths_,
|
||||
const std::vector<std::string> &tgt_paths_,
|
||||
const std::chrono::milliseconds &timeout_)
|
||||
{
|
||||
bool first_loop;
|
||||
std::vector<fs::path> successes;
|
||||
std::vector<fs::path> failures;
|
||||
std::set<fs::path> tgt_paths;
|
||||
std::vector<std::string> successes;
|
||||
std::vector<std::string> failures;
|
||||
std::set<std::string> tgt_paths;
|
||||
std::chrono::time_point<std::chrono::steady_clock> now;
|
||||
std::chrono::time_point<std::chrono::steady_clock> deadline;
|
||||
|
||||
|
|
@ -120,13 +120,13 @@ _wait_for_mount(const struct stat &src_st_,
|
|||
for(const auto &path : successes)
|
||||
{
|
||||
tgt_paths.erase(path);
|
||||
SysLog::info("{} is ready",path.string());
|
||||
SysLog::info("{} is ready",path);
|
||||
}
|
||||
|
||||
if(first_loop)
|
||||
{
|
||||
for(const auto &path : failures)
|
||||
SysLog::notice("{} is not ready, waiting",path.string());
|
||||
SysLog::notice("{} is not ready, waiting",path);
|
||||
first_loop = false;
|
||||
}
|
||||
|
||||
|
|
@ -135,14 +135,14 @@ _wait_for_mount(const struct stat &src_st_,
|
|||
}
|
||||
|
||||
for(const auto &path : failures)
|
||||
SysLog::notice("{} not ready within timeout",path.string());
|
||||
SysLog::notice("{} not ready within timeout",path);
|
||||
|
||||
return failures.size();
|
||||
}
|
||||
|
||||
int
|
||||
fs::wait_for_mount(const fs::path &src_path_,
|
||||
const std::vector<fs::path> &tgt_paths_,
|
||||
fs::wait_for_mount(const std::string &src_path_,
|
||||
const std::vector<std::string> &tgt_paths_,
|
||||
const std::chrono::milliseconds &timeout_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -151,7 +151,7 @@ fs::wait_for_mount(const fs::path &src_path_,
|
|||
rv = fs::stat(src_path_,&src_st);
|
||||
if(rv < 0)
|
||||
SysLog::error("Error stat'ing mount path: {} ({})",
|
||||
src_path_.string(),
|
||||
src_path_,
|
||||
::strerror(-rv));
|
||||
|
||||
for(auto &tgt_path : tgt_paths_)
|
||||
|
|
@ -163,7 +163,7 @@ fs::wait_for_mount(const fs::path &src_path_,
|
|||
|
||||
rv = fs::mount(tgt_path);
|
||||
SysLog::notice("mount {}: {}",
|
||||
tgt_path.string(),
|
||||
tgt_path,
|
||||
((rv == 0) ? "success" : "fail"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,16 +17,15 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
int
|
||||
wait_for_mount(const fs::path &srcpath,
|
||||
const std::vector<fs::path> &tgtpaths,
|
||||
wait_for_mount(const std::string &srcpath,
|
||||
const std::vector<std::string> &tgtpaths,
|
||||
const std::chrono::milliseconds &timeout);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ static
|
|||
int
|
||||
_access(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const int mask_)
|
||||
{
|
||||
int rv;
|
||||
StrVec basepaths;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
std::vector<Branch*> branches;
|
||||
|
||||
rv = searchFunc_(branches_,fusepath_,branches);
|
||||
|
|
@ -45,7 +45,7 @@ _access(const Policy::Search &searchFunc_,
|
|||
if(branches.empty())
|
||||
return -ENOENT;
|
||||
|
||||
fullpath = branches[0]->path / fusepath_;
|
||||
fullpath.assign_concat(branches[0]->path,fusepath_);
|
||||
|
||||
rv = fs::eaccess(fullpath,mask_);
|
||||
|
||||
|
|
@ -54,13 +54,12 @@ _access(const Policy::Search &searchFunc_,
|
|||
|
||||
int
|
||||
FUSE::access(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
int mask_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return ::_access(cfg.func.access.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
mask_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
namespace FUSE
|
||||
{
|
||||
int
|
||||
access(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
int mask);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
int
|
||||
FUSE::bmap(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
size_t blocksize_,
|
||||
u64 *idx_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "base_types.h"
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
|
@ -28,7 +29,7 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
bmap(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
size_t blocksize,
|
||||
u64 *idx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,33 +30,24 @@
|
|||
#include <string>
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
_chmod_loop_core(const std::string &basepath_,
|
||||
const fs::path &fusepath_,
|
||||
const mode_t mode_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
|
||||
fullpath = basepath_ / fusepath_;
|
||||
|
||||
rv = fs::lchmod(fullpath,mode_);
|
||||
|
||||
prv_->insert(rv,basepath_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_chmod_loop(const std::vector<Branch*> &branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
fs::relpath fullpath = fusepath_;
|
||||
|
||||
for(auto &branch : branches_)
|
||||
{
|
||||
::_chmod_loop_core(branch->path,fusepath_,mode_,prv_);
|
||||
int rv;
|
||||
|
||||
fullpath.set_prefix(branch->path);
|
||||
|
||||
rv = fs::lchmod(fullpath,mode_);
|
||||
|
||||
prv_->insert(rv,branch->path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +56,7 @@ int
|
|||
_chmod(const Policy::Action &actionFunc_,
|
||||
const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -96,7 +87,7 @@ _chmod(const Policy::Action &actionFunc_,
|
|||
|
||||
static
|
||||
int
|
||||
_chmod(const fs::path &fusepath_,
|
||||
_chmod(const fs::relpath &fusepath_,
|
||||
const mode_t mode_)
|
||||
{
|
||||
|
||||
|
|
@ -109,10 +100,9 @@ _chmod(const fs::path &fusepath_,
|
|||
|
||||
int
|
||||
FUSE::chmod(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
mode_t mode_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return ::_chmod(fusepath,mode_);
|
||||
return ::_chmod(fusepath_,mode_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
|
@ -27,6 +28,6 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
chmod(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
mode_t mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,35 +30,25 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
static
|
||||
void
|
||||
_chown_loop_core(const fs::path &basepath_,
|
||||
const fs::path &fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
|
||||
fullpath = basepath_ / fusepath_;
|
||||
|
||||
rv = fs::lchown(fullpath,uid_,gid_);
|
||||
|
||||
prv_->insert(rv,basepath_);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
_chown_loop(const std::vector<Branch*> &branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_,
|
||||
PolicyRV *prv_)
|
||||
{
|
||||
fs::relpath fullpath = fusepath_;
|
||||
|
||||
for(const auto &branch : branches_)
|
||||
{
|
||||
::_chown_loop_core(branch->path,fusepath_,uid_,gid_,prv_);
|
||||
int rv;
|
||||
|
||||
fullpath.set_prefix(branch->path);
|
||||
|
||||
rv = fs::lchown(fullpath,uid_,gid_);
|
||||
|
||||
prv_->insert(rv,branch->path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +57,7 @@ int
|
|||
_chown(const Policy::Action &actionFunc_,
|
||||
const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const uid_t uid_,
|
||||
const gid_t gid_)
|
||||
{
|
||||
|
|
@ -100,16 +90,15 @@ _chown(const Policy::Action &actionFunc_,
|
|||
|
||||
int
|
||||
FUSE::chown(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
uid_t uid_,
|
||||
gid_t gid_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return ::_chown(cfg.func.chown.policy,
|
||||
cfg.func.getattr.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
uid_,
|
||||
gid_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
chown(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
uid_t uid,
|
||||
gid_t gid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ _config_to_ffi_flags(const int tid_,
|
|||
static
|
||||
int
|
||||
_create_core(const ugid_t ugid_,
|
||||
const fs::path &fullpath_,
|
||||
const fs::relpath &fullpath_,
|
||||
mode_t mode_,
|
||||
const mode_t umask_,
|
||||
const int flags_)
|
||||
|
|
@ -180,16 +180,16 @@ static
|
|||
int
|
||||
_create_core(const ugid_t ugid_,
|
||||
const Branch *branch_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_)
|
||||
{
|
||||
int rv;
|
||||
FileInfo *fi;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
|
||||
fullpath = branch_->path / fusepath_;
|
||||
fullpath.assign_concat(branch_->path,fusepath_);
|
||||
|
||||
rv = ::_create_core(ugid_,fullpath,mode_,umask_,ffi_->flags);
|
||||
if(rv < 0)
|
||||
|
|
@ -208,14 +208,14 @@ _create(const ugid_t ugid_,
|
|||
const Policy::Search &searchFunc_,
|
||||
const Policy::Create &createFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
fs::path fusedirpath;
|
||||
fs::relpath fullpath;
|
||||
fs::relpath fusedirpath;
|
||||
std::vector<Branch*> createpaths;
|
||||
std::vector<Branch*> existingpaths;
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ _(const PassthroughIOEnum e_,
|
|||
static
|
||||
int
|
||||
_create(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
mode_t mode_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
|
|
@ -345,11 +345,10 @@ _create(const fuse_req_ctx_t *ctx_,
|
|||
|
||||
int
|
||||
FUSE::create(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
mode_t mode_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return ::_create(ctx_,fusepath,mode_,ffi_);
|
||||
return ::_create(ctx_,fusepath_,mode_,ffi_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
create(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
mode_t mode,
|
||||
fuse_file_info_t *ffi);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
static
|
||||
void
|
||||
_set_stat_if_leads_to_dir(const fs::path &path_,
|
||||
_set_stat_if_leads_to_dir(const fs::relpath &path_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -55,7 +55,7 @@ _set_stat_if_leads_to_dir(const fs::path &path_,
|
|||
|
||||
static
|
||||
void
|
||||
_set_stat_if_leads_to_reg(const fs::path &path_,
|
||||
_set_stat_if_leads_to_reg(const fs::relpath &path_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -129,14 +129,14 @@ static
|
|||
int
|
||||
_getattr(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
struct stat *st_,
|
||||
const bool symlinkify_,
|
||||
const time_t symlinkify_timeout_,
|
||||
FollowSymlinks followsymlinks_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
std::vector<Branch*> branches;
|
||||
|
||||
rv = searchFunc_(branches_,fusepath_,branches);
|
||||
|
|
@ -145,7 +145,7 @@ _getattr(const Policy::Search &searchFunc_,
|
|||
if(branches.empty())
|
||||
return -ENOENT;
|
||||
|
||||
fullpath = branches[0]->path / fusepath_;
|
||||
fullpath.assign_concat(branches[0]->path,fusepath_);
|
||||
|
||||
switch(followsymlinks_)
|
||||
{
|
||||
|
|
@ -183,7 +183,7 @@ _getattr(const Policy::Search &searchFunc_,
|
|||
}
|
||||
|
||||
int
|
||||
_getattr(const fs::path &fusepath_,
|
||||
_getattr(const fs::relpath &fusepath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeout_)
|
||||
{
|
||||
|
|
@ -209,18 +209,7 @@ _getattr(const fs::path &fusepath_,
|
|||
|
||||
int
|
||||
FUSE::getattr(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeout_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return FUSE::getattr(ctx_,fusepath,st_,timeout_);
|
||||
}
|
||||
|
||||
int
|
||||
FUSE::getattr(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeout_)
|
||||
{
|
||||
|
|
@ -228,7 +217,7 @@ FUSE::getattr(const fuse_req_ctx_t *ctx_,
|
|||
}
|
||||
|
||||
int
|
||||
FUSE::getattr(const fs::path &fusepath_,
|
||||
FUSE::getattr(const fs::relpath &fusepath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeout_)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,18 +31,12 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
getattr(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
struct stat *buf,
|
||||
fuse_timeouts_t *timeout);
|
||||
|
||||
int
|
||||
getattr(const fuse_req_ctx_t *ctx,
|
||||
const fs::path &fusepath,
|
||||
struct stat *buf,
|
||||
fuse_timeouts_t *timeout);
|
||||
|
||||
int
|
||||
getattr(const fs::path &fusepath,
|
||||
getattr(const fs::relpath &fusepath,
|
||||
struct stat *buf,
|
||||
fuse_timeouts_t *timeout);
|
||||
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ _getxattr_ctrl_file(Config &cfg_,
|
|||
|
||||
static
|
||||
int
|
||||
_getxattr_from_string(char *destbuf_,
|
||||
const size_t destbufsize_,
|
||||
const std::string &src_)
|
||||
_getxattr_from_string(char *destbuf_,
|
||||
const size_t destbufsize_,
|
||||
const std::string_view src_)
|
||||
{
|
||||
const size_t srcbufsize = src_.size();
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ _getxattr_from_string(char *destbuf_,
|
|||
static
|
||||
int
|
||||
_getxattr_user_mergerfs_allpaths(const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
char *buf_,
|
||||
const size_t count_)
|
||||
{
|
||||
|
|
@ -117,9 +117,9 @@ _getxattr_user_mergerfs_allpaths(const Branches::Ptr branches_,
|
|||
|
||||
static
|
||||
int
|
||||
_getxattr_user_mergerfs(const fs::path &basepath_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::path &fullpath_,
|
||||
_getxattr_user_mergerfs(const fs::relpath &basepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const fs::relpath &fullpath_,
|
||||
const Branches::Ptr branches_,
|
||||
const char *attrname_,
|
||||
char *buf_,
|
||||
|
|
@ -145,13 +145,13 @@ static
|
|||
int
|
||||
_getxattr(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const char *attrname_,
|
||||
char *buf_,
|
||||
const size_t count_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
std::vector<Branch*> branches;
|
||||
|
||||
rv = searchFunc_(branches_,fusepath_,branches);
|
||||
|
|
@ -160,7 +160,7 @@ _getxattr(const Policy::Search &searchFunc_,
|
|||
if(branches.empty())
|
||||
return -ENOENT;
|
||||
|
||||
fullpath = branches[0]->path / fusepath_;
|
||||
fullpath.assign_concat(branches[0]->path,fusepath_);
|
||||
|
||||
if(Config::is_mergerfs_xattr(attrname_))
|
||||
return ::_getxattr_user_mergerfs(branches[0]->path,
|
||||
|
|
@ -176,14 +176,13 @@ _getxattr(const Policy::Search &searchFunc_,
|
|||
|
||||
int
|
||||
FUSE::getxattr(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const char *attrname_,
|
||||
char *attrvalue_,
|
||||
size_t attrvalue_size_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
if(Config::is_ctrl_file(fusepath))
|
||||
if(Config::is_ctrl_file(fusepath_))
|
||||
return ::_getxattr_ctrl_file(cfg,
|
||||
attrname_,
|
||||
attrvalue_,
|
||||
|
|
@ -198,7 +197,7 @@ FUSE::getxattr(const fuse_req_ctx_t *ctx_,
|
|||
|
||||
return ::_getxattr(cfg.func.getxattr.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
attrname_,
|
||||
attrvalue_,
|
||||
attrvalue_size_);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
getxattr(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
const char *attrname,
|
||||
char *attrvalue,
|
||||
size_t attrvalue_size);
|
||||
|
|
|
|||
|
|
@ -144,16 +144,16 @@ _want_if_capable_max_pages(fuse_conn_info_t *conn_,
|
|||
|
||||
static
|
||||
void
|
||||
_readahead(const fs::path &path_,
|
||||
const int readahead_)
|
||||
_readahead(const std::string &path_,
|
||||
const int readahead_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
rv = fs::readahead(path_,readahead_);
|
||||
rv = fs::readahead(path_.c_str(),readahead_);
|
||||
if(rv == 0)
|
||||
SysLog::info("{} - readahead set to {}",path_.string(),readahead_);
|
||||
SysLog::info("{} - readahead set to {}",path_,readahead_);
|
||||
else
|
||||
SysLog::error("{} - unable to set readahead",path_.string());
|
||||
SysLog::error("{} - unable to set readahead",path_);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
|||
|
|
@ -131,14 +131,14 @@ static
|
|||
int
|
||||
_ioctl_dir_base(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const u32 cmd_,
|
||||
void *data_,
|
||||
u32 *out_bufsz_)
|
||||
{
|
||||
int fd;
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
std::vector<Branch*> branches;
|
||||
|
||||
rv = searchFunc_(branches_,fusepath_,branches);
|
||||
|
|
@ -147,7 +147,7 @@ _ioctl_dir_base(const Policy::Search &searchFunc_,
|
|||
if(branches.empty())
|
||||
return -ENOENT;
|
||||
|
||||
fullpath = branches[0]->path / fusepath_;
|
||||
fullpath.assign_concat(branches[0]->path,fusepath_);
|
||||
|
||||
fd = fs::open(fullpath,O_RDONLY|O_NOATIME|O_NONBLOCK);
|
||||
if(fd < 0)
|
||||
|
|
|
|||
|
|
@ -38,20 +38,20 @@ static
|
|||
int
|
||||
_link_create_path_loop(const std::vector<Branch*> &oldbranches_,
|
||||
const Branch *newbranch_,
|
||||
const fs::path &oldfusepath_,
|
||||
const fs::path &newfusepath_,
|
||||
const fs::path &newfusedirpath_)
|
||||
const fs::relpath &oldfusepath_,
|
||||
const fs::relpath &newfusepath_,
|
||||
const fs::relpath &newfusedirpath_)
|
||||
{
|
||||
int rv;
|
||||
int err;
|
||||
fs::path oldfullpath;
|
||||
fs::path newfullpath;
|
||||
fs::relpath oldfullpath = oldfusepath_;
|
||||
fs::relpath newfullpath = newfusepath_;
|
||||
|
||||
err = -ENOENT;
|
||||
for(const auto &oldbranch : oldbranches_)
|
||||
{
|
||||
oldfullpath = oldbranch->path / oldfusepath_;
|
||||
newfullpath = oldbranch->path / newfusepath_;
|
||||
oldfullpath.set_prefix(oldbranch->path);
|
||||
newfullpath.set_prefix(oldbranch->path);
|
||||
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
if(rv == -ENOENT)
|
||||
|
|
@ -75,11 +75,11 @@ int
|
|||
_link_create_path(const Policy::Search &searchFunc_,
|
||||
const Policy::Action &actionFunc_,
|
||||
const Branches::Ptr ibranches_,
|
||||
const fs::path &oldfusepath_,
|
||||
const fs::path &newfusepath_)
|
||||
const fs::relpath &oldfusepath_,
|
||||
const fs::relpath &newfusepath_)
|
||||
{
|
||||
int rv;
|
||||
fs::path newfusedirpath;
|
||||
fs::relpath newfusedirpath;
|
||||
std::vector<Branch*> oldbranches;
|
||||
std::vector<Branch*> newbranches;
|
||||
|
||||
|
|
@ -102,46 +102,30 @@ _link_create_path(const Policy::Search &searchFunc_,
|
|||
newfusedirpath);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link_preserve_path_core(const fs::path &oldbasepath_,
|
||||
const fs::path &oldfusepath_,
|
||||
const fs::path &newfusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
fs::path oldfullpath;
|
||||
fs::path newfullpath;
|
||||
|
||||
oldfullpath = oldbasepath_ / oldfusepath_;
|
||||
newfullpath = oldbasepath_ / newfusepath_;
|
||||
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
if(rv == -ENOENT)
|
||||
rv = -EXDEV;
|
||||
if((rv == 0) && (st_->st_ino == 0))
|
||||
rv = fs::lstat(oldfullpath,st_);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_link_preserve_path_loop(const std::vector<Branch*> &oldbranches_,
|
||||
const fs::path &oldfusepath_,
|
||||
const fs::path &newfusepath_,
|
||||
const fs::relpath &oldfusepath_,
|
||||
const fs::relpath &newfusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
int err;
|
||||
fs::relpath oldfullpath = oldfusepath_;
|
||||
fs::relpath newfullpath = newfusepath_;
|
||||
|
||||
err = -ENOENT;
|
||||
for(const auto &oldbranch : oldbranches_)
|
||||
{
|
||||
rv = ::_link_preserve_path_core(oldbranch->path,
|
||||
oldfusepath_,
|
||||
newfusepath_,
|
||||
st_);
|
||||
oldfullpath.set_prefix(oldbranch->path);
|
||||
newfullpath.set_prefix(oldbranch->path);
|
||||
|
||||
rv = fs::link(oldfullpath,newfullpath);
|
||||
if(rv == -ENOENT)
|
||||
rv = -EXDEV;
|
||||
if((rv == 0) && (st_->st_ino == 0))
|
||||
rv = fs::lstat(oldfullpath,st_);
|
||||
|
||||
if(err < 0)
|
||||
err = rv;
|
||||
}
|
||||
|
|
@ -153,8 +137,8 @@ static
|
|||
int
|
||||
_link_preserve_path(const Policy::Action &actionFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &oldfusepath_,
|
||||
const fs::path &newfusepath_,
|
||||
const fs::relpath &oldfusepath_,
|
||||
const fs::relpath &newfusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -174,8 +158,8 @@ _link_preserve_path(const Policy::Action &actionFunc_,
|
|||
|
||||
static
|
||||
int
|
||||
_link(const fs::path &oldpath_,
|
||||
const fs::path &newpath_,
|
||||
_link(const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
if(cfg.func.create.policy.path_preserving() && !cfg.ignorepponrename)
|
||||
|
|
@ -195,8 +179,8 @@ _link(const fs::path &oldpath_,
|
|||
static
|
||||
int
|
||||
_link(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &oldpath_,
|
||||
const fs::path &newpath_,
|
||||
const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
|
|
@ -212,18 +196,19 @@ _link(const fuse_req_ctx_t *ctx_,
|
|||
static
|
||||
int
|
||||
_link_exdev_rel_symlink(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &oldpath_,
|
||||
const fs::path &newpath_,
|
||||
const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
fs::path target(oldpath_);
|
||||
fs::path linkpath(newpath_);
|
||||
// lexically_relative builds the target as a relpath; newpath_ is
|
||||
// passed straight through to FUSE::symlink without copying.
|
||||
fs::relpath target = oldpath_.lexically_relative(newpath_.parent_path());
|
||||
if(target.empty())
|
||||
return -EXDEV;
|
||||
|
||||
target = target.lexically_relative(linkpath.parent_path());
|
||||
|
||||
rv = FUSE::symlink(ctx_,target.c_str(),linkpath);
|
||||
rv = FUSE::symlink(ctx_,target.c_str(),newpath_);
|
||||
if(rv == 0)
|
||||
rv = FUSE::getattr(ctx_,oldpath_,st_,timeouts_);
|
||||
|
||||
|
|
@ -239,13 +224,13 @@ int
|
|||
_link_exdev_abs_base_symlink(const fuse_req_ctx_t *ctx_,
|
||||
const Policy::Search &openPolicy_,
|
||||
const Branches::Ptr ibranches_,
|
||||
const fs::path &oldpath_,
|
||||
const fs::path &newpath_,
|
||||
const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
fs::path target;
|
||||
fs::relpath target;
|
||||
std::vector<Branch*> obranches;
|
||||
|
||||
rv = openPolicy_(ibranches_,oldpath_,obranches);
|
||||
|
|
@ -270,15 +255,15 @@ _link_exdev_abs_base_symlink(const fuse_req_ctx_t *ctx_,
|
|||
static
|
||||
int
|
||||
_link_exdev_abs_pool_symlink(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &mount_,
|
||||
const fs::path &oldpath_,
|
||||
const fs::path &newpath_,
|
||||
const std::string &mount_,
|
||||
const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
StrVec basepaths;
|
||||
fs::path target;
|
||||
fs::relpath target;
|
||||
|
||||
target = mount_ / oldpath_;
|
||||
|
||||
|
|
@ -296,8 +281,8 @@ _link_exdev_abs_pool_symlink(const fuse_req_ctx_t *ctx_,
|
|||
static
|
||||
int
|
||||
_link_exdev(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &oldpath_,
|
||||
const fs::path &newpath_,
|
||||
const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
|
|
@ -333,18 +318,16 @@ _link_exdev(const fuse_req_ctx_t *ctx_,
|
|||
|
||||
int
|
||||
FUSE::link(const fuse_req_ctx_t *ctx_,
|
||||
const char *oldpath_,
|
||||
const char *newpath_,
|
||||
const fs::relpath &oldpath_,
|
||||
const fs::relpath &newpath_,
|
||||
struct stat *st_,
|
||||
fuse_timeouts_t *timeouts_)
|
||||
{
|
||||
int rv;
|
||||
const fs::path oldpath{oldpath_};
|
||||
const fs::path newpath{newpath_};
|
||||
|
||||
rv = ::_link(ctx_,oldpath,newpath,st_,timeouts_);
|
||||
rv = ::_link(ctx_,oldpath_,newpath_,st_,timeouts_);
|
||||
if(rv == -EXDEV)
|
||||
rv = ::_link_exdev(ctx_,oldpath,newpath,st_,timeouts_);
|
||||
rv = ::_link_exdev(ctx_,oldpath_,newpath_,st_,timeouts_);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
link(const fuse_req_ctx_t *ctx,
|
||||
const char *oldpath,
|
||||
const char *newpath,
|
||||
const fs::relpath &oldpath,
|
||||
const fs::relpath &newpath,
|
||||
struct stat *st,
|
||||
fuse_timeouts_t *timeouts);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include "fuse.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
|
||||
|
|
@ -33,12 +32,12 @@
|
|||
static
|
||||
ssize_t
|
||||
_listxattr_size(const std::vector<Branch*> &branches_,
|
||||
const fs::path &fusepath_)
|
||||
const fs::relpath &fusepath_)
|
||||
{
|
||||
ssize_t size;
|
||||
ssize_t err;
|
||||
bool success;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath = fusepath_;
|
||||
|
||||
if(branches_.empty())
|
||||
return -ENOENT;
|
||||
|
|
@ -50,7 +49,7 @@ _listxattr_size(const std::vector<Branch*> &branches_,
|
|||
{
|
||||
ssize_t rv;
|
||||
|
||||
fullpath = branch->path / fusepath_;
|
||||
fullpath.set_prefix(branch->path);
|
||||
|
||||
rv = fs::llistxattr(fullpath,NULL,0);
|
||||
if(rv < 0)
|
||||
|
|
@ -73,7 +72,7 @@ _listxattr_size(const std::vector<Branch*> &branches_,
|
|||
static
|
||||
ssize_t
|
||||
_listxattr(const std::vector<Branch*> &branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
char *list_,
|
||||
size_t size_)
|
||||
{
|
||||
|
|
@ -81,7 +80,7 @@ _listxattr(const std::vector<Branch*> &branches_,
|
|||
ssize_t size;
|
||||
ssize_t err;
|
||||
bool success;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath = fusepath_;
|
||||
|
||||
if(size_ == 0)
|
||||
return ::_listxattr_size(branches_,fusepath_);
|
||||
|
|
@ -91,7 +90,7 @@ _listxattr(const std::vector<Branch*> &branches_,
|
|||
success = false;
|
||||
for(const auto branch : branches_)
|
||||
{
|
||||
fullpath = branch->path / fusepath_;
|
||||
fullpath.set_prefix(branch->path);
|
||||
|
||||
rv = fs::llistxattr(fullpath,list_,size_);
|
||||
if(rv < 0)
|
||||
|
|
@ -122,7 +121,7 @@ static
|
|||
int
|
||||
_listxattr(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr ibranches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
char *list_,
|
||||
const size_t size_)
|
||||
{
|
||||
|
|
@ -141,13 +140,12 @@ _listxattr(const Policy::Search &searchFunc_,
|
|||
|
||||
int
|
||||
FUSE::listxattr(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
char *list_,
|
||||
size_t size_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
if(Config::is_ctrl_file(fusepath))
|
||||
if(Config::is_ctrl_file(fusepath_))
|
||||
return cfg.keys_listxattr(list_,size_);
|
||||
|
||||
switch(cfg.xattr)
|
||||
|
|
@ -162,7 +160,7 @@ FUSE::listxattr(const fuse_req_ctx_t *ctx_,
|
|||
|
||||
return ::_listxattr(cfg.func.listxattr.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
list_,
|
||||
size_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
|
@ -26,7 +27,7 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
listxattr(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
char *buf,
|
||||
size_t count);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
static
|
||||
int
|
||||
_mkdir_core(const ugid_t ugid_,
|
||||
const fs::path &fullpath_,
|
||||
const fs::relpath &fullpath_,
|
||||
mode_t mode_,
|
||||
const mode_t umask_)
|
||||
{
|
||||
|
|
@ -48,16 +48,16 @@ _mkdir_core(const ugid_t ugid_,
|
|||
|
||||
static
|
||||
int
|
||||
_mkdir_loop_core(const ugid_t ugid_,
|
||||
const fs::path &createpath_,
|
||||
const fs::path &fusepath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_)
|
||||
_mkdir_loop_core(const ugid_t ugid_,
|
||||
const std::string &createpath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
|
||||
fullpath = createpath_ / fusepath_;
|
||||
fullpath.assign_concat(createpath_,fusepath_);
|
||||
|
||||
rv = ::_mkdir_core(ugid_,fullpath,mode_,umask_);
|
||||
|
||||
|
|
@ -69,8 +69,8 @@ int
|
|||
_mkdir_loop(const ugid_t ugid_,
|
||||
const Branch *existingbranch_,
|
||||
const std::vector<Branch*> &createbranches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::path &fusedirpath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const fs::relpath &fusedirpath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_)
|
||||
{
|
||||
|
|
@ -104,12 +104,12 @@ _mkdir(const ugid_t ugid_,
|
|||
const Policy::Search &getattrPolicy_,
|
||||
const Policy::Create &mkdirPolicy_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fusedirpath;
|
||||
fs::relpath fusedirpath;
|
||||
std::vector<Branch*> createbranches;
|
||||
std::vector<Branch*> existingbranches;
|
||||
|
||||
|
|
@ -138,17 +138,16 @@ _mkdir(const ugid_t ugid_,
|
|||
|
||||
int
|
||||
FUSE::mkdir(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
mode_t mode_)
|
||||
{
|
||||
int rv;
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
rv = ::_mkdir(ctx_,
|
||||
cfg.func.getattr.policy,
|
||||
cfg.func.mkdir.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
mode_,
|
||||
ctx_->umask);
|
||||
if(rv == -EROFS)
|
||||
|
|
@ -158,7 +157,7 @@ FUSE::mkdir(const fuse_req_ctx_t *ctx_,
|
|||
cfg.func.getattr.policy,
|
||||
cfg.func.mkdir.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
mode_,
|
||||
ctx_->umask);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
|
@ -27,6 +28,6 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
mkdir(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
mode_t mode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ static
|
|||
inline
|
||||
int
|
||||
_mknod_core(const ugid_t ugid_,
|
||||
const fs::path &fullpath_,
|
||||
const fs::relpath &fullpath_,
|
||||
mode_t mode_,
|
||||
const mode_t umask_,
|
||||
const dev_t dev_)
|
||||
|
|
@ -50,17 +50,17 @@ _mknod_core(const ugid_t ugid_,
|
|||
|
||||
static
|
||||
int
|
||||
_mknod_loop_core(const ugid_t ugid_,
|
||||
const fs::path &createbranch_,
|
||||
const fs::path &fusepath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_,
|
||||
const dev_t dev_)
|
||||
_mknod_loop_core(const ugid_t ugid_,
|
||||
const std::string &createbranch_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_,
|
||||
const dev_t dev_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fullpath;
|
||||
fs::relpath fullpath;
|
||||
|
||||
fullpath = createbranch_ / fusepath_;
|
||||
fullpath.assign_concat(createbranch_,fusepath_);
|
||||
|
||||
rv = ::_mknod_core(ugid_,fullpath,mode_,umask_,dev_);
|
||||
|
||||
|
|
@ -70,10 +70,10 @@ _mknod_loop_core(const ugid_t ugid_,
|
|||
static
|
||||
int
|
||||
_mknod_loop(const ugid_t ugid_,
|
||||
const fs::path &existingbranch_,
|
||||
const std::string &existingbranch_,
|
||||
const std::vector<Branch*> &createbranches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::path &fusedirpath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const fs::relpath &fusedirpath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_,
|
||||
const dev_t dev_)
|
||||
|
|
@ -109,13 +109,13 @@ _mknod(const ugid_t ugid_,
|
|||
const Policy::Search &searchFunc_,
|
||||
const Policy::Create &createFunc_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
const mode_t mode_,
|
||||
const mode_t umask_,
|
||||
const dev_t dev_)
|
||||
{
|
||||
int rv;
|
||||
fs::path fusedirpath;
|
||||
fs::relpath fusedirpath;
|
||||
std::vector<Branch*> createbranches;
|
||||
std::vector<Branch*> existingbranches;
|
||||
|
||||
|
|
@ -145,18 +145,17 @@ _mknod(const ugid_t ugid_,
|
|||
|
||||
int
|
||||
FUSE::mknod(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
mode_t mode_,
|
||||
dev_t rdev_)
|
||||
{
|
||||
int rv;
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
rv = ::_mknod(ctx_,
|
||||
cfg.func.getattr.policy,
|
||||
cfg.func.mknod.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
mode_,
|
||||
ctx_->umask,
|
||||
rdev_);
|
||||
|
|
@ -167,7 +166,7 @@ FUSE::mknod(const fuse_req_ctx_t *ctx_,
|
|||
cfg.func.getattr.policy,
|
||||
cfg.func.mknod.policy,
|
||||
cfg.branches,
|
||||
fusepath,
|
||||
fusepath_,
|
||||
mode_,
|
||||
ctx_->umask,
|
||||
rdev_);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse_req_ctx.h"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
|
@ -28,7 +29,7 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
mknod(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
mode_t mode,
|
||||
dev_t rdev);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ _rdonly(const int flags_)
|
|||
|
||||
static
|
||||
int
|
||||
_lchmod_and_open_if_not_writable_and_empty(const fs::path &fullpath_,
|
||||
const int flags_)
|
||||
_lchmod_and_open_if_not_writable_and_empty(const std::string &fullpath_,
|
||||
const int flags_)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
|
|
@ -151,7 +151,7 @@ _lchmod_and_open_if_not_writable_and_empty(const fs::path &fullpath_,
|
|||
|
||||
static
|
||||
int
|
||||
_nfsopenhack(const fs::path &fullpath_,
|
||||
_nfsopenhack(const std::string &fullpath_,
|
||||
const int flags_,
|
||||
const NFSOpenHack nfsopenhack_)
|
||||
{
|
||||
|
|
@ -163,7 +163,7 @@ _nfsopenhack(const fs::path &fullpath_,
|
|||
case NFSOpenHack::ENUM::GIT:
|
||||
if(::_rdonly(flags_))
|
||||
return -EACCES;
|
||||
if(fullpath_.string().find("/.git/") == std::string::npos)
|
||||
if(fullpath_.find("/.git/") == std::string::npos)
|
||||
return -EACCES;
|
||||
return ::_lchmod_and_open_if_not_writable_and_empty(fullpath_,flags_);
|
||||
case NFSOpenHack::ENUM::ALL:
|
||||
|
|
@ -262,9 +262,9 @@ _config_to_ffi_flags(const int tid_,
|
|||
|
||||
static
|
||||
int
|
||||
_open_path(const fs::path &filepath_,
|
||||
_open_path(const std::string &filepath_,
|
||||
const Branch *branch_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_,
|
||||
const NFSOpenHack nfsopenhack_)
|
||||
{
|
||||
|
|
@ -288,7 +288,7 @@ static
|
|||
int
|
||||
_open_fd(const int fd_,
|
||||
const Branch *branch_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
int fd;
|
||||
|
|
@ -309,13 +309,13 @@ static
|
|||
int
|
||||
_open(const Policy::Search &searchFunc_,
|
||||
const Branches::Ptr ibranches_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_,
|
||||
const bool link_cow_,
|
||||
const NFSOpenHack nfsopenhack_)
|
||||
{
|
||||
int rv;
|
||||
fs::path filepath;
|
||||
std::string filepath;
|
||||
std::vector<Branch*> obranches;
|
||||
|
||||
rv = searchFunc_(ibranches_,fusepath_,obranches);
|
||||
|
|
@ -324,7 +324,9 @@ _open(const Policy::Search &searchFunc_,
|
|||
if(obranches.empty())
|
||||
return -ENOENT;
|
||||
|
||||
filepath = obranches[0]->path / fusepath_;
|
||||
filepath = obranches[0]->path;
|
||||
filepath += '/';
|
||||
filepath.append(fusepath_.native());
|
||||
|
||||
if(link_cow_ && fs::cow::is_eligible(filepath,ffi_->flags))
|
||||
fs::cow::break_link(filepath);
|
||||
|
|
@ -349,7 +351,7 @@ _(const PassthroughIOEnum e_,
|
|||
static
|
||||
int
|
||||
_open(const fuse_req_ctx_t *ctx_,
|
||||
const fs::path &fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
int rv;
|
||||
|
|
@ -484,10 +486,9 @@ _open(const fuse_req_ctx_t *ctx_,
|
|||
|
||||
int
|
||||
FUSE::open(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
const fs::path fusepath{fusepath_};
|
||||
|
||||
return ::_open(ctx_,fusepath,ffi_);
|
||||
return ::_open(ctx_,fusepath_,ffi_);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
open(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
fuse_file_info_t *ffi);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
int
|
||||
FUSE::opendir(const fuse_req_ctx_t *ctx_,
|
||||
const char *fusepath_,
|
||||
const fs::relpath &fusepath_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
DirInfo *di;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,6 @@ namespace FUSE
|
|||
{
|
||||
int
|
||||
opendir(const fuse_req_ctx_t *ctx,
|
||||
const char *fusepath,
|
||||
const fs::relpath &fusepath,
|
||||
fuse_file_info_t *ffi);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ inline
|
|||
int
|
||||
_concurrent_readdir(ThreadPool &tp_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &rel_dirpath_,
|
||||
const fs::relpath &rel_dirpath_,
|
||||
fuse_dirents_t *dirents_)
|
||||
{
|
||||
HashSet names;
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@
|
|||
static
|
||||
inline
|
||||
int
|
||||
_readdir(const fs::path &branch_path_,
|
||||
const fs::path &rel_dirpath_,
|
||||
_readdir(const std::string &branch_path_,
|
||||
const fs::relpath &rel_dirpath_,
|
||||
HashSet &names_,
|
||||
fuse_dirents_t *dirents_,
|
||||
mutex_t &mutex_)
|
||||
{
|
||||
int fd;
|
||||
fuse_msgbuf_t *buf;
|
||||
fs::path abs_dirpath;
|
||||
fs::relpath abs_dirpath;
|
||||
|
||||
abs_dirpath = branch_path_ / rel_dirpath_;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,14 +50,14 @@ _dirent_exact_namelen(const struct dirent *d_)
|
|||
static
|
||||
inline
|
||||
int
|
||||
_readdir(const fs::path &branch_path_,
|
||||
const fs::path &rel_dirpath_,
|
||||
_readdir(const std::string &branch_path_,
|
||||
const fs::relpath &rel_dirpath_,
|
||||
HashSet &names_,
|
||||
fuse_dirents_t *dirents_,
|
||||
mutex_t &mutex_)
|
||||
{
|
||||
DIR *dir;
|
||||
fs::path abs_dirpath;
|
||||
fs::relpath abs_dirpath;
|
||||
|
||||
abs_dirpath = branch_path_ / rel_dirpath_;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ inline
|
|||
int
|
||||
_readdir(ThreadPool &tp_,
|
||||
const Branches::Ptr branches_,
|
||||
const fs::path &rel_dirpath_,
|
||||
const fs::relpath &rel_dirpath_,
|
||||
fuse_dirents_t *dirents_)
|
||||
{
|
||||
int rv;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue