diff --git a/src/create.cpp b/src/create.cpp index fed2f5f2..3ff02ef8 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -84,19 +84,17 @@ _create(Policy::Func::Search searchFunc, int rv; string fullpath; string fusedirpath; - const char *fusedirpathcstr; vector createpaths; vector existingpaths; fusedirpath = fusepath; fs::path::dirname(fusedirpath); - fusedirpathcstr = fusedirpath.c_str(); - rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths); + rv = searchFunc(srcmounts,fusedirpath,minfreespace,existingpaths); if(rv == -1) return -errno; - rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths); + rv = createFunc(srcmounts,fusedirpath,minfreespace,createpaths); if(rv == -1) return -errno; diff --git a/src/fs_base_setxattr.hpp b/src/fs_base_setxattr.hpp index 0a149bb2..ee91b6c1 100644 --- a/src/fs_base_setxattr.hpp +++ b/src/fs_base_setxattr.hpp @@ -18,29 +18,47 @@ #pragma once -#include - #include "errno.hpp" #include "xattr.hpp" +#include + +#include + namespace fs { static inline int - lsetxattr(const std::string &path, - const char *name, - const void *value, - const size_t size, - const int flags) + lsetxattr(const char *path_, + const char *name_, + const void *value_, + const size_t size_, + const int flags_) { #ifdef USE_XATTR - return ::lsetxattr(path.c_str(),name,value,size,flags); + return ::lsetxattr(path_,name_,value_,size_,flags_); #else return (errno=ENOTSUP,-1); #endif } + static + inline + int + lsetxattr(const std::string &path_, + const std::string &name_, + const void *value_, + const size_t size_, + const int flags_) + { + return fs::lsetxattr(path_.c_str(), + name_.c_str(), + value_, + size_, + flags_); + } + static inline int diff --git a/src/fs_xattr.cpp b/src/fs_xattr.cpp index 12a7cc53..f2b52a04 100644 --- a/src/fs_xattr.cpp +++ b/src/fs_xattr.cpp @@ -295,8 +295,8 @@ namespace fs const string &value, const int flags) { - return fs::lsetxattr(path.c_str(), - key.c_str(), + return fs::lsetxattr(path, + key, value.data(), value.size(), flags); diff --git a/src/link.cpp b/src/link.cpp index 2c492124..e521511c 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -99,7 +99,8 @@ _link_create_path(Policy::Func::Search searchFunc, newfusedirpath = newfusepath; fs::path::dirname(newfusedirpath); - rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepaths); + + rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepaths); if(rv == -1) return -errno; @@ -120,25 +121,23 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc, { int rv; string newfusedirpath; - const char *newfusedirpathcstr; vector newbasepath; newfusedirpath = newfusepath; fs::path::dirname(newfusedirpath); - newfusedirpathcstr = newfusedirpath.c_str(); - rv = createFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath); + rv = createFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); if(rv == -1) return -1; if(oldbasepath != *newbasepath[0]) return (errno=EXDEV,-1); - rv = searchFunc(srcmounts,newfusedirpathcstr,minfreespace,newbasepath); + rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); if(rv == -1) return -1; - return fs::clonepath_as_root(*newbasepath[0],oldbasepath,newfusedirpathcstr); + return fs::clonepath_as_root(*newbasepath[0],oldbasepath,newfusedirpath); } static diff --git a/src/mkdir.cpp b/src/mkdir.cpp index 355913df..9ff75f4d 100644 --- a/src/mkdir.cpp +++ b/src/mkdir.cpp @@ -68,7 +68,7 @@ int _mkdir_loop(const string &existingpath, const vector &createpaths, const char *fusepath, - const char *fusedirpath, + const string &fusedirpath, const mode_t mode, const mode_t umask) { @@ -102,24 +102,22 @@ _mkdir(Policy::Func::Search searchFunc, { int rv; string fusedirpath; - const char *fusedirpathcstr; vector createpaths; vector existingpaths; fusedirpath = fusepath; fs::path::dirname(fusedirpath); - fusedirpathcstr = fusedirpath.c_str(); - rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths); + rv = searchFunc(srcmounts,fusedirpath,minfreespace,existingpaths); if(rv == -1) return -errno; - rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths); + rv = createFunc(srcmounts,fusedirpath,minfreespace,createpaths); if(rv == -1) return -errno; return _mkdir_loop(*existingpaths[0],createpaths, - fusepath,fusedirpathcstr,mode,umask); + fusepath,fusedirpath,mode,umask); } namespace mergerfs diff --git a/src/mknod.cpp b/src/mknod.cpp index 9f51c43a..4d602b03 100644 --- a/src/mknod.cpp +++ b/src/mknod.cpp @@ -71,7 +71,7 @@ int _mknod_loop(const string &existingpath, const vector &createpaths, const char *fusepath, - const char *fusedirpath, + const string &fusedirpath, const mode_t mode, const mode_t umask, const dev_t dev) @@ -107,24 +107,22 @@ _mknod(Policy::Func::Search searchFunc, { int rv; string fusedirpath; - const char *fusedirpathcstr; vector createpaths; vector existingpaths; fusedirpath = fusepath; fs::path::dirname(fusedirpath); - fusedirpathcstr = fusedirpath.c_str(); - rv = searchFunc(srcmounts,fusedirpathcstr,minfreespace,existingpaths); + rv = searchFunc(srcmounts,fusedirpath,minfreespace,existingpaths); if(rv == -1) return -errno; - rv = createFunc(srcmounts,fusedirpathcstr,minfreespace,createpaths); + rv = createFunc(srcmounts,fusedirpath,minfreespace,createpaths); if(rv == -1) return -errno; return _mknod_loop(*existingpaths[0],createpaths, - fusepath,fusedirpathcstr, + fusepath,fusedirpath, mode,umask,dev); } diff --git a/src/policy.hpp b/src/policy.hpp index 215a85ad..5b79a528 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -16,19 +16,12 @@ #pragma once -#include -#include -#include - -#include "fs.hpp" #include "category.hpp" +#include "fs.hpp" -#define POLICY_SUCCESS 0 -#define POLICY_FAIL -1 -#define POLICY_SUCCEEDED(RV) ((RV) == POLICY_SUCCESS) -#define POLICY_FAILED(RV) ((RV) == POLICY_FAIL) -#define POLICY_FAIL_ERRNO(ERRNO) (errno=ERRNO,POLICY_FAIL) -#define POLICY_FAIL_ENOENT POLICY_FAIL_ERRNO(ENOENT) +#include +#include +#include namespace mergerfs { @@ -88,6 +81,12 @@ namespace mergerfs return func(T,b,c,d,e); } + int + operator()(cstrvec &b,const string &c,cuint64_t d,cstrptrvec &e) + { + return func(T,b,c.c_str(),d,e); + } + private: const Ptr func; }; diff --git a/src/policy_all.cpp b/src/policy_all.cpp index 764ee8c6..4a06df81 100644 --- a/src/policy_all.cpp +++ b/src/policy_all.cpp @@ -49,9 +49,9 @@ _all_create(const vector &basepaths, } if(paths.empty()) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); - return POLICY_SUCCESS; + return 0; } static @@ -75,9 +75,9 @@ _all_other(const vector &basepaths, } if(paths.empty()) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); - return POLICY_SUCCESS; + return 0; } namespace mergerfs diff --git a/src/policy_epall.cpp b/src/policy_epall.cpp index 57fcf85b..473ce0c3 100644 --- a/src/policy_epall.cpp +++ b/src/policy_epall.cpp @@ -56,9 +56,9 @@ _epall_create(const vector &basepaths, } if(paths.empty()) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); - return POLICY_SUCCESS; + return 0; } static @@ -82,9 +82,9 @@ _epall_other(const vector &basepaths, } if(paths.empty()) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); - return POLICY_SUCCESS; + return 0; } namespace mergerfs diff --git a/src/policy_epff.cpp b/src/policy_epff.cpp index 7b00b3de..be88cb05 100644 --- a/src/policy_epff.cpp +++ b/src/policy_epff.cpp @@ -59,15 +59,15 @@ _epff_create(const vector &basepaths, paths.push_back(basepath); - return POLICY_SUCCESS; + return 0; } if(fallback == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(fallback); - return POLICY_SUCCESS; + return 0; } static @@ -89,10 +89,10 @@ _epff_other(const vector &basepaths, paths.push_back(basepath); - return POLICY_SUCCESS; + return 0; } - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); } static @@ -122,7 +122,7 @@ namespace mergerfs int rv; rv = _epff(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_eplfs.cpp b/src/policy_eplfs.cpp index d1d0e00b..501f6816 100644 --- a/src/policy_eplfs.cpp +++ b/src/policy_eplfs.cpp @@ -65,11 +65,11 @@ _eplfs_create(const vector &basepaths, } if(eplfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(eplfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -103,11 +103,11 @@ _eplfs_other(const vector &basepaths, } if(eplfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(eplfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -136,7 +136,7 @@ namespace mergerfs int rv; rv = _eplfs(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::lfs(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_eplus.cpp b/src/policy_eplus.cpp index cbdcbfe5..c0761f2b 100644 --- a/src/policy_eplus.cpp +++ b/src/policy_eplus.cpp @@ -65,11 +65,11 @@ _eplus_create(const vector &basepaths, } if(eplusbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(eplusbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -103,11 +103,11 @@ _eplus_other(const vector &basepaths, } if(eplusbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(eplusbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -136,7 +136,7 @@ namespace mergerfs int rv; rv = _eplus(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::lus(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_epmfs.cpp b/src/policy_epmfs.cpp index fcde084a..8b54fd1e 100644 --- a/src/policy_epmfs.cpp +++ b/src/policy_epmfs.cpp @@ -65,11 +65,11 @@ _epmfs_create(const vector &basepaths, } if(epmfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(epmfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -103,11 +103,11 @@ _epmfs_other(const vector &basepaths, } if(epmfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(epmfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -136,7 +136,7 @@ namespace mergerfs int rv; rv = _epmfs(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_eprand.cpp b/src/policy_eprand.cpp index 2620bc49..010b55c5 100644 --- a/src/policy_eprand.cpp +++ b/src/policy_eprand.cpp @@ -37,7 +37,7 @@ namespace mergerfs int rv; rv = Policy::Func::epall(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_SUCCEEDED(rv)) + if(rv == 0) std::random_shuffle(paths.begin(),paths.end()); return rv; diff --git a/src/policy_erofs.cpp b/src/policy_erofs.cpp index ba8bd196..8449f6a4 100644 --- a/src/policy_erofs.cpp +++ b/src/policy_erofs.cpp @@ -32,6 +32,6 @@ namespace mergerfs const uint64_t minfreespace, vector &paths) { - return POLICY_FAIL_ERRNO(EROFS); + return (errno=EROFS,-1); } } diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index eb5c5110..34e70a5a 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -52,15 +52,15 @@ _ff_create(const vector &basepaths, paths.push_back(basepath); - return POLICY_SUCCESS; + return 0; } if(fallback == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(fallback); - return POLICY_SUCCESS; + return 0; } static @@ -82,10 +82,10 @@ _ff_other(const vector &basepaths, paths.push_back(basepath); - return POLICY_SUCCESS; + return 0; } - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); } namespace mergerfs diff --git a/src/policy_invalid.cpp b/src/policy_invalid.cpp index 4bcddc0a..b56084dd 100644 --- a/src/policy_invalid.cpp +++ b/src/policy_invalid.cpp @@ -32,6 +32,6 @@ namespace mergerfs const uint64_t minfreespace, vector &paths) { - return POLICY_FAIL_ERRNO(EINVAL); + return (errno=EINVAL,-1); } } diff --git a/src/policy_lfs.cpp b/src/policy_lfs.cpp index 3a880b6f..88049c96 100644 --- a/src/policy_lfs.cpp +++ b/src/policy_lfs.cpp @@ -60,11 +60,11 @@ _lfs_create(const vector &basepaths, } if(lfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(lfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -98,11 +98,11 @@ _lfs_other(const vector &basepaths, } if(lfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(lfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -132,7 +132,7 @@ namespace mergerfs int rv; rv = _lfs(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_lus.cpp b/src/policy_lus.cpp index ea73648e..7d8c05e5 100644 --- a/src/policy_lus.cpp +++ b/src/policy_lus.cpp @@ -60,11 +60,11 @@ _lus_create(const vector &basepaths, } if(lusbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(lusbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -98,11 +98,11 @@ _lus_other(const vector &basepaths, } if(lusbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(lusbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -131,7 +131,7 @@ namespace mergerfs int rv; rv = _lus(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_mfs.cpp b/src/policy_mfs.cpp index 668dc0b1..ba68b5a5 100644 --- a/src/policy_mfs.cpp +++ b/src/policy_mfs.cpp @@ -56,11 +56,11 @@ _mfs_create(const vector &basepaths, } if(mfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(mfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -94,11 +94,11 @@ _mfs_other(const vector &basepaths, } if(mfsbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(mfsbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -126,7 +126,7 @@ namespace mergerfs int rv; rv = _mfs(type,basepaths,fusepath,paths); - if(POLICY_FAILED(rv)) + if(rv == -1) rv = Policy::Func::ff(type,basepaths,fusepath,minfreespace,paths); return rv; diff --git a/src/policy_newest.cpp b/src/policy_newest.cpp index 1e905c08..cc17d9e8 100644 --- a/src/policy_newest.cpp +++ b/src/policy_newest.cpp @@ -61,11 +61,11 @@ _newest_create(const vector &basepaths, } if(newestbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(newestbasepath); - return POLICY_SUCCESS; + return 0; } static @@ -97,11 +97,11 @@ _newest_other(const vector &basepaths, } if(newestbasepath == NULL) - return POLICY_FAIL_ENOENT; + return (errno=ENOENT,-1); paths.push_back(newestbasepath); - return POLICY_SUCCESS; + return 0; } namespace mergerfs diff --git a/src/policy_rand.cpp b/src/policy_rand.cpp index a7aa1314..8ef22de2 100644 --- a/src/policy_rand.cpp +++ b/src/policy_rand.cpp @@ -37,7 +37,7 @@ namespace mergerfs int rv; rv = Policy::Func::all(type,basepaths,fusepath,minfreespace,paths); - if(POLICY_SUCCEEDED(rv)) + if(rv == 0) std::random_shuffle(paths.begin(),paths.end()); return rv; diff --git a/src/rename.cpp b/src/rename.cpp index f7ab4bf0..29073150 100644 --- a/src/rename.cpp +++ b/src/rename.cpp @@ -112,13 +112,13 @@ _rename_create_path(Policy::Func::Search searchFunc, vector oldbasepaths; rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); - if(POLICY_FAILED(rv)) + if(rv == -1) return -errno; string newfusedirpath = newfusepath; fs::path::dirname(newfusedirpath); - rv = searchFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath); - if(POLICY_FAILED(rv)) + rv = searchFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); + if(rv == -1) return -errno; error = -1; @@ -151,13 +151,13 @@ _clonepath(Policy::Func::Search searchFunc, int rv; vector srcbasepath; - rv = searchFunc(srcmounts,fusedirpath.c_str(),minfreespace,srcbasepath); - if(POLICY_FAILED(rv)) + rv = searchFunc(srcmounts,fusedirpath,minfreespace,srcbasepath); + if(rv == -1) return -errno; fs::clonepath_as_root(*srcbasepath[0],dstbasepath,fusedirpath); - return POLICY_SUCCESS; + return 0; } static @@ -176,14 +176,14 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc, newfusedirpath = newfusepath; fs::path::dirname(newfusedirpath); - rv = createFunc(srcmounts,newfusedirpath.c_str(),minfreespace,newbasepath); - if(POLICY_FAILED(rv)) + rv = createFunc(srcmounts,newfusedirpath,minfreespace,newbasepath); + if(rv == -1) return rv; if(oldbasepath == *newbasepath[0]) return _clonepath(searchFunc,srcmounts,minfreespace,oldbasepath,newfusedirpath); - return POLICY_FAIL_ERRNO(EXDEV); + return (errno=EXDEV,-1); } static @@ -218,7 +218,7 @@ _rename_preserve_path_core(Policy::Func::Search searchFunc, rv = _clonepath_if_would_create(searchFunc,createFunc, srcmounts,minfreespace, oldbasepath,oldfusepath,newfusepath); - if(POLICY_SUCCEEDED(rv)) + if(rv == 0) rv = fs::rename(oldfullpath,newfullpath); } @@ -248,7 +248,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc, vector oldbasepaths; rv = actionFunc(srcmounts,oldfusepath,minfreespace,oldbasepaths); - if(POLICY_FAILED(rv)) + if(rv == -1) return -errno; error = -1; diff --git a/src/symlink.cpp b/src/symlink.cpp index cc49faf8..f119a69c 100644 --- a/src/symlink.cpp +++ b/src/symlink.cpp @@ -57,7 +57,7 @@ _symlink_loop(const string &existingpath, const vector newbasepaths, const char *oldpath, const char *newpath, - const char *newdirpath) + const string &newdirpath) { int rv; int error; @@ -89,24 +89,22 @@ _symlink(Policy::Func::Search searchFunc, { int rv; string newdirpath; - const char *newdirpathcstr; vector newbasepaths; vector existingpaths; newdirpath = newpath; fs::path::dirname(newdirpath); - newdirpathcstr = newdirpath.c_str(); - rv = searchFunc(srcmounts,newdirpathcstr,minfreespace,existingpaths); + rv = searchFunc(srcmounts,newdirpath,minfreespace,existingpaths); if(rv == -1) return -errno; - rv = createFunc(srcmounts,newdirpathcstr,minfreespace,newbasepaths); + rv = createFunc(srcmounts,newdirpath,minfreespace,newbasepaths); if(rv == -1) return -errno; return _symlink_loop(*existingpaths[0],newbasepaths, - oldpath,newpath,newdirpathcstr); + oldpath,newpath,newdirpath); } namespace mergerfs