2015-06-23 22:24:55 -04:00
|
|
|
/*
|
2016-01-14 16:50:22 -05: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-23 22:24:55 -04:00
|
|
|
*/
|
|
|
|
|
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2018-10-13 23:48:30 -04:00
|
|
|
#include "fs_exists.hpp"
|
|
|
|
|
#include "fs_info.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2015-06-23 22:24:55 -04:00
|
|
|
#include "policy.hpp"
|
2018-10-20 23:40:02 -04:00
|
|
|
#include "policy_error.hpp"
|
2019-09-24 10:27:46 -04:00
|
|
|
#include "rwlock.hpp"
|
2015-06-23 22:24:55 -04:00
|
|
|
|
2018-10-13 23:48:30 -04:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2015-06-23 22:24:55 -04:00
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
2018-10-20 23:40:02 -04:00
|
|
|
namespace ff
|
2015-06-30 23:35:28 -04:00
|
|
|
{
|
2018-10-20 23:40:02 -04:00
|
|
|
static
|
|
|
|
|
int
|
2020-08-20 18:47:04 -04:00
|
|
|
create(const BranchVec &branches_,
|
|
|
|
|
vector<string> *paths_)
|
2018-10-20 23:40:02 -04:00
|
|
|
{
|
|
|
|
|
int rv;
|
|
|
|
|
int error;
|
|
|
|
|
fs::info_t info;
|
|
|
|
|
const Branch *branch;
|
|
|
|
|
|
|
|
|
|
error = ENOENT;
|
|
|
|
|
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
|
|
|
|
{
|
|
|
|
|
branch = &branches_[i];
|
|
|
|
|
|
2018-11-01 23:37:45 -04:00
|
|
|
if(branch->ro_or_nc())
|
2018-10-20 23:40:02 -04:00
|
|
|
error_and_continue(error,EROFS);
|
2020-08-16 18:22:25 -04:00
|
|
|
rv = fs::info(branch->path,&info);
|
2018-10-20 23:40:02 -04:00
|
|
|
if(rv == -1)
|
|
|
|
|
error_and_continue(error,ENOENT);
|
|
|
|
|
if(info.readonly)
|
|
|
|
|
error_and_continue(error,EROFS);
|
2020-08-20 18:47:04 -04:00
|
|
|
if(info.spaceavail < branch->minfreespace())
|
2018-10-20 23:40:02 -04:00
|
|
|
error_and_continue(error,ENOSPC);
|
|
|
|
|
|
2020-08-16 18:22:25 -04:00
|
|
|
paths_->push_back(branch->path);
|
2018-10-20 23:40:02 -04:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (errno=error,-1);
|
|
|
|
|
}
|
2020-08-20 18:47:04 -04:00
|
|
|
|
|
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
create(const Branches &branches_,
|
|
|
|
|
vector<string> *paths_)
|
|
|
|
|
{
|
|
|
|
|
rwlock::ReadGuard guard(branches_.lock);
|
|
|
|
|
|
|
|
|
|
return ff::create(branches_.vec,paths_);
|
|
|
|
|
}
|
2015-07-21 14:19:17 -04:00
|
|
|
}
|
|
|
|
|
|
2019-01-06 12:52:55 -05:00
|
|
|
int
|
2020-08-16 18:22:25 -04:00
|
|
|
Policy::Func::ff(const Category type_,
|
2020-08-16 13:30:43 -04:00
|
|
|
const Branches &branches_,
|
2020-08-16 18:22:25 -04:00
|
|
|
const char *fusepath_,
|
|
|
|
|
vector<string> *paths_)
|
2015-06-23 22:24:55 -04:00
|
|
|
{
|
2020-08-16 18:22:25 -04:00
|
|
|
if(type_ == Category::CREATE)
|
2020-08-20 18:47:04 -04:00
|
|
|
return ff::create(branches_,paths_);
|
2015-07-21 14:19:17 -04:00
|
|
|
|
2020-08-20 18:47:04 -04:00
|
|
|
return Policy::Func::epff(type_,branches_,fusepath_,paths_);
|
2015-06-23 22:24:55 -04:00
|
|
|
}
|