From 7c85cd906a9d10e22348b409adc1e9847541ed46 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Wed, 24 Feb 2016 12:40:02 -0500 Subject: [PATCH] ff policy tweaks --- src/policy.hpp | 2 ++ src/policy_ff.cpp | 51 +++++++++++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/policy.hpp b/src/policy.hpp index 2c31eec1..7cfe3ba3 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -28,6 +28,8 @@ #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) namespace mergerfs { diff --git a/src/policy_ff.cpp b/src/policy_ff.cpp index 14edb338..0a2d2ee8 100644 --- a/src/policy_ff.cpp +++ b/src/policy_ff.cpp @@ -31,12 +31,9 @@ using std::size_t; static int -_ff(const vector &basepaths, - const char *fusepath, - const bool needswritablefs, - vector &paths) +_ff_rw(const vector &basepaths, + vector &paths) { - string fullpath; struct statvfs st; const string *fallback = NULL; @@ -44,12 +41,10 @@ _ff(const vector &basepaths, { const string *basepath = &basepaths[i]; - fs::path::make(basepath,fusepath,fullpath); - - if(!fs::exists(fullpath,st)) + if(!fs::exists(basepath->c_str(),st)) continue; - if(needswritablefs && StatVFS::readonly(st)) + if(StatVFS::readonly(st)) { if(fallback == NULL) fallback = basepath; @@ -61,13 +56,37 @@ _ff(const vector &basepaths, return POLICY_SUCCESS; } - if(fallback != NULL) + if(fallback == NULL) + return POLICY_FAIL_ENOENT; + + paths.push_back(fallback); + + return POLICY_SUCCESS; +} + +static +int +_ff_ro(const vector &basepaths, + const char *fusepath, + vector &paths) +{ + string fullpath; + + for(size_t i = 0, ei = basepaths.size(); i != ei; i++) { - paths.push_back(fallback); + const string *basepath = &basepaths[i]; + + fs::path::make(basepath,fusepath,fullpath); + + if(!fs::exists(fullpath)) + continue; + + paths.push_back(basepath); + return POLICY_SUCCESS; } - return (errno=ENOENT,POLICY_FAIL); + return POLICY_FAIL_ENOENT; } namespace mergerfs @@ -79,11 +98,9 @@ namespace mergerfs const size_t minfreespace, vector &paths) { - const char *fp = - ((type == Category::Enum::create) ? "" : fusepath); - const bool needswritablefs = - (type == Category::Enum::create); + if(type == Category::Enum::create) + return _ff_rw(basepaths,paths); - return _ff(basepaths,fp,needswritablefs,paths); + return _ff_ro(basepaths,fusepath,paths); } }