mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-03-15 02:35:12 +08:00
commit
a5bf48c8ae
@ -45,14 +45,14 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_access(const fs::find::Func searchFunc,
|
_access(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
const int mask)
|
const int mask)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
@ -39,7 +39,7 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_chmod(const fs::find::Func actionFunc,
|
_chmod(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -47,14 +47,14 @@ _chmod(const fs::find::Func actionFunc,
|
|||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::chmod(i->full.c_str(),mode);
|
rv = ::chmod(i->full.c_str(),mode);
|
||||||
|
@ -40,7 +40,7 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_chown(const fs::find::Func actionFunc,
|
_chown(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -49,14 +49,14 @@ _chown(const fs::find::Func actionFunc,
|
|||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::lchown(i->full.c_str(),uid,gid);
|
rv = ::lchown(i->full.c_str(),uid,gid);
|
||||||
|
@ -43,8 +43,8 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_create(const fs::find::Func searchFunc,
|
_create(const Policy::Func::Ptr searchFunc,
|
||||||
const fs::find::Func createFunc,
|
const Policy::Func::Ptr createFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -56,8 +56,8 @@ _create(const fs::find::Func searchFunc,
|
|||||||
int rv;
|
int rv;
|
||||||
string path;
|
string path;
|
||||||
string dirname;
|
string dirname;
|
||||||
fs::Paths createpath;
|
Paths createpath;
|
||||||
fs::Paths existingpath;
|
Paths existingpath;
|
||||||
|
|
||||||
dirname = fs::dirname(fusepath);
|
dirname = fs::dirname(fusepath);
|
||||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||||
|
338
src/fs.cpp
338
src/fs.cpp
@ -28,7 +28,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -514,341 +513,4 @@ namespace fs
|
|||||||
|
|
||||||
globfree(&gbuf);
|
globfree(&gbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace find
|
|
||||||
{
|
|
||||||
int
|
|
||||||
invalid(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &rv)
|
|
||||||
{
|
|
||||||
return (errno = EINVAL,-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ff(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
errno = ENOENT;
|
|
||||||
for(vector<string>::const_iterator
|
|
||||||
iter = basepaths.begin(), eiter = basepaths.end();
|
|
||||||
iter != eiter;
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
struct stat st;
|
|
||||||
string fullpath;
|
|
||||||
|
|
||||||
fullpath = fs::make_path(*iter,fusepath);
|
|
||||||
|
|
||||||
rv = ::lstat(fullpath.c_str(),&st);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
paths.push_back(Path(*iter,fullpath));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
ffwp(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
Path fallback;
|
|
||||||
|
|
||||||
errno = ENOENT;
|
|
||||||
for(vector<string>::const_iterator
|
|
||||||
iter = basepaths.begin(), eiter = basepaths.end();
|
|
||||||
iter != eiter;
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
struct stat st;
|
|
||||||
string fullpath;
|
|
||||||
|
|
||||||
fullpath = fs::make_path(*iter,fusepath);
|
|
||||||
|
|
||||||
rv = ::lstat(fullpath.c_str(),&st);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
paths.push_back(Path(*iter,fullpath));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if(errno == EACCES)
|
|
||||||
{
|
|
||||||
fallback.base = *iter;
|
|
||||||
fallback.full = fullpath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!fallback.base.empty())
|
|
||||||
return (paths.push_back(fallback),0);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
fwfs(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
const char *basepath;
|
|
||||||
struct statvfs fsstats;
|
|
||||||
|
|
||||||
basepath = basepaths[i].c_str();
|
|
||||||
rv = ::statvfs(basepath,&fsstats);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
fsblkcnt_t spaceavail;
|
|
||||||
|
|
||||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
|
||||||
if(spaceavail > minfreespace)
|
|
||||||
{
|
|
||||||
paths.push_back(Path(basepath,
|
|
||||||
fs::make_path(basepath,fusepath)));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mfs(basepaths,fusepath,minfreespace,paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
newest(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
time_t newest;
|
|
||||||
string npath;
|
|
||||||
vector<string>::const_iterator niter;
|
|
||||||
|
|
||||||
newest = 0;
|
|
||||||
errno = ENOENT;
|
|
||||||
for(vector<string>::const_iterator
|
|
||||||
iter = basepaths.begin(), eiter = basepaths.end();
|
|
||||||
iter != eiter;
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
struct stat st;
|
|
||||||
string fullpath;
|
|
||||||
|
|
||||||
fullpath = fs::make_path(*iter,fusepath);
|
|
||||||
|
|
||||||
rv = ::lstat(fullpath.c_str(),&st);
|
|
||||||
if(rv == 0 && st.st_mtime > newest)
|
|
||||||
{
|
|
||||||
newest = st.st_mtime;
|
|
||||||
niter = iter;
|
|
||||||
npath = fullpath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(newest)
|
|
||||||
return (paths.push_back(Path(*niter,npath)),0);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
lfs(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
fsblkcnt_t lfs;
|
|
||||||
const char *lfsstr;
|
|
||||||
|
|
||||||
lfs = -1;
|
|
||||||
lfsstr = NULL;
|
|
||||||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
const char *basepath;
|
|
||||||
struct statvfs fsstats;
|
|
||||||
|
|
||||||
basepath = basepaths[i].c_str();
|
|
||||||
rv = ::statvfs(basepath,&fsstats);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
fsblkcnt_t spaceavail;
|
|
||||||
|
|
||||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
|
||||||
if((spaceavail > minfreespace) &&
|
|
||||||
(spaceavail < lfs))
|
|
||||||
{
|
|
||||||
lfs = spaceavail;
|
|
||||||
lfsstr = basepath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lfsstr == NULL)
|
|
||||||
return mfs(basepaths,fusepath,minfreespace,paths);
|
|
||||||
|
|
||||||
paths.push_back(Path(lfsstr,
|
|
||||||
fs::make_path(lfsstr,fusepath)));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
mfs(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
fsblkcnt_t mfs;
|
|
||||||
size_t mfsidx;
|
|
||||||
|
|
||||||
mfs = 0;
|
|
||||||
for(size_t i = 0, size = basepaths.size();
|
|
||||||
i != size;
|
|
||||||
i++)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
struct statvfs fsstats;
|
|
||||||
|
|
||||||
rv = ::statvfs(basepaths[i].c_str(),&fsstats);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
fsblkcnt_t spaceavail;
|
|
||||||
|
|
||||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
|
||||||
if(spaceavail > mfs)
|
|
||||||
{
|
|
||||||
mfs = spaceavail;
|
|
||||||
mfsidx = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mfs == 0)
|
|
||||||
return (errno=ENOENT,-1);
|
|
||||||
|
|
||||||
paths.push_back(Path(basepaths[mfsidx],
|
|
||||||
fs::make_path(basepaths[mfsidx],fusepath)));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
epmfs(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
fsblkcnt_t existingmfs;
|
|
||||||
fsblkcnt_t generalmfs;
|
|
||||||
string fullpath;
|
|
||||||
string generalmfspath;
|
|
||||||
string existingmfspath;
|
|
||||||
vector<string>::const_iterator iter = basepaths.begin();
|
|
||||||
vector<string>::const_iterator eiter = basepaths.end();
|
|
||||||
|
|
||||||
if(iter == eiter)
|
|
||||||
return (errno = ENOENT,-1);
|
|
||||||
|
|
||||||
existingmfs = 0;
|
|
||||||
generalmfs = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
struct statvfs fsstats;
|
|
||||||
const string &mountpoint = *iter;
|
|
||||||
|
|
||||||
rv = ::statvfs(mountpoint.c_str(),&fsstats);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
fsblkcnt_t spaceavail;
|
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
|
||||||
if(spaceavail > generalmfs)
|
|
||||||
{
|
|
||||||
generalmfs = spaceavail;
|
|
||||||
generalmfspath = mountpoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
fullpath = fs::make_path(mountpoint,fusepath);
|
|
||||||
rv = ::lstat(fullpath.c_str(),&st);
|
|
||||||
if(rv == 0)
|
|
||||||
{
|
|
||||||
if(spaceavail > existingmfs)
|
|
||||||
{
|
|
||||||
existingmfs = spaceavail;
|
|
||||||
existingmfspath = mountpoint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
++iter;
|
|
||||||
}
|
|
||||||
while(iter != eiter);
|
|
||||||
|
|
||||||
if(existingmfspath.empty())
|
|
||||||
existingmfspath = generalmfspath;
|
|
||||||
|
|
||||||
paths.push_back(Path(existingmfspath,
|
|
||||||
fullpath));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
all(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
struct stat st;
|
|
||||||
string fullpath;
|
|
||||||
|
|
||||||
for(vector<string>::const_iterator
|
|
||||||
iter = basepaths.begin(), eiter = basepaths.end();
|
|
||||||
iter != eiter;
|
|
||||||
++iter)
|
|
||||||
{
|
|
||||||
fullpath = fs::make_path(*iter,fusepath);
|
|
||||||
|
|
||||||
rv = ::lstat(fullpath.c_str(),&st);
|
|
||||||
if(rv == 0)
|
|
||||||
paths.push_back(Path(*iter,fullpath));
|
|
||||||
}
|
|
||||||
|
|
||||||
return paths.empty() ? (errno=ENOENT,-1) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
rand(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &paths)
|
|
||||||
{
|
|
||||||
int rv;
|
|
||||||
|
|
||||||
rv = all(basepaths,fusepath,minfreespace,paths);
|
|
||||||
if(rv == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
std::random_shuffle(paths.begin(),paths.end());
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
72
src/fs.hpp
72
src/fs.hpp
@ -29,6 +29,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "path.hpp"
|
||||||
|
|
||||||
namespace fs
|
namespace fs
|
||||||
{
|
{
|
||||||
using std::size_t;
|
using std::size_t;
|
||||||
@ -36,30 +38,6 @@ namespace fs
|
|||||||
using std::vector;
|
using std::vector;
|
||||||
using std::map;
|
using std::map;
|
||||||
|
|
||||||
struct Path
|
|
||||||
{
|
|
||||||
Path() {}
|
|
||||||
|
|
||||||
explicit
|
|
||||||
Path(const string &b,
|
|
||||||
const string &f)
|
|
||||||
: base(b),
|
|
||||||
full(f)
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit
|
|
||||||
Path(const char *b,
|
|
||||||
const string &f)
|
|
||||||
: base(b),
|
|
||||||
full(f)
|
|
||||||
{}
|
|
||||||
|
|
||||||
string base;
|
|
||||||
string full;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef vector<Path> Paths;
|
|
||||||
|
|
||||||
string dirname(const string &path);
|
string dirname(const string &path);
|
||||||
string basename(const string &path);
|
string basename(const string &path);
|
||||||
|
|
||||||
@ -119,52 +97,6 @@ namespace fs
|
|||||||
|
|
||||||
void glob(const vector<string> &patterns,
|
void glob(const vector<string> &patterns,
|
||||||
vector<string> &strs);
|
vector<string> &strs);
|
||||||
|
|
||||||
namespace find
|
|
||||||
{
|
|
||||||
typedef int (*Func)(const vector<string>&,const string&,const size_t,Paths&);
|
|
||||||
|
|
||||||
int invalid(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int all(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int ff(const vector<string> &basepaths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int ffwp(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int fwfs(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int newest(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int lfs(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int mfs(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int epmfs(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
int rand(const vector<string> &paths,
|
|
||||||
const string &fusepath,
|
|
||||||
const size_t minfreespace,
|
|
||||||
Paths &path);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __FS_HPP__
|
#endif // __FS_HPP__
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
@ -65,14 +66,14 @@ _getattr_controlfile(struct stat &buf)
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_getattr(const fs::find::Func searchFunc,
|
_getattr(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
struct stat &buf)
|
struct stat &buf)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths path;
|
Paths path;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
@ -167,7 +167,7 @@ _getxattr_user_mergerfs_allpaths(const vector<string> &srcmounts,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_getxattr_user_mergerfs(const fs::Path &path,
|
_getxattr_user_mergerfs(const Path &path,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
const char *attrname,
|
const char *attrname,
|
||||||
@ -190,7 +190,7 @@ _getxattr_user_mergerfs(const fs::Path &path,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_getxattr(const fs::find::Func searchFunc,
|
_getxattr(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -200,7 +200,7 @@ _getxattr(const fs::find::Func searchFunc,
|
|||||||
{
|
{
|
||||||
#ifndef WITHOUT_XATTR
|
#ifndef WITHOUT_XATTR
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths path;
|
Paths path;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
@ -82,7 +82,7 @@ _ioctl(const int fd,
|
|||||||
#ifdef FUSE_IOCTL_DIR
|
#ifdef FUSE_IOCTL_DIR
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_ioctl_dir_base(const fs::find::Func searchFunc,
|
_ioctl_dir_base(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -93,7 +93,7 @@ _ioctl_dir_base(const fs::find::Func searchFunc,
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths path;
|
Paths path;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
12
src/link.cpp
12
src/link.cpp
@ -41,7 +41,7 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_single_link(const fs::find::Func searchFunc,
|
_single_link(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &base,
|
const string &base,
|
||||||
@ -56,7 +56,7 @@ _single_link(const fs::find::Func searchFunc,
|
|||||||
if(rv == -1 && errno == ENOENT)
|
if(rv == -1 && errno == ENOENT)
|
||||||
{
|
{
|
||||||
string newpathdir;
|
string newpathdir;
|
||||||
fs::Paths foundpath;
|
Paths foundpath;
|
||||||
|
|
||||||
newpathdir = fs::dirname(newpath);
|
newpathdir = fs::dirname(newpath);
|
||||||
rv = searchFunc(srcmounts,newpathdir,minfreespace,foundpath);
|
rv = searchFunc(srcmounts,newpathdir,minfreespace,foundpath);
|
||||||
@ -76,8 +76,8 @@ _single_link(const fs::find::Func searchFunc,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_link(const fs::find::Func searchFunc,
|
_link(const Policy::Func::Ptr searchFunc,
|
||||||
const fs::find::Func actionFunc,
|
const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &oldpath,
|
const string &oldpath,
|
||||||
@ -85,14 +85,14 @@ _link(const fs::find::Func searchFunc,
|
|||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths oldpaths;
|
Paths oldpaths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
|
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = _single_link(searchFunc,srcmounts,minfreespace,i->base,oldpath,newpath);
|
rv = _single_link(searchFunc,srcmounts,minfreespace,i->base,oldpath,newpath);
|
||||||
|
@ -69,7 +69,7 @@ _listxattr_controlfile(char *list,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_listxattr(const fs::find::Func searchFunc,
|
_listxattr(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -78,7 +78,7 @@ _listxattr(const fs::find::Func searchFunc,
|
|||||||
{
|
{
|
||||||
#ifndef WITHOUT_XATTR
|
#ifndef WITHOUT_XATTR
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths path;
|
Paths path;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
@ -38,11 +38,12 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_mkdir(const fs::find::Func searchFunc,
|
_mkdir(const Policy::Func::Ptr searchFunc,
|
||||||
const fs::find::Func createFunc,
|
const Policy::Func::Ptr createFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -52,8 +53,8 @@ _mkdir(const fs::find::Func searchFunc,
|
|||||||
int error;
|
int error;
|
||||||
string dirname;
|
string dirname;
|
||||||
string fullpath;
|
string fullpath;
|
||||||
fs::Paths createpaths;
|
Paths createpaths;
|
||||||
fs::Paths existingpath;
|
Paths existingpath;
|
||||||
|
|
||||||
dirname = fs::dirname(fusepath);
|
dirname = fs::dirname(fusepath);
|
||||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||||
@ -65,7 +66,7 @@ _mkdir(const fs::find::Func searchFunc,
|
|||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
|
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
if(i->base != existingpath[0].base)
|
if(i->base != existingpath[0].base)
|
||||||
|
@ -40,11 +40,12 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_mknod(const fs::find::Func searchFunc,
|
_mknod(const Policy::Func::Ptr searchFunc,
|
||||||
const fs::find::Func createFunc,
|
const Policy::Func::Ptr createFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -55,8 +56,8 @@ _mknod(const fs::find::Func searchFunc,
|
|||||||
int error;
|
int error;
|
||||||
string dirname;
|
string dirname;
|
||||||
string fullpath;
|
string fullpath;
|
||||||
fs::Paths createpaths;
|
Paths createpaths;
|
||||||
fs::Paths existingpath;
|
Paths existingpath;
|
||||||
|
|
||||||
dirname = fs::dirname(fusepath);
|
dirname = fs::dirname(fusepath);
|
||||||
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
|
||||||
@ -68,7 +69,7 @@ _mknod(const fs::find::Func searchFunc,
|
|||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
|
i = createpaths.begin(), ei = createpaths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
if(i->base != existingpath[0].base)
|
if(i->base != existingpath[0].base)
|
||||||
|
@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_open(const fs::find::Func searchFunc,
|
_open(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -50,7 +51,7 @@ _open(const fs::find::Func searchFunc,
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths path;
|
Paths path;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
55
src/path.hpp
Normal file
55
src/path.hpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PATH_HPP__
|
||||||
|
#define __PATH_HPP__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct Path
|
||||||
|
{
|
||||||
|
Path() {}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
Path(const std::string &b,
|
||||||
|
const std::string &f)
|
||||||
|
: base(b),
|
||||||
|
full(f)
|
||||||
|
{}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
Path(const char *b,
|
||||||
|
const std::string &f)
|
||||||
|
: base(b),
|
||||||
|
full(f)
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::string base;
|
||||||
|
std::string full;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<Path> Paths;
|
||||||
|
|
||||||
|
#endif /* __PATH_HPP__ */
|
@ -28,7 +28,7 @@
|
|||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
#include "buildvector.hpp"
|
#include "buildvector.hpp"
|
||||||
|
|
||||||
#define POLICY(X) (Policy(Policy::Enum::X,#X,fs::find::X))
|
#define POLICY(X) (Policy(Policy::Enum::X,#X,Policy::Func::X))
|
||||||
|
|
||||||
namespace mergerfs
|
namespace mergerfs
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,10 @@
|
|||||||
#define __POLICY_HPP__
|
#define __POLICY_HPP__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "path.hpp"
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
|
|
||||||
namespace mergerfs
|
namespace mergerfs
|
||||||
@ -54,10 +56,30 @@ namespace mergerfs
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Func
|
||||||
|
{
|
||||||
|
typedef std::string string;
|
||||||
|
typedef std::size_t size_t;
|
||||||
|
typedef std::vector<string> strvec;
|
||||||
|
|
||||||
|
typedef int (*Ptr)(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
|
||||||
|
static int invalid(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int all(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int epmfs(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int ff(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int ffwp(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int fwfs(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int lfs(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int mfs(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int newest(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
static int rand(const strvec&,const string&,const size_t,Paths&);
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Enum::Type _enum;
|
Enum::Type _enum;
|
||||||
std::string _str;
|
std::string _str;
|
||||||
fs::find::Func _func;
|
Func::Ptr _func;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Policy()
|
Policy()
|
||||||
@ -69,7 +91,7 @@ namespace mergerfs
|
|||||||
|
|
||||||
Policy(const Enum::Type enum_,
|
Policy(const Enum::Type enum_,
|
||||||
const std::string &str_,
|
const std::string &str_,
|
||||||
const fs::find::Func func_)
|
const Func::Ptr func_)
|
||||||
: _enum(enum_),
|
: _enum(enum_),
|
||||||
_str(str_),
|
_str(str_),
|
||||||
_func(func_)
|
_func(func_)
|
||||||
@ -79,14 +101,14 @@ namespace mergerfs
|
|||||||
public:
|
public:
|
||||||
operator const Enum::Type() const { return _enum; }
|
operator const Enum::Type() const { return _enum; }
|
||||||
operator const std::string&() const { return _str; }
|
operator const std::string&() const { return _str; }
|
||||||
operator const fs::find::Func() const { return _func; }
|
operator const Func::Ptr() const { return _func; }
|
||||||
operator const Policy*() const { return this; }
|
operator const Policy*() const { return this; }
|
||||||
|
|
||||||
bool operator==(const Enum::Type enum_) const
|
bool operator==(const Enum::Type enum_) const
|
||||||
{ return _enum == enum_; }
|
{ return _enum == enum_; }
|
||||||
bool operator==(const std::string &str_) const
|
bool operator==(const std::string &str_) const
|
||||||
{ return _str == str_; }
|
{ return _str == str_; }
|
||||||
bool operator==(const fs::find::Func func_) const
|
bool operator==(const Func::Ptr func_) const
|
||||||
{ return _func == func_; }
|
{ return _func == func_; }
|
||||||
|
|
||||||
bool operator!=(const Policy &r) const
|
bool operator!=(const Policy &r) const
|
||||||
|
65
src/policy_all.cpp
Normal file
65
src/policy_all.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::all(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
struct stat st;
|
||||||
|
string fullpath;
|
||||||
|
|
||||||
|
for(vector<string>::const_iterator
|
||||||
|
iter = basepaths.begin(), eiter = basepaths.end();
|
||||||
|
iter != eiter;
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
fullpath = fs::make_path(*iter,fusepath);
|
||||||
|
|
||||||
|
rv = ::lstat(fullpath.c_str(),&st);
|
||||||
|
if(rv == 0)
|
||||||
|
paths.push_back(Path(*iter,fullpath));
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths.empty() ? (errno=ENOENT,-1) : 0;
|
||||||
|
}
|
||||||
|
}
|
104
src/policy_epmfs.cpp
Normal file
104
src/policy_epmfs.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::epmfs(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
fsblkcnt_t existingmfs;
|
||||||
|
fsblkcnt_t generalmfs;
|
||||||
|
string fullpath;
|
||||||
|
string generalmfspath;
|
||||||
|
string existingmfspath;
|
||||||
|
vector<string>::const_iterator iter = basepaths.begin();
|
||||||
|
vector<string>::const_iterator eiter = basepaths.end();
|
||||||
|
|
||||||
|
if(iter == eiter)
|
||||||
|
return (errno = ENOENT,-1);
|
||||||
|
|
||||||
|
existingmfs = 0;
|
||||||
|
generalmfs = 0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
struct statvfs fsstats;
|
||||||
|
const string &mountpoint = *iter;
|
||||||
|
|
||||||
|
rv = ::statvfs(mountpoint.c_str(),&fsstats);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
fsblkcnt_t spaceavail;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||||
|
if(spaceavail > generalmfs)
|
||||||
|
{
|
||||||
|
generalmfs = spaceavail;
|
||||||
|
generalmfspath = mountpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
fullpath = fs::make_path(mountpoint,fusepath);
|
||||||
|
rv = ::lstat(fullpath.c_str(),&st);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
if(spaceavail > existingmfs)
|
||||||
|
{
|
||||||
|
existingmfs = spaceavail;
|
||||||
|
existingmfspath = mountpoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++iter;
|
||||||
|
}
|
||||||
|
while(iter != eiter);
|
||||||
|
|
||||||
|
if(existingmfspath.empty())
|
||||||
|
existingmfspath = generalmfspath;
|
||||||
|
|
||||||
|
paths.push_back(Path(existingmfspath,
|
||||||
|
fullpath));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
70
src/policy_ff.cpp
Normal file
70
src/policy_ff.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "path.hpp"
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::ff(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
errno = ENOENT;
|
||||||
|
for(vector<string>::const_iterator
|
||||||
|
iter = basepaths.begin(), eiter = basepaths.end();
|
||||||
|
iter != eiter;
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
struct stat st;
|
||||||
|
string fullpath;
|
||||||
|
|
||||||
|
fullpath = fs::make_path(*iter,fusepath);
|
||||||
|
|
||||||
|
rv = ::lstat(fullpath.c_str(),&st);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
paths.push_back(Path(*iter,fullpath));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
79
src/policy_ffwp.cpp
Normal file
79
src/policy_ffwp.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::ffwp(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
Path fallback;
|
||||||
|
|
||||||
|
errno = ENOENT;
|
||||||
|
for(vector<string>::const_iterator
|
||||||
|
iter = basepaths.begin(), eiter = basepaths.end();
|
||||||
|
iter != eiter;
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
struct stat st;
|
||||||
|
string fullpath;
|
||||||
|
|
||||||
|
fullpath = fs::make_path(*iter,fusepath);
|
||||||
|
|
||||||
|
rv = ::lstat(fullpath.c_str(),&st);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
paths.push_back(Path(*iter,fullpath));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if(errno == EACCES)
|
||||||
|
{
|
||||||
|
fallback.base = *iter;
|
||||||
|
fallback.full = fullpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!fallback.base.empty())
|
||||||
|
return (paths.push_back(fallback),0);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
69
src/policy_fwfs.cpp
Normal file
69
src/policy_fwfs.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::fwfs(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
const char *basepath;
|
||||||
|
struct statvfs fsstats;
|
||||||
|
|
||||||
|
basepath = basepaths[i].c_str();
|
||||||
|
rv = ::statvfs(basepath,&fsstats);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
fsblkcnt_t spaceavail;
|
||||||
|
|
||||||
|
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||||
|
if(spaceavail > minfreespace)
|
||||||
|
{
|
||||||
|
paths.push_back(Path(basepath,
|
||||||
|
fs::make_path(basepath,fusepath)));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mfs(basepaths,fusepath,minfreespace,paths);
|
||||||
|
}
|
||||||
|
}
|
46
src/policy_invalid.cpp
Normal file
46
src/policy_invalid.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::invalid(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &rv)
|
||||||
|
{
|
||||||
|
return (errno = EINVAL,-1);
|
||||||
|
}
|
||||||
|
}
|
83
src/policy_lfs.cpp
Normal file
83
src/policy_lfs.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::lfs(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
fsblkcnt_t lfs;
|
||||||
|
const char *lfsstr;
|
||||||
|
|
||||||
|
lfs = -1;
|
||||||
|
lfsstr = NULL;
|
||||||
|
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
const char *basepath;
|
||||||
|
struct statvfs fsstats;
|
||||||
|
|
||||||
|
basepath = basepaths[i].c_str();
|
||||||
|
rv = ::statvfs(basepath,&fsstats);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
fsblkcnt_t spaceavail;
|
||||||
|
|
||||||
|
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||||
|
if((spaceavail > minfreespace) &&
|
||||||
|
(spaceavail < lfs))
|
||||||
|
{
|
||||||
|
lfs = spaceavail;
|
||||||
|
lfsstr = basepath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lfsstr == NULL)
|
||||||
|
return Policy::Func::mfs(basepaths,fusepath,minfreespace,paths);
|
||||||
|
|
||||||
|
paths.push_back(Path(lfsstr,
|
||||||
|
fs::make_path(lfsstr,fusepath)));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
78
src/policy_mfs.cpp
Normal file
78
src/policy_mfs.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/statvfs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::mfs(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
fsblkcnt_t mfs;
|
||||||
|
size_t mfsidx;
|
||||||
|
|
||||||
|
mfs = 0;
|
||||||
|
for(size_t i = 0, size = basepaths.size();
|
||||||
|
i != size;
|
||||||
|
i++)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
struct statvfs fsstats;
|
||||||
|
|
||||||
|
rv = ::statvfs(basepaths[i].c_str(),&fsstats);
|
||||||
|
if(rv == 0)
|
||||||
|
{
|
||||||
|
fsblkcnt_t spaceavail;
|
||||||
|
|
||||||
|
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
|
||||||
|
if(spaceavail > mfs)
|
||||||
|
{
|
||||||
|
mfs = spaceavail;
|
||||||
|
mfsidx = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mfs == 0)
|
||||||
|
return (errno=ENOENT,-1);
|
||||||
|
|
||||||
|
paths.push_back(Path(basepaths[mfsidx],
|
||||||
|
fs::make_path(basepaths[mfsidx],fusepath)));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
78
src/policy_newest.cpp
Normal file
78
src/policy_newest.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::newest(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
time_t newest;
|
||||||
|
string npath;
|
||||||
|
vector<string>::const_iterator niter;
|
||||||
|
|
||||||
|
newest = 0;
|
||||||
|
errno = ENOENT;
|
||||||
|
for(vector<string>::const_iterator
|
||||||
|
iter = basepaths.begin(), eiter = basepaths.end();
|
||||||
|
iter != eiter;
|
||||||
|
++iter)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
struct stat st;
|
||||||
|
string fullpath;
|
||||||
|
|
||||||
|
fullpath = fs::make_path(*iter,fusepath);
|
||||||
|
|
||||||
|
rv = ::lstat(fullpath.c_str(),&st);
|
||||||
|
if(rv == 0 && st.st_mtime > newest)
|
||||||
|
{
|
||||||
|
newest = st.st_mtime;
|
||||||
|
niter = iter;
|
||||||
|
npath = fullpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(newest)
|
||||||
|
return (paths.push_back(Path(*niter,npath)),0);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
55
src/policy_rand.cpp
Normal file
55
src/policy_rand.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "policy.hpp"
|
||||||
|
|
||||||
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
|
using std::size_t;
|
||||||
|
|
||||||
|
namespace mergerfs
|
||||||
|
{
|
||||||
|
int
|
||||||
|
Policy::Func::rand(const vector<string> &basepaths,
|
||||||
|
const string &fusepath,
|
||||||
|
const size_t minfreespace,
|
||||||
|
Paths &paths)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv = Policy::Func::all(basepaths,fusepath,minfreespace,paths);
|
||||||
|
if(rv == -1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
std::random_shuffle(paths.begin(),paths.end());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -41,7 +41,7 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_readlink(const fs::find::Func searchFunc,
|
_readlink(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -49,7 +49,7 @@ _readlink(const fs::find::Func searchFunc,
|
|||||||
const size_t size)
|
const size_t size)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
fs::Paths path;
|
Paths path;
|
||||||
|
|
||||||
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
|
@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_removexattr(const fs::find::Func actionFunc,
|
_removexattr(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -50,14 +51,14 @@ _removexattr(const fs::find::Func actionFunc,
|
|||||||
#ifndef WITHOUT_XATTR
|
#ifndef WITHOUT_XATTR
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::lremovexattr(i->full.c_str(),attrname);
|
rv = ::lremovexattr(i->full.c_str(),attrname);
|
||||||
|
@ -38,13 +38,14 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_single_rename(const fs::find::Func searchFunc,
|
_single_rename(const Policy::Func::Ptr searchFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const fs::Path &oldpath,
|
const Path &oldpath,
|
||||||
const string &newpath)
|
const string &newpath)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
@ -54,7 +55,7 @@ _single_rename(const fs::find::Func searchFunc,
|
|||||||
if(rv == -1 && errno == ENOENT)
|
if(rv == -1 && errno == ENOENT)
|
||||||
{
|
{
|
||||||
string dirname;
|
string dirname;
|
||||||
fs::Paths newpathdir;
|
Paths newpathdir;
|
||||||
|
|
||||||
dirname = fs::dirname(newpath);
|
dirname = fs::dirname(newpath);
|
||||||
rv = searchFunc(srcmounts,dirname,minfreespace,newpathdir);
|
rv = searchFunc(srcmounts,dirname,minfreespace,newpathdir);
|
||||||
@ -74,8 +75,8 @@ _single_rename(const fs::find::Func searchFunc,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_rename(const fs::find::Func searchFunc,
|
_rename(const Policy::Func::Ptr searchFunc,
|
||||||
const fs::find::Func actionFunc,
|
const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &oldpath,
|
const string &oldpath,
|
||||||
@ -83,14 +84,14 @@ _rename(const fs::find::Func searchFunc,
|
|||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths oldpaths;
|
Paths oldpaths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
|
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = _single_rename(searchFunc,srcmounts,minfreespace,*i,newpath);
|
rv = _single_rename(searchFunc,srcmounts,minfreespace,*i,newpath);
|
||||||
|
@ -40,21 +40,21 @@ using mergerfs::Policy;
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_rmdir(const fs::find::Func actionFunc,
|
_rmdir(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath)
|
const string &fusepath)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::rmdir(i->full.c_str());
|
rv = ::rmdir(i->full.c_str());
|
||||||
|
@ -240,7 +240,7 @@ _setxattr_controlfile(config::Config &config,
|
|||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_setxattr(const fs::find::Func actionFunc,
|
_setxattr(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -252,14 +252,14 @@ _setxattr(const fs::find::Func actionFunc,
|
|||||||
#ifndef WITHOUT_XATTR
|
#ifndef WITHOUT_XATTR
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::lsetxattr(i->full.c_str(),attrname,attrval,attrvalsize,flags);
|
rv = ::lsetxattr(i->full.c_str(),attrname,attrval,attrvalsize,flags);
|
||||||
|
@ -36,10 +36,11 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_symlink(const fs::find::Func createFunc,
|
_symlink(const Policy::Func::Ptr createFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &oldpath,
|
const string &oldpath,
|
||||||
@ -48,7 +49,7 @@ _symlink(const fs::find::Func createFunc,
|
|||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
string newpathdir;
|
string newpathdir;
|
||||||
fs::Paths newpathdirs;
|
Paths newpathdirs;
|
||||||
|
|
||||||
newpathdir = fs::dirname(newpath);
|
newpathdir = fs::dirname(newpath);
|
||||||
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
|
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
|
||||||
@ -56,7 +57,7 @@ _symlink(const fs::find::Func createFunc,
|
|||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::iterator
|
for(Paths::iterator
|
||||||
i = newpathdirs.begin(), ei = newpathdirs.end(); i != ei; ++i)
|
i = newpathdirs.begin(), ei = newpathdirs.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
i->full = fs::make_path(i->base,newpath);
|
i->full = fs::make_path(i->base,newpath);
|
||||||
|
@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_truncate(const fs::find::Func actionFunc,
|
_truncate(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -49,14 +50,14 @@ _truncate(const fs::find::Func actionFunc,
|
|||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::truncate(i->full.c_str(),size);
|
rv = ::truncate(i->full.c_str(),size);
|
||||||
|
@ -37,24 +37,25 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_unlink(const fs::find::Func actionFunc,
|
_unlink(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath)
|
const string &fusepath)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::unlink(i->full.c_str());
|
rv = ::unlink(i->full.c_str());
|
||||||
|
@ -38,10 +38,11 @@
|
|||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
using mergerfs::Policy;
|
||||||
|
|
||||||
static
|
static
|
||||||
int
|
int
|
||||||
_utimens(const fs::find::Func actionFunc,
|
_utimens(const Policy::Func::Ptr actionFunc,
|
||||||
const vector<string> &srcmounts,
|
const vector<string> &srcmounts,
|
||||||
const size_t minfreespace,
|
const size_t minfreespace,
|
||||||
const string &fusepath,
|
const string &fusepath,
|
||||||
@ -49,14 +50,14 @@ _utimens(const fs::find::Func actionFunc,
|
|||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
int error;
|
int error;
|
||||||
fs::Paths paths;
|
Paths paths;
|
||||||
|
|
||||||
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
|
||||||
if(rv == -1)
|
if(rv == -1)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
error = 0;
|
error = 0;
|
||||||
for(fs::Paths::const_iterator
|
for(Paths::const_iterator
|
||||||
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
i = paths.begin(), ei = paths.end(); i != ei; ++i)
|
||||||
{
|
{
|
||||||
rv = ::utimensat(0,i->full.c_str(),ts,AT_SYMLINK_NOFOLLOW);
|
rv = ::utimensat(0,i->full.c_str(),ts,AT_SYMLINK_NOFOLLOW);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user