mirror of https://github.com/trapexit/mergerfs.git
Antonio SJ Musumeci
10 years ago
35 changed files with 886 additions and 523 deletions
-
10src/access.cpp
-
10src/chmod.cpp
-
12src/chown.cpp
-
16src/create.cpp
-
338src/fs.cpp
-
44src/fs.hpp
-
10src/getattr.cpp
-
14src/getxattr.cpp
-
16src/ioctl.cpp
-
24src/link.cpp
-
12src/listxattr.cpp
-
12src/mkdir.cpp
-
14src/mknod.cpp
-
12src/open.cpp
-
2src/policy.cpp
-
30src/policy.hpp
-
65src/policy_all.cpp
-
104src/policy_epmfs.cpp
-
70src/policy_ff.cpp
-
79src/policy_ffwp.cpp
-
69src/policy_fwfs.cpp
-
46src/policy_invalid.cpp
-
83src/policy_lfs.cpp
-
78src/policy_mfs.cpp
-
78src/policy_newest.cpp
-
55src/policy_rand.cpp
-
12src/readlink.cpp
-
10src/removexattr.cpp
-
22src/rename.cpp
-
8src/rmdir.cpp
-
16src/setxattr.cpp
-
10src/symlink.cpp
-
10src/truncate.cpp
-
8src/unlink.cpp
-
10src/utimens.cpp
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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); |
||||
|
} |
||||
|
} |
@ -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); |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
@ -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; |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue