diff --git a/README.md b/README.md index 49aa5daa..7a61cc33 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Filesystem calls are broken up into 3 categories: **action**, **create**, **sear | lfs (least free space) | Pick the path with least available space but more than **minfreespace**. | | rand (random) | Pick an existing destination at random. | | all | Applies action to all found. For searches it will behave like first found **ff**. | +| enosys, einval, enotsup, exdev, erofs | Exclusively return `-1` with `errno` set to the respective value. Useful for debugging other applications' behavior to errors. | #### Defaults #### diff --git a/src/policy.cpp b/src/policy.cpp index 6428e705..4b7db213 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -36,7 +36,12 @@ namespace mergerfs buildvector (POLICY(invalid)) (POLICY(all)) + (POLICY(einval)) + (POLICY(enosys)) + (POLICY(enotsup)) (POLICY(epmfs)) + (POLICY(erofs)) + (POLICY(exdev)) (POLICY(ff)) (POLICY(ffwp)) (POLICY(fwfs)) @@ -47,16 +52,23 @@ namespace mergerfs const Policy * const Policy::policies = &_policies_[1]; - const Policy &Policy::invalid = Policy::policies[Policy::Enum::invalid]; - const Policy &Policy::all = Policy::policies[Policy::Enum::all]; - const Policy &Policy::epmfs = Policy::policies[Policy::Enum::epmfs]; - const Policy &Policy::ff = Policy::policies[Policy::Enum::ff]; - const Policy &Policy::ffwp = Policy::policies[Policy::Enum::ffwp]; - const Policy &Policy::fwfs = Policy::policies[Policy::Enum::fwfs]; - const Policy &Policy::lfs = Policy::policies[Policy::Enum::lfs]; - const Policy &Policy::mfs = Policy::policies[Policy::Enum::mfs]; - const Policy &Policy::newest = Policy::policies[Policy::Enum::newest]; - const Policy &Policy::rand = Policy::policies[Policy::Enum::rand]; +#define CONST_POLICY(X) const Policy &Policy::X = Policy::policies[Policy::Enum::X] + + CONST_POLICY(invalid); + CONST_POLICY(all); + CONST_POLICY(einval); + CONST_POLICY(enosys); + CONST_POLICY(enotsup); + CONST_POLICY(epmfs); + CONST_POLICY(erofs); + CONST_POLICY(exdev); + CONST_POLICY(ff); + CONST_POLICY(ffwp); + CONST_POLICY(fwfs); + CONST_POLICY(lfs); + CONST_POLICY(mfs); + CONST_POLICY(newest); + CONST_POLICY(rand); const Policy& Policy::find(const std::string &str) diff --git a/src/policy.hpp b/src/policy.hpp index e75f559f..d05731c6 100644 --- a/src/policy.hpp +++ b/src/policy.hpp @@ -45,7 +45,12 @@ namespace mergerfs invalid = -1, BEGIN = 0, all = BEGIN, + einval, + enosys, + enotsup, epmfs, + erofs, + exdev, ff, ffwp, fwfs, @@ -120,12 +125,17 @@ namespace mergerfs const Ptr func; }; - static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&); static int all(CType,cstrvec&,cstring&,csize_t,strvec&); + static int einval(CType,cstrvec&,cstring&,csize_t,strvec&); + static int enosys(CType,cstrvec&,cstring&,csize_t,strvec&); + static int enotsup(CType,cstrvec&,cstring&,csize_t,strvec&); static int epmfs(CType,cstrvec&,cstring&,csize_t,strvec&); + static int erofs(CType,cstrvec&,cstring&,csize_t,strvec&); + static int exdev(CType,cstrvec&,cstring&,csize_t,strvec&); static int ff(CType,cstrvec&,cstring&,csize_t,strvec&); static int ffwp(CType,cstrvec&,cstring&,csize_t,strvec&); static int fwfs(CType,cstrvec&,cstring&,csize_t,strvec&); + static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&); static int lfs(CType,cstrvec&,cstring&,csize_t,strvec&); static int mfs(CType,cstrvec&,cstring&,csize_t,strvec&); static int newest(CType,cstrvec&,cstring&,csize_t,strvec&); @@ -183,7 +193,11 @@ namespace mergerfs static const Policy &invalid; static const Policy &all; + static const Policy &enosys; + static const Policy &enotsup; static const Policy &epmfs; + static const Policy &erofs; + static const Policy &exdev; static const Policy &ff; static const Policy &ffwp; static const Policy &fwfs; diff --git a/src/policy_einval.cpp b/src/policy_einval.cpp new file mode 100644 index 00000000..2949633f --- /dev/null +++ b/src/policy_einval.cpp @@ -0,0 +1,46 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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 + +#include +#include + +#include "policy.hpp" + +using std::string; +using std::vector; + +namespace mergerfs +{ + int + Policy::Func::einval(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + vector &paths) + { + return (errno=EINVAL,-1); + } +} diff --git a/src/policy_enosys.cpp b/src/policy_enosys.cpp new file mode 100644 index 00000000..038d8aca --- /dev/null +++ b/src/policy_enosys.cpp @@ -0,0 +1,46 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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 + +#include +#include + +#include "policy.hpp" + +using std::string; +using std::vector; + +namespace mergerfs +{ + int + Policy::Func::enosys(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + vector &paths) + { + return (errno=ENOSYS,-1); + } +} diff --git a/src/policy_enotsup.cpp b/src/policy_enotsup.cpp new file mode 100644 index 00000000..2d0a4b92 --- /dev/null +++ b/src/policy_enotsup.cpp @@ -0,0 +1,46 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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 + +#include +#include + +#include "policy.hpp" + +using std::string; +using std::vector; + +namespace mergerfs +{ + int + Policy::Func::enotsup(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + vector &paths) + { + return (errno=ENOTSUP,-1); + } +} diff --git a/src/policy_erofs.cpp b/src/policy_erofs.cpp new file mode 100644 index 00000000..9a59ee7c --- /dev/null +++ b/src/policy_erofs.cpp @@ -0,0 +1,46 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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 + +#include +#include + +#include "policy.hpp" + +using std::string; +using std::vector; + +namespace mergerfs +{ + int + Policy::Func::erofs(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + vector &paths) + { + return (errno=EROFS,-1); + } +} diff --git a/src/policy_exdev.cpp b/src/policy_exdev.cpp new file mode 100644 index 00000000..31047ffb --- /dev/null +++ b/src/policy_exdev.cpp @@ -0,0 +1,46 @@ +/* + The MIT License (MIT) + + Copyright (c) 2014 Antonio SJ Musumeci + + 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 + +#include +#include + +#include "policy.hpp" + +using std::string; +using std::vector; + +namespace mergerfs +{ + int + Policy::Func::exdev(const Category::Enum::Type type, + const vector &basepaths, + const string &fusepath, + const size_t minfreespace, + vector &paths) + { + return (errno=EXDEV,-1); + } +} diff --git a/src/policy_invalid.cpp b/src/policy_invalid.cpp index 5fa251db..b887d87b 100644 --- a/src/policy_invalid.cpp +++ b/src/policy_invalid.cpp @@ -42,6 +42,6 @@ namespace mergerfs const size_t minfreespace, vector &rv) { - return (errno = EINVAL,-1); + return (errno=EINVAL,-1); } }