2015-06-24 10:24:55 +08:00
|
|
|
/*
|
2016-01-15 05:50:22 +08:00
|
|
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2015-06-24 10:24:55 +08:00
|
|
|
*/
|
|
|
|
|
2016-09-14 20:36:06 +08:00
|
|
|
#include "errno.hpp"
|
2018-10-14 11:48:30 +08:00
|
|
|
#include "fs_exists.hpp"
|
|
|
|
#include "fs_info.hpp"
|
2015-09-16 06:49:18 +08:00
|
|
|
#include "fs_path.hpp"
|
2020-12-20 04:06:08 +08:00
|
|
|
#include "policies.hpp"
|
2015-06-24 10:24:55 +08:00
|
|
|
#include "policy.hpp"
|
2018-10-21 11:40:02 +08:00
|
|
|
#include "policy_error.hpp"
|
2015-06-24 10:24:55 +08:00
|
|
|
|
2018-10-14 11:48:30 +08:00
|
|
|
#include <string>
|
|
|
|
|
2015-06-24 10:24:55 +08:00
|
|
|
using std::string;
|
|
|
|
|
2018-10-21 11:40:02 +08:00
|
|
|
namespace mfs
|
2015-07-01 11:35:28 +08:00
|
|
|
{
|
2018-10-21 11:40:02 +08:00
|
|
|
static
|
|
|
|
int
|
2020-12-20 04:06:08 +08:00
|
|
|
create(const Branches::CPtr &branches_,
|
|
|
|
StrVec *paths_)
|
2018-10-21 11:40:02 +08:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
int error;
|
|
|
|
uint64_t mfs;
|
|
|
|
fs::info_t info;
|
2020-08-21 06:47:04 +08:00
|
|
|
const string *basepath;
|
2018-10-21 11:40:02 +08:00
|
|
|
|
|
|
|
error = ENOENT;
|
|
|
|
mfs = 0;
|
2020-08-21 06:47:04 +08:00
|
|
|
basepath = NULL;
|
2020-12-20 04:06:08 +08:00
|
|
|
for(const auto &branch : *branches_)
|
2018-10-21 11:40:02 +08:00
|
|
|
{
|
2020-12-20 04:06:08 +08:00
|
|
|
if(branch.ro_or_nc())
|
2018-10-21 11:40:02 +08:00
|
|
|
error_and_continue(error,EROFS);
|
2020-12-20 04:06:08 +08:00
|
|
|
rv = fs::info(branch.path,&info);
|
2018-10-21 11:40:02 +08:00
|
|
|
if(rv == -1)
|
|
|
|
error_and_continue(error,ENOENT);
|
|
|
|
if(info.readonly)
|
|
|
|
error_and_continue(error,EROFS);
|
2020-12-20 04:06:08 +08:00
|
|
|
if(info.spaceavail < branch.minfreespace())
|
2018-10-21 11:40:02 +08:00
|
|
|
error_and_continue(error,ENOSPC);
|
|
|
|
if(info.spaceavail < mfs)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
mfs = info.spaceavail;
|
2020-12-20 04:06:08 +08:00
|
|
|
basepath = &branch.path;
|
2018-10-21 11:40:02 +08:00
|
|
|
}
|
|
|
|
|
2020-08-21 06:47:04 +08:00
|
|
|
if(basepath == NULL)
|
2018-10-21 11:40:02 +08:00
|
|
|
return (errno=error,-1);
|
|
|
|
|
2020-08-21 06:47:04 +08:00
|
|
|
paths_->push_back(*basepath);
|
2018-10-21 11:40:02 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-12-20 04:06:08 +08:00
|
|
|
}
|
2020-08-21 06:47:04 +08:00
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
int
|
|
|
|
Policy::MFS::Action::operator()(const Branches::CPtr &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
StrVec *paths_) const
|
|
|
|
{
|
2021-08-30 00:33:52 +08:00
|
|
|
return Policies::Action::epmfs(branches_,fusepath_,paths_);
|
2016-03-01 11:58:13 +08:00
|
|
|
}
|
|
|
|
|
2019-01-07 01:52:55 +08:00
|
|
|
int
|
2020-12-20 04:06:08 +08:00
|
|
|
Policy::MFS::Create::operator()(const Branches::CPtr &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
StrVec *paths_) const
|
2015-06-24 10:24:55 +08:00
|
|
|
{
|
2020-12-20 04:06:08 +08:00
|
|
|
return ::mfs::create(branches_,paths_);
|
|
|
|
}
|
2015-07-01 11:35:28 +08:00
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
int
|
|
|
|
Policy::MFS::Search::operator()(const Branches::CPtr &branches_,
|
|
|
|
const char *fusepath_,
|
|
|
|
StrVec *paths_) const
|
|
|
|
{
|
|
|
|
return Policies::Search::epmfs(branches_,fusepath_,paths_);
|
2015-06-24 10:24:55 +08:00
|
|
|
}
|